aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Moore <robert.moore@intel.com>2016-09-07 02:14:30 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-09-09 20:37:59 -0400
commit5ebd2eaaefc0d4fe37ab72e716e1b8065ed4206c (patch)
tree36563f7c5e47e58b2d0fe5624f135a19dfbd3c33
parent60361b75848c8614233e3374ef5a0056527f0385 (diff)
ACPICA: Cleanup for all string-to-integer conversions
ACPICA commit e2e72a351201fd58e4694418859ae2c247dafca0 Consolidate multiple versions of strtoul64 to one common version. limit possible bases to either 10 or 16. Handles both implicit and explicit conversions. Added a 2-character ascii-to-hex function for GPEs and buffers. Adds a new file, utstrtoul64.c Link: https://github.com/acpica/acpica/commit/e2e72a35 Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/acpica/Makefile1
-rw-r--r--drivers/acpi/acpica/acutils.h17
-rw-r--r--drivers/acpi/acpica/dbconvert.c7
-rw-r--r--drivers/acpi/acpica/dswexec.c3
-rw-r--r--drivers/acpi/acpica/evgpeinit.c7
-rw-r--r--drivers/acpi/acpica/exconcat.c2
-rw-r--r--drivers/acpi/acpica/exconvrt.c8
-rw-r--r--drivers/acpi/acpica/exmisc.c4
-rw-r--r--drivers/acpi/acpica/exoparg1.c5
-rw-r--r--drivers/acpi/acpica/exresop.c11
-rw-r--r--drivers/acpi/acpica/nsconvert.c1
-rw-r--r--drivers/acpi/acpica/uthex.c45
-rw-r--r--drivers/acpi/acpica/utnonansi.c357
-rw-r--r--drivers/acpi/acpica/utstrtoul64.c348
-rw-r--r--tools/power/acpi/tools/acpidump/Makefile2
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c4
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c4
17 files changed, 435 insertions, 391 deletions
diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile
index 227bb7bb19d7..32d93edbc479 100644
--- a/drivers/acpi/acpica/Makefile
+++ b/drivers/acpi/acpica/Makefile
@@ -175,6 +175,7 @@ acpi-y += \
175 utresrc.o \ 175 utresrc.o \
176 utstate.o \ 176 utstate.o \
177 utstring.o \ 177 utstring.o \
178 utstrtoul64.o \
178 utxface.o \ 179 utxface.o \
179 utxfinit.o \ 180 utxfinit.o \
180 utxferror.o \ 181 utxferror.o \
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index d899296eeb47..0a1b53c9ee0e 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -196,14 +196,15 @@ void acpi_ut_strlwr(char *src_string);
196 196
197int acpi_ut_stricmp(char *string1, char *string2); 197int acpi_ut_stricmp(char *string1, char *string2);
198 198
199acpi_status 199acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *ret_integer);
200acpi_ut_strtoul64(char *string,
201 u32 base, u32 max_integer_byte_width, u64 *ret_integer);
202
203/* Values for max_integer_byte_width above */
204 200
205#define ACPI_MAX32_BYTE_WIDTH 4 201/*
206#define ACPI_MAX64_BYTE_WIDTH 8 202 * Values for Flags above
203 * Note: LIMIT values correspond to acpi_gbl_integer_byte_width values (4/8)
204 */
205#define ACPI_STRTOUL_32BIT 0x04 /* 4 bytes */
206#define ACPI_STRTOUL_64BIT 0x08 /* 8 bytes */
207#define ACPI_STRTOUL_BASE16 0x10 /* Default: Base10/16 */
207 208
208/* 209/*
209 * utglobal - Global data structures and procedures 210 * utglobal - Global data structures and procedures
@@ -233,6 +234,8 @@ const char *acpi_ut_get_event_name(u32 event_id);
233 234
234char acpi_ut_hex_to_ascii_char(u64 integer, u32 position); 235char acpi_ut_hex_to_ascii_char(u64 integer, u32 position);
235 236
237acpi_status acpi_ut_ascii_to_hex_byte(char *two_ascii_chars, u8 *return_byte);
238
236u8 acpi_ut_ascii_char_to_hex(int hex_char); 239u8 acpi_ut_ascii_char_to_hex(int hex_char);
237 240
238u8 acpi_ut_valid_object_type(acpi_object_type type); 241u8 acpi_ut_valid_object_type(acpi_object_type type);
diff --git a/drivers/acpi/acpica/dbconvert.c b/drivers/acpi/acpica/dbconvert.c
index 7cd07b27f758..147ce8894f76 100644
--- a/drivers/acpi/acpica/dbconvert.c
+++ b/drivers/acpi/acpica/dbconvert.c
@@ -277,9 +277,10 @@ 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 = 280 status = acpi_ut_strtoul64(string,
281 acpi_ut_strtoul64(string, 16, acpi_gbl_integer_byte_width, 281 (acpi_gbl_integer_byte_width |
282 &object->integer.value); 282 ACPI_STRTOUL_BASE16),
283 &object->integer.value);
283 break; 284 break;
284 } 285 }
285 286
diff --git a/drivers/acpi/acpica/dswexec.c b/drivers/acpi/acpica/dswexec.c
index 402ecc590c56..438597cf6cc5 100644
--- a/drivers/acpi/acpica/dswexec.c
+++ b/drivers/acpi/acpica/dswexec.c
@@ -133,7 +133,8 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
133 * Result of predicate evaluation must be an Integer 133 * Result of predicate evaluation must be an Integer
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, 16); 136 status = acpi_ex_convert_to_integer(obj_desc, &local_obj_desc,
137 ACPI_STRTOUL_BASE16);
137 if (ACPI_FAILURE(status)) { 138 if (ACPI_FAILURE(status)) {
138 goto cleanup; 139 goto cleanup;
139 } 140 }
diff --git a/drivers/acpi/acpica/evgpeinit.c b/drivers/acpi/acpica/evgpeinit.c
index 7dc75474c897..16ce4835e7d0 100644
--- a/drivers/acpi/acpica/evgpeinit.c
+++ b/drivers/acpi/acpica/evgpeinit.c
@@ -323,7 +323,9 @@ acpi_ev_match_gpe_method(acpi_handle obj_handle,
323 struct acpi_gpe_walk_info *walk_info = 323 struct acpi_gpe_walk_info *walk_info =
324 ACPI_CAST_PTR(struct acpi_gpe_walk_info, context); 324 ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
325 struct acpi_gpe_event_info *gpe_event_info; 325 struct acpi_gpe_event_info *gpe_event_info;
326 acpi_status status;
326 u32 gpe_number; 327 u32 gpe_number;
328 u8 temp_gpe_number;
327 char name[ACPI_NAME_SIZE + 1]; 329 char name[ACPI_NAME_SIZE + 1];
328 u8 type; 330 u8 type;
329 331
@@ -377,8 +379,8 @@ acpi_ev_match_gpe_method(acpi_handle obj_handle,
377 379
378 /* 4) The last two characters of the name are the hex GPE Number */ 380 /* 4) The last two characters of the name are the hex GPE Number */
379 381
380 gpe_number = strtoul(&name[2], NULL, 16); 382 status = acpi_ut_ascii_to_hex_byte(&name[2], &temp_gpe_number);
381 if (gpe_number == ACPI_UINT32_MAX) { 383 if (ACPI_FAILURE(status)) {
382 384
383 /* Conversion failed; invalid method, just ignore it */ 385 /* Conversion failed; invalid method, just ignore it */
384 386
@@ -390,6 +392,7 @@ acpi_ev_match_gpe_method(acpi_handle obj_handle,
390 392
391 /* Ensure that we have a valid GPE number for this GPE block */ 393 /* Ensure that we have a valid GPE number for this GPE block */
392 394
395 gpe_number = (u32)temp_gpe_number;
393 gpe_event_info = 396 gpe_event_info =
394 acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block); 397 acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
395 if (!gpe_event_info) { 398 if (!gpe_event_info) {
diff --git a/drivers/acpi/acpica/exconcat.c b/drivers/acpi/acpica/exconcat.c
index 2423fe03e879..5429c2a6bc41 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 16); 159 ACPI_STRTOUL_BASE16);
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 b7e9b3d803e1..588ad1409dbe 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -124,9 +124,9 @@ acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
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 */ 126 */
127 status = acpi_ut_strtoul64((char *)pointer, flags, 127 status = acpi_ut_strtoul64(ACPI_CAST_PTR(char, pointer),
128 acpi_gbl_integer_byte_width, 128 (acpi_gbl_integer_byte_width |
129 &result); 129 flags), &result);
130 if (ACPI_FAILURE(status)) { 130 if (ACPI_FAILURE(status)) {
131 return_ACPI_STATUS(status); 131 return_ACPI_STATUS(status);
132 } 132 }
@@ -632,7 +632,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
632 */ 632 */
633 status = 633 status =
634 acpi_ex_convert_to_integer(source_desc, result_desc, 634 acpi_ex_convert_to_integer(source_desc, result_desc,
635 16); 635 ACPI_STRTOUL_BASE16);
636 break; 636 break;
637 637
638 case ACPI_TYPE_STRING: 638 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exmisc.c b/drivers/acpi/acpica/exmisc.c
index 4f7e667624b3..37c88b424a02 100644
--- a/drivers/acpi/acpica/exmisc.c
+++ b/drivers/acpi/acpica/exmisc.c
@@ -327,8 +327,8 @@ acpi_ex_do_logical_op(u16 opcode,
327 switch (operand0->common.type) { 327 switch (operand0->common.type) {
328 case ACPI_TYPE_INTEGER: 328 case ACPI_TYPE_INTEGER:
329 329
330 status = 330 status = acpi_ex_convert_to_integer(operand1, &local_operand1,
331 acpi_ex_convert_to_integer(operand1, &local_operand1, 16); 331 ACPI_STRTOUL_BASE16);
332 break; 332 break;
333 333
334 case ACPI_TYPE_STRING: 334 case ACPI_TYPE_STRING:
diff --git a/drivers/acpi/acpica/exoparg1.c b/drivers/acpi/acpica/exoparg1.c
index 4e17506a7384..6ae19cb26eb2 100644
--- a/drivers/acpi/acpica/exoparg1.c
+++ b/drivers/acpi/acpica/exoparg1.c
@@ -521,9 +521,10 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
521 521
522 case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */ 522 case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
523 523
524 /* Perform "explicit" conversion */
525
524 status = 526 status =
525 acpi_ex_convert_to_integer(operand[0], &return_desc, 527 acpi_ex_convert_to_integer(operand[0], &return_desc, 0);
526 ACPI_ANY_BASE);
527 if (return_desc == operand[0]) { 528 if (return_desc == operand[0]) {
528 529
529 /* No conversion performed, add ref to handle return value */ 530 /* No conversion performed, add ref to handle return value */
diff --git a/drivers/acpi/acpica/exresop.c b/drivers/acpi/acpica/exresop.c
index 27b41fd7542d..f29eba1dc5e9 100644
--- a/drivers/acpi/acpica/exresop.c
+++ b/drivers/acpi/acpica/exresop.c
@@ -410,12 +410,13 @@ acpi_ex_resolve_operands(u16 opcode,
410 case ARGI_INTEGER: 410 case ARGI_INTEGER:
411 411
412 /* 412 /*
413 * Need an operand of type ACPI_TYPE_INTEGER, 413 * Need an operand of type ACPI_TYPE_INTEGER, but we can
414 * But we can implicitly convert from a STRING or BUFFER 414 * implicitly convert from a STRING or BUFFER.
415 * aka - "Implicit Source Operand Conversion" 415 *
416 * Known as "Implicit Source Operand Conversion"
416 */ 417 */
417 status = 418 status = acpi_ex_convert_to_integer(obj_desc, stack_ptr,
418 acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16); 419 ACPI_STRTOUL_BASE16);
419 if (ACPI_FAILURE(status)) { 420 if (ACPI_FAILURE(status)) {
420 if (status == AE_TYPE) { 421 if (status == AE_TYPE) {
421 ACPI_ERROR((AE_INFO, 422 ACPI_ERROR((AE_INFO,
diff --git a/drivers/acpi/acpica/nsconvert.c b/drivers/acpi/acpica/nsconvert.c
index c803bda7915c..2b85dee6d4c0 100644
--- a/drivers/acpi/acpica/nsconvert.c
+++ b/drivers/acpi/acpica/nsconvert.c
@@ -79,7 +79,6 @@ acpi_ns_convert_to_integer(union acpi_operand_object *original_object,
79 /* String-to-Integer conversion */ 79 /* String-to-Integer conversion */
80 80
81 status = acpi_ut_strtoul64(original_object->string.pointer, 81 status = acpi_ut_strtoul64(original_object->string.pointer,
82 ACPI_ANY_BASE,
83 acpi_gbl_integer_byte_width, &value); 82 acpi_gbl_integer_byte_width, &value);
84 if (ACPI_FAILURE(status)) { 83 if (ACPI_FAILURE(status)) {
85 return (status); 84 return (status);
diff --git a/drivers/acpi/acpica/uthex.c b/drivers/acpi/acpica/uthex.c
index 4354fb800fe4..3a4ca951d762 100644
--- a/drivers/acpi/acpica/uthex.c
+++ b/drivers/acpi/acpica/uthex.c
@@ -75,9 +75,40 @@ char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
75 75
76/******************************************************************************* 76/*******************************************************************************
77 * 77 *
78 * FUNCTION: acpi_ut_ascii_to_hex_byte
79 *
80 * PARAMETERS: two_ascii_chars - Pointer to two ASCII characters
81 * return_byte - Where converted byte is returned
82 *
83 * RETURN: Status and converted hex byte
84 *
85 * DESCRIPTION: Perform ascii-to-hex translation, exactly two ASCII characters
86 * to a single converted byte value.
87 *
88 ******************************************************************************/
89
90acpi_status acpi_ut_ascii_to_hex_byte(char *two_ascii_chars, u8 *return_byte)
91{
92
93 /* Both ASCII characters must be valid hex digits */
94
95 if (!isxdigit(two_ascii_chars[0]) || !isxdigit(two_ascii_chars[1])) {
96 return (AE_BAD_HEX_CONSTANT);
97 }
98
99 *return_byte =
100 acpi_ut_ascii_char_to_hex(two_ascii_chars[1]) |
101 (acpi_ut_ascii_char_to_hex(two_ascii_chars[0]) << 4);
102
103 return (AE_OK);
104}
105
106/*******************************************************************************
107 *
78 * FUNCTION: acpi_ut_ascii_char_to_hex 108 * FUNCTION: acpi_ut_ascii_char_to_hex
79 * 109 *
80 * PARAMETERS: hex_char - Hex character in Ascii 110 * PARAMETERS: hex_char - Hex character in Ascii. Must be:
111 * 0-9 or A-F or a-f
81 * 112 *
82 * RETURN: The binary value of the ascii/hex character 113 * RETURN: The binary value of the ascii/hex character
83 * 114 *
@@ -88,13 +119,19 @@ char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
88u8 acpi_ut_ascii_char_to_hex(int hex_char) 119u8 acpi_ut_ascii_char_to_hex(int hex_char)
89{ 120{
90 121
91 if (hex_char <= 0x39) { 122 /* Values 0-9 */
92 return ((u8)(hex_char - 0x30)); 123
124 if (hex_char <= '9') {
125 return ((u8)(hex_char - '0'));
93 } 126 }
94 127
95 if (hex_char <= 0x46) { 128 /* Upper case A-F */
129
130 if (hex_char <= 'F') {
96 return ((u8)(hex_char - 0x37)); 131 return ((u8)(hex_char - 0x37));
97 } 132 }
98 133
134 /* Lower case a-f */
135
99 return ((u8)(hex_char - 0x57)); 136 return ((u8)(hex_char - 0x57));
100} 137}
diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
index 3465fe2c5a5c..2514239282c2 100644
--- a/drivers/acpi/acpica/utnonansi.c
+++ b/drivers/acpi/acpica/utnonansi.c
@@ -48,8 +48,8 @@
48ACPI_MODULE_NAME("utnonansi") 48ACPI_MODULE_NAME("utnonansi")
49 49
50/* 50/*
51 * Non-ANSI C library functions - strlwr, strupr, stricmp, and a 64-bit 51 * Non-ANSI C library functions - strlwr, strupr, stricmp, and "safe"
52 * version of strtoul. 52 * string functions.
53 */ 53 */
54/******************************************************************************* 54/*******************************************************************************
55 * 55 *
@@ -200,356 +200,3 @@ acpi_ut_safe_strncat(char *dest,
200 return (FALSE); 200 return (FALSE);
201} 201}
202#endif 202#endif
203
204/*******************************************************************************
205 *
206 * FUNCTION: acpi_ut_strtoul64
207 *
208 * PARAMETERS: string - Null terminated string
209 * base - Radix of the string: 16 or 10 or
210 * ACPI_ANY_BASE
211 * max_integer_byte_width - Maximum allowable integer,in bytes:
212 * 4 or 8 (32 or 64 bits)
213 * ret_integer - Where the converted integer is
214 * returned
215 *
216 * RETURN: Status and Converted value
217 *
218 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
219 * 32-bit or 64-bit conversion, depending on the input integer
220 * size (often the current mode of the interpreter).
221 *
222 * NOTES: Negative numbers are not supported, as they are not supported
223 * by ACPI.
224 *
225 * acpi_gbl_integer_byte_width should be set to the proper width.
226 * For the core ACPICA code, this width depends on the DSDT
227 * version. For iASL, the default byte width is always 8 for the
228 * parser, but error checking is performed later to flag cases
229 * where a 64-bit constant is defined in a 32-bit DSDT/SSDT.
230 *
231 * Does not support Octal strings, not needed at this time.
232 *
233 ******************************************************************************/
234
235acpi_status
236acpi_ut_strtoul64(char *string,
237 u32 base, u32 max_integer_byte_width, u64 *ret_integer)
238{
239 u32 this_digit = 0;
240 u64 return_value = 0;
241 u64 quotient;
242 u64 dividend;
243 u8 valid_digits = 0;
244 u8 sign_of0x = 0;
245 u8 term = 0;
246
247 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string);
248
249 switch (base) {
250 case ACPI_ANY_BASE:
251 case 10:
252 case 16:
253
254 break;
255
256 default:
257
258 /* Invalid Base */
259
260 return_ACPI_STATUS(AE_BAD_PARAMETER);
261 }
262
263 if (!string) {
264 goto error_exit;
265 }
266
267 /* Skip over any white space in the buffer */
268
269 while ((*string) && (isspace((int)*string) || *string == '\t')) {
270 string++;
271 }
272
273 if (base == ACPI_ANY_BASE) {
274 /*
275 * Base equal to ACPI_ANY_BASE means 'Either decimal or hex'.
276 * We need to determine if it is decimal or hexadecimal.
277 */
278 if ((*string == '0') && (tolower((int)*(string + 1)) == 'x')) {
279 sign_of0x = 1;
280 base = 16;
281
282 /* Skip over the leading '0x' */
283 string += 2;
284 } else {
285 base = 10;
286 }
287 }
288
289 /* Any string left? Check that '0x' is not followed by white space. */
290
291 if (!(*string) || isspace((int)*string) || *string == '\t') {
292 if (base == ACPI_ANY_BASE) {
293 goto error_exit;
294 } else {
295 goto all_done;
296 }
297 }
298
299 /*
300 * Perform a 32-bit or 64-bit conversion, depending upon the input
301 * byte width
302 */
303 dividend = (max_integer_byte_width <= ACPI_MAX32_BYTE_WIDTH) ?
304 ACPI_UINT32_MAX : ACPI_UINT64_MAX;
305
306 /* Main loop: convert the string to a 32- or 64-bit integer */
307
308 while (*string) {
309 if (isdigit((int)*string)) {
310
311 /* Convert ASCII 0-9 to Decimal value */
312
313 this_digit = ((u8)*string) - '0';
314 } else if (base == 10) {
315
316 /* Digit is out of range; possible in to_integer case only */
317
318 term = 1;
319 } else {
320 this_digit = (u8)toupper((int)*string);
321 if (isxdigit((int)this_digit)) {
322
323 /* Convert ASCII Hex char to value */
324
325 this_digit = this_digit - 'A' + 10;
326 } else {
327 term = 1;
328 }
329 }
330
331 if (term) {
332 if (base == ACPI_ANY_BASE) {
333 goto error_exit;
334 } else {
335 break;
336 }
337 } else if ((valid_digits == 0) && (this_digit == 0)
338 && !sign_of0x) {
339
340 /* Skip zeros */
341 string++;
342 continue;
343 }
344
345 valid_digits++;
346
347 if (sign_of0x && ((valid_digits > 16) ||
348 ((valid_digits > 8)
349 && (max_integer_byte_width <=
350 ACPI_MAX32_BYTE_WIDTH)))) {
351 /*
352 * This is to_integer operation case.
353 * No restrictions for string-to-integer conversion,
354 * see ACPI spec.
355 */
356 goto error_exit;
357 }
358
359 /* Divide the digit into the correct position */
360
361 (void)acpi_ut_short_divide((dividend - (u64)this_digit), base,
362 &quotient, NULL);
363
364 if (return_value > quotient) {
365 if (base == ACPI_ANY_BASE) {
366 goto error_exit;
367 } else {
368 break;
369 }
370 }
371
372 return_value *= base;
373 return_value += this_digit;
374 string++;
375 }
376
377 /* All done, normal exit */
378
379all_done:
380
381 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
382 ACPI_FORMAT_UINT64(return_value)));
383
384 *ret_integer = return_value;
385 return_ACPI_STATUS(AE_OK);
386
387error_exit:
388
389 /* Base was set/validated above (10 or 16) */
390
391 if (base == 10) {
392 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
393 } else {
394 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
395 }
396}
397
398#ifdef _OBSOLETE_FUNCTIONS
399/* Removed: 01/2016 */
400
401/*******************************************************************************
402 *
403 * FUNCTION: strtoul64
404 *
405 * PARAMETERS: string - Null terminated string
406 * terminater - Where a pointer to the terminating byte
407 * is returned
408 * base - Radix of the string
409 *
410 * RETURN: Converted value
411 *
412 * DESCRIPTION: Convert a string into an unsigned value.
413 *
414 ******************************************************************************/
415
416acpi_status strtoul64(char *string, u32 base, u64 *ret_integer)
417{
418 u32 index;
419 u32 sign;
420 u64 return_value = 0;
421 acpi_status status = AE_OK;
422
423 *ret_integer = 0;
424
425 switch (base) {
426 case 0:
427 case 8:
428 case 10:
429 case 16:
430
431 break;
432
433 default:
434 /*
435 * The specified Base parameter is not in the domain of
436 * this function:
437 */
438 return (AE_BAD_PARAMETER);
439 }
440
441 /* Skip over any white space in the buffer: */
442
443 while (isspace((int)*string) || *string == '\t') {
444 ++string;
445 }
446
447 /*
448 * The buffer may contain an optional plus or minus sign.
449 * If it does, then skip over it but remember what is was:
450 */
451 if (*string == '-') {
452 sign = ACPI_SIGN_NEGATIVE;
453 ++string;
454 } else if (*string == '+') {
455 ++string;
456 sign = ACPI_SIGN_POSITIVE;
457 } else {
458 sign = ACPI_SIGN_POSITIVE;
459 }
460
461 /*
462 * If the input parameter Base is zero, then we need to
463 * determine if it is octal, decimal, or hexadecimal:
464 */
465 if (base == 0) {
466 if (*string == '0') {
467 if (tolower((int)*(++string)) == 'x') {
468 base = 16;
469 ++string;
470 } else {
471 base = 8;
472 }
473 } else {
474 base = 10;
475 }
476 }
477
478 /*
479 * For octal and hexadecimal bases, skip over the leading
480 * 0 or 0x, if they are present.
481 */
482 if (base == 8 && *string == '0') {
483 string++;
484 }
485
486 if (base == 16 && *string == '0' && tolower((int)*(++string)) == 'x') {
487 string++;
488 }
489
490 /* Main loop: convert the string to an unsigned long */
491
492 while (*string) {
493 if (isdigit((int)*string)) {
494 index = ((u8)*string) - '0';
495 } else {
496 index = (u8)toupper((int)*string);
497 if (isupper((int)index)) {
498 index = index - 'A' + 10;
499 } else {
500 goto error_exit;
501 }
502 }
503
504 if (index >= base) {
505 goto error_exit;
506 }
507
508 /* Check to see if value is out of range: */
509
510 if (return_value > ((ACPI_UINT64_MAX - (u64)index) / (u64)base)) {
511 goto error_exit;
512 } else {
513 return_value *= base;
514 return_value += index;
515 }
516
517 ++string;
518 }
519
520 /* If a minus sign was present, then "the conversion is negated": */
521
522 if (sign == ACPI_SIGN_NEGATIVE) {
523 return_value = (ACPI_UINT32_MAX - return_value) + 1;
524 }
525
526 *ret_integer = return_value;
527 return (status);
528
529error_exit:
530 switch (base) {
531 case 8:
532
533 status = AE_BAD_OCTAL_CONSTANT;
534 break;
535
536 case 10:
537
538 status = AE_BAD_DECIMAL_CONSTANT;
539 break;
540
541 case 16:
542
543 status = AE_BAD_HEX_CONSTANT;
544 break;
545
546 default:
547
548 /* Base validated above */
549
550 break;
551 }
552
553 return (status);
554}
555#endif
diff --git a/drivers/acpi/acpica/utstrtoul64.c b/drivers/acpi/acpica/utstrtoul64.c
new file mode 100644
index 000000000000..b4f341c98a95
--- /dev/null
+++ b/drivers/acpi/acpica/utstrtoul64.c
@@ -0,0 +1,348 @@
1/*******************************************************************************
2 *
3 * Module Name: utstrtoul64 - string to 64-bit integer support
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2016, 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/*******************************************************************************
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
55ACPI_MODULE_NAME("utstrtoul64")
56
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/*******************************************************************************
63 *
64 * String conversion rules as written in the ACPI specification. The error
65 * conditions and behavior are different depending on the type of conversion.
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 *
79 * 1) A "0x" prefix is not allowed. However, ACPICA allows this for
80 * compatibility with previous ACPICA. (NO ERROR)
81 *
82 * 2) Terminates when the size of an integer is reached (32 or 64 bits).
83 * (NO ERROR)
84 *
85 * 3) The first non-hex character terminates the conversion without error.
86 * (NO ERROR)
87 *
88 * 4) Conversion of a null (zero-length) string to an integer is not
89 * allowed. However, ACPICA allows this for compatibility with previous
90 * ACPICA. This conversion returns the value 0. (NO ERROR)
91 *
92 *
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 *
105 * 2) The value must not exceed the maximum of an integer value. ACPI spec
106 * states the behavior is "unpredictable", so ACPICA matches the behavior
107 * of the implicit conversion case.(NO ERROR)
108 *
109 * 3) Behavior on the first non-hex character is not specified by the ACPI
110 * spec, so ACPICA matches the behavior of the implicit conversion case
111 * and terminates. (NO ERROR)
112 *
113 * 4) A null (zero-length) string is illegal.
114 * However, ACPICA allows this for compatibility with previous ACPICA.
115 * This conversion returns the value 0. (NO ERROR)
116 *
117 ******************************************************************************/
118
119/*******************************************************************************
120 *
121 * FUNCTION: acpi_ut_strtoul64
122 *
123 * PARAMETERS: string - Null terminated input string
124 * flags - Conversion info, see below
125 * return_value - Where the converted integer is
126 * returned
127 *
128 * RETURN: Status and Converted value
129 *
130 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
131 * 32-bit or 64-bit conversion, depending on the input integer
132 * size in Flags (often the current mode of the interpreter).
133 *
134 * Values for Flags:
135 * ACPI_STRTOUL_32BIT - Max integer value is 32 bits
136 * ACPI_STRTOUL_64BIT - Max integer value is 64 bits
137 * ACPI_STRTOUL_BASE16 - Input string is hexadecimal. Default
138 * is 10/16 based on string prefix (0x).
139 *
140 * NOTES:
141 * Negative numbers are not supported, as they are not supported by ACPI.
142 *
143 * Supports only base 16 or base 10 strings/values. Does not
144 * support Octal strings, as these are not supported by ACPI.
145 *
146 * Current users of this support:
147 *
148 * interpreter - Implicit and explicit conversions, GPE method names
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 *
163 ******************************************************************************/
164
165acpi_status acpi_ut_strtoul64(char *string, u32 flags, u64 *return_value)
166{
167 acpi_status status = AE_OK;
168 u32 base;
169
170 ACPI_FUNCTION_TRACE_STR(ut_strtoul64, string);
171
172 /* Parameter validation */
173
174 if (!string || !return_value) {
175 return_ACPI_STATUS(AE_BAD_PARAMETER);
176 }
177
178 *return_value = 0;
179
180 /* Check for zero-length string, returns 0 */
181
182 if (*string == 0) {
183 return_ACPI_STATUS(AE_OK);
184 }
185
186 /* Skip over any white space at start of 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);
196 }
197
198 /*
199 * 1) The "0x" prefix indicates base 16. Per the ACPI specification,
200 * the "0x" prefix is only allowed for implicit (non-strict) conversions.
201 * However, we always allow it for compatibility with older ACPICA.
202 */
203 if ((*string == ACPI_ASCII_ZERO) &&
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;
211 }
212
213 /* 2) Force to base 16 (implicit conversion case) */
214
215 else if (flags & ACPI_STRTOUL_BASE16) {
216 base = 16;
217 }
218
219 /* 3) Default fallback is to Base 10 */
220
221 else {
222 base = 10;
223 }
224
225 /* Skip all leading zeros */
226
227 while (*string == ACPI_ASCII_ZERO) {
228 string++;
229 if (*string == 0) {
230 return_ACPI_STATUS(AE_OK); /* Return value 0 */
231 }
232 }
233
234 /* Perform the base 16 or 10 conversion */
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
242 return_ACPI_STATUS(status);
243}
244
245/*******************************************************************************
246 *
247 * FUNCTION: acpi_ut_strtoul_base10
248 *
249 * PARAMETERS: string - Null terminated input string
250 * flags - Conversion info
251 *
252 * RETURN: 64-bit converted integer
253 *
254 * DESCRIPTION: Performs a base 10 conversion of the input string to an
255 * integer value, either 32 or 64 bits.
256 * Note: String must be valid and non-null.
257 *
258 ******************************************************************************/
259
260static u64 acpi_ut_strtoul_base10(char *string, u32 flags)
261{
262 int ascii_digit;
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
279 next_value =
280 (return_value * 10) + (ascii_digit - ACPI_ASCII_ZERO);
281
282 /* Check for overflow (32 or 64 bit) - return current converted value */
283
284 if (((flags & ACPI_STRTOUL_32BIT) && (next_value > ACPI_UINT32_MAX)) || (next_value < return_value)) { /* 64-bit overflow case */
285 goto exit;
286 }
287
288 return_value = next_value;
289 string++;
290 }
291
292exit:
293 return (return_value);
294}
295
296/*******************************************************************************
297 *
298 * FUNCTION: acpi_ut_strtoul_base16
299 *
300 * PARAMETERS: string - Null terminated input string
301 * flags - conversion info
302 *
303 * RETURN: 64-bit converted integer
304 *
305 * DESCRIPTION: Performs a base 16 conversion of the input string to an
306 * integer value, either 32 or 64 bits.
307 * Note: String must be valid and non-null.
308 *
309 ******************************************************************************/
310
311static u64 acpi_ut_strtoul_base16(char *string, u32 flags)
312{
313 int ascii_digit;
314 u32 valid_digits = 1;
315 u64 return_value = 0;
316
317 /* Main loop: convert each ASCII byte in the input string */
318
319 while (*string) {
320
321 /* Check for overflow (32 or 64 bit) - return current converted value */
322
323 if ((valid_digits > 16) ||
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
336 /* Convert and insert the hex digit */
337
338 return_value =
339 (return_value << 4) |
340 acpi_ut_ascii_char_to_hex(ascii_digit);
341
342 string++;
343 valid_digits++;
344 }
345
346exit:
347 return (return_value);
348}
diff --git a/tools/power/acpi/tools/acpidump/Makefile b/tools/power/acpi/tools/acpidump/Makefile
index a710f60290ee..04b5db7c7c0b 100644
--- a/tools/power/acpi/tools/acpidump/Makefile
+++ b/tools/power/acpi/tools/acpidump/Makefile
@@ -36,10 +36,12 @@ TOOL_OBJS = \
36 utdebug.o\ 36 utdebug.o\
37 utexcep.o\ 37 utexcep.o\
38 utglobal.o\ 38 utglobal.o\
39 uthex.o\
39 utmath.o\ 40 utmath.o\
40 utnonansi.o\ 41 utnonansi.o\
41 utprint.o\ 42 utprint.o\
42 utstring.o\ 43 utstring.o\
44 utstrtoul64.o\
43 utxferror.o\ 45 utxferror.o\
44 oslinuxtbl.o\ 46 oslinuxtbl.o\
45 cmfsize.o\ 47 cmfsize.o\
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 1c4e00bd8acb..9031be1afe63 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -287,8 +287,8 @@ 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_ANY_BASE, 290 status = acpi_ut_strtoul64(ascii_address, ACPI_STRTOUL_64BIT,
291 ACPI_MAX64_BYTE_WIDTH, &long_address); 291 &long_address);
292 if (ACPI_FAILURE(status)) { 292 if (ACPI_FAILURE(status)) {
293 fprintf(stderr, "%s: Could not convert to a physical address\n", 293 fprintf(stderr, "%s: Could not convert to a physical address\n",
294 ascii_address); 294 ascii_address);
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index f32968e22af5..7ff46be908f0 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -208,8 +208,8 @@ 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, ACPI_ANY_BASE, 211 acpi_ut_strtoul64(acpi_gbl_optarg,
212 ACPI_MAX64_BYTE_WIDTH, 212 ACPI_STRTOUL_64BIT,
213 &gbl_rsdp_base); 213 &gbl_rsdp_base);
214 if (ACPI_FAILURE(status)) { 214 if (ACPI_FAILURE(status)) {
215 fprintf(stderr, 215 fprintf(stderr,