Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: utmisc - common utility procedures |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Thomas Renninger | be63c92 | 2006-06-02 15:58:00 -0400 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("utmisc") |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************* |
| 54 | * |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 55 | * 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 | ******************************************************************************/ |
| 66 | const char *acpi_ut_validate_exception(acpi_status status) |
| 67 | { |
Bob Moore | 11f2a61 | 2008-06-10 12:53:01 +0800 | [diff] [blame] | 68 | u32 sub_status; |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 69 | 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 Moore | 11f2a61 | 2008-06-10 12:53:01 +0800 | [diff] [blame] | 89 | exception = acpi_gbl_exception_names_pgm[sub_status]; |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 90 | } |
| 91 | break; |
| 92 | |
| 93 | case AE_CODE_ACPI_TABLES: |
| 94 | |
| 95 | if (sub_status <= AE_CODE_TBL_MAX) { |
Bob Moore | 11f2a61 | 2008-06-10 12:53:01 +0800 | [diff] [blame] | 96 | exception = acpi_gbl_exception_names_tbl[sub_status]; |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 97 | } |
| 98 | break; |
| 99 | |
| 100 | case AE_CODE_AML: |
| 101 | |
| 102 | if (sub_status <= AE_CODE_AML_MAX) { |
Bob Moore | 11f2a61 | 2008-06-10 12:53:01 +0800 | [diff] [blame] | 103 | exception = acpi_gbl_exception_names_aml[sub_status]; |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 104 | } |
| 105 | break; |
| 106 | |
| 107 | case AE_CODE_CONTROL: |
| 108 | |
| 109 | if (sub_status <= AE_CODE_CTRL_MAX) { |
Bob Moore | 11f2a61 | 2008-06-10 12:53:01 +0800 | [diff] [blame] | 110 | exception = acpi_gbl_exception_names_ctrl[sub_status]; |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 111 | } |
| 112 | break; |
| 113 | |
| 114 | default: |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | return (ACPI_CAST_PTR(const char, exception)); |
| 119 | } |
| 120 | |
| 121 | /******************************************************************************* |
| 122 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 123 | * 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 Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 134 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 135 | u8 acpi_ut_is_aml_table(struct acpi_table_header *table) |
| 136 | { |
| 137 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 138 | /* These are the only tables that contain executable AML */ |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 139 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 140 | 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 Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 143 | return (TRUE); |
| 144 | } |
| 145 | |
| 146 | return (FALSE); |
| 147 | } |
| 148 | |
| 149 | /******************************************************************************* |
| 150 | * |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 151 | * FUNCTION: acpi_ut_allocate_owner_id |
| 152 | * |
| 153 | * PARAMETERS: owner_id - Where the new owner ID is returned |
| 154 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 155 | * 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 Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 160 | * |
| 161 | ******************************************************************************/ |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 164 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 165 | u32 i; |
| 166 | u32 j; |
| 167 | u32 k; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | acpi_status status; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 169 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 170 | ACPI_FUNCTION_TRACE(ut_allocate_owner_id); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 171 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 172 | /* Guard against multiple allocations of ID to the same location */ |
| 173 | |
| 174 | if (*owner_id) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 175 | ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists", |
| 176 | *owner_id)); |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 177 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
| 178 | } |
| 179 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 180 | /* Mutex for the global ID mask */ |
| 181 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
| 183 | if (ACPI_FAILURE(status)) { |
| 184 | return_ACPI_STATUS(status); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 187 | /* |
| 188 | * Find a free owner ID, cycle through all possible IDs on repeated |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 189 | * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have |
| 190 | * to be scanned twice. |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 191 | */ |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 192 | 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 Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 196 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 197 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 198 | for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) { |
| 199 | if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 200 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 201 | /* There are no free IDs in this mask */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 202 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 203 | break; |
| 204 | } |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 205 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 206 | 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 Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 227 | "Allocated OwnerId: %2.2X\n", |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 228 | (unsigned int)*owner_id)); |
| 229 | goto exit; |
| 230 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 231 | } |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 232 | |
| 233 | acpi_gbl_next_owner_id_offset = 0; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 237 | * All owner_ids have been allocated. This typically should |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 238 | * 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 Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 242 | * |
| 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 Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 245 | */ |
| 246 | status = AE_OWNER_ID_LIMIT; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 247 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 248 | "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT")); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 249 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | exit: |
| 251 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
| 252 | return_ACPI_STATUS(status); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 255 | /******************************************************************************* |
| 256 | * |
| 257 | * FUNCTION: acpi_ut_release_owner_id |
| 258 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 259 | * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 260 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 261 | * 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 Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 265 | * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255 |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 266 | * |
| 267 | ******************************************************************************/ |
| 268 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 270 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | acpi_owner_id owner_id = *owner_id_ptr; |
| 272 | acpi_status status; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 273 | u32 index; |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 274 | u32 bit; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 275 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 276 | ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 277 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 278 | /* 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 Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 284 | if (owner_id == 0) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 285 | ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id)); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 286 | return_VOID; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 289 | /* Mutex for the global ID mask */ |
| 290 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
| 292 | if (ACPI_FAILURE(status)) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 293 | return_VOID; |
| 294 | } |
| 295 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 296 | /* Normalize the ID to zero */ |
| 297 | |
| 298 | owner_id--; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 299 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 300 | /* Decode ID to index/offset pair */ |
| 301 | |
| 302 | index = ACPI_DIV_32(owner_id); |
| 303 | bit = 1 << ACPI_MOD_32(owner_id); |
| 304 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 305 | /* Free the owner ID only if it is valid */ |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 306 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 307 | if (acpi_gbl_owner_id_mask[index] & bit) { |
| 308 | acpi_gbl_owner_id_mask[index] ^= bit; |
| 309 | } else { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 310 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 311 | "Release of non-allocated OwnerId: %2.2X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 312 | owner_id + 1)); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 313 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 314 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 316 | return_VOID; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 319 | /******************************************************************************* |
| 320 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 321 | * FUNCTION: acpi_ut_strupr (strupr) |
| 322 | * |
| 323 | * PARAMETERS: src_string - The source string to convert |
| 324 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 325 | * RETURN: None |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 326 | * |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | void acpi_ut_strupr(char *src_string) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 334 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | char *string; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 336 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 338 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 339 | if (!src_string) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 340 | return; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 343 | /* Walk entire string, uppercasing the letters */ |
| 344 | |
| 345 | for (string = src_string; *string; string++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | *string = (char)ACPI_TOUPPER(*string); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 349 | return; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /******************************************************************************* |
| 353 | * |
| 354 | * FUNCTION: acpi_ut_print_string |
| 355 | * |
| 356 | * PARAMETERS: String - Null terminated ASCII string |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 357 | * max_length - Maximum output length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | * |
| 359 | * RETURN: None |
| 360 | * |
| 361 | * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape |
| 362 | * sequences. |
| 363 | * |
| 364 | ******************************************************************************/ |
| 365 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | void acpi_ut_print_string(char *string, u8 max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | if (!string) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | acpi_os_printf("<\"NULL STRING PTR\">"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | acpi_os_printf("\""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | for (i = 0; string[i] && (i < max_length); i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* Escape sequences */ |
| 379 | |
| 380 | switch (string[i]) { |
| 381 | case 0x07: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | acpi_os_printf("\\a"); /* BELL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | case 0x08: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | acpi_os_printf("\\b"); /* BACKSPACE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | break; |
| 388 | |
| 389 | case 0x0C: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | acpi_os_printf("\\f"); /* FORMFEED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | break; |
| 392 | |
| 393 | case 0x0A: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | acpi_os_printf("\\n"); /* LINEFEED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | break; |
| 396 | |
| 397 | case 0x0D: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | acpi_os_printf("\\r"); /* CARRIAGE RETURN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | case 0x09: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | acpi_os_printf("\\t"); /* HORIZONTAL TAB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | break; |
| 404 | |
| 405 | case 0x0B: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | acpi_os_printf("\\v"); /* VERTICAL TAB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | break; |
| 408 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | case '\'': /* Single Quote */ |
| 410 | case '\"': /* Double Quote */ |
| 411 | case '\\': /* Backslash */ |
| 412 | acpi_os_printf("\\%c", (int)string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | break; |
| 414 | |
| 415 | default: |
| 416 | |
| 417 | /* Check for printable character or hex escape */ |
| 418 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | if (ACPI_IS_PRINT(string[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* This is a normal character */ |
| 421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | acpi_os_printf("%c", (int)string[i]); |
| 423 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* All others will be Hex escapes */ |
| 425 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | acpi_os_printf("\\x%2.2X", (s32) string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | break; |
| 429 | } |
| 430 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 431 | acpi_os_printf("\""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | if (i == max_length && string[i]) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | acpi_os_printf("..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /******************************************************************************* |
| 439 | * |
| 440 | * FUNCTION: acpi_ut_dword_byte_swap |
| 441 | * |
| 442 | * PARAMETERS: Value - Value to be converted |
| 443 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 444 | * RETURN: u32 integer with bytes swapped |
| 445 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) |
| 447 | * |
| 448 | ******************************************************************************/ |
| 449 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | u32 acpi_ut_dword_byte_swap(u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | { |
| 452 | union { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | u32 value; |
| 454 | u8 bytes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | union { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | u32 value; |
| 458 | u8 bytes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } in; |
| 460 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /******************************************************************************* |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | void acpi_ut_set_integer_width(u8 revision) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
| 490 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 491 | if (revision < 2) { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 492 | |
| 493 | /* 32-bit case */ |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | acpi_gbl_integer_bit_width = 32; |
| 496 | acpi_gbl_integer_nybble_width = 8; |
| 497 | acpi_gbl_integer_byte_width = 4; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | } else { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 499 | /* 64-bit case (ACPI 2.0+) */ |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | acpi_gbl_integer_bit_width = 64; |
| 502 | acpi_gbl_integer_nybble_width = 16; |
| 503 | acpi_gbl_integer_byte_width = 8; |
| 504 | } |
| 505 | } |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | #ifdef ACPI_DEBUG_OUTPUT |
| 508 | /******************************************************************************* |
| 509 | * |
| 510 | * FUNCTION: acpi_ut_display_init_pathname |
| 511 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 512 | * PARAMETERS: Type - Object type of the node |
| 513 | * obj_handle - Handle whose pathname will be displayed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | * 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 | |
| 523 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 524 | acpi_ut_display_init_pathname(u8 type, |
| 525 | struct acpi_namespace_node *obj_handle, |
| 526 | char *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 528 | acpi_status status; |
| 529 | struct acpi_buffer buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 531 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 542 | status = acpi_ns_handle_to_pathname(obj_handle, &buffer); |
| 543 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return; |
| 545 | } |
| 546 | |
| 547 | /* Print what we're doing */ |
| 548 | |
| 549 | switch (type) { |
| 550 | case ACPI_TYPE_METHOD: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 551 | acpi_os_printf("Executing "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 555 | acpi_os_printf("Initializing "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | |
| 559 | /* Print the object type and pathname */ |
| 560 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 561 | acpi_os_printf("%-12s %s", |
| 562 | acpi_ut_get_type_name(type), (char *)buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | /* Extra path is used to append names like _STA, _INI, etc. */ |
| 565 | |
| 566 | if (path) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | acpi_os_printf(".%s", path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | acpi_os_printf("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 571 | ACPI_FREE(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | #endif |
| 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | /******************************************************************************* |
| 576 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 577 | * FUNCTION: acpi_ut_valid_acpi_char |
| 578 | * |
| 579 | * PARAMETERS: Char - The character to be examined |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 580 | * Position - Byte position (0-3) |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 581 | * |
| 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 Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 593 | u8 acpi_ut_valid_acpi_char(char character, u32 position) |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 594 | { |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | * FUNCTION: acpi_ut_valid_acpi_name |
| 614 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 615 | * PARAMETERS: Name - The name to be examined |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 617 | * RETURN: TRUE if the name is valid, FALSE otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | * |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | u8 acpi_ut_valid_acpi_name(u32 name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 628 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
| 632 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 633 | if (!acpi_ut_valid_acpi_char |
| 634 | ((ACPI_CAST_PTR(char, &name))[i], i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | return (FALSE); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | return (TRUE); |
| 640 | } |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /******************************************************************************* |
| 643 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 644 | * FUNCTION: acpi_ut_repair_name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 646 | * PARAMETERS: Name - The ACPI name to be repaired |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 648 | * RETURN: Repaired version of the name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 650 | * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and |
| 651 | * return the new name. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | * |
| 653 | ******************************************************************************/ |
| 654 | |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 655 | acpi_name acpi_ut_repair_name(char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 657 | u32 i; |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 658 | char new_name[ACPI_NAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 660 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 661 | new_name[i] = name[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 663 | /* |
| 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 Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 668 | if (!acpi_ut_valid_acpi_char(name[i], i)) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 669 | new_name[i] = '*'; |
| 670 | } |
| 671 | } |
| 672 | |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 673 | return (*(u32 *) new_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | /******************************************************************************* |
| 677 | * |
| 678 | * FUNCTION: acpi_ut_strtoul64 |
| 679 | * |
| 680 | * PARAMETERS: String - Null terminated string |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 681 | * Base - Radix of the string: 16 or ACPI_ANY_BASE; |
| 682 | * ACPI_ANY_BASE means 'in behalf of to_integer' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | * ret_integer - Where the converted integer is returned |
| 684 | * |
| 685 | * RETURN: Status and Converted value |
| 686 | * |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 687 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | * NOTE: Does not support Octal strings, not needed. |
| 691 | * |
| 692 | ******************************************************************************/ |
| 693 | |
| 694 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | u32 this_digit = 0; |
| 698 | acpi_integer return_value = 0; |
| 699 | acpi_integer quotient; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 700 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 707 | ACPI_FUNCTION_TRACE_STR(ut_stroul64, string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | switch (base) { |
| 710 | case ACPI_ANY_BASE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | case 16: |
| 712 | break; |
| 713 | |
| 714 | default: |
| 715 | /* Invalid Base */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 716 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 719 | if (!string) { |
| 720 | goto error_exit; |
| 721 | } |
| 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* Skip over any white space in the buffer */ |
| 724 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 725 | while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | string++; |
| 727 | } |
| 728 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 729 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 734 | if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 735 | sign_of0x = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | base = 16; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 737 | |
| 738 | /* Skip over the leading '0x' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | string += 2; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 740 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | base = 10; |
| 742 | } |
| 743 | } |
| 744 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 745 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 755 | /* |
| 756 | * Perform a 32-bit or 64-bit conversion, depending upon the current |
| 757 | * execution mode of the interpreter |
| 758 | */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 759 | dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 761 | /* Main loop: convert the string to a 32- or 64-bit integer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | while (*string) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | if (ACPI_IS_DIGIT(*string)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | /* Convert ASCII 0-9 to Decimal value */ |
| 767 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 768 | this_digit = ((u8) * string) - '0'; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 769 | } else if (base == 10) { |
| 770 | |
| 771 | /* Digit is out of range; possible in to_integer case only */ |
| 772 | |
| 773 | term = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 774 | } else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 775 | this_digit = (u8) ACPI_TOUPPER(*string); |
| 776 | if (ACPI_IS_XDIGIT((char)this_digit)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | /* Convert ASCII Hex char to value */ |
| 779 | |
| 780 | this_digit = this_digit - 'A' + 10; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 781 | } else { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 782 | term = 1; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | if (term) { |
| 787 | if (to_integer_op) { |
| 788 | goto error_exit; |
| 789 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | break; |
| 791 | } |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 792 | } 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 Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 802 | if (sign_of0x && ((valid_digits > 16) |
| 803 | || ((valid_digits > 8) && mode32))) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 804 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* Divide the digit into the correct position */ |
| 813 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 814 | (void) |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 815 | acpi_ut_short_divide((dividend - (acpi_integer) this_digit), |
| 816 | base, "ient, NULL); |
| 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | if (return_value > quotient) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 819 | if (to_integer_op) { |
| 820 | goto error_exit; |
| 821 | } else { |
| 822 | break; |
| 823 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | return_value *= base; |
| 827 | return_value += this_digit; |
| 828 | string++; |
| 829 | } |
| 830 | |
| 831 | /* All done, normal exit */ |
| 832 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 833 | all_done: |
| 834 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 835 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", |
| 836 | ACPI_FORMAT_UINT64(return_value))); |
| 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | *ret_integer = return_value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 839 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | /* Base was set/validated above */ |
| 843 | |
| 844 | if (base == 10) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT); |
| 846 | } else { |
| 847 | return_ACPI_STATUS(AE_BAD_HEX_CONSTANT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | /******************************************************************************* |
| 852 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | * FUNCTION: acpi_ut_create_update_state_and_push |
| 854 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 855 | * PARAMETERS: Object - Object to be added to the new state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | * Action - Increment/Decrement |
| 857 | * state_list - List the state will be added to |
| 858 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 859 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | * |
| 861 | * DESCRIPTION: Create a new state and push it |
| 862 | * |
| 863 | ******************************************************************************/ |
| 864 | |
| 865 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | acpi_ut_create_update_state_and_push(union acpi_operand_object *object, |
| 867 | u16 action, |
| 868 | union acpi_generic_state **state_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | union acpi_generic_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 872 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | /* Ignore null objects; these are expected */ |
| 875 | |
| 876 | if (!object) { |
| 877 | return (AE_OK); |
| 878 | } |
| 879 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 880 | state = acpi_ut_create_update_state(object, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | if (!state) { |
| 882 | return (AE_NO_MEMORY); |
| 883 | } |
| 884 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 885 | acpi_ut_push_generic_state(state_list, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | return (AE_OK); |
| 887 | } |
| 888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | /******************************************************************************* |
| 890 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | * FUNCTION: acpi_ut_walk_package_tree |
| 892 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 893 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | * |
| 898 | * RETURN: Status |
| 899 | * |
| 900 | * DESCRIPTION: Walk through a package |
| 901 | * |
| 902 | ******************************************************************************/ |
| 903 | |
| 904 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 905 | acpi_ut_walk_package_tree(union acpi_operand_object * source_object, |
| 906 | void *target_object, |
| 907 | acpi_pkg_callback walk_callback, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 909 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 915 | ACPI_FUNCTION_TRACE(ut_walk_package_tree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 917 | state = acpi_ut_create_pkg_state(source_object, target_object, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 919 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | while (state) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | /* Get one element of the package */ |
| 925 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 926 | this_index = state->pkg.index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | this_source_obj = (union acpi_operand_object *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 928 | state->pkg.source_object->package.elements[this_index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 939 | (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != |
| 940 | ACPI_DESC_TYPE_OPERAND) |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 941 | || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | state->pkg.index++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 950 | while (state->pkg.index >= |
| 951 | state->pkg.source_object->package.count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | /* |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 959 | acpi_ut_delete_generic_state(state); |
| 960 | state = acpi_ut_pop_generic_state(&state_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 970 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 979 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | /* This is a subobject of type package */ |
| 981 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 982 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* |
| 990 | * Push the current state and create a new one |
| 991 | * The callback above returned a new target package object. |
| 992 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 993 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (!state) { |
Lin Ming | cf058bd | 2008-09-27 11:29:57 +0800 | [diff] [blame] | 998 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1007 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /* We should never get here */ |
| 1013 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1014 | return_ACPI_STATUS(AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | /******************************************************************************* |
| 1018 | * |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1019 | * FUNCTION: acpi_error, acpi_exception, acpi_warning, acpi_info |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1020 | * |
| 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 | |
| 1031 | void ACPI_INTERNAL_VAR_XFACE |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1032 | acpi_error(const char *module_name, u32 line_number, const char *format, ...) |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1033 | { |
| 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 Moore | 507f046 | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 1041 | va_end(args); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | void ACPI_INTERNAL_VAR_XFACE |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1045 | acpi_exception(const char *module_name, |
| 1046 | u32 line_number, acpi_status status, const char *format, ...) |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1047 | { |
| 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 Brown | 3549dba | 2008-06-06 15:32:39 -0400 | [diff] [blame] | 1056 | va_end(args); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1057 | } |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 1058 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1059 | void ACPI_INTERNAL_VAR_XFACE |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1060 | acpi_warning(const char *module_name, u32 line_number, const char *format, ...) |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1061 | { |
| 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 Moore | 507f046 | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 1069 | va_end(args); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1070 | } |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 1071 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1072 | void ACPI_INTERNAL_VAR_XFACE |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1073 | acpi_info(const char *module_name, u32 line_number, const char *format, ...) |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1074 | { |
| 1075 | va_list args; |
| 1076 | |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 1077 | /* |
| 1078 | * Removed module_name, line_number, and acpica version, not needed |
| 1079 | * for info output |
| 1080 | */ |
| 1081 | acpi_os_printf("ACPI: "); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1082 | |
| 1083 | va_start(args, format); |
| 1084 | acpi_os_vprintf(format, args); |
Bob Moore | c5fc42a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 1085 | acpi_os_printf("\n"); |
Bob Moore | 507f046 | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 1086 | va_end(args); |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1087 | } |
Bob Moore | 50df4d8 | 2008-12-31 03:01:23 +0800 | [diff] [blame] | 1088 | |
| 1089 | ACPI_EXPORT_SYMBOL(acpi_error) |
| 1090 | ACPI_EXPORT_SYMBOL(acpi_exception) |
| 1091 | ACPI_EXPORT_SYMBOL(acpi_warning) |
| 1092 | ACPI_EXPORT_SYMBOL(acpi_info) |