exutils.c revision 197104
167754Smsmith
267754Smsmith/******************************************************************************
367754Smsmith *
477424Smsmith * Module Name: exutils - interpreter/scanner utilities
567754Smsmith *
667754Smsmith *****************************************************************************/
767754Smsmith
867754Smsmith/******************************************************************************
967754Smsmith *
1067754Smsmith * 1. Copyright Notice
1167754Smsmith *
12193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1370243Smsmith * All rights reserved.
1467754Smsmith *
1567754Smsmith * 2. License
1667754Smsmith *
1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1867754Smsmith * rights.  You may have additional license terms from the party that provided
1967754Smsmith * you this software, covering your right to use that party's intellectual
2067754Smsmith * property rights.
2167754Smsmith *
2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2767754Smsmith * Code in any form, with the right to sublicense such rights; and
2867754Smsmith *
2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3067754Smsmith * license (with the right to sublicense), under only those claims of Intel
3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3467754Smsmith * license, and in no event shall the patent license extend to any additions
3567754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3667754Smsmith * is granted directly or by implication, estoppel or otherwise;
3767754Smsmith *
3867754Smsmith * The above copyright and patent license is granted only if the following
3967754Smsmith * conditions are met:
4067754Smsmith *
4167754Smsmith * 3. Conditions
4267754Smsmith *
4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4467754Smsmith * Redistribution of source code of any substantial portion of the Covered
4567754Smsmith * Code or modification with rights to further distribute source must include
4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4767754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5067754Smsmith * Code and the date of any change.  Licensee must include in that file the
5167754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5267754Smsmith * must include a prominent statement that the modification is derived,
5367754Smsmith * directly or indirectly, from Original Intel Code.
5467754Smsmith *
5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5667754Smsmith * Redistribution of source code of any substantial portion of the Covered
5767754Smsmith * Code or modification without rights to further distribute source must
5867754Smsmith * include the following Disclaimer and Export Compliance provision in the
5967754Smsmith * documentation and/or other materials provided with distribution.  In
6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6267754Smsmith * license from Licensee to its licensee is limited to the intellectual
6367754Smsmith * property embodied in the software Licensee provides to its licensee, and
6467754Smsmith * not to intellectual property embodied in modifications its licensee may
6567754Smsmith * make.
6667754Smsmith *
6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the
6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7067754Smsmith * provision in the documentation and/or other materials provided with the
7167754Smsmith * distribution.
7267754Smsmith *
7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7467754Smsmith * Intel Code.
7567754Smsmith *
7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7867754Smsmith * other dealings in products derived from or relating to the Covered Code
7967754Smsmith * without prior written authorization from Intel.
8067754Smsmith *
8167754Smsmith * 4. Disclaimer and Export Compliance
8267754Smsmith *
8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8467754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8967754Smsmith * PARTICULAR PURPOSE.
9067754Smsmith *
9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9867754Smsmith * LIMITED REMEDY.
9967754Smsmith *
10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10167754Smsmith * software or system incorporating such software without first obtaining any
10267754Smsmith * required license or other approval from the U. S. Department of Commerce or
10367754Smsmith * any other agency or department of the United States Government.  In the
10467754Smsmith * event Licensee exports any such software from the United States or
10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10667754Smsmith * ensure that the distribution and export/re-export of the software is in
10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11067754Smsmith * software, or service, directly or indirectly, to any country for which the
11167754Smsmith * United States government or any agency thereof requires an export license,
11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11367754Smsmith * such license, approval or letter.
11467754Smsmith *
11567754Smsmith *****************************************************************************/
11667754Smsmith
11777424Smsmith#define __EXUTILS_C__
11867754Smsmith
11983174Smsmith/*
12083174Smsmith * DEFINE_AML_GLOBALS is tested in amlcode.h
12183174Smsmith * to determine whether certain global names should be "defined" or only
12283174Smsmith * "declared" in the current compilation.  This enhances maintainability
12383174Smsmith * by enabling a single header file to embody all knowledge of the names
12483174Smsmith * in question.
12583174Smsmith *
12683174Smsmith * Exactly one module of any executable should #define DEFINE_GLOBALS
12783174Smsmith * before #including the header files which use this convention.  The
12883174Smsmith * names in question will be defined and initialized in that module,
12983174Smsmith * and declared as extern in all other modules which #include those
13083174Smsmith * header files.
13183174Smsmith */
13283174Smsmith
13383174Smsmith#define DEFINE_AML_GLOBALS
13483174Smsmith
135193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
136193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
137193341Sjkim#include <contrib/dev/acpica/include/acinterp.h>
138193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
13967754Smsmith
14077424Smsmith#define _COMPONENT          ACPI_EXECUTER
14191116Smsmith        ACPI_MODULE_NAME    ("exutils")
14267754Smsmith
143151937Sjkim/* Local prototypes */
14467754Smsmith
145151937Sjkimstatic UINT32
146151937SjkimAcpiExDigitsNeeded (
147151937Sjkim    ACPI_INTEGER            Value,
148151937Sjkim    UINT32                  Base);
149151937Sjkim
150151937Sjkim
151100966Siwasaki#ifndef ACPI_NO_METHOD_EXECUTION
152100966Siwasaki/*******************************************************************************
153100966Siwasaki *
15477424Smsmith * FUNCTION:    AcpiExEnterInterpreter
15567754Smsmith *
15667754Smsmith * PARAMETERS:  None
15767754Smsmith *
158167802Sjkim * RETURN:      None
159151937Sjkim *
160167802Sjkim * DESCRIPTION: Enter the interpreter execution region. Failure to enter
161167802Sjkim *              the interpreter region is a fatal system error. Used in
162167802Sjkim *              conjunction with ExitInterpreter.
16367754Smsmith *
16467754Smsmith ******************************************************************************/
16567754Smsmith
166167802Sjkimvoid
167151937SjkimAcpiExEnterInterpreter (
168151937Sjkim    void)
16967754Smsmith{
17077424Smsmith    ACPI_STATUS             Status;
17167754Smsmith
17267754Smsmith
173167802Sjkim    ACPI_FUNCTION_TRACE (ExEnterInterpreter);
17467754Smsmith
175167802Sjkim
176167802Sjkim    Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
17791116Smsmith    if (ACPI_FAILURE (Status))
17891116Smsmith    {
179167802Sjkim        ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
18091116Smsmith    }
18191116Smsmith
182167802Sjkim    return_VOID;
18367754Smsmith}
18467754Smsmith
18567754Smsmith
18667754Smsmith/*******************************************************************************
18767754Smsmith *
188167802Sjkim * FUNCTION:    AcpiExReacquireInterpreter
189167802Sjkim *
190167802Sjkim * PARAMETERS:  None
191167802Sjkim *
192167802Sjkim * RETURN:      None
193167802Sjkim *
194167802Sjkim * DESCRIPTION: Reacquire the interpreter execution region from within the
195167802Sjkim *              interpreter code. Failure to enter the interpreter region is a
196167802Sjkim *              fatal system error. Used in  conjuction with
197167802Sjkim *              RelinquishInterpreter
198167802Sjkim *
199167802Sjkim ******************************************************************************/
200167802Sjkim
201167802Sjkimvoid
202167802SjkimAcpiExReacquireInterpreter (
203167802Sjkim    void)
204167802Sjkim{
205167802Sjkim    ACPI_FUNCTION_TRACE (ExReacquireInterpreter);
206167802Sjkim
207167802Sjkim
208167802Sjkim    /*
209167802Sjkim     * If the global serialized flag is set, do not release the interpreter,
210167802Sjkim     * since it was not actually released by AcpiExRelinquishInterpreter.
211167802Sjkim     * This forces the interpreter to be single threaded.
212167802Sjkim     */
213167802Sjkim    if (!AcpiGbl_AllMethodsSerialized)
214167802Sjkim    {
215167802Sjkim        AcpiExEnterInterpreter ();
216167802Sjkim    }
217167802Sjkim
218167802Sjkim    return_VOID;
219167802Sjkim}
220167802Sjkim
221167802Sjkim
222167802Sjkim/*******************************************************************************
223167802Sjkim *
22477424Smsmith * FUNCTION:    AcpiExExitInterpreter
22567754Smsmith *
22667754Smsmith * PARAMETERS:  None
22767754Smsmith *
228151937Sjkim * RETURN:      None
229151937Sjkim *
230167802Sjkim * DESCRIPTION: Exit the interpreter execution region. This is the top level
231167802Sjkim *              routine used to exit the interpreter when all processing has
232167802Sjkim *              been completed.
23367754Smsmith *
23467754Smsmith ******************************************************************************/
23567754Smsmith
23667754Smsmithvoid
237151937SjkimAcpiExExitInterpreter (
238151937Sjkim    void)
23967754Smsmith{
24091116Smsmith    ACPI_STATUS             Status;
24167754Smsmith
24267754Smsmith
243167802Sjkim    ACPI_FUNCTION_TRACE (ExExitInterpreter);
24467754Smsmith
24591116Smsmith
246167802Sjkim    Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
24799679Siwasaki    if (ACPI_FAILURE (Status))
24899679Siwasaki    {
249167802Sjkim        ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
25099679Siwasaki    }
25191116Smsmith
25267754Smsmith    return_VOID;
25367754Smsmith}
25467754Smsmith
25567754Smsmith
25667754Smsmith/*******************************************************************************
25767754Smsmith *
258167802Sjkim * FUNCTION:    AcpiExRelinquishInterpreter
259167802Sjkim *
260167802Sjkim * PARAMETERS:  None
261167802Sjkim *
262167802Sjkim * RETURN:      None
263167802Sjkim *
264167802Sjkim * DESCRIPTION: Exit the interpreter execution region, from within the
265167802Sjkim *              interpreter - before attempting an operation that will possibly
266167802Sjkim *              block the running thread.
267167802Sjkim *
268167802Sjkim * Cases where the interpreter is unlocked internally
269167802Sjkim *      1) Method to be blocked on a Sleep() AML opcode
270167802Sjkim *      2) Method to be blocked on an Acquire() AML opcode
271167802Sjkim *      3) Method to be blocked on a Wait() AML opcode
272167802Sjkim *      4) Method to be blocked to acquire the global lock
273167802Sjkim *      5) Method to be blocked waiting to execute a serialized control method
274167802Sjkim *          that is currently executing
275167802Sjkim *      6) About to invoke a user-installed opregion handler
276167802Sjkim *
277167802Sjkim ******************************************************************************/
278167802Sjkim
279167802Sjkimvoid
280167802SjkimAcpiExRelinquishInterpreter (
281167802Sjkim    void)
282167802Sjkim{
283167802Sjkim    ACPI_FUNCTION_TRACE (ExRelinquishInterpreter);
284167802Sjkim
285167802Sjkim
286167802Sjkim    /*
287167802Sjkim     * If the global serialized flag is set, do not release the interpreter.
288167802Sjkim     * This forces the interpreter to be single threaded.
289167802Sjkim     */
290167802Sjkim    if (!AcpiGbl_AllMethodsSerialized)
291167802Sjkim    {
292167802Sjkim        AcpiExExitInterpreter ();
293167802Sjkim    }
294167802Sjkim
295167802Sjkim    return_VOID;
296167802Sjkim}
297167802Sjkim
298167802Sjkim
299167802Sjkim/*******************************************************************************
300167802Sjkim *
30177424Smsmith * FUNCTION:    AcpiExTruncateFor32bitTable
30267754Smsmith *
30369450Smsmith * PARAMETERS:  ObjDesc         - Object to be truncated
30467754Smsmith *
30569450Smsmith * RETURN:      none
30667754Smsmith *
307167802Sjkim * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
308167802Sjkim *              32-bit, as determined by the revision of the DSDT.
30967754Smsmith *
31067754Smsmith ******************************************************************************/
31167754Smsmith
31269450Smsmithvoid
31377424SmsmithAcpiExTruncateFor32bitTable (
31499679Siwasaki    ACPI_OPERAND_OBJECT     *ObjDesc)
31567754Smsmith{
31667754Smsmith
31791116Smsmith    ACPI_FUNCTION_ENTRY ();
31883174Smsmith
31983174Smsmith
32069450Smsmith    /*
32169450Smsmith     * Object must be a valid number and we must be executing
322167802Sjkim     * a control method. NS node could be there for AML_INT_NAMEPATH_OP.
32369450Smsmith     */
32469450Smsmith    if ((!ObjDesc) ||
325167802Sjkim        (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
326193267Sjkim        (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
32769450Smsmith    {
32869450Smsmith        return;
32969450Smsmith    }
33069450Smsmith
33199679Siwasaki    if (AcpiGbl_IntegerByteWidth == 4)
33269450Smsmith    {
33369450Smsmith        /*
33469450Smsmith         * We are running a method that exists in a 32-bit ACPI table.
33569450Smsmith         * Truncate the value to 32 bits by zeroing out the upper 32-bit field
33669450Smsmith         */
33771867Smsmith        ObjDesc->Integer.Value &= (ACPI_INTEGER) ACPI_UINT32_MAX;
33869450Smsmith    }
33967754Smsmith}
34067754Smsmith
34167754Smsmith
34267754Smsmith/*******************************************************************************
34367754Smsmith *
34477424Smsmith * FUNCTION:    AcpiExAcquireGlobalLock
34567754Smsmith *
34691116Smsmith * PARAMETERS:  FieldFlags            - Flags with Lock rule:
34787031Smsmith *                                      AlwaysLock or NeverLock
34867754Smsmith *
349167802Sjkim * RETURN:      None
35067754Smsmith *
351167802Sjkim * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
352167802Sjkim *              flags specifiy that it is to be obtained before field access.
35367754Smsmith *
35467754Smsmith ******************************************************************************/
35567754Smsmith
356167802Sjkimvoid
35777424SmsmithAcpiExAcquireGlobalLock (
35887031Smsmith    UINT32                  FieldFlags)
35967754Smsmith{
36067754Smsmith    ACPI_STATUS             Status;
36167754Smsmith
36267754Smsmith
363167802Sjkim    ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
36467754Smsmith
36567754Smsmith
366167802Sjkim    /* Only use the lock if the AlwaysLock bit is set */
36767754Smsmith
368167802Sjkim    if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
36967754Smsmith    {
370167802Sjkim        return_VOID;
371167802Sjkim    }
37267754Smsmith
373167802Sjkim    /* Attempt to get the global lock, wait forever */
374167802Sjkim
375167802Sjkim    Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
376167802Sjkim                AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
377167802Sjkim
378167802Sjkim    if (ACPI_FAILURE (Status))
379167802Sjkim    {
380167802Sjkim        ACPI_EXCEPTION ((AE_INFO, Status,
381167802Sjkim            "Could not acquire Global Lock"));
38267754Smsmith    }
38367754Smsmith
384167802Sjkim    return_VOID;
38567754Smsmith}
38667754Smsmith
38767754Smsmith
38867754Smsmith/*******************************************************************************
38967754Smsmith *
39077424Smsmith * FUNCTION:    AcpiExReleaseGlobalLock
39167754Smsmith *
392167802Sjkim * PARAMETERS:  FieldFlags            - Flags with Lock rule:
393167802Sjkim *                                      AlwaysLock or NeverLock
39467754Smsmith *
395151937Sjkim * RETURN:      None
39667754Smsmith *
397167802Sjkim * DESCRIPTION: Release the ACPI hardware Global Lock
39867754Smsmith *
39967754Smsmith ******************************************************************************/
40067754Smsmith
40199679Siwasakivoid
40277424SmsmithAcpiExReleaseGlobalLock (
403167802Sjkim    UINT32                  FieldFlags)
40467754Smsmith{
40599679Siwasaki    ACPI_STATUS             Status;
40667754Smsmith
40799679Siwasaki
408167802Sjkim    ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
40967754Smsmith
41067754Smsmith
411167802Sjkim    /* Only use the lock if the AlwaysLock bit is set */
41267754Smsmith
413167802Sjkim    if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
41467754Smsmith    {
415167802Sjkim        return_VOID;
416167802Sjkim    }
41767754Smsmith
418167802Sjkim    /* Release the global lock */
41999679Siwasaki
420167802Sjkim    Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
421167802Sjkim    if (ACPI_FAILURE (Status))
422167802Sjkim    {
423167802Sjkim        /* Report the error, but there isn't much else we can do */
424167802Sjkim
425167802Sjkim        ACPI_EXCEPTION ((AE_INFO, Status,
426167802Sjkim            "Could not release Global Lock"));
42767754Smsmith    }
428100966Siwasaki
429100966Siwasaki    return_VOID;
43067754Smsmith}
43167754Smsmith
43267754Smsmith
43367754Smsmith/*******************************************************************************
43467754Smsmith *
43577424Smsmith * FUNCTION:    AcpiExDigitsNeeded
43667754Smsmith *
43784491Smsmith * PARAMETERS:  Value           - Value to be represented
43884491Smsmith *              Base            - Base of representation
43967754Smsmith *
440151937Sjkim * RETURN:      The number of digits.
44167754Smsmith *
442151937Sjkim * DESCRIPTION: Calculate the number of digits needed to represent the Value
443151937Sjkim *              in the given Base (Radix)
444151937Sjkim *
44567754Smsmith ******************************************************************************/
44667754Smsmith
447151937Sjkimstatic UINT32
44877424SmsmithAcpiExDigitsNeeded (
44984491Smsmith    ACPI_INTEGER            Value,
45084491Smsmith    UINT32                  Base)
45167754Smsmith{
45299679Siwasaki    UINT32                  NumDigits;
45399679Siwasaki    ACPI_INTEGER            CurrentValue;
45467754Smsmith
45567754Smsmith
456167802Sjkim    ACPI_FUNCTION_TRACE (ExDigitsNeeded);
45767754Smsmith
45867754Smsmith
459138287Smarks    /* ACPI_INTEGER is unsigned, so we don't worry about a '-' prefix */
460138287Smarks
461138287Smarks    if (Value == 0)
462117521Snjl    {
463151937Sjkim        return_UINT32 (1);
464117521Snjl    }
465117521Snjl
466138287Smarks    CurrentValue = Value;
46799679Siwasaki    NumDigits = 0;
46899679Siwasaki
469138287Smarks    /* Count the digits in the requested base */
470138287Smarks
47199679Siwasaki    while (CurrentValue)
47267754Smsmith    {
473138287Smarks        (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
47499679Siwasaki        NumDigits++;
47567754Smsmith    }
47667754Smsmith
477151937Sjkim    return_UINT32 (NumDigits);
47867754Smsmith}
47967754Smsmith
48067754Smsmith
48167754Smsmith/*******************************************************************************
48267754Smsmith *
48377424Smsmith * FUNCTION:    AcpiExEisaIdToString
48467754Smsmith *
485197104Sjkim * PARAMETERS:  CompressedId    - EISAID to be converted
48667754Smsmith *              OutString       - Where to put the converted string (8 bytes)
48767754Smsmith *
488151937Sjkim * RETURN:      None
489151937Sjkim *
490197104Sjkim * DESCRIPTION: Convert a numeric EISAID to string representation. Return
491197104Sjkim *              buffer must be large enough to hold the string. The string
492197104Sjkim *              returned is always exactly of length ACPI_EISAID_STRING_SIZE
493197104Sjkim *              (includes null terminator). The EISAID is always 32 bits.
49467754Smsmith *
49567754Smsmith ******************************************************************************/
49667754Smsmith
49799679Siwasakivoid
49877424SmsmithAcpiExEisaIdToString (
499197104Sjkim    char                    *OutString,
500197104Sjkim    ACPI_INTEGER            CompressedId)
50167754Smsmith{
502197104Sjkim    UINT32                  SwappedId;
50367754Smsmith
50483174Smsmith
50591116Smsmith    ACPI_FUNCTION_ENTRY ();
50683174Smsmith
50783174Smsmith
508197104Sjkim    /* The EISAID should be a 32-bit integer */
509197104Sjkim
510197104Sjkim    if (CompressedId > ACPI_UINT32_MAX)
511197104Sjkim    {
512197104Sjkim        ACPI_WARNING ((AE_INFO,
513197104Sjkim            "Expected EISAID is larger than 32 bits: 0x%8.8X%8.8X, truncating",
514197104Sjkim            ACPI_FORMAT_UINT64 (CompressedId)));
515197104Sjkim    }
516197104Sjkim
51799679Siwasaki    /* Swap ID to big-endian to get contiguous bits */
51867754Smsmith
519197104Sjkim    SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
52067754Smsmith
521197104Sjkim    /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
522197104Sjkim
523197104Sjkim    OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
524197104Sjkim    OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
525197104Sjkim    OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
526197104Sjkim    OutString[3] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 12);
527197104Sjkim    OutString[4] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 8);
528197104Sjkim    OutString[5] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 4);
529197104Sjkim    OutString[6] = AcpiUtHexToAsciiChar ((ACPI_INTEGER) SwappedId, 0);
53067754Smsmith    OutString[7] = 0;
53167754Smsmith}
53267754Smsmith
53367754Smsmith
53467754Smsmith/*******************************************************************************
53567754Smsmith *
536197104Sjkim * FUNCTION:    AcpiExIntegerToString
53767754Smsmith *
538197104Sjkim * PARAMETERS:  OutString       - Where to put the converted string. At least
539197104Sjkim *                                21 bytes are needed to hold the largest
540197104Sjkim *                                possible 64-bit integer.
541197104Sjkim *              Value           - Value to be converted
54267754Smsmith *
543151937Sjkim * RETURN:      None, string
54467754Smsmith *
545197104Sjkim * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
546197104Sjkim *              Assumes string buffer is large enough to hold the string. The
547197104Sjkim *              largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
548151937Sjkim *
54967754Smsmith ******************************************************************************/
55067754Smsmith
55199679Siwasakivoid
552197104SjkimAcpiExIntegerToString (
553197104Sjkim    char                    *OutString,
554197104Sjkim    ACPI_INTEGER            Value)
55567754Smsmith{
55667754Smsmith    UINT32                  Count;
55767754Smsmith    UINT32                  DigitsNeeded;
55884491Smsmith    UINT32                  Remainder;
55967754Smsmith
56067754Smsmith
56191116Smsmith    ACPI_FUNCTION_ENTRY ();
56283174Smsmith
56383174Smsmith
56477424Smsmith    DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
56584491Smsmith    OutString[DigitsNeeded] = 0;
56667754Smsmith
56767754Smsmith    for (Count = DigitsNeeded; Count > 0; Count--)
56867754Smsmith    {
569138287Smarks        (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
570114237Snjl        OutString[Count-1] = (char) ('0' + Remainder);\
57167754Smsmith    }
57267754Smsmith}
57367754Smsmith
574100966Siwasaki#endif
575