blob: f34be6773556beebd53f3dde5f63bc03a78e07cf [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>
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 Moore84fb2c92007-02-02 19:48:19 +030054 * FUNCTION: acpi_ut_validate_exception
55 *
56 * PARAMETERS: Status - The acpi_status code to be formatted
57 *
58 * RETURN: A string containing the exception text. NULL if exception is
59 * not valid.
60 *
61 * DESCRIPTION: This function validates and translates an ACPI exception into
62 * an ASCII string.
63 *
64 ******************************************************************************/
65const char *acpi_ut_validate_exception(acpi_status status)
66{
Bob Moore11f2a612008-06-10 12:53:01 +080067 u32 sub_status;
Bob Moore84fb2c92007-02-02 19:48:19 +030068 const char *exception = NULL;
69
70 ACPI_FUNCTION_ENTRY();
71
72 /*
73 * Status is composed of two parts, a "type" and an actual code
74 */
75 sub_status = (status & ~AE_CODE_MASK);
76
77 switch (status & AE_CODE_MASK) {
78 case AE_CODE_ENVIRONMENTAL:
79
80 if (sub_status <= AE_CODE_ENV_MAX) {
81 exception = acpi_gbl_exception_names_env[sub_status];
82 }
83 break;
84
85 case AE_CODE_PROGRAMMER:
86
87 if (sub_status <= AE_CODE_PGM_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +080088 exception = acpi_gbl_exception_names_pgm[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +030089 }
90 break;
91
92 case AE_CODE_ACPI_TABLES:
93
94 if (sub_status <= AE_CODE_TBL_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +080095 exception = acpi_gbl_exception_names_tbl[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +030096 }
97 break;
98
99 case AE_CODE_AML:
100
101 if (sub_status <= AE_CODE_AML_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +0800102 exception = acpi_gbl_exception_names_aml[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +0300103 }
104 break;
105
106 case AE_CODE_CONTROL:
107
108 if (sub_status <= AE_CODE_CTRL_MAX) {
Bob Moore11f2a612008-06-10 12:53:01 +0800109 exception = acpi_gbl_exception_names_ctrl[sub_status];
Bob Moore84fb2c92007-02-02 19:48:19 +0300110 }
111 break;
112
113 default:
114 break;
115 }
116
117 return (ACPI_CAST_PTR(const char, exception));
118}
119
120/*******************************************************************************
121 *
Bob Moore793c2382006-03-31 00:00:00 -0500122 * FUNCTION: acpi_ut_is_aml_table
123 *
124 * PARAMETERS: Table - An ACPI table
125 *
126 * RETURN: TRUE if table contains executable AML; FALSE otherwise
127 *
128 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
129 * Currently, these are DSDT,SSDT,PSDT. All other table types are
130 * data tables that do not contain AML code.
131 *
132 ******************************************************************************/
Bob Moore84fb2c92007-02-02 19:48:19 +0300133
Bob Moore793c2382006-03-31 00:00:00 -0500134u8 acpi_ut_is_aml_table(struct acpi_table_header *table)
135{
136
Bob Mooref6dd9222006-07-07 20:44:38 -0400137 /* These are the only tables that contain executable AML */
Bob Moore793c2382006-03-31 00:00:00 -0500138
Bob Mooref3d2e782007-02-02 19:48:18 +0300139 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) ||
140 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) ||
141 ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
Bob Moore793c2382006-03-31 00:00:00 -0500142 return (TRUE);
143 }
144
145 return (FALSE);
146}
147
148/*******************************************************************************
149 *
Robert Mooref9f46012005-07-08 00:00:00 -0400150 * FUNCTION: acpi_ut_allocate_owner_id
151 *
152 * PARAMETERS: owner_id - Where the new owner ID is returned
153 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700154 * RETURN: Status
155 *
156 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
157 * track objects created by the table or method, to be deleted
158 * when the method exits or the table is unloaded.
Robert Mooref9f46012005-07-08 00:00:00 -0400159 *
160 ******************************************************************************/
Bob Moore793c2382006-03-31 00:00:00 -0500161
Len Brown4be44fc2005-08-05 00:44:28 -0400162acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
Robert Mooref9f46012005-07-08 00:00:00 -0400163{
Bob Moore67a119f2008-06-10 13:42:13 +0800164 u32 i;
165 u32 j;
166 u32 k;
Len Brown4be44fc2005-08-05 00:44:28 -0400167 acpi_status status;
Robert Mooref9f46012005-07-08 00:00:00 -0400168
Bob Mooreb229cf92006-04-21 17:15:00 -0400169 ACPI_FUNCTION_TRACE(ut_allocate_owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400170
Robert Mooreaff8c272005-09-02 17:24:17 -0400171 /* Guard against multiple allocations of ID to the same location */
172
173 if (*owner_id) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500174 ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
175 *owner_id));
Robert Mooreaff8c272005-09-02 17:24:17 -0400176 return_ACPI_STATUS(AE_ALREADY_EXISTS);
177 }
178
Robert Moore0c9938c2005-07-29 15:15:00 -0700179 /* Mutex for the global ID mask */
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
182 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400184 }
185
Bob Moorec51a4de2005-11-17 13:07:00 -0500186 /*
187 * Find a free owner ID, cycle through all possible IDs on repeated
Bob Moore28f55eb2005-12-02 18:27:00 -0500188 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
189 * to be scanned twice.
Bob Moorec51a4de2005-11-17 13:07:00 -0500190 */
Bob Moore28f55eb2005-12-02 18:27:00 -0500191 for (i = 0, j = acpi_gbl_last_owner_id_index;
192 i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) {
193 if (j >= ACPI_NUM_OWNERID_MASKS) {
194 j = 0; /* Wraparound to start of mask array */
Bob Moorec51a4de2005-11-17 13:07:00 -0500195 }
Robert Mooref9f46012005-07-08 00:00:00 -0400196
Bob Moore28f55eb2005-12-02 18:27:00 -0500197 for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) {
198 if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400199
Bob Moore28f55eb2005-12-02 18:27:00 -0500200 /* There are no free IDs in this mask */
Bob Moorec51a4de2005-11-17 13:07:00 -0500201
Bob Moore28f55eb2005-12-02 18:27:00 -0500202 break;
203 }
Bob Moorea18ecf42005-08-15 03:42:00 -0800204
Bob Moore28f55eb2005-12-02 18:27:00 -0500205 if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) {
206 /*
207 * Found a free ID. The actual ID is the bit index plus one,
208 * making zero an invalid Owner ID. Save this as the last ID
209 * allocated and update the global ID mask.
210 */
211 acpi_gbl_owner_id_mask[j] |= (1 << k);
212
213 acpi_gbl_last_owner_id_index = (u8) j;
214 acpi_gbl_next_owner_id_offset = (u8) (k + 1);
215
216 /*
217 * Construct encoded ID from the index and bit position
218 *
219 * Note: Last [j].k (bit 255) is never used and is marked
220 * permanently allocated (prevents +1 overflow)
221 */
222 *owner_id =
223 (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j));
224
225 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
Bob Mooreb229cf92006-04-21 17:15:00 -0400226 "Allocated OwnerId: %2.2X\n",
Bob Moore28f55eb2005-12-02 18:27:00 -0500227 (unsigned int)*owner_id));
228 goto exit;
229 }
Robert Mooref9f46012005-07-08 00:00:00 -0400230 }
Bob Moore28f55eb2005-12-02 18:27:00 -0500231
232 acpi_gbl_next_owner_id_offset = 0;
Robert Mooref9f46012005-07-08 00:00:00 -0400233 }
234
235 /*
Bob Moorec51a4de2005-11-17 13:07:00 -0500236 * All owner_ids have been allocated. This typically should
Robert Mooref9f46012005-07-08 00:00:00 -0400237 * not happen since the IDs are reused after deallocation. The IDs are
238 * allocated upon table load (one per table) and method execution, and
239 * they are released when a table is unloaded or a method completes
240 * execution.
Bob Moorec51a4de2005-11-17 13:07:00 -0500241 *
242 * If this error happens, there may be very deep nesting of invoked control
243 * methods, or there may be a bug where the IDs are not released.
Robert Mooref9f46012005-07-08 00:00:00 -0400244 */
245 status = AE_OWNER_ID_LIMIT;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500246 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400247 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
Robert Mooref9f46012005-07-08 00:00:00 -0400248
Len Brown4be44fc2005-08-05 00:44:28 -0400249 exit:
250 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
251 return_ACPI_STATUS(status);
Robert Mooref9f46012005-07-08 00:00:00 -0400252}
253
Robert Mooref9f46012005-07-08 00:00:00 -0400254/*******************************************************************************
255 *
256 * FUNCTION: acpi_ut_release_owner_id
257 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700258 * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD
Robert Mooref9f46012005-07-08 00:00:00 -0400259 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700260 * RETURN: None. No error is returned because we are either exiting a
261 * control method or unloading a table. Either way, we would
262 * ignore any error anyway.
263 *
Bob Moore28f55eb2005-12-02 18:27:00 -0500264 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
Robert Mooref9f46012005-07-08 00:00:00 -0400265 *
266 ******************************************************************************/
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
Robert Mooref9f46012005-07-08 00:00:00 -0400269{
Len Brown4be44fc2005-08-05 00:44:28 -0400270 acpi_owner_id owner_id = *owner_id_ptr;
271 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800272 u32 index;
Bob Moore28f55eb2005-12-02 18:27:00 -0500273 u32 bit;
Robert Mooref9f46012005-07-08 00:00:00 -0400274
Bob Mooreb229cf92006-04-21 17:15:00 -0400275 ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400276
Robert Moore0c9938c2005-07-29 15:15:00 -0700277 /* Always clear the input owner_id (zero is an invalid ID) */
278
279 *owner_id_ptr = 0;
280
281 /* Zero is not a valid owner_iD */
282
Bob Mooredefba1d2005-12-16 17:05:00 -0500283 if (owner_id == 0) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400284 ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
Robert Moore0c9938c2005-07-29 15:15:00 -0700285 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400286 }
287
Robert Moore0c9938c2005-07-29 15:15:00 -0700288 /* Mutex for the global ID mask */
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES);
291 if (ACPI_FAILURE(status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700292 return_VOID;
293 }
294
Robert Mooreaff8c272005-09-02 17:24:17 -0400295 /* Normalize the ID to zero */
296
297 owner_id--;
Robert Moore0c9938c2005-07-29 15:15:00 -0700298
Bob Moore28f55eb2005-12-02 18:27:00 -0500299 /* Decode ID to index/offset pair */
300
301 index = ACPI_DIV_32(owner_id);
302 bit = 1 << ACPI_MOD_32(owner_id);
303
Robert Moore0c9938c2005-07-29 15:15:00 -0700304 /* Free the owner ID only if it is valid */
Robert Mooref9f46012005-07-08 00:00:00 -0400305
Bob Moore28f55eb2005-12-02 18:27:00 -0500306 if (acpi_gbl_owner_id_mask[index] & bit) {
307 acpi_gbl_owner_id_mask[index] ^= bit;
308 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500309 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400310 "Release of non-allocated OwnerId: %2.2X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500311 owner_id + 1));
Robert Mooref9f46012005-07-08 00:00:00 -0400312 }
Robert Mooref9f46012005-07-08 00:00:00 -0400313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 (void)acpi_ut_release_mutex(ACPI_MTX_CACHES);
Robert Moore0c9938c2005-07-29 15:15:00 -0700315 return_VOID;
Robert Mooref9f46012005-07-08 00:00:00 -0400316}
317
Robert Mooref9f46012005-07-08 00:00:00 -0400318/*******************************************************************************
319 *
Robert Moore44f6c012005-04-18 22:49:35 -0400320 * FUNCTION: acpi_ut_strupr (strupr)
321 *
322 * PARAMETERS: src_string - The source string to convert
323 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700324 * RETURN: None
Robert Moore44f6c012005-04-18 22:49:35 -0400325 *
326 * DESCRIPTION: Convert string to uppercase
327 *
328 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
329 *
330 ******************************************************************************/
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332void acpi_ut_strupr(char *src_string)
Robert Moore44f6c012005-04-18 22:49:35 -0400333{
Len Brown4be44fc2005-08-05 00:44:28 -0400334 char *string;
Robert Moore44f6c012005-04-18 22:49:35 -0400335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 ACPI_FUNCTION_ENTRY();
Robert Moore44f6c012005-04-18 22:49:35 -0400337
Robert Moore73459f72005-06-24 00:00:00 -0400338 if (!src_string) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700339 return;
Robert Moore73459f72005-06-24 00:00:00 -0400340 }
341
Robert Moore44f6c012005-04-18 22:49:35 -0400342 /* Walk entire string, uppercasing the letters */
343
344 for (string = src_string; *string; string++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400345 *string = (char)ACPI_TOUPPER(*string);
Robert Moore44f6c012005-04-18 22:49:35 -0400346 }
347
Robert Moore0c9938c2005-07-29 15:15:00 -0700348 return;
Robert Moore44f6c012005-04-18 22:49:35 -0400349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*******************************************************************************
352 *
353 * FUNCTION: acpi_ut_print_string
354 *
355 * PARAMETERS: String - Null terminated ASCII string
Robert Moore44f6c012005-04-18 22:49:35 -0400356 * max_length - Maximum output length
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 *
358 * RETURN: None
359 *
360 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
361 * sequences.
362 *
363 ******************************************************************************/
364
Len Brown4be44fc2005-08-05 00:44:28 -0400365void acpi_ut_print_string(char *string, u8 max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Len Brown4be44fc2005-08-05 00:44:28 -0400367 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 if (!string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400370 acpi_os_printf("<\"NULL STRING PTR\">");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return;
372 }
373
Len Brown4be44fc2005-08-05 00:44:28 -0400374 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 for (i = 0; string[i] && (i < max_length); i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /* Escape sequences */
378
379 switch (string[i]) {
380 case 0x07:
Len Brown4be44fc2005-08-05 00:44:28 -0400381 acpi_os_printf("\\a"); /* BELL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 break;
383
384 case 0x08:
Len Brown4be44fc2005-08-05 00:44:28 -0400385 acpi_os_printf("\\b"); /* BACKSPACE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 break;
387
388 case 0x0C:
Len Brown4be44fc2005-08-05 00:44:28 -0400389 acpi_os_printf("\\f"); /* FORMFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 break;
391
392 case 0x0A:
Len Brown4be44fc2005-08-05 00:44:28 -0400393 acpi_os_printf("\\n"); /* LINEFEED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
395
396 case 0x0D:
Len Brown4be44fc2005-08-05 00:44:28 -0400397 acpi_os_printf("\\r"); /* CARRIAGE RETURN */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 break;
399
400 case 0x09:
Len Brown4be44fc2005-08-05 00:44:28 -0400401 acpi_os_printf("\\t"); /* HORIZONTAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 break;
403
404 case 0x0B:
Len Brown4be44fc2005-08-05 00:44:28 -0400405 acpi_os_printf("\\v"); /* VERTICAL TAB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 break;
407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 case '\'': /* Single Quote */
409 case '\"': /* Double Quote */
410 case '\\': /* Backslash */
411 acpi_os_printf("\\%c", (int)string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413
414 default:
415
416 /* Check for printable character or hex escape */
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 if (ACPI_IS_PRINT(string[i])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 /* This is a normal character */
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 acpi_os_printf("%c", (int)string[i]);
422 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* All others will be Hex escapes */
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 acpi_os_printf("\\x%2.2X", (s32) string[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427 break;
428 }
429 }
Len Brown4be44fc2005-08-05 00:44:28 -0400430 acpi_os_printf("\"");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 if (i == max_length && string[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_os_printf("...");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*******************************************************************************
438 *
439 * FUNCTION: acpi_ut_dword_byte_swap
440 *
441 * PARAMETERS: Value - Value to be converted
442 *
Robert Moore44f6c012005-04-18 22:49:35 -0400443 * RETURN: u32 integer with bytes swapped
444 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
446 *
447 ******************************************************************************/
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449u32 acpi_ut_dword_byte_swap(u32 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
451 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400452 u32 value;
453 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 } out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 union {
Len Brown4be44fc2005-08-05 00:44:28 -0400456 u32 value;
457 u8 bytes[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 } in;
459
Len Brown4be44fc2005-08-05 00:44:28 -0400460 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 in.value = value;
463
464 out.bytes[0] = in.bytes[3];
465 out.bytes[1] = in.bytes[2];
466 out.bytes[2] = in.bytes[1];
467 out.bytes[3] = in.bytes[0];
468
469 return (out.value);
470}
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472/*******************************************************************************
473 *
474 * FUNCTION: acpi_ut_set_integer_width
475 *
476 * PARAMETERS: Revision From DSDT header
477 *
478 * RETURN: None
479 *
480 * DESCRIPTION: Set the global integer bit width based upon the revision
481 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
482 * For Revision 2 and above, Integers are 64 bits. Yes, this
483 * makes a difference.
484 *
485 ******************************************************************************/
486
Len Brown4be44fc2005-08-05 00:44:28 -0400487void acpi_ut_set_integer_width(u8 revision)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489
Bob Mooref3d2e782007-02-02 19:48:18 +0300490 if (revision < 2) {
Bob Mooref6dd9222006-07-07 20:44:38 -0400491
492 /* 32-bit case */
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 acpi_gbl_integer_bit_width = 32;
495 acpi_gbl_integer_nybble_width = 8;
496 acpi_gbl_integer_byte_width = 4;
Len Brown4be44fc2005-08-05 00:44:28 -0400497 } else {
Bob Mooref6dd9222006-07-07 20:44:38 -0400498 /* 64-bit case (ACPI 2.0+) */
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 acpi_gbl_integer_bit_width = 64;
501 acpi_gbl_integer_nybble_width = 16;
502 acpi_gbl_integer_byte_width = 8;
503 }
504}
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#ifdef ACPI_DEBUG_OUTPUT
507/*******************************************************************************
508 *
509 * FUNCTION: acpi_ut_display_init_pathname
510 *
Robert Moore44f6c012005-04-18 22:49:35 -0400511 * PARAMETERS: Type - Object type of the node
512 * obj_handle - Handle whose pathname will be displayed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 * Path - Additional path string to be appended.
514 * (NULL if no extra path)
515 *
516 * RETURN: acpi_status
517 *
518 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
519 *
520 ******************************************************************************/
521
522void
Len Brown4be44fc2005-08-05 00:44:28 -0400523acpi_ut_display_init_pathname(u8 type,
524 struct acpi_namespace_node *obj_handle,
525 char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Len Brown4be44fc2005-08-05 00:44:28 -0400527 acpi_status status;
528 struct acpi_buffer buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Len Brown4be44fc2005-08-05 00:44:28 -0400530 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 /* Only print the path if the appropriate debug level is enabled */
533
534 if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) {
535 return;
536 }
537
538 /* Get the full pathname to the node */
539
540 buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER;
Len Brown4be44fc2005-08-05 00:44:28 -0400541 status = acpi_ns_handle_to_pathname(obj_handle, &buffer);
542 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return;
544 }
545
546 /* Print what we're doing */
547
548 switch (type) {
549 case ACPI_TYPE_METHOD:
Len Brown4be44fc2005-08-05 00:44:28 -0400550 acpi_os_printf("Executing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 break;
552
553 default:
Len Brown4be44fc2005-08-05 00:44:28 -0400554 acpi_os_printf("Initializing ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 break;
556 }
557
558 /* Print the object type and pathname */
559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 acpi_os_printf("%-12s %s",
561 acpi_ut_get_type_name(type), (char *)buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 /* Extra path is used to append names like _STA, _INI, etc. */
564
565 if (path) {
Len Brown4be44fc2005-08-05 00:44:28 -0400566 acpi_os_printf(".%s", path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
Len Brown4be44fc2005-08-05 00:44:28 -0400568 acpi_os_printf("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Bob Moore83135242006-10-03 00:00:00 -0400570 ACPI_FREE(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572#endif
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574/*******************************************************************************
575 *
Bob Moore793c2382006-03-31 00:00:00 -0500576 * FUNCTION: acpi_ut_valid_acpi_char
577 *
578 * PARAMETERS: Char - The character to be examined
Bob Mooref6dd9222006-07-07 20:44:38 -0400579 * Position - Byte position (0-3)
Bob Moore793c2382006-03-31 00:00:00 -0500580 *
581 * RETURN: TRUE if the character is valid, FALSE otherwise
582 *
583 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
584 * 1) Upper case alpha
585 * 2) numeric
586 * 3) underscore
587 *
588 * We allow a '!' as the last character because of the ASF! table
589 *
590 ******************************************************************************/
591
Bob Moore67a119f2008-06-10 13:42:13 +0800592u8 acpi_ut_valid_acpi_char(char character, u32 position)
Bob Moore793c2382006-03-31 00:00:00 -0500593{
594
595 if (!((character >= 'A' && character <= 'Z') ||
596 (character >= '0' && character <= '9') || (character == '_'))) {
597
598 /* Allow a '!' in the last position */
599
600 if (character == '!' && position == 3) {
601 return (TRUE);
602 }
603
604 return (FALSE);
605 }
606
607 return (TRUE);
608}
609
610/*******************************************************************************
611 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 * FUNCTION: acpi_ut_valid_acpi_name
613 *
Robert Moore44f6c012005-04-18 22:49:35 -0400614 * PARAMETERS: Name - The name to be examined
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 *
Robert Moore44f6c012005-04-18 22:49:35 -0400616 * RETURN: TRUE if the name is valid, FALSE otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 *
618 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
619 * 1) Upper case alpha
620 * 2) numeric
621 * 3) underscore
622 *
623 ******************************************************************************/
624
Len Brown4be44fc2005-08-05 00:44:28 -0400625u8 acpi_ut_valid_acpi_name(u32 name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
Bob Moore67a119f2008-06-10 13:42:13 +0800627 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore793c2382006-03-31 00:00:00 -0500632 if (!acpi_ut_valid_acpi_char
633 ((ACPI_CAST_PTR(char, &name))[i], i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return (FALSE);
635 }
636 }
637
638 return (TRUE);
639}
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641/*******************************************************************************
642 *
Bob Moore793c2382006-03-31 00:00:00 -0500643 * FUNCTION: acpi_ut_repair_name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 *
Bob Moore793c2382006-03-31 00:00:00 -0500645 * PARAMETERS: Name - The ACPI name to be repaired
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 *
Bob Moore793c2382006-03-31 00:00:00 -0500647 * RETURN: Repaired version of the name
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 *
Bob Moore793c2382006-03-31 00:00:00 -0500649 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
650 * return the new name.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 *
652 ******************************************************************************/
653
Bob Moore3d81b232007-02-02 19:48:19 +0300654acpi_name acpi_ut_repair_name(char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Bob Moore67a119f2008-06-10 13:42:13 +0800656 u32 i;
Bob Moore3d81b232007-02-02 19:48:19 +0300657 char new_name[ACPI_NAME_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Bob Moore793c2382006-03-31 00:00:00 -0500659 for (i = 0; i < ACPI_NAME_SIZE; i++) {
Bob Moore3d81b232007-02-02 19:48:19 +0300660 new_name[i] = name[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Bob Moore793c2382006-03-31 00:00:00 -0500662 /*
663 * Replace a bad character with something printable, yet technically
664 * still invalid. This prevents any collisions with existing "good"
665 * names in the namespace.
666 */
Bob Moore3d81b232007-02-02 19:48:19 +0300667 if (!acpi_ut_valid_acpi_char(name[i], i)) {
Bob Moore793c2382006-03-31 00:00:00 -0500668 new_name[i] = '*';
669 }
670 }
671
Bob Moore3d81b232007-02-02 19:48:19 +0300672 return (*(u32 *) new_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675/*******************************************************************************
676 *
677 * FUNCTION: acpi_ut_strtoul64
678 *
679 * PARAMETERS: String - Null terminated string
Bob Moore41195322006-05-26 16:36:00 -0400680 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
681 * ACPI_ANY_BASE means 'in behalf of to_integer'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 * ret_integer - Where the converted integer is returned
683 *
684 * RETURN: Status and Converted value
685 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400686 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
687 * 32-bit or 64-bit conversion, depending on the current mode
688 * of the interpreter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 * NOTE: Does not support Octal strings, not needed.
690 *
691 ******************************************************************************/
692
693acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400694acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Len Brown4be44fc2005-08-05 00:44:28 -0400696 u32 this_digit = 0;
697 acpi_integer return_value = 0;
698 acpi_integer quotient;
Bob Moore41195322006-05-26 16:36:00 -0400699 acpi_integer dividend;
700 u32 to_integer_op = (base == ACPI_ANY_BASE);
701 u32 mode32 = (acpi_gbl_integer_byte_width == 4);
702 u8 valid_digits = 0;
703 u8 sign_of0x = 0;
704 u8 term = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Bob Mooref6dd9222006-07-07 20:44:38 -0400706 ACPI_FUNCTION_TRACE_STR(ut_stroul64, string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 switch (base) {
709 case ACPI_ANY_BASE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 case 16:
711 break;
712
713 default:
714 /* Invalid Base */
Len Brown4be44fc2005-08-05 00:44:28 -0400715 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
Bob Moore41195322006-05-26 16:36:00 -0400718 if (!string) {
719 goto error_exit;
720 }
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /* Skip over any white space in the buffer */
723
Bob Moore41195322006-05-26 16:36:00 -0400724 while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 string++;
726 }
727
Bob Moore41195322006-05-26 16:36:00 -0400728 if (to_integer_op) {
729 /*
730 * Base equal to ACPI_ANY_BASE means 'to_integer operation case'.
731 * We need to determine if it is decimal or hexadecimal.
732 */
Len Brown4be44fc2005-08-05 00:44:28 -0400733 if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) {
Bob Moore41195322006-05-26 16:36:00 -0400734 sign_of0x = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 base = 16;
Bob Moore41195322006-05-26 16:36:00 -0400736
737 /* Skip over the leading '0x' */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 string += 2;
Len Brown4be44fc2005-08-05 00:44:28 -0400739 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 base = 10;
741 }
742 }
743
Bob Moore41195322006-05-26 16:36:00 -0400744 /* Any string left? Check that '0x' is not followed by white space. */
745
746 if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') {
747 if (to_integer_op) {
748 goto error_exit;
749 } else {
750 goto all_done;
751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753
Bob Mooref6dd9222006-07-07 20:44:38 -0400754 /*
755 * Perform a 32-bit or 64-bit conversion, depending upon the current
756 * execution mode of the interpreter
757 */
Bob Moore41195322006-05-26 16:36:00 -0400758 dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Bob Mooref6dd9222006-07-07 20:44:38 -0400760 /* Main loop: convert the string to a 32- or 64-bit integer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 while (*string) {
Len Brown4be44fc2005-08-05 00:44:28 -0400763 if (ACPI_IS_DIGIT(*string)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 /* Convert ASCII 0-9 to Decimal value */
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767 this_digit = ((u8) * string) - '0';
Bob Moore41195322006-05-26 16:36:00 -0400768 } else if (base == 10) {
769
770 /* Digit is out of range; possible in to_integer case only */
771
772 term = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400773 } else {
Len Brown4be44fc2005-08-05 00:44:28 -0400774 this_digit = (u8) ACPI_TOUPPER(*string);
775 if (ACPI_IS_XDIGIT((char)this_digit)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 /* Convert ASCII Hex char to value */
778
779 this_digit = this_digit - 'A' + 10;
Len Brown4be44fc2005-08-05 00:44:28 -0400780 } else {
Bob Moore41195322006-05-26 16:36:00 -0400781 term = 1;
782 }
783 }
784
785 if (term) {
786 if (to_integer_op) {
787 goto error_exit;
788 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 break;
790 }
Bob Moore41195322006-05-26 16:36:00 -0400791 } else if ((valid_digits == 0) && (this_digit == 0)
792 && !sign_of0x) {
793
794 /* Skip zeros */
795 string++;
796 continue;
797 }
798
799 valid_digits++;
800
Len Brownfd350942007-05-09 23:34:35 -0400801 if (sign_of0x && ((valid_digits > 16)
802 || ((valid_digits > 8) && mode32))) {
Bob Moore41195322006-05-26 16:36:00 -0400803 /*
804 * This is to_integer operation case.
805 * No any restrictions for string-to-integer conversion,
806 * see ACPI spec.
807 */
808 goto error_exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
811 /* Divide the digit into the correct position */
812
Len Brown4be44fc2005-08-05 00:44:28 -0400813 (void)
Bob Moore41195322006-05-26 16:36:00 -0400814 acpi_ut_short_divide((dividend - (acpi_integer) this_digit),
815 base, &quotient, NULL);
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (return_value > quotient) {
Bob Moore41195322006-05-26 16:36:00 -0400818 if (to_integer_op) {
819 goto error_exit;
820 } else {
821 break;
822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 }
824
825 return_value *= base;
826 return_value += this_digit;
827 string++;
828 }
829
830 /* All done, normal exit */
831
Bob Moore41195322006-05-26 16:36:00 -0400832 all_done:
833
Bob Mooref6dd9222006-07-07 20:44:38 -0400834 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
835 ACPI_FORMAT_UINT64(return_value)));
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 *ret_integer = return_value;
Len Brown4be44fc2005-08-05 00:44:28 -0400838 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Len Brown4be44fc2005-08-05 00:44:28 -0400840 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 /* Base was set/validated above */
842
843 if (base == 10) {
Len Brown4be44fc2005-08-05 00:44:28 -0400844 return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT);
845 } else {
846 return_ACPI_STATUS(AE_BAD_HEX_CONSTANT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848}
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850/*******************************************************************************
851 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 * FUNCTION: acpi_ut_create_update_state_and_push
853 *
Robert Moore44f6c012005-04-18 22:49:35 -0400854 * PARAMETERS: Object - Object to be added to the new state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 * Action - Increment/Decrement
856 * state_list - List the state will be added to
857 *
Robert Moore44f6c012005-04-18 22:49:35 -0400858 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 *
860 * DESCRIPTION: Create a new state and push it
861 *
862 ******************************************************************************/
863
864acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400865acpi_ut_create_update_state_and_push(union acpi_operand_object *object,
866 u16 action,
867 union acpi_generic_state **state_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Len Brown4be44fc2005-08-05 00:44:28 -0400869 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
Len Brown4be44fc2005-08-05 00:44:28 -0400871 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 /* Ignore null objects; these are expected */
874
875 if (!object) {
876 return (AE_OK);
877 }
878
Len Brown4be44fc2005-08-05 00:44:28 -0400879 state = acpi_ut_create_update_state(object, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 if (!state) {
881 return (AE_NO_MEMORY);
882 }
883
Len Brown4be44fc2005-08-05 00:44:28 -0400884 acpi_ut_push_generic_state(state_list, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 return (AE_OK);
886}
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888/*******************************************************************************
889 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 * FUNCTION: acpi_ut_walk_package_tree
891 *
Robert Moore44f6c012005-04-18 22:49:35 -0400892 * PARAMETERS: source_object - The package to walk
893 * target_object - Target object (if package is being copied)
894 * walk_callback - Called once for each package element
895 * Context - Passed to the callback function
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 *
897 * RETURN: Status
898 *
899 * DESCRIPTION: Walk through a package
900 *
901 ******************************************************************************/
902
903acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400904acpi_ut_walk_package_tree(union acpi_operand_object * source_object,
905 void *target_object,
906 acpi_pkg_callback walk_callback, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Len Brown4be44fc2005-08-05 00:44:28 -0400908 acpi_status status = AE_OK;
909 union acpi_generic_state *state_list = NULL;
910 union acpi_generic_state *state;
911 u32 this_index;
912 union acpi_operand_object *this_source_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Bob Mooreb229cf92006-04-21 17:15:00 -0400914 ACPI_FUNCTION_TRACE(ut_walk_package_tree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Len Brown4be44fc2005-08-05 00:44:28 -0400916 state = acpi_ut_create_pkg_state(source_object, target_object, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400918 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920
921 while (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* Get one element of the package */
924
Len Brown4be44fc2005-08-05 00:44:28 -0400925 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 this_source_obj = (union acpi_operand_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400927 state->pkg.source_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 /*
930 * Check for:
931 * 1) An uninitialized package element. It is completely
932 * legal to declare a package and leave it uninitialized
933 * 2) Not an internal object - can be a namespace node instead
934 * 3) Any type other than a package. Packages are handled in else
935 * case below.
936 */
937 if ((!this_source_obj) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400938 (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) !=
939 ACPI_DESC_TYPE_OPERAND)
940 || (ACPI_GET_OBJECT_TYPE(this_source_obj) !=
941 ACPI_TYPE_PACKAGE)) {
942 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) {
Len Brown4be44fc2005-08-05 00:44:28 -0400998 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000 }
1001 }
1002
1003 /* We should never get here */
1004
Len Brown4be44fc2005-08-05 00:44:28 -04001005 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008/*******************************************************************************
1009 *
Bob Mooreb8e4d892006-01-27 16:43:00 -05001010 * FUNCTION: acpi_ut_error, acpi_ut_warning, acpi_ut_info
1011 *
1012 * PARAMETERS: module_name - Caller's module name (for error output)
1013 * line_number - Caller's line number (for error output)
1014 * Format - Printf format string + additional args
1015 *
1016 * RETURN: None
1017 *
1018 * DESCRIPTION: Print message with module/line/version info
1019 *
1020 ******************************************************************************/
1021
1022void ACPI_INTERNAL_VAR_XFACE
Bob Moore4b8ed632008-06-10 13:55:53 +08001023acpi_ut_error(const char *module_name, u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001024{
1025 va_list args;
1026
1027 acpi_os_printf("ACPI Error (%s-%04d): ", module_name, line_number);
1028
1029 va_start(args, format);
1030 acpi_os_vprintf(format, args);
1031 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Bob Moore507f0462008-04-10 19:06:42 +04001032 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001033}
1034
1035void ACPI_INTERNAL_VAR_XFACE
Bob Moore4b8ed632008-06-10 13:55:53 +08001036acpi_ut_exception(const char *module_name,
1037 u32 line_number, acpi_status status, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001038{
1039 va_list args;
1040
1041 acpi_os_printf("ACPI Exception (%s-%04d): %s, ", module_name,
1042 line_number, acpi_format_exception(status));
1043
1044 va_start(args, format);
1045 acpi_os_vprintf(format, args);
1046 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Len Brown3549dba2008-06-06 15:32:39 -04001047 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001048}
Len Brownfd350942007-05-09 23:34:35 -04001049
Thomas Renningerbe63c922006-06-02 15:58:00 -04001050EXPORT_SYMBOL(acpi_ut_exception);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001051
1052void ACPI_INTERNAL_VAR_XFACE
Bob Moore4b8ed632008-06-10 13:55:53 +08001053acpi_ut_warning(const char *module_name,
1054 u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001055{
1056 va_list args;
1057
1058 acpi_os_printf("ACPI Warning (%s-%04d): ", module_name, line_number);
1059
1060 va_start(args, format);
1061 acpi_os_vprintf(format, args);
1062 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
Bob Moore507f0462008-04-10 19:06:42 +04001063 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001064}
Len Browncece9292006-06-26 23:04:31 -04001065
Bob Mooreb8e4d892006-01-27 16:43:00 -05001066void ACPI_INTERNAL_VAR_XFACE
Bob Moore4b8ed632008-06-10 13:55:53 +08001067acpi_ut_info(const char *module_name, u32 line_number, const char *format, ...)
Bob Mooreb8e4d892006-01-27 16:43:00 -05001068{
1069 va_list args;
1070
Bob Moorec5fc42a2007-02-02 19:48:19 +03001071 /*
1072 * Removed module_name, line_number, and acpica version, not needed
1073 * for info output
1074 */
1075 acpi_os_printf("ACPI: ");
Bob Mooreb8e4d892006-01-27 16:43:00 -05001076
1077 va_start(args, format);
1078 acpi_os_vprintf(format, args);
Bob Moorec5fc42a2007-02-02 19:48:19 +03001079 acpi_os_printf("\n");
Bob Moore507f0462008-04-10 19:06:42 +04001080 va_end(args);
Bob Mooreb8e4d892006-01-27 16:43:00 -05001081}