aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-11-12 19:36:58 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-11-12 19:36:58 -0500
commit60764eb379b371b8c7145f1a0914ee56d19e689f (patch)
treedfd3c6eefa87999f8710a94460f4a69ede19bcd8
parent1be9c3a0a03330c8e61db30d442b31522092c291 (diff)
parentd954f94cfa4488f4281db2b698d90e1b03facb4d (diff)
Merge branch 'acpica'
* acpica: ACPICA: Update version to 20170831 ACPICA: Update acpi_get_timer for 64-bit interface to acpi_hw_read ACPICA: String conversions: Update to add new behaviors ACPICA: String conversions: Cleanup/format comments. No functional changes ACPICA: Restructure/cleanup all string-to-integer conversion functions ACPICA: Header support for the PDTT ACPI table ACPICA: acpiexec: Add testability of deferred table verification ACPICA: Hardware: Enable 64-bit support of hardware accesses
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/achware.h4
-rw-r--r--drivers/acpi/acpica/acinterp.h6
-rw-r--r--drivers/acpi/acpica/acutils.h33
-rw-r--r--drivers/acpi/acpica/dbconvert.c5
-rw-r--r--drivers/acpi/acpica/dswexec.c2
-rw-r--r--drivers/acpi/acpica/evgpe.c6
-rw-r--r--drivers/acpi/acpica/exconcat.c2
-rw-r--r--drivers/acpi/acpica/exconvrt.c30
-rw-r--r--drivers/acpi/acpica/exmisc.c2
-rw-r--r--drivers/acpi/acpica/exresop.c2
-rw-r--r--drivers/acpi/acpica/hwgpe.c4
-rw-r--r--drivers/acpi/acpica/hwregs.c72
-rw-r--r--drivers/acpi/acpica/hwtimer.c10
-rw-r--r--drivers/acpi/acpica/hwxface.c118
-rw-r--r--drivers/acpi/acpica/nsconvert.c4
-rw-r--r--drivers/acpi/acpica/tbxface.c9
-rw-r--r--drivers/acpi/acpica/utstrsuppt.c438
-rw-r--r--drivers/acpi/acpica/utstrtoul64.c442
-rw-r--r--include/acpi/acexcep.h16
-rw-r--r--include/acpi/acpixf.h2
-rw-r--r--include/acpi/actbl1.h30
-rw-r--r--tools/power/acpi/tools/acpidump/Makefile1
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c3
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c4
25 files changed, 834 insertions, 412 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index e05232da0588..71f6f2624deb 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -178,6 +178,7 @@ acpi-y += \
178 utresrc.o \ 178 utresrc.o \
179 utstate.o \ 179 utstate.o \
180 utstring.o \ 180 utstring.o \
181 utstrsuppt.o \
181 utstrtoul64.o \ 182 utstrtoul64.o \
182 utxface.o \ 183 utxface.o \
183 utxfinit.o \ 184 utxfinit.o \
diff --git a/drivers/acpi/acpica/achware.h b/drivers/acpi/acpica/achware.h
index fd4f3cacb356..cd722d8edacb 100644
--- a/drivers/acpi/acpica/achware.h
+++ b/drivers/acpi/acpica/achware.h
@@ -66,9 +66,9 @@ acpi_status
66acpi_hw_validate_register(struct acpi_generic_address *reg, 66acpi_hw_validate_register(struct acpi_generic_address *reg,
67 u8 max_bit_width, u64 *address); 67 u8 max_bit_width, u64 *address);
68 68
69acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg); 69acpi_status acpi_hw_read(u64 *value, struct acpi_generic_address *reg);
70 70
71acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg); 71acpi_status acpi_hw_write(u64 value, struct acpi_generic_address *reg);
72 72
73struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id); 73struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id);
74 74
diff --git a/drivers/acpi/acpica/acinterp.h b/drivers/acpi/acpica/acinterp.h
index 29a863c85318..29555c8789a3 100644
--- a/drivers/acpi/acpica/acinterp.h
+++ b/drivers/acpi/acpica/acinterp.h
@@ -101,7 +101,8 @@ typedef const struct acpi_exdump_info {
101 */ 101 */
102acpi_status 102acpi_status
103acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc, 103acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
104 union acpi_operand_object **result_desc, u32 flags); 104 union acpi_operand_object **result_desc,
105 u32 implicit_conversion);
105 106
106acpi_status 107acpi_status
107acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc, 108acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
@@ -424,9 +425,6 @@ acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
424 struct acpi_walk_state *walk_state, 425 struct acpi_walk_state *walk_state,
425 u8 implicit_conversion); 426 u8 implicit_conversion);
426 427
427#define ACPI_IMPLICIT_CONVERSION TRUE
428#define ACPI_NO_IMPLICIT_CONVERSION FALSE
429
430/* 428/*
431 * exstoren - resolve/store object 429 * exstoren - resolve/store object
432 */ 430 */
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 745134ade35f..83b75e9db7ef 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -141,6 +141,11 @@ extern const char *acpi_gbl_ptyp_decode[];
141#define ACPI_MSG_SUFFIX \ 141#define ACPI_MSG_SUFFIX \
142 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number) 142 acpi_os_printf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, module_name, line_number)
143 143
144/* Flags to indicate implicit or explicit string-to-integer conversion */
145
146#define ACPI_IMPLICIT_CONVERSION TRUE
147#define ACPI_NO_IMPLICIT_CONVERSION FALSE
148
144/* Types for Resource descriptor entries */ 149/* Types for Resource descriptor entries */
145 150
146#define ACPI_INVALID_RESOURCE 0 151#define ACPI_INVALID_RESOURCE 0
@@ -197,15 +202,31 @@ void acpi_ut_strlwr(char *src_string);
197 202
198int acpi_ut_stricmp(char *string1, char *string2); 203int acpi_ut_stricmp(char *string1, char *string2);
199 204
200acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *ret_integer); 205/*
206 * utstrsuppt - string-to-integer conversion support functions
207 */
208acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value);
209
210acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr);
211
212acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr);
213
214char acpi_ut_remove_whitespace(char **string);
215
216char acpi_ut_remove_leading_zeros(char **string);
217
218u8 acpi_ut_detect_hex_prefix(char **string);
219
220u8 acpi_ut_detect_octal_prefix(char **string);
201 221
202/* 222/*
203 * Values for Flags above 223 * utstrtoul64 - string-to-integer conversion functions
204 * Note: LIMIT values correspond to acpi_gbl_integer_byte_width values (4/8)
205 */ 224 */
206#define ACPI_STRTOUL_32BIT 0x04 /* 4 bytes */ 225acpi_status acpi_ut_strtoul64(char *string, u64 *ret_integer);
207#define ACPI_STRTOUL_64BIT 0x08 /* 8 bytes */ 226
208#define ACPI_STRTOUL_BASE16 0x10 /* Default: Base10/16 */ 227u64 acpi_ut_explicit_strtoul64(char *string);
228
229u64 acpi_ut_implicit_strtoul64(char *string);
209 230
210/* 231/*
211 * utglobal - Global data structures and procedures 232 * utglobal - Global data structures and procedures
diff --git a/drivers/acpi/acpica/dbconvert.c b/drivers/acpi/acpica/dbconvert.c
index 857dbc43a9b1..32d546f0db2f 100644
--- a/drivers/acpi/acpica/dbconvert.c
+++ b/drivers/acpi/acpica/dbconvert.c
@@ -277,10 +277,7 @@ acpi_db_convert_to_object(acpi_object_type type,
277 default: 277 default:
278 278
279 object->type = ACPI_TYPE_INTEGER; 279 object->type = ACPI_TYPE_INTEGER;
280 status = acpi_ut_strtoul64(string, 280 status = acpi_ut_strtoul64(string, &object->integer.value);
281 (acpi_gbl_integer_byte_width |
282 ACPI_STRTOUL_BASE16),
283 &object->integer.value);
284 break; 281 break;
285 } 282 }
286 283
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index 20d7744b06ae..22f45d090733 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -134,7 +134,7 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
134 * object. Implicitly convert the argument if necessary. 134 * object. Implicitly convert the argument if necessary.
135 */ 135 */
136 status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc, 136 status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc,
137 ACPI_STRTOUL_BASE16); 137 ACPI_IMPLICIT_CONVERSION);
138 if (ACPI_FAILURE(status)) { 138 if (ACPI_FAILURE(status)) {
139 goto cleanup; 139 goto cleanup;
140 } 140 }
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index 229382035550..263d8fc4a9e2 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -390,8 +390,8 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list)
390 struct acpi_gpe_handler_info *gpe_handler_info; 390 struct acpi_gpe_handler_info *gpe_handler_info;
391 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; 391 u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
392 u8 enabled_status_byte; 392 u8 enabled_status_byte;
393 u32 status_reg; 393 u64 status_reg;
394 u32 enable_reg; 394 u64 enable_reg;
395 acpi_cpu_flags flags; 395 acpi_cpu_flags flags;
396 u32 i; 396 u32 i;
397 u32 j; 397 u32 j;
@@ -472,7 +472,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list)
472 gpe_register_info->base_gpe_number, 472 gpe_register_info->base_gpe_number,
473 gpe_register_info->base_gpe_number + 473 gpe_register_info->base_gpe_number +
474 (ACPI_GPE_REGISTER_WIDTH - 1), 474 (ACPI_GPE_REGISTER_WIDTH - 1),
475 status_reg, enable_reg, 475 (u32)status_reg, (u32)enable_reg,
476 gpe_register_info->enable_for_run, 476 gpe_register_info->enable_for_run,
477 gpe_register_info->enable_for_wake)); 477 gpe_register_info->enable_for_wake));
478 478
diff --git a/drivers/acpi/acpica/exconcat.c b/drivers/acpi/acpica/exconcat.c
index 76bfb7dcae2f..59b8de2f07d3 100644
--- a/drivers/acpi/acpica/exconcat.c
+++ b/drivers/acpi/acpica/exconcat.c
@@ -156,7 +156,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
156 156
157 status = 157 status =
158 acpi_ex_convert_to_integer(local_operand1, &temp_operand1, 158 acpi_ex_convert_to_integer(local_operand1, &temp_operand1,
159 ACPI_STRTOUL_BASE16); 159 ACPI_IMPLICIT_CONVERSION);
160 break; 160 break;
161 161
162 case ACPI_TYPE_BUFFER: 162 case ACPI_TYPE_BUFFER:
diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
index f71028e334ee..23ebadb06a95 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -57,10 +57,10 @@ acpi_ex_convert_to_ascii(u64 integer, u16 base, u8 *string, u8 max_length);
57 * 57 *
58 * FUNCTION: acpi_ex_convert_to_integer 58 * FUNCTION: acpi_ex_convert_to_integer
59 * 59 *
60 * PARAMETERS: obj_desc - Object to be converted. Must be an 60 * PARAMETERS: obj_desc - Object to be converted. Must be an
61 * Integer, Buffer, or String 61 * Integer, Buffer, or String
62 * result_desc - Where the new Integer object is returned 62 * result_desc - Where the new Integer object is returned
63 * flags - Used for string conversion 63 * implicit_conversion - Used for string conversion
64 * 64 *
65 * RETURN: Status 65 * RETURN: Status
66 * 66 *
@@ -70,14 +70,14 @@ acpi_ex_convert_to_ascii(u64 integer, u16 base, u8 *string, u8 max_length);
70 70
71acpi_status 71acpi_status
72acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc, 72acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
73 union acpi_operand_object **result_desc, u32 flags) 73 union acpi_operand_object **result_desc,
74 u32 implicit_conversion)
74{ 75{
75 union acpi_operand_object *return_desc; 76 union acpi_operand_object *return_desc;
76 u8 *pointer; 77 u8 *pointer;
77 u64 result; 78 u64 result;
78 u32 i; 79 u32 i;
79 u32 count; 80 u32 count;
80 acpi_status status;
81 81
82 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc); 82 ACPI_FUNCTION_TRACE_PTR(ex_convert_to_integer, obj_desc);
83 83
@@ -123,12 +123,18 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
123 * hexadecimal as per the ACPI specification. The only exception (as 123 * hexadecimal as per the ACPI specification. The only exception (as
124 * of ACPI 3.0) is that the to_integer() operator allows both decimal 124 * of ACPI 3.0) is that the to_integer() operator allows both decimal
125 * and hexadecimal strings (hex prefixed with "0x"). 125 * and hexadecimal strings (hex prefixed with "0x").
126 *
127 * Explicit conversion is used only by to_integer.
128 * All other string-to-integer conversions are implicit conversions.
126 */ 129 */
127 status = acpi_ut_strtoul64(ACPI_CAST_PTR(char, pointer), 130 if (implicit_conversion) {
128 (acpi_gbl_integer_byte_width | 131 result =
129 flags), &result); 132 acpi_ut_implicit_strtoul64(ACPI_CAST_PTR
130 if (ACPI_FAILURE(status)) { 133 (char, pointer));
131 return_ACPI_STATUS(status); 134 } else {
135 result =
136 acpi_ut_explicit_strtoul64(ACPI_CAST_PTR
137 (char, pointer));
132 } 138 }
133 break; 139 break;
134 140
@@ -631,7 +637,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
631 */ 637 */
632 status = 638 status =
633 acpi_ex_convert_to_integer(source_desc, result_desc, 639 acpi_ex_convert_to_integer(source_desc, result_desc,
634 ACPI_STRTOUL_BASE16); 640 ACPI_IMPLICIT_CONVERSION);
635 break; 641 break;
636 642
637 case ACPI_TYPE_STRING: 643 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 1e7649ce0a7b..dbad3ebd7df5 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -330,7 +330,7 @@ acpi_ex_do_logical_op(u16 opcode,
330 case ACPI_TYPE_INTEGER: 330 case ACPI_TYPE_INTEGER:
331 331
332 status = acpi_ex_convert_to_integer(operand1, &local_operand1, 332 status = acpi_ex_convert_to_integer(operand1, &local_operand1,
333 ACPI_STRTOUL_BASE16); 333 ACPI_IMPLICIT_CONVERSION);
334 break; 334 break;
335 335
336 case ACPI_TYPE_STRING: 336 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index c4852429e2ff..1c7c9962b0de 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -415,7 +415,7 @@ acpi_ex_resolve_operands(u16 opcode,
415 * Known as "Implicit Source Operand Conversion" 415 * Known as "Implicit Source Operand Conversion"
416 */ 416 */
417 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr, 417 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr,
418 ACPI_STRTOUL_BASE16); 418 ACPI_IMPLICIT_CONVERSION);
419 if (ACPI_FAILURE(status)) { 419 if (ACPI_FAILURE(status)) {
420 if (status == AE_TYPE) { 420 if (status == AE_TYPE) {
421 ACPI_ERROR((AE_INFO, 421 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/hwgpe.c b/drivers/acpi/acpica/hwgpe.c
index 5eb11b30a79e..09b6822aa5cc 100644
--- a/drivers/acpi/acpica/hwgpe.c
+++ b/drivers/acpi/acpica/hwgpe.c
@@ -99,7 +99,7 @@ acpi_hw_low_set_gpe(struct acpi_gpe_event_info *gpe_event_info, u32 action)
99{ 99{
100 struct acpi_gpe_register_info *gpe_register_info; 100 struct acpi_gpe_register_info *gpe_register_info;
101 acpi_status status = AE_OK; 101 acpi_status status = AE_OK;
102 u32 enable_mask; 102 u64 enable_mask;
103 u32 register_bit; 103 u32 register_bit;
104 104
105 ACPI_FUNCTION_ENTRY(); 105 ACPI_FUNCTION_ENTRY();
@@ -214,7 +214,7 @@ acpi_status
214acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info, 214acpi_hw_get_gpe_status(struct acpi_gpe_event_info *gpe_event_info,
215 acpi_event_status *event_status) 215 acpi_event_status *event_status)
216{ 216{
217 u32 in_byte; 217 u64 in_byte;
218 u32 register_bit; 218 u32 register_bit;
219 struct acpi_gpe_register_info *gpe_register_info; 219 struct acpi_gpe_register_info *gpe_register_info;
220 acpi_event_status local_event_status = 0; 220 acpi_event_status local_event_status = 0;
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index acb417b58bbb..aa6e00081915 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -220,16 +220,15 @@ acpi_hw_validate_register(struct acpi_generic_address *reg,
220 * 220 *
221 * RETURN: Status 221 * RETURN: Status
222 * 222 *
223 * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max 223 * DESCRIPTION: Read from either memory or IO space. This is a 64-bit max
224 * version of acpi_read, used internally since the overhead of 224 * version of acpi_read.
225 * 64-bit values is not needed.
226 * 225 *
227 * LIMITATIONS: <These limitations also apply to acpi_hw_write> 226 * LIMITATIONS: <These limitations also apply to acpi_hw_write>
228 * space_ID must be system_memory or system_IO. 227 * space_ID must be system_memory or system_IO.
229 * 228 *
230 ******************************************************************************/ 229 ******************************************************************************/
231 230
232acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg) 231acpi_status acpi_hw_read(u64 *value, struct acpi_generic_address *reg)
233{ 232{
234 u64 address; 233 u64 address;
235 u8 access_width; 234 u8 access_width;
@@ -244,17 +243,17 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
244 243
245 /* Validate contents of the GAS register */ 244 /* Validate contents of the GAS register */
246 245
247 status = acpi_hw_validate_register(reg, 32, &address); 246 status = acpi_hw_validate_register(reg, 64, &address);
248 if (ACPI_FAILURE(status)) { 247 if (ACPI_FAILURE(status)) {
249 return (status); 248 return (status);
250 } 249 }
251 250
252 /* 251 /*
253 * Initialize entire 32-bit return value to zero, convert access_width 252 * Initialize entire 64-bit return value to zero, convert access_width
254 * into number of bits based 253 * into number of bits based
255 */ 254 */
256 *value = 0; 255 *value = 0;
257 access_width = acpi_hw_get_access_bit_width(address, reg, 32); 256 access_width = acpi_hw_get_access_bit_width(address, reg, 64);
258 bit_width = reg->bit_offset + reg->bit_width; 257 bit_width = reg->bit_offset + reg->bit_width;
259 bit_offset = reg->bit_offset; 258 bit_offset = reg->bit_offset;
260 259
@@ -265,7 +264,7 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
265 index = 0; 264 index = 0;
266 while (bit_width) { 265 while (bit_width) {
267 if (bit_offset >= access_width) { 266 if (bit_offset >= access_width) {
268 value32 = 0; 267 value64 = 0;
269 bit_offset -= access_width; 268 bit_offset -= access_width;
270 } else { 269 } else {
271 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 270 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
@@ -276,7 +275,6 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
276 ACPI_DIV_8 275 ACPI_DIV_8
277 (access_width), 276 (access_width),
278 &value64, access_width); 277 &value64, access_width);
279 value32 = (u32)value64;
280 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */ 278 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
281 279
282 status = acpi_hw_read_port((acpi_io_address) 280 status = acpi_hw_read_port((acpi_io_address)
@@ -286,15 +284,16 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
286 (access_width), 284 (access_width),
287 &value32, 285 &value32,
288 access_width); 286 access_width);
287 value64 = (u64)value32;
289 } 288 }
290 } 289 }
291 290
292 /* 291 /*
293 * Use offset style bit writes because "Index * AccessWidth" is 292 * Use offset style bit writes because "Index * AccessWidth" is
294 * ensured to be less than 32-bits by acpi_hw_validate_register(). 293 * ensured to be less than 64-bits by acpi_hw_validate_register().
295 */ 294 */
296 ACPI_SET_BITS(value, index * access_width, 295 ACPI_SET_BITS(value, index * access_width,
297 ACPI_MASK_BITS_ABOVE_32(access_width), value32); 296 ACPI_MASK_BITS_ABOVE_64(access_width), value64);
298 297
299 bit_width -= 298 bit_width -=
300 bit_width > access_width ? access_width : bit_width; 299 bit_width > access_width ? access_width : bit_width;
@@ -302,8 +301,9 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
302 } 301 }
303 302
304 ACPI_DEBUG_PRINT((ACPI_DB_IO, 303 ACPI_DEBUG_PRINT((ACPI_DB_IO,
305 "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n", 304 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
306 *value, access_width, ACPI_FORMAT_UINT64(address), 305 ACPI_FORMAT_UINT64(*value), access_width,
306 ACPI_FORMAT_UINT64(address),
307 acpi_ut_get_region_name(reg->space_id))); 307 acpi_ut_get_region_name(reg->space_id)));
308 308
309 return (status); 309 return (status);
@@ -318,20 +318,18 @@ acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
318 * 318 *
319 * RETURN: Status 319 * RETURN: Status
320 * 320 *
321 * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max 321 * DESCRIPTION: Write to either memory or IO space. This is a 64-bit max
322 * version of acpi_write, used internally since the overhead of 322 * version of acpi_write.
323 * 64-bit values is not needed.
324 * 323 *
325 ******************************************************************************/ 324 ******************************************************************************/
326 325
327acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg) 326acpi_status acpi_hw_write(u64 value, struct acpi_generic_address *reg)
328{ 327{
329 u64 address; 328 u64 address;
330 u8 access_width; 329 u8 access_width;
331 u32 bit_width; 330 u32 bit_width;
332 u8 bit_offset; 331 u8 bit_offset;
333 u64 value64; 332 u64 value64;
334 u32 value32;
335 u8 index; 333 u8 index;
336 acpi_status status; 334 acpi_status status;
337 335
@@ -339,14 +337,14 @@ acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
339 337
340 /* Validate contents of the GAS register */ 338 /* Validate contents of the GAS register */
341 339
342 status = acpi_hw_validate_register(reg, 32, &address); 340 status = acpi_hw_validate_register(reg, 64, &address);
343 if (ACPI_FAILURE(status)) { 341 if (ACPI_FAILURE(status)) {
344 return (status); 342 return (status);
345 } 343 }
346 344
347 /* Convert access_width into number of bits based */ 345 /* Convert access_width into number of bits based */
348 346
349 access_width = acpi_hw_get_access_bit_width(address, reg, 32); 347 access_width = acpi_hw_get_access_bit_width(address, reg, 64);
350 bit_width = reg->bit_offset + reg->bit_width; 348 bit_width = reg->bit_offset + reg->bit_width;
351 bit_offset = reg->bit_offset; 349 bit_offset = reg->bit_offset;
352 350
@@ -358,16 +356,15 @@ acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
358 while (bit_width) { 356 while (bit_width) {
359 /* 357 /*
360 * Use offset style bit reads because "Index * AccessWidth" is 358 * Use offset style bit reads because "Index * AccessWidth" is
361 * ensured to be less than 32-bits by acpi_hw_validate_register(). 359 * ensured to be less than 64-bits by acpi_hw_validate_register().
362 */ 360 */
363 value32 = ACPI_GET_BITS(&value, index * access_width, 361 value64 = ACPI_GET_BITS(&value, index * access_width,
364 ACPI_MASK_BITS_ABOVE_32(access_width)); 362 ACPI_MASK_BITS_ABOVE_64(access_width));
365 363
366 if (bit_offset >= access_width) { 364 if (bit_offset >= access_width) {
367 bit_offset -= access_width; 365 bit_offset -= access_width;
368 } else { 366 } else {
369 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 367 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
370 value64 = (u64)value32;
371 status = 368 status =
372 acpi_os_write_memory((acpi_physical_address) 369 acpi_os_write_memory((acpi_physical_address)
373 address + 370 address +
@@ -382,7 +379,7 @@ acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
382 index * 379 index *
383 ACPI_DIV_8 380 ACPI_DIV_8
384 (access_width), 381 (access_width),
385 value32, 382 (u32)value64,
386 access_width); 383 access_width);
387 } 384 }
388 } 385 }
@@ -397,8 +394,9 @@ acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
397 } 394 }
398 395
399 ACPI_DEBUG_PRINT((ACPI_DB_IO, 396 ACPI_DEBUG_PRINT((ACPI_DB_IO,
400 "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n", 397 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
401 value, access_width, ACPI_FORMAT_UINT64(address), 398 ACPI_FORMAT_UINT64(value), access_width,
399 ACPI_FORMAT_UINT64(address),
402 acpi_ut_get_region_name(reg->space_id))); 400 acpi_ut_get_region_name(reg->space_id)));
403 401
404 return (status); 402 return (status);
@@ -526,6 +524,7 @@ acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
526acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value) 524acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
527{ 525{
528 u32 value = 0; 526 u32 value = 0;
527 u64 value64;
529 acpi_status status; 528 acpi_status status;
530 529
531 ACPI_FUNCTION_TRACE(hw_register_read); 530 ACPI_FUNCTION_TRACE(hw_register_read);
@@ -564,12 +563,14 @@ acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
564 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */ 563 case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
565 564
566 status = 565 status =
567 acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block); 566 acpi_hw_read(&value64, &acpi_gbl_FADT.xpm2_control_block);
567 value = (u32)value64;
568 break; 568 break;
569 569
570 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */ 570 case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
571 571
572 status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block); 572 status = acpi_hw_read(&value64, &acpi_gbl_FADT.xpm_timer_block);
573 value = (u32)value64;
573 break; 574 break;
574 575
575 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */ 576 case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
@@ -586,7 +587,7 @@ acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
586 } 587 }
587 588
588 if (ACPI_SUCCESS(status)) { 589 if (ACPI_SUCCESS(status)) {
589 *return_value = value; 590 *return_value = (u32)value;
590 } 591 }
591 592
592 return_ACPI_STATUS(status); 593 return_ACPI_STATUS(status);
@@ -622,6 +623,7 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
622{ 623{
623 acpi_status status; 624 acpi_status status;
624 u32 read_value; 625 u32 read_value;
626 u64 read_value64;
625 627
626 ACPI_FUNCTION_TRACE(hw_register_write); 628 ACPI_FUNCTION_TRACE(hw_register_write);
627 629
@@ -685,11 +687,12 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
685 * as per the ACPI spec. 687 * as per the ACPI spec.
686 */ 688 */
687 status = 689 status =
688 acpi_hw_read(&read_value, 690 acpi_hw_read(&read_value64,
689 &acpi_gbl_FADT.xpm2_control_block); 691 &acpi_gbl_FADT.xpm2_control_block);
690 if (ACPI_FAILURE(status)) { 692 if (ACPI_FAILURE(status)) {
691 goto exit; 693 goto exit;
692 } 694 }
695 read_value = (u32)read_value64;
693 696
694 /* Insert the bits to be preserved */ 697 /* Insert the bits to be preserved */
695 698
@@ -745,22 +748,25 @@ acpi_hw_read_multiple(u32 *value,
745{ 748{
746 u32 value_a = 0; 749 u32 value_a = 0;
747 u32 value_b = 0; 750 u32 value_b = 0;
751 u64 value64;
748 acpi_status status; 752 acpi_status status;
749 753
750 /* The first register is always required */ 754 /* The first register is always required */
751 755
752 status = acpi_hw_read(&value_a, register_a); 756 status = acpi_hw_read(&value64, register_a);
753 if (ACPI_FAILURE(status)) { 757 if (ACPI_FAILURE(status)) {
754 return (status); 758 return (status);
755 } 759 }
760 value_a = (u32)value64;
756 761
757 /* Second register is optional */ 762 /* Second register is optional */
758 763
759 if (register_b->address) { 764 if (register_b->address) {
760 status = acpi_hw_read(&value_b, register_b); 765 status = acpi_hw_read(&value64, register_b);
761 if (ACPI_FAILURE(status)) { 766 if (ACPI_FAILURE(status)) {
762 return (status); 767 return (status);
763 } 768 }
769 value_b = (u32)value64;
764 } 770 }
765 771
766 /* 772 /*
diff --git a/drivers/acpi/acpica/hwtimer.c b/drivers/acpi/acpica/hwtimer.c
index b3c5d8c754bb..a2f4e25d45b1 100644
--- a/drivers/acpi/acpica/hwtimer.c
+++ b/drivers/acpi/acpica/hwtimer.c
@@ -94,6 +94,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_timer_resolution)
94acpi_status acpi_get_timer(u32 * ticks) 94acpi_status acpi_get_timer(u32 * ticks)
95{ 95{
96 acpi_status status; 96 acpi_status status;
97 u64 timer_value;
97 98
98 ACPI_FUNCTION_TRACE(acpi_get_timer); 99 ACPI_FUNCTION_TRACE(acpi_get_timer);
99 100
@@ -107,7 +108,14 @@ acpi_status acpi_get_timer(u32 * ticks)
107 return_ACPI_STATUS(AE_SUPPORT); 108 return_ACPI_STATUS(AE_SUPPORT);
108 } 109 }
109 110
110 status = acpi_hw_read(ticks, &acpi_gbl_FADT.xpm_timer_block); 111 status = acpi_hw_read(&timer_value, &acpi_gbl_FADT.xpm_timer_block);
112 if (ACPI_SUCCESS(status)) {
113
114 /* ACPI PM Timer is defined to be 32 bits (PM_TMR_LEN) */
115
116 *ticks = (u32)timer_value;
117 }
118
111 return_ACPI_STATUS(status); 119 return_ACPI_STATUS(status);
112} 120}
113 121
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index 34684ae89981..b3c6e439933c 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -125,76 +125,12 @@ ACPI_EXPORT_SYMBOL(acpi_reset)
125 ******************************************************************************/ 125 ******************************************************************************/
126acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg) 126acpi_status acpi_read(u64 *return_value, struct acpi_generic_address *reg)
127{ 127{
128 u32 value_lo;
129 u32 value_hi;
130 u32 width;
131 u64 address;
132 acpi_status status; 128 acpi_status status;
133 129
134 ACPI_FUNCTION_NAME(acpi_read); 130 ACPI_FUNCTION_NAME(acpi_read);
135 131
136 if (!return_value) { 132 status = acpi_hw_read(return_value, reg);
137 return (AE_BAD_PARAMETER); 133 return (status);
138 }
139
140 /* Validate contents of the GAS register. Allow 64-bit transfers */
141
142 status = acpi_hw_validate_register(reg, 64, &address);
143 if (ACPI_FAILURE(status)) {
144 return (status);
145 }
146
147 /*
148 * Two address spaces supported: Memory or I/O. PCI_Config is
149 * not supported here because the GAS structure is insufficient
150 */
151 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
152 status = acpi_os_read_memory((acpi_physical_address)
153 address, return_value,
154 reg->bit_width);
155 if (ACPI_FAILURE(status)) {
156 return (status);
157 }
158 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
159
160 value_lo = 0;
161 value_hi = 0;
162
163 width = reg->bit_width;
164 if (width == 64) {
165 width = 32; /* Break into two 32-bit transfers */
166 }
167
168 status = acpi_hw_read_port((acpi_io_address)
169 address, &value_lo, width);
170 if (ACPI_FAILURE(status)) {
171 return (status);
172 }
173
174 if (reg->bit_width == 64) {
175
176 /* Read the top 32 bits */
177
178 status = acpi_hw_read_port((acpi_io_address)
179 (address + 4), &value_hi,
180 32);
181 if (ACPI_FAILURE(status)) {
182 return (status);
183 }
184 }
185
186 /* Set the return value only if status is AE_OK */
187
188 *return_value = (value_lo | ((u64)value_hi << 32));
189 }
190
191 ACPI_DEBUG_PRINT((ACPI_DB_IO,
192 "Read: %8.8X%8.8X width %2d from %8.8X%8.8X (%s)\n",
193 ACPI_FORMAT_UINT64(*return_value), reg->bit_width,
194 ACPI_FORMAT_UINT64(address),
195 acpi_ut_get_region_name(reg->space_id)));
196
197 return (AE_OK);
198} 134}
199 135
200ACPI_EXPORT_SYMBOL(acpi_read) 136ACPI_EXPORT_SYMBOL(acpi_read)
@@ -213,59 +149,11 @@ ACPI_EXPORT_SYMBOL(acpi_read)
213 ******************************************************************************/ 149 ******************************************************************************/
214acpi_status acpi_write(u64 value, struct acpi_generic_address *reg) 150acpi_status acpi_write(u64 value, struct acpi_generic_address *reg)
215{ 151{
216 u32 width;
217 u64 address;
218 acpi_status status; 152 acpi_status status;
219 153
220 ACPI_FUNCTION_NAME(acpi_write); 154 ACPI_FUNCTION_NAME(acpi_write);
221 155
222 /* Validate contents of the GAS register. Allow 64-bit transfers */ 156 status = acpi_hw_write(value, reg);
223
224 status = acpi_hw_validate_register(reg, 64, &address);
225 if (ACPI_FAILURE(status)) {
226 return (status);
227 }
228
229 /*
230 * Two address spaces supported: Memory or IO. PCI_Config is
231 * not supported here because the GAS structure is insufficient
232 */
233 if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
234 status = acpi_os_write_memory((acpi_physical_address)
235 address, value, reg->bit_width);
236 if (ACPI_FAILURE(status)) {
237 return (status);
238 }
239 } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
240
241 width = reg->bit_width;
242 if (width == 64) {
243 width = 32; /* Break into two 32-bit transfers */
244 }
245
246 status = acpi_hw_write_port((acpi_io_address)
247 address, ACPI_LODWORD(value),
248 width);
249 if (ACPI_FAILURE(status)) {
250 return (status);
251 }
252
253 if (reg->bit_width == 64) {
254 status = acpi_hw_write_port((acpi_io_address)
255 (address + 4),
256 ACPI_HIDWORD(value), 32);
257 if (ACPI_FAILURE(status)) {
258 return (status);
259 }
260 }
261 }
262
263 ACPI_DEBUG_PRINT((ACPI_DB_IO,
264 "Wrote: %8.8X%8.8X width %2d to %8.8X%8.8X (%s)\n",
265 ACPI_FORMAT_UINT64(value), reg->bit_width,
266 ACPI_FORMAT_UINT64(address),
267 acpi_ut_get_region_name(reg->space_id)));
268
269 return (status); 157 return (status);
270} 158}
271 159
diff --git a/drivers/acpi/acpica/nsconvert.c b/drivers/acpi/acpica/nsconvert.c
index e4a7da8a11f0..539d775bbc92 100644
--- a/drivers/acpi/acpica/nsconvert.c
+++ b/drivers/acpi/acpica/nsconvert.c
@@ -78,8 +78,8 @@ acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
78 78
79 /* String-to-Integer conversion */ 79 /* String-to-Integer conversion */
80 80
81 status = acpi_ut_strtoul64(original_object->string.pointer, 81 status =
82 acpi_gbl_integer_byte_width, &value); 82 acpi_ut_strtoul64(original_object->string.pointer, &value);
83 if (ACPI_FAILURE(status)) { 83 if (ACPI_FAILURE(status)) {
84 return (status); 84 return (status);
85 } 85 }
diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c
index 26ad596c973e..5ecb8d2e6834 100644
--- a/drivers/acpi/acpica/tbxface.c
+++ b/drivers/acpi/acpica/tbxface.c
@@ -173,10 +173,13 @@ acpi_status ACPI_INIT_FUNCTION acpi_reallocate_root_table(void)
173 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table); 173 ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
174 174
175 /* 175 /*
176 * Only reallocate the root table if the host provided a static buffer 176 * If there are tables unverified, it is required to reallocate the
177 * for the table array in the call to acpi_initialize_tables. 177 * root table list to clean up invalid table entries. Otherwise only
178 * reallocate the root table list if the host provided a static buffer
179 * for the table array in the call to acpi_initialize_tables().
178 */ 180 */
179 if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { 181 if ((acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) &&
182 acpi_gbl_enable_table_validation) {
180 return_ACPI_STATUS(AE_SUPPORT); 183 return_ACPI_STATUS(AE_SUPPORT);
181 } 184 }
182 185
diff --git a/drivers/acpi/acpica/utstrsuppt.c b/drivers/acpi/acpica/utstrsuppt.c
new file mode 100644
index 000000000000..965fb5cec94f
--- /dev/null
+++ b/drivers/acpi/acpica/utstrsuppt.c
@@ -0,0 +1,438 @@
1/*******************************************************************************
2 *
3 * Module Name: utstrsuppt - Support functions for string-to-integer conversion
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2017, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46
47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utstrsuppt")
49
50/* Local prototypes */
51static acpi_status
52acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit);
53
54static acpi_status
55acpi_ut_strtoul_multiply64(u64 multiplicand, u64 multiplier, u64 *out_product);
56
57static acpi_status
58acpi_ut_strtoul_add64(u64 addend1, u64 addend2, u64 *out_sum);
59
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_ut_convert_octal_string
63 *
64 * PARAMETERS: string - Null terminated input string
65 * return_value_ptr - Where the converted value is returned
66 *
67 * RETURN: Status and 64-bit converted integer
68 *
69 * DESCRIPTION: Performs a base 8 conversion of the input string to an
70 * integer value, either 32 or 64 bits.
71 *
72 * NOTE: Maximum 64-bit unsigned octal value is 01777777777777777777777
73 * Maximum 32-bit unsigned octal value is 037777777777
74 *
75 ******************************************************************************/
76
77acpi_status acpi_ut_convert_octal_string(char *string, u64 *return_value_ptr)
78{
79 u64 accumulated_value = 0;
80 acpi_status status = AE_OK;
81
82 /* Convert each ASCII byte in the input string */
83
84 while (*string) {
85
86 /* Character must be ASCII 0-7, otherwise terminate with no error */
87
88 if (!(ACPI_IS_OCTAL_DIGIT(*string))) {
89 break;
90 }
91
92 /* Convert and insert this octal digit into the accumulator */
93
94 status = acpi_ut_insert_digit(&accumulated_value, 8, *string);
95 if (ACPI_FAILURE(status)) {
96 status = AE_OCTAL_OVERFLOW;
97 break;
98 }
99
100 string++;
101 }
102
103 /* Always return the value that has been accumulated */
104
105 *return_value_ptr = accumulated_value;
106 return (status);
107}
108
109/*******************************************************************************
110 *
111 * FUNCTION: acpi_ut_convert_decimal_string
112 *
113 * PARAMETERS: string - Null terminated input string
114 * return_value_ptr - Where the converted value is returned
115 *
116 * RETURN: Status and 64-bit converted integer
117 *
118 * DESCRIPTION: Performs a base 10 conversion of the input string to an
119 * integer value, either 32 or 64 bits.
120 *
121 * NOTE: Maximum 64-bit unsigned decimal value is 18446744073709551615
122 * Maximum 32-bit unsigned decimal value is 4294967295
123 *
124 ******************************************************************************/
125
126acpi_status acpi_ut_convert_decimal_string(char *string, u64 *return_value_ptr)
127{
128 u64 accumulated_value = 0;
129 acpi_status status = AE_OK;
130
131 /* Convert each ASCII byte in the input string */
132
133 while (*string) {
134
135 /* Character must be ASCII 0-9, otherwise terminate with no error */
136
137 if (!isdigit(*string)) {
138 break;
139 }
140
141 /* Convert and insert this decimal digit into the accumulator */
142
143 status = acpi_ut_insert_digit(&accumulated_value, 10, *string);
144 if (ACPI_FAILURE(status)) {
145 status = AE_DECIMAL_OVERFLOW;
146 break;
147 }
148
149 string++;
150 }
151
152 /* Always return the value that has been accumulated */
153
154 *return_value_ptr = accumulated_value;
155 return (status);
156}
157
158/*******************************************************************************
159 *
160 * FUNCTION: acpi_ut_convert_hex_string
161 *
162 * PARAMETERS: string - Null terminated input string
163 * return_value_ptr - Where the converted value is returned
164 *
165 * RETURN: Status and 64-bit converted integer
166 *
167 * DESCRIPTION: Performs a base 16 conversion of the input string to an
168 * integer value, either 32 or 64 bits.
169 *
170 * NOTE: Maximum 64-bit unsigned hex value is 0xFFFFFFFFFFFFFFFF
171 * Maximum 32-bit unsigned hex value is 0xFFFFFFFF
172 *
173 ******************************************************************************/
174
175acpi_status acpi_ut_convert_hex_string(char *string, u64 *return_value_ptr)
176{
177 u64 accumulated_value = 0;
178 acpi_status status = AE_OK;
179
180 /* Convert each ASCII byte in the input string */
181
182 while (*string) {
183
184 /* Must be ASCII A-F, a-f, or 0-9, otherwise terminate with no error */
185
186 if (!isxdigit(*string)) {
187 break;
188 }
189
190 /* Convert and insert this hex digit into the accumulator */
191
192 status = acpi_ut_insert_digit(&accumulated_value, 16, *string);
193 if (ACPI_FAILURE(status)) {
194 status = AE_HEX_OVERFLOW;
195 break;
196 }
197
198 string++;
199 }
200
201 /* Always return the value that has been accumulated */
202
203 *return_value_ptr = accumulated_value;
204 return (status);
205}
206
207/*******************************************************************************
208 *
209 * FUNCTION: acpi_ut_remove_leading_zeros
210 *
211 * PARAMETERS: string - Pointer to input ASCII string
212 *
213 * RETURN: Next character after any leading zeros. This character may be
214 * used by the caller to detect end-of-string.
215 *
216 * DESCRIPTION: Remove any leading zeros in the input string. Return the
217 * next character after the final ASCII zero to enable the caller
218 * to check for the end of the string (NULL terminator).
219 *
220 ******************************************************************************/
221
222char acpi_ut_remove_leading_zeros(char **string)
223{
224
225 while (**string == ACPI_ASCII_ZERO) {
226 *string += 1;
227 }
228
229 return (**string);
230}
231
232/*******************************************************************************
233 *
234 * FUNCTION: acpi_ut_remove_whitespace
235 *
236 * PARAMETERS: string - Pointer to input ASCII string
237 *
238 * RETURN: Next character after any whitespace. This character may be
239 * used by the caller to detect end-of-string.
240 *
241 * DESCRIPTION: Remove any leading whitespace in the input string. Return the
242 * next character after the final ASCII zero to enable the caller
243 * to check for the end of the string (NULL terminator).
244 *
245 ******************************************************************************/
246
247char acpi_ut_remove_whitespace(char **string)
248{
249
250 while (isspace((u8)**string)) {
251 *string += 1;
252 }
253
254 return (**string);
255}
256
257/*******************************************************************************
258 *
259 * FUNCTION: acpi_ut_detect_hex_prefix
260 *
261 * PARAMETERS: string - Pointer to input ASCII string
262 *
263 * RETURN: TRUE if a "0x" prefix was found at the start of the string
264 *
265 * DESCRIPTION: Detect and remove a hex "0x" prefix
266 *
267 ******************************************************************************/
268
269u8 acpi_ut_detect_hex_prefix(char **string)
270{
271
272 if ((**string == ACPI_ASCII_ZERO) &&
273 (tolower((int)*(*string + 1)) == 'x')) {
274 *string += 2; /* Go past the leading 0x */
275 return (TRUE);
276 }
277
278 return (FALSE); /* Not a hex string */
279}
280
281/*******************************************************************************
282 *
283 * FUNCTION: acpi_ut_detect_octal_prefix
284 *
285 * PARAMETERS: string - Pointer to input ASCII string
286 *
287 * RETURN: True if an octal "0" prefix was found at the start of the
288 * string
289 *
290 * DESCRIPTION: Detect and remove an octal prefix (zero)
291 *
292 ******************************************************************************/
293
294u8 acpi_ut_detect_octal_prefix(char **string)
295{
296
297 if (**string == ACPI_ASCII_ZERO) {
298 *string += 1; /* Go past the leading 0 */
299 return (TRUE);
300 }
301
302 return (FALSE); /* Not an octal string */
303}
304
305/*******************************************************************************
306 *
307 * FUNCTION: acpi_ut_insert_digit
308 *
309 * PARAMETERS: accumulated_value - Current value of the integer value
310 * accumulator. The new value is
311 * returned here.
312 * base - Radix, either 8/10/16
313 * ascii_digit - ASCII single digit to be inserted
314 *
315 * RETURN: Status and result of the convert/insert operation. The only
316 * possible returned exception code is numeric overflow of
317 * either the multiply or add conversion operations.
318 *
319 * DESCRIPTION: Generic conversion and insertion function for all bases:
320 *
321 * 1) Multiply the current accumulated/converted value by the
322 * base in order to make room for the new character.
323 *
324 * 2) Convert the new character to binary and add it to the
325 * current accumulated value.
326 *
327 * Note: The only possible exception indicates an integer
328 * overflow (AE_NUMERIC_OVERFLOW)
329 *
330 ******************************************************************************/
331
332static acpi_status
333acpi_ut_insert_digit(u64 *accumulated_value, u32 base, int ascii_digit)
334{
335 acpi_status status;
336 u64 product;
337
338 /* Make room in the accumulated value for the incoming digit */
339
340 status = acpi_ut_strtoul_multiply64(*accumulated_value, base, &product);
341 if (ACPI_FAILURE(status)) {
342 return (status);
343 }
344
345 /* Add in the new digit, and store the sum to the accumulated value */
346
347 status =
348 acpi_ut_strtoul_add64(product,
349 acpi_ut_ascii_char_to_hex(ascii_digit),
350 accumulated_value);
351
352 return (status);
353}
354
355/*******************************************************************************
356 *
357 * FUNCTION: acpi_ut_strtoul_multiply64
358 *
359 * PARAMETERS: multiplicand - Current accumulated converted integer
360 * multiplier - Base/Radix
361 * out_product - Where the product is returned
362 *
363 * RETURN: Status and 64-bit product
364 *
365 * DESCRIPTION: Multiply two 64-bit values, with checking for 64-bit overflow as
366 * well as 32-bit overflow if necessary (if the current global
367 * integer width is 32).
368 *
369 ******************************************************************************/
370
371static acpi_status
372acpi_ut_strtoul_multiply64(u64 multiplicand, u64 multiplier, u64 *out_product)
373{
374 u64 val;
375
376 /* Exit if either operand is zero */
377
378 *out_product = 0;
379 if (!multiplicand || !multiplier) {
380 return (AE_OK);
381 }
382
383 /* Check for 64-bit overflow before the actual multiplication */
384
385 acpi_ut_short_divide(ACPI_UINT64_MAX, (u32)multiplier, &val, NULL);
386 if (multiplicand > val) {
387 return (AE_NUMERIC_OVERFLOW);
388 }
389
390 val = multiplicand * multiplier;
391
392 /* Check for 32-bit overflow if necessary */
393
394 if ((acpi_gbl_integer_bit_width == 32) && (val > ACPI_UINT32_MAX)) {
395 return (AE_NUMERIC_OVERFLOW);
396 }
397
398 *out_product = val;
399 return (AE_OK);
400}
401
402/*******************************************************************************
403 *
404 * FUNCTION: acpi_ut_strtoul_add64
405 *
406 * PARAMETERS: addend1 - Current accumulated converted integer
407 * addend2 - New hex value/char
408 * out_sum - Where sum is returned (Accumulator)
409 *
410 * RETURN: Status and 64-bit sum
411 *
412 * DESCRIPTION: Add two 64-bit values, with checking for 64-bit overflow as
413 * well as 32-bit overflow if necessary (if the current global
414 * integer width is 32).
415 *
416 ******************************************************************************/
417
418static acpi_status acpi_ut_strtoul_add64(u64 addend1, u64 addend2, u64 *out_sum)
419{
420 u64 sum;
421
422 /* Check for 64-bit overflow before the actual addition */
423
424 if ((addend1 > 0) && (addend2 > (ACPI_UINT64_MAX - addend1))) {
425 return (AE_NUMERIC_OVERFLOW);
426 }
427
428 sum = addend1 + addend2;
429
430 /* Check for 32-bit overflow if necessary */
431
432 if ((acpi_gbl_integer_bit_width == 32) && (sum > ACPI_UINT32_MAX)) {
433 return (AE_NUMERIC_OVERFLOW);
434 }
435
436 *out_sum = sum;
437 return (AE_OK);
438}
diff --git a/drivers/acpi/acpica/utstrtoul64.c b/drivers/acpi/acpica/utstrtoul64.c
index 9633ee142855..e2067dcb9389 100644
--- a/drivers/acpi/acpica/utstrtoul64.c
+++ b/drivers/acpi/acpica/utstrtoul64.c
@@ -1,6 +1,7 @@
1/******************************************************************************* 1/*******************************************************************************
2 * 2 *
3 * Module Name: utstrtoul64 - string to 64-bit integer support 3 * Module Name: utstrtoul64 - String-to-integer conversion support for both
4 * 64-bit and 32-bit integers
4 * 5 *
5 ******************************************************************************/ 6 ******************************************************************************/
6 7
@@ -44,304 +45,319 @@
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46 47
47/*******************************************************************************
48 *
49 * The functions in this module satisfy the need for 64-bit string-to-integer
50 * conversions on both 32-bit and 64-bit platforms.
51 *
52 ******************************************************************************/
53
54#define _COMPONENT ACPI_UTILITIES 48#define _COMPONENT ACPI_UTILITIES
55ACPI_MODULE_NAME("utstrtoul64") 49ACPI_MODULE_NAME("utstrtoul64")
56 50
57/* Local prototypes */
58static u64 acpi_ut_strtoul_base10(char *string, u32 flags);
59
60static u64 acpi_ut_strtoul_base16(char *string, u32 flags);
61
62/******************************************************************************* 51/*******************************************************************************
63 * 52 *
64 * String conversion rules as written in the ACPI specification. The error 53 * This module contains the top-level string to 64/32-bit unsigned integer
65 * conditions and behavior are different depending on the type of conversion. 54 * conversion functions:
66 *
67 *
68 * Implicit data type conversion: string-to-integer
69 * --------------------------------------------------
70 *
71 * Base is always 16. This is the ACPI_STRTOUL_BASE16 case.
72 *
73 * Example:
74 * Add ("BA98", Arg0, Local0)
75 *
76 * The integer is initialized to the value zero.
77 * The ASCII string is interpreted as a hexadecimal constant.
78 * 55 *
79 * 1) A "0x" prefix is not allowed. However, ACPICA allows this for 56 * 1) A standard strtoul() function that supports 64-bit integers, base
80 * compatibility with previous ACPICA. (NO ERROR) 57 * 8/10/16, with integer overflow support. This is used mainly by the
58 * iASL compiler, which implements tighter constraints on integer
59 * constants than the runtime (interpreter) integer-to-string conversions.
60 * 2) Runtime "Explicit conversion" as defined in the ACPI specification.
61 * 3) Runtime "Implicit conversion" as defined in the ACPI specification.
81 * 62 *
82 * 2) Terminates when the size of an integer is reached (32 or 64 bits). 63 * Current users of this module:
83 * (NO ERROR)
84 * 64 *
85 * 3) The first non-hex character terminates the conversion without error. 65 * iASL - Preprocessor (constants and math expressions)
86 * (NO ERROR) 66 * iASL - Main parser, conversion of constants to integers
87 * 67 * iASL - Data Table Compiler parser (constants and math expressions)
88 * 4) Conversion of a null (zero-length) string to an integer is not 68 * interpreter - Implicit and explicit conversions, GPE method names
89 * allowed. However, ACPICA allows this for compatibility with previous 69 * interpreter - Repair code for return values from predefined names
90 * ACPICA. This conversion returns the value 0. (NO ERROR) 70 * debugger - Command line input string conversion
91 * 71 * acpi_dump - ACPI table physical addresses
92 * 72 * acpi_exec - Support for namespace overrides
93 * Explicit data type conversion: to_integer() with string operand
94 * ---------------------------------------------------------------
95 *
96 * Base is either 10 (default) or 16 (with 0x prefix)
97 *
98 * Examples:
99 * to_integer ("1000")
100 * to_integer ("0xABCD")
101 *
102 * 1) Can be (must be) either a decimal or hexadecimal numeric string.
103 * A hex value must be prefixed by "0x" or it is interpreted as a decimal.
104 * 73 *
105 * 2) The value must not exceed the maximum of an integer value. ACPI spec 74 * Notes concerning users of these interfaces:
106 * states the behavior is "unpredictable", so ACPICA matches the behavior
107 * of the implicit conversion case.(NO ERROR)
108 * 75 *
109 * 3) Behavior on the first non-hex character is not specified by the ACPI 76 * acpi_gbl_integer_byte_width is used to set the 32/64 bit limit for explicit
110 * spec, so ACPICA matches the behavior of the implicit conversion case 77 * and implicit conversions. This global must be set to the proper width.
111 * and terminates. (NO ERROR) 78 * For the core ACPICA code, the width depends on the DSDT version. For the
79 * acpi_ut_strtoul64 interface, all conversions are 64 bits. This interface is
80 * used primarily for iASL, where the default width is 64 bits for all parsers,
81 * but error checking is performed later to flag cases where a 64-bit constant
82 * is wrongly defined in a 32-bit DSDT/SSDT.
112 * 83 *
113 * 4) A null (zero-length) string is illegal. 84 * In ACPI, the only place where octal numbers are supported is within
114 * However, ACPICA allows this for compatibility with previous ACPICA. 85 * the ASL language itself. This is implemented via the main acpi_ut_strtoul64
115 * This conversion returns the value 0. (NO ERROR) 86 * interface. According the ACPI specification, there is no ACPI runtime
87 * support (explicit/implicit) for octal string conversions.
116 * 88 *
117 ******************************************************************************/ 89 ******************************************************************************/
118
119/******************************************************************************* 90/*******************************************************************************
120 * 91 *
121 * FUNCTION: acpi_ut_strtoul64 92 * FUNCTION: acpi_ut_strtoul64
122 * 93 *
123 * PARAMETERS: string - Null terminated input string 94 * PARAMETERS: string - Null terminated input string,
124 * flags - Conversion info, see below 95 * must be a valid pointer
125 * return_value - Where the converted integer is 96 * return_value - Where the converted integer is
126 * returned 97 * returned. Must be a valid pointer
127 *
128 * RETURN: Status and Converted value
129 * 98 *
130 * DESCRIPTION: Convert a string into an unsigned value. Performs either a 99 * RETURN: Status and converted integer. Returns an exception on a
131 * 32-bit or 64-bit conversion, depending on the input integer 100 * 64-bit numeric overflow
132 * size in Flags (often the current mode of the interpreter).
133 * 101 *
134 * Values for Flags: 102 * DESCRIPTION: Convert a string into an unsigned integer. Always performs a
135 * ACPI_STRTOUL_32BIT - Max integer value is 32 bits 103 * full 64-bit conversion, regardless of the current global
136 * ACPI_STRTOUL_64BIT - Max integer value is 64 bits 104 * integer width. Supports Decimal, Hex, and Octal strings.
137 * ACPI_STRTOUL_BASE16 - Input string is hexadecimal. Default
138 * is 10/16 based on string prefix (0x).
139 * 105 *
140 * NOTES: 106 * Current users of this function:
141 * Negative numbers are not supported, as they are not supported by ACPI.
142 * 107 *
143 * Supports only base 16 or base 10 strings/values. Does not 108 * iASL - Preprocessor (constants and math expressions)
144 * support Octal strings, as these are not supported by ACPI. 109 * iASL - Main ASL parser, conversion of ASL constants to integers
145 * 110 * iASL - Data Table Compiler parser (constants and math expressions)
146 * Current users of this support: 111 * interpreter - Repair code for return values from predefined names
147 * 112 * acpi_dump - ACPI table physical addresses
148 * interpreter - Implicit and explicit conversions, GPE method names 113 * acpi_exec - Support for namespace overrides
149 * debugger - Command line input string conversion
150 * iASL - Main parser, conversion of constants to integers
151 * iASL - Data Table Compiler parser (constant math expressions)
152 * iASL - Preprocessor (constant math expressions)
153 * acpi_dump - Input table addresses
154 * acpi_exec - Testing of the acpi_ut_strtoul64 function
155 *
156 * Note concerning callers:
157 * acpi_gbl_integer_byte_width can be used to set the 32/64 limit. If used,
158 * this global should be set to the proper width. For the core ACPICA code,
159 * this width depends on the DSDT version. For iASL, the default byte
160 * width is always 8 for the parser, but error checking is performed later
161 * to flag cases where a 64-bit constant is defined in a 32-bit DSDT/SSDT.
162 * 114 *
163 ******************************************************************************/ 115 ******************************************************************************/
164 116acpi_status acpi_ut_strtoul64(char *string, u64 *return_value)
165acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *return_value)
166{ 117{
167 acpi_status status = AE_OK; 118 acpi_status status = AE_OK;
168 u32 base; 119 u8 original_bit_width;
120 u32 base = 10; /* Default is decimal */
169 121
170 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string); 122 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string);
171 123
172 /* Parameter validation */
173
174 if (!string || !return_value) {
175 return_ACPI_STATUS(AE_BAD_PARAMETER);
176 }
177
178 *return_value = 0; 124 *return_value = 0;
179 125
180 /* Check for zero-length string, returns 0 */ 126 /* A NULL return string returns a value of zero */
181 127
182 if (*string == 0) { 128 if (*string == 0) {
183 return_ACPI_STATUS(AE_OK); 129 return_ACPI_STATUS(AE_OK);
184 } 130 }
185 131
186 /* Skip over any white space at start of string */ 132 if (!acpi_ut_remove_whitespace(&string)) {
187
188 while (isspace((int)*string)) {
189 string++;
190 }
191
192 /* End of string? return 0 */
193
194 if (*string == 0) {
195 return_ACPI_STATUS(AE_OK); 133 return_ACPI_STATUS(AE_OK);
196 } 134 }
197 135
198 /* 136 /*
199 * 1) The "0x" prefix indicates base 16. Per the ACPI specification, 137 * 1) Check for a hex constant. A "0x" prefix indicates base 16.
200 * the "0x" prefix is only allowed for implicit (non-strict) conversions.
201 * However, we always allow it for compatibility with older ACPICA.
202 */ 138 */
203 if ((*string == ACPI_ASCII_ZERO) && 139 if (acpi_ut_detect_hex_prefix(&string)) {
204 (tolower((int)*(string + 1)) == 'x')) {
205 string += 2; /* Go past the 0x */
206 if (*string == 0) {
207 return_ACPI_STATUS(AE_OK); /* Return value 0 */
208 }
209
210 base = 16; 140 base = 16;
211 } 141 }
212 142
213 /* 2) Force to base 16 (implicit conversion case) */ 143 /*
214 144 * 2) Check for an octal constant, defined to be a leading zero
215 else if (flags & ACPI_STRTOUL_BASE16) { 145 * followed by sequence of octal digits (0-7)
216 base = 16; 146 */
147 else if (acpi_ut_detect_octal_prefix(&string)) {
148 base = 8;
217 } 149 }
218 150
219 /* 3) Default fallback is to Base 10 */ 151 if (!acpi_ut_remove_leading_zeros(&string)) {
220 152 return_ACPI_STATUS(AE_OK); /* Return value 0 */
221 else {
222 base = 10;
223 } 153 }
224 154
225 /* Skip all leading zeros */ 155 /*
156 * Force a full 64-bit conversion. The caller (usually iASL) must
157 * check for a 32-bit overflow later as necessary (If current mode
158 * is 32-bit, meaning a 32-bit DSDT).
159 */
160 original_bit_width = acpi_gbl_integer_bit_width;
161 acpi_gbl_integer_bit_width = 64;
226 162
227 while (*string == ACPI_ASCII_ZERO) { 163 /*
228 string++; 164 * Perform the base 8, 10, or 16 conversion. A 64-bit numeric overflow
229 if (*string == 0) { 165 * will return an exception (to allow iASL to flag the statement).
230 return_ACPI_STATUS(AE_OK); /* Return value 0 */ 166 */
231 } 167 switch (base) {
168 case 8:
169 status = acpi_ut_convert_octal_string(string, return_value);
170 break;
171
172 case 10:
173 status = acpi_ut_convert_decimal_string(string, return_value);
174 break;
175
176 case 16:
177 default:
178 status = acpi_ut_convert_hex_string(string, return_value);
179 break;
232 } 180 }
233 181
234 /* Perform the base 16 or 10 conversion */ 182 /* Only possible exception from above is a 64-bit overflow */
235
236 if (base == 16) {
237 *return_value = acpi_ut_strtoul_base16(string, flags);
238 } else {
239 *return_value = acpi_ut_strtoul_base10(string, flags);
240 }
241 183
184 acpi_gbl_integer_bit_width = original_bit_width;
242 return_ACPI_STATUS(status); 185 return_ACPI_STATUS(status);
243} 186}
244 187
245/******************************************************************************* 188/*******************************************************************************
246 * 189 *
247 * FUNCTION: acpi_ut_strtoul_base10 190 * FUNCTION: acpi_ut_implicit_strtoul64
191 *
192 * PARAMETERS: string - Null terminated input string,
193 * must be a valid pointer
194 *
195 * RETURN: Converted integer
196 *
197 * DESCRIPTION: Perform a 64-bit conversion with restrictions placed upon
198 * an "implicit conversion" by the ACPI specification. Used by
199 * many ASL operators that require an integer operand, and support
200 * an automatic (implicit) conversion from a string operand
201 * to the final integer operand. The major restriction is that
202 * only hex strings are supported.
203 *
204 * -----------------------------------------------------------------------------
205 *
206 * Base is always 16, either with or without the 0x prefix. Decimal and
207 * Octal strings are not supported, as per the ACPI specification.
208 *
209 * Examples (both are hex values):
210 * Add ("BA98", Arg0, Local0)
211 * Subtract ("0x12345678", Arg1, Local1)
212 *
213 * Conversion rules as extracted from the ACPI specification:
214 *
215 * The converted integer is initialized to the value zero.
216 * The ASCII string is always interpreted as a hexadecimal constant.
217 *
218 * 1) According to the ACPI specification, a "0x" prefix is not allowed.
219 * However, ACPICA allows this as an ACPI extension on general
220 * principle. (NO ERROR)
221 *
222 * 2) The conversion terminates when the size of an integer is reached
223 * (32 or 64 bits). There are no numeric overflow conditions. (NO ERROR)
224 *
225 * 3) The first non-hex character terminates the conversion and returns
226 * the current accumulated value of the converted integer (NO ERROR).
248 * 227 *
249 * PARAMETERS: string - Null terminated input string 228 * 4) Conversion of a null (zero-length) string to an integer is
250 * flags - Conversion info 229 * technically not allowed. However, ACPICA allows this as an ACPI
230 * extension. The conversion returns the value 0. (NO ERROR)
251 * 231 *
252 * RETURN: 64-bit converted integer 232 * NOTE: There are no error conditions returned by this function. At
233 * the minimum, a value of zero is returned.
253 * 234 *
254 * DESCRIPTION: Performs a base 10 conversion of the input string to an 235 * Current users of this function:
255 * integer value, either 32 or 64 bits. 236 *
256 * Note: String must be valid and non-null. 237 * interpreter - All runtime implicit conversions, as per ACPI specification
238 * iASL - Data Table Compiler parser (constants and math expressions)
257 * 239 *
258 ******************************************************************************/ 240 ******************************************************************************/
259 241
260static u64 acpi_ut_strtoul_base10(char *string, u32 flags) 242u64 acpi_ut_implicit_strtoul64(char *string)
261{ 243{
262 int ascii_digit; 244 u64 converted_integer = 0;
263 u64 next_value;
264 u64 return_value = 0;
265
266 /* Main loop: convert each ASCII byte in the input string */
267
268 while (*string) {
269 ascii_digit = *string;
270 if (!isdigit(ascii_digit)) {
271
272 /* Not ASCII 0-9, terminate */
273
274 goto exit;
275 }
276
277 /* Convert and insert (add) the decimal digit */
278 245
279 acpi_ut_short_multiply(return_value, 10, &next_value); 246 ACPI_FUNCTION_TRACE_STR(ut_implicit_strtoul64, string);
280 next_value += (ascii_digit - ACPI_ASCII_ZERO);
281 247
282 /* Check for overflow (32 or 64 bit) - return current converted value */ 248 if (!acpi_ut_remove_whitespace(&string)) {
249 return_VALUE(0);
250 }
283 251
284 if (((flags & ACPI_STRTOUL_32BIT) && (next_value > ACPI_UINT32_MAX)) || (next_value < return_value)) { /* 64-bit overflow case */ 252 /*
285 goto exit; 253 * Per the ACPI specification, only hexadecimal is supported for
286 } 254 * implicit conversions, and the "0x" prefix is "not allowed".
255 * However, allow a "0x" prefix as an ACPI extension.
256 */
257 acpi_ut_detect_hex_prefix(&string);
287 258
288 return_value = next_value; 259 if (!acpi_ut_remove_leading_zeros(&string)) {
289 string++; 260 return_VALUE(0);
290 } 261 }
291 262
292exit: 263 /*
293 return (return_value); 264 * Ignore overflow as per the ACPI specification. This is implemented by
265 * ignoring the return status from the conversion function called below.
266 * On overflow, the input string is simply truncated.
267 */
268 acpi_ut_convert_hex_string(string, &converted_integer);
269 return_VALUE(converted_integer);
294} 270}
295 271
296/******************************************************************************* 272/*******************************************************************************
297 * 273 *
298 * FUNCTION: acpi_ut_strtoul_base16 274 * FUNCTION: acpi_ut_explicit_strtoul64
275 *
276 * PARAMETERS: string - Null terminated input string,
277 * must be a valid pointer
299 * 278 *
300 * PARAMETERS: string - Null terminated input string 279 * RETURN: Converted integer
301 * flags - conversion info
302 * 280 *
303 * RETURN: 64-bit converted integer 281 * DESCRIPTION: Perform a 64-bit conversion with the restrictions placed upon
282 * an "explicit conversion" by the ACPI specification. The
283 * main restriction is that only hex and decimal are supported.
304 * 284 *
305 * DESCRIPTION: Performs a base 16 conversion of the input string to an 285 * -----------------------------------------------------------------------------
306 * integer value, either 32 or 64 bits. 286 *
307 * Note: String must be valid and non-null. 287 * Base is either 10 (default) or 16 (with 0x prefix). Octal (base 8) strings
288 * are not supported, as per the ACPI specification.
289 *
290 * Examples:
291 * to_integer ("1000") Decimal
292 * to_integer ("0xABCD") Hex
293 *
294 * Conversion rules as extracted from the ACPI specification:
295 *
296 * 1) The input string is either a decimal or hexadecimal numeric string.
297 * A hex value must be prefixed by "0x" or it is interpreted as decimal.
298 *
299 * 2) The value must not exceed the maximum of an integer value
300 * (32 or 64 bits). The ACPI specification states the behavior is
301 * "unpredictable", so ACPICA matches the behavior of the implicit
302 * conversion case. There are no numeric overflow conditions. (NO ERROR)
303 *
304 * 3) Behavior on the first non-hex character is not defined by the ACPI
305 * specification (for the to_integer operator), so ACPICA matches the
306 * behavior of the implicit conversion case. It terminates the
307 * conversion and returns the current accumulated value of the converted
308 * integer. (NO ERROR)
309 *
310 * 4) Conversion of a null (zero-length) string to an integer is
311 * technically not allowed. However, ACPICA allows this as an ACPI
312 * extension. The conversion returns the value 0. (NO ERROR)
313 *
314 * NOTE: There are no error conditions returned by this function. At the
315 * minimum, a value of zero is returned.
316 *
317 * Current users of this function:
318 *
319 * interpreter - Runtime ASL to_integer operator, as per the ACPI specification
308 * 320 *
309 ******************************************************************************/ 321 ******************************************************************************/
310 322
311static u64 acpi_ut_strtoul_base16(char *string, u32 flags) 323u64 acpi_ut_explicit_strtoul64(char *string)
312{ 324{
313 int ascii_digit; 325 u64 converted_integer = 0;
314 u32 valid_digits = 1; 326 u32 base = 10; /* Default is decimal */
315 u64 return_value = 0;
316
317 /* Main loop: convert each ASCII byte in the input string */
318 327
319 while (*string) { 328 ACPI_FUNCTION_TRACE_STR(ut_explicit_strtoul64, string);
320 329
321 /* Check for overflow (32 or 64 bit) - return current converted value */ 330 if (!acpi_ut_remove_whitespace(&string)) {
322 331 return_VALUE(0);
323 if ((valid_digits > 16) || 332 }
324 ((valid_digits > 8) && (flags & ACPI_STRTOUL_32BIT))) {
325 goto exit;
326 }
327
328 ascii_digit = *string;
329 if (!isxdigit(ascii_digit)) {
330
331 /* Not Hex ASCII A-F, a-f, or 0-9, terminate */
332
333 goto exit;
334 }
335 333
336 /* Convert and insert the hex digit */ 334 /*
335 * Only Hex and Decimal are supported, as per the ACPI specification.
336 * A "0x" prefix indicates hex; otherwise decimal is assumed.
337 */
338 if (acpi_ut_detect_hex_prefix(&string)) {
339 base = 16;
340 }
337 341
338 acpi_ut_short_shift_left(return_value, 4, &return_value); 342 if (!acpi_ut_remove_leading_zeros(&string)) {
339 return_value |= acpi_ut_ascii_char_to_hex(ascii_digit); 343 return_VALUE(0);
344 }
340 345
341 string++; 346 /*
342 valid_digits++; 347 * Ignore overflow as per the ACPI specification. This is implemented by
348 * ignoring the return status from the conversion functions called below.
349 * On overflow, the input string is simply truncated.
350 */
351 switch (base) {
352 case 10:
353 default:
354 acpi_ut_convert_decimal_string(string, &converted_integer);
355 break;
356
357 case 16:
358 acpi_ut_convert_hex_string(string, &converted_integer);
359 break;
343 } 360 }
344 361
345exit: 362 return_VALUE(converted_integer);
346 return (return_value);
347} 363}
diff --git a/include/acpi/acexcep.h b/include/acpi/acexcep.h
index ad54610ea6cd..17d61b1f2511 100644
--- a/include/acpi/acexcep.h
+++ b/include/acpi/acexcep.h
@@ -126,8 +126,12 @@ struct acpi_exception_info {
126#define AE_NOT_CONFIGURED EXCEP_ENV (0x001C) 126#define AE_NOT_CONFIGURED EXCEP_ENV (0x001C)
127#define AE_ACCESS EXCEP_ENV (0x001D) 127#define AE_ACCESS EXCEP_ENV (0x001D)
128#define AE_IO_ERROR EXCEP_ENV (0x001E) 128#define AE_IO_ERROR EXCEP_ENV (0x001E)
129#define AE_NUMERIC_OVERFLOW EXCEP_ENV (0x001F)
130#define AE_HEX_OVERFLOW EXCEP_ENV (0x0020)
131#define AE_DECIMAL_OVERFLOW EXCEP_ENV (0x0021)
132#define AE_OCTAL_OVERFLOW EXCEP_ENV (0x0022)
129 133
130#define AE_CODE_ENV_MAX 0x001E 134#define AE_CODE_ENV_MAX 0x0022
131 135
132/* 136/*
133 * Programmer exceptions 137 * Programmer exceptions
@@ -263,7 +267,15 @@ static const struct acpi_exception_info acpi_gbl_exception_names_env[] = {
263 EXCEP_TXT("AE_NOT_CONFIGURED", 267 EXCEP_TXT("AE_NOT_CONFIGURED",
264 "The interface is not part of the current subsystem configuration"), 268 "The interface is not part of the current subsystem configuration"),
265 EXCEP_TXT("AE_ACCESS", "Permission denied for the requested operation"), 269 EXCEP_TXT("AE_ACCESS", "Permission denied for the requested operation"),
266 EXCEP_TXT("AE_IO_ERROR", "An I/O error occurred") 270 EXCEP_TXT("AE_IO_ERROR", "An I/O error occurred"),
271 EXCEP_TXT("AE_NUMERIC_OVERFLOW",
272 "Overflow during string-to-integer conversion"),
273 EXCEP_TXT("AE_HEX_OVERFLOW",
274 "Overflow during ASCII hex-to-binary conversion"),
275 EXCEP_TXT("AE_DECIMAL_OVERFLOW",
276 "Overflow during ASCII decimal-to-binary conversion"),
277 EXCEP_TXT("AE_OCTAL_OVERFLOW",
278 "Overflow during ASCII octal-to-binary conversion")
267}; 279};
268 280
269static const struct acpi_exception_info acpi_gbl_exception_names_pgm[] = { 281static const struct acpi_exception_info acpi_gbl_exception_names_pgm[] = {
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index 53c5e2f7bcec..e1dd1a8d42b6 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -46,7 +46,7 @@
46 46
47/* Current ACPICA subsystem version in YYYYMMDD format */ 47/* Current ACPICA subsystem version in YYYYMMDD format */
48 48
49#define ACPI_CA_VERSION 0x20170728 49#define ACPI_CA_VERSION 0x20170831
50 50
51#include <acpi/acconfig.h> 51#include <acpi/acconfig.h>
52#include <acpi/actypes.h> 52#include <acpi/actypes.h>
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index 6b8714a428b6..7a89e6de94da 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -69,6 +69,7 @@
69#define ACPI_SIG_HEST "HEST" /* Hardware Error Source Table */ 69#define ACPI_SIG_HEST "HEST" /* Hardware Error Source Table */
70#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */ 70#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */
71#define ACPI_SIG_MSCT "MSCT" /* Maximum System Characteristics Table */ 71#define ACPI_SIG_MSCT "MSCT" /* Maximum System Characteristics Table */
72#define ACPI_SIG_PDTT "PDTT" /* Processor Debug Trigger Table */
72#define ACPI_SIG_PPTT "PPTT" /* Processor Properties Topology Table */ 73#define ACPI_SIG_PPTT "PPTT" /* Processor Properties Topology Table */
73#define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Table */ 74#define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Table */
74#define ACPI_SIG_SLIT "SLIT" /* System Locality Distance Information Table */ 75#define ACPI_SIG_SLIT "SLIT" /* System Locality Distance Information Table */
@@ -1282,6 +1283,35 @@ struct acpi_nfit_flush_address {
1282 1283
1283/******************************************************************************* 1284/*******************************************************************************
1284 * 1285 *
1286 * PDTT - Processor Debug Trigger Table (ACPI 6.2)
1287 * Version 0
1288 *
1289 ******************************************************************************/
1290
1291struct acpi_table_pdtt {
1292 struct acpi_table_header header; /* Common ACPI table header */
1293 u8 trigger_count;
1294 u8 reserved[3];
1295 u32 array_offset;
1296};
1297
1298/*
1299 * PDTT Communication Channel Identifier Structure.
1300 * The number of these structures is defined by trigger_count above,
1301 * starting at array_offset.
1302 */
1303struct acpi_pdtt_channel {
1304 u16 sub_channel_id;
1305};
1306
1307/* Mask and Flags for above */
1308
1309#define ACPI_PDTT_SUBCHANNEL_ID_MASK 0x00FF
1310#define ACPI_PDTT_RUNTIME_TRIGGER (1<<8)
1311#define ACPI_PPTT_WAIT_COMPLETION (1<<9)
1312
1313/*******************************************************************************
1314 *
1285 * PPTT - Processor Properties Topology Table (ACPI 6.2) 1315 * PPTT - Processor Properties Topology Table (ACPI 6.2)
1286 * Version 1 1316 * Version 1
1287 * 1317 *
diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile
index f7c7af1f9258..b436f8675f6a 100644
--- a/tools/power/acpi/tools/acpidump/Makefile
+++ b/tools/power/acpi/tools/acpidump/Makefile
@@ -39,6 +39,7 @@ TOOL_OBJS = \
39 utnonansi.o\ 39 utnonansi.o\
40 utprint.o\ 40 utprint.o\
41 utstring.o\ 41 utstring.o\
42 utstrsuppt.o\
42 utstrtoul64.o\ 43 utstrtoul64.o\
43 utxferror.o\ 44 utxferror.o\
44 oslinuxtbl.o\ 45 oslinuxtbl.o\
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 60df1fbd4a77..0634449156d8 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -287,8 +287,7 @@ int ap_dump_table_by_address(char *ascii_address)
287 287
288 /* Convert argument to an integer physical address */ 288 /* Convert argument to an integer physical address */
289 289
290 status = acpi_ut_strtoul64(ascii_address, ACPI_STRTOUL_64BIT, 290 status = acpi_ut_strtoul64(ascii_address, &long_address);
291 &long_address);
292 if (ACPI_FAILURE(status)) { 291 if (ACPI_FAILURE(status)) {
293 fprintf(stderr, "%s: Could not convert to a physical address\n", 292 fprintf(stderr, "%s: Could not convert to a physical address\n",
294 ascii_address); 293 ascii_address);
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 943b6b614683..22c3b4ee1617 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -208,9 +208,7 @@ static int ap_do_options(int argc, char **argv)
208 case 'r': /* Dump tables from specified RSDP */ 208 case 'r': /* Dump tables from specified RSDP */
209 209
210 status = 210 status =
211 acpi_ut_strtoul64(acpi_gbl_optarg, 211 acpi_ut_strtoul64(acpi_gbl_optarg, &gbl_rsdp_base);
212 ACPI_STRTOUL_64BIT,
213 &gbl_rsdp_base);
214 if (ACPI_FAILURE(status)) { 212 if (ACPI_FAILURE(status)) {
215 fprintf(stderr, 213 fprintf(stderr,
216 "%s: Could not convert to a physical address\n", 214 "%s: Could not convert to a physical address\n",