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