|
||||
Warning, cross-references for /kernel/drivers/acpica/exutils.c need to be fixed.
0001 0002 /****************************************************************************** 0003 * 0004 * Module Name: exutils - interpreter/scanner utilities 0005 * 0006 *****************************************************************************/ 0007 0008 /****************************************************************************** 0009 * 0010 * 1. Copyright Notice 0011 * 0012 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 0013 * All rights reserved. 0014 * 0015 * 2. License 0016 * 0017 * 2.1. This is your license from Intel Corp. under its intellectual property 0018 * rights. You may have additional license terms from the party that provided 0019 * you this software, covering your right to use that party's intellectual 0020 * property rights. 0021 * 0022 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 0023 * copy of the source code appearing in this file ("Covered Code") an 0024 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 0025 * base code distributed originally by Intel ("Original Intel Code") to copy, 0026 * make derivatives, distribute, use and display any portion of the Covered 0027 * Code in any form, with the right to sublicense such rights; and 0028 * 0029 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 0030 * license (with the right to sublicense), under only those claims of Intel 0031 * patents that are infringed by the Original Intel Code, to make, use, sell, 0032 * offer to sell, and import the Covered Code and derivative works thereof 0033 * solely to the minimum extent necessary to exercise the above copyright 0034 * license, and in no event shall the patent license extend to any additions 0035 * to or modifications of the Original Intel Code. No other license or right 0036 * is granted directly or by implication, estoppel or otherwise; 0037 * 0038 * The above copyright and patent license is granted only if the following 0039 * conditions are met: 0040 * 0041 * 3. Conditions 0042 * 0043 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 0044 * Redistribution of source code of any substantial portion of the Covered 0045 * Code or modification with rights to further distribute source must include 0046 * the above Copyright Notice, the above License, this list of Conditions, 0047 * and the following Disclaimer and Export Compliance provision. In addition, 0048 * Licensee must cause all Covered Code to which Licensee contributes to 0049 * contain a file documenting the changes Licensee made to create that Covered 0050 * Code and the date of any change. Licensee must include in that file the 0051 * documentation of any changes made by any predecessor Licensee. Licensee 0052 * must include a prominent statement that the modification is derived, 0053 * directly or indirectly, from Original Intel Code. 0054 * 0055 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 0056 * Redistribution of source code of any substantial portion of the Covered 0057 * Code or modification without rights to further distribute source must 0058 * include the following Disclaimer and Export Compliance provision in the 0059 * documentation and/or other materials provided with distribution. In 0060 * addition, Licensee may not authorize further sublicense of source of any 0061 * portion of the Covered Code, and must include terms to the effect that the 0062 * license from Licensee to its licensee is limited to the intellectual 0063 * property embodied in the software Licensee provides to its licensee, and 0064 * not to intellectual property embodied in modifications its licensee may 0065 * make. 0066 * 0067 * 3.3. Redistribution of Executable. Redistribution in executable form of any 0068 * substantial portion of the Covered Code or modification must reproduce the 0069 * above Copyright Notice, and the following Disclaimer and Export Compliance 0070 * provision in the documentation and/or other materials provided with the 0071 * distribution. 0072 * 0073 * 3.4. Intel retains all right, title, and interest in and to the Original 0074 * Intel Code. 0075 * 0076 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 0077 * Intel shall be used in advertising or otherwise to promote the sale, use or 0078 * other dealings in products derived from or relating to the Covered Code 0079 * without prior written authorization from Intel. 0080 * 0081 * 4. Disclaimer and Export Compliance 0082 * 0083 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 0084 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 0085 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 0086 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 0087 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 0088 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 0089 * PARTICULAR PURPOSE. 0090 * 0091 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 0092 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 0093 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 0094 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 0095 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 0096 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 0097 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 0098 * LIMITED REMEDY. 0099 * 0100 * 4.3. Licensee shall not export, either directly or indirectly, any of this 0101 * software or system incorporating such software without first obtaining any 0102 * required license or other approval from the U. S. Department of Commerce or 0103 * any other agency or department of the United States Government. In the 0104 * event Licensee exports any such software from the United States or 0105 * re-exports any such software from a foreign destination, Licensee shall 0106 * ensure that the distribution and export/re-export of the software is in 0107 * compliance with all laws, regulations, orders, or other restrictions of the 0108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 0109 * any of its subsidiaries will export/re-export any technical data, process, 0110 * software, or service, directly or indirectly, to any country for which the 0111 * United States government or any agency thereof requires an export license, 0112 * other governmental approval, or letter of assurance, without first obtaining 0113 * such license, approval or letter. 0114 * 0115 *****************************************************************************/ 0116 0117 #define __EXUTILS_C__ 0118 0119 /* 0120 * DEFINE_AML_GLOBALS is tested in amlcode.h 0121 * to determine whether certain global names should be "defined" or only 0122 * "declared" in the current compilation. This enhances maintainability 0123 * by enabling a single header file to embody all knowledge of the names 0124 * in question. 0125 * 0126 * Exactly one module of any executable should #define DEFINE_GLOBALS 0127 * before #including the header files which use this convention. The 0128 * names in question will be defined and initialized in that module, 0129 * and declared as extern in all other modules which #include those 0130 * header files. 0131 */ 0132 0133 #define DEFINE_AML_GLOBALS 0134 0135 #include "acpi.h" 0136 #include "accommon.h" 0137 #include "acinterp.h" 0138 #include "amlcode.h" 0139 0140 #define _COMPONENT ACPI_EXECUTER 0141 ACPI_MODULE_NAME ("exutils") 0142 0143 /* Local prototypes */ 0144 0145 static UINT32 0146 AcpiExDigitsNeeded ( 0147 ACPI_INTEGER Value, 0148 UINT32 Base); 0149 0150 0151 #ifndef ACPI_NO_METHOD_EXECUTION 0152 /******************************************************************************* 0153 * 0154 * FUNCTION: AcpiExEnterInterpreter 0155 * 0156 * PARAMETERS: None 0157 * 0158 * RETURN: None 0159 * 0160 * DESCRIPTION: Enter the interpreter execution region. Failure to enter 0161 * the interpreter region is a fatal system error. Used in 0162 * conjunction with ExitInterpreter. 0163 * 0164 ******************************************************************************/ 0165 0166 void 0167 AcpiExEnterInterpreter ( 0168 void) 0169 { 0170 ACPI_STATUS Status; 0171 0172 0173 ACPI_FUNCTION_TRACE (ExEnterInterpreter); 0174 0175 0176 Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER); 0177 if (ACPI_FAILURE (Status)) 0178 { 0179 ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex")); 0180 } 0181 0182 return_VOID; 0183 } 0184 0185 0186 /******************************************************************************* 0187 * 0188 * FUNCTION: AcpiExReacquireInterpreter 0189 * 0190 * PARAMETERS: None 0191 * 0192 * RETURN: None 0193 * 0194 * DESCRIPTION: Reacquire the interpreter execution region from within the 0195 * interpreter code. Failure to enter the interpreter region is a 0196 * fatal system error. Used in conjuction with 0197 * RelinquishInterpreter 0198 * 0199 ******************************************************************************/ 0200 0201 void 0202 AcpiExReacquireInterpreter ( 0203 void) 0204 { 0205 ACPI_FUNCTION_TRACE (ExReacquireInterpreter); 0206 0207 0208 /* 0209 * If the global serialized flag is set, do not release the interpreter, 0210 * since it was not actually released by AcpiExRelinquishInterpreter. 0211 * This forces the interpreter to be single threaded. 0212 */ 0213 if (!AcpiGbl_AllMethodsSerialized) 0214 { 0215 AcpiExEnterInterpreter (); 0216 } 0217 0218 return_VOID; 0219 } 0220 0221 0222 /******************************************************************************* 0223 * 0224 * FUNCTION: AcpiExExitInterpreter 0225 * 0226 * PARAMETERS: None 0227 * 0228 * RETURN: None 0229 * 0230 * DESCRIPTION: Exit the interpreter execution region. This is the top level 0231 * routine used to exit the interpreter when all processing has 0232 * been completed. 0233 * 0234 ******************************************************************************/ 0235 0236 void 0237 AcpiExExitInterpreter ( 0238 void) 0239 { 0240 ACPI_STATUS Status; 0241 0242 0243 ACPI_FUNCTION_TRACE (ExExitInterpreter); 0244 0245 0246 Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER); 0247 if (ACPI_FAILURE (Status)) 0248 { 0249 ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex")); 0250 } 0251 0252 return_VOID; 0253 } 0254 0255 0256 /******************************************************************************* 0257 * 0258 * FUNCTION: AcpiExRelinquishInterpreter 0259 * 0260 * PARAMETERS: None 0261 * 0262 * RETURN: None 0263 * 0264 * DESCRIPTION: Exit the interpreter execution region, from within the 0265 * interpreter - before attempting an operation that will possibly 0266 * block the running thread. 0267 * 0268 * Cases where the interpreter is unlocked internally 0269 * 1) Method to be blocked on a Sleep() AML opcode 0270 * 2) Method to be blocked on an Acquire() AML opcode 0271 * 3) Method to be blocked on a Wait() AML opcode 0272 * 4) Method to be blocked to acquire the global lock 0273 * 5) Method to be blocked waiting to execute a serialized control method 0274 * that is currently executing 0275 * 6) About to invoke a user-installed opregion handler 0276 * 0277 ******************************************************************************/ 0278 0279 void 0280 AcpiExRelinquishInterpreter ( 0281 void) 0282 { 0283 ACPI_FUNCTION_TRACE (ExRelinquishInterpreter); 0284 0285 0286 /* 0287 * If the global serialized flag is set, do not release the interpreter. 0288 * This forces the interpreter to be single threaded. 0289 */ 0290 if (!AcpiGbl_AllMethodsSerialized) 0291 { 0292 AcpiExExitInterpreter (); 0293 } 0294 0295 return_VOID; 0296 } 0297 0298 0299 /******************************************************************************* 0300 * 0301 * FUNCTION: AcpiExTruncateFor32bitTable 0302 * 0303 * PARAMETERS: ObjDesc - Object to be truncated 0304 * 0305 * RETURN: none 0306 * 0307 * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is 0308 * 32-bit, as determined by the revision of the DSDT. 0309 * 0310 ******************************************************************************/ 0311 0312 void 0313 AcpiExTruncateFor32bitTable ( 0314 ACPI_OPERAND_OBJECT *ObjDesc) 0315 { 0316 0317 ACPI_FUNCTION_ENTRY (); 0318 0319 0320 /* 0321 * Object must be a valid number and we must be executing 0322 * a control method. NS node could be there for AML_INT_NAMEPATH_OP. 0323 */ 0324 if ((!ObjDesc) || 0325 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) || 0326 (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)) 0327 { 0328 return; 0329 } 0330 0331 if (AcpiGbl_IntegerByteWidth == 4) 0332 { 0333 /* 0334 * We are running a method that exists in a 32-bit ACPI table. 0335 * Truncate the value to 32 bits by zeroing out the upper 32-bit field 0336 */ 0337 ObjDesc->Integer.Value &= (ACPI_INTEGER) ACPI_UINT32_MAX; 0338 } 0339 } 0340 0341 0342 /******************************************************************************* 0343 * 0344 * FUNCTION: AcpiExAcquireGlobalLock 0345 * 0346 * PARAMETERS: FieldFlags - Flags with Lock rule: 0347 * AlwaysLock or NeverLock 0348 * 0349 * RETURN: None 0350 * 0351 * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field 0352 * flags specifiy that it is to be obtained before field access. 0353 * 0354 ******************************************************************************/ 0355 0356 void 0357 AcpiExAcquireGlobalLock ( 0358 UINT32 FieldFlags) 0359 { 0360 ACPI_STATUS Status; 0361 0362 0363 ACPI_FUNCTION_TRACE (ExAcquireGlobalLock); 0364 0365 0366 /* Only use the lock if the AlwaysLock bit is set */ 0367 0368 if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK)) 0369 { 0370 return_VOID; 0371 } 0372 0373 /* Attempt to get the global lock, wait forever */ 0374 0375 Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER, 0376 AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ()); 0377 0378 if (ACPI_FAILURE (Status)) 0379 { 0380 ACPI_EXCEPTION ((AE_INFO, Status, 0381 "Could not acquire Global Lock")); 0382 } 0383 0384 return_VOID; 0385 } 0386 0387 0388 /******************************************************************************* 0389 * 0390 * FUNCTION: AcpiExReleaseGlobalLock 0391 * 0392 * PARAMETERS: FieldFlags - Flags with Lock rule: 0393 * AlwaysLock or NeverLock 0394 * 0395 * RETURN: None 0396 * 0397 * DESCRIPTION: Release the ACPI hardware Global Lock 0398 * 0399 ******************************************************************************/ 0400 0401 void 0402 AcpiExReleaseGlobalLock ( 0403 UINT32 FieldFlags) 0404 { 0405 ACPI_STATUS Status; 0406 0407 0408 ACPI_FUNCTION_TRACE (ExReleaseGlobalLock); 0409 0410 0411 /* Only use the lock if the AlwaysLock bit is set */ 0412 0413 if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK)) 0414 { 0415 return_VOID; 0416 } 0417 0418 /* Release the global lock */ 0419 0420 Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex); 0421 if (ACPI_FAILURE (Status)) 0422 { 0423 /* Report the error, but there isn't much else we can do */ 0424 0425 ACPI_EXCEPTION ((AE_INFO, Status, 0426 "Could not release Global Lock")); 0427 } 0428 0429 return_VOID; 0430 } 0431 0432 0433 /******************************************************************************* 0434 * 0435 * FUNCTION: AcpiExDigitsNeeded 0436 * 0437 * PARAMETERS: Value - Value to be represented 0438 * Base - Base of representation 0439 * 0440 * RETURN: The number of digits. 0441 * 0442 * DESCRIPTION: Calculate the number of digits needed to represent the Value 0443 * in the given Base (Radix) 0444 * 0445 ******************************************************************************/ 0446 0447 static UINT32 0448 AcpiExDigitsNeeded ( 0449 ACPI_INTEGER Value, 0450 UINT32 Base) 0451 { 0452 UINT32 NumDigits; 0453 ACPI_INTEGER CurrentValue; 0454 0455 0456 ACPI_FUNCTION_TRACE (ExDigitsNeeded); 0457 0458 0459 /* ACPI_INTEGER is unsigned, so we don't worry about a '-' prefix */ 0460 0461 if (Value == 0) 0462 { 0463 return_UINT32 (1); 0464 } 0465 0466 CurrentValue = Value; 0467 NumDigits = 0; 0468 0469 /* Count the digits in the requested base */ 0470 0471 while (CurrentValue) 0472 { 0473 (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL); 0474 NumDigits++; 0475 } 0476 0477 return_UINT32 (NumDigits); 0478 } 0479 0480 0481 /******************************************************************************* 0482 * 0483 * FUNCTION: AcpiExEisaIdToString 0484 * 0485 * PARAMETERS: CompressedId - EISAID to be converted 0486 * OutString - Where to put the converted string (8 bytes) 0487 * 0488 * RETURN: None 0489 * 0490 * DESCRIPTION: Convert a numeric EISAID to string representation. Return 0491 * buffer must be large enough to hold the string. The string 0492 * returned is always exactly of length ACPI_EISAID_STRING_SIZE 0493 * (includes null terminator). The EISAID is always 32 bits. 0494 * 0495 ******************************************************************************/ 0496 0497 void 0498 AcpiExEisaIdToString ( 0499 char *OutString, 0500 ACPI_INTEGER CompressedId) 0501 { 0502 UINT32 SwappedId; 0503 0504 0505 ACPI_FUNCTION_ENTRY (); 0506 0507 0508 /* The EISAID should be a 32-bit integer */ 0509 0510 if (CompressedId > ACPI_UINT32_MAX) 0511 { 0512 ACPI_WARNING ((AE_INFO, 0513 "Expected EISAID is larger than 32 bits: 0x%8.8X%8.8X, truncating", 0514 ACPI_FORMAT_UINT64 (CompressedId))); 0515 } 0516 0517 /* Swap ID to big-endian to get contiguous bits */ 0518 0519 SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId); 0520 0521 /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */ 0522 0523 OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F)); 0524 OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F)); 0525 OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F)); 0526 OutString[3] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 12); 0527 OutString[4] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 8); 0528 OutString[5] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 4); 0529 OutString[6] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 0); 0530 OutString[7] = 0; 0531 } 0532 0533 0534 /******************************************************************************* 0535 * 0536 * FUNCTION: AcpiExIntegerToString 0537 * 0538 * PARAMETERS: OutString - Where to put the converted string. At least 0539 * 21 bytes are needed to hold the largest 0540 * possible 64-bit integer. 0541 * Value - Value to be converted 0542 * 0543 * RETURN: None, string 0544 * 0545 * DESCRIPTION: Convert a 64-bit integer to decimal string representation. 0546 * Assumes string buffer is large enough to hold the string. The 0547 * largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1). 0548 * 0549 ******************************************************************************/ 0550 0551 void 0552 AcpiExIntegerToString ( 0553 char *OutString, 0554 ACPI_INTEGER Value) 0555 { 0556 UINT32 Count; 0557 UINT32 DigitsNeeded; 0558 UINT32 Remainder; 0559 0560 0561 ACPI_FUNCTION_ENTRY (); 0562 0563 0564 DigitsNeeded = AcpiExDigitsNeeded (Value, 10); 0565 OutString[DigitsNeeded] = 0; 0566 0567 for (Count = DigitsNeeded; Count > 0; Count--) 0568 { 0569 (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder); 0570 OutString[Count-1] = (char) ('0' + Remainder);\ 0571 } 0572 } 0573 0574 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 1.2.0 LXR engine. |