Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: utmisc - common utility procedures | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
4a90c7e8 | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
1da177e4 LT |
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 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acnamesp.h> | |
46 | ||
1da177e4 | 47 | #define _COMPONENT ACPI_UTILITIES |
4be44fcd | 48 | ACPI_MODULE_NAME("utmisc") |
44f6c012 | 49 | |
f9f4601f RM |
50 | /******************************************************************************* |
51 | * | |
52 | * FUNCTION: acpi_ut_allocate_owner_id | |
53 | * | |
54 | * PARAMETERS: owner_id - Where the new owner ID is returned | |
55 | * | |
0c9938cc RM |
56 | * RETURN: Status |
57 | * | |
58 | * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to | |
59 | * track objects created by the table or method, to be deleted | |
60 | * when the method exits or the table is unloaded. | |
f9f4601f RM |
61 | * |
62 | ******************************************************************************/ | |
4be44fcd | 63 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) |
f9f4601f | 64 | { |
4be44fcd | 65 | acpi_native_uint i; |
c51a4de8 | 66 | acpi_native_uint j; |
28f55ebc | 67 | acpi_native_uint k; |
4be44fcd | 68 | acpi_status status; |
f9f4601f | 69 | |
4be44fcd | 70 | ACPI_FUNCTION_TRACE("ut_allocate_owner_id"); |
f9f4601f | 71 | |
aff8c277 RM |
72 | /* Guard against multiple allocations of ID to the same location */ |
73 | ||
74 | if (*owner_id) { | |
b8e4d893 BM |
75 | ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists", |
76 | *owner_id)); | |
aff8c277 RM |
77 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
78 | } | |
79 | ||
0c9938cc RM |
80 | /* Mutex for the global ID mask */ |
81 | ||
4be44fcd LB |
82 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
83 | if (ACPI_FAILURE(status)) { | |
84 | return_ACPI_STATUS(status); | |
f9f4601f RM |
85 | } |
86 | ||
c51a4de8 BM |
87 | /* |
88 | * Find a free owner ID, cycle through all possible IDs on repeated | |
28f55ebc BM |
89 | * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have |
90 | * to be scanned twice. | |
c51a4de8 | 91 | */ |
28f55ebc BM |
92 | for (i = 0, j = acpi_gbl_last_owner_id_index; |
93 | i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) { | |
94 | if (j >= ACPI_NUM_OWNERID_MASKS) { | |
95 | j = 0; /* Wraparound to start of mask array */ | |
c51a4de8 BM |
96 | } |
97 | ||
28f55ebc BM |
98 | for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) { |
99 | if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) { | |
52fc0b02 | 100 | |
28f55ebc BM |
101 | /* There are no free IDs in this mask */ |
102 | ||
103 | break; | |
104 | } | |
105 | ||
106 | if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) { | |
107 | /* | |
108 | * Found a free ID. The actual ID is the bit index plus one, | |
109 | * making zero an invalid Owner ID. Save this as the last ID | |
110 | * allocated and update the global ID mask. | |
111 | */ | |
112 | acpi_gbl_owner_id_mask[j] |= (1 << k); | |
113 | ||
114 | acpi_gbl_last_owner_id_index = (u8) j; | |
115 | acpi_gbl_next_owner_id_offset = (u8) (k + 1); | |
116 | ||
117 | /* | |
118 | * Construct encoded ID from the index and bit position | |
119 | * | |
120 | * Note: Last [j].k (bit 255) is never used and is marked | |
121 | * permanently allocated (prevents +1 overflow) | |
122 | */ | |
123 | *owner_id = | |
124 | (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j)); | |
125 | ||
126 | ACPI_DEBUG_PRINT((ACPI_DB_VALUES, | |
127 | "Allocated owner_id: %2.2X\n", | |
128 | (unsigned int)*owner_id)); | |
129 | goto exit; | |
130 | } | |
f9f4601f | 131 | } |
28f55ebc BM |
132 | |
133 | acpi_gbl_next_owner_id_offset = 0; | |
f9f4601f RM |
134 | } |
135 | ||
136 | /* | |
c51a4de8 | 137 | * All owner_ids have been allocated. This typically should |
f9f4601f RM |
138 | * not happen since the IDs are reused after deallocation. The IDs are |
139 | * allocated upon table load (one per table) and method execution, and | |
140 | * they are released when a table is unloaded or a method completes | |
141 | * execution. | |
c51a4de8 BM |
142 | * |
143 | * If this error happens, there may be very deep nesting of invoked control | |
144 | * methods, or there may be a bug where the IDs are not released. | |
f9f4601f RM |
145 | */ |
146 | status = AE_OWNER_ID_LIMIT; | |
b8e4d893 BM |
147 | ACPI_ERROR((AE_INFO, |
148 | "Could not allocate new owner_id (255 max), AE_OWNER_ID_LIMIT")); | |
f9f4601f | 149 | |
4be44fcd LB |
150 | exit: |
151 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); | |
152 | return_ACPI_STATUS(status); | |
f9f4601f RM |
153 | } |
154 | ||
f9f4601f RM |
155 | /******************************************************************************* |
156 | * | |
157 | * FUNCTION: acpi_ut_release_owner_id | |
158 | * | |
0c9938cc | 159 | * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD |
f9f4601f | 160 | * |
0c9938cc RM |
161 | * RETURN: None. No error is returned because we are either exiting a |
162 | * control method or unloading a table. Either way, we would | |
163 | * ignore any error anyway. | |
164 | * | |
28f55ebc | 165 | * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255 |
f9f4601f RM |
166 | * |
167 | ******************************************************************************/ | |
168 | ||
4be44fcd | 169 | void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) |
f9f4601f | 170 | { |
4be44fcd LB |
171 | acpi_owner_id owner_id = *owner_id_ptr; |
172 | acpi_status status; | |
28f55ebc BM |
173 | acpi_native_uint index; |
174 | u32 bit; | |
f9f4601f | 175 | |
a18ecf41 | 176 | ACPI_FUNCTION_TRACE_U32("ut_release_owner_id", owner_id); |
f9f4601f | 177 | |
0c9938cc RM |
178 | /* Always clear the input owner_id (zero is an invalid ID) */ |
179 | ||
180 | *owner_id_ptr = 0; | |
181 | ||
182 | /* Zero is not a valid owner_iD */ | |
183 | ||
defba1d8 | 184 | if (owner_id == 0) { |
b8e4d893 | 185 | ACPI_ERROR((AE_INFO, "Invalid owner_id: %2.2X", owner_id)); |
0c9938cc RM |
186 | return_VOID; |
187 | } | |
188 | ||
189 | /* Mutex for the global ID mask */ | |
190 | ||
4be44fcd LB |
191 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
192 | if (ACPI_FAILURE(status)) { | |
0c9938cc | 193 | return_VOID; |
f9f4601f RM |
194 | } |
195 | ||
aff8c277 RM |
196 | /* Normalize the ID to zero */ |
197 | ||
198 | owner_id--; | |
0c9938cc | 199 | |
28f55ebc BM |
200 | /* Decode ID to index/offset pair */ |
201 | ||
202 | index = ACPI_DIV_32(owner_id); | |
203 | bit = 1 << ACPI_MOD_32(owner_id); | |
204 | ||
0c9938cc | 205 | /* Free the owner ID only if it is valid */ |
f9f4601f | 206 | |
28f55ebc BM |
207 | if (acpi_gbl_owner_id_mask[index] & bit) { |
208 | acpi_gbl_owner_id_mask[index] ^= bit; | |
209 | } else { | |
b8e4d893 BM |
210 | ACPI_ERROR((AE_INFO, |
211 | "Release of non-allocated owner_id: %2.2X", | |
212 | owner_id + 1)); | |
f9f4601f | 213 | } |
f9f4601f | 214 | |
4be44fcd | 215 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
0c9938cc | 216 | return_VOID; |
f9f4601f RM |
217 | } |
218 | ||
44f6c012 RM |
219 | /******************************************************************************* |
220 | * | |
221 | * FUNCTION: acpi_ut_strupr (strupr) | |
222 | * | |
223 | * PARAMETERS: src_string - The source string to convert | |
224 | * | |
0c9938cc | 225 | * RETURN: None |
44f6c012 RM |
226 | * |
227 | * DESCRIPTION: Convert string to uppercase | |
228 | * | |
229 | * NOTE: This is not a POSIX function, so it appears here, not in utclib.c | |
230 | * | |
231 | ******************************************************************************/ | |
232 | ||
4be44fcd | 233 | void acpi_ut_strupr(char *src_string) |
44f6c012 | 234 | { |
4be44fcd | 235 | char *string; |
44f6c012 | 236 | |
4be44fcd | 237 | ACPI_FUNCTION_ENTRY(); |
44f6c012 | 238 | |
73459f73 | 239 | if (!src_string) { |
0c9938cc | 240 | return; |
73459f73 RM |
241 | } |
242 | ||
44f6c012 RM |
243 | /* Walk entire string, uppercasing the letters */ |
244 | ||
245 | for (string = src_string; *string; string++) { | |
4be44fcd | 246 | *string = (char)ACPI_TOUPPER(*string); |
44f6c012 RM |
247 | } |
248 | ||
0c9938cc | 249 | return; |
44f6c012 RM |
250 | } |
251 | ||
1da177e4 LT |
252 | /******************************************************************************* |
253 | * | |
254 | * FUNCTION: acpi_ut_print_string | |
255 | * | |
256 | * PARAMETERS: String - Null terminated ASCII string | |
44f6c012 | 257 | * max_length - Maximum output length |
1da177e4 LT |
258 | * |
259 | * RETURN: None | |
260 | * | |
261 | * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape | |
262 | * sequences. | |
263 | * | |
264 | ******************************************************************************/ | |
265 | ||
4be44fcd | 266 | void acpi_ut_print_string(char *string, u8 max_length) |
1da177e4 | 267 | { |
4be44fcd | 268 | u32 i; |
1da177e4 LT |
269 | |
270 | if (!string) { | |
4be44fcd | 271 | acpi_os_printf("<\"NULL STRING PTR\">"); |
1da177e4 LT |
272 | return; |
273 | } | |
274 | ||
4be44fcd | 275 | acpi_os_printf("\""); |
1da177e4 | 276 | for (i = 0; string[i] && (i < max_length); i++) { |
52fc0b02 | 277 | |
1da177e4 LT |
278 | /* Escape sequences */ |
279 | ||
280 | switch (string[i]) { | |
281 | case 0x07: | |
4be44fcd | 282 | acpi_os_printf("\\a"); /* BELL */ |
1da177e4 LT |
283 | break; |
284 | ||
285 | case 0x08: | |
4be44fcd | 286 | acpi_os_printf("\\b"); /* BACKSPACE */ |
1da177e4 LT |
287 | break; |
288 | ||
289 | case 0x0C: | |
4be44fcd | 290 | acpi_os_printf("\\f"); /* FORMFEED */ |
1da177e4 LT |
291 | break; |
292 | ||
293 | case 0x0A: | |
4be44fcd | 294 | acpi_os_printf("\\n"); /* LINEFEED */ |
1da177e4 LT |
295 | break; |
296 | ||
297 | case 0x0D: | |
4be44fcd | 298 | acpi_os_printf("\\r"); /* CARRIAGE RETURN */ |
1da177e4 LT |
299 | break; |
300 | ||
301 | case 0x09: | |
4be44fcd | 302 | acpi_os_printf("\\t"); /* HORIZONTAL TAB */ |
1da177e4 LT |
303 | break; |
304 | ||
305 | case 0x0B: | |
4be44fcd | 306 | acpi_os_printf("\\v"); /* VERTICAL TAB */ |
1da177e4 LT |
307 | break; |
308 | ||
4be44fcd LB |
309 | case '\'': /* Single Quote */ |
310 | case '\"': /* Double Quote */ | |
311 | case '\\': /* Backslash */ | |
312 | acpi_os_printf("\\%c", (int)string[i]); | |
1da177e4 LT |
313 | break; |
314 | ||
315 | default: | |
316 | ||
317 | /* Check for printable character or hex escape */ | |
318 | ||
4be44fcd | 319 | if (ACPI_IS_PRINT(string[i])) { |
1da177e4 LT |
320 | /* This is a normal character */ |
321 | ||
4be44fcd LB |
322 | acpi_os_printf("%c", (int)string[i]); |
323 | } else { | |
1da177e4 LT |
324 | /* All others will be Hex escapes */ |
325 | ||
4be44fcd | 326 | acpi_os_printf("\\x%2.2X", (s32) string[i]); |
1da177e4 LT |
327 | } |
328 | break; | |
329 | } | |
330 | } | |
4be44fcd | 331 | acpi_os_printf("\""); |
1da177e4 LT |
332 | |
333 | if (i == max_length && string[i]) { | |
4be44fcd | 334 | acpi_os_printf("..."); |
1da177e4 LT |
335 | } |
336 | } | |
337 | ||
1da177e4 LT |
338 | /******************************************************************************* |
339 | * | |
340 | * FUNCTION: acpi_ut_dword_byte_swap | |
341 | * | |
342 | * PARAMETERS: Value - Value to be converted | |
343 | * | |
44f6c012 RM |
344 | * RETURN: u32 integer with bytes swapped |
345 | * | |
1da177e4 LT |
346 | * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) |
347 | * | |
348 | ******************************************************************************/ | |
349 | ||
4be44fcd | 350 | u32 acpi_ut_dword_byte_swap(u32 value) |
1da177e4 LT |
351 | { |
352 | union { | |
4be44fcd LB |
353 | u32 value; |
354 | u8 bytes[4]; | |
1da177e4 | 355 | } out; |
1da177e4 | 356 | union { |
4be44fcd LB |
357 | u32 value; |
358 | u8 bytes[4]; | |
1da177e4 LT |
359 | } in; |
360 | ||
4be44fcd | 361 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
362 | |
363 | in.value = value; | |
364 | ||
365 | out.bytes[0] = in.bytes[3]; | |
366 | out.bytes[1] = in.bytes[2]; | |
367 | out.bytes[2] = in.bytes[1]; | |
368 | out.bytes[3] = in.bytes[0]; | |
369 | ||
370 | return (out.value); | |
371 | } | |
372 | ||
1da177e4 LT |
373 | /******************************************************************************* |
374 | * | |
375 | * FUNCTION: acpi_ut_set_integer_width | |
376 | * | |
377 | * PARAMETERS: Revision From DSDT header | |
378 | * | |
379 | * RETURN: None | |
380 | * | |
381 | * DESCRIPTION: Set the global integer bit width based upon the revision | |
382 | * of the DSDT. For Revision 1 and 0, Integers are 32 bits. | |
383 | * For Revision 2 and above, Integers are 64 bits. Yes, this | |
384 | * makes a difference. | |
385 | * | |
386 | ******************************************************************************/ | |
387 | ||
4be44fcd | 388 | void acpi_ut_set_integer_width(u8 revision) |
1da177e4 LT |
389 | { |
390 | ||
391 | if (revision <= 1) { | |
392 | acpi_gbl_integer_bit_width = 32; | |
393 | acpi_gbl_integer_nybble_width = 8; | |
394 | acpi_gbl_integer_byte_width = 4; | |
4be44fcd | 395 | } else { |
1da177e4 LT |
396 | acpi_gbl_integer_bit_width = 64; |
397 | acpi_gbl_integer_nybble_width = 16; | |
398 | acpi_gbl_integer_byte_width = 8; | |
399 | } | |
400 | } | |
401 | ||
1da177e4 LT |
402 | #ifdef ACPI_DEBUG_OUTPUT |
403 | /******************************************************************************* | |
404 | * | |
405 | * FUNCTION: acpi_ut_display_init_pathname | |
406 | * | |
44f6c012 RM |
407 | * PARAMETERS: Type - Object type of the node |
408 | * obj_handle - Handle whose pathname will be displayed | |
1da177e4 LT |
409 | * Path - Additional path string to be appended. |
410 | * (NULL if no extra path) | |
411 | * | |
412 | * RETURN: acpi_status | |
413 | * | |
414 | * DESCRIPTION: Display full pathname of an object, DEBUG ONLY | |
415 | * | |
416 | ******************************************************************************/ | |
417 | ||
418 | void | |
4be44fcd LB |
419 | acpi_ut_display_init_pathname(u8 type, |
420 | struct acpi_namespace_node *obj_handle, | |
421 | char *path) | |
1da177e4 | 422 | { |
4be44fcd LB |
423 | acpi_status status; |
424 | struct acpi_buffer buffer; | |
1da177e4 | 425 | |
4be44fcd | 426 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
427 | |
428 | /* Only print the path if the appropriate debug level is enabled */ | |
429 | ||
430 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { | |
431 | return; | |
432 | } | |
433 | ||
434 | /* Get the full pathname to the node */ | |
435 | ||
436 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; | |
4be44fcd LB |
437 | status = acpi_ns_handle_to_pathname(obj_handle, &buffer); |
438 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
439 | return; |
440 | } | |
441 | ||
442 | /* Print what we're doing */ | |
443 | ||
444 | switch (type) { | |
445 | case ACPI_TYPE_METHOD: | |
4be44fcd | 446 | acpi_os_printf("Executing "); |
1da177e4 LT |
447 | break; |
448 | ||
449 | default: | |
4be44fcd | 450 | acpi_os_printf("Initializing "); |
1da177e4 LT |
451 | break; |
452 | } | |
453 | ||
454 | /* Print the object type and pathname */ | |
455 | ||
4be44fcd LB |
456 | acpi_os_printf("%-12s %s", |
457 | acpi_ut_get_type_name(type), (char *)buffer.pointer); | |
1da177e4 LT |
458 | |
459 | /* Extra path is used to append names like _STA, _INI, etc. */ | |
460 | ||
461 | if (path) { | |
4be44fcd | 462 | acpi_os_printf(".%s", path); |
1da177e4 | 463 | } |
4be44fcd | 464 | acpi_os_printf("\n"); |
1da177e4 | 465 | |
8313524a | 466 | ACPI_FREE(buffer.pointer); |
1da177e4 LT |
467 | } |
468 | #endif | |
469 | ||
1da177e4 LT |
470 | /******************************************************************************* |
471 | * | |
472 | * FUNCTION: acpi_ut_valid_acpi_name | |
473 | * | |
44f6c012 | 474 | * PARAMETERS: Name - The name to be examined |
1da177e4 | 475 | * |
44f6c012 | 476 | * RETURN: TRUE if the name is valid, FALSE otherwise |
1da177e4 LT |
477 | * |
478 | * DESCRIPTION: Check for a valid ACPI name. Each character must be one of: | |
479 | * 1) Upper case alpha | |
480 | * 2) numeric | |
481 | * 3) underscore | |
482 | * | |
483 | ******************************************************************************/ | |
484 | ||
4be44fcd | 485 | u8 acpi_ut_valid_acpi_name(u32 name) |
1da177e4 | 486 | { |
4be44fcd LB |
487 | char *name_ptr = (char *)&name; |
488 | char character; | |
489 | acpi_native_uint i; | |
1da177e4 | 490 | |
4be44fcd | 491 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
492 | |
493 | for (i = 0; i < ACPI_NAME_SIZE; i++) { | |
494 | character = *name_ptr; | |
495 | name_ptr++; | |
496 | ||
497 | if (!((character == '_') || | |
4be44fcd LB |
498 | (character >= 'A' && character <= 'Z') || |
499 | (character >= '0' && character <= '9'))) { | |
1da177e4 LT |
500 | return (FALSE); |
501 | } | |
502 | } | |
503 | ||
504 | return (TRUE); | |
505 | } | |
506 | ||
1da177e4 LT |
507 | /******************************************************************************* |
508 | * | |
509 | * FUNCTION: acpi_ut_valid_acpi_character | |
510 | * | |
511 | * PARAMETERS: Character - The character to be examined | |
512 | * | |
513 | * RETURN: 1 if Character may appear in a name, else 0 | |
514 | * | |
515 | * DESCRIPTION: Check for a printable character | |
516 | * | |
517 | ******************************************************************************/ | |
518 | ||
4be44fcd | 519 | u8 acpi_ut_valid_acpi_character(char character) |
1da177e4 LT |
520 | { |
521 | ||
4be44fcd | 522 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 523 | |
4be44fcd LB |
524 | return ((u8) ((character == '_') || |
525 | (character >= 'A' && character <= 'Z') || | |
526 | (character >= '0' && character <= '9'))); | |
1da177e4 LT |
527 | } |
528 | ||
1da177e4 LT |
529 | /******************************************************************************* |
530 | * | |
531 | * FUNCTION: acpi_ut_strtoul64 | |
532 | * | |
533 | * PARAMETERS: String - Null terminated string | |
534 | * Base - Radix of the string: 10, 16, or ACPI_ANY_BASE | |
535 | * ret_integer - Where the converted integer is returned | |
536 | * | |
537 | * RETURN: Status and Converted value | |
538 | * | |
539 | * DESCRIPTION: Convert a string into an unsigned value. | |
540 | * NOTE: Does not support Octal strings, not needed. | |
541 | * | |
542 | ******************************************************************************/ | |
543 | ||
544 | acpi_status | |
4be44fcd | 545 | acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer) |
1da177e4 | 546 | { |
4be44fcd LB |
547 | u32 this_digit = 0; |
548 | acpi_integer return_value = 0; | |
549 | acpi_integer quotient; | |
1da177e4 | 550 | |
4be44fcd | 551 | ACPI_FUNCTION_TRACE("ut_stroul64"); |
1da177e4 LT |
552 | |
553 | if ((!string) || !(*string)) { | |
554 | goto error_exit; | |
555 | } | |
556 | ||
557 | switch (base) { | |
558 | case ACPI_ANY_BASE: | |
559 | case 10: | |
560 | case 16: | |
561 | break; | |
562 | ||
563 | default: | |
564 | /* Invalid Base */ | |
4be44fcd | 565 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
566 | } |
567 | ||
568 | /* Skip over any white space in the buffer */ | |
569 | ||
4be44fcd | 570 | while (ACPI_IS_SPACE(*string) || *string == '\t') { |
1da177e4 LT |
571 | string++; |
572 | } | |
573 | ||
574 | /* | |
575 | * If the input parameter Base is zero, then we need to | |
576 | * determine if it is decimal or hexadecimal: | |
577 | */ | |
578 | if (base == 0) { | |
4be44fcd | 579 | if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) { |
1da177e4 LT |
580 | base = 16; |
581 | string += 2; | |
4be44fcd | 582 | } else { |
1da177e4 LT |
583 | base = 10; |
584 | } | |
585 | } | |
586 | ||
587 | /* | |
588 | * For hexadecimal base, skip over the leading | |
589 | * 0 or 0x, if they are present. | |
590 | */ | |
591 | if ((base == 16) && | |
4be44fcd | 592 | (*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) { |
1da177e4 LT |
593 | string += 2; |
594 | } | |
595 | ||
596 | /* Any string left? */ | |
597 | ||
598 | if (!(*string)) { | |
599 | goto error_exit; | |
600 | } | |
601 | ||
602 | /* Main loop: convert the string to a 64-bit integer */ | |
603 | ||
604 | while (*string) { | |
4be44fcd | 605 | if (ACPI_IS_DIGIT(*string)) { |
52fc0b02 | 606 | |
1da177e4 LT |
607 | /* Convert ASCII 0-9 to Decimal value */ |
608 | ||
4be44fcd LB |
609 | this_digit = ((u8) * string) - '0'; |
610 | } else { | |
1da177e4 | 611 | if (base == 10) { |
52fc0b02 | 612 | |
1da177e4 LT |
613 | /* Digit is out of range */ |
614 | ||
615 | goto error_exit; | |
616 | } | |
617 | ||
4be44fcd LB |
618 | this_digit = (u8) ACPI_TOUPPER(*string); |
619 | if (ACPI_IS_XDIGIT((char)this_digit)) { | |
52fc0b02 | 620 | |
1da177e4 LT |
621 | /* Convert ASCII Hex char to value */ |
622 | ||
623 | this_digit = this_digit - 'A' + 10; | |
4be44fcd | 624 | } else { |
1da177e4 LT |
625 | /* |
626 | * We allow non-hex chars, just stop now, same as end-of-string. | |
627 | * See ACPI spec, string-to-integer conversion. | |
628 | */ | |
629 | break; | |
630 | } | |
631 | } | |
632 | ||
633 | /* Divide the digit into the correct position */ | |
634 | ||
4be44fcd LB |
635 | (void) |
636 | acpi_ut_short_divide((ACPI_INTEGER_MAX - | |
637 | (acpi_integer) this_digit), base, | |
638 | "ient, NULL); | |
1da177e4 LT |
639 | if (return_value > quotient) { |
640 | goto error_exit; | |
641 | } | |
642 | ||
643 | return_value *= base; | |
644 | return_value += this_digit; | |
645 | string++; | |
646 | } | |
647 | ||
648 | /* All done, normal exit */ | |
649 | ||
650 | *ret_integer = return_value; | |
4be44fcd | 651 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 652 | |
4be44fcd | 653 | error_exit: |
1da177e4 LT |
654 | /* Base was set/validated above */ |
655 | ||
656 | if (base == 10) { | |
4be44fcd LB |
657 | return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT); |
658 | } else { | |
659 | return_ACPI_STATUS(AE_BAD_HEX_CONSTANT); | |
1da177e4 LT |
660 | } |
661 | } | |
662 | ||
1da177e4 LT |
663 | /******************************************************************************* |
664 | * | |
665 | * FUNCTION: acpi_ut_create_update_state_and_push | |
666 | * | |
44f6c012 | 667 | * PARAMETERS: Object - Object to be added to the new state |
1da177e4 LT |
668 | * Action - Increment/Decrement |
669 | * state_list - List the state will be added to | |
670 | * | |
44f6c012 | 671 | * RETURN: Status |
1da177e4 LT |
672 | * |
673 | * DESCRIPTION: Create a new state and push it | |
674 | * | |
675 | ******************************************************************************/ | |
676 | ||
677 | acpi_status | |
4be44fcd LB |
678 | acpi_ut_create_update_state_and_push(union acpi_operand_object *object, |
679 | u16 action, | |
680 | union acpi_generic_state **state_list) | |
1da177e4 | 681 | { |
4be44fcd | 682 | union acpi_generic_state *state; |
1da177e4 | 683 | |
4be44fcd | 684 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
685 | |
686 | /* Ignore null objects; these are expected */ | |
687 | ||
688 | if (!object) { | |
689 | return (AE_OK); | |
690 | } | |
691 | ||
4be44fcd | 692 | state = acpi_ut_create_update_state(object, action); |
1da177e4 LT |
693 | if (!state) { |
694 | return (AE_NO_MEMORY); | |
695 | } | |
696 | ||
4be44fcd | 697 | acpi_ut_push_generic_state(state_list, state); |
1da177e4 LT |
698 | return (AE_OK); |
699 | } | |
700 | ||
1da177e4 LT |
701 | /******************************************************************************* |
702 | * | |
703 | * FUNCTION: acpi_ut_walk_package_tree | |
704 | * | |
44f6c012 RM |
705 | * PARAMETERS: source_object - The package to walk |
706 | * target_object - Target object (if package is being copied) | |
707 | * walk_callback - Called once for each package element | |
708 | * Context - Passed to the callback function | |
1da177e4 LT |
709 | * |
710 | * RETURN: Status | |
711 | * | |
712 | * DESCRIPTION: Walk through a package | |
713 | * | |
714 | ******************************************************************************/ | |
715 | ||
716 | acpi_status | |
4be44fcd LB |
717 | acpi_ut_walk_package_tree(union acpi_operand_object * source_object, |
718 | void *target_object, | |
719 | acpi_pkg_callback walk_callback, void *context) | |
1da177e4 | 720 | { |
4be44fcd LB |
721 | acpi_status status = AE_OK; |
722 | union acpi_generic_state *state_list = NULL; | |
723 | union acpi_generic_state *state; | |
724 | u32 this_index; | |
725 | union acpi_operand_object *this_source_obj; | |
1da177e4 | 726 | |
4be44fcd | 727 | ACPI_FUNCTION_TRACE("ut_walk_package_tree"); |
1da177e4 | 728 | |
4be44fcd | 729 | state = acpi_ut_create_pkg_state(source_object, target_object, 0); |
1da177e4 | 730 | if (!state) { |
4be44fcd | 731 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
732 | } |
733 | ||
734 | while (state) { | |
52fc0b02 | 735 | |
1da177e4 LT |
736 | /* Get one element of the package */ |
737 | ||
4be44fcd | 738 | this_index = state->pkg.index; |
1da177e4 | 739 | this_source_obj = (union acpi_operand_object *) |
4be44fcd | 740 | state->pkg.source_object->package.elements[this_index]; |
1da177e4 LT |
741 | |
742 | /* | |
743 | * Check for: | |
744 | * 1) An uninitialized package element. It is completely | |
745 | * legal to declare a package and leave it uninitialized | |
746 | * 2) Not an internal object - can be a namespace node instead | |
747 | * 3) Any type other than a package. Packages are handled in else | |
748 | * case below. | |
749 | */ | |
750 | if ((!this_source_obj) || | |
4be44fcd LB |
751 | (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != |
752 | ACPI_DESC_TYPE_OPERAND) | |
753 | || (ACPI_GET_OBJECT_TYPE(this_source_obj) != | |
754 | ACPI_TYPE_PACKAGE)) { | |
755 | status = | |
756 | walk_callback(ACPI_COPY_TYPE_SIMPLE, | |
757 | this_source_obj, state, context); | |
758 | if (ACPI_FAILURE(status)) { | |
759 | return_ACPI_STATUS(status); | |
1da177e4 LT |
760 | } |
761 | ||
762 | state->pkg.index++; | |
4be44fcd LB |
763 | while (state->pkg.index >= |
764 | state->pkg.source_object->package.count) { | |
1da177e4 LT |
765 | /* |
766 | * We've handled all of the objects at this level, This means | |
767 | * that we have just completed a package. That package may | |
768 | * have contained one or more packages itself. | |
769 | * | |
770 | * Delete this state and pop the previous state (package). | |
771 | */ | |
4be44fcd LB |
772 | acpi_ut_delete_generic_state(state); |
773 | state = acpi_ut_pop_generic_state(&state_list); | |
1da177e4 LT |
774 | |
775 | /* Finished when there are no more states */ | |
776 | ||
777 | if (!state) { | |
778 | /* | |
779 | * We have handled all of the objects in the top level | |
780 | * package just add the length of the package objects | |
781 | * and exit | |
782 | */ | |
4be44fcd | 783 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
784 | } |
785 | ||
786 | /* | |
787 | * Go back up a level and move the index past the just | |
788 | * completed package object. | |
789 | */ | |
790 | state->pkg.index++; | |
791 | } | |
4be44fcd | 792 | } else { |
1da177e4 LT |
793 | /* This is a subobject of type package */ |
794 | ||
4be44fcd LB |
795 | status = |
796 | walk_callback(ACPI_COPY_TYPE_PACKAGE, | |
797 | this_source_obj, state, context); | |
798 | if (ACPI_FAILURE(status)) { | |
799 | return_ACPI_STATUS(status); | |
1da177e4 LT |
800 | } |
801 | ||
802 | /* | |
803 | * Push the current state and create a new one | |
804 | * The callback above returned a new target package object. | |
805 | */ | |
4be44fcd LB |
806 | acpi_ut_push_generic_state(&state_list, state); |
807 | state = acpi_ut_create_pkg_state(this_source_obj, | |
808 | state->pkg. | |
809 | this_target_obj, 0); | |
1da177e4 | 810 | if (!state) { |
4be44fcd | 811 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
812 | } |
813 | } | |
814 | } | |
815 | ||
816 | /* We should never get here */ | |
817 | ||
4be44fcd | 818 | return_ACPI_STATUS(AE_AML_INTERNAL); |
1da177e4 LT |
819 | } |
820 | ||
1da177e4 LT |
821 | /******************************************************************************* |
822 | * | |
b8e4d893 | 823 | * FUNCTION: acpi_ut_error, acpi_ut_warning, acpi_ut_info |
1da177e4 LT |
824 | * |
825 | * PARAMETERS: module_name - Caller's module name (for error output) | |
826 | * line_number - Caller's line number (for error output) | |
b8e4d893 | 827 | * Format - Printf format string + additional args |
1da177e4 LT |
828 | * |
829 | * RETURN: None | |
830 | * | |
b8e4d893 | 831 | * DESCRIPTION: Print message with module/line/version info |
1da177e4 LT |
832 | * |
833 | ******************************************************************************/ | |
834 | ||
b8e4d893 BM |
835 | void ACPI_INTERNAL_VAR_XFACE |
836 | acpi_ut_error(char *module_name, u32 line_number, char *format, ...) | |
1da177e4 | 837 | { |
b8e4d893 | 838 | va_list args; |
1da177e4 | 839 | |
4a90c7e8 | 840 | acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number); |
b8e4d893 BM |
841 | |
842 | va_start(args, format); | |
843 | acpi_os_vprintf(format, args); | |
844 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | |
1da177e4 LT |
845 | } |
846 | ||
b8e4d893 BM |
847 | void ACPI_INTERNAL_VAR_XFACE |
848 | acpi_ut_exception(char *module_name, | |
849 | u32 line_number, acpi_status status, char *format, ...) | |
850 | { | |
851 | va_list args; | |
1da177e4 | 852 | |
b8e4d893 BM |
853 | acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name, |
854 | line_number, acpi_format_exception(status)); | |
855 | ||
856 | va_start(args, format); | |
857 | acpi_os_vprintf(format, args); | |
858 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | |
859 | } | |
860 | ||
861 | void ACPI_INTERNAL_VAR_XFACE | |
862 | acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) | |
1da177e4 | 863 | { |
b8e4d893 | 864 | va_list args; |
1da177e4 | 865 | |
4a90c7e8 | 866 | acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number); |
b8e4d893 BM |
867 | |
868 | va_start(args, format); | |
869 | acpi_os_vprintf(format, args); | |
870 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | |
871 | } | |
872 | ||
873 | void ACPI_INTERNAL_VAR_XFACE | |
874 | acpi_ut_info(char *module_name, u32 line_number, char *format, ...) | |
875 | { | |
876 | va_list args; | |
877 | ||
878 | acpi_os_printf("ACPI (%s-%04d): ", module_name, line_number); | |
879 | ||
880 | va_start(args, format); | |
881 | acpi_os_vprintf(format, args); | |
882 | acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); | |
1da177e4 | 883 | } |