Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/utmisc.c need to be fixed.

0001 /*******************************************************************************
0002  *
0003  * Module Name: utmisc - common utility procedures
0004  *
0005  ******************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 
0117 #define __UTMISC_C__
0118 
0119 #include "acpi.h"
0120 #include "accommon.h"
0121 #include "acnamesp.h"
0122 
0123 
0124 #define _COMPONENT          ACPI_UTILITIES
0125         ACPI_MODULE_NAME    ("utmisc")
0126 
0127 /*
0128  * Common suffix for messages
0129  */
0130 #define ACPI_COMMON_MSG_SUFFIX \
0131     AcpiOsPrintf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, ModuleName, LineNumber)
0132 
0133 
0134 /*******************************************************************************
0135  *
0136  * FUNCTION:    AcpiUtValidateException
0137  *
0138  * PARAMETERS:  Status       - The ACPI_STATUS code to be formatted
0139  *
0140  * RETURN:      A string containing the exception text. NULL if exception is
0141  *              not valid.
0142  *
0143  * DESCRIPTION: This function validates and translates an ACPI exception into
0144  *              an ASCII string.
0145  *
0146  ******************************************************************************/
0147 
0148 const char *
0149 AcpiUtValidateException (
0150     ACPI_STATUS             Status)
0151 {
0152     UINT32                  SubStatus;
0153     const char              *Exception = NULL;
0154 
0155 
0156     ACPI_FUNCTION_ENTRY ();
0157 
0158 
0159     /*
0160      * Status is composed of two parts, a "type" and an actual code
0161      */
0162     SubStatus = (Status & ~AE_CODE_MASK);
0163 
0164     switch (Status & AE_CODE_MASK)
0165     {
0166     case AE_CODE_ENVIRONMENTAL:
0167 
0168         if (SubStatus <= AE_CODE_ENV_MAX)
0169         {
0170             Exception = AcpiGbl_ExceptionNames_Env [SubStatus];
0171         }
0172         break;
0173 
0174     case AE_CODE_PROGRAMMER:
0175 
0176         if (SubStatus <= AE_CODE_PGM_MAX)
0177         {
0178             Exception = AcpiGbl_ExceptionNames_Pgm [SubStatus];
0179         }
0180         break;
0181 
0182     case AE_CODE_ACPI_TABLES:
0183 
0184         if (SubStatus <= AE_CODE_TBL_MAX)
0185         {
0186             Exception = AcpiGbl_ExceptionNames_Tbl [SubStatus];
0187         }
0188         break;
0189 
0190     case AE_CODE_AML:
0191 
0192         if (SubStatus <= AE_CODE_AML_MAX)
0193         {
0194             Exception = AcpiGbl_ExceptionNames_Aml [SubStatus];
0195         }
0196         break;
0197 
0198     case AE_CODE_CONTROL:
0199 
0200         if (SubStatus <= AE_CODE_CTRL_MAX)
0201         {
0202             Exception = AcpiGbl_ExceptionNames_Ctrl [SubStatus];
0203         }
0204         break;
0205 
0206     default:
0207         break;
0208     }
0209 
0210     return (ACPI_CAST_PTR (const char, Exception));
0211 }
0212 
0213 
0214 /*******************************************************************************
0215  *
0216  * FUNCTION:    AcpiUtIsPciRootBridge
0217  *
0218  * PARAMETERS:  Id              - The HID/CID in string format
0219  *
0220  * RETURN:      TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
0221  *
0222  * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
0223  *
0224  ******************************************************************************/
0225 
0226 BOOLEAN
0227 AcpiUtIsPciRootBridge (
0228     char                    *Id)
0229 {
0230 
0231     /*
0232      * Check if this is a PCI root bridge.
0233      * ACPI 3.0+: check for a PCI Express root also.
0234      */
0235     if (!(ACPI_STRCMP (Id,
0236             PCI_ROOT_HID_STRING)) ||
0237 
0238         !(ACPI_STRCMP (Id,
0239             PCI_EXPRESS_ROOT_HID_STRING)))
0240     {
0241         return (TRUE);
0242     }
0243 
0244     return (FALSE);
0245 }
0246 
0247 
0248 /*******************************************************************************
0249  *
0250  * FUNCTION:    AcpiUtIsAmlTable
0251  *
0252  * PARAMETERS:  Table               - An ACPI table
0253  *
0254  * RETURN:      TRUE if table contains executable AML; FALSE otherwise
0255  *
0256  * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
0257  *              Currently, these are DSDT,SSDT,PSDT. All other table types are
0258  *              data tables that do not contain AML code.
0259  *
0260  ******************************************************************************/
0261 
0262 BOOLEAN
0263 AcpiUtIsAmlTable (
0264     ACPI_TABLE_HEADER       *Table)
0265 {
0266 
0267     /* These are the only tables that contain executable AML */
0268 
0269     if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) ||
0270         ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_PSDT) ||
0271         ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
0272     {
0273         return (TRUE);
0274     }
0275 
0276     return (FALSE);
0277 }
0278 
0279 
0280 /*******************************************************************************
0281  *
0282  * FUNCTION:    AcpiUtAllocateOwnerId
0283  *
0284  * PARAMETERS:  OwnerId         - Where the new owner ID is returned
0285  *
0286  * RETURN:      Status
0287  *
0288  * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
0289  *              track objects created by the table or method, to be deleted
0290  *              when the method exits or the table is unloaded.
0291  *
0292  ******************************************************************************/
0293 
0294 ACPI_STATUS
0295 AcpiUtAllocateOwnerId (
0296     ACPI_OWNER_ID           *OwnerId)
0297 {
0298     UINT32                  i;
0299     UINT32                  j;
0300     UINT32                  k;
0301     ACPI_STATUS             Status;
0302 
0303 
0304     ACPI_FUNCTION_TRACE (UtAllocateOwnerId);
0305 
0306 
0307     /* Guard against multiple allocations of ID to the same location */
0308 
0309     if (*OwnerId)
0310     {
0311         ACPI_ERROR ((AE_INFO, "Owner ID [%2.2X] already exists", *OwnerId));
0312         return_ACPI_STATUS (AE_ALREADY_EXISTS);
0313     }
0314 
0315     /* Mutex for the global ID mask */
0316 
0317     Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
0318     if (ACPI_FAILURE (Status))
0319     {
0320         return_ACPI_STATUS (Status);
0321     }
0322 
0323     /*
0324      * Find a free owner ID, cycle through all possible IDs on repeated
0325      * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
0326      * to be scanned twice.
0327      */
0328     for (i = 0, j = AcpiGbl_LastOwnerIdIndex;
0329          i < (ACPI_NUM_OWNERID_MASKS + 1);
0330          i++, j++)
0331     {
0332         if (j >= ACPI_NUM_OWNERID_MASKS)
0333         {
0334             j = 0;  /* Wraparound to start of mask array */
0335         }
0336 
0337         for (k = AcpiGbl_NextOwnerIdOffset; k < 32; k++)
0338         {
0339             if (AcpiGbl_OwnerIdMask[j] == ACPI_UINT32_MAX)
0340             {
0341                 /* There are no free IDs in this mask */
0342 
0343                 break;
0344             }
0345 
0346             if (!(AcpiGbl_OwnerIdMask[j] & (1 << k)))
0347             {
0348                 /*
0349                  * Found a free ID. The actual ID is the bit index plus one,
0350                  * making zero an invalid Owner ID. Save this as the last ID
0351                  * allocated and update the global ID mask.
0352                  */
0353                 AcpiGbl_OwnerIdMask[j] |= (1 << k);
0354 
0355                 AcpiGbl_LastOwnerIdIndex = (UINT8) j;
0356                 AcpiGbl_NextOwnerIdOffset = (UINT8) (k + 1);
0357 
0358                 /*
0359                  * Construct encoded ID from the index and bit position
0360                  *
0361                  * Note: Last [j].k (bit 255) is never used and is marked
0362                  * permanently allocated (prevents +1 overflow)
0363                  */
0364                 *OwnerId = (ACPI_OWNER_ID) ((k + 1) + ACPI_MUL_32 (j));
0365 
0366                 ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
0367                     "Allocated OwnerId: %2.2X\n", (unsigned int) *OwnerId));
0368                 goto Exit;
0369             }
0370         }
0371 
0372         AcpiGbl_NextOwnerIdOffset = 0;
0373     }
0374 
0375     /*
0376      * All OwnerIds have been allocated. This typically should
0377      * not happen since the IDs are reused after deallocation. The IDs are
0378      * allocated upon table load (one per table) and method execution, and
0379      * they are released when a table is unloaded or a method completes
0380      * execution.
0381      *
0382      * If this error happens, there may be very deep nesting of invoked control
0383      * methods, or there may be a bug where the IDs are not released.
0384      */
0385     Status = AE_OWNER_ID_LIMIT;
0386     ACPI_ERROR ((AE_INFO,
0387         "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
0388 
0389 Exit:
0390     (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
0391     return_ACPI_STATUS (Status);
0392 }
0393 
0394 
0395 /*******************************************************************************
0396  *
0397  * FUNCTION:    AcpiUtReleaseOwnerId
0398  *
0399  * PARAMETERS:  OwnerIdPtr          - Pointer to a previously allocated OwnerID
0400  *
0401  * RETURN:      None. No error is returned because we are either exiting a
0402  *              control method or unloading a table. Either way, we would
0403  *              ignore any error anyway.
0404  *
0405  * DESCRIPTION: Release a table or method owner ID.  Valid IDs are 1 - 255
0406  *
0407  ******************************************************************************/
0408 
0409 void
0410 AcpiUtReleaseOwnerId (
0411     ACPI_OWNER_ID           *OwnerIdPtr)
0412 {
0413     ACPI_OWNER_ID           OwnerId = *OwnerIdPtr;
0414     ACPI_STATUS             Status;
0415     UINT32                  Index;
0416     UINT32                  Bit;
0417 
0418 
0419     ACPI_FUNCTION_TRACE_U32 (UtReleaseOwnerId, OwnerId);
0420 
0421 
0422     /* Always clear the input OwnerId (zero is an invalid ID) */
0423 
0424     *OwnerIdPtr = 0;
0425 
0426     /* Zero is not a valid OwnerID */
0427 
0428     if (OwnerId == 0)
0429     {
0430         ACPI_ERROR ((AE_INFO, "Invalid OwnerId: %2.2X", OwnerId));
0431         return_VOID;
0432     }
0433 
0434     /* Mutex for the global ID mask */
0435 
0436     Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
0437     if (ACPI_FAILURE (Status))
0438     {
0439         return_VOID;
0440     }
0441 
0442     /* Normalize the ID to zero */
0443 
0444     OwnerId--;
0445 
0446     /* Decode ID to index/offset pair */
0447 
0448     Index = ACPI_DIV_32 (OwnerId);
0449     Bit = 1 << ACPI_MOD_32 (OwnerId);
0450 
0451     /* Free the owner ID only if it is valid */
0452 
0453     if (AcpiGbl_OwnerIdMask[Index] & Bit)
0454     {
0455         AcpiGbl_OwnerIdMask[Index] ^= Bit;
0456     }
0457     else
0458     {
0459         ACPI_ERROR ((AE_INFO,
0460             "Release of non-allocated OwnerId: %2.2X", OwnerId + 1));
0461     }
0462 
0463     (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
0464     return_VOID;
0465 }
0466 
0467 
0468 /*******************************************************************************
0469  *
0470  * FUNCTION:    AcpiUtStrupr (strupr)
0471  *
0472  * PARAMETERS:  SrcString       - The source string to convert
0473  *
0474  * RETURN:      None
0475  *
0476  * DESCRIPTION: Convert string to uppercase
0477  *
0478  * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
0479  *
0480  ******************************************************************************/
0481 
0482 void
0483 AcpiUtStrupr (
0484     char                    *SrcString)
0485 {
0486     char                    *String;
0487 
0488 
0489     ACPI_FUNCTION_ENTRY ();
0490 
0491 
0492     if (!SrcString)
0493     {
0494         return;
0495     }
0496 
0497     /* Walk entire string, uppercasing the letters */
0498 
0499     for (String = SrcString; *String; String++)
0500     {
0501         *String = (char) ACPI_TOUPPER (*String);
0502     }
0503 
0504     return;
0505 }
0506 
0507 
0508 /*******************************************************************************
0509  *
0510  * FUNCTION:    AcpiUtPrintString
0511  *
0512  * PARAMETERS:  String          - Null terminated ASCII string
0513  *              MaxLength       - Maximum output length
0514  *
0515  * RETURN:      None
0516  *
0517  * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
0518  *              sequences.
0519  *
0520  ******************************************************************************/
0521 
0522 void
0523 AcpiUtPrintString (
0524     char                    *String,
0525     UINT8                   MaxLength)
0526 {
0527     UINT32                  i;
0528 
0529 
0530     if (!String)
0531     {
0532         AcpiOsPrintf ("<\"NULL STRING PTR\">");
0533         return;
0534     }
0535 
0536     AcpiOsPrintf ("\"");
0537     for (i = 0; String[i] && (i < MaxLength); i++)
0538     {
0539         /* Escape sequences */
0540 
0541         switch (String[i])
0542         {
0543         case 0x07:
0544             AcpiOsPrintf ("\\a");       /* BELL */
0545             break;
0546 
0547         case 0x08:
0548             AcpiOsPrintf ("\\b");       /* BACKSPACE */
0549             break;
0550 
0551         case 0x0C:
0552             AcpiOsPrintf ("\\f");       /* FORMFEED */
0553             break;
0554 
0555         case 0x0A:
0556             AcpiOsPrintf ("\\n");       /* LINEFEED */
0557             break;
0558 
0559         case 0x0D:
0560             AcpiOsPrintf ("\\r");       /* CARRIAGE RETURN*/
0561             break;
0562 
0563         case 0x09:
0564             AcpiOsPrintf ("\\t");       /* HORIZONTAL TAB */
0565             break;
0566 
0567         case 0x0B:
0568             AcpiOsPrintf ("\\v");       /* VERTICAL TAB */
0569             break;
0570 
0571         case '\'':                      /* Single Quote */
0572         case '\"':                      /* Double Quote */
0573         case '\\':                      /* Backslash */
0574             AcpiOsPrintf ("\\%c", (int) String[i]);
0575             break;
0576 
0577         default:
0578 
0579             /* Check for printable character or hex escape */
0580 
0581             if (ACPI_IS_PRINT (String[i]))
0582             {
0583                 /* This is a normal character */
0584 
0585                 AcpiOsPrintf ("%c", (int) String[i]);
0586             }
0587             else
0588             {
0589                 /* All others will be Hex escapes */
0590 
0591                 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
0592             }
0593             break;
0594         }
0595     }
0596     AcpiOsPrintf ("\"");
0597 
0598     if (i == MaxLength && String[i])
0599     {
0600         AcpiOsPrintf ("...");
0601     }
0602 }
0603 
0604 
0605 /*******************************************************************************
0606  *
0607  * FUNCTION:    AcpiUtDwordByteSwap
0608  *
0609  * PARAMETERS:  Value           - Value to be converted
0610  *
0611  * RETURN:      UINT32 integer with bytes swapped
0612  *
0613  * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
0614  *
0615  ******************************************************************************/
0616 
0617 UINT32
0618 AcpiUtDwordByteSwap (
0619     UINT32                  Value)
0620 {
0621     union
0622     {
0623         UINT32              Value;
0624         UINT8               Bytes[4];
0625     } Out;
0626     union
0627     {
0628         UINT32              Value;
0629         UINT8               Bytes[4];
0630     } In;
0631 
0632 
0633     ACPI_FUNCTION_ENTRY ();
0634 
0635 
0636     In.Value = Value;
0637 
0638     Out.Bytes[0] = In.Bytes[3];
0639     Out.Bytes[1] = In.Bytes[2];
0640     Out.Bytes[2] = In.Bytes[1];
0641     Out.Bytes[3] = In.Bytes[0];
0642 
0643     return (Out.Value);
0644 }
0645 
0646 
0647 /*******************************************************************************
0648  *
0649  * FUNCTION:    AcpiUtSetIntegerWidth
0650  *
0651  * PARAMETERS:  Revision            From DSDT header
0652  *
0653  * RETURN:      None
0654  *
0655  * DESCRIPTION: Set the global integer bit width based upon the revision
0656  *              of the DSDT.  For Revision 1 and 0, Integers are 32 bits.
0657  *              For Revision 2 and above, Integers are 64 bits.  Yes, this
0658  *              makes a difference.
0659  *
0660  ******************************************************************************/
0661 
0662 void
0663 AcpiUtSetIntegerWidth (
0664     UINT8                   Revision)
0665 {
0666 
0667     if (Revision < 2)
0668     {
0669         /* 32-bit case */
0670 
0671         AcpiGbl_IntegerBitWidth    = 32;
0672         AcpiGbl_IntegerNybbleWidth = 8;
0673         AcpiGbl_IntegerByteWidth   = 4;
0674     }
0675     else
0676     {
0677         /* 64-bit case (ACPI 2.0+) */
0678 
0679         AcpiGbl_IntegerBitWidth    = 64;
0680         AcpiGbl_IntegerNybbleWidth = 16;
0681         AcpiGbl_IntegerByteWidth   = 8;
0682     }
0683 }
0684 
0685 
0686 #ifdef ACPI_DEBUG_OUTPUT
0687 /*******************************************************************************
0688  *
0689  * FUNCTION:    AcpiUtDisplayInitPathname
0690  *
0691  * PARAMETERS:  Type                - Object type of the node
0692  *              ObjHandle           - Handle whose pathname will be displayed
0693  *              Path                - Additional path string to be appended.
0694  *                                      (NULL if no extra path)
0695  *
0696  * RETURN:      ACPI_STATUS
0697  *
0698  * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
0699  *
0700  ******************************************************************************/
0701 
0702 void
0703 AcpiUtDisplayInitPathname (
0704     UINT8                   Type,
0705     ACPI_NAMESPACE_NODE     *ObjHandle,
0706     char                    *Path)
0707 {
0708     ACPI_STATUS             Status;
0709     ACPI_BUFFER             Buffer;
0710 
0711 
0712     ACPI_FUNCTION_ENTRY ();
0713 
0714 
0715     /* Only print the path if the appropriate debug level is enabled */
0716 
0717     if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
0718     {
0719         return;
0720     }
0721 
0722     /* Get the full pathname to the node */
0723 
0724     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
0725     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
0726     if (ACPI_FAILURE (Status))
0727     {
0728         return;
0729     }
0730 
0731     /* Print what we're doing */
0732 
0733     switch (Type)
0734     {
0735     case ACPI_TYPE_METHOD:
0736         AcpiOsPrintf ("Executing    ");
0737         break;
0738 
0739     default:
0740         AcpiOsPrintf ("Initializing ");
0741         break;
0742     }
0743 
0744     /* Print the object type and pathname */
0745 
0746     AcpiOsPrintf ("%-12s  %s",
0747         AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
0748 
0749     /* Extra path is used to append names like _STA, _INI, etc. */
0750 
0751     if (Path)
0752     {
0753         AcpiOsPrintf (".%s", Path);
0754     }
0755     AcpiOsPrintf ("\n");
0756 
0757     ACPI_FREE (Buffer.Pointer);
0758 }
0759 #endif
0760 
0761 
0762 /*******************************************************************************
0763  *
0764  * FUNCTION:    AcpiUtValidAcpiChar
0765  *
0766  * PARAMETERS:  Char            - The character to be examined
0767  *              Position        - Byte position (0-3)
0768  *
0769  * RETURN:      TRUE if the character is valid, FALSE otherwise
0770  *
0771  * DESCRIPTION: Check for a valid ACPI character. Must be one of:
0772  *              1) Upper case alpha
0773  *              2) numeric
0774  *              3) underscore
0775  *
0776  *              We allow a '!' as the last character because of the ASF! table
0777  *
0778  ******************************************************************************/
0779 
0780 BOOLEAN
0781 AcpiUtValidAcpiChar (
0782     char                    Character,
0783     UINT32                  Position)
0784 {
0785 
0786     if (!((Character >= 'A' && Character <= 'Z') ||
0787           (Character >= '0' && Character <= '9') ||
0788           (Character == '_')))
0789     {
0790         /* Allow a '!' in the last position */
0791 
0792         if (Character == '!' && Position == 3)
0793         {
0794             return (TRUE);
0795         }
0796 
0797         return (FALSE);
0798     }
0799 
0800     return (TRUE);
0801 }
0802 
0803 
0804 /*******************************************************************************
0805  *
0806  * FUNCTION:    AcpiUtValidAcpiName
0807  *
0808  * PARAMETERS:  Name            - The name to be examined
0809  *
0810  * RETURN:      TRUE if the name is valid, FALSE otherwise
0811  *
0812  * DESCRIPTION: Check for a valid ACPI name.  Each character must be one of:
0813  *              1) Upper case alpha
0814  *              2) numeric
0815  *              3) underscore
0816  *
0817  ******************************************************************************/
0818 
0819 BOOLEAN
0820 AcpiUtValidAcpiName (
0821     UINT32                  Name)
0822 {
0823     UINT32                  i;
0824 
0825 
0826     ACPI_FUNCTION_ENTRY ();
0827 
0828 
0829     for (i = 0; i < ACPI_NAME_SIZE; i++)
0830     {
0831         if (!AcpiUtValidAcpiChar ((ACPI_CAST_PTR (char, &Name))[i], i))
0832         {
0833             return (FALSE);
0834         }
0835     }
0836 
0837     return (TRUE);
0838 }
0839 
0840 
0841 /*******************************************************************************
0842  *
0843  * FUNCTION:    AcpiUtRepairName
0844  *
0845  * PARAMETERS:  Name            - The ACPI name to be repaired
0846  *
0847  * RETURN:      Repaired version of the name
0848  *
0849  * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
0850  *              return the new name. NOTE: the Name parameter must reside in
0851  *              read/write memory, cannot be a const.
0852  *
0853  * An ACPI Name must consist of valid ACPI characters. We will repair the name
0854  * if necessary because we don't want to abort because of this, but we want
0855  * all namespace names to be printable. A warning message is appropriate.
0856  *
0857  * This issue came up because there are in fact machines that exhibit
0858  * this problem, and we want to be able to enable ACPI support for them,
0859  * even though there are a few bad names.
0860  *
0861  ******************************************************************************/
0862 
0863 void
0864 AcpiUtRepairName (
0865     char                    *Name)
0866 {
0867     UINT32                  i;
0868     BOOLEAN                 FoundBadChar = FALSE;
0869 
0870 
0871     ACPI_FUNCTION_NAME (UtRepairName);
0872 
0873 
0874     /* Check each character in the name */
0875 
0876     for (i = 0; i < ACPI_NAME_SIZE; i++)
0877     {
0878         if (AcpiUtValidAcpiChar (Name[i], i))
0879         {
0880             continue;
0881         }
0882 
0883         /*
0884          * Replace a bad character with something printable, yet technically
0885          * still invalid. This prevents any collisions with existing "good"
0886          * names in the namespace.
0887          */
0888         Name[i] = '*';
0889         FoundBadChar = TRUE;
0890     }
0891 
0892     if (FoundBadChar)
0893     {
0894         /* Report warning only if in strict mode or debug mode */
0895 
0896         if (!AcpiGbl_EnableInterpreterSlack)
0897         {
0898             ACPI_WARNING ((AE_INFO,
0899                 "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
0900         }
0901         else
0902         {
0903             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0904                 "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
0905         }
0906     }
0907 }
0908 
0909 
0910 /*******************************************************************************
0911  *
0912  * FUNCTION:    AcpiUtStrtoul64
0913  *
0914  * PARAMETERS:  String          - Null terminated string
0915  *              Base            - Radix of the string: 16 or ACPI_ANY_BASE;
0916  *                                ACPI_ANY_BASE means 'in behalf of ToInteger'
0917  *              RetInteger      - Where the converted integer is returned
0918  *
0919  * RETURN:      Status and Converted value
0920  *
0921  * DESCRIPTION: Convert a string into an unsigned value. Performs either a
0922  *              32-bit or 64-bit conversion, depending on the current mode
0923  *              of the interpreter.
0924  *              NOTE: Does not support Octal strings, not needed.
0925  *
0926  ******************************************************************************/
0927 
0928 ACPI_STATUS
0929 AcpiUtStrtoul64 (
0930     char                    *String,
0931     UINT32                  Base,
0932     ACPI_INTEGER            *RetInteger)
0933 {
0934     UINT32                  ThisDigit = 0;
0935     ACPI_INTEGER            ReturnValue = 0;
0936     ACPI_INTEGER            Quotient;
0937     ACPI_INTEGER            Dividend;
0938     UINT32                  ToIntegerOp = (Base == ACPI_ANY_BASE);
0939     UINT32                  Mode32 = (AcpiGbl_IntegerByteWidth == 4);
0940     UINT8                   ValidDigits = 0;
0941     UINT8                   SignOf0x = 0;
0942     UINT8                   Term = 0;
0943 
0944 
0945     ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
0946 
0947 
0948     switch (Base)
0949     {
0950     case ACPI_ANY_BASE:
0951     case 16:
0952         break;
0953 
0954     default:
0955         /* Invalid Base */
0956         return_ACPI_STATUS (AE_BAD_PARAMETER);
0957     }
0958 
0959     if (!String)
0960     {
0961         goto ErrorExit;
0962     }
0963 
0964     /* Skip over any white space in the buffer */
0965 
0966     while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
0967     {
0968         String++;
0969     }
0970 
0971     if (ToIntegerOp)
0972     {
0973         /*
0974          * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
0975          * We need to determine if it is decimal or hexadecimal.
0976          */
0977         if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
0978         {
0979             SignOf0x = 1;
0980             Base = 16;
0981 
0982             /* Skip over the leading '0x' */
0983             String += 2;
0984         }
0985         else
0986         {
0987             Base = 10;
0988         }
0989     }
0990 
0991     /* Any string left? Check that '0x' is not followed by white space. */
0992 
0993     if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
0994     {
0995         if (ToIntegerOp)
0996         {
0997             goto ErrorExit;
0998         }
0999         else
1000         {
1001             goto AllDone;
1002         }
1003     }
1004 
1005     /*
1006      * Perform a 32-bit or 64-bit conversion, depending upon the current
1007      * execution mode of the interpreter
1008      */
1009     Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
1010 
1011     /* Main loop: convert the string to a 32- or 64-bit integer */
1012 
1013     while (*String)
1014     {
1015         if (ACPI_IS_DIGIT (*String))
1016         {
1017             /* Convert ASCII 0-9 to Decimal value */
1018 
1019             ThisDigit = ((UINT8) *String) - '0';
1020         }
1021         else if (Base == 10)
1022         {
1023             /* Digit is out of range; possible in ToInteger case only */
1024 
1025             Term = 1;
1026         }
1027         else
1028         {
1029             ThisDigit = (UINT8) ACPI_TOUPPER (*String);
1030             if (ACPI_IS_XDIGIT ((char) ThisDigit))
1031             {
1032                 /* Convert ASCII Hex char to value */
1033 
1034                 ThisDigit = ThisDigit - 'A' + 10;
1035             }
1036             else
1037             {
1038                 Term = 1;
1039             }
1040         }
1041 
1042         if (Term)
1043         {
1044             if (ToIntegerOp)
1045             {
1046                 goto ErrorExit;
1047             }
1048             else
1049             {
1050                 break;
1051             }
1052         }
1053         else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
1054         {
1055             /* Skip zeros */
1056             String++;
1057             continue;
1058         }
1059 
1060         ValidDigits++;
1061 
1062         if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
1063         {
1064             /*
1065              * This is ToInteger operation case.
1066              * No any restrictions for string-to-integer conversion,
1067              * see ACPI spec.
1068              */
1069             goto ErrorExit;
1070         }
1071 
1072         /* Divide the digit into the correct position */
1073 
1074         (void) AcpiUtShortDivide ((Dividend - (ACPI_INTEGER) ThisDigit),
1075                     Base, &Quotient, NULL);
1076 
1077         if (ReturnValue > Quotient)
1078         {
1079             if (ToIntegerOp)
1080             {
1081                 goto ErrorExit;
1082             }
1083             else
1084             {
1085                 break;
1086             }
1087         }
1088 
1089         ReturnValue *= Base;
1090         ReturnValue += ThisDigit;
1091         String++;
1092     }
1093 
1094     /* All done, normal exit */
1095 
1096 AllDone:
1097 
1098     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
1099         ACPI_FORMAT_UINT64 (ReturnValue)));
1100 
1101     *RetInteger = ReturnValue;
1102     return_ACPI_STATUS (AE_OK);
1103 
1104 
1105 ErrorExit:
1106     /* Base was set/validated above */
1107 
1108     if (Base == 10)
1109     {
1110         return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
1111     }
1112     else
1113     {
1114         return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
1115     }
1116 }
1117 
1118 
1119 /*******************************************************************************
1120  *
1121  * FUNCTION:    AcpiUtCreateUpdateStateAndPush
1122  *
1123  * PARAMETERS:  Object          - Object to be added to the new state
1124  *              Action          - Increment/Decrement
1125  *              StateList       - List the state will be added to
1126  *
1127  * RETURN:      Status
1128  *
1129  * DESCRIPTION: Create a new state and push it
1130  *
1131  ******************************************************************************/
1132 
1133 ACPI_STATUS
1134 AcpiUtCreateUpdateStateAndPush (
1135     ACPI_OPERAND_OBJECT     *Object,
1136     UINT16                  Action,
1137     ACPI_GENERIC_STATE      **StateList)
1138 {
1139     ACPI_GENERIC_STATE       *State;
1140 
1141 
1142     ACPI_FUNCTION_ENTRY ();
1143 
1144 
1145     /* Ignore null objects; these are expected */
1146 
1147     if (!Object)
1148     {
1149         return (AE_OK);
1150     }
1151 
1152     State = AcpiUtCreateUpdateState (Object, Action);
1153     if (!State)
1154     {
1155         return (AE_NO_MEMORY);
1156     }
1157 
1158     AcpiUtPushGenericState (StateList, State);
1159     return (AE_OK);
1160 }
1161 
1162 
1163 /*******************************************************************************
1164  *
1165  * FUNCTION:    AcpiUtWalkPackageTree
1166  *
1167  * PARAMETERS:  SourceObject        - The package to walk
1168  *              TargetObject        - Target object (if package is being copied)
1169  *              WalkCallback        - Called once for each package element
1170  *              Context             - Passed to the callback function
1171  *
1172  * RETURN:      Status
1173  *
1174  * DESCRIPTION: Walk through a package
1175  *
1176  ******************************************************************************/
1177 
1178 ACPI_STATUS
1179 AcpiUtWalkPackageTree (
1180     ACPI_OPERAND_OBJECT     *SourceObject,
1181     void                    *TargetObject,
1182     ACPI_PKG_CALLBACK       WalkCallback,
1183     void                    *Context)
1184 {
1185     ACPI_STATUS             Status = AE_OK;
1186     ACPI_GENERIC_STATE      *StateList = NULL;
1187     ACPI_GENERIC_STATE      *State;
1188     UINT32                  ThisIndex;
1189     ACPI_OPERAND_OBJECT     *ThisSourceObj;
1190 
1191 
1192     ACPI_FUNCTION_TRACE (UtWalkPackageTree);
1193 
1194 
1195     State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1196     if (!State)
1197     {
1198         return_ACPI_STATUS (AE_NO_MEMORY);
1199     }
1200 
1201     while (State)
1202     {
1203         /* Get one element of the package */
1204 
1205         ThisIndex     = State->Pkg.Index;
1206         ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1207                         State->Pkg.SourceObject->Package.Elements[ThisIndex];
1208 
1209         /*
1210          * Check for:
1211          * 1) An uninitialized package element.  It is completely
1212          *    legal to declare a package and leave it uninitialized
1213          * 2) Not an internal object - can be a namespace node instead
1214          * 3) Any type other than a package.  Packages are handled in else
1215          *    case below.
1216          */
1217         if ((!ThisSourceObj) ||
1218             (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1219             (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
1220         {
1221             Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1222                                     State, Context);
1223             if (ACPI_FAILURE (Status))
1224             {
1225                 return_ACPI_STATUS (Status);
1226             }
1227 
1228             State->Pkg.Index++;
1229             while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1230             {
1231                 /*
1232                  * We've handled all of the objects at this level,  This means
1233                  * that we have just completed a package.  That package may
1234                  * have contained one or more packages itself.
1235                  *
1236                  * Delete this state and pop the previous state (package).
1237                  */
1238                 AcpiUtDeleteGenericState (State);
1239                 State = AcpiUtPopGenericState (&StateList);
1240 
1241                 /* Finished when there are no more states */
1242 
1243                 if (!State)
1244                 {
1245                     /*
1246                      * We have handled all of the objects in the top level
1247                      * package just add the length of the package objects
1248                      * and exit
1249                      */
1250                     return_ACPI_STATUS (AE_OK);
1251                 }
1252 
1253                 /*
1254                  * Go back up a level and move the index past the just
1255                  * completed package object.
1256                  */
1257                 State->Pkg.Index++;
1258             }
1259         }
1260         else
1261         {
1262             /* This is a subobject of type package */
1263 
1264             Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1265                                         State, Context);
1266             if (ACPI_FAILURE (Status))
1267             {
1268                 return_ACPI_STATUS (Status);
1269             }
1270 
1271             /*
1272              * Push the current state and create a new one
1273              * The callback above returned a new target package object.
1274              */
1275             AcpiUtPushGenericState (&StateList, State);
1276             State = AcpiUtCreatePkgState (ThisSourceObj,
1277                                             State->Pkg.ThisTargetObj, 0);
1278             if (!State)
1279             {
1280                 /* Free any stacked Update State objects */
1281 
1282                 while (StateList)
1283                 {
1284                     State = AcpiUtPopGenericState (&StateList);
1285                     AcpiUtDeleteGenericState (State);
1286                 }
1287                 return_ACPI_STATUS (AE_NO_MEMORY);
1288             }
1289         }
1290     }
1291 
1292     /* We should never get here */
1293 
1294     return_ACPI_STATUS (AE_AML_INTERNAL);
1295 }
1296 
1297 
1298 /*******************************************************************************
1299  *
1300  * FUNCTION:    AcpiError, AcpiException, AcpiWarning, AcpiInfo
1301  *
1302  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
1303  *              LineNumber          - Caller's line number (for error output)
1304  *              Format              - Printf format string + additional args
1305  *
1306  * RETURN:      None
1307  *
1308  * DESCRIPTION: Print message with module/line/version info
1309  *
1310  ******************************************************************************/
1311 
1312 void  ACPI_INTERNAL_VAR_XFACE
1313 AcpiError (
1314     const char              *ModuleName,
1315     UINT32                  LineNumber,
1316     const char              *Format,
1317     ...)
1318 {
1319     va_list                 args;
1320 
1321 
1322     AcpiOsPrintf ("ACPI Error: ");
1323 
1324     va_start (args, Format);
1325     AcpiOsVprintf (Format, args);
1326     ACPI_COMMON_MSG_SUFFIX;
1327     va_end (args);
1328 }
1329 
1330 void  ACPI_INTERNAL_VAR_XFACE
1331 AcpiException (
1332     const char              *ModuleName,
1333     UINT32                  LineNumber,
1334     ACPI_STATUS             Status,
1335     const char              *Format,
1336     ...)
1337 {
1338     va_list                 args;
1339 
1340 
1341     AcpiOsPrintf ("ACPI Exception: %s, ", AcpiFormatException (Status));
1342 
1343     va_start (args, Format);
1344     AcpiOsVprintf (Format, args);
1345     ACPI_COMMON_MSG_SUFFIX;
1346     va_end (args);
1347 }
1348 
1349 void  ACPI_INTERNAL_VAR_XFACE
1350 AcpiWarning (
1351     const char              *ModuleName,
1352     UINT32                  LineNumber,
1353     const char              *Format,
1354     ...)
1355 {
1356     va_list                 args;
1357 
1358 
1359     AcpiOsPrintf ("ACPI Warning: ");
1360 
1361     va_start (args, Format);
1362     AcpiOsVprintf (Format, args);
1363     ACPI_COMMON_MSG_SUFFIX;
1364     va_end (args);
1365 }
1366 
1367 void  ACPI_INTERNAL_VAR_XFACE
1368 AcpiInfo (
1369     const char              *ModuleName,
1370     UINT32                  LineNumber,
1371     const char              *Format,
1372     ...)
1373 {
1374     va_list                 args;
1375 
1376 
1377     AcpiOsPrintf ("ACPI: ");
1378 
1379     va_start (args, Format);
1380     AcpiOsVprintf (Format, args);
1381     AcpiOsPrintf ("\n");
1382     va_end (args);
1383 }
1384 
1385 ACPI_EXPORT_SYMBOL (AcpiError)
1386 ACPI_EXPORT_SYMBOL (AcpiException)
1387 ACPI_EXPORT_SYMBOL (AcpiWarning)
1388 ACPI_EXPORT_SYMBOL (AcpiInfo)
1389 
1390 
1391 /*******************************************************************************
1392  *
1393  * FUNCTION:    AcpiUtPredefinedWarning
1394  *
1395  * PARAMETERS:  ModuleName      - Caller's module name (for error output)
1396  *              LineNumber      - Caller's line number (for error output)
1397  *              Pathname        - Full pathname to the node
1398  *              NodeFlags       - From Namespace node for the method/object
1399  *              Format          - Printf format string + additional args
1400  *
1401  * RETURN:      None
1402  *
1403  * DESCRIPTION: Warnings for the predefined validation module. Messages are
1404  *              only emitted the first time a problem with a particular
1405  *              method/object is detected. This prevents a flood of error
1406  *              messages for methods that are repeatedly evaluated.
1407  *
1408  ******************************************************************************/
1409 
1410 void  ACPI_INTERNAL_VAR_XFACE
1411 AcpiUtPredefinedWarning (
1412     const char              *ModuleName,
1413     UINT32                  LineNumber,
1414     char                    *Pathname,
1415     UINT8                   NodeFlags,
1416     const char              *Format,
1417     ...)
1418 {
1419     va_list                 args;
1420 
1421 
1422     /*
1423      * Warning messages for this method/object will be disabled after the
1424      * first time a validation fails or an object is successfully repaired.
1425      */
1426     if (NodeFlags & ANOBJ_EVALUATED)
1427     {
1428         return;
1429     }
1430 
1431     AcpiOsPrintf ("ACPI Warning for %s: ", Pathname);
1432 
1433     va_start (args, Format);
1434     AcpiOsVprintf (Format, args);
1435     ACPI_COMMON_MSG_SUFFIX;
1436     va_end (args);
1437 }