blob: 1c9e250caefb0c0eb57809c543514b227bf89557 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: utmisc - common utility procedures
4 *
5 ******************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("utmisc")
Robert Moore44f6c012005-04-18 22:49:35 -040052
53/*******************************************************************************
54 *
Bob Moore84fb2c92007-02-02 19:48:19 +030055 * FUNCTION: acpi_ut_validate_exception
56 *
57 * PARAMETERS: Status - The acpi_status code to be formatted
58 *
59 * RETURN: A string containing the exception text. NULL if exception is
60 * not valid.
61 *
62 * DESCRIPTION: This function validates and translates an ACPI exception into
63 * an ASCII string.
64 *
65 ******************************************************************************/
66const char *acpi_ut_validate_exception(acpi_status status)
67{
Bob Moore11f2a612008-06-10 12:53:01 +080068 u32 sub_status;
Bob Moore84fb2c92007-02-02 19:48:19 +030069 const char *exception = NULL;
70
71 ACPI_FUNCTION_ENTRY();
72
73 /*
74 * Status is composed of two parts, a "type" and an actual code
75 */
76 sub_status = (status & ~AE_CODE_MASK);
77
78 switch (status & AE_CODE_MASK) {
79 case AE_CODE_ENVIRONMENTAL:
80
81 if (sub_status <= AE_CODE_ENV_MAX) {
82 exception = acpi_gbl_exception_names_env[sub_status];
83 }
84 break;
85
86 case AE_CODE_PROGRAMMER:
87
88 if (sub_status <= AE_CODE_PGM_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +080089 exception = acpi_gbl_exception_names_pgm[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +030090 }
91 break;
92
93 case AE_CODE_ACPI_TABLES:
94
95 if (sub_status <= AE_CODE_TBL_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +080096 exception = acpi_gbl_exception_names_tbl[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +030097 }
98 break;
99
100 case AE_CODE_AML:
101
102 if (sub_status <= AE_CODE_AML_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +0800103 exception = acpi_gbl_exception_names_aml[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +0300104 }
105 break;
106
107 case AE_CODE_CONTROL:
108
109 if (sub_status <= AE_CODE_CTRL_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +0800110 exception = acpi_gbl_exception_names_ctrl[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +0300111 }
112 break;
113
114 default:
115 break;
116 }
117
118 return (ACPI_CAST_PTR(const char, exception));
119}
120
121/*******************************************************************************
122 *
Bob Moore793c2382006-03-31 00:00:00 -0500123 * FUNCTION: acpi_ut_is_aml_table
124 *
125 * PARAMETERS: Table - An ACPI table
126 *
127 * RETURN: TRUE if table contains executable AML; FALSE otherwise
128 *
129 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
130 * Currently, these are DSDT,SSDT,PSDT. All other table types are
131 * data tables that do not contain AML code.
132 *
133 ******************************************************************************/
Bob Moore84fb2c92007-02-02 19:48:19 +0300134
Bob Moore793c2382006-03-31 00:00:00 -0500135u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
136{
137
Bob Mooref6dd9222006-07-07 20:44:38 -0400138 /* These are the only tables that contain executable AML */
Bob Moore793c2382006-03-31 00:00:00 -0500139
Bob Mooref3d2e782007-02-02 19:48:18 +0300140 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
141 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
142 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Bob Moore793c2382006-03-31 00:00:00 -0500143 return (TRUE);
144 }
145
146 return (FALSE);
147}
148
149/*******************************************************************************
150 *
Robert Mooref9f46012005-07-08 00:00:00 -0400151 * FUNCTION: acpi_ut_allocate_owner_id
152 *
153 * PARAMETERS: owner_id - Where the new owner ID is returned
154 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700155 * RETURN: Status
156 *
157 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
158 * track objects created by the table or method, to be deleted
159 * when the method exits or the table is unloaded.
Robert Mooref9f46012005-07-08 00:00:00 -0400160 *
161 ******************************************************************************/
Bob Moore793c2382006-03-31 00:00:00 -0500162
Len Brown4be44fc2005-08-05 00:44:28 -0400163acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
Robert Mooref9f46012005-07-08 00:00:00 -0400164{
Bob Moore67a119f2008-06-10 13:42:13 +0800165 u32 i;
166 u32 j;
167 u32 k;
Len Brown4be44fc2005-08-05 00:44:28 -0400168 acpi_status status;
Robert Mooref9f46012005-07-08 00:00:00 -0400169
Bob Mooreb229cf92006-04-21 17:15:00 -0400170 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400171
Robert Mooreaff8c272005-09-02 17:24:17 -0400172 /* Guard against multiple allocations of ID to the same location */
173
174 if (*owner_id) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500175 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
176 *owner_id));
Robert Mooreaff8c272005-09-02 17:24:17 -0400177 return_ACPI_STATUS(AE_ALREADY_EXISTS);
178 }
179
Robert Moore0c9938c2005-07-29 15:15:00 -0700180 /* Mutex for the global ID mask */
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
183 if (ACPI_FAILURE(status)) {
184 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400185 }
186
Bob Moorec51a4de2005-11-17 13:07:00 -0500187 /*
188 * Find a free owner ID, cycle through all possible IDs on repeated
Bob Moore28f55eb2005-12-02 18:27:00 -0500189 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
190 * to be scanned twice.
Bob Moorec51a4de2005-11-17 13:07:00 -0500191 */
Bob Moore28f55eb2005-12-02 18:27:00 -0500192 for (i = 0, j = acpi_gbl_last_owner_id_index;
193 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
194 if (j >= ACPI_NUM_OWNERID_MASKS) {
195 j = 0; /* Wraparound to start of mask array */
Bob Moorec51a4de2005-11-17 13:07:00 -0500196 }
Robert Mooref9f46012005-07-08 00:00:00 -0400197
Bob Moore28f55eb2005-12-02 18:27:00 -0500198 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
199 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400200
Bob Moore28f55eb2005-12-02 18:27:00 -0500201 /* There are no free IDs in this mask */
Bob Moorec51a4de2005-11-17 13:07:00 -0500202
Bob Moore28f55eb2005-12-02 18:27:00 -0500203 break;
204 }
Bob Moorea18ecf42005-08-15 03:42:00 -0800205
Bob Moore28f55eb2005-12-02 18:27:00 -0500206 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
207 /*
208 * Found a free ID. The actual ID is the bit index plus one,
209 * making zero an invalid Owner ID. Save this as the last ID
210 * allocated and update the global ID mask.
211 */
212 acpi_gbl_owner_id_mask[j] |= (1 << k);
213
214 acpi_gbl_last_owner_id_index = (u8) j;
215 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
216
217 /*
218 * Construct encoded ID from the index and bit position
219 *
220 * Note: Last [j].k (bit 255) is never used and is marked
221 * permanently allocated (prevents +1 overflow)
222 */
223 *owner_id =
224 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
225
226 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
Bob Mooreb229cf92006-04-21 17:15:00 -0400227 "Allocated OwnerId: %2.2X\n",
Bob Moore28f55eb2005-12-02 18:27:00 -0500228 (unsigned int)*owner_id));
229 goto exit;
230 }
Robert Mooref9f46012005-07-08 00:00:00 -0400231 }
Bob Moore28f55eb2005-12-02 18:27:00 -0500232
233 acpi_gbl_next_owner_id_offset = 0;
Robert Mooref9f46012005-07-08 00:00:00 -0400234 }
235
236 /*
Bob Moorec51a4de2005-11-17 13:07:00 -0500237 * All owner_ids have been allocated. This typically should
Robert Mooref9f46012005-07-08 00:00:00 -0400238 * not happen since the IDs are reused after deallocation. The IDs are
239 * allocated upon table load (one per table) and method execution, and
240 * they are released when a table is unloaded or a method completes
241 * execution.
Bob Moorec51a4de2005-11-17 13:07:00 -0500242 *
243 * If this error happens, there may be very deep nesting of invoked control
244 * methods, or there may be a bug where the IDs are not released.
Robert Mooref9f46012005-07-08 00:00:00 -0400245 */
246 status = AE_OWNER_ID_LIMIT;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500247 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400248 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
Robert Mooref9f46012005-07-08 00:00:00 -0400249
Len Brown4be44fc2005-08-05 00:44:28 -0400250 exit:
251 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
252 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400253}
254
Robert Mooref9f46012005-07-08 00:00:00 -0400255/*******************************************************************************
256 *
257 * FUNCTION: acpi_ut_release_owner_id
258 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700259 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
Robert Mooref9f46012005-07-08 00:00:00 -0400260 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700261 * RETURN: None. No error is returned because we are either exiting a
262 * control method or unloading a table. Either way, we would
263 * ignore any error anyway.
264 *
Bob Moore28f55eb2005-12-02 18:27:00 -0500265 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
Robert Mooref9f46012005-07-08 00:00:00 -0400266 *
267 ******************************************************************************/
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
Robert Mooref9f46012005-07-08 00:00:00 -0400270{
Len Brown4be44fc2005-08-05 00:44:28 -0400271 acpi_owner_id owner_id = *owner_id_ptr;
272 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800273 u32 index;
Bob Moore28f55eb2005-12-02 18:27:00 -0500274 u32 bit;
Robert Mooref9f46012005-07-08 00:00:00 -0400275
Bob Mooreb229cf92006-04-21 17:15:00 -0400276 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400277
Robert Moore0c9938c2005-07-29 15:15:00 -0700278 /* Always clear the input owner_id (zero is an invalid ID) */
279
280 *owner_id_ptr = 0;
281
282 /* Zero is not a valid owner_iD */
283
Bob Mooredefba1d2005-12-16 17:05:00 -0500284 if (owner_id == 0) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400285 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
Robert Moore0c9938c2005-07-29 15:15:00 -0700286 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400287 }
288
Robert Moore0c9938c2005-07-29 15:15:00 -0700289 /* Mutex for the global ID mask */
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
292 if (ACPI_FAILURE(status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700293 return_VOID;
294 }
295
Robert Mooreaff8c272005-09-02 17:24:17 -0400296 /* Normalize the ID to zero */
297
298 owner_id--;
Robert Moore0c9938c2005-07-29 15:15:00 -0700299
Bob Moore28f55eb2005-12-02 18:27:00 -0500300 /* Decode ID to index/offset pair */
301
302 index = ACPI_DIV_32(owner_id);
303 bit = 1 << ACPI_MOD_32(owner_id);
304
Robert Moore0c9938c2005-07-29 15:15:00 -0700305 /* Free the owner ID only if it is valid */
Robert Mooref9f46012005-07-08 00:00:00 -0400306
Bob Moore28f55eb2005-12-02 18:27:00 -0500307 if (acpi_gbl_owner_id_mask[index] & bit) {
308 acpi_gbl_owner_id_mask[index] ^= bit;
309 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500310 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400311 "Release of non-allocated OwnerId: %2.2X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500312 owner_id + 1));
Robert Mooref9f46012005-07-08 00:00:00 -0400313 }
Robert Mooref9f46012005-07-08 00:00:00 -0400314
Len Brown4be44fc2005-08-05 00:44:28 -0400315 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
Robert Moore0c9938c2005-07-29 15:15:00 -0700316 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400317}
318
Robert Mooref9f46012005-07-08 00:00:00 -0400319/*******************************************************************************
320 *
Robert Moore44f6c012005-04-18 22:49:35 -0400321 * FUNCTION: acpi_ut_strupr (strupr)
322 *
323 * PARAMETERS: src_string - The source string to convert
324 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700325 * RETURN: None
Robert Moore44f6c012005-04-18 22:49:35 -0400326 *
327 * DESCRIPTION: Convert string to uppercase
328 *
329 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
330 *
331 ******************************************************************************/
332
Len Brown4be44fc2005-08-05 00:44:28 -0400333void acpi_ut_strupr(char *src_string)
Robert Moore44f6c012005-04-18 22:49:35 -0400334{
Len Brown4be44fc2005-08-05 00:44:28 -0400335 char *string;
Robert Moore44f6c012005-04-18 22:49:35 -0400336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 ACPI_FUNCTION_ENTRY();
Robert Moore44f6c012005-04-18 22:49:35 -0400338
Robert Moore73459f72005-06-24 00:00:00 -0400339 if (!src_string) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700340 return;
Robert Moore73459f72005-06-24 00:00:00 -0400341 }
342
Robert Moore44f6c012005-04-18 22:49:35 -0400343 /* Walk entire string, uppercasing the letters */
344
345 for (string = src_string; *string; string++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400346 *string = (char)ACPI_TOUPPER(*string);
Robert Moore44f6c012005-04-18 22:49:35 -0400347 }
348
Robert Moore0c9938c2005-07-29 15:15:00 -0700349 return;
Robert Moore44f6c012005-04-18 22:49:35 -0400350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/*******************************************************************************
353 *
354 * FUNCTION: acpi_ut_print_string
355 *
356 * PARAMETERS: String - Null terminated ASCII string
Robert Moore44f6c012005-04-18 22:49:35 -0400357 * max_length - Maximum output length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *
359 * RETURN: None
360 *
361 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
362 * sequences.
363 *
364 ******************************************************************************/
365
Len Brown4be44fc2005-08-05 00:44:28 -0400366void acpi_ut_print_string(char *string, u8 max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Len Brown4be44fc2005-08-05 00:44:28 -0400368 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 if (!string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400371 acpi_os_printf("<\"NULL STRING PTR\">");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return;
373 }
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 for (i = 0; string[i] && (i < max_length); i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /* Escape sequences */
379
380 switch (string[i]) {
381 case 0x07:
Len Brown4be44fc2005-08-05 00:44:28 -0400382 acpi_os_printf("\\a"); /* BELL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
384
385 case 0x08:
Len Brown4be44fc2005-08-05 00:44:28 -0400386 acpi_os_printf("\\b"); /* BACKSPACE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 break;
388
389 case 0x0C:
Len Brown4be44fc2005-08-05 00:44:28 -0400390 acpi_os_printf("\\f"); /* FORMFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 break;
392
393 case 0x0A:
Len Brown4be44fc2005-08-05 00:44:28 -0400394 acpi_os_printf("\\n"); /* LINEFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 break;
396
397 case 0x0D:
Len Brown4be44fc2005-08-05 00:44:28 -0400398 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 break;
400
401 case 0x09:
Len Brown4be44fc2005-08-05 00:44:28 -0400402 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
404
405 case 0x0B:
Len Brown4be44fc2005-08-05 00:44:28 -0400406 acpi_os_printf("\\v"); /* VERTICAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 case '\'': /* Single Quote */
410 case '\"': /* Double Quote */
411 case '\\': /* Backslash */
412 acpi_os_printf("\\%c", (int)string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 break;
414
415 default:
416
417 /* Check for printable character or hex escape */
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 if (ACPI_IS_PRINT(string[i])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 /* This is a normal character */
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 acpi_os_printf("%c", (int)string[i]);
423 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 /* All others will be Hex escapes */
425
Len Brown4be44fc2005-08-05 00:44:28 -0400426 acpi_os_printf("\\x%2.2X", (s32) string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428 break;
429 }
430 }
Len Brown4be44fc2005-08-05 00:44:28 -0400431 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 if (i == max_length && string[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400434 acpi_os_printf("...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/*******************************************************************************
439 *
440 * FUNCTION: acpi_ut_dword_byte_swap
441 *
442 * PARAMETERS: Value - Value to be converted
443 *
Robert Moore44f6c012005-04-18 22:49:35 -0400444 * RETURN: u32 integer with bytes swapped
445 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
447 *
448 ******************************************************************************/
449
Len Brown4be44fc2005-08-05 00:44:28 -0400450u32 acpi_ut_dword_byte_swap(u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400453 u32 value;
454 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 } out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400457 u32 value;
458 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 } in;
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 in.value = value;
464
465 out.bytes[0] = in.bytes[3];
466 out.bytes[1] = in.bytes[2];
467 out.bytes[2] = in.bytes[1];
468 out.bytes[3] = in.bytes[0];
469
470 return (out.value);
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/*******************************************************************************
474 *
475 * FUNCTION: acpi_ut_set_integer_width
476 *
477 * PARAMETERS: Revision From DSDT header
478 *
479 * RETURN: None
480 *
481 * DESCRIPTION: Set the global integer bit width based upon the revision
482 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
483 * For Revision 2 and above, Integers are 64 bits. Yes, this
484 * makes a difference.
485 *
486 ******************************************************************************/
487
Len Brown4be44fc2005-08-05 00:44:28 -0400488void acpi_ut_set_integer_width(u8 revision)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490
Bob Mooref3d2e782007-02-02 19:48:18 +0300491 if (revision < 2) {
Bob Mooref6dd9222006-07-07 20:44:38 -0400492
493 /* 32-bit case */
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 acpi_gbl_integer_bit_width = 32;
496 acpi_gbl_integer_nybble_width = 8;
497 acpi_gbl_integer_byte_width = 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 } else {
Bob Mooref6dd9222006-07-07 20:44:38 -0400499 /* 64-bit case (ACPI 2.0+) */
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 acpi_gbl_integer_bit_width = 64;
502 acpi_gbl_integer_nybble_width = 16;
503 acpi_gbl_integer_byte_width = 8;
504 }
505}
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#ifdef ACPI_DEBUG_OUTPUT
508/*******************************************************************************
509 *
510 * FUNCTION: acpi_ut_display_init_pathname
511 *
Robert Moore44f6c012005-04-18 22:49:35 -0400512 * PARAMETERS: Type - Object type of the node
513 * obj_handle - Handle whose pathname will be displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 * Path - Additional path string to be appended.
515 * (NULL if no extra path)
516 *
517 * RETURN: acpi_status
518 *
519 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
520 *
521 ******************************************************************************/
522
523void
Len Brown4be44fc2005-08-05 00:44:28 -0400524acpi_ut_display_init_pathname(u8 type,
525 struct acpi_namespace_node *obj_handle,
526 char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Len Brown4be44fc2005-08-05 00:44:28 -0400528 acpi_status status;
529 struct acpi_buffer buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Len Brown4be44fc2005-08-05 00:44:28 -0400531 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 /* Only print the path if the appropriate debug level is enabled */
534
535 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
536 return;
537 }
538
539 /* Get the full pathname to the node */
540
541 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
Len Brown4be44fc2005-08-05 00:44:28 -0400542 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
543 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 return;
545 }
546
547 /* Print what we're doing */
548
549 switch (type) {
550 case ACPI_TYPE_METHOD:
Len Brown4be44fc2005-08-05 00:44:28 -0400551 acpi_os_printf("Executing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 break;
553
554 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_os_printf("Initializing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 break;
557 }
558
559 /* Print the object type and pathname */
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 acpi_os_printf("%-12s %s",
562 acpi_ut_get_type_name(type), (char *)buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 /* Extra path is used to append names like _STA, _INI, etc. */
565
566 if (path) {
Len Brown4be44fc2005-08-05 00:44:28 -0400567 acpi_os_printf(".%s", path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
Len Brown4be44fc2005-08-05 00:44:28 -0400569 acpi_os_printf("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Bob Moore83135242006-10-03 00:00:00 -0400571 ACPI_FREE(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573#endif
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575/*******************************************************************************
576 *
Bob Moore793c2382006-03-31 00:00:00 -0500577 * FUNCTION: acpi_ut_valid_acpi_char
578 *
579 * PARAMETERS: Char - The character to be examined
Bob Mooref6dd9222006-07-07 20:44:38 -0400580 * Position - Byte position (0-3)
Bob Moore793c2382006-03-31 00:00:00 -0500581 *
582 * RETURN: TRUE if the character is valid, FALSE otherwise
583 *
584 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
585 * 1) Upper case alpha
586 * 2) numeric
587 * 3) underscore
588 *
589 * We allow a '!' as the last character because of the ASF! table
590 *
591 ******************************************************************************/
592
Bob Moore67a119f2008-06-10 13:42:13 +0800593u8 acpi_ut_valid_acpi_char(char character, u32 position)
Bob Moore793c2382006-03-31 00:00:00 -0500594{
595
596 if (!((character >= 'A' && character <= 'Z') ||
597 (character >= '0' && character <= '9') || (character == '_'))) {
598
599 /* Allow a '!' in the last position */
600
601 if (character == '!' && position == 3) {
602 return (TRUE);
603 }
604
605 return (FALSE);
606 }
607
608 return (TRUE);
609}
610
611/*******************************************************************************
612 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 * FUNCTION: acpi_ut_valid_acpi_name
614 *
Robert Moore44f6c012005-04-18 22:49:35 -0400615 * PARAMETERS: Name - The name to be examined
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 *
Robert Moore44f6c012005-04-18 22:49:35 -0400617 * RETURN: TRUE if the name is valid, FALSE otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 *
619 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
620 * 1) Upper case alpha
621 * 2) numeric
622 * 3) underscore
623 *
624 ******************************************************************************/
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626u8 acpi_ut_valid_acpi_name(u32 name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Bob Moore67a119f2008-06-10 13:42:13 +0800628 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Len Brown4be44fc2005-08-05 00:44:28 -0400630 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore793c2382006-03-31 00:00:00 -0500633 if (!acpi_ut_valid_acpi_char
634 ((ACPI_CAST_PTR(char, &name))[i], i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return (FALSE);
636 }
637 }
638
639 return (TRUE);
640}
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*******************************************************************************
643 *
Bob Moore793c2382006-03-31 00:00:00 -0500644 * FUNCTION: acpi_ut_repair_name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 *
Bob Moore793c2382006-03-31 00:00:00 -0500646 * PARAMETERS: Name - The ACPI name to be repaired
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 *
Bob Moore793c2382006-03-31 00:00:00 -0500648 * RETURN: Repaired version of the name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 *
Bob Moore793c2382006-03-31 00:00:00 -0500650 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
651 * return the new name.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 *
653 ******************************************************************************/
654
Bob Moore3d81b232007-02-02 19:48:19 +0300655acpi_name acpi_ut_repair_name(char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Bob Moore67a119f2008-06-10 13:42:13 +0800657 u32 i;
Bob Moore3d81b232007-02-02 19:48:19 +0300658 char new_name[ACPI_NAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Bob Moore793c2382006-03-31 00:00:00 -0500660 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore3d81b232007-02-02 19:48:19 +0300661 new_name[i] = name[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Bob Moore793c2382006-03-31 00:00:00 -0500663 /*
664 * Replace a bad character with something printable, yet technically
665 * still invalid. This prevents any collisions with existing "good"
666 * names in the namespace.
667 */
Bob Moore3d81b232007-02-02 19:48:19 +0300668 if (!acpi_ut_valid_acpi_char(name[i], i)) {
Bob Moore793c2382006-03-31 00:00:00 -0500669 new_name[i] = '*';
670 }
671 }
672
Bob Moore3d81b232007-02-02 19:48:19 +0300673 return (*(u32 *) new_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*******************************************************************************
677 *
678 * FUNCTION: acpi_ut_strtoul64
679 *
680 * PARAMETERS: String - Null terminated string
Bob Moore41195322006-05-26 16:36:00 -0400681 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
682 * ACPI_ANY_BASE means 'in behalf of to_integer'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 * ret_integer - Where the converted integer is returned
684 *
685 * RETURN: Status and Converted value
686 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400687 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
688 * 32-bit or 64-bit conversion, depending on the current mode
689 * of the interpreter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 * NOTE: Does not support Octal strings, not needed.
691 *
692 ******************************************************************************/
693
694acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400695acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Len Brown4be44fc2005-08-05 00:44:28 -0400697 u32 this_digit = 0;
698 acpi_integer return_value = 0;
699 acpi_integer quotient;
Bob Moore41195322006-05-26 16:36:00 -0400700 acpi_integer dividend;
701 u32 to_integer_op = (base == ACPI_ANY_BASE);
702 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
703 u8 valid_digits = 0;
704 u8 sign_of0x = 0;
705 u8 term = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Bob Mooref6dd9222006-07-07 20:44:38 -0400707 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 switch (base) {
710 case ACPI_ANY_BASE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 case 16:
712 break;
713
714 default:
715 /* Invalid Base */
Len Brown4be44fc2005-08-05 00:44:28 -0400716 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
Bob Moore41195322006-05-26 16:36:00 -0400719 if (!string) {
720 goto error_exit;
721 }
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 /* Skip over any white space in the buffer */
724
Bob Moore41195322006-05-26 16:36:00 -0400725 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 string++;
727 }
728
Bob Moore41195322006-05-26 16:36:00 -0400729 if (to_integer_op) {
730 /*
731 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
732 * We need to determine if it is decimal or hexadecimal.
733 */
Len Brown4be44fc2005-08-05 00:44:28 -0400734 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
Bob Moore41195322006-05-26 16:36:00 -0400735 sign_of0x = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 base = 16;
Bob Moore41195322006-05-26 16:36:00 -0400737
738 /* Skip over the leading '0x' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 string += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400740 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 base = 10;
742 }
743 }
744
Bob Moore41195322006-05-26 16:36:00 -0400745 /* Any string left? Check that '0x' is not followed by white space. */
746
747 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
748 if (to_integer_op) {
749 goto error_exit;
750 } else {
751 goto all_done;
752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754
Bob Mooref6dd9222006-07-07 20:44:38 -0400755 /*
756 * Perform a 32-bit or 64-bit conversion, depending upon the current
757 * execution mode of the interpreter
758 */
Bob Moore41195322006-05-26 16:36:00 -0400759 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Bob Mooref6dd9222006-07-07 20:44:38 -0400761 /* Main loop: convert the string to a 32- or 64-bit integer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 while (*string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400764 if (ACPI_IS_DIGIT(*string)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 /* Convert ASCII 0-9 to Decimal value */
767
Len Brown4be44fc2005-08-05 00:44:28 -0400768 this_digit = ((u8) * string) - '0';
Bob Moore41195322006-05-26 16:36:00 -0400769 } else if (base == 10) {
770
771 /* Digit is out of range; possible in to_integer case only */
772
773 term = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400774 } else {
Len Brown4be44fc2005-08-05 00:44:28 -0400775 this_digit = (u8) ACPI_TOUPPER(*string);
776 if (ACPI_IS_XDIGIT((char)this_digit)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 /* Convert ASCII Hex char to value */
779
780 this_digit = this_digit - 'A' + 10;
Len Brown4be44fc2005-08-05 00:44:28 -0400781 } else {
Bob Moore41195322006-05-26 16:36:00 -0400782 term = 1;
783 }
784 }
785
786 if (term) {
787 if (to_integer_op) {
788 goto error_exit;
789 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 break;
791 }
Bob Moore41195322006-05-26 16:36:00 -0400792 } else if ((valid_digits == 0) && (this_digit == 0)
793 && !sign_of0x) {
794
795 /* Skip zeros */
796 string++;
797 continue;
798 }
799
800 valid_digits++;
801
Len Brownfd350942007-05-09 23:34:35 -0400802 if (sign_of0x && ((valid_digits > 16)
803 || ((valid_digits > 8) && mode32))) {
Bob Moore41195322006-05-26 16:36:00 -0400804 /*
805 * This is to_integer operation case.
806 * No any restrictions for string-to-integer conversion,
807 * see ACPI spec.
808 */
809 goto error_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
812 /* Divide the digit into the correct position */
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814 (void)
Bob Moore41195322006-05-26 16:36:00 -0400815 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
816 base, &quotient, NULL);
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (return_value > quotient) {
Bob Moore41195322006-05-26 16:36:00 -0400819 if (to_integer_op) {
820 goto error_exit;
821 } else {
822 break;
823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 }
825
826 return_value *= base;
827 return_value += this_digit;
828 string++;
829 }
830
831 /* All done, normal exit */
832
Bob Moore41195322006-05-26 16:36:00 -0400833 all_done:
834
Bob Mooref6dd9222006-07-07 20:44:38 -0400835 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
836 ACPI_FORMAT_UINT64(return_value)));
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 *ret_integer = return_value;
Len Brown4be44fc2005-08-05 00:44:28 -0400839 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Len Brown4be44fc2005-08-05 00:44:28 -0400841 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 /* Base was set/validated above */
843
844 if (base == 10) {
Len Brown4be44fc2005-08-05 00:44:28 -0400845 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
846 } else {
847 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849}
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851/*******************************************************************************
852 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 * FUNCTION: acpi_ut_create_update_state_and_push
854 *
Robert Moore44f6c012005-04-18 22:49:35 -0400855 * PARAMETERS: Object - Object to be added to the new state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 * Action - Increment/Decrement
857 * state_list - List the state will be added to
858 *
Robert Moore44f6c012005-04-18 22:49:35 -0400859 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 *
861 * DESCRIPTION: Create a new state and push it
862 *
863 ******************************************************************************/
864
865acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400866acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
867 u16 action,
868 union acpi_generic_state **state_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Len Brown4be44fc2005-08-05 00:44:28 -0400870 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Len Brown4be44fc2005-08-05 00:44:28 -0400872 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874 /* Ignore null objects; these are expected */
875
876 if (!object) {
877 return (AE_OK);
878 }
879
Len Brown4be44fc2005-08-05 00:44:28 -0400880 state = acpi_ut_create_update_state(object, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (!state) {
882 return (AE_NO_MEMORY);
883 }
884
Len Brown4be44fc2005-08-05 00:44:28 -0400885 acpi_ut_push_generic_state(state_list, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return (AE_OK);
887}
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889/*******************************************************************************
890 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 * FUNCTION: acpi_ut_walk_package_tree
892 *
Robert Moore44f6c012005-04-18 22:49:35 -0400893 * PARAMETERS: source_object - The package to walk
894 * target_object - Target object (if package is being copied)
895 * walk_callback - Called once for each package element
896 * Context - Passed to the callback function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 *
898 * RETURN: Status
899 *
900 * DESCRIPTION: Walk through a package
901 *
902 ******************************************************************************/
903
904acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400905acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
906 void *target_object,
907 acpi_pkg_callback walk_callback, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Len Brown4be44fc2005-08-05 00:44:28 -0400909 acpi_status status = AE_OK;
910 union acpi_generic_state *state_list = NULL;
911 union acpi_generic_state *state;
912 u32 this_index;
913 union acpi_operand_object *this_source_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Bob Mooreb229cf92006-04-21 17:15:00 -0400915 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Len Brown4be44fc2005-08-05 00:44:28 -0400917 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400919 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921
922 while (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 /* Get one element of the package */
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 this_source_obj = (union acpi_operand_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400928 state->pkg.source_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 /*
931 * Check for:
932 * 1) An uninitialized package element. It is completely
933 * legal to declare a package and leave it uninitialized
934 * 2) Not an internal object - can be a namespace node instead
935 * 3) Any type other than a package. Packages are handled in else
936 * case below.
937 */
938 if ((!this_source_obj) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400939 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
940 ACPI_DESC_TYPE_OPERAND)
Bob Moore3371c192009-02-18 14:44:03 +0800941 || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400942 status =
943 walk_callback(ACPI_COPY_TYPE_SIMPLE,
944 this_source_obj, state, context);
945 if (ACPI_FAILURE(status)) {
946 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
949 state->pkg.index++;
Len Brown4be44fc2005-08-05 00:44:28 -0400950 while (state->pkg.index >=
951 state->pkg.source_object->package.count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 /*
953 * We've handled all of the objects at this level, This means
954 * that we have just completed a package. That package may
955 * have contained one or more packages itself.
956 *
957 * Delete this state and pop the previous state (package).
958 */
Len Brown4be44fc2005-08-05 00:44:28 -0400959 acpi_ut_delete_generic_state(state);
960 state = acpi_ut_pop_generic_state(&state_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 /* Finished when there are no more states */
963
964 if (!state) {
965 /*
966 * We have handled all of the objects in the top level
967 * package just add the length of the package objects
968 * and exit
969 */
Len Brown4be44fc2005-08-05 00:44:28 -0400970 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 }
972
973 /*
974 * Go back up a level and move the index past the just
975 * completed package object.
976 */
977 state->pkg.index++;
978 }
Len Brown4be44fc2005-08-05 00:44:28 -0400979 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 /* This is a subobject of type package */
981
Len Brown4be44fc2005-08-05 00:44:28 -0400982 status =
983 walk_callback(ACPI_COPY_TYPE_PACKAGE,
984 this_source_obj, state, context);
985 if (ACPI_FAILURE(status)) {
986 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 }
988
989 /*
990 * Push the current state and create a new one
991 * The callback above returned a new target package object.
992 */
Len Brown4be44fc2005-08-05 00:44:28 -0400993 acpi_ut_push_generic_state(&state_list, state);
994 state = acpi_ut_create_pkg_state(this_source_obj,
995 state->pkg.
996 this_target_obj, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 if (!state) {
Lin Mingcf058bd2008-09-27 11:29:57 +0800998
999 /* Free any stacked Update State objects */
1000
1001 while (state_list) {
1002 state =
1003 acpi_ut_pop_generic_state
1004 (&state_list);
1005 acpi_ut_delete_generic_state(state);
1006 }
Len Brown4be44fc2005-08-05 00:44:28 -04001007 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
1009 }
1010 }
1011
1012 /* We should never get here */
1013
Len Brown4be44fc2005-08-05 00:44:28 -04001014 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017/*******************************************************************************
1018 *
Bob Moore50df4d82008-12-31 03:01:23 +08001019 * FUNCTION: acpi_error, acpi_exception, acpi_warning, acpi_info
Bob Mooreb8e4d892006-01-27 16:43:00 -05001020 *
1021 * PARAMETERS: module_name - Caller's module name (for error output)
1022 * line_number - Caller's line number (for error output)
1023 * Format - Printf format string + additional args
1024 *
1025 * RETURN: None
1026 *
1027 * DESCRIPTION: Print message with module/line/version info
1028 *
1029 ******************************************************************************/
1030
1031void ACPI_INTERNAL_VAR_XFACE
Bob Moore50df4d82008-12-31 03:01:23 +08001032acpi_error(const char *module_name, u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001033{
1034 va_list args;
1035
1036 acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number);
1037
1038 va_start(args, format);
1039 acpi_os_vprintf(format, args);
1040 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Bob Moore507f0462008-04-10 19:06:42 +04001041 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001042}
1043
1044void ACPI_INTERNAL_VAR_XFACE
Bob Moore50df4d82008-12-31 03:01:23 +08001045acpi_exception(const char *module_name,
1046 u32 line_number, acpi_status status, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001047{
1048 va_list args;
1049
1050 acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name,
1051 line_number, acpi_format_exception(status));
1052
1053 va_start(args, format);
1054 acpi_os_vprintf(format, args);
1055 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Len Brown3549dba2008-06-06 15:32:39 -04001056 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001057}
Len Brownfd350942007-05-09 23:34:35 -04001058
Bob Mooreb8e4d892006-01-27 16:43:00 -05001059void ACPI_INTERNAL_VAR_XFACE
Bob Moore50df4d82008-12-31 03:01:23 +08001060acpi_warning(const char *module_name, u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001061{
1062 va_list args;
1063
1064 acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number);
1065
1066 va_start(args, format);
1067 acpi_os_vprintf(format, args);
1068 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Bob Moore507f0462008-04-10 19:06:42 +04001069 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001070}
Len Browncece9292006-06-26 23:04:31 -04001071
Bob Mooreb8e4d892006-01-27 16:43:00 -05001072void ACPI_INTERNAL_VAR_XFACE
Bob Moore50df4d82008-12-31 03:01:23 +08001073acpi_info(const char *module_name, u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001074{
1075 va_list args;
1076
Bob Moorec5fc42a2007-02-02 19:48:19 +03001077 /*
1078 * Removed module_name, line_number, and acpica version, not needed
1079 * for info output
1080 */
1081 acpi_os_printf("ACPI: ");
Bob Mooreb8e4d892006-01-27 16:43:00 -05001082
1083 va_start(args, format);
1084 acpi_os_vprintf(format, args);
Bob Moorec5fc42a2007-02-02 19:48:19 +03001085 acpi_os_printf("\n");
Bob Moore507f0462008-04-10 19:06:42 +04001086 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001087}
Bob Moore50df4d82008-12-31 03:01:23 +08001088
1089ACPI_EXPORT_SYMBOL(acpi_error)
1090ACPI_EXPORT_SYMBOL(acpi_exception)
1091ACPI_EXPORT_SYMBOL(acpi_warning)
1092ACPI_EXPORT_SYMBOL(acpi_info)