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