blob: 36d88158f9f4d0ddea7c166dea5f12b3bf771c1b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: utmisc - common utility procedures
4 *
5 ******************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Thomas Renningerbe63c922006-06-02 15:58:00 -040044#include <linux/module.h>
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
47#include <acpi/acnamesp.h>
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("utmisc")
Robert Moore44f6c012005-04-18 22:49:35 -040051
52/*******************************************************************************
53 *
Bob Moore793c2382006-03-31 00:00:00 -050054 * FUNCTION: acpi_ut_is_aml_table
55 *
56 * PARAMETERS: Table - An ACPI table
57 *
58 * RETURN: TRUE if table contains executable AML; FALSE otherwise
59 *
60 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
61 * Currently, these are DSDT,SSDT,PSDT. All other table types are
62 * data tables that do not contain AML code.
63 *
64 ******************************************************************************/
65u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
66{
67
Bob Mooref6dd9222006-07-07 20:44:38 -040068 /* These are the only tables that contain executable AML */
Bob Moore793c2382006-03-31 00:00:00 -050069
Bob Mooref3d2e782007-02-02 19:48:18 +030070 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
71 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
72 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Bob Moore793c2382006-03-31 00:00:00 -050073 return (TRUE);
74 }
75
76 return (FALSE);
77}
78
79/*******************************************************************************
80 *
Robert Mooref9f46012005-07-08 00:00:00 -040081 * FUNCTION: acpi_ut_allocate_owner_id
82 *
83 * PARAMETERS: owner_id - Where the new owner ID is returned
84 *
Robert Moore0c9938c2005-07-29 15:15:00 -070085 * RETURN: Status
86 *
87 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
88 * track objects created by the table or method, to be deleted
89 * when the method exits or the table is unloaded.
Robert Mooref9f46012005-07-08 00:00:00 -040090 *
91 ******************************************************************************/
Bob Moore793c2382006-03-31 00:00:00 -050092
Len Brown4be44fc2005-08-05 00:44:28 -040093acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
Robert Mooref9f46012005-07-08 00:00:00 -040094{
Len Brown4be44fc2005-08-05 00:44:28 -040095 acpi_native_uint i;
Bob Moorec51a4de2005-11-17 13:07:00 -050096 acpi_native_uint j;
Bob Moore28f55eb2005-12-02 18:27:00 -050097 acpi_native_uint k;
Len Brown4be44fc2005-08-05 00:44:28 -040098 acpi_status status;
Robert Mooref9f46012005-07-08 00:00:00 -040099
Bob Mooreb229cf92006-04-21 17:15:00 -0400100 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400101
Robert Mooreaff8c272005-09-02 17:24:17 -0400102 /* Guard against multiple allocations of ID to the same location */
103
104 if (*owner_id) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500105 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
106 *owner_id));
Robert Mooreaff8c272005-09-02 17:24:17 -0400107 return_ACPI_STATUS(AE_ALREADY_EXISTS);
108 }
109
Robert Moore0c9938c2005-07-29 15:15:00 -0700110 /* Mutex for the global ID mask */
111
Len Brown4be44fc2005-08-05 00:44:28 -0400112 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
113 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400115 }
116
Bob Moorec51a4de2005-11-17 13:07:00 -0500117 /*
118 * Find a free owner ID, cycle through all possible IDs on repeated
Bob Moore28f55eb2005-12-02 18:27:00 -0500119 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
120 * to be scanned twice.
Bob Moorec51a4de2005-11-17 13:07:00 -0500121 */
Bob Moore28f55eb2005-12-02 18:27:00 -0500122 for (i = 0, j = acpi_gbl_last_owner_id_index;
123 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
124 if (j >= ACPI_NUM_OWNERID_MASKS) {
125 j = 0; /* Wraparound to start of mask array */
Bob Moorec51a4de2005-11-17 13:07:00 -0500126 }
Robert Mooref9f46012005-07-08 00:00:00 -0400127
Bob Moore28f55eb2005-12-02 18:27:00 -0500128 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
129 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400130
Bob Moore28f55eb2005-12-02 18:27:00 -0500131 /* There are no free IDs in this mask */
Bob Moorec51a4de2005-11-17 13:07:00 -0500132
Bob Moore28f55eb2005-12-02 18:27:00 -0500133 break;
134 }
Bob Moorea18ecf42005-08-15 03:42:00 -0800135
Bob Moore28f55eb2005-12-02 18:27:00 -0500136 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
137 /*
138 * Found a free ID. The actual ID is the bit index plus one,
139 * making zero an invalid Owner ID. Save this as the last ID
140 * allocated and update the global ID mask.
141 */
142 acpi_gbl_owner_id_mask[j] |= (1 << k);
143
144 acpi_gbl_last_owner_id_index = (u8) j;
145 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
146
147 /*
148 * Construct encoded ID from the index and bit position
149 *
150 * Note: Last [j].k (bit 255) is never used and is marked
151 * permanently allocated (prevents +1 overflow)
152 */
153 *owner_id =
154 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
155
156 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
Bob Mooreb229cf92006-04-21 17:15:00 -0400157 "Allocated OwnerId: %2.2X\n",
Bob Moore28f55eb2005-12-02 18:27:00 -0500158 (unsigned int)*owner_id));
159 goto exit;
160 }
Robert Mooref9f46012005-07-08 00:00:00 -0400161 }
Bob Moore28f55eb2005-12-02 18:27:00 -0500162
163 acpi_gbl_next_owner_id_offset = 0;
Robert Mooref9f46012005-07-08 00:00:00 -0400164 }
165
166 /*
Bob Moorec51a4de2005-11-17 13:07:00 -0500167 * All owner_ids have been allocated. This typically should
Robert Mooref9f46012005-07-08 00:00:00 -0400168 * not happen since the IDs are reused after deallocation. The IDs are
169 * allocated upon table load (one per table) and method execution, and
170 * they are released when a table is unloaded or a method completes
171 * execution.
Bob Moorec51a4de2005-11-17 13:07:00 -0500172 *
173 * If this error happens, there may be very deep nesting of invoked control
174 * methods, or there may be a bug where the IDs are not released.
Robert Mooref9f46012005-07-08 00:00:00 -0400175 */
176 status = AE_OWNER_ID_LIMIT;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500177 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400178 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
Robert Mooref9f46012005-07-08 00:00:00 -0400179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 exit:
181 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
182 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400183}
184
Robert Mooref9f46012005-07-08 00:00:00 -0400185/*******************************************************************************
186 *
187 * FUNCTION: acpi_ut_release_owner_id
188 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700189 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
Robert Mooref9f46012005-07-08 00:00:00 -0400190 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700191 * RETURN: None. No error is returned because we are either exiting a
192 * control method or unloading a table. Either way, we would
193 * ignore any error anyway.
194 *
Bob Moore28f55eb2005-12-02 18:27:00 -0500195 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
Robert Mooref9f46012005-07-08 00:00:00 -0400196 *
197 ******************************************************************************/
198
Len Brown4be44fc2005-08-05 00:44:28 -0400199void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
Robert Mooref9f46012005-07-08 00:00:00 -0400200{
Len Brown4be44fc2005-08-05 00:44:28 -0400201 acpi_owner_id owner_id = *owner_id_ptr;
202 acpi_status status;
Bob Moore28f55eb2005-12-02 18:27:00 -0500203 acpi_native_uint index;
204 u32 bit;
Robert Mooref9f46012005-07-08 00:00:00 -0400205
Bob Mooreb229cf92006-04-21 17:15:00 -0400206 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400207
Robert Moore0c9938c2005-07-29 15:15:00 -0700208 /* Always clear the input owner_id (zero is an invalid ID) */
209
210 *owner_id_ptr = 0;
211
212 /* Zero is not a valid owner_iD */
213
Bob Mooredefba1d2005-12-16 17:05:00 -0500214 if (owner_id == 0) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400215 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
Robert Moore0c9938c2005-07-29 15:15:00 -0700216 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400217 }
218
Robert Moore0c9938c2005-07-29 15:15:00 -0700219 /* Mutex for the global ID mask */
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
222 if (ACPI_FAILURE(status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700223 return_VOID;
224 }
225
Robert Mooreaff8c272005-09-02 17:24:17 -0400226 /* Normalize the ID to zero */
227
228 owner_id--;
Robert Moore0c9938c2005-07-29 15:15:00 -0700229
Bob Moore28f55eb2005-12-02 18:27:00 -0500230 /* Decode ID to index/offset pair */
231
232 index = ACPI_DIV_32(owner_id);
233 bit = 1 << ACPI_MOD_32(owner_id);
234
Robert Moore0c9938c2005-07-29 15:15:00 -0700235 /* Free the owner ID only if it is valid */
Robert Mooref9f46012005-07-08 00:00:00 -0400236
Bob Moore28f55eb2005-12-02 18:27:00 -0500237 if (acpi_gbl_owner_id_mask[index] & bit) {
238 acpi_gbl_owner_id_mask[index] ^= bit;
239 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500240 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400241 "Release of non-allocated OwnerId: %2.2X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500242 owner_id + 1));
Robert Mooref9f46012005-07-08 00:00:00 -0400243 }
Robert Mooref9f46012005-07-08 00:00:00 -0400244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
Robert Moore0c9938c2005-07-29 15:15:00 -0700246 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400247}
248
Robert Mooref9f46012005-07-08 00:00:00 -0400249/*******************************************************************************
250 *
Robert Moore44f6c012005-04-18 22:49:35 -0400251 * FUNCTION: acpi_ut_strupr (strupr)
252 *
253 * PARAMETERS: src_string - The source string to convert
254 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700255 * RETURN: None
Robert Moore44f6c012005-04-18 22:49:35 -0400256 *
257 * DESCRIPTION: Convert string to uppercase
258 *
259 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
260 *
261 ******************************************************************************/
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263void acpi_ut_strupr(char *src_string)
Robert Moore44f6c012005-04-18 22:49:35 -0400264{
Len Brown4be44fc2005-08-05 00:44:28 -0400265 char *string;
Robert Moore44f6c012005-04-18 22:49:35 -0400266
Len Brown4be44fc2005-08-05 00:44:28 -0400267 ACPI_FUNCTION_ENTRY();
Robert Moore44f6c012005-04-18 22:49:35 -0400268
Robert Moore73459f72005-06-24 00:00:00 -0400269 if (!src_string) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700270 return;
Robert Moore73459f72005-06-24 00:00:00 -0400271 }
272
Robert Moore44f6c012005-04-18 22:49:35 -0400273 /* Walk entire string, uppercasing the letters */
274
275 for (string = src_string; *string; string++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400276 *string = (char)ACPI_TOUPPER(*string);
Robert Moore44f6c012005-04-18 22:49:35 -0400277 }
278
Robert Moore0c9938c2005-07-29 15:15:00 -0700279 return;
Robert Moore44f6c012005-04-18 22:49:35 -0400280}
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282/*******************************************************************************
283 *
284 * FUNCTION: acpi_ut_print_string
285 *
286 * PARAMETERS: String - Null terminated ASCII string
Robert Moore44f6c012005-04-18 22:49:35 -0400287 * max_length - Maximum output length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 *
289 * RETURN: None
290 *
291 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
292 * sequences.
293 *
294 ******************************************************************************/
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296void acpi_ut_print_string(char *string, u8 max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Len Brown4be44fc2005-08-05 00:44:28 -0400298 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 if (!string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400301 acpi_os_printf("<\"NULL STRING PTR\">");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return;
303 }
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 for (i = 0; string[i] && (i < max_length); i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* Escape sequences */
309
310 switch (string[i]) {
311 case 0x07:
Len Brown4be44fc2005-08-05 00:44:28 -0400312 acpi_os_printf("\\a"); /* BELL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 break;
314
315 case 0x08:
Len Brown4be44fc2005-08-05 00:44:28 -0400316 acpi_os_printf("\\b"); /* BACKSPACE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 break;
318
319 case 0x0C:
Len Brown4be44fc2005-08-05 00:44:28 -0400320 acpi_os_printf("\\f"); /* FORMFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 break;
322
323 case 0x0A:
Len Brown4be44fc2005-08-05 00:44:28 -0400324 acpi_os_printf("\\n"); /* LINEFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 break;
326
327 case 0x0D:
Len Brown4be44fc2005-08-05 00:44:28 -0400328 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 break;
330
331 case 0x09:
Len Brown4be44fc2005-08-05 00:44:28 -0400332 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 break;
334
335 case 0x0B:
Len Brown4be44fc2005-08-05 00:44:28 -0400336 acpi_os_printf("\\v"); /* VERTICAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 break;
338
Len Brown4be44fc2005-08-05 00:44:28 -0400339 case '\'': /* Single Quote */
340 case '\"': /* Double Quote */
341 case '\\': /* Backslash */
342 acpi_os_printf("\\%c", (int)string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 break;
344
345 default:
346
347 /* Check for printable character or hex escape */
348
Len Brown4be44fc2005-08-05 00:44:28 -0400349 if (ACPI_IS_PRINT(string[i])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /* This is a normal character */
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 acpi_os_printf("%c", (int)string[i]);
353 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 /* All others will be Hex escapes */
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 acpi_os_printf("\\x%2.2X", (s32) string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358 break;
359 }
360 }
Len Brown4be44fc2005-08-05 00:44:28 -0400361 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 if (i == max_length && string[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400364 acpi_os_printf("...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366}
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368/*******************************************************************************
369 *
370 * FUNCTION: acpi_ut_dword_byte_swap
371 *
372 * PARAMETERS: Value - Value to be converted
373 *
Robert Moore44f6c012005-04-18 22:49:35 -0400374 * RETURN: u32 integer with bytes swapped
375 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
377 *
378 ******************************************************************************/
379
Len Brown4be44fc2005-08-05 00:44:28 -0400380u32 acpi_ut_dword_byte_swap(u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
382 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400383 u32 value;
384 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 } out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400387 u32 value;
388 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 } in;
390
Len Brown4be44fc2005-08-05 00:44:28 -0400391 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 in.value = value;
394
395 out.bytes[0] = in.bytes[3];
396 out.bytes[1] = in.bytes[2];
397 out.bytes[2] = in.bytes[1];
398 out.bytes[3] = in.bytes[0];
399
400 return (out.value);
401}
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/*******************************************************************************
404 *
405 * FUNCTION: acpi_ut_set_integer_width
406 *
407 * PARAMETERS: Revision From DSDT header
408 *
409 * RETURN: None
410 *
411 * DESCRIPTION: Set the global integer bit width based upon the revision
412 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
413 * For Revision 2 and above, Integers are 64 bits. Yes, this
414 * makes a difference.
415 *
416 ******************************************************************************/
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418void acpi_ut_set_integer_width(u8 revision)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420
Bob Mooref3d2e782007-02-02 19:48:18 +0300421 if (revision < 2) {
Bob Mooref6dd9222006-07-07 20:44:38 -0400422
423 /* 32-bit case */
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 acpi_gbl_integer_bit_width = 32;
426 acpi_gbl_integer_nybble_width = 8;
427 acpi_gbl_integer_byte_width = 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400428 } else {
Bob Mooref6dd9222006-07-07 20:44:38 -0400429 /* 64-bit case (ACPI 2.0+) */
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 acpi_gbl_integer_bit_width = 64;
432 acpi_gbl_integer_nybble_width = 16;
433 acpi_gbl_integer_byte_width = 8;
434 }
435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#ifdef ACPI_DEBUG_OUTPUT
438/*******************************************************************************
439 *
440 * FUNCTION: acpi_ut_display_init_pathname
441 *
Robert Moore44f6c012005-04-18 22:49:35 -0400442 * PARAMETERS: Type - Object type of the node
443 * obj_handle - Handle whose pathname will be displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 * Path - Additional path string to be appended.
445 * (NULL if no extra path)
446 *
447 * RETURN: acpi_status
448 *
449 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
450 *
451 ******************************************************************************/
452
453void
Len Brown4be44fc2005-08-05 00:44:28 -0400454acpi_ut_display_init_pathname(u8 type,
455 struct acpi_namespace_node *obj_handle,
456 char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Len Brown4be44fc2005-08-05 00:44:28 -0400458 acpi_status status;
459 struct acpi_buffer buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 /* Only print the path if the appropriate debug level is enabled */
464
465 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
466 return;
467 }
468
469 /* Get the full pathname to the node */
470
471 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
Len Brown4be44fc2005-08-05 00:44:28 -0400472 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
473 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return;
475 }
476
477 /* Print what we're doing */
478
479 switch (type) {
480 case ACPI_TYPE_METHOD:
Len Brown4be44fc2005-08-05 00:44:28 -0400481 acpi_os_printf("Executing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 break;
483
484 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400485 acpi_os_printf("Initializing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487 }
488
489 /* Print the object type and pathname */
490
Len Brown4be44fc2005-08-05 00:44:28 -0400491 acpi_os_printf("%-12s %s",
492 acpi_ut_get_type_name(type), (char *)buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 /* Extra path is used to append names like _STA, _INI, etc. */
495
496 if (path) {
Len Brown4be44fc2005-08-05 00:44:28 -0400497 acpi_os_printf(".%s", path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Len Brown4be44fc2005-08-05 00:44:28 -0400499 acpi_os_printf("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Bob Moore83135242006-10-03 00:00:00 -0400501 ACPI_FREE(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503#endif
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505/*******************************************************************************
506 *
Bob Moore793c2382006-03-31 00:00:00 -0500507 * FUNCTION: acpi_ut_valid_acpi_char
508 *
509 * PARAMETERS: Char - The character to be examined
Bob Mooref6dd9222006-07-07 20:44:38 -0400510 * Position - Byte position (0-3)
Bob Moore793c2382006-03-31 00:00:00 -0500511 *
512 * RETURN: TRUE if the character is valid, FALSE otherwise
513 *
514 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
515 * 1) Upper case alpha
516 * 2) numeric
517 * 3) underscore
518 *
519 * We allow a '!' as the last character because of the ASF! table
520 *
521 ******************************************************************************/
522
523u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position)
524{
525
526 if (!((character >= 'A' && character <= 'Z') ||
527 (character >= '0' && character <= '9') || (character == '_'))) {
528
529 /* Allow a '!' in the last position */
530
531 if (character == '!' && position == 3) {
532 return (TRUE);
533 }
534
535 return (FALSE);
536 }
537
538 return (TRUE);
539}
540
541/*******************************************************************************
542 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 * FUNCTION: acpi_ut_valid_acpi_name
544 *
Robert Moore44f6c012005-04-18 22:49:35 -0400545 * PARAMETERS: Name - The name to be examined
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 *
Robert Moore44f6c012005-04-18 22:49:35 -0400547 * RETURN: TRUE if the name is valid, FALSE otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 *
549 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
550 * 1) Upper case alpha
551 * 2) numeric
552 * 3) underscore
553 *
554 ******************************************************************************/
555
Len Brown4be44fc2005-08-05 00:44:28 -0400556u8 acpi_ut_valid_acpi_name(u32 name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Len Brown4be44fc2005-08-05 00:44:28 -0400558 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore793c2382006-03-31 00:00:00 -0500563 if (!acpi_ut_valid_acpi_char
564 ((ACPI_CAST_PTR(char, &name))[i], i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return (FALSE);
566 }
567 }
568
569 return (TRUE);
570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572/*******************************************************************************
573 *
Bob Moore793c2382006-03-31 00:00:00 -0500574 * FUNCTION: acpi_ut_repair_name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 *
Bob Moore793c2382006-03-31 00:00:00 -0500576 * PARAMETERS: Name - The ACPI name to be repaired
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 *
Bob Moore793c2382006-03-31 00:00:00 -0500578 * RETURN: Repaired version of the name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 *
Bob Moore793c2382006-03-31 00:00:00 -0500580 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
581 * return the new name.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 *
583 ******************************************************************************/
584
Bob Moore3d81b232007-02-02 19:48:19 +0300585acpi_name acpi_ut_repair_name(char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Bob Moore793c2382006-03-31 00:00:00 -0500587 acpi_native_uint i;
Bob Moore3d81b232007-02-02 19:48:19 +0300588 char new_name[ACPI_NAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Bob Moore793c2382006-03-31 00:00:00 -0500590 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore3d81b232007-02-02 19:48:19 +0300591 new_name[i] = name[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Bob Moore793c2382006-03-31 00:00:00 -0500593 /*
594 * Replace a bad character with something printable, yet technically
595 * still invalid. This prevents any collisions with existing "good"
596 * names in the namespace.
597 */
Bob Moore3d81b232007-02-02 19:48:19 +0300598 if (!acpi_ut_valid_acpi_char(name[i], i)) {
Bob Moore793c2382006-03-31 00:00:00 -0500599 new_name[i] = '*';
600 }
601 }
602
Bob Moore3d81b232007-02-02 19:48:19 +0300603 return (*(u32 *) new_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606/*******************************************************************************
607 *
608 * FUNCTION: acpi_ut_strtoul64
609 *
610 * PARAMETERS: String - Null terminated string
Bob Moore41195322006-05-26 16:36:00 -0400611 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
612 * ACPI_ANY_BASE means 'in behalf of to_integer'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 * ret_integer - Where the converted integer is returned
614 *
615 * RETURN: Status and Converted value
616 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400617 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
618 * 32-bit or 64-bit conversion, depending on the current mode
619 * of the interpreter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 * NOTE: Does not support Octal strings, not needed.
621 *
622 ******************************************************************************/
623
624acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400625acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
Len Brown4be44fc2005-08-05 00:44:28 -0400627 u32 this_digit = 0;
628 acpi_integer return_value = 0;
629 acpi_integer quotient;
Bob Moore41195322006-05-26 16:36:00 -0400630 acpi_integer dividend;
631 u32 to_integer_op = (base == ACPI_ANY_BASE);
632 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
633 u8 valid_digits = 0;
634 u8 sign_of0x = 0;
635 u8 term = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Bob Mooref6dd9222006-07-07 20:44:38 -0400637 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 switch (base) {
640 case ACPI_ANY_BASE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 case 16:
642 break;
643
644 default:
645 /* Invalid Base */
Len Brown4be44fc2005-08-05 00:44:28 -0400646 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Bob Moore41195322006-05-26 16:36:00 -0400649 if (!string) {
650 goto error_exit;
651 }
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* Skip over any white space in the buffer */
654
Bob Moore41195322006-05-26 16:36:00 -0400655 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 string++;
657 }
658
Bob Moore41195322006-05-26 16:36:00 -0400659 if (to_integer_op) {
660 /*
661 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
662 * We need to determine if it is decimal or hexadecimal.
663 */
Len Brown4be44fc2005-08-05 00:44:28 -0400664 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
Bob Moore41195322006-05-26 16:36:00 -0400665 sign_of0x = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 base = 16;
Bob Moore41195322006-05-26 16:36:00 -0400667
668 /* Skip over the leading '0x' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 string += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400670 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 base = 10;
672 }
673 }
674
Bob Moore41195322006-05-26 16:36:00 -0400675 /* Any string left? Check that '0x' is not followed by white space. */
676
677 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
678 if (to_integer_op) {
679 goto error_exit;
680 } else {
681 goto all_done;
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
684
Bob Mooref6dd9222006-07-07 20:44:38 -0400685 /*
686 * Perform a 32-bit or 64-bit conversion, depending upon the current
687 * execution mode of the interpreter
688 */
Bob Moore41195322006-05-26 16:36:00 -0400689 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Bob Mooref6dd9222006-07-07 20:44:38 -0400691 /* Main loop: convert the string to a 32- or 64-bit integer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 while (*string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400694 if (ACPI_IS_DIGIT(*string)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /* Convert ASCII 0-9 to Decimal value */
697
Len Brown4be44fc2005-08-05 00:44:28 -0400698 this_digit = ((u8) * string) - '0';
Bob Moore41195322006-05-26 16:36:00 -0400699 } else if (base == 10) {
700
701 /* Digit is out of range; possible in to_integer case only */
702
703 term = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400704 } else {
Len Brown4be44fc2005-08-05 00:44:28 -0400705 this_digit = (u8) ACPI_TOUPPER(*string);
706 if (ACPI_IS_XDIGIT((char)this_digit)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 /* Convert ASCII Hex char to value */
709
710 this_digit = this_digit - 'A' + 10;
Len Brown4be44fc2005-08-05 00:44:28 -0400711 } else {
Bob Moore41195322006-05-26 16:36:00 -0400712 term = 1;
713 }
714 }
715
716 if (term) {
717 if (to_integer_op) {
718 goto error_exit;
719 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 break;
721 }
Bob Moore41195322006-05-26 16:36:00 -0400722 } else if ((valid_digits == 0) && (this_digit == 0)
723 && !sign_of0x) {
724
725 /* Skip zeros */
726 string++;
727 continue;
728 }
729
730 valid_digits++;
731
732 if (sign_of0x
733 && ((valid_digits > 16)
734 || ((valid_digits > 8) && mode32))) {
735 /*
736 * This is to_integer operation case.
737 * No any restrictions for string-to-integer conversion,
738 * see ACPI spec.
739 */
740 goto error_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742
743 /* Divide the digit into the correct position */
744
Len Brown4be44fc2005-08-05 00:44:28 -0400745 (void)
Bob Moore41195322006-05-26 16:36:00 -0400746 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
747 base, &quotient, NULL);
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (return_value > quotient) {
Bob Moore41195322006-05-26 16:36:00 -0400750 if (to_integer_op) {
751 goto error_exit;
752 } else {
753 break;
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
757 return_value *= base;
758 return_value += this_digit;
759 string++;
760 }
761
762 /* All done, normal exit */
763
Bob Moore41195322006-05-26 16:36:00 -0400764 all_done:
765
Bob Mooref6dd9222006-07-07 20:44:38 -0400766 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
767 ACPI_FORMAT_UINT64(return_value)));
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 *ret_integer = return_value;
Len Brown4be44fc2005-08-05 00:44:28 -0400770 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Len Brown4be44fc2005-08-05 00:44:28 -0400772 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 /* Base was set/validated above */
774
775 if (base == 10) {
Len Brown4be44fc2005-08-05 00:44:28 -0400776 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
777 } else {
778 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
780}
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782/*******************************************************************************
783 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 * FUNCTION: acpi_ut_create_update_state_and_push
785 *
Robert Moore44f6c012005-04-18 22:49:35 -0400786 * PARAMETERS: Object - Object to be added to the new state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 * Action - Increment/Decrement
788 * state_list - List the state will be added to
789 *
Robert Moore44f6c012005-04-18 22:49:35 -0400790 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 *
792 * DESCRIPTION: Create a new state and push it
793 *
794 ******************************************************************************/
795
796acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400797acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
798 u16 action,
799 union acpi_generic_state **state_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Len Brown4be44fc2005-08-05 00:44:28 -0400801 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 /* Ignore null objects; these are expected */
806
807 if (!object) {
808 return (AE_OK);
809 }
810
Len Brown4be44fc2005-08-05 00:44:28 -0400811 state = acpi_ut_create_update_state(object, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 if (!state) {
813 return (AE_NO_MEMORY);
814 }
815
Len Brown4be44fc2005-08-05 00:44:28 -0400816 acpi_ut_push_generic_state(state_list, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 return (AE_OK);
818}
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/*******************************************************************************
821 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 * FUNCTION: acpi_ut_walk_package_tree
823 *
Robert Moore44f6c012005-04-18 22:49:35 -0400824 * PARAMETERS: source_object - The package to walk
825 * target_object - Target object (if package is being copied)
826 * walk_callback - Called once for each package element
827 * Context - Passed to the callback function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 *
829 * RETURN: Status
830 *
831 * DESCRIPTION: Walk through a package
832 *
833 ******************************************************************************/
834
835acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400836acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
837 void *target_object,
838 acpi_pkg_callback walk_callback, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
Len Brown4be44fc2005-08-05 00:44:28 -0400840 acpi_status status = AE_OK;
841 union acpi_generic_state *state_list = NULL;
842 union acpi_generic_state *state;
843 u32 this_index;
844 union acpi_operand_object *this_source_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Bob Mooreb229cf92006-04-21 17:15:00 -0400846 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Len Brown4be44fc2005-08-05 00:44:28 -0400848 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400850 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852
853 while (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* Get one element of the package */
856
Len Brown4be44fc2005-08-05 00:44:28 -0400857 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 this_source_obj = (union acpi_operand_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400859 state->pkg.source_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 /*
862 * Check for:
863 * 1) An uninitialized package element. It is completely
864 * legal to declare a package and leave it uninitialized
865 * 2) Not an internal object - can be a namespace node instead
866 * 3) Any type other than a package. Packages are handled in else
867 * case below.
868 */
869 if ((!this_source_obj) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400870 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
871 ACPI_DESC_TYPE_OPERAND)
872 || (ACPI_GET_OBJECT_TYPE(this_source_obj) !=
873 ACPI_TYPE_PACKAGE)) {
874 status =
875 walk_callback(ACPI_COPY_TYPE_SIMPLE,
876 this_source_obj, state, context);
877 if (ACPI_FAILURE(status)) {
878 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
880
881 state->pkg.index++;
Len Brown4be44fc2005-08-05 00:44:28 -0400882 while (state->pkg.index >=
883 state->pkg.source_object->package.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /*
885 * We've handled all of the objects at this level, This means
886 * that we have just completed a package. That package may
887 * have contained one or more packages itself.
888 *
889 * Delete this state and pop the previous state (package).
890 */
Len Brown4be44fc2005-08-05 00:44:28 -0400891 acpi_ut_delete_generic_state(state);
892 state = acpi_ut_pop_generic_state(&state_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 /* Finished when there are no more states */
895
896 if (!state) {
897 /*
898 * We have handled all of the objects in the top level
899 * package just add the length of the package objects
900 * and exit
901 */
Len Brown4be44fc2005-08-05 00:44:28 -0400902 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
904
905 /*
906 * Go back up a level and move the index past the just
907 * completed package object.
908 */
909 state->pkg.index++;
910 }
Len Brown4be44fc2005-08-05 00:44:28 -0400911 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 /* This is a subobject of type package */
913
Len Brown4be44fc2005-08-05 00:44:28 -0400914 status =
915 walk_callback(ACPI_COPY_TYPE_PACKAGE,
916 this_source_obj, state, context);
917 if (ACPI_FAILURE(status)) {
918 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920
921 /*
922 * Push the current state and create a new one
923 * The callback above returned a new target package object.
924 */
Len Brown4be44fc2005-08-05 00:44:28 -0400925 acpi_ut_push_generic_state(&state_list, state);
926 state = acpi_ut_create_pkg_state(this_source_obj,
927 state->pkg.
928 this_target_obj, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400930 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932 }
933 }
934
935 /* We should never get here */
936
Len Brown4be44fc2005-08-05 00:44:28 -0400937 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940/*******************************************************************************
941 *
Bob Mooreb8e4d892006-01-27 16:43:00 -0500942 * FUNCTION: acpi_ut_error, acpi_ut_warning, acpi_ut_info
943 *
944 * PARAMETERS: module_name - Caller's module name (for error output)
945 * line_number - Caller's line number (for error output)
946 * Format - Printf format string + additional args
947 *
948 * RETURN: None
949 *
950 * DESCRIPTION: Print message with module/line/version info
951 *
952 ******************************************************************************/
953
954void ACPI_INTERNAL_VAR_XFACE
955acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
956{
957 va_list args;
958
959 acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number);
960
961 va_start(args, format);
962 acpi_os_vprintf(format, args);
963 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
964}
965
966void ACPI_INTERNAL_VAR_XFACE
967acpi_ut_exception(char *module_name,
968 u32 line_number, acpi_status status, char *format, ...)
969{
970 va_list args;
971
972 acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name,
973 line_number, acpi_format_exception(status));
974
975 va_start(args, format);
976 acpi_os_vprintf(format, args);
977 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
978}
Thomas Renningerbe63c922006-06-02 15:58:00 -0400979EXPORT_SYMBOL(acpi_ut_exception);
Bob Mooreb8e4d892006-01-27 16:43:00 -0500980
981void ACPI_INTERNAL_VAR_XFACE
982acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
983{
984 va_list args;
985
986 acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number);
987
988 va_start(args, format);
989 acpi_os_vprintf(format, args);
990 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
991}
Len Browncece9292006-06-26 23:04:31 -0400992
Bob Mooreb8e4d892006-01-27 16:43:00 -0500993void ACPI_INTERNAL_VAR_XFACE
994acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
995{
996 va_list args;
997
Bob Moorec5fc42a2007-02-02 19:48:19 +0300998 /*
999 * Removed module_name, line_number, and acpica version, not needed
1000 * for info output
1001 */
1002 acpi_os_printf("ACPI: ");
Bob Mooreb8e4d892006-01-27 16:43:00 -05001003
1004 va_start(args, format);
1005 acpi_os_vprintf(format, args);
Bob Moorec5fc42a2007-02-02 19:48:19 +03001006 acpi_os_printf("\n");
Bob Mooreb8e4d892006-01-27 16:43:00 -05001007}