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