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