1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acnamesp.h>
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("utmisc")
128 /*******************************************************************************
130 * FUNCTION: AcpiUtValidateException
132 * PARAMETERS: Status - The ACPI_STATUS code to be formatted
134 * RETURN: A string containing the exception text. NULL if exception is
137 * DESCRIPTION: This function validates and translates an ACPI exception into
140 ******************************************************************************/
143 AcpiUtValidateException (
147 const char *Exception = NULL;
150 ACPI_FUNCTION_ENTRY ();
154 * Status is composed of two parts, a "type" and an actual code
156 SubStatus = (Status & ~AE_CODE_MASK);
158 switch (Status & AE_CODE_MASK)
160 case AE_CODE_ENVIRONMENTAL:
162 if (SubStatus <= AE_CODE_ENV_MAX)
164 Exception = AcpiGbl_ExceptionNames_Env [SubStatus];
168 case AE_CODE_PROGRAMMER:
170 if (SubStatus <= AE_CODE_PGM_MAX)
172 Exception = AcpiGbl_ExceptionNames_Pgm [SubStatus];
176 case AE_CODE_ACPI_TABLES:
178 if (SubStatus <= AE_CODE_TBL_MAX)
180 Exception = AcpiGbl_ExceptionNames_Tbl [SubStatus];
186 if (SubStatus <= AE_CODE_AML_MAX)
188 Exception = AcpiGbl_ExceptionNames_Aml [SubStatus];
192 case AE_CODE_CONTROL:
194 if (SubStatus <= AE_CODE_CTRL_MAX)
196 Exception = AcpiGbl_ExceptionNames_Ctrl [SubStatus];
204 return (ACPI_CAST_PTR (const char, Exception));
208 /*******************************************************************************
210 * FUNCTION: AcpiUtIsPciRootBridge
212 * PARAMETERS: Id - The HID/CID in string format
214 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
216 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
218 ******************************************************************************/
221 AcpiUtIsPciRootBridge (
226 * Check if this is a PCI root bridge.
227 * ACPI 3.0+: check for a PCI Express root also.
229 if (!(ACPI_STRCMP (Id,
230 PCI_ROOT_HID_STRING)) ||
233 PCI_EXPRESS_ROOT_HID_STRING)))
242 /*******************************************************************************
244 * FUNCTION: AcpiUtIsAmlTable
246 * PARAMETERS: Table - An ACPI table
248 * RETURN: TRUE if table contains executable AML; FALSE otherwise
250 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
251 * Currently, these are DSDT,SSDT,PSDT. All other table types are
252 * data tables that do not contain AML code.
254 ******************************************************************************/
258 ACPI_TABLE_HEADER *Table)
261 /* These are the only tables that contain executable AML */
263 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) ||
264 ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_PSDT) ||
265 ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
274 /*******************************************************************************
276 * FUNCTION: AcpiUtAllocateOwnerId
278 * PARAMETERS: OwnerId - Where the new owner ID is returned
282 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
283 * track objects created by the table or method, to be deleted
284 * when the method exits or the table is unloaded.
286 ******************************************************************************/
289 AcpiUtAllocateOwnerId (
290 ACPI_OWNER_ID *OwnerId)
298 ACPI_FUNCTION_TRACE (UtAllocateOwnerId);
301 /* Guard against multiple allocations of ID to the same location */
305 ACPI_ERROR ((AE_INFO, "Owner ID [0x%2.2X] already exists", *OwnerId));
306 return_ACPI_STATUS (AE_ALREADY_EXISTS);
309 /* Mutex for the global ID mask */
311 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
312 if (ACPI_FAILURE (Status))
314 return_ACPI_STATUS (Status);
318 * Find a free owner ID, cycle through all possible IDs on repeated
319 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
320 * to be scanned twice.
322 for (i = 0, j = AcpiGbl_LastOwnerIdIndex;
323 i < (ACPI_NUM_OWNERID_MASKS + 1);
326 if (j >= ACPI_NUM_OWNERID_MASKS)
328 j = 0; /* Wraparound to start of mask array */
331 for (k = AcpiGbl_NextOwnerIdOffset; k < 32; k++)
333 if (AcpiGbl_OwnerIdMask[j] == ACPI_UINT32_MAX)
335 /* There are no free IDs in this mask */
340 if (!(AcpiGbl_OwnerIdMask[j] & (1 << k)))
343 * Found a free ID. The actual ID is the bit index plus one,
344 * making zero an invalid Owner ID. Save this as the last ID
345 * allocated and update the global ID mask.
347 AcpiGbl_OwnerIdMask[j] |= (1 << k);
349 AcpiGbl_LastOwnerIdIndex = (UINT8) j;
350 AcpiGbl_NextOwnerIdOffset = (UINT8) (k + 1);
353 * Construct encoded ID from the index and bit position
355 * Note: Last [j].k (bit 255) is never used and is marked
356 * permanently allocated (prevents +1 overflow)
358 *OwnerId = (ACPI_OWNER_ID) ((k + 1) + ACPI_MUL_32 (j));
360 ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
361 "Allocated OwnerId: %2.2X\n", (unsigned int) *OwnerId));
366 AcpiGbl_NextOwnerIdOffset = 0;
370 * All OwnerIds have been allocated. This typically should
371 * not happen since the IDs are reused after deallocation. The IDs are
372 * allocated upon table load (one per table) and method execution, and
373 * they are released when a table is unloaded or a method completes
376 * If this error happens, there may be very deep nesting of invoked control
377 * methods, or there may be a bug where the IDs are not released.
379 Status = AE_OWNER_ID_LIMIT;
380 ACPI_ERROR ((AE_INFO,
381 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
384 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
385 return_ACPI_STATUS (Status);
389 /*******************************************************************************
391 * FUNCTION: AcpiUtReleaseOwnerId
393 * PARAMETERS: OwnerIdPtr - Pointer to a previously allocated OwnerID
395 * RETURN: None. No error is returned because we are either exiting a
396 * control method or unloading a table. Either way, we would
397 * ignore any error anyway.
399 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
401 ******************************************************************************/
404 AcpiUtReleaseOwnerId (
405 ACPI_OWNER_ID *OwnerIdPtr)
407 ACPI_OWNER_ID OwnerId = *OwnerIdPtr;
413 ACPI_FUNCTION_TRACE_U32 (UtReleaseOwnerId, OwnerId);
416 /* Always clear the input OwnerId (zero is an invalid ID) */
420 /* Zero is not a valid OwnerID */
424 ACPI_ERROR ((AE_INFO, "Invalid OwnerId: 0x%2.2X", OwnerId));
428 /* Mutex for the global ID mask */
430 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
431 if (ACPI_FAILURE (Status))
436 /* Normalize the ID to zero */
440 /* Decode ID to index/offset pair */
442 Index = ACPI_DIV_32 (OwnerId);
443 Bit = 1 << ACPI_MOD_32 (OwnerId);
445 /* Free the owner ID only if it is valid */
447 if (AcpiGbl_OwnerIdMask[Index] & Bit)
449 AcpiGbl_OwnerIdMask[Index] ^= Bit;
453 ACPI_ERROR ((AE_INFO,
454 "Release of non-allocated OwnerId: 0x%2.2X", OwnerId + 1));
457 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
462 /*******************************************************************************
464 * FUNCTION: AcpiUtStrupr (strupr)
466 * PARAMETERS: SrcString - The source string to convert
470 * DESCRIPTION: Convert string to uppercase
472 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
474 ******************************************************************************/
483 ACPI_FUNCTION_ENTRY ();
491 /* Walk entire string, uppercasing the letters */
493 for (String = SrcString; *String; String++)
495 *String = (char) ACPI_TOUPPER (*String);
502 #ifdef ACPI_ASL_COMPILER
503 /*******************************************************************************
505 * FUNCTION: AcpiUtStrlwr (strlwr)
507 * PARAMETERS: SrcString - The source string to convert
511 * DESCRIPTION: Convert string to lowercase
513 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
515 ******************************************************************************/
524 ACPI_FUNCTION_ENTRY ();
532 /* Walk entire string, lowercasing the letters */
534 for (String = SrcString; *String; String++)
536 *String = (char) ACPI_TOLOWER (*String);
544 /*******************************************************************************
546 * FUNCTION: AcpiUtPrintString
548 * PARAMETERS: String - Null terminated ASCII string
549 * MaxLength - Maximum output length
553 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
556 ******************************************************************************/
568 AcpiOsPrintf ("<\"NULL STRING PTR\">");
573 for (i = 0; String[i] && (i < MaxLength); i++)
575 /* Escape sequences */
580 AcpiOsPrintf ("\\a"); /* BELL */
584 AcpiOsPrintf ("\\b"); /* BACKSPACE */
588 AcpiOsPrintf ("\\f"); /* FORMFEED */
592 AcpiOsPrintf ("\\n"); /* LINEFEED */
596 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
600 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
604 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
607 case '\'': /* Single Quote */
608 case '\"': /* Double Quote */
609 case '\\': /* Backslash */
610 AcpiOsPrintf ("\\%c", (int) String[i]);
615 /* Check for printable character or hex escape */
617 if (ACPI_IS_PRINT (String[i]))
619 /* This is a normal character */
621 AcpiOsPrintf ("%c", (int) String[i]);
625 /* All others will be Hex escapes */
627 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
634 if (i == MaxLength && String[i])
636 AcpiOsPrintf ("...");
641 /*******************************************************************************
643 * FUNCTION: AcpiUtDwordByteSwap
645 * PARAMETERS: Value - Value to be converted
647 * RETURN: UINT32 integer with bytes swapped
649 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
651 ******************************************************************************/
654 AcpiUtDwordByteSwap (
669 ACPI_FUNCTION_ENTRY ();
674 Out.Bytes[0] = In.Bytes[3];
675 Out.Bytes[1] = In.Bytes[2];
676 Out.Bytes[2] = In.Bytes[1];
677 Out.Bytes[3] = In.Bytes[0];
683 /*******************************************************************************
685 * FUNCTION: AcpiUtSetIntegerWidth
687 * PARAMETERS: Revision From DSDT header
691 * DESCRIPTION: Set the global integer bit width based upon the revision
692 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
693 * For Revision 2 and above, Integers are 64 bits. Yes, this
694 * makes a difference.
696 ******************************************************************************/
699 AcpiUtSetIntegerWidth (
707 AcpiGbl_IntegerBitWidth = 32;
708 AcpiGbl_IntegerNybbleWidth = 8;
709 AcpiGbl_IntegerByteWidth = 4;
713 /* 64-bit case (ACPI 2.0+) */
715 AcpiGbl_IntegerBitWidth = 64;
716 AcpiGbl_IntegerNybbleWidth = 16;
717 AcpiGbl_IntegerByteWidth = 8;
722 #ifdef ACPI_DEBUG_OUTPUT
723 /*******************************************************************************
725 * FUNCTION: AcpiUtDisplayInitPathname
727 * PARAMETERS: Type - Object type of the node
728 * ObjHandle - Handle whose pathname will be displayed
729 * Path - Additional path string to be appended.
730 * (NULL if no extra path)
732 * RETURN: ACPI_STATUS
734 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
736 ******************************************************************************/
739 AcpiUtDisplayInitPathname (
741 ACPI_NAMESPACE_NODE *ObjHandle,
748 ACPI_FUNCTION_ENTRY ();
751 /* Only print the path if the appropriate debug level is enabled */
753 if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
758 /* Get the full pathname to the node */
760 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
761 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
762 if (ACPI_FAILURE (Status))
767 /* Print what we're doing */
771 case ACPI_TYPE_METHOD:
772 AcpiOsPrintf ("Executing ");
776 AcpiOsPrintf ("Initializing ");
780 /* Print the object type and pathname */
782 AcpiOsPrintf ("%-12s %s",
783 AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
785 /* Extra path is used to append names like _STA, _INI, etc. */
789 AcpiOsPrintf (".%s", Path);
793 ACPI_FREE (Buffer.Pointer);
798 /*******************************************************************************
800 * FUNCTION: AcpiUtValidAcpiChar
802 * PARAMETERS: Char - The character to be examined
803 * Position - Byte position (0-3)
805 * RETURN: TRUE if the character is valid, FALSE otherwise
807 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
808 * 1) Upper case alpha
812 * We allow a '!' as the last character because of the ASF! table
814 ******************************************************************************/
817 AcpiUtValidAcpiChar (
822 if (!((Character >= 'A' && Character <= 'Z') ||
823 (Character >= '0' && Character <= '9') ||
826 /* Allow a '!' in the last position */
828 if (Character == '!' && Position == 3)
840 /*******************************************************************************
842 * FUNCTION: AcpiUtValidAcpiName
844 * PARAMETERS: Name - The name to be examined
846 * RETURN: TRUE if the name is valid, FALSE otherwise
848 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
849 * 1) Upper case alpha
853 ******************************************************************************/
856 AcpiUtValidAcpiName (
862 ACPI_FUNCTION_ENTRY ();
865 for (i = 0; i < ACPI_NAME_SIZE; i++)
867 if (!AcpiUtValidAcpiChar ((ACPI_CAST_PTR (char, &Name))[i], i))
877 /*******************************************************************************
879 * FUNCTION: AcpiUtRepairName
881 * PARAMETERS: Name - The ACPI name to be repaired
883 * RETURN: Repaired version of the name
885 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
886 * return the new name. NOTE: the Name parameter must reside in
887 * read/write memory, cannot be a const.
889 * An ACPI Name must consist of valid ACPI characters. We will repair the name
890 * if necessary because we don't want to abort because of this, but we want
891 * all namespace names to be printable. A warning message is appropriate.
893 * This issue came up because there are in fact machines that exhibit
894 * this problem, and we want to be able to enable ACPI support for them,
895 * even though there are a few bad names.
897 ******************************************************************************/
904 BOOLEAN FoundBadChar = FALSE;
907 ACPI_FUNCTION_NAME (UtRepairName);
910 /* Check each character in the name */
912 for (i = 0; i < ACPI_NAME_SIZE; i++)
914 if (AcpiUtValidAcpiChar (Name[i], i))
920 * Replace a bad character with something printable, yet technically
921 * still invalid. This prevents any collisions with existing "good"
922 * names in the namespace.
930 /* Report warning only if in strict mode or debug mode */
932 if (!AcpiGbl_EnableInterpreterSlack)
934 ACPI_WARNING ((AE_INFO,
935 "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
939 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
940 "Found bad character(s) in name, repaired: [%4.4s]\n", Name));
946 /*******************************************************************************
948 * FUNCTION: AcpiUtStrtoul64
950 * PARAMETERS: String - Null terminated string
951 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
952 * ACPI_ANY_BASE means 'in behalf of ToInteger'
953 * RetInteger - Where the converted integer is returned
955 * RETURN: Status and Converted value
957 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
958 * 32-bit or 64-bit conversion, depending on the current mode
959 * of the interpreter.
960 * NOTE: Does not support Octal strings, not needed.
962 ******************************************************************************/
970 UINT32 ThisDigit = 0;
971 UINT64 ReturnValue = 0;
974 UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
975 UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
976 UINT8 ValidDigits = 0;
981 ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
992 return_ACPI_STATUS (AE_BAD_PARAMETER);
1000 /* Skip over any white space in the buffer */
1002 while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
1010 * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
1011 * We need to determine if it is decimal or hexadecimal.
1013 if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
1018 /* Skip over the leading '0x' */
1027 /* Any string left? Check that '0x' is not followed by white space. */
1029 if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
1042 * Perform a 32-bit or 64-bit conversion, depending upon the current
1043 * execution mode of the interpreter
1045 Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
1047 /* Main loop: convert the string to a 32- or 64-bit integer */
1051 if (ACPI_IS_DIGIT (*String))
1053 /* Convert ASCII 0-9 to Decimal value */
1055 ThisDigit = ((UINT8) *String) - '0';
1057 else if (Base == 10)
1059 /* Digit is out of range; possible in ToInteger case only */
1065 ThisDigit = (UINT8) ACPI_TOUPPER (*String);
1066 if (ACPI_IS_XDIGIT ((char) ThisDigit))
1068 /* Convert ASCII Hex char to value */
1070 ThisDigit = ThisDigit - 'A' + 10;
1089 else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
1098 if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
1101 * This is ToInteger operation case.
1102 * No any restrictions for string-to-integer conversion,
1108 /* Divide the digit into the correct position */
1110 (void) AcpiUtShortDivide ((Dividend - (UINT64) ThisDigit),
1111 Base, &Quotient, NULL);
1113 if (ReturnValue > Quotient)
1125 ReturnValue *= Base;
1126 ReturnValue += ThisDigit;
1130 /* All done, normal exit */
1134 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
1135 ACPI_FORMAT_UINT64 (ReturnValue)));
1137 *RetInteger = ReturnValue;
1138 return_ACPI_STATUS (AE_OK);
1142 /* Base was set/validated above */
1146 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
1150 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
1155 /*******************************************************************************
1157 * FUNCTION: AcpiUtCreateUpdateStateAndPush
1159 * PARAMETERS: Object - Object to be added to the new state
1160 * Action - Increment/Decrement
1161 * StateList - List the state will be added to
1165 * DESCRIPTION: Create a new state and push it
1167 ******************************************************************************/
1170 AcpiUtCreateUpdateStateAndPush (
1171 ACPI_OPERAND_OBJECT *Object,
1173 ACPI_GENERIC_STATE **StateList)
1175 ACPI_GENERIC_STATE *State;
1178 ACPI_FUNCTION_ENTRY ();
1181 /* Ignore null objects; these are expected */
1188 State = AcpiUtCreateUpdateState (Object, Action);
1191 return (AE_NO_MEMORY);
1194 AcpiUtPushGenericState (StateList, State);
1199 /*******************************************************************************
1201 * FUNCTION: AcpiUtWalkPackageTree
1203 * PARAMETERS: SourceObject - The package to walk
1204 * TargetObject - Target object (if package is being copied)
1205 * WalkCallback - Called once for each package element
1206 * Context - Passed to the callback function
1210 * DESCRIPTION: Walk through a package
1212 ******************************************************************************/
1215 AcpiUtWalkPackageTree (
1216 ACPI_OPERAND_OBJECT *SourceObject,
1218 ACPI_PKG_CALLBACK WalkCallback,
1221 ACPI_STATUS Status = AE_OK;
1222 ACPI_GENERIC_STATE *StateList = NULL;
1223 ACPI_GENERIC_STATE *State;
1225 ACPI_OPERAND_OBJECT *ThisSourceObj;
1228 ACPI_FUNCTION_TRACE (UtWalkPackageTree);
1231 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1234 return_ACPI_STATUS (AE_NO_MEMORY);
1239 /* Get one element of the package */
1241 ThisIndex = State->Pkg.Index;
1242 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1243 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1247 * 1) An uninitialized package element. It is completely
1248 * legal to declare a package and leave it uninitialized
1249 * 2) Not an internal object - can be a namespace node instead
1250 * 3) Any type other than a package. Packages are handled in else
1253 if ((!ThisSourceObj) ||
1254 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1255 (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
1257 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1259 if (ACPI_FAILURE (Status))
1261 return_ACPI_STATUS (Status);
1265 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1268 * We've handled all of the objects at this level, This means
1269 * that we have just completed a package. That package may
1270 * have contained one or more packages itself.
1272 * Delete this state and pop the previous state (package).
1274 AcpiUtDeleteGenericState (State);
1275 State = AcpiUtPopGenericState (&StateList);
1277 /* Finished when there are no more states */
1282 * We have handled all of the objects in the top level
1283 * package just add the length of the package objects
1286 return_ACPI_STATUS (AE_OK);
1290 * Go back up a level and move the index past the just
1291 * completed package object.
1298 /* This is a subobject of type package */
1300 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1302 if (ACPI_FAILURE (Status))
1304 return_ACPI_STATUS (Status);
1308 * Push the current state and create a new one
1309 * The callback above returned a new target package object.
1311 AcpiUtPushGenericState (&StateList, State);
1312 State = AcpiUtCreatePkgState (ThisSourceObj,
1313 State->Pkg.ThisTargetObj, 0);
1316 /* Free any stacked Update State objects */
1320 State = AcpiUtPopGenericState (&StateList);
1321 AcpiUtDeleteGenericState (State);
1323 return_ACPI_STATUS (AE_NO_MEMORY);
1328 /* We should never get here */
1330 return_ACPI_STATUS (AE_AML_INTERNAL);