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 | /* |
Bob Moore | b4e104e | 2011-01-17 11:05:40 +0800 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2011, 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 | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 123 | * FUNCTION: acpi_ut_is_pci_root_bridge |
| 124 | * |
| 125 | * PARAMETERS: Id - The HID/CID in string format |
| 126 | * |
| 127 | * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge |
| 128 | * |
| 129 | * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID. |
| 130 | * |
| 131 | ******************************************************************************/ |
| 132 | |
| 133 | u8 acpi_ut_is_pci_root_bridge(char *id) |
| 134 | { |
| 135 | |
| 136 | /* |
| 137 | * Check if this is a PCI root bridge. |
| 138 | * ACPI 3.0+: check for a PCI Express root also. |
| 139 | */ |
| 140 | if (!(ACPI_STRCMP(id, |
| 141 | PCI_ROOT_HID_STRING)) || |
| 142 | !(ACPI_STRCMP(id, PCI_EXPRESS_ROOT_HID_STRING))) { |
| 143 | return (TRUE); |
| 144 | } |
| 145 | |
| 146 | return (FALSE); |
| 147 | } |
| 148 | |
| 149 | /******************************************************************************* |
| 150 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 151 | * FUNCTION: acpi_ut_is_aml_table |
| 152 | * |
| 153 | * PARAMETERS: Table - An ACPI table |
| 154 | * |
| 155 | * RETURN: TRUE if table contains executable AML; FALSE otherwise |
| 156 | * |
| 157 | * DESCRIPTION: Check ACPI Signature for a table that contains AML code. |
| 158 | * Currently, these are DSDT,SSDT,PSDT. All other table types are |
| 159 | * data tables that do not contain AML code. |
| 160 | * |
| 161 | ******************************************************************************/ |
Bob Moore | 84fb2c9 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 162 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 163 | u8 acpi_ut_is_aml_table(struct acpi_table_header *table) |
| 164 | { |
| 165 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 166 | /* These are the only tables that contain executable AML */ |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 167 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 168 | if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) || |
| 169 | ACPI_COMPARE_NAME(table->signature, ACPI_SIG_PSDT) || |
| 170 | ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 171 | return (TRUE); |
| 172 | } |
| 173 | |
| 174 | return (FALSE); |
| 175 | } |
| 176 | |
| 177 | /******************************************************************************* |
| 178 | * |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 179 | * FUNCTION: acpi_ut_allocate_owner_id |
| 180 | * |
| 181 | * PARAMETERS: owner_id - Where the new owner ID is returned |
| 182 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 183 | * RETURN: Status |
| 184 | * |
| 185 | * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to |
| 186 | * track objects created by the table or method, to be deleted |
| 187 | * when the method exits or the table is unloaded. |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 188 | * |
| 189 | ******************************************************************************/ |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 192 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 193 | u32 i; |
| 194 | u32 j; |
| 195 | u32 k; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_status status; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 197 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 198 | ACPI_FUNCTION_TRACE(ut_allocate_owner_id); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 199 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 200 | /* Guard against multiple allocations of ID to the same location */ |
| 201 | |
| 202 | if (*owner_id) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 203 | ACPI_ERROR((AE_INFO, "Owner ID [0x%2.2X] already exists", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 204 | *owner_id)); |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 205 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
| 206 | } |
| 207 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 208 | /* Mutex for the global ID mask */ |
| 209 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
| 211 | if (ACPI_FAILURE(status)) { |
| 212 | return_ACPI_STATUS(status); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 215 | /* |
| 216 | * Find a free owner ID, cycle through all possible IDs on repeated |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 217 | * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have |
| 218 | * to be scanned twice. |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 219 | */ |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 220 | for (i = 0, j = acpi_gbl_last_owner_id_index; |
| 221 | i < (ACPI_NUM_OWNERID_MASKS + 1); i++, j++) { |
| 222 | if (j >= ACPI_NUM_OWNERID_MASKS) { |
| 223 | j = 0; /* Wraparound to start of mask array */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 224 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 225 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 226 | for (k = acpi_gbl_next_owner_id_offset; k < 32; k++) { |
| 227 | if (acpi_gbl_owner_id_mask[j] == ACPI_UINT32_MAX) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 228 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 229 | /* There are no free IDs in this mask */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 230 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 231 | break; |
| 232 | } |
Bob Moore | a18ecf4 | 2005-08-15 03:42:00 -0800 | [diff] [blame] | 233 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 234 | if (!(acpi_gbl_owner_id_mask[j] & (1 << k))) { |
| 235 | /* |
| 236 | * Found a free ID. The actual ID is the bit index plus one, |
| 237 | * making zero an invalid Owner ID. Save this as the last ID |
| 238 | * allocated and update the global ID mask. |
| 239 | */ |
| 240 | acpi_gbl_owner_id_mask[j] |= (1 << k); |
| 241 | |
| 242 | acpi_gbl_last_owner_id_index = (u8) j; |
| 243 | acpi_gbl_next_owner_id_offset = (u8) (k + 1); |
| 244 | |
| 245 | /* |
| 246 | * Construct encoded ID from the index and bit position |
| 247 | * |
| 248 | * Note: Last [j].k (bit 255) is never used and is marked |
| 249 | * permanently allocated (prevents +1 overflow) |
| 250 | */ |
| 251 | *owner_id = |
| 252 | (acpi_owner_id) ((k + 1) + ACPI_MUL_32(j)); |
| 253 | |
| 254 | ACPI_DEBUG_PRINT((ACPI_DB_VALUES, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 255 | "Allocated OwnerId: %2.2X\n", |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 256 | (unsigned int)*owner_id)); |
| 257 | goto exit; |
| 258 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 259 | } |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 260 | |
| 261 | acpi_gbl_next_owner_id_offset = 0; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 265 | * All owner_ids have been allocated. This typically should |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 266 | * not happen since the IDs are reused after deallocation. The IDs are |
| 267 | * allocated upon table load (one per table) and method execution, and |
| 268 | * they are released when a table is unloaded or a method completes |
| 269 | * execution. |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 270 | * |
| 271 | * If this error happens, there may be very deep nesting of invoked control |
| 272 | * 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] | 273 | */ |
| 274 | status = AE_OWNER_ID_LIMIT; |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 275 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 276 | "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT")); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 277 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | exit: |
| 279 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
| 280 | return_ACPI_STATUS(status); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 281 | } |
| 282 | |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 283 | /******************************************************************************* |
| 284 | * |
| 285 | * FUNCTION: acpi_ut_release_owner_id |
| 286 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 287 | * PARAMETERS: owner_id_ptr - Pointer to a previously allocated owner_iD |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 288 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 289 | * RETURN: None. No error is returned because we are either exiting a |
| 290 | * control method or unloading a table. Either way, we would |
| 291 | * ignore any error anyway. |
| 292 | * |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 293 | * 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] | 294 | * |
| 295 | ******************************************************************************/ |
| 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 298 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | acpi_owner_id owner_id = *owner_id_ptr; |
| 300 | acpi_status status; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 301 | u32 index; |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 302 | u32 bit; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 303 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 304 | ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 305 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 306 | /* Always clear the input owner_id (zero is an invalid ID) */ |
| 307 | |
| 308 | *owner_id_ptr = 0; |
| 309 | |
| 310 | /* Zero is not a valid owner_iD */ |
| 311 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 312 | if (owner_id == 0) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 313 | ACPI_ERROR((AE_INFO, "Invalid OwnerId: 0x%2.2X", owner_id)); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 314 | return_VOID; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 315 | } |
| 316 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 317 | /* Mutex for the global ID mask */ |
| 318 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | status = acpi_ut_acquire_mutex(ACPI_MTX_CACHES); |
| 320 | if (ACPI_FAILURE(status)) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 321 | return_VOID; |
| 322 | } |
| 323 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 324 | /* Normalize the ID to zero */ |
| 325 | |
| 326 | owner_id--; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 327 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 328 | /* Decode ID to index/offset pair */ |
| 329 | |
| 330 | index = ACPI_DIV_32(owner_id); |
| 331 | bit = 1 << ACPI_MOD_32(owner_id); |
| 332 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 333 | /* Free the owner ID only if it is valid */ |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 334 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 335 | if (acpi_gbl_owner_id_mask[index] & bit) { |
| 336 | acpi_gbl_owner_id_mask[index] ^= bit; |
| 337 | } else { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 338 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 339 | "Release of non-allocated OwnerId: 0x%2.2X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 340 | owner_id + 1)); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 341 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 342 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 343 | (void)acpi_ut_release_mutex(ACPI_MTX_CACHES); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 344 | return_VOID; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 345 | } |
| 346 | |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 347 | /******************************************************************************* |
| 348 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 349 | * FUNCTION: acpi_ut_strupr (strupr) |
| 350 | * |
| 351 | * PARAMETERS: src_string - The source string to convert |
| 352 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 353 | * RETURN: None |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 354 | * |
| 355 | * DESCRIPTION: Convert string to uppercase |
| 356 | * |
| 357 | * NOTE: This is not a POSIX function, so it appears here, not in utclib.c |
| 358 | * |
| 359 | ******************************************************************************/ |
| 360 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | void acpi_ut_strupr(char *src_string) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 362 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 363 | char *string; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 364 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 366 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 367 | if (!src_string) { |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 368 | return; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 371 | /* Walk entire string, uppercasing the letters */ |
| 372 | |
| 373 | for (string = src_string; *string; string++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 374 | *string = (char)ACPI_TOUPPER(*string); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 375 | } |
| 376 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 377 | return; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 378 | } |
| 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /******************************************************************************* |
| 381 | * |
| 382 | * FUNCTION: acpi_ut_print_string |
| 383 | * |
| 384 | * PARAMETERS: String - Null terminated ASCII string |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 385 | * max_length - Maximum output length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | * |
| 387 | * RETURN: None |
| 388 | * |
| 389 | * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape |
| 390 | * sequences. |
| 391 | * |
| 392 | ******************************************************************************/ |
| 393 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | void acpi_ut_print_string(char *string, u8 max_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | if (!string) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | acpi_os_printf("<\"NULL STRING PTR\">"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return; |
| 401 | } |
| 402 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | acpi_os_printf("\""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | for (i = 0; string[i] && (i < max_length); i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | /* Escape sequences */ |
| 407 | |
| 408 | switch (string[i]) { |
| 409 | case 0x07: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | acpi_os_printf("\\a"); /* BELL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | break; |
| 412 | |
| 413 | case 0x08: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | acpi_os_printf("\\b"); /* BACKSPACE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | break; |
| 416 | |
| 417 | case 0x0C: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 418 | acpi_os_printf("\\f"); /* FORMFEED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | break; |
| 420 | |
| 421 | case 0x0A: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | acpi_os_printf("\\n"); /* LINEFEED */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | break; |
| 424 | |
| 425 | case 0x0D: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | acpi_os_printf("\\r"); /* CARRIAGE RETURN */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | break; |
| 428 | |
| 429 | case 0x09: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | acpi_os_printf("\\t"); /* HORIZONTAL TAB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | break; |
| 432 | |
| 433 | case 0x0B: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | acpi_os_printf("\\v"); /* VERTICAL TAB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | case '\'': /* Single Quote */ |
| 438 | case '\"': /* Double Quote */ |
| 439 | case '\\': /* Backslash */ |
| 440 | acpi_os_printf("\\%c", (int)string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | break; |
| 442 | |
| 443 | default: |
| 444 | |
| 445 | /* Check for printable character or hex escape */ |
| 446 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | if (ACPI_IS_PRINT(string[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /* This is a normal character */ |
| 449 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | acpi_os_printf("%c", (int)string[i]); |
| 451 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* All others will be Hex escapes */ |
| 453 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | acpi_os_printf("\\x%2.2X", (s32) string[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | break; |
| 457 | } |
| 458 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 459 | acpi_os_printf("\""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | if (i == max_length && string[i]) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 462 | acpi_os_printf("..."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /******************************************************************************* |
| 467 | * |
| 468 | * FUNCTION: acpi_ut_dword_byte_swap |
| 469 | * |
| 470 | * PARAMETERS: Value - Value to be converted |
| 471 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 472 | * RETURN: u32 integer with bytes swapped |
| 473 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes) |
| 475 | * |
| 476 | ******************************************************************************/ |
| 477 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | u32 acpi_ut_dword_byte_swap(u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | union { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | u32 value; |
| 482 | u8 bytes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | union { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | u32 value; |
| 486 | u8 bytes[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } in; |
| 488 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | in.value = value; |
| 492 | |
| 493 | out.bytes[0] = in.bytes[3]; |
| 494 | out.bytes[1] = in.bytes[2]; |
| 495 | out.bytes[2] = in.bytes[1]; |
| 496 | out.bytes[3] = in.bytes[0]; |
| 497 | |
| 498 | return (out.value); |
| 499 | } |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /******************************************************************************* |
| 502 | * |
| 503 | * FUNCTION: acpi_ut_set_integer_width |
| 504 | * |
| 505 | * PARAMETERS: Revision From DSDT header |
| 506 | * |
| 507 | * RETURN: None |
| 508 | * |
| 509 | * DESCRIPTION: Set the global integer bit width based upon the revision |
| 510 | * of the DSDT. For Revision 1 and 0, Integers are 32 bits. |
| 511 | * For Revision 2 and above, Integers are 64 bits. Yes, this |
| 512 | * makes a difference. |
| 513 | * |
| 514 | ******************************************************************************/ |
| 515 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | void acpi_ut_set_integer_width(u8 revision) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 518 | |
Bob Moore | f3d2e78 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 519 | if (revision < 2) { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 520 | |
| 521 | /* 32-bit case */ |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | acpi_gbl_integer_bit_width = 32; |
| 524 | acpi_gbl_integer_nybble_width = 8; |
| 525 | acpi_gbl_integer_byte_width = 4; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 526 | } else { |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 527 | /* 64-bit case (ACPI 2.0+) */ |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | acpi_gbl_integer_bit_width = 64; |
| 530 | acpi_gbl_integer_nybble_width = 16; |
| 531 | acpi_gbl_integer_byte_width = 8; |
| 532 | } |
| 533 | } |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | #ifdef ACPI_DEBUG_OUTPUT |
| 536 | /******************************************************************************* |
| 537 | * |
| 538 | * FUNCTION: acpi_ut_display_init_pathname |
| 539 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 540 | * PARAMETERS: Type - Object type of the node |
| 541 | * obj_handle - Handle whose pathname will be displayed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | * Path - Additional path string to be appended. |
| 543 | * (NULL if no extra path) |
| 544 | * |
| 545 | * RETURN: acpi_status |
| 546 | * |
| 547 | * DESCRIPTION: Display full pathname of an object, DEBUG ONLY |
| 548 | * |
| 549 | ******************************************************************************/ |
| 550 | |
| 551 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | acpi_ut_display_init_pathname(u8 type, |
| 553 | struct acpi_namespace_node *obj_handle, |
| 554 | char *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 556 | acpi_status status; |
| 557 | struct acpi_buffer buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | /* Only print the path if the appropriate debug level is enabled */ |
| 562 | |
| 563 | if (!(acpi_dbg_level & ACPI_LV_INIT_NAMES)) { |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | /* Get the full pathname to the node */ |
| 568 | |
| 569 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | status = acpi_ns_handle_to_pathname(obj_handle, &buffer); |
| 571 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return; |
| 573 | } |
| 574 | |
| 575 | /* Print what we're doing */ |
| 576 | |
| 577 | switch (type) { |
| 578 | case ACPI_TYPE_METHOD: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 579 | acpi_os_printf("Executing "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | break; |
| 581 | |
| 582 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 583 | acpi_os_printf("Initializing "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | break; |
| 585 | } |
| 586 | |
| 587 | /* Print the object type and pathname */ |
| 588 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 589 | acpi_os_printf("%-12s %s", |
| 590 | acpi_ut_get_type_name(type), (char *)buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | /* Extra path is used to append names like _STA, _INI, etc. */ |
| 593 | |
| 594 | if (path) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 595 | acpi_os_printf(".%s", path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 597 | acpi_os_printf("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 599 | ACPI_FREE(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | #endif |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /******************************************************************************* |
| 604 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 605 | * FUNCTION: acpi_ut_valid_acpi_char |
| 606 | * |
| 607 | * PARAMETERS: Char - The character to be examined |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 608 | * Position - Byte position (0-3) |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 609 | * |
| 610 | * RETURN: TRUE if the character is valid, FALSE otherwise |
| 611 | * |
| 612 | * DESCRIPTION: Check for a valid ACPI character. Must be one of: |
| 613 | * 1) Upper case alpha |
| 614 | * 2) numeric |
| 615 | * 3) underscore |
| 616 | * |
| 617 | * We allow a '!' as the last character because of the ASF! table |
| 618 | * |
| 619 | ******************************************************************************/ |
| 620 | |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 621 | u8 acpi_ut_valid_acpi_char(char character, u32 position) |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 622 | { |
| 623 | |
| 624 | if (!((character >= 'A' && character <= 'Z') || |
| 625 | (character >= '0' && character <= '9') || (character == '_'))) { |
| 626 | |
| 627 | /* Allow a '!' in the last position */ |
| 628 | |
| 629 | if (character == '!' && position == 3) { |
| 630 | return (TRUE); |
| 631 | } |
| 632 | |
| 633 | return (FALSE); |
| 634 | } |
| 635 | |
| 636 | return (TRUE); |
| 637 | } |
| 638 | |
| 639 | /******************************************************************************* |
| 640 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | * FUNCTION: acpi_ut_valid_acpi_name |
| 642 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 643 | * PARAMETERS: Name - The name to be examined |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 645 | * RETURN: TRUE if the name is valid, FALSE otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | * |
| 647 | * DESCRIPTION: Check for a valid ACPI name. Each character must be one of: |
| 648 | * 1) Upper case alpha |
| 649 | * 2) numeric |
| 650 | * 3) underscore |
| 651 | * |
| 652 | ******************************************************************************/ |
| 653 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 654 | u8 acpi_ut_valid_acpi_name(u32 name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 656 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 661 | if (!acpi_ut_valid_acpi_char |
| 662 | ((ACPI_CAST_PTR(char, &name))[i], i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | return (FALSE); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | return (TRUE); |
| 668 | } |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /******************************************************************************* |
| 671 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 672 | * FUNCTION: acpi_ut_repair_name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 674 | * PARAMETERS: Name - The ACPI name to be repaired |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 676 | * RETURN: Repaired version of the name |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 678 | * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and |
| 679 | * return the new name. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | * |
| 681 | ******************************************************************************/ |
| 682 | |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 683 | acpi_name acpi_ut_repair_name(char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 685 | u32 i; |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 686 | char new_name[ACPI_NAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 688 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 689 | new_name[i] = name[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 691 | /* |
| 692 | * Replace a bad character with something printable, yet technically |
| 693 | * still invalid. This prevents any collisions with existing "good" |
| 694 | * names in the namespace. |
| 695 | */ |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 696 | if (!acpi_ut_valid_acpi_char(name[i], i)) { |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 697 | new_name[i] = '*'; |
| 698 | } |
| 699 | } |
| 700 | |
Bob Moore | 3d81b23 | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 701 | return (*(u32 *) new_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | /******************************************************************************* |
| 705 | * |
| 706 | * FUNCTION: acpi_ut_strtoul64 |
| 707 | * |
| 708 | * PARAMETERS: String - Null terminated string |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 709 | * Base - Radix of the string: 16 or ACPI_ANY_BASE; |
| 710 | * ACPI_ANY_BASE means 'in behalf of to_integer' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | * ret_integer - Where the converted integer is returned |
| 712 | * |
| 713 | * RETURN: Status and Converted value |
| 714 | * |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 715 | * DESCRIPTION: Convert a string into an unsigned value. Performs either a |
| 716 | * 32-bit or 64-bit conversion, depending on the current mode |
| 717 | * of the interpreter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | * NOTE: Does not support Octal strings, not needed. |
| 719 | * |
| 720 | ******************************************************************************/ |
| 721 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 722 | acpi_status acpi_ut_strtoul64(char *string, u32 base, u64 * ret_integer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 724 | u32 this_digit = 0; |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 725 | u64 return_value = 0; |
| 726 | u64 quotient; |
| 727 | u64 dividend; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 728 | u32 to_integer_op = (base == ACPI_ANY_BASE); |
| 729 | u32 mode32 = (acpi_gbl_integer_byte_width == 4); |
| 730 | u8 valid_digits = 0; |
| 731 | u8 sign_of0x = 0; |
| 732 | u8 term = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 734 | ACPI_FUNCTION_TRACE_STR(ut_stroul64, string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | switch (base) { |
| 737 | case ACPI_ANY_BASE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | case 16: |
| 739 | break; |
| 740 | |
| 741 | default: |
| 742 | /* Invalid Base */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 743 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 746 | if (!string) { |
| 747 | goto error_exit; |
| 748 | } |
| 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | /* Skip over any white space in the buffer */ |
| 751 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 752 | while ((*string) && (ACPI_IS_SPACE(*string) || *string == '\t')) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | string++; |
| 754 | } |
| 755 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 756 | if (to_integer_op) { |
| 757 | /* |
| 758 | * Base equal to ACPI_ANY_BASE means 'to_integer operation case'. |
| 759 | * We need to determine if it is decimal or hexadecimal. |
| 760 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | if ((*string == '0') && (ACPI_TOLOWER(*(string + 1)) == 'x')) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 762 | sign_of0x = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | base = 16; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 764 | |
| 765 | /* Skip over the leading '0x' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | string += 2; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 767 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | base = 10; |
| 769 | } |
| 770 | } |
| 771 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 772 | /* Any string left? Check that '0x' is not followed by white space. */ |
| 773 | |
| 774 | if (!(*string) || ACPI_IS_SPACE(*string) || *string == '\t') { |
| 775 | if (to_integer_op) { |
| 776 | goto error_exit; |
| 777 | } else { |
| 778 | goto all_done; |
| 779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 782 | /* |
| 783 | * Perform a 32-bit or 64-bit conversion, depending upon the current |
| 784 | * execution mode of the interpreter |
| 785 | */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 786 | dividend = (mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 788 | /* Main loop: convert the string to a 32- or 64-bit integer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | while (*string) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 791 | if (ACPI_IS_DIGIT(*string)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* Convert ASCII 0-9 to Decimal value */ |
| 794 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | this_digit = ((u8) * string) - '0'; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 796 | } else if (base == 10) { |
| 797 | |
| 798 | /* Digit is out of range; possible in to_integer case only */ |
| 799 | |
| 800 | term = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 801 | } else { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 | this_digit = (u8) ACPI_TOUPPER(*string); |
| 803 | if (ACPI_IS_XDIGIT((char)this_digit)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | /* Convert ASCII Hex char to value */ |
| 806 | |
| 807 | this_digit = this_digit - 'A' + 10; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | } else { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 809 | term = 1; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | if (term) { |
| 814 | if (to_integer_op) { |
| 815 | goto error_exit; |
| 816 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | break; |
| 818 | } |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 819 | } else if ((valid_digits == 0) && (this_digit == 0) |
| 820 | && !sign_of0x) { |
| 821 | |
| 822 | /* Skip zeros */ |
| 823 | string++; |
| 824 | continue; |
| 825 | } |
| 826 | |
| 827 | valid_digits++; |
| 828 | |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 829 | if (sign_of0x && ((valid_digits > 16) |
| 830 | || ((valid_digits > 8) && mode32))) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 831 | /* |
| 832 | * This is to_integer operation case. |
| 833 | * No any restrictions for string-to-integer conversion, |
| 834 | * see ACPI spec. |
| 835 | */ |
| 836 | goto error_exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | /* Divide the digit into the correct position */ |
| 840 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 841 | (void)acpi_ut_short_divide((dividend - (u64) this_digit), |
| 842 | base, "ient, NULL); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | if (return_value > quotient) { |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 845 | if (to_integer_op) { |
| 846 | goto error_exit; |
| 847 | } else { |
| 848 | break; |
| 849 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | return_value *= base; |
| 853 | return_value += this_digit; |
| 854 | string++; |
| 855 | } |
| 856 | |
| 857 | /* All done, normal exit */ |
| 858 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 859 | all_done: |
| 860 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 861 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", |
| 862 | ACPI_FORMAT_UINT64(return_value))); |
| 863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | *ret_integer = return_value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 865 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 867 | error_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* Base was set/validated above */ |
| 869 | |
| 870 | if (base == 10) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | return_ACPI_STATUS(AE_BAD_DECIMAL_CONSTANT); |
| 872 | } else { |
| 873 | return_ACPI_STATUS(AE_BAD_HEX_CONSTANT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | /******************************************************************************* |
| 878 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | * FUNCTION: acpi_ut_create_update_state_and_push |
| 880 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 881 | * PARAMETERS: Object - Object to be added to the new state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | * Action - Increment/Decrement |
| 883 | * state_list - List the state will be added to |
| 884 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 885 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | * |
| 887 | * DESCRIPTION: Create a new state and push it |
| 888 | * |
| 889 | ******************************************************************************/ |
| 890 | |
| 891 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 892 | acpi_ut_create_update_state_and_push(union acpi_operand_object *object, |
| 893 | u16 action, |
| 894 | union acpi_generic_state **state_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 896 | union acpi_generic_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 898 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | /* Ignore null objects; these are expected */ |
| 901 | |
| 902 | if (!object) { |
| 903 | return (AE_OK); |
| 904 | } |
| 905 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 906 | state = acpi_ut_create_update_state(object, action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if (!state) { |
| 908 | return (AE_NO_MEMORY); |
| 909 | } |
| 910 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 911 | acpi_ut_push_generic_state(state_list, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | return (AE_OK); |
| 913 | } |
| 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | /******************************************************************************* |
| 916 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | * FUNCTION: acpi_ut_walk_package_tree |
| 918 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 919 | * PARAMETERS: source_object - The package to walk |
| 920 | * target_object - Target object (if package is being copied) |
| 921 | * walk_callback - Called once for each package element |
| 922 | * Context - Passed to the callback function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | * |
| 924 | * RETURN: Status |
| 925 | * |
| 926 | * DESCRIPTION: Walk through a package |
| 927 | * |
| 928 | ******************************************************************************/ |
| 929 | |
| 930 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 931 | acpi_ut_walk_package_tree(union acpi_operand_object * source_object, |
| 932 | void *target_object, |
| 933 | acpi_pkg_callback walk_callback, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 935 | acpi_status status = AE_OK; |
| 936 | union acpi_generic_state *state_list = NULL; |
| 937 | union acpi_generic_state *state; |
| 938 | u32 this_index; |
| 939 | union acpi_operand_object *this_source_obj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 941 | ACPI_FUNCTION_TRACE(ut_walk_package_tree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 943 | state = acpi_ut_create_pkg_state(source_object, target_object, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 945 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | while (state) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | /* Get one element of the package */ |
| 951 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 952 | this_index = state->pkg.index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | this_source_obj = (union acpi_operand_object *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 954 | state->pkg.source_object->package.elements[this_index]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
| 956 | /* |
| 957 | * Check for: |
| 958 | * 1) An uninitialized package element. It is completely |
| 959 | * legal to declare a package and leave it uninitialized |
| 960 | * 2) Not an internal object - can be a namespace node instead |
| 961 | * 3) Any type other than a package. Packages are handled in else |
| 962 | * case below. |
| 963 | */ |
| 964 | if ((!this_source_obj) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 965 | (ACPI_GET_DESCRIPTOR_TYPE(this_source_obj) != |
| 966 | ACPI_DESC_TYPE_OPERAND) |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 967 | || (this_source_obj->common.type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 968 | status = |
| 969 | walk_callback(ACPI_COPY_TYPE_SIMPLE, |
| 970 | this_source_obj, state, context); |
| 971 | if (ACPI_FAILURE(status)) { |
| 972 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | state->pkg.index++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 976 | while (state->pkg.index >= |
| 977 | state->pkg.source_object->package.count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | /* |
| 979 | * We've handled all of the objects at this level, This means |
| 980 | * that we have just completed a package. That package may |
| 981 | * have contained one or more packages itself. |
| 982 | * |
| 983 | * Delete this state and pop the previous state (package). |
| 984 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 985 | acpi_ut_delete_generic_state(state); |
| 986 | state = acpi_ut_pop_generic_state(&state_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | /* Finished when there are no more states */ |
| 989 | |
| 990 | if (!state) { |
| 991 | /* |
| 992 | * We have handled all of the objects in the top level |
| 993 | * package just add the length of the package objects |
| 994 | * and exit |
| 995 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 996 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /* |
| 1000 | * Go back up a level and move the index past the just |
| 1001 | * completed package object. |
| 1002 | */ |
| 1003 | state->pkg.index++; |
| 1004 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1005 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | /* This is a subobject of type package */ |
| 1007 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1008 | status = |
| 1009 | walk_callback(ACPI_COPY_TYPE_PACKAGE, |
| 1010 | this_source_obj, state, context); |
| 1011 | if (ACPI_FAILURE(status)) { |
| 1012 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Push the current state and create a new one |
| 1017 | * The callback above returned a new target package object. |
| 1018 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1019 | acpi_ut_push_generic_state(&state_list, state); |
| 1020 | state = acpi_ut_create_pkg_state(this_source_obj, |
| 1021 | state->pkg. |
| 1022 | this_target_obj, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (!state) { |
Lin Ming | cf058bd | 2008-09-27 11:29:57 +0800 | [diff] [blame] | 1024 | |
| 1025 | /* Free any stacked Update State objects */ |
| 1026 | |
| 1027 | while (state_list) { |
| 1028 | state = |
| 1029 | acpi_ut_pop_generic_state |
| 1030 | (&state_list); |
| 1031 | acpi_ut_delete_generic_state(state); |
| 1032 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1033 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | /* We should never get here */ |
| 1039 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1040 | return_ACPI_STATUS(AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |