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