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