utmisc.c revision 30082d0cc16bf5799269ca464a219de900f519cd
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi/*******************************************************************************
49b7860084dbba18bc00b29413d6182197f9fe93Robert Mustacchi * Module Name: utmisc - common utility procedures
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * $Revision: 1.136 $
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi ******************************************************************************/
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi/******************************************************************************
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 1. Copyright Notice
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * All rights reserved.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * rights. You may have additional license terms from the party that provided
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * you this software, covering your right to use that party's intellectual
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * property rights.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Code in any form, with the right to sublicense such rights; and
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * license (with the right to sublicense), under only those claims of Intel
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * license, and in no event shall the patent license extend to any additions
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * to or modifications of the Original Intel Code. No other license or right
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * is granted directly or by implication, estoppel or otherwise;
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * The above copyright and patent license is granted only if the following
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * conditions are met:
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 3. Conditions
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Code or modification with rights to further distribute source must include
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * must include a prominent statement that the modification is derived,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * directly or indirectly, from Original Intel Code.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Code or modification without rights to further distribute source must
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * documentation and/or other materials provided with distribution. In
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * not to intellectual property embodied in modifications its licensee may
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * provision in the documentation and/or other materials provided with the
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * distribution.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Intel Code.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * without prior written authorization from Intel.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * 4. Disclaimer and Export Compliance
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * PARTICULAR PURPOSE.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * LIMITED REMEDY.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * software or system incorporating such software without first obtaining any
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * required license or other approval from the U. S. Department of Commerce or
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * any other agency or department of the United States Government. In the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * event Licensee exports any such software from the United States or
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * ensure that the distribution and export/re-export of the software is in
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * United States government or any agency thereof requires an export license,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * such license, approval or letter.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi *****************************************************************************/
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi/*******************************************************************************
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * FUNCTION: AcpiUtAllocateOwnerId
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * PARAMETERS: OwnerId - Where the new owner ID is returned
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * RETURN: Status
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * DESCRIPTION: Allocate a table or method owner ID. The owner ID is used to
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * track objects created by the table or method, to be deleted
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi * when the method exits or the table is unloaded.
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi ******************************************************************************/
c124a83e09115de88ecccd4f689983f42a1d53bdRobert Mustacchi /* Guard against multiple allocations of ID to the same location */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi ACPI_ERROR ((AE_INFO, "Owner ID [%2.2X] already exists", *OwnerId));
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Mutex for the global ID mask */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Find a free owner ID, cycle through all possible IDs on repeated
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * allocations. (ACPI_NUM_OWNERID_MASKS + 1) because first index may have
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * to be scanned twice.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi j = 0; /* Wraparound to start of mask array */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi for (k = AcpiGbl_NextOwnerIdOffset; k < 32; k++)
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi if (AcpiGbl_OwnerIdMask[j] == ACPI_UINT32_MAX)
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* There are no free IDs in this mask */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Found a free ID. The actual ID is the bit index plus one,
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * making zero an invalid Owner ID. Save this as the last ID
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * allocated and update the global ID mask.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi AcpiGbl_NextOwnerIdOffset = (UINT8) (k + 1);
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Construct encoded ID from the index and bit position
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * Note: Last [j].k (bit 255) is never used and is marked
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * permanently allocated (prevents +1 overflow)
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi *OwnerId = (ACPI_OWNER_ID) ((k + 1) + ACPI_MUL_32 (j));
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi "Allocated OwnerId: %2.2X\n", (unsigned int) *OwnerId));
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * All OwnerIds have been allocated. This typically should
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * not happen since the IDs are reused after deallocation. The IDs are
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * allocated upon table load (one per table) and method execution, and
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * they are released when a table is unloaded or a method completes
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * If this error happens, there may be very deep nesting of invoked control
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * methods, or there may be a bug where the IDs are not released.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi "Could not allocate new OwnerId (255 max), AE_OWNER_ID_LIMIT"));
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi/*******************************************************************************
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * FUNCTION: AcpiUtReleaseOwnerId
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * PARAMETERS: OwnerIdPtr - Pointer to a previously allocated OwnerID
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * RETURN: None. No error is returned because we are either exiting a
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * control method or unloading a table. Either way, we would
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * ignore any error anyway.
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi * DESCRIPTION: Release a table or method owner ID. Valid IDs are 1 - 255
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi ******************************************************************************/
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi ACPI_FUNCTION_TRACE_U32 ("UtReleaseOwnerId", OwnerId);
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Always clear the input OwnerId (zero is an invalid ID) */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Zero is not a valid OwnerID */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi ACPI_ERROR ((AE_INFO, "Invalid OwnerId: %2.2X", OwnerId));
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Mutex for the global ID mask */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi Status = AcpiUtAcquireMutex (ACPI_MTX_CACHES);
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Normalize the ID to zero */
75eba5b6d79ed4d2ce3daf7b2806306b6b69a938Robert Mustacchi /* Decode ID to index/offset pair */
* NOTE: This is not a POSIX function, so it appears here, not in utclib.c
char *SrcString)
char *String;
if (!SrcString)
char *String,
UINT32 i;
if (!String)
switch (String[i])
} Out;
} In;
#ifdef ACPI_DEBUG_OUTPUT
char *Path)
switch (Type)
case ACPI_TYPE_METHOD:
if (Path)
char Character;
for (i = 0; i < ACPI_NAME_SIZE; i++)
NamePtr++;
return (FALSE);
return (TRUE);
char Character)
char *String,
goto ErrorExit;
switch (Base)
case ACPI_ANY_BASE:
String++;
if (Base == 0)
if (!(*String))
goto ErrorExit;
while (*String)
goto ErrorExit;
goto ErrorExit;
String++;
if (!Object)
return (AE_OK);
if (!State)
return (AE_NO_MEMORY);
return (AE_OK);
void *TargetObject,
void *Context)
if (!State)
while (State)
if ((!ThisSourceObj) ||
if (!State)
if (!State)
char *ModuleName,
char *Format,
char *ModuleName,
char *Format,
char *ModuleName,
char *Format,
char *ModuleName,
char *Format,
char *ModuleName,
char *ModuleName,
char *ModuleName,