ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

exutils.c
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  *
00004  * Module Name: exutils - interpreter/scanner utilities
00005  *
00006  *****************************************************************************/
00007 
00008 /******************************************************************************
00009  *
00010  * 1. Copyright Notice
00011  *
00012  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00013  * All rights reserved.
00014  *
00015  * 2. License
00016  *
00017  * 2.1. This is your license from Intel Corp. under its intellectual property
00018  * rights.  You may have additional license terms from the party that provided
00019  * you this software, covering your right to use that party's intellectual
00020  * property rights.
00021  *
00022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00023  * copy of the source code appearing in this file ("Covered Code") an
00024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00025  * base code distributed originally by Intel ("Original Intel Code") to copy,
00026  * make derivatives, distribute, use and display any portion of the Covered
00027  * Code in any form, with the right to sublicense such rights; and
00028  *
00029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00030  * license (with the right to sublicense), under only those claims of Intel
00031  * patents that are infringed by the Original Intel Code, to make, use, sell,
00032  * offer to sell, and import the Covered Code and derivative works thereof
00033  * solely to the minimum extent necessary to exercise the above copyright
00034  * license, and in no event shall the patent license extend to any additions
00035  * to or modifications of the Original Intel Code.  No other license or right
00036  * is granted directly or by implication, estoppel or otherwise;
00037  *
00038  * The above copyright and patent license is granted only if the following
00039  * conditions are met:
00040  *
00041  * 3. Conditions
00042  *
00043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00044  * Redistribution of source code of any substantial portion of the Covered
00045  * Code or modification with rights to further distribute source must include
00046  * the above Copyright Notice, the above License, this list of Conditions,
00047  * and the following Disclaimer and Export Compliance provision.  In addition,
00048  * Licensee must cause all Covered Code to which Licensee contributes to
00049  * contain a file documenting the changes Licensee made to create that Covered
00050  * Code and the date of any change.  Licensee must include in that file the
00051  * documentation of any changes made by any predecessor Licensee.  Licensee
00052  * must include a prominent statement that the modification is derived,
00053  * directly or indirectly, from Original Intel Code.
00054  *
00055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00056  * Redistribution of source code of any substantial portion of the Covered
00057  * Code or modification without rights to further distribute source must
00058  * include the following Disclaimer and Export Compliance provision in the
00059  * documentation and/or other materials provided with distribution.  In
00060  * addition, Licensee may not authorize further sublicense of source of any
00061  * portion of the Covered Code, and must include terms to the effect that the
00062  * license from Licensee to its licensee is limited to the intellectual
00063  * property embodied in the software Licensee provides to its licensee, and
00064  * not to intellectual property embodied in modifications its licensee may
00065  * make.
00066  *
00067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00068  * substantial portion of the Covered Code or modification must reproduce the
00069  * above Copyright Notice, and the following Disclaimer and Export Compliance
00070  * provision in the documentation and/or other materials provided with the
00071  * distribution.
00072  *
00073  * 3.4. Intel retains all right, title, and interest in and to the Original
00074  * Intel Code.
00075  *
00076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00077  * Intel shall be used in advertising or otherwise to promote the sale, use or
00078  * other dealings in products derived from or relating to the Covered Code
00079  * without prior written authorization from Intel.
00080  *
00081  * 4. Disclaimer and Export Compliance
00082  *
00083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00089  * PARTICULAR PURPOSE.
00090  *
00091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00098  * LIMITED REMEDY.
00099  *
00100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00101  * software or system incorporating such software without first obtaining any
00102  * required license or other approval from the U. S. Department of Commerce or
00103  * any other agency or department of the United States Government.  In the
00104  * event Licensee exports any such software from the United States or
00105  * re-exports any such software from a foreign destination, Licensee shall
00106  * ensure that the distribution and export/re-export of the software is in
00107  * compliance with all laws, regulations, orders, or other restrictions of the
00108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00109  * any of its subsidiaries will export/re-export any technical data, process,
00110  * software, or service, directly or indirectly, to any country for which the
00111  * United States government or any agency thereof requires an export license,
00112  * other governmental approval, or letter of assurance, without first obtaining
00113  * such license, approval or letter.
00114  *
00115  *****************************************************************************/
00116 
00117 #define __EXUTILS_C__
00118 
00119 /*
00120  * DEFINE_AML_GLOBALS is tested in amlcode.h
00121  * to determine whether certain global names should be "defined" or only
00122  * "declared" in the current compilation.  This enhances maintainability
00123  * by enabling a single header file to embody all knowledge of the names
00124  * in question.
00125  *
00126  * Exactly one module of any executable should #define DEFINE_GLOBALS
00127  * before #including the header files which use this convention.  The
00128  * names in question will be defined and initialized in that module,
00129  * and declared as extern in all other modules which #include those
00130  * header files.
00131  */
00132 
00133 #define DEFINE_AML_GLOBALS
00134 
00135 #include "acpi.h"
00136 #include "accommon.h"
00137 #include "acinterp.h"
00138 #include "amlcode.h"
00139 
00140 #define _COMPONENT          ACPI_EXECUTER
00141         ACPI_MODULE_NAME    ("exutils")
00142 
00143 /* Local prototypes */
00144 
00145 static UINT32
00146 AcpiExDigitsNeeded (
00147     UINT64                  Value,
00148     UINT32                  Base);
00149 
00150 
00151 #ifndef ACPI_NO_METHOD_EXECUTION
00152 /*******************************************************************************
00153  *
00154  * FUNCTION:    AcpiExEnterInterpreter
00155  *
00156  * PARAMETERS:  None
00157  *
00158  * RETURN:      None
00159  *
00160  * DESCRIPTION: Enter the interpreter execution region. Failure to enter
00161  *              the interpreter region is a fatal system error. Used in
00162  *              conjunction with ExitInterpreter.
00163  *
00164  ******************************************************************************/
00165 
00166 void
00167 AcpiExEnterInterpreter (
00168     void)
00169 {
00170     ACPI_STATUS             Status;
00171 
00172 
00173     ACPI_FUNCTION_TRACE (ExEnterInterpreter);
00174 
00175 
00176     Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
00177     if (ACPI_FAILURE (Status))
00178     {
00179         ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
00180     }
00181 
00182     return_VOID;
00183 }
00184 
00185 
00186 /*******************************************************************************
00187  *
00188  * FUNCTION:    AcpiExReacquireInterpreter
00189  *
00190  * PARAMETERS:  None
00191  *
00192  * RETURN:      None
00193  *
00194  * DESCRIPTION: Reacquire the interpreter execution region from within the
00195  *              interpreter code. Failure to enter the interpreter region is a
00196  *              fatal system error. Used in  conjuction with
00197  *              RelinquishInterpreter
00198  *
00199  ******************************************************************************/
00200 
00201 void
00202 AcpiExReacquireInterpreter (
00203     void)
00204 {
00205     ACPI_FUNCTION_TRACE (ExReacquireInterpreter);
00206 
00207 
00208     /*
00209      * If the global serialized flag is set, do not release the interpreter,
00210      * since it was not actually released by AcpiExRelinquishInterpreter.
00211      * This forces the interpreter to be single threaded.
00212      */
00213     if (!AcpiGbl_AllMethodsSerialized)
00214     {
00215         AcpiExEnterInterpreter ();
00216     }
00217 
00218     return_VOID;
00219 }
00220 
00221 
00222 /*******************************************************************************
00223  *
00224  * FUNCTION:    AcpiExExitInterpreter
00225  *
00226  * PARAMETERS:  None
00227  *
00228  * RETURN:      None
00229  *
00230  * DESCRIPTION: Exit the interpreter execution region. This is the top level
00231  *              routine used to exit the interpreter when all processing has
00232  *              been completed.
00233  *
00234  ******************************************************************************/
00235 
00236 void
00237 AcpiExExitInterpreter (
00238     void)
00239 {
00240     ACPI_STATUS             Status;
00241 
00242 
00243     ACPI_FUNCTION_TRACE (ExExitInterpreter);
00244 
00245 
00246     Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
00247     if (ACPI_FAILURE (Status))
00248     {
00249         ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
00250     }
00251 
00252     return_VOID;
00253 }
00254 
00255 
00256 /*******************************************************************************
00257  *
00258  * FUNCTION:    AcpiExRelinquishInterpreter
00259  *
00260  * PARAMETERS:  None
00261  *
00262  * RETURN:      None
00263  *
00264  * DESCRIPTION: Exit the interpreter execution region, from within the
00265  *              interpreter - before attempting an operation that will possibly
00266  *              block the running thread.
00267  *
00268  * Cases where the interpreter is unlocked internally
00269  *      1) Method to be blocked on a Sleep() AML opcode
00270  *      2) Method to be blocked on an Acquire() AML opcode
00271  *      3) Method to be blocked on a Wait() AML opcode
00272  *      4) Method to be blocked to acquire the global lock
00273  *      5) Method to be blocked waiting to execute a serialized control method
00274  *          that is currently executing
00275  *      6) About to invoke a user-installed opregion handler
00276  *
00277  ******************************************************************************/
00278 
00279 void
00280 AcpiExRelinquishInterpreter (
00281     void)
00282 {
00283     ACPI_FUNCTION_TRACE (ExRelinquishInterpreter);
00284 
00285 
00286     /*
00287      * If the global serialized flag is set, do not release the interpreter.
00288      * This forces the interpreter to be single threaded.
00289      */
00290     if (!AcpiGbl_AllMethodsSerialized)
00291     {
00292         AcpiExExitInterpreter ();
00293     }
00294 
00295     return_VOID;
00296 }
00297 
00298 
00299 /*******************************************************************************
00300  *
00301  * FUNCTION:    AcpiExTruncateFor32bitTable
00302  *
00303  * PARAMETERS:  ObjDesc         - Object to be truncated
00304  *
00305  * RETURN:      none
00306  *
00307  * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
00308  *              32-bit, as determined by the revision of the DSDT.
00309  *
00310  ******************************************************************************/
00311 
00312 void
00313 AcpiExTruncateFor32bitTable (
00314     ACPI_OPERAND_OBJECT     *ObjDesc)
00315 {
00316 
00317     ACPI_FUNCTION_ENTRY ();
00318 
00319 
00320     /*
00321      * Object must be a valid number and we must be executing
00322      * a control method. NS node could be there for AML_INT_NAMEPATH_OP.
00323      */
00324     if ((!ObjDesc) ||
00325         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
00326         (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
00327     {
00328         return;
00329     }
00330 
00331     if (AcpiGbl_IntegerByteWidth == 4)
00332     {
00333         /*
00334          * We are running a method that exists in a 32-bit ACPI table.
00335          * Truncate the value to 32 bits by zeroing out the upper 32-bit field
00336          */
00337         ObjDesc->Integer.Value &= (UINT64) ACPI_UINT32_MAX;
00338     }
00339 }
00340 
00341 
00342 /*******************************************************************************
00343  *
00344  * FUNCTION:    AcpiExAcquireGlobalLock
00345  *
00346  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
00347  *                                      AlwaysLock or NeverLock
00348  *
00349  * RETURN:      None
00350  *
00351  * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
00352  *              flags specifiy that it is to be obtained before field access.
00353  *
00354  ******************************************************************************/
00355 
00356 void
00357 AcpiExAcquireGlobalLock (
00358     UINT32                  FieldFlags)
00359 {
00360     ACPI_STATUS             Status;
00361 
00362 
00363     ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
00364 
00365 
00366     /* Only use the lock if the AlwaysLock bit is set */
00367 
00368     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
00369     {
00370         return_VOID;
00371     }
00372 
00373     /* Attempt to get the global lock, wait forever */
00374 
00375     Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
00376                 AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
00377 
00378     if (ACPI_FAILURE (Status))
00379     {
00380         ACPI_EXCEPTION ((AE_INFO, Status,
00381             "Could not acquire Global Lock"));
00382     }
00383 
00384     return_VOID;
00385 }
00386 
00387 
00388 /*******************************************************************************
00389  *
00390  * FUNCTION:    AcpiExReleaseGlobalLock
00391  *
00392  * PARAMETERS:  FieldFlags            - Flags with Lock rule:
00393  *                                      AlwaysLock or NeverLock
00394  *
00395  * RETURN:      None
00396  *
00397  * DESCRIPTION: Release the ACPI hardware Global Lock
00398  *
00399  ******************************************************************************/
00400 
00401 void
00402 AcpiExReleaseGlobalLock (
00403     UINT32                  FieldFlags)
00404 {
00405     ACPI_STATUS             Status;
00406 
00407 
00408     ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
00409 
00410 
00411     /* Only use the lock if the AlwaysLock bit is set */
00412 
00413     if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
00414     {
00415         return_VOID;
00416     }
00417 
00418     /* Release the global lock */
00419 
00420     Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
00421     if (ACPI_FAILURE (Status))
00422     {
00423         /* Report the error, but there isn't much else we can do */
00424 
00425         ACPI_EXCEPTION ((AE_INFO, Status,
00426             "Could not release Global Lock"));
00427     }
00428 
00429     return_VOID;
00430 }
00431 
00432 
00433 /*******************************************************************************
00434  *
00435  * FUNCTION:    AcpiExDigitsNeeded
00436  *
00437  * PARAMETERS:  Value           - Value to be represented
00438  *              Base            - Base of representation
00439  *
00440  * RETURN:      The number of digits.
00441  *
00442  * DESCRIPTION: Calculate the number of digits needed to represent the Value
00443  *              in the given Base (Radix)
00444  *
00445  ******************************************************************************/
00446 
00447 static UINT32
00448 AcpiExDigitsNeeded (
00449     UINT64                  Value,
00450     UINT32                  Base)
00451 {
00452     UINT32                  NumDigits;
00453     UINT64                  CurrentValue;
00454 
00455 
00456     ACPI_FUNCTION_TRACE (ExDigitsNeeded);
00457 
00458 
00459     /* UINT64 is unsigned, so we don't worry about a '-' prefix */
00460 
00461     if (Value == 0)
00462     {
00463         return_UINT32 (1);
00464     }
00465 
00466     CurrentValue = Value;
00467     NumDigits = 0;
00468 
00469     /* Count the digits in the requested base */
00470 
00471     while (CurrentValue)
00472     {
00473         (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
00474         NumDigits++;
00475     }
00476 
00477     return_UINT32 (NumDigits);
00478 }
00479 
00480 
00481 /*******************************************************************************
00482  *
00483  * FUNCTION:    AcpiExEisaIdToString
00484  *
00485  * PARAMETERS:  CompressedId    - EISAID to be converted
00486  *              OutString       - Where to put the converted string (8 bytes)
00487  *
00488  * RETURN:      None
00489  *
00490  * DESCRIPTION: Convert a numeric EISAID to string representation. Return
00491  *              buffer must be large enough to hold the string. The string
00492  *              returned is always exactly of length ACPI_EISAID_STRING_SIZE
00493  *              (includes null terminator). The EISAID is always 32 bits.
00494  *
00495  ******************************************************************************/
00496 
00497 void
00498 AcpiExEisaIdToString (
00499     char                    *OutString,
00500     UINT64                  CompressedId)
00501 {
00502     UINT32                  SwappedId;
00503 
00504 
00505     ACPI_FUNCTION_ENTRY ();
00506 
00507 
00508     /* The EISAID should be a 32-bit integer */
00509 
00510     if (CompressedId > ACPI_UINT32_MAX)
00511     {
00512         ACPI_WARNING ((AE_INFO,
00513             "Expected EISAID is larger than 32 bits: 0x%8.8X%8.8X, truncating",
00514             ACPI_FORMAT_UINT64 (CompressedId)));
00515     }
00516 
00517     /* Swap ID to big-endian to get contiguous bits */
00518 
00519     SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
00520 
00521     /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
00522 
00523     OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
00524     OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
00525     OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
00526     OutString[3] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 12);
00527     OutString[4] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 8);
00528     OutString[5] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 4);
00529     OutString[6] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 0);
00530     OutString[7] = 0;
00531 }
00532 
00533 
00534 /*******************************************************************************
00535  *
00536  * FUNCTION:    AcpiExIntegerToString
00537  *
00538  * PARAMETERS:  OutString       - Where to put the converted string. At least
00539  *                                21 bytes are needed to hold the largest
00540  *                                possible 64-bit integer.
00541  *              Value           - Value to be converted
00542  *
00543  * RETURN:      None, string
00544  *
00545  * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
00546  *              Assumes string buffer is large enough to hold the string. The
00547  *              largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
00548  *
00549  ******************************************************************************/
00550 
00551 void
00552 AcpiExIntegerToString (
00553     char                    *OutString,
00554     UINT64                  Value)
00555 {
00556     UINT32                  Count;
00557     UINT32                  DigitsNeeded;
00558     UINT32                  Remainder;
00559 
00560 
00561     ACPI_FUNCTION_ENTRY ();
00562 
00563 
00564     DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
00565     OutString[DigitsNeeded] = 0;
00566 
00567     for (Count = DigitsNeeded; Count > 0; Count--)
00568     {
00569         (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
00570         OutString[Count-1] = (char) ('0' + Remainder);\
00571     }
00572 }
00573 
00574 #endif

Generated on Sat May 26 2012 04:25:47 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.