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