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