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