i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / utilities / utmisc.c
blob11e9d4f61535ad4545572379f2f040d5de2d4829
1 /*******************************************************************************
3 * Module Name: utmisc - common utility procedures
4 * $Revision: 1.150 $
6 ******************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __UTMISC_C__
120 #include "acpi.h"
121 #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
135 * not valid.
137 * DESCRIPTION: This function validates and translates an ACPI exception into
138 * an ASCII string.
140 ******************************************************************************/
142 const char *
143 AcpiUtValidateException (
144 ACPI_STATUS Status)
146 ACPI_STATUS SubStatus;
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];
166 break;
168 case AE_CODE_PROGRAMMER:
170 if (SubStatus <= AE_CODE_PGM_MAX)
172 Exception = AcpiGbl_ExceptionNames_Pgm [SubStatus -1];
174 break;
176 case AE_CODE_ACPI_TABLES:
178 if (SubStatus <= AE_CODE_TBL_MAX)
180 Exception = AcpiGbl_ExceptionNames_Tbl [SubStatus -1];
182 break;
184 case AE_CODE_AML:
186 if (SubStatus <= AE_CODE_AML_MAX)
188 Exception = AcpiGbl_ExceptionNames_Aml [SubStatus -1];
190 break;
192 case AE_CODE_CONTROL:
194 if (SubStatus <= AE_CODE_CTRL_MAX)
196 Exception = AcpiGbl_ExceptionNames_Ctrl [SubStatus -1];
198 break;
200 default:
201 break;
204 return (ACPI_CAST_PTR (const char, Exception));
208 /*******************************************************************************
210 * FUNCTION: AcpiUtIsAmlTable
212 * PARAMETERS: Table - An ACPI table
214 * RETURN: TRUE if table contains executable AML; FALSE otherwise
216 * DESCRIPTION: Check ACPI Signature for a table that contains AML code.
217 * Currently, these are DSDT,SSDT,PSDT. All other table types are
218 * data tables that do not contain AML code.
220 ******************************************************************************/
222 BOOLEAN
223 AcpiUtIsAmlTable (
224 ACPI_TABLE_HEADER *Table)
227 /* These are the only tables that contain executable AML */
229 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) ||
230 ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_PSDT) ||
231 ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
233 return (TRUE);
236 return (FALSE);
240 /*******************************************************************************
242 * FUNCTION: AcpiUtAllocateOwnerId
244 * PARAMETERS: OwnerId - Where the new owner ID is returned
246 * RETURN: Status
248 * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
249 * track objects created by the table or method, to be deleted
250 * when the method exits or the table is unloaded.
252 ******************************************************************************/
254 ACPI_STATUS
255 AcpiUtAllocateOwnerId (
256 ACPI_OWNER_ID *OwnerId)
258 ACPI_NATIVE_UINT i;
259 ACPI_NATIVE_UINT j;
260 ACPI_NATIVE_UINT k;
261 ACPI_STATUS Status;
264 ACPI_FUNCTION_TRACE (UtAllocateOwnerId);
267 /* Guard against multiple allocations of ID to the same location */
269 if (*OwnerId)
271 ACPI_ERROR ((AE_INFO, "Owner ID [%2.2X] already exists", *OwnerId));
272 return_ACPI_STATUS (AE_ALREADY_EXISTS);
275 /* Mutex for the global ID mask */
277 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
278 if (ACPI_FAILURE (Status))
280 return_ACPI_STATUS (Status);
284 * Find a free owner ID, cycle through all possible IDs on repeated
285 * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
286 * to be scanned twice.
288 for (i = 0, j = AcpiGbl_LastOwnerIdIndex;
289 i < (ACPI_NUM_OWNERID_MASKS + 1);
290 i++, j++)
292 if (j >= ACPI_NUM_OWNERID_MASKS)
294 j = 0; /* Wraparound to start of mask array */
297 for (k = AcpiGbl_NextOwnerIdOffset; k < 32; k++)
299 if (AcpiGbl_OwnerIdMask[j] == ACPI_UINT32_MAX)
301 /* There are no free IDs in this mask */
303 break;
306 if (!(AcpiGbl_OwnerIdMask[j] & (1 << k)))
309 * Found a free ID. The actual ID is the bit index plus one,
310 * making zero an invalid Owner ID. Save this as the last ID
311 * allocated and update the global ID mask.
313 AcpiGbl_OwnerIdMask[j] |= (1 << k);
315 AcpiGbl_LastOwnerIdIndex = (UINT8) j;
316 AcpiGbl_NextOwnerIdOffset = (UINT8) (k + 1);
319 * Construct encoded ID from the index and bit position
321 * Note: Last [j].k (bit 255) is never used and is marked
322 * permanently allocated (prevents +1 overflow)
324 *OwnerId = (ACPI_OWNER_ID) ((k + 1) + ACPI_MUL_32 (j));
326 ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
327 "Allocated OwnerId: %2.2X\n", (unsigned int) *OwnerId));
328 goto Exit;
332 AcpiGbl_NextOwnerIdOffset = 0;
336 * All OwnerIds have been allocated. This typically should
337 * not happen since the IDs are reused after deallocation. The IDs are
338 * allocated upon table load (one per table) and method execution, and
339 * they are released when a table is unloaded or a method completes
340 * execution.
342 * If this error happens, there may be very deep nesting of invoked control
343 * methods, or there may be a bug where the IDs are not released.
345 Status = AE_OWNER_ID_LIMIT;
346 ACPI_ERROR ((AE_INFO,
347 "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
349 Exit:
350 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
351 return_ACPI_STATUS (Status);
355 /*******************************************************************************
357 * FUNCTION: AcpiUtReleaseOwnerId
359 * PARAMETERS: OwnerIdPtr - Pointer to a previously allocated OwnerID
361 * RETURN: None. No error is returned because we are either exiting a
362 * control method or unloading a table. Either way, we would
363 * ignore any error anyway.
365 * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
367 ******************************************************************************/
369 void
370 AcpiUtReleaseOwnerId (
371 ACPI_OWNER_ID *OwnerIdPtr)
373 ACPI_OWNER_ID OwnerId = *OwnerIdPtr;
374 ACPI_STATUS Status;
375 ACPI_NATIVE_UINT Index;
376 UINT32 Bit;
379 ACPI_FUNCTION_TRACE_U32 (UtReleaseOwnerId, OwnerId);
382 /* Always clear the input OwnerId (zero is an invalid ID) */
384 *OwnerIdPtr = 0;
386 /* Zero is not a valid OwnerID */
388 if (OwnerId == 0)
390 ACPI_ERROR ((AE_INFO, "Invalid OwnerId: %2.2X", OwnerId));
391 return_VOID;
394 /* Mutex for the global ID mask */
396 Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
397 if (ACPI_FAILURE (Status))
399 return_VOID;
402 /* Normalize the ID to zero */
404 OwnerId--;
406 /* Decode ID to index/offset pair */
408 Index = ACPI_DIV_32 (OwnerId);
409 Bit = 1 << ACPI_MOD_32 (OwnerId);
411 /* Free the owner ID only if it is valid */
413 if (AcpiGbl_OwnerIdMask[Index] & Bit)
415 AcpiGbl_OwnerIdMask[Index] ^= Bit;
417 else
419 ACPI_ERROR ((AE_INFO,
420 "Release of non-allocated OwnerId: %2.2X", OwnerId + 1));
423 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
424 return_VOID;
428 /*******************************************************************************
430 * FUNCTION: AcpiUtStrupr (strupr)
432 * PARAMETERS: SrcString - The source string to convert
434 * RETURN: None
436 * DESCRIPTION: Convert string to uppercase
438 * NOTE: This is not a POSIX function, so it appears here, not in utclib.c
440 ******************************************************************************/
442 void
443 AcpiUtStrupr (
444 char *SrcString)
446 char *String;
449 ACPI_FUNCTION_ENTRY ();
452 if (!SrcString)
454 return;
457 /* Walk entire string, uppercasing the letters */
459 for (String = SrcString; *String; String++)
461 *String = (char) ACPI_TOUPPER (*String);
464 return;
468 /*******************************************************************************
470 * FUNCTION: AcpiUtPrintString
472 * PARAMETERS: String - Null terminated ASCII string
473 * MaxLength - Maximum output length
475 * RETURN: None
477 * DESCRIPTION: Dump an ASCII string with support for ACPI-defined escape
478 * sequences.
480 ******************************************************************************/
482 void
483 AcpiUtPrintString (
484 char *String,
485 UINT8 MaxLength)
487 UINT32 i;
490 if (!String)
492 AcpiOsPrintf ("<\"NULL STRING PTR\">");
493 return;
496 AcpiOsPrintf ("\"");
497 for (i = 0; String[i] && (i < MaxLength); i++)
499 /* Escape sequences */
501 switch (String[i])
503 case 0x07:
504 AcpiOsPrintf ("\\a"); /* BELL */
505 break;
507 case 0x08:
508 AcpiOsPrintf ("\\b"); /* BACKSPACE */
509 break;
511 case 0x0C:
512 AcpiOsPrintf ("\\f"); /* FORMFEED */
513 break;
515 case 0x0A:
516 AcpiOsPrintf ("\\n"); /* LINEFEED */
517 break;
519 case 0x0D:
520 AcpiOsPrintf ("\\r"); /* CARRIAGE RETURN*/
521 break;
523 case 0x09:
524 AcpiOsPrintf ("\\t"); /* HORIZONTAL TAB */
525 break;
527 case 0x0B:
528 AcpiOsPrintf ("\\v"); /* VERTICAL TAB */
529 break;
531 case '\'': /* Single Quote */
532 case '\"': /* Double Quote */
533 case '\\': /* Backslash */
534 AcpiOsPrintf ("\\%c", (int) String[i]);
535 break;
537 default:
539 /* Check for printable character or hex escape */
541 if (ACPI_IS_PRINT (String[i]))
543 /* This is a normal character */
545 AcpiOsPrintf ("%c", (int) String[i]);
547 else
549 /* All others will be Hex escapes */
551 AcpiOsPrintf ("\\x%2.2X", (INT32) String[i]);
553 break;
556 AcpiOsPrintf ("\"");
558 if (i == MaxLength && String[i])
560 AcpiOsPrintf ("...");
565 /*******************************************************************************
567 * FUNCTION: AcpiUtDwordByteSwap
569 * PARAMETERS: Value - Value to be converted
571 * RETURN: UINT32 integer with bytes swapped
573 * DESCRIPTION: Convert a 32-bit value to big-endian (swap the bytes)
575 ******************************************************************************/
577 UINT32
578 AcpiUtDwordByteSwap (
579 UINT32 Value)
581 union
583 UINT32 Value;
584 UINT8 Bytes[4];
585 } Out;
586 union
588 UINT32 Value;
589 UINT8 Bytes[4];
590 } In;
593 ACPI_FUNCTION_ENTRY ();
596 In.Value = Value;
598 Out.Bytes[0] = In.Bytes[3];
599 Out.Bytes[1] = In.Bytes[2];
600 Out.Bytes[2] = In.Bytes[1];
601 Out.Bytes[3] = In.Bytes[0];
603 return (Out.Value);
607 /*******************************************************************************
609 * FUNCTION: AcpiUtSetIntegerWidth
611 * PARAMETERS: Revision From DSDT header
613 * RETURN: None
615 * DESCRIPTION: Set the global integer bit width based upon the revision
616 * of the DSDT. For Revision 1 and 0, Integers are 32 bits.
617 * For Revision 2 and above, Integers are 64 bits. Yes, this
618 * makes a difference.
620 ******************************************************************************/
622 void
623 AcpiUtSetIntegerWidth (
624 UINT8 Revision)
627 if (Revision < 2)
629 /* 32-bit case */
631 AcpiGbl_IntegerBitWidth = 32;
632 AcpiGbl_IntegerNybbleWidth = 8;
633 AcpiGbl_IntegerByteWidth = 4;
635 else
637 /* 64-bit case (ACPI 2.0+) */
639 AcpiGbl_IntegerBitWidth = 64;
640 AcpiGbl_IntegerNybbleWidth = 16;
641 AcpiGbl_IntegerByteWidth = 8;
646 #ifdef ACPI_DEBUG_OUTPUT
647 /*******************************************************************************
649 * FUNCTION: AcpiUtDisplayInitPathname
651 * PARAMETERS: Type - Object type of the node
652 * ObjHandle - Handle whose pathname will be displayed
653 * Path - Additional path string to be appended.
654 * (NULL if no extra path)
656 * RETURN: ACPI_STATUS
658 * DESCRIPTION: Display full pathname of an object, DEBUG ONLY
660 ******************************************************************************/
662 void
663 AcpiUtDisplayInitPathname (
664 UINT8 Type,
665 ACPI_NAMESPACE_NODE *ObjHandle,
666 char *Path)
668 ACPI_STATUS Status;
669 ACPI_BUFFER Buffer;
672 ACPI_FUNCTION_ENTRY ();
675 /* Only print the path if the appropriate debug level is enabled */
677 if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
679 return;
682 /* Get the full pathname to the node */
684 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
685 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
686 if (ACPI_FAILURE (Status))
688 return;
691 /* Print what we're doing */
693 switch (Type)
695 case ACPI_TYPE_METHOD:
696 AcpiOsPrintf ("Executing ");
697 break;
699 default:
700 AcpiOsPrintf ("Initializing ");
701 break;
704 /* Print the object type and pathname */
706 AcpiOsPrintf ("%-12s %s",
707 AcpiUtGetTypeName (Type), (char *) Buffer.Pointer);
709 /* Extra path is used to append names like _STA, _INI, etc. */
711 if (Path)
713 AcpiOsPrintf (".%s", Path);
715 AcpiOsPrintf ("\n");
717 ACPI_FREE (Buffer.Pointer);
719 #endif
722 /*******************************************************************************
724 * FUNCTION: AcpiUtValidAcpiChar
726 * PARAMETERS: Char - The character to be examined
727 * Position - Byte position (0-3)
729 * RETURN: TRUE if the character is valid, FALSE otherwise
731 * DESCRIPTION: Check for a valid ACPI character. Must be one of:
732 * 1) Upper case alpha
733 * 2) numeric
734 * 3) underscore
736 * We allow a '!' as the last character because of the ASF! table
738 ******************************************************************************/
740 BOOLEAN
741 AcpiUtValidAcpiChar (
742 char Character,
743 ACPI_NATIVE_UINT Position)
746 if (!((Character >= 'A' && Character <= 'Z') ||
747 (Character >= '0' && Character <= '9') ||
748 (Character == '_')))
750 /* Allow a '!' in the last position */
752 if (Character == '!' && Position == 3)
754 return (TRUE);
757 return (FALSE);
760 return (TRUE);
764 /*******************************************************************************
766 * FUNCTION: AcpiUtValidAcpiName
768 * PARAMETERS: Name - The name to be examined
770 * RETURN: TRUE if the name is valid, FALSE otherwise
772 * DESCRIPTION: Check for a valid ACPI name. Each character must be one of:
773 * 1) Upper case alpha
774 * 2) numeric
775 * 3) underscore
777 ******************************************************************************/
779 BOOLEAN
780 AcpiUtValidAcpiName (
781 UINT32 Name)
783 ACPI_NATIVE_UINT i;
786 ACPI_FUNCTION_ENTRY ();
789 for (i = 0; i < ACPI_NAME_SIZE; i++)
791 if (!AcpiUtValidAcpiChar ((ACPI_CAST_PTR (char, &Name))[i], i))
793 return (FALSE);
797 return (TRUE);
801 /*******************************************************************************
803 * FUNCTION: AcpiUtRepairName
805 * PARAMETERS: Name - The ACPI name to be repaired
807 * RETURN: Repaired version of the name
809 * DESCRIPTION: Repair an ACPI name: Change invalid characters to '*' and
810 * return the new name.
812 ******************************************************************************/
814 ACPI_NAME
815 AcpiUtRepairName (
816 char *Name)
818 ACPI_NATIVE_UINT i;
819 char NewName[ACPI_NAME_SIZE];
822 for (i = 0; i < ACPI_NAME_SIZE; i++)
824 NewName[i] = Name[i];
827 * Replace a bad character with something printable, yet technically
828 * still invalid. This prevents any collisions with existing "good"
829 * names in the namespace.
831 if (!AcpiUtValidAcpiChar (Name[i], i))
833 NewName[i] = '*';
837 return (*(UINT32 *) NewName);
841 /*******************************************************************************
843 * FUNCTION: AcpiUtStrtoul64
845 * PARAMETERS: String - Null terminated string
846 * Base - Radix of the string: 16 or ACPI_ANY_BASE;
847 * ACPI_ANY_BASE means 'in behalf of ToInteger'
848 * RetInteger - Where the converted integer is returned
850 * RETURN: Status and Converted value
852 * DESCRIPTION: Convert a string into an unsigned value. Performs either a
853 * 32-bit or 64-bit conversion, depending on the current mode
854 * of the interpreter.
855 * NOTE: Does not support Octal strings, not needed.
857 ******************************************************************************/
859 ACPI_STATUS
860 AcpiUtStrtoul64 (
861 char *String,
862 UINT32 Base,
863 ACPI_INTEGER *RetInteger)
865 UINT32 ThisDigit = 0;
866 ACPI_INTEGER ReturnValue = 0;
867 ACPI_INTEGER Quotient;
868 ACPI_INTEGER Dividend;
869 UINT32 ToIntegerOp = (Base == ACPI_ANY_BASE);
870 UINT32 Mode32 = (AcpiGbl_IntegerByteWidth == 4);
871 UINT8 ValidDigits = 0;
872 UINT8 SignOf0x = 0;
873 UINT8 Term = 0;
876 ACPI_FUNCTION_TRACE_STR (UtStroul64, String);
879 switch (Base)
881 case ACPI_ANY_BASE:
882 case 16:
883 break;
885 default:
886 /* Invalid Base */
887 return_ACPI_STATUS (AE_BAD_PARAMETER);
890 if (!String)
892 goto ErrorExit;
895 /* Skip over any white space in the buffer */
897 while ((*String) && (ACPI_IS_SPACE (*String) || *String == '\t'))
899 String++;
902 if (ToIntegerOp)
905 * Base equal to ACPI_ANY_BASE means 'ToInteger operation case'.
906 * We need to determine if it is decimal or hexadecimal.
908 if ((*String == '0') && (ACPI_TOLOWER (*(String + 1)) == 'x'))
910 SignOf0x = 1;
911 Base = 16;
913 /* Skip over the leading '0x' */
914 String += 2;
916 else
918 Base = 10;
922 /* Any string left? Check that '0x' is not followed by white space. */
924 if (!(*String) || ACPI_IS_SPACE (*String) || *String == '\t')
926 if (ToIntegerOp)
928 goto ErrorExit;
930 else
932 goto AllDone;
937 * Perform a 32-bit or 64-bit conversion, depending upon the current
938 * execution mode of the interpreter
940 Dividend = (Mode32) ? ACPI_UINT32_MAX : ACPI_UINT64_MAX;
942 /* Main loop: convert the string to a 32- or 64-bit integer */
944 while (*String)
946 if (ACPI_IS_DIGIT (*String))
948 /* Convert ASCII 0-9 to Decimal value */
950 ThisDigit = ((UINT8) *String) - '0';
952 else if (Base == 10)
954 /* Digit is out of range; possible in ToInteger case only */
956 Term = 1;
958 else
960 ThisDigit = (UINT8) ACPI_TOUPPER (*String);
961 if (ACPI_IS_XDIGIT ((char) ThisDigit))
963 /* Convert ASCII Hex char to value */
965 ThisDigit = ThisDigit - 'A' + 10;
967 else
969 Term = 1;
973 if (Term)
975 if (ToIntegerOp)
977 goto ErrorExit;
979 else
981 break;
984 else if ((ValidDigits == 0) && (ThisDigit == 0) && !SignOf0x)
986 /* Skip zeros */
987 String++;
988 continue;
991 ValidDigits++;
993 if (SignOf0x && ((ValidDigits > 16) || ((ValidDigits > 8) && Mode32)))
996 * This is ToInteger operation case.
997 * No any restrictions for string-to-integer conversion,
998 * see ACPI spec.
1000 goto ErrorExit;
1003 /* Divide the digit into the correct position */
1005 (void) AcpiUtShortDivide ((Dividend - (ACPI_INTEGER) ThisDigit),
1006 Base, &Quotient, NULL);
1008 if (ReturnValue > Quotient)
1010 if (ToIntegerOp)
1012 goto ErrorExit;
1014 else
1016 break;
1020 ReturnValue *= Base;
1021 ReturnValue += ThisDigit;
1022 String++;
1025 /* All done, normal exit */
1027 AllDone:
1029 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
1030 ACPI_FORMAT_UINT64 (ReturnValue)));
1032 *RetInteger = ReturnValue;
1033 return_ACPI_STATUS (AE_OK);
1036 ErrorExit:
1037 /* Base was set/validated above */
1039 if (Base == 10)
1041 return_ACPI_STATUS (AE_BAD_DECIMAL_CONSTANT);
1043 else
1045 return_ACPI_STATUS (AE_BAD_HEX_CONSTANT);
1050 /*******************************************************************************
1052 * FUNCTION: AcpiUtCreateUpdateStateAndPush
1054 * PARAMETERS: Object - Object to be added to the new state
1055 * Action - Increment/Decrement
1056 * StateList - List the state will be added to
1058 * RETURN: Status
1060 * DESCRIPTION: Create a new state and push it
1062 ******************************************************************************/
1064 ACPI_STATUS
1065 AcpiUtCreateUpdateStateAndPush (
1066 ACPI_OPERAND_OBJECT *Object,
1067 UINT16 Action,
1068 ACPI_GENERIC_STATE **StateList)
1070 ACPI_GENERIC_STATE *State;
1073 ACPI_FUNCTION_ENTRY ();
1076 /* Ignore null objects; these are expected */
1078 if (!Object)
1080 return (AE_OK);
1083 State = AcpiUtCreateUpdateState (Object, Action);
1084 if (!State)
1086 return (AE_NO_MEMORY);
1089 AcpiUtPushGenericState (StateList, State);
1090 return (AE_OK);
1094 /*******************************************************************************
1096 * FUNCTION: AcpiUtWalkPackageTree
1098 * PARAMETERS: SourceObject - The package to walk
1099 * TargetObject - Target object (if package is being copied)
1100 * WalkCallback - Called once for each package element
1101 * Context - Passed to the callback function
1103 * RETURN: Status
1105 * DESCRIPTION: Walk through a package
1107 ******************************************************************************/
1109 ACPI_STATUS
1110 AcpiUtWalkPackageTree (
1111 ACPI_OPERAND_OBJECT *SourceObject,
1112 void *TargetObject,
1113 ACPI_PKG_CALLBACK WalkCallback,
1114 void *Context)
1116 ACPI_STATUS Status = AE_OK;
1117 ACPI_GENERIC_STATE *StateList = NULL;
1118 ACPI_GENERIC_STATE *State;
1119 UINT32 ThisIndex;
1120 ACPI_OPERAND_OBJECT *ThisSourceObj;
1123 ACPI_FUNCTION_TRACE (UtWalkPackageTree);
1126 State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
1127 if (!State)
1129 return_ACPI_STATUS (AE_NO_MEMORY);
1132 while (State)
1134 /* Get one element of the package */
1136 ThisIndex = State->Pkg.Index;
1137 ThisSourceObj = (ACPI_OPERAND_OBJECT *)
1138 State->Pkg.SourceObject->Package.Elements[ThisIndex];
1141 * Check for:
1142 * 1) An uninitialized package element. It is completely
1143 * legal to declare a package and leave it uninitialized
1144 * 2) Not an internal object - can be a namespace node instead
1145 * 3) Any type other than a package. Packages are handled in else
1146 * case below.
1148 if ((!ThisSourceObj) ||
1149 (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) != ACPI_DESC_TYPE_OPERAND) ||
1150 (ACPI_GET_OBJECT_TYPE (ThisSourceObj) != ACPI_TYPE_PACKAGE))
1152 Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
1153 State, Context);
1154 if (ACPI_FAILURE (Status))
1156 return_ACPI_STATUS (Status);
1159 State->Pkg.Index++;
1160 while (State->Pkg.Index >= State->Pkg.SourceObject->Package.Count)
1163 * We've handled all of the objects at this level, This means
1164 * that we have just completed a package. That package may
1165 * have contained one or more packages itself.
1167 * Delete this state and pop the previous state (package).
1169 AcpiUtDeleteGenericState (State);
1170 State = AcpiUtPopGenericState (&StateList);
1172 /* Finished when there are no more states */
1174 if (!State)
1177 * We have handled all of the objects in the top level
1178 * package just add the length of the package objects
1179 * and exit
1181 return_ACPI_STATUS (AE_OK);
1185 * Go back up a level and move the index past the just
1186 * completed package object.
1188 State->Pkg.Index++;
1191 else
1193 /* This is a subobject of type package */
1195 Status = WalkCallback (ACPI_COPY_TYPE_PACKAGE, ThisSourceObj,
1196 State, Context);
1197 if (ACPI_FAILURE (Status))
1199 return_ACPI_STATUS (Status);
1203 * Push the current state and create a new one
1204 * The callback above returned a new target package object.
1206 AcpiUtPushGenericState (&StateList, State);
1207 State = AcpiUtCreatePkgState (ThisSourceObj,
1208 State->Pkg.ThisTargetObj, 0);
1209 if (!State)
1211 return_ACPI_STATUS (AE_NO_MEMORY);
1216 /* We should never get here */
1218 return_ACPI_STATUS (AE_AML_INTERNAL);
1222 /*******************************************************************************
1224 * FUNCTION: AcpiUtError, AcpiUtWarning, AcpiUtInfo
1226 * PARAMETERS: ModuleName - Caller's module name (for error output)
1227 * LineNumber - Caller's line number (for error output)
1228 * Format - Printf format string + additional args
1230 * RETURN: None
1232 * DESCRIPTION: Print message with module/line/version info
1234 ******************************************************************************/
1236 void ACPI_INTERNAL_VAR_XFACE
1237 AcpiUtError (
1238 char *ModuleName,
1239 UINT32 LineNumber,
1240 char *Format,
1241 ...)
1243 va_list args;
1246 AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
1248 va_start (args, Format);
1249 AcpiOsVprintf (Format, args);
1250 AcpiOsPrintf (" [%X]\n", ACPI_CA_VERSION);
1253 void ACPI_INTERNAL_VAR_XFACE
1254 AcpiUtException (
1255 char *ModuleName,
1256 UINT32 LineNumber,
1257 ACPI_STATUS Status,
1258 char *Format,
1259 ...)
1261 va_list args;
1264 AcpiOsPrintf ("ACPI Exception (%s-%04d): %s, ", ModuleName, LineNumber,
1265 AcpiFormatException (Status));
1267 va_start (args, Format);
1268 AcpiOsVprintf (Format, args);
1269 AcpiOsPrintf (" [%X]\n", ACPI_CA_VERSION);
1272 void ACPI_INTERNAL_VAR_XFACE
1273 AcpiUtWarning (
1274 char *ModuleName,
1275 UINT32 LineNumber,
1276 char *Format,
1277 ...)
1279 va_list args;
1282 AcpiOsPrintf ("ACPI Warning (%s-%04d): ", ModuleName, LineNumber);
1284 va_start (args, Format);
1285 AcpiOsVprintf (Format, args);
1286 AcpiOsPrintf (" [%X]\n", ACPI_CA_VERSION);
1289 void ACPI_INTERNAL_VAR_XFACE
1290 AcpiUtInfo (
1291 char *ModuleName,
1292 UINT32 LineNumber,
1293 char *Format,
1294 ...)
1296 va_list args;
1300 * Removed ModuleName, LineNumber, and acpica version, not needed
1301 * for info output
1303 AcpiOsPrintf ("ACPI: ");
1305 va_start (args, Format);
1306 AcpiOsVprintf (Format, args);
1307 AcpiOsPrintf ("\n");