Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1497 → Rev 1498

/drivers/devman/acpica/namespace/nsaccess.c
0,0 → 1,772
/*******************************************************************************
*
* Module Name: nsaccess - Top-level functions for accessing ACPI namespace
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSACCESS_C__
 
#include "acpi.h"
#include "accommon.h"
#include "amlcode.h"
#include "acnamesp.h"
#include "acdispat.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsaccess")
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsRootInitialize
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Allocate and initialize the default root named objects
*
* MUTEX: Locks namespace for entire execution
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsRootInitialize (
void)
{
ACPI_STATUS Status;
const ACPI_PREDEFINED_NAMES *InitVal = NULL;
ACPI_NAMESPACE_NODE *NewNode;
ACPI_OPERAND_OBJECT *ObjDesc;
ACPI_STRING Val = NULL;
 
 
ACPI_FUNCTION_TRACE (NsRootInitialize);
 
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/*
* The global root ptr is initially NULL, so a non-NULL value indicates
* that AcpiNsRootInitialize() has already been called; just return.
*/
if (AcpiGbl_RootNode)
{
Status = AE_OK;
goto UnlockAndExit;
}
 
/*
* Tell the rest of the subsystem that the root is initialized
* (This is OK because the namespace is locked)
*/
AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct;
 
/* Enter the pre-defined names in the name table */
 
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"Entering predefined entries into namespace\n"));
 
for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++)
{
/* _OSI is optional for now, will be permanent later */
 
if (!ACPI_STRCMP (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod)
{
continue;
}
 
Status = AcpiNsLookup (NULL, InitVal->Name, InitVal->Type,
ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH,
NULL, &NewNode);
 
if (ACPI_FAILURE (Status) || (!NewNode)) /* Must be on same line for code converter */
{
ACPI_EXCEPTION ((AE_INFO, Status,
"Could not create predefined name %s",
InitVal->Name));
}
 
/*
* Name entered successfully. If entry in PreDefinedNames[] specifies
* an initial value, create the initial value.
*/
if (InitVal->Val)
{
Status = AcpiOsPredefinedOverride (InitVal, &Val);
if (ACPI_FAILURE (Status))
{
ACPI_ERROR ((AE_INFO,
"Could not override predefined %s",
InitVal->Name));
}
 
if (!Val)
{
Val = InitVal->Val;
}
 
/*
* Entry requests an initial value, allocate a
* descriptor for it.
*/
ObjDesc = AcpiUtCreateInternalObject (InitVal->Type);
if (!ObjDesc)
{
Status = AE_NO_MEMORY;
goto UnlockAndExit;
}
 
/*
* Convert value string from table entry to
* internal representation. Only types actually
* used for initial values are implemented here.
*/
switch (InitVal->Type)
{
case ACPI_TYPE_METHOD:
ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val);
ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
 
#if defined (ACPI_ASL_COMPILER)
 
/* Save the parameter count for the iASL compiler */
 
NewNode->Value = ObjDesc->Method.ParamCount;
#else
/* Mark this as a very SPECIAL method */
 
ObjDesc->Method.MethodFlags = AML_METHOD_INTERNAL_ONLY;
ObjDesc->Method.Extra.Implementation = AcpiUtOsiImplementation;
#endif
break;
 
case ACPI_TYPE_INTEGER:
 
ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val);
break;
 
 
case ACPI_TYPE_STRING:
 
/* Build an object around the static string */
 
ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Val);
ObjDesc->String.Pointer = Val;
ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
break;
 
 
case ACPI_TYPE_MUTEX:
 
ObjDesc->Mutex.Node = NewNode;
ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1);
 
/* Create a mutex */
 
Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex);
if (ACPI_FAILURE (Status))
{
AcpiUtRemoveReference (ObjDesc);
goto UnlockAndExit;
}
 
/* Special case for ACPI Global Lock */
 
if (ACPI_STRCMP (InitVal->Name, "_GL_") == 0)
{
AcpiGbl_GlobalLockMutex = ObjDesc;
 
/* Create additional counting semaphore for global lock */
 
Status = AcpiOsCreateSemaphore (
1, 0, &AcpiGbl_GlobalLockSemaphore);
if (ACPI_FAILURE (Status))
{
AcpiUtRemoveReference (ObjDesc);
goto UnlockAndExit;
}
}
break;
 
 
default:
 
ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X",
InitVal->Type));
AcpiUtRemoveReference (ObjDesc);
ObjDesc = NULL;
continue;
}
 
/* Store pointer to value descriptor in the Node */
 
Status = AcpiNsAttachObject (NewNode, ObjDesc,
ObjDesc->Common.Type);
 
/* Remove local reference to the object */
 
AcpiUtRemoveReference (ObjDesc);
}
}
 
 
UnlockAndExit:
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 
/* Save a handle to "_GPE", it is always present */
 
if (ACPI_SUCCESS (Status))
{
Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH,
&AcpiGbl_FadtGpeDevice);
}
 
return_ACPI_STATUS (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsLookup
*
* PARAMETERS: ScopeInfo - Current scope info block
* Pathname - Search pathname, in internal format
* (as represented in the AML stream)
* Type - Type associated with name
* InterpreterMode - IMODE_LOAD_PASS2 => add name if not found
* Flags - Flags describing the search restrictions
* WalkState - Current state of the walk
* ReturnNode - Where the Node is placed (if found
* or created successfully)
*
* RETURN: Status
*
* DESCRIPTION: Find or enter the passed name in the name space.
* Log an error if name not found in Exec mode.
*
* MUTEX: Assumes namespace is locked.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsLookup (
ACPI_GENERIC_STATE *ScopeInfo,
char *Pathname,
ACPI_OBJECT_TYPE Type,
ACPI_INTERPRETER_MODE InterpreterMode,
UINT32 Flags,
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE **ReturnNode)
{
ACPI_STATUS Status;
char *Path = Pathname;
ACPI_NAMESPACE_NODE *PrefixNode;
ACPI_NAMESPACE_NODE *CurrentNode = NULL;
ACPI_NAMESPACE_NODE *ThisNode = NULL;
UINT32 NumSegments;
UINT32 NumCarats;
ACPI_NAME SimpleName;
ACPI_OBJECT_TYPE TypeToCheckFor;
ACPI_OBJECT_TYPE ThisSearchType;
UINT32 SearchParentFlag = ACPI_NS_SEARCH_PARENT;
UINT32 LocalFlags;
 
 
ACPI_FUNCTION_TRACE (NsLookup);
 
 
if (!ReturnNode)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
LocalFlags = Flags & ~(ACPI_NS_ERROR_IF_FOUND | ACPI_NS_SEARCH_PARENT);
*ReturnNode = ACPI_ENTRY_NOT_FOUND;
AcpiGbl_NsLookupCount++;
 
if (!AcpiGbl_RootNode)
{
return_ACPI_STATUS (AE_NO_NAMESPACE);
}
 
/* Get the prefix scope. A null scope means use the root scope */
 
if ((!ScopeInfo) ||
(!ScopeInfo->Scope.Node))
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Null scope prefix, using root node (%p)\n",
AcpiGbl_RootNode));
 
PrefixNode = AcpiGbl_RootNode;
}
else
{
PrefixNode = ScopeInfo->Scope.Node;
if (ACPI_GET_DESCRIPTOR_TYPE (PrefixNode) != ACPI_DESC_TYPE_NAMED)
{
ACPI_ERROR ((AE_INFO, "%p is not a namespace node [%s]",
PrefixNode, AcpiUtGetDescriptorName (PrefixNode)));
return_ACPI_STATUS (AE_AML_INTERNAL);
}
 
if (!(Flags & ACPI_NS_PREFIX_IS_SCOPE))
{
/*
* This node might not be a actual "scope" node (such as a
* Device/Method, etc.) It could be a Package or other object
* node. Backup up the tree to find the containing scope node.
*/
while (!AcpiNsOpensScope (PrefixNode->Type) &&
PrefixNode->Type != ACPI_TYPE_ANY)
{
PrefixNode = PrefixNode->Parent;
}
}
}
 
/* Save type. TBD: may be no longer necessary */
 
TypeToCheckFor = Type;
 
/*
* Begin examination of the actual pathname
*/
if (!Pathname)
{
/* A Null NamePath is allowed and refers to the root */
 
NumSegments = 0;
ThisNode = AcpiGbl_RootNode;
Path = "";
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Null Pathname (Zero segments), Flags=%X\n", Flags));
}
else
{
/*
* Name pointer is valid (and must be in internal name format)
*
* Check for scope prefixes:
*
* As represented in the AML stream, a namepath consists of an
* optional scope prefix followed by a name segment part.
*
* If present, the scope prefix is either a Root Prefix (in
* which case the name is fully qualified), or one or more
* Parent Prefixes (in which case the name's scope is relative
* to the current scope).
*/
if (*Path == (UINT8) AML_ROOT_PREFIX)
{
/* Pathname is fully qualified, start from the root */
 
ThisNode = AcpiGbl_RootNode;
SearchParentFlag = ACPI_NS_NO_UPSEARCH;
 
/* Point to name segment part */
 
Path++;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Path is absolute from root [%p]\n", ThisNode));
}
else
{
/* Pathname is relative to current scope, start there */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Searching relative to prefix scope [%4.4s] (%p)\n",
AcpiUtGetNodeName (PrefixNode), PrefixNode));
 
/*
* Handle multiple Parent Prefixes (carat) by just getting
* the parent node for each prefix instance.
*/
ThisNode = PrefixNode;
NumCarats = 0;
while (*Path == (UINT8) AML_PARENT_PREFIX)
{
/* Name is fully qualified, no search rules apply */
 
SearchParentFlag = ACPI_NS_NO_UPSEARCH;
 
/*
* Point past this prefix to the name segment
* part or the next Parent Prefix
*/
Path++;
 
/* Backup to the parent node */
 
NumCarats++;
ThisNode = ThisNode->Parent;
if (!ThisNode)
{
/* Current scope has no parent scope */
 
ACPI_ERROR ((AE_INFO,
"ACPI path has too many parent prefixes (^) "
"- reached beyond root node"));
return_ACPI_STATUS (AE_NOT_FOUND);
}
}
 
if (SearchParentFlag == ACPI_NS_NO_UPSEARCH)
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Search scope is [%4.4s], path has %u carat(s)\n",
AcpiUtGetNodeName (ThisNode), NumCarats));
}
}
 
/*
* Determine the number of ACPI name segments in this pathname.
*
* The segment part consists of either:
* - A Null name segment (0)
* - A DualNamePrefix followed by two 4-byte name segments
* - A MultiNamePrefix followed by a byte indicating the
* number of segments and the segments themselves.
* - A single 4-byte name segment
*
* Examine the name prefix opcode, if any, to determine the number of
* segments.
*/
switch (*Path)
{
case 0:
/*
* Null name after a root or parent prefixes. We already
* have the correct target node and there are no name segments.
*/
NumSegments = 0;
Type = ThisNode->Type;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Prefix-only Pathname (Zero name segments), Flags=%X\n",
Flags));
break;
 
case AML_DUAL_NAME_PREFIX:
 
/* More than one NameSeg, search rules do not apply */
 
SearchParentFlag = ACPI_NS_NO_UPSEARCH;
 
/* Two segments, point to first name segment */
 
NumSegments = 2;
Path++;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Dual Pathname (2 segments, Flags=%X)\n", Flags));
break;
 
case AML_MULTI_NAME_PREFIX_OP:
 
/* More than one NameSeg, search rules do not apply */
 
SearchParentFlag = ACPI_NS_NO_UPSEARCH;
 
/* Extract segment count, point to first name segment */
 
Path++;
NumSegments = (UINT32) (UINT8) *Path;
Path++;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Multi Pathname (%u Segments, Flags=%X)\n",
NumSegments, Flags));
break;
 
default:
/*
* Not a Null name, no Dual or Multi prefix, hence there is
* only one name segment and Pathname is already pointing to it.
*/
NumSegments = 1;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Simple Pathname (1 segment, Flags=%X)\n", Flags));
break;
}
 
ACPI_DEBUG_EXEC (AcpiNsPrintPathname (NumSegments, Path));
}
 
 
/*
* Search namespace for each segment of the name. Loop through and
* verify (or add to the namespace) each name segment.
*
* The object type is significant only at the last name
* segment. (We don't care about the types along the path, only
* the type of the final target object.)
*/
ThisSearchType = ACPI_TYPE_ANY;
CurrentNode = ThisNode;
while (NumSegments && CurrentNode)
{
NumSegments--;
if (!NumSegments)
{
/* This is the last segment, enable typechecking */
 
ThisSearchType = Type;
 
/*
* Only allow automatic parent search (search rules) if the caller
* requested it AND we have a single, non-fully-qualified NameSeg
*/
if ((SearchParentFlag != ACPI_NS_NO_UPSEARCH) &&
(Flags & ACPI_NS_SEARCH_PARENT))
{
LocalFlags |= ACPI_NS_SEARCH_PARENT;
}
 
/* Set error flag according to caller */
 
if (Flags & ACPI_NS_ERROR_IF_FOUND)
{
LocalFlags |= ACPI_NS_ERROR_IF_FOUND;
}
}
 
/* Extract one ACPI name from the front of the pathname */
 
ACPI_MOVE_32_TO_32 (&SimpleName, Path);
 
/* Try to find the single (4 character) ACPI name */
 
Status = AcpiNsSearchAndEnter (SimpleName, WalkState, CurrentNode,
InterpreterMode, ThisSearchType, LocalFlags, &ThisNode);
if (ACPI_FAILURE (Status))
{
if (Status == AE_NOT_FOUND)
{
/* Name not found in ACPI namespace */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Name [%4.4s] not found in scope [%4.4s] %p\n",
(char *) &SimpleName, (char *) &CurrentNode->Name,
CurrentNode));
}
 
*ReturnNode = ThisNode;
return_ACPI_STATUS (Status);
}
 
/* More segments to follow? */
 
if (NumSegments > 0)
{
/*
* If we have an alias to an object that opens a scope (such as a
* device or processor), we need to dereference the alias here so
* that we can access any children of the original node (via the
* remaining segments).
*/
if (ThisNode->Type == ACPI_TYPE_LOCAL_ALIAS)
{
if (!ThisNode->Object)
{
return_ACPI_STATUS (AE_NOT_EXIST);
}
 
if (AcpiNsOpensScope (((ACPI_NAMESPACE_NODE *)
ThisNode->Object)->Type))
{
ThisNode = (ACPI_NAMESPACE_NODE *) ThisNode->Object;
}
}
}
 
/* Special handling for the last segment (NumSegments == 0) */
 
else
{
/*
* Sanity typecheck of the target object:
*
* If 1) This is the last segment (NumSegments == 0)
* 2) And we are looking for a specific type
* (Not checking for TYPE_ANY)
* 3) Which is not an alias
* 4) Which is not a local type (TYPE_SCOPE)
* 5) And the type of target object is known (not TYPE_ANY)
* 6) And target object does not match what we are looking for
*
* Then we have a type mismatch. Just warn and ignore it.
*/
if ((TypeToCheckFor != ACPI_TYPE_ANY) &&
(TypeToCheckFor != ACPI_TYPE_LOCAL_ALIAS) &&
(TypeToCheckFor != ACPI_TYPE_LOCAL_METHOD_ALIAS) &&
(TypeToCheckFor != ACPI_TYPE_LOCAL_SCOPE) &&
(ThisNode->Type != ACPI_TYPE_ANY) &&
(ThisNode->Type != TypeToCheckFor))
{
/* Complain about a type mismatch */
 
ACPI_WARNING ((AE_INFO,
"NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
ACPI_CAST_PTR (char, &SimpleName),
AcpiUtGetTypeName (ThisNode->Type),
AcpiUtGetTypeName (TypeToCheckFor)));
}
 
/*
* If this is the last name segment and we are not looking for a
* specific type, but the type of found object is known, use that
* type to (later) see if it opens a scope.
*/
if (Type == ACPI_TYPE_ANY)
{
Type = ThisNode->Type;
}
}
 
/* Point to next name segment and make this node current */
 
Path += ACPI_NAME_SIZE;
CurrentNode = ThisNode;
}
 
/* Always check if we need to open a new scope */
 
if (!(Flags & ACPI_NS_DONT_OPEN_SCOPE) && (WalkState))
{
/*
* If entry is a type which opens a scope, push the new scope on the
* scope stack.
*/
if (AcpiNsOpensScope (Type))
{
Status = AcpiDsScopeStackPush (ThisNode, Type, WalkState);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
}
}
 
*ReturnNode = ThisNode;
return_ACPI_STATUS (AE_OK);
}
 
/drivers/devman/acpica/namespace/nsalloc.c
0,0 → 1,650
/*******************************************************************************
*
* Module Name: nsalloc - Namespace allocation and deletion utilities
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSALLOC_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsalloc")
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCreateNode
*
* PARAMETERS: Name - Name of the new node (4 char ACPI name)
*
* RETURN: New namespace node (Null on failure)
*
* DESCRIPTION: Create a namespace node
*
******************************************************************************/
 
ACPI_NAMESPACE_NODE *
AcpiNsCreateNode (
UINT32 Name)
{
ACPI_NAMESPACE_NODE *Node;
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
UINT32 Temp;
#endif
 
 
ACPI_FUNCTION_TRACE (NsCreateNode);
 
 
Node = AcpiOsAcquireObject (AcpiGbl_NamespaceCache);
if (!Node)
{
return_PTR (NULL);
}
 
ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalAllocated++);
 
#ifdef ACPI_DBG_TRACK_ALLOCATIONS
Temp = AcpiGbl_NsNodeList->TotalAllocated -
AcpiGbl_NsNodeList->TotalFreed;
if (Temp > AcpiGbl_NsNodeList->MaxOccupied)
{
AcpiGbl_NsNodeList->MaxOccupied = Temp;
}
#endif
 
Node->Name.Integer = Name;
ACPI_SET_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED);
return_PTR (Node);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDeleteNode
*
* PARAMETERS: Node - Node to be deleted
*
* RETURN: None
*
* DESCRIPTION: Delete a namespace node. All node deletions must come through
* here. Detaches any attached objects, including any attached
* data. If a handler is associated with attached data, it is
* invoked before the node is deleted.
*
******************************************************************************/
 
void
AcpiNsDeleteNode (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_OPERAND_OBJECT *ObjDesc;
 
 
ACPI_FUNCTION_NAME (NsDeleteNode);
 
 
/* Detach an object if there is one */
 
AcpiNsDetachObject (Node);
 
/*
* Delete an attached data object if present (an object that was created
* and attached via AcpiAttachData). Note: After any normal object is
* detached above, the only possible remaining object is a data object.
*/
ObjDesc = Node->Object;
if (ObjDesc &&
(ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
{
/* Invoke the attached data deletion handler if present */
 
if (ObjDesc->Data.Handler)
{
ObjDesc->Data.Handler (Node, ObjDesc->Data.Pointer);
}
 
AcpiUtRemoveReference (ObjDesc);
}
 
/* Now we can delete the node */
 
(void) AcpiOsReleaseObject (AcpiGbl_NamespaceCache, Node);
 
ACPI_MEM_TRACKING (AcpiGbl_NsNodeList->TotalFreed++);
ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Node %p, Remaining %X\n",
Node, AcpiGbl_CurrentNodeCount));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsRemoveNode
*
* PARAMETERS: Node - Node to be removed/deleted
*
* RETURN: None
*
* DESCRIPTION: Remove (unlink) and delete a namespace node
*
******************************************************************************/
 
void
AcpiNsRemoveNode (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_NAMESPACE_NODE *ParentNode;
ACPI_NAMESPACE_NODE *PrevNode;
ACPI_NAMESPACE_NODE *NextNode;
 
 
ACPI_FUNCTION_TRACE_PTR (NsRemoveNode, Node);
 
 
ParentNode = Node->Parent;
 
PrevNode = NULL;
NextNode = ParentNode->Child;
 
/* Find the node that is the previous peer in the parent's child list */
 
while (NextNode != Node)
{
PrevNode = NextNode;
NextNode = NextNode->Peer;
}
 
if (PrevNode)
{
/* Node is not first child, unlink it */
 
PrevNode->Peer = Node->Peer;
}
else
{
/*
* Node is first child (has no previous peer).
* Link peer list to parent
*/
ParentNode->Child = Node->Peer;
}
 
/* Delete the node and any attached objects */
 
AcpiNsDeleteNode (Node);
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInstallNode
*
* PARAMETERS: WalkState - Current state of the walk
* ParentNode - The parent of the new Node
* Node - The new Node to install
* Type - ACPI object type of the new Node
*
* RETURN: None
*
* DESCRIPTION: Initialize a new namespace node and install it amongst
* its peers.
*
* Note: Current namespace lookup is linear search. This appears
* to be sufficient as namespace searches consume only a small
* fraction of the execution time of the ACPI subsystem.
*
******************************************************************************/
 
void
AcpiNsInstallNode (
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE *ParentNode, /* Parent */
ACPI_NAMESPACE_NODE *Node, /* New Child*/
ACPI_OBJECT_TYPE Type)
{
ACPI_OWNER_ID OwnerId = 0;
ACPI_NAMESPACE_NODE *ChildNode;
 
 
ACPI_FUNCTION_TRACE (NsInstallNode);
 
 
if (WalkState)
{
/*
* Get the owner ID from the Walk state. The owner ID is used to
* track table deletion and deletion of objects created by methods.
*/
OwnerId = WalkState->OwnerId;
 
if ((WalkState->MethodDesc) &&
(ParentNode != WalkState->MethodNode))
{
/*
* A method is creating a new node that is not a child of the
* method (it is non-local). Mark the executing method as having
* modified the namespace. This is used for cleanup when the
* method exits.
*/
WalkState->MethodDesc->Method.Flags |= AOPOBJ_MODIFIED_NAMESPACE;
}
}
 
/* Link the new entry into the parent and existing children */
 
Node->Peer = NULL;
Node->Parent = ParentNode;
ChildNode = ParentNode->Child;
 
if (!ChildNode)
{
ParentNode->Child = Node;
}
else
{
/* Add node to the end of the peer list */
 
while (ChildNode->Peer)
{
ChildNode = ChildNode->Peer;
}
 
ChildNode->Peer = Node;
}
 
/* Init the new entry */
 
Node->OwnerId = OwnerId;
Node->Type = (UINT8) Type;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"%4.4s (%s) [Node %p Owner %X] added to %4.4s (%s) [Node %p]\n",
AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type), Node, OwnerId,
AcpiUtGetNodeName (ParentNode), AcpiUtGetTypeName (ParentNode->Type),
ParentNode));
 
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDeleteChildren
*
* PARAMETERS: ParentNode - Delete this objects children
*
* RETURN: None.
*
* DESCRIPTION: Delete all children of the parent object. In other words,
* deletes a "scope".
*
******************************************************************************/
 
void
AcpiNsDeleteChildren (
ACPI_NAMESPACE_NODE *ParentNode)
{
ACPI_NAMESPACE_NODE *NextNode;
ACPI_NAMESPACE_NODE *NodeToDelete;
 
 
ACPI_FUNCTION_TRACE_PTR (NsDeleteChildren, ParentNode);
 
 
if (!ParentNode)
{
return_VOID;
}
 
/* Deallocate all children at this level */
 
NextNode = ParentNode->Child;
while (NextNode)
{
/* Grandchildren should have all been deleted already */
 
if (NextNode->Child)
{
ACPI_ERROR ((AE_INFO, "Found a grandchild! P=%p C=%p",
ParentNode, NextNode));
}
 
/*
* Delete this child node and move on to the next child in the list.
* No need to unlink the node since we are deleting the entire branch.
*/
NodeToDelete = NextNode;
NextNode = NextNode->Peer;
AcpiNsDeleteNode (NodeToDelete);
};
 
/* Clear the parent's child pointer */
 
ParentNode->Child = NULL;
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDeleteNamespaceSubtree
*
* PARAMETERS: ParentNode - Root of the subtree to be deleted
*
* RETURN: None.
*
* DESCRIPTION: Delete a subtree of the namespace. This includes all objects
* stored within the subtree.
*
******************************************************************************/
 
void
AcpiNsDeleteNamespaceSubtree (
ACPI_NAMESPACE_NODE *ParentNode)
{
ACPI_NAMESPACE_NODE *ChildNode = NULL;
UINT32 Level = 1;
 
 
ACPI_FUNCTION_TRACE (NsDeleteNamespaceSubtree);
 
 
if (!ParentNode)
{
return_VOID;
}
 
/*
* Traverse the tree of objects until we bubble back up
* to where we started.
*/
while (Level > 0)
{
/* Get the next node in this scope (NULL if none) */
 
ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
if (ChildNode)
{
/* Found a child node - detach any attached object */
 
AcpiNsDetachObject (ChildNode);
 
/* Check if this node has any children */
 
if (ChildNode->Child)
{
/*
* There is at least one child of this node,
* visit the node
*/
Level++;
ParentNode = ChildNode;
ChildNode = NULL;
}
}
else
{
/*
* No more children of this parent node.
* Move up to the grandparent.
*/
Level--;
 
/*
* Now delete all of the children of this parent
* all at the same time.
*/
AcpiNsDeleteChildren (ParentNode);
 
/* New "last child" is this parent node */
 
ChildNode = ParentNode;
 
/* Move up the tree to the grandparent */
 
ParentNode = ParentNode->Parent;
}
}
 
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDeleteNamespaceByOwner
*
* PARAMETERS: OwnerId - All nodes with this owner will be deleted
*
* RETURN: Status
*
* DESCRIPTION: Delete entries within the namespace that are owned by a
* specific ID. Used to delete entire ACPI tables. All
* reference counts are updated.
*
* MUTEX: Locks namespace during deletion walk.
*
******************************************************************************/
 
void
AcpiNsDeleteNamespaceByOwner (
ACPI_OWNER_ID OwnerId)
{
ACPI_NAMESPACE_NODE *ChildNode;
ACPI_NAMESPACE_NODE *DeletionNode;
ACPI_NAMESPACE_NODE *ParentNode;
UINT32 Level;
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE_U32 (NsDeleteNamespaceByOwner, OwnerId);
 
 
if (OwnerId == 0)
{
return_VOID;
}
 
/* Lock namespace for possible update */
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return_VOID;
}
 
DeletionNode = NULL;
ParentNode = AcpiGbl_RootNode;
ChildNode = NULL;
Level = 1;
 
/*
* Traverse the tree of nodes until we bubble back up
* to where we started.
*/
while (Level > 0)
{
/*
* Get the next child of this parent node. When ChildNode is NULL,
* the first child of the parent is returned
*/
ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
 
if (DeletionNode)
{
AcpiNsDeleteChildren (DeletionNode);
AcpiNsRemoveNode (DeletionNode);
DeletionNode = NULL;
}
 
if (ChildNode)
{
if (ChildNode->OwnerId == OwnerId)
{
/* Found a matching child node - detach any attached object */
 
AcpiNsDetachObject (ChildNode);
}
 
/* Check if this node has any children */
 
if (ChildNode->Child)
{
/*
* There is at least one child of this node,
* visit the node
*/
Level++;
ParentNode = ChildNode;
ChildNode = NULL;
}
else if (ChildNode->OwnerId == OwnerId)
{
DeletionNode = ChildNode;
}
}
else
{
/*
* No more children of this parent node.
* Move up to the grandparent.
*/
Level--;
if (Level != 0)
{
if (ParentNode->OwnerId == OwnerId)
{
DeletionNode = ParentNode;
}
}
 
/* New "last child" is this parent node */
 
ChildNode = ParentNode;
 
/* Move up the tree to the grandparent */
 
ParentNode = ParentNode->Parent;
}
}
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return_VOID;
}
 
 
/drivers/devman/acpica/namespace/nsdump.c
0,0 → 1,826
/******************************************************************************
*
* Module Name: nsdump - table dumping routines for debug
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
 
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSDUMP_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsdump")
 
/* Local prototypes */
 
#ifdef ACPI_OBSOLETE_FUNCTIONS
void
AcpiNsDumpRootDevices (
void);
 
static ACPI_STATUS
AcpiNsDumpOneDevice (
ACPI_HANDLE ObjHandle,
UINT32 Level,
void *Context,
void **ReturnValue);
#endif
 
 
#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
/*******************************************************************************
*
* FUNCTION: AcpiNsPrintPathname
*
* PARAMETERS: NumSegments - Number of ACPI name segments
* Pathname - The compressed (internal) path
*
* RETURN: None
*
* DESCRIPTION: Print an object's full namespace pathname
*
******************************************************************************/
 
void
AcpiNsPrintPathname (
UINT32 NumSegments,
char *Pathname)
{
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsPrintPathname);
 
 
if (!(AcpiDbgLevel & ACPI_LV_NAMES) || !(AcpiDbgLayer & ACPI_NAMESPACE))
{
return;
}
 
/* Print the entire name */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
 
while (NumSegments)
{
for (i = 0; i < 4; i++)
{
ACPI_IS_PRINT (Pathname[i]) ?
AcpiOsPrintf ("%c", Pathname[i]) :
AcpiOsPrintf ("?");
}
 
Pathname += ACPI_NAME_SIZE;
NumSegments--;
if (NumSegments)
{
AcpiOsPrintf (".");
}
}
 
AcpiOsPrintf ("]\n");
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpPathname
*
* PARAMETERS: Handle - Object
* Msg - Prefix message
* Level - Desired debug level
* Component - Caller's component ID
*
* RETURN: None
*
* DESCRIPTION: Print an object's full namespace pathname
* Manages allocation/freeing of a pathname buffer
*
******************************************************************************/
 
void
AcpiNsDumpPathname (
ACPI_HANDLE Handle,
char *Msg,
UINT32 Level,
UINT32 Component)
{
 
ACPI_FUNCTION_TRACE (NsDumpPathname);
 
 
/* Do this only if the requested debug level and component are enabled */
 
if (!(AcpiDbgLevel & Level) || !(AcpiDbgLayer & Component))
{
return_VOID;
}
 
/* Convert handle to a full pathname and print it (with supplied message) */
 
AcpiNsPrintNodePathname (Handle, Msg);
AcpiOsPrintf ("\n");
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpOneObject
*
* PARAMETERS: ObjHandle - Node to be dumped
* Level - Nesting level of the handle
* Context - Passed into WalkNamespace
* ReturnValue - Not used
*
* RETURN: Status
*
* DESCRIPTION: Dump a single Node
* This procedure is a UserFunction called by AcpiNsWalkNamespace.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsDumpOneObject (
ACPI_HANDLE ObjHandle,
UINT32 Level,
void *Context,
void **ReturnValue)
{
ACPI_WALK_INFO *Info = (ACPI_WALK_INFO *) Context;
ACPI_NAMESPACE_NODE *ThisNode;
ACPI_OPERAND_OBJECT *ObjDesc = NULL;
ACPI_OBJECT_TYPE ObjType;
ACPI_OBJECT_TYPE Type;
UINT32 BytesToDump;
UINT32 DbgLevel;
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsDumpOneObject);
 
 
/* Is output enabled? */
 
if (!(AcpiDbgLevel & Info->DebugLevel))
{
return (AE_OK);
}
 
if (!ObjHandle)
{
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
return (AE_OK);
}
 
ThisNode = AcpiNsValidateHandle (ObjHandle);
if (!ThisNode)
{
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Invalid object handle %p\n",
ObjHandle));
return (AE_OK);
}
 
Type = ThisNode->Type;
 
/* Check if the owner matches */
 
if ((Info->OwnerId != ACPI_OWNER_ID_MAX) &&
(Info->OwnerId != ThisNode->OwnerId))
{
return (AE_OK);
}
 
if (!(Info->DisplayType & ACPI_DISPLAY_SHORT))
{
/* Indent the object according to the level */
 
AcpiOsPrintf ("%2d%*s", (UINT32) Level - 1, (int) Level * 2, " ");
 
/* Check the node type and name */
 
if (Type > ACPI_TYPE_LOCAL_MAX)
{
ACPI_WARNING ((AE_INFO, "Invalid ACPI Object Type 0x%08X", Type));
}
 
AcpiOsPrintf ("%4.4s", AcpiUtGetNodeName (ThisNode));
}
 
/* Now we can print out the pertinent information */
 
AcpiOsPrintf (" %-12s %p %2.2X ",
AcpiUtGetTypeName (Type), ThisNode, ThisNode->OwnerId);
 
DbgLevel = AcpiDbgLevel;
AcpiDbgLevel = 0;
ObjDesc = AcpiNsGetAttachedObject (ThisNode);
AcpiDbgLevel = DbgLevel;
 
/* Temp nodes are those nodes created by a control method */
 
if (ThisNode->Flags & ANOBJ_TEMPORARY)
{
AcpiOsPrintf ("(T) ");
}
 
switch (Info->DisplayType & ACPI_DISPLAY_MASK)
{
case ACPI_DISPLAY_SUMMARY:
 
if (!ObjDesc)
{
/* No attached object, we are done */
 
AcpiOsPrintf ("\n");
return (AE_OK);
}
 
switch (Type)
{
case ACPI_TYPE_PROCESSOR:
 
AcpiOsPrintf ("ID %X Len %.4X Addr %p\n",
ObjDesc->Processor.ProcId, ObjDesc->Processor.Length,
ACPI_CAST_PTR (void, ObjDesc->Processor.Address));
break;
 
 
case ACPI_TYPE_DEVICE:
 
AcpiOsPrintf ("Notify Object: %p\n", ObjDesc);
break;
 
 
case ACPI_TYPE_METHOD:
 
AcpiOsPrintf ("Args %X Len %.4X Aml %p\n",
(UINT32) ObjDesc->Method.ParamCount,
ObjDesc->Method.AmlLength, ObjDesc->Method.AmlStart);
break;
 
 
case ACPI_TYPE_INTEGER:
 
AcpiOsPrintf ("= %8.8X%8.8X\n",
ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
break;
 
 
case ACPI_TYPE_PACKAGE:
 
if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
{
AcpiOsPrintf ("Elements %.2X\n",
ObjDesc->Package.Count);
}
else
{
AcpiOsPrintf ("[Length not yet evaluated]\n");
}
break;
 
 
case ACPI_TYPE_BUFFER:
 
if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
{
AcpiOsPrintf ("Len %.2X",
ObjDesc->Buffer.Length);
 
/* Dump some of the buffer */
 
if (ObjDesc->Buffer.Length > 0)
{
AcpiOsPrintf (" =");
for (i = 0; (i < ObjDesc->Buffer.Length && i < 12); i++)
{
AcpiOsPrintf (" %.2hX", ObjDesc->Buffer.Pointer[i]);
}
}
AcpiOsPrintf ("\n");
}
else
{
AcpiOsPrintf ("[Length not yet evaluated]\n");
}
break;
 
 
case ACPI_TYPE_STRING:
 
AcpiOsPrintf ("Len %.2X ", ObjDesc->String.Length);
AcpiUtPrintString (ObjDesc->String.Pointer, 32);
AcpiOsPrintf ("\n");
break;
 
 
case ACPI_TYPE_REGION:
 
AcpiOsPrintf ("[%s]",
AcpiUtGetRegionName (ObjDesc->Region.SpaceId));
if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
{
AcpiOsPrintf (" Addr %8.8X%8.8X Len %.4X\n",
ACPI_FORMAT_NATIVE_UINT (ObjDesc->Region.Address),
ObjDesc->Region.Length);
}
else
{
AcpiOsPrintf (" [Address/Length not yet evaluated]\n");
}
break;
 
 
case ACPI_TYPE_LOCAL_REFERENCE:
 
AcpiOsPrintf ("[%s]\n", AcpiUtGetReferenceName (ObjDesc));
break;
 
 
case ACPI_TYPE_BUFFER_FIELD:
 
if (ObjDesc->BufferField.BufferObj &&
ObjDesc->BufferField.BufferObj->Buffer.Node)
{
AcpiOsPrintf ("Buf [%4.4s]",
AcpiUtGetNodeName (
ObjDesc->BufferField.BufferObj->Buffer.Node));
}
break;
 
 
case ACPI_TYPE_LOCAL_REGION_FIELD:
 
AcpiOsPrintf ("Rgn [%4.4s]",
AcpiUtGetNodeName (
ObjDesc->CommonField.RegionObj->Region.Node));
break;
 
 
case ACPI_TYPE_LOCAL_BANK_FIELD:
 
AcpiOsPrintf ("Rgn [%4.4s] Bnk [%4.4s]",
AcpiUtGetNodeName (
ObjDesc->CommonField.RegionObj->Region.Node),
AcpiUtGetNodeName (
ObjDesc->BankField.BankObj->CommonField.Node));
break;
 
 
case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
AcpiOsPrintf ("Idx [%4.4s] Dat [%4.4s]",
AcpiUtGetNodeName (
ObjDesc->IndexField.IndexObj->CommonField.Node),
AcpiUtGetNodeName (
ObjDesc->IndexField.DataObj->CommonField.Node));
break;
 
 
case ACPI_TYPE_LOCAL_ALIAS:
case ACPI_TYPE_LOCAL_METHOD_ALIAS:
 
AcpiOsPrintf ("Target %4.4s (%p)\n",
AcpiUtGetNodeName (ObjDesc), ObjDesc);
break;
 
default:
 
AcpiOsPrintf ("Object %p\n", ObjDesc);
break;
}
 
/* Common field handling */
 
switch (Type)
{
case ACPI_TYPE_BUFFER_FIELD:
case ACPI_TYPE_LOCAL_REGION_FIELD:
case ACPI_TYPE_LOCAL_BANK_FIELD:
case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
AcpiOsPrintf (" Off %.3X Len %.2X Acc %.2hd\n",
(ObjDesc->CommonField.BaseByteOffset * 8)
+ ObjDesc->CommonField.StartFieldBitOffset,
ObjDesc->CommonField.BitLength,
ObjDesc->CommonField.AccessByteWidth);
break;
 
default:
break;
}
break;
 
 
case ACPI_DISPLAY_OBJECTS:
 
AcpiOsPrintf ("O:%p", ObjDesc);
if (!ObjDesc)
{
/* No attached object, we are done */
 
AcpiOsPrintf ("\n");
return (AE_OK);
}
 
AcpiOsPrintf ("(R%u)", ObjDesc->Common.ReferenceCount);
 
switch (Type)
{
case ACPI_TYPE_METHOD:
 
/* Name is a Method and its AML offset/length are set */
 
AcpiOsPrintf (" M:%p-%X\n", ObjDesc->Method.AmlStart,
ObjDesc->Method.AmlLength);
break;
 
case ACPI_TYPE_INTEGER:
 
AcpiOsPrintf (" I:%8.8X8.8%X\n",
ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
break;
 
case ACPI_TYPE_STRING:
 
AcpiOsPrintf (" S:%p-%X\n", ObjDesc->String.Pointer,
ObjDesc->String.Length);
break;
 
case ACPI_TYPE_BUFFER:
 
AcpiOsPrintf (" B:%p-%X\n", ObjDesc->Buffer.Pointer,
ObjDesc->Buffer.Length);
break;
 
default:
 
AcpiOsPrintf ("\n");
break;
}
break;
 
 
default:
AcpiOsPrintf ("\n");
break;
}
 
/* If debug turned off, done */
 
if (!(AcpiDbgLevel & ACPI_LV_VALUES))
{
return (AE_OK);
}
 
/* If there is an attached object, display it */
 
DbgLevel = AcpiDbgLevel;
AcpiDbgLevel = 0;
ObjDesc = AcpiNsGetAttachedObject (ThisNode);
AcpiDbgLevel = DbgLevel;
 
/* Dump attached objects */
 
while (ObjDesc)
{
ObjType = ACPI_TYPE_INVALID;
AcpiOsPrintf ("Attached Object %p: ", ObjDesc);
 
/* Decode the type of attached object and dump the contents */
 
switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
{
case ACPI_DESC_TYPE_NAMED:
 
AcpiOsPrintf ("(Ptr to Node)\n");
BytesToDump = sizeof (ACPI_NAMESPACE_NODE);
ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
break;
 
case ACPI_DESC_TYPE_OPERAND:
 
ObjType = ObjDesc->Common.Type;
 
if (ObjType > ACPI_TYPE_LOCAL_MAX)
{
AcpiOsPrintf ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
ObjType);
BytesToDump = 32;
}
else
{
AcpiOsPrintf ("(Pointer to ACPI Object type %.2X [%s])\n",
ObjType, AcpiUtGetTypeName (ObjType));
BytesToDump = sizeof (ACPI_OPERAND_OBJECT);
}
 
ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
break;
 
default:
 
break;
}
 
/* If value is NOT an internal object, we are done */
 
if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
{
goto Cleanup;
}
 
/* Valid object, get the pointer to next level, if any */
 
switch (ObjType)
{
case ACPI_TYPE_BUFFER:
case ACPI_TYPE_STRING:
/*
* NOTE: takes advantage of common fields between string/buffer
*/
BytesToDump = ObjDesc->String.Length;
ObjDesc = (void *) ObjDesc->String.Pointer;
AcpiOsPrintf ( "(Buffer/String pointer %p length %X)\n",
ObjDesc, BytesToDump);
ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
goto Cleanup;
 
case ACPI_TYPE_BUFFER_FIELD:
ObjDesc = (ACPI_OPERAND_OBJECT *) ObjDesc->BufferField.BufferObj;
break;
 
case ACPI_TYPE_PACKAGE:
ObjDesc = (void *) ObjDesc->Package.Elements;
break;
 
case ACPI_TYPE_METHOD:
ObjDesc = (void *) ObjDesc->Method.AmlStart;
break;
 
case ACPI_TYPE_LOCAL_REGION_FIELD:
ObjDesc = (void *) ObjDesc->Field.RegionObj;
break;
 
case ACPI_TYPE_LOCAL_BANK_FIELD:
ObjDesc = (void *) ObjDesc->BankField.RegionObj;
break;
 
case ACPI_TYPE_LOCAL_INDEX_FIELD:
ObjDesc = (void *) ObjDesc->IndexField.IndexObj;
break;
 
default:
goto Cleanup;
}
 
ObjType = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
}
 
Cleanup:
AcpiOsPrintf ("\n");
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpObjects
*
* PARAMETERS: Type - Object type to be dumped
* DisplayType - 0 or ACPI_DISPLAY_SUMMARY
* MaxDepth - Maximum depth of dump. Use ACPI_UINT32_MAX
* for an effectively unlimited depth.
* OwnerId - Dump only objects owned by this ID. Use
* ACPI_UINT32_MAX to match all owners.
* StartHandle - Where in namespace to start/end search
*
* RETURN: None
*
* DESCRIPTION: Dump typed objects within the loaded namespace. Uses
* AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObject.
*
******************************************************************************/
 
void
AcpiNsDumpObjects (
ACPI_OBJECT_TYPE Type,
UINT8 DisplayType,
UINT32 MaxDepth,
ACPI_OWNER_ID OwnerId,
ACPI_HANDLE StartHandle)
{
ACPI_WALK_INFO Info;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
Info.DebugLevel = ACPI_LV_TABLES;
Info.OwnerId = OwnerId;
Info.DisplayType = DisplayType;
 
(void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpEntry
*
* PARAMETERS: Handle - Node to be dumped
* DebugLevel - Output level
*
* RETURN: None
*
* DESCRIPTION: Dump a single Node
*
******************************************************************************/
 
void
AcpiNsDumpEntry (
ACPI_HANDLE Handle,
UINT32 DebugLevel)
{
ACPI_WALK_INFO Info;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
Info.DebugLevel = DebugLevel;
Info.OwnerId = ACPI_OWNER_ID_MAX;
Info.DisplayType = ACPI_DISPLAY_SUMMARY;
 
(void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
}
 
 
#ifdef ACPI_ASL_COMPILER
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpTables
*
* PARAMETERS: SearchBase - Root of subtree to be dumped, or
* NS_ALL to dump the entire namespace
* MaxDepth - Maximum depth of dump. Use INT_MAX
* for an effectively unlimited depth.
*
* RETURN: None
*
* DESCRIPTION: Dump the name space, or a portion of it.
*
******************************************************************************/
 
void
AcpiNsDumpTables (
ACPI_HANDLE SearchBase,
UINT32 MaxDepth)
{
ACPI_HANDLE SearchHandle = SearchBase;
 
 
ACPI_FUNCTION_TRACE (NsDumpTables);
 
 
if (!AcpiGbl_RootNode)
{
/*
* If the name space has not been initialized,
* there is nothing to dump.
*/
ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "namespace not initialized!\n"));
return_VOID;
}
 
if (ACPI_NS_ALL == SearchBase)
{
/* Entire namespace */
 
SearchHandle = AcpiGbl_RootNode;
ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
}
 
AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
ACPI_OWNER_ID_MAX, SearchHandle);
return_VOID;
}
#endif
#endif
 
/drivers/devman/acpica/namespace/nsdumpdv.c
0,0 → 1,234
/******************************************************************************
*
* Module Name: nsdump - table dumping routines for debug
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
 
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSDUMPDV_C__
 
#include "acpi.h"
 
 
/* TBD: This entire module is apparently obsolete and should be removed */
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsdumpdv")
 
#ifdef ACPI_OBSOLETE_FUNCTIONS
#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
 
#include "acnamesp.h"
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpOneDevice
*
* PARAMETERS: Handle - Node to be dumped
* Level - Nesting level of the handle
* Context - Passed into WalkNamespace
* ReturnValue - Not used
*
* RETURN: Status
*
* DESCRIPTION: Dump a single Node that represents a device
* This procedure is a UserFunction called by AcpiNsWalkNamespace.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsDumpOneDevice (
ACPI_HANDLE ObjHandle,
UINT32 Level,
void *Context,
void **ReturnValue)
{
ACPI_BUFFER Buffer;
ACPI_DEVICE_INFO *Info;
ACPI_STATUS Status;
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsDumpOneDevice);
 
 
Status = AcpiNsDumpOneObject (ObjHandle, Level, Context, ReturnValue);
 
Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
Status = AcpiGetObjectInfo (ObjHandle, &Buffer);
if (ACPI_SUCCESS (Status))
{
Info = Buffer.Pointer;
for (i = 0; i < Level; i++)
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_TABLES, " "));
}
 
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_TABLES,
" HID: %s, ADR: %8.8X%8.8X, Status: %X\n",
Info->HardwareId.Value, ACPI_FORMAT_UINT64 (Info->Address),
Info->CurrentStatus));
ACPI_FREE (Info);
}
 
return (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDumpRootDevices
*
* PARAMETERS: None
*
* RETURN: None
*
* DESCRIPTION: Dump all objects of type "device"
*
******************************************************************************/
 
void
AcpiNsDumpRootDevices (
void)
{
ACPI_HANDLE SysBusHandle;
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_NAME (NsDumpRootDevices);
 
 
/* Only dump the table if tracing is enabled */
 
if (!(ACPI_LV_TABLES & AcpiDbgLevel))
{
return;
}
 
Status = AcpiGetHandle (NULL, ACPI_NS_SYSTEM_BUS, &SysBusHandle);
if (ACPI_FAILURE (Status))
{
return;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
"Display of all devices in the namespace:\n"));
 
Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, SysBusHandle,
ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
AcpiNsDumpOneDevice, NULL, NULL, NULL);
}
 
#endif
#endif
 
 
/drivers/devman/acpica/namespace/nseval.c
0,0 → 1,558
/*******************************************************************************
*
* Module Name: nseval - Object evaluation, includes control method execution
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
 
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSEVAL_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acparser.h"
#include "acinterp.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nseval")
 
/* Local prototypes */
 
static void
AcpiNsExecModuleCode (
ACPI_OPERAND_OBJECT *MethodObj,
ACPI_EVALUATE_INFO *Info);
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsEvaluate
*
* PARAMETERS: Info - Evaluation info block, contains:
* PrefixNode - Prefix or Method/Object Node to execute
* Pathname - Name of method to execute, If NULL, the
* Node is the object to execute
* Parameters - List of parameters to pass to the method,
* terminated by NULL. Params itself may be
* NULL if no parameters are being passed.
* ReturnObject - Where to put method's return value (if
* any). If NULL, no value is returned.
* ParameterType - Type of Parameter list
* ReturnObject - Where to put method's return value (if
* any). If NULL, no value is returned.
* Flags - ACPI_IGNORE_RETURN_VALUE to delete return
*
* RETURN: Status
*
* DESCRIPTION: Execute a control method or return the current value of an
* ACPI namespace object.
*
* MUTEX: Locks interpreter
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsEvaluate (
ACPI_EVALUATE_INFO *Info)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
 
 
ACPI_FUNCTION_TRACE (NsEvaluate);
 
 
if (!Info)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Initialize the return value to an invalid object */
 
Info->ReturnObject = NULL;
Info->ParamCount = 0;
 
/*
* Get the actual namespace node for the target object. Handles these cases:
*
* 1) Null node, Pathname (absolute path)
* 2) Node, Pathname (path relative to Node)
* 3) Node, Null Pathname
*/
Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname,
ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/*
* For a method alias, we must grab the actual method node so that proper
* scoping context will be established before execution.
*/
if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
{
Info->ResolvedNode =
ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object);
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname,
Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode)));
 
Node = Info->ResolvedNode;
 
/*
* Two major cases here:
*
* 1) The object is a control method -- execute it
* 2) The object is not a method -- just return it's current value
*/
if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD)
{
/*
* 1) Object is a control method - execute it
*/
 
/* Verify that there is a method object associated with this node */
 
Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode);
if (!Info->ObjDesc)
{
ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object"));
return_ACPI_STATUS (AE_NULL_OBJECT);
}
 
/* Count the number of arguments being passed to the method */
 
if (Info->Parameters)
{
while (Info->Parameters[Info->ParamCount])
{
if (Info->ParamCount > ACPI_METHOD_MAX_ARG)
{
return_ACPI_STATUS (AE_LIMIT);
}
Info->ParamCount++;
}
}
 
ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method",
ACPI_LV_INFO, _COMPONENT);
 
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
"Method at AML address %p Length %X\n",
Info->ObjDesc->Method.AmlStart + 1,
Info->ObjDesc->Method.AmlLength - 1));
 
/*
* Any namespace deletion must acquire both the namespace and
* interpreter locks to ensure that no thread is using the portion of
* the namespace that is being deleted.
*
* Execute the method via the interpreter. The interpreter is locked
* here before calling into the AML parser
*/
AcpiExEnterInterpreter ();
Status = AcpiPsExecuteMethod (Info);
AcpiExExitInterpreter ();
}
else
{
/*
* 2) Object is not a method, return its current value
*
* Disallow certain object types. For these, "evaluation" is undefined.
*/
switch (Info->ResolvedNode->Type)
{
case ACPI_TYPE_DEVICE:
case ACPI_TYPE_EVENT:
case ACPI_TYPE_MUTEX:
case ACPI_TYPE_REGION:
case ACPI_TYPE_THERMAL:
case ACPI_TYPE_LOCAL_SCOPE:
 
ACPI_ERROR ((AE_INFO,
"[%4.4s] Evaluation of object type [%s] is not supported",
Info->ResolvedNode->Name.Ascii,
AcpiUtGetTypeName (Info->ResolvedNode->Type)));
 
return_ACPI_STATUS (AE_TYPE);
 
default:
break;
}
 
/*
* Objects require additional resolution steps (e.g., the Node may be
* a field that must be read, etc.) -- we can't just grab the object
* out of the node.
*
* Use ResolveNodeToValue() to get the associated value.
*
* NOTE: we can get away with passing in NULL for a walk state because
* ResolvedNode is guaranteed to not be a reference to either a method
* local or a method argument (because this interface is never called
* from a running method.)
*
* Even though we do not directly invoke the interpreter for object
* resolution, we must lock it because we could access an opregion.
* The opregion access code assumes that the interpreter is locked.
*/
AcpiExEnterInterpreter ();
 
/* Function has a strange interface */
 
Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL);
AcpiExExitInterpreter ();
 
/*
* If AcpiExResolveNodeToValue() succeeded, the return value was placed
* in ResolvedNode.
*/
if (ACPI_SUCCESS (Status))
{
Status = AE_CTRL_RETURN_VALUE;
Info->ReturnObject =
ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode);
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
Info->ReturnObject,
AcpiUtGetObjectTypeName (Info->ReturnObject)));
}
}
 
/*
* Check input argument count against the ASL-defined count for a method.
* Also check predefined names: argument count and return value against
* the ACPI specification. Some incorrect return value types are repaired.
*/
(void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount,
Status, &Info->ReturnObject);
 
/* Check if there is a return value that must be dealt with */
 
if (Status == AE_CTRL_RETURN_VALUE)
{
/* If caller does not want the return value, delete it */
 
if (Info->Flags & ACPI_IGNORE_RETURN_VALUE)
{
AcpiUtRemoveReference (Info->ReturnObject);
Info->ReturnObject = NULL;
}
 
/* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
 
Status = AE_OK;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"*** Completed evaluation of object %s ***\n", Info->Pathname));
 
/*
* Namespace was unlocked by the handling AcpiNs* function, so we
* just return
*/
return_ACPI_STATUS (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsExecModuleCodeList
*
* PARAMETERS: None
*
* RETURN: None. Exceptions during method execution are ignored, since
* we cannot abort a table load.
*
* DESCRIPTION: Execute all elements of the global module-level code list.
* Each element is executed as a single control method.
*
******************************************************************************/
 
void
AcpiNsExecModuleCodeList (
void)
{
ACPI_OPERAND_OBJECT *Prev;
ACPI_OPERAND_OBJECT *Next;
ACPI_EVALUATE_INFO *Info;
UINT32 MethodCount = 0;
 
 
ACPI_FUNCTION_TRACE (NsExecModuleCodeList);
 
 
/* Exit now if the list is empty */
 
Next = AcpiGbl_ModuleCodeList;
if (!Next)
{
return_VOID;
}
 
/* Allocate the evaluation information block */
 
Info = ACPI_ALLOCATE (sizeof (ACPI_EVALUATE_INFO));
if (!Info)
{
return_VOID;
}
 
/* Walk the list, executing each "method" */
 
while (Next)
{
Prev = Next;
Next = Next->Method.Mutex;
 
/* Clear the link field and execute the method */
 
Prev->Method.Mutex = NULL;
AcpiNsExecModuleCode (Prev, Info);
MethodCount++;
 
/* Delete the (temporary) method object */
 
AcpiUtRemoveReference (Prev);
}
 
ACPI_INFO ((AE_INFO,
"Executed %u blocks of module-level executable AML code",
MethodCount));
 
ACPI_FREE (Info);
AcpiGbl_ModuleCodeList = NULL;
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsExecModuleCode
*
* PARAMETERS: MethodObj - Object container for the module-level code
* Info - Info block for method evaluation
*
* RETURN: None. Exceptions during method execution are ignored, since
* we cannot abort a table load.
*
* DESCRIPTION: Execute a control method containing a block of module-level
* executable AML code. The control method is temporarily
* installed to the root node, then evaluated.
*
******************************************************************************/
 
static void
AcpiNsExecModuleCode (
ACPI_OPERAND_OBJECT *MethodObj,
ACPI_EVALUATE_INFO *Info)
{
ACPI_OPERAND_OBJECT *ParentObj;
ACPI_NAMESPACE_NODE *ParentNode;
ACPI_OBJECT_TYPE Type;
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (NsExecModuleCode);
 
 
/*
* Get the parent node. We cheat by using the NextObject field
* of the method object descriptor.
*/
ParentNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
MethodObj->Method.NextObject);
Type = AcpiNsGetType (ParentNode);
 
/*
* Get the region handler and save it in the method object. We may need
* this if an operation region declaration causes a _REG method to be run.
*
* We can't do this in AcpiPsLinkModuleCode because
* AcpiGbl_RootNode->Object is NULL at PASS1.
*/
if ((Type == ACPI_TYPE_DEVICE) && ParentNode->Object)
{
MethodObj->Method.Extra.Handler =
ParentNode->Object->Device.Handler;
}
 
/* Must clear NextObject (AcpiNsAttachObject needs the field) */
 
MethodObj->Method.NextObject = NULL;
 
/* Initialize the evaluation information block */
 
ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO));
Info->PrefixNode = ParentNode;
 
/*
* Get the currently attached parent object. Add a reference, because the
* ref count will be decreased when the method object is installed to
* the parent node.
*/
ParentObj = AcpiNsGetAttachedObject (ParentNode);
if (ParentObj)
{
AcpiUtAddReference (ParentObj);
}
 
/* Install the method (module-level code) in the parent node */
 
Status = AcpiNsAttachObject (ParentNode, MethodObj,
ACPI_TYPE_METHOD);
if (ACPI_FAILURE (Status))
{
goto Exit;
}
 
/* Execute the parent node as a control method */
 
Status = AcpiNsEvaluate (Info);
 
ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Executed module-level code at %p\n",
MethodObj->Method.AmlStart));
 
/* Delete a possible implicit return value (in slack mode) */
 
if (Info->ReturnObject)
{
AcpiUtRemoveReference (Info->ReturnObject);
}
 
/* Detach the temporary method object */
 
AcpiNsDetachObject (ParentNode);
 
/* Restore the original parent object */
 
if (ParentObj)
{
Status = AcpiNsAttachObject (ParentNode, ParentObj, Type);
}
else
{
ParentNode->Type = (UINT8) Type;
}
 
Exit:
if (ParentObj)
{
AcpiUtRemoveReference (ParentObj);
}
return_VOID;
}
 
/drivers/devman/acpica/namespace/nsinit.c
0,0 → 1,737
/******************************************************************************
*
* Module Name: nsinit - namespace initialization
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSXFINIT_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acdispat.h"
#include "acinterp.h"
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsinit")
 
/* Local prototypes */
 
static ACPI_STATUS
AcpiNsInitOneObject (
ACPI_HANDLE ObjHandle,
UINT32 Level,
void *Context,
void **ReturnValue);
 
static ACPI_STATUS
AcpiNsInitOneDevice (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue);
 
static ACPI_STATUS
AcpiNsFindIniMethods (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue);
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInitializeObjects
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Walk the entire namespace and perform any necessary
* initialization on the objects found therein
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsInitializeObjects (
void)
{
ACPI_STATUS Status;
ACPI_INIT_WALK_INFO Info;
 
 
ACPI_FUNCTION_TRACE (NsInitializeObjects);
 
 
ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
"**** Starting initialization of namespace objects ****\n"));
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
"Completing Region/Field/Buffer/Package initialization:"));
 
/* Set all init info to zero */
 
ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
 
/* Walk entire namespace from the supplied root */
 
Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL,
&Info, NULL);
if (ACPI_FAILURE (Status))
{
ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
}
 
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
"\nInitialized %u/%u Regions %u/%u Fields %u/%u "
"Buffers %u/%u Packages (%u nodes)\n",
Info.OpRegionInit, Info.OpRegionCount,
Info.FieldInit, Info.FieldCount,
Info.BufferInit, Info.BufferCount,
Info.PackageInit, Info.PackageCount, Info.ObjectCount));
 
ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
"%u Control Methods found\n", Info.MethodCount));
ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
"%u Op Regions found\n", Info.OpRegionCount));
 
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInitializeDevices
*
* PARAMETERS: None
*
* RETURN: ACPI_STATUS
*
* DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
* This means running _INI on all present devices.
*
* Note: We install PCI config space handler on region access,
* not here.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsInitializeDevices (
void)
{
ACPI_STATUS Status;
ACPI_DEVICE_WALK_INFO Info;
 
 
ACPI_FUNCTION_TRACE (NsInitializeDevices);
 
 
/* Init counters */
 
Info.DeviceCount = 0;
Info.Num_STA = 0;
Info.Num_INI = 0;
 
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
"Initializing Device/Processor/Thermal objects "
"by executing _INI methods:"));
 
/* Tree analysis: find all subtrees that contain _INI methods */
 
Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
 
/* Allocate the evaluation information block */
 
Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
if (!Info.EvaluateInfo)
{
Status = AE_NO_MEMORY;
goto ErrorExit;
}
 
/*
* Execute the "global" _INI method that may appear at the root. This
* support is provided for Windows compatibility (Vista+) and is not
* part of the ACPI specification.
*/
Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
Info.EvaluateInfo->Pathname = METHOD_NAME__INI;
Info.EvaluateInfo->Parameters = NULL;
Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
 
Status = AcpiNsEvaluate (Info.EvaluateInfo);
if (ACPI_SUCCESS (Status))
{
Info.Num_INI++;
}
 
/* Walk namespace to execute all _INIs on present devices */
 
Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
 
/*
* Any _OSI requests should be completed by now. If the BIOS has
* requested any Windows OSI strings, we will always truncate
* I/O addresses to 16 bits -- for Windows compatibility.
*/
if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
{
AcpiGbl_TruncateIoAddresses = TRUE;
}
 
ACPI_FREE (Info.EvaluateInfo);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
 
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
"\nExecuted %u _INI methods requiring %u _STA executions "
"(examined %u objects)\n",
Info.Num_INI, Info.Num_STA, Info.DeviceCount));
 
return_ACPI_STATUS (Status);
 
 
ErrorExit:
ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
return_ACPI_STATUS (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInitOneObject
*
* PARAMETERS: ObjHandle - Node
* Level - Current nesting level
* Context - Points to a init info struct
* ReturnValue - Not used
*
* RETURN: Status
*
* DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
* within the namespace.
*
* Currently, the only objects that require initialization are:
* 1) Methods
* 2) Op Regions
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsInitOneObject (
ACPI_HANDLE ObjHandle,
UINT32 Level,
void *Context,
void **ReturnValue)
{
ACPI_OBJECT_TYPE Type;
ACPI_STATUS Status = AE_OK;
ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
ACPI_OPERAND_OBJECT *ObjDesc;
 
 
ACPI_FUNCTION_NAME (NsInitOneObject);
 
 
Info->ObjectCount++;
 
/* And even then, we are only interested in a few object types */
 
Type = AcpiNsGetType (ObjHandle);
ObjDesc = AcpiNsGetAttachedObject (Node);
if (!ObjDesc)
{
return (AE_OK);
}
 
/* Increment counters for object types we are looking for */
 
switch (Type)
{
case ACPI_TYPE_REGION:
Info->OpRegionCount++;
break;
 
case ACPI_TYPE_BUFFER_FIELD:
Info->FieldCount++;
break;
 
case ACPI_TYPE_LOCAL_BANK_FIELD:
Info->FieldCount++;
break;
 
case ACPI_TYPE_BUFFER:
Info->BufferCount++;
break;
 
case ACPI_TYPE_PACKAGE:
Info->PackageCount++;
break;
 
default:
 
/* No init required, just exit now */
return (AE_OK);
}
 
/* If the object is already initialized, nothing else to do */
 
if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
{
return (AE_OK);
}
 
/* Must lock the interpreter before executing AML code */
 
AcpiExEnterInterpreter ();
 
/*
* Each of these types can contain executable AML code within the
* declaration.
*/
switch (Type)
{
case ACPI_TYPE_REGION:
 
Info->OpRegionInit++;
Status = AcpiDsGetRegionArguments (ObjDesc);
break;
 
case ACPI_TYPE_BUFFER_FIELD:
 
Info->FieldInit++;
Status = AcpiDsGetBufferFieldArguments (ObjDesc);
break;
 
case ACPI_TYPE_LOCAL_BANK_FIELD:
 
Info->FieldInit++;
Status = AcpiDsGetBankFieldArguments (ObjDesc);
break;
 
case ACPI_TYPE_BUFFER:
 
Info->BufferInit++;
Status = AcpiDsGetBufferArguments (ObjDesc);
break;
 
case ACPI_TYPE_PACKAGE:
 
Info->PackageInit++;
Status = AcpiDsGetPackageArguments (ObjDesc);
break;
 
default:
/* No other types can get here */
break;
}
 
if (ACPI_FAILURE (Status))
{
ACPI_EXCEPTION ((AE_INFO, Status,
"Could not execute arguments for [%4.4s] (%s)",
AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
}
 
/*
* Print a dot for each object unless we are going to print the entire
* pathname
*/
if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
}
 
/*
* We ignore errors from above, and always return OK, since we don't want
* to abort the walk on any single error.
*/
AcpiExExitInterpreter ();
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsFindIniMethods
*
* PARAMETERS: ACPI_WALK_CALLBACK
*
* RETURN: ACPI_STATUS
*
* DESCRIPTION: Called during namespace walk. Finds objects named _INI under
* device/processor/thermal objects, and marks the entire subtree
* with a SUBTREE_HAS_INI flag. This flag is used during the
* subsequent device initialization walk to avoid entire subtrees
* that do not contain an _INI.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsFindIniMethods (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue)
{
ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
ACPI_NAMESPACE_NODE *Node;
ACPI_NAMESPACE_NODE *ParentNode;
 
 
/* Keep count of device/processor/thermal objects */
 
Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
if ((Node->Type == ACPI_TYPE_DEVICE) ||
(Node->Type == ACPI_TYPE_PROCESSOR) ||
(Node->Type == ACPI_TYPE_THERMAL))
{
Info->DeviceCount++;
return (AE_OK);
}
 
/* We are only looking for methods named _INI */
 
if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
{
return (AE_OK);
}
 
/*
* The only _INI methods that we care about are those that are
* present under Device, Processor, and Thermal objects.
*/
ParentNode = Node->Parent;
switch (ParentNode->Type)
{
case ACPI_TYPE_DEVICE:
case ACPI_TYPE_PROCESSOR:
case ACPI_TYPE_THERMAL:
 
/* Mark parent and bubble up the INI present flag to the root */
 
while (ParentNode)
{
ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
ParentNode = ParentNode->Parent;
}
break;
 
default:
break;
}
 
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInitOneDevice
*
* PARAMETERS: ACPI_WALK_CALLBACK
*
* RETURN: ACPI_STATUS
*
* DESCRIPTION: This is called once per device soon after ACPI is enabled
* to initialize each device. It determines if the device is
* present, and if so, calls _INI.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsInitOneDevice (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue)
{
ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo;
UINT32 Flags;
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *DeviceNode;
 
 
ACPI_FUNCTION_TRACE (NsInitOneDevice);
 
 
/* We are interested in Devices, Processors and ThermalZones only */
 
DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
if ((DeviceNode->Type != ACPI_TYPE_DEVICE) &&
(DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
(DeviceNode->Type != ACPI_TYPE_THERMAL))
{
return_ACPI_STATUS (AE_OK);
}
 
/*
* Because of an earlier namespace analysis, all subtrees that contain an
* _INI method are tagged.
*
* If this device subtree does not contain any _INI methods, we
* can exit now and stop traversing this entire subtree.
*/
if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
{
return_ACPI_STATUS (AE_CTRL_DEPTH);
}
 
/*
* Run _STA to determine if this device is present and functioning. We
* must know this information for two important reasons (from ACPI spec):
*
* 1) We can only run _INI if the device is present.
* 2) We must abort the device tree walk on this subtree if the device is
* not present and is not functional (we will not examine the children)
*
* The _STA method is not required to be present under the device, we
* assume the device is present if _STA does not exist.
*/
ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
 
Status = AcpiUtExecute_STA (DeviceNode, &Flags);
if (ACPI_FAILURE (Status))
{
/* Ignore error and move on to next device */
 
return_ACPI_STATUS (AE_OK);
}
 
/*
* Flags == -1 means that _STA was not found. In this case, we assume that
* the device is both present and functional.
*
* From the ACPI spec, description of _STA:
*
* "If a device object (including the processor object) does not have an
* _STA object, then OSPM assumes that all of the above bits are set (in
* other words, the device is present, ..., and functioning)"
*/
if (Flags != ACPI_UINT32_MAX)
{
WalkInfo->Num_STA++;
}
 
/*
* Examine the PRESENT and FUNCTIONING status bits
*
* Note: ACPI spec does not seem to specify behavior for the present but
* not functioning case, so we assume functioning if present.
*/
if (!(Flags & ACPI_STA_DEVICE_PRESENT))
{
/* Device is not present, we must examine the Functioning bit */
 
if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
{
/*
* Device is not present but is "functioning". In this case,
* we will not run _INI, but we continue to examine the children
* of this device.
*
* From the ACPI spec, description of _STA: (Note - no mention
* of whether to run _INI or not on the device in question)
*
* "_STA may return bit 0 clear (not present) with bit 3 set
* (device is functional). This case is used to indicate a valid
* device for which no device driver should be loaded (for example,
* a bridge device.) Children of this device may be present and
* valid. OSPM should continue enumeration below a device whose
* _STA returns this bit combination"
*/
return_ACPI_STATUS (AE_OK);
}
else
{
/*
* Device is not present and is not functioning. We must abort the
* walk of this subtree immediately -- don't look at the children
* of such a device.
*
* From the ACPI spec, description of _INI:
*
* "If the _STA method indicates that the device is not present,
* OSPM will not run the _INI and will not examine the children
* of the device for _INI methods"
*/
return_ACPI_STATUS (AE_CTRL_DEPTH);
}
}
 
/*
* The device is present or is assumed present if no _STA exists.
* Run the _INI if it exists (not required to exist)
*
* Note: We know there is an _INI within this subtree, but it may not be
* under this particular device, it may be lower in the branch.
*/
ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
 
Info->PrefixNode = DeviceNode;
Info->Pathname = METHOD_NAME__INI;
Info->Parameters = NULL;
Info->Flags = ACPI_IGNORE_RETURN_VALUE;
 
Status = AcpiNsEvaluate (Info);
if (ACPI_SUCCESS (Status))
{
WalkInfo->Num_INI++;
 
if ((AcpiDbgLevel <= ACPI_LV_ALL_EXCEPTIONS) &&
(!(AcpiDbgLevel & ACPI_LV_INFO)))
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
}
}
 
#ifdef ACPI_DEBUG_OUTPUT
else if (Status != AE_NOT_FOUND)
{
/* Ignore error and move on to next device */
 
char *ScopeName = AcpiNsGetExternalPathname (Info->ResolvedNode);
 
ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
ScopeName));
ACPI_FREE (ScopeName);
}
#endif
 
/* Ignore errors from above */
 
Status = AE_OK;
 
/*
* The _INI method has been run if present; call the Global Initialization
* Handler for this device.
*/
if (AcpiGbl_InitHandler)
{
Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
}
 
return_ACPI_STATUS (Status);
}
/drivers/devman/acpica/namespace/nsload.c
0,0 → 1,428
/******************************************************************************
*
* Module Name: nsload - namespace loading/expanding/contracting procedures
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSLOAD_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acdispat.h"
#include "actables.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsload")
 
/* Local prototypes */
 
#ifdef ACPI_FUTURE_IMPLEMENTATION
ACPI_STATUS
AcpiNsUnloadNamespace (
ACPI_HANDLE Handle);
 
static ACPI_STATUS
AcpiNsDeleteSubtree (
ACPI_HANDLE StartHandle);
#endif
 
 
#ifndef ACPI_NO_METHOD_EXECUTION
/*******************************************************************************
*
* FUNCTION: AcpiNsLoadTable
*
* PARAMETERS: TableIndex - Index for table to be loaded
* Node - Owning NS node
*
* RETURN: Status
*
* DESCRIPTION: Load one ACPI table into the namespace
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsLoadTable (
UINT32 TableIndex,
ACPI_NAMESPACE_NODE *Node)
{
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (NsLoadTable);
 
 
/*
* Parse the table and load the namespace with all named
* objects found within. Control methods are NOT parsed
* at this time. In fact, the control methods cannot be
* parsed until the entire namespace is loaded, because
* if a control method makes a forward reference (call)
* to another control method, we can't continue parsing
* because we don't know how many arguments to parse next!
*/
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* If table already loaded into namespace, just return */
 
if (AcpiTbIsTableLoaded (TableIndex))
{
Status = AE_ALREADY_EXISTS;
goto Unlock;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"**** Loading table into namespace ****\n"));
 
Status = AcpiTbAllocateOwnerId (TableIndex);
if (ACPI_FAILURE (Status))
{
goto Unlock;
}
 
Status = AcpiNsParseTable (TableIndex, Node);
if (ACPI_SUCCESS (Status))
{
AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
}
else
{
(void) AcpiTbReleaseOwnerId (TableIndex);
}
 
Unlock:
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/*
* Now we can parse the control methods. We always parse
* them here for a sanity check, and if configured for
* just-in-time parsing, we delete the control method
* parse trees.
*/
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"**** Begin Table Method Parsing and Object Initialization\n"));
 
Status = AcpiDsInitializeObjects (TableIndex, Node);
 
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"**** Completed Table Method Parsing and Object Initialization\n"));
 
return_ACPI_STATUS (Status);
}
 
 
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
*
* FUNCTION: AcpiLoadNamespace
*
* PARAMETERS: None
*
* RETURN: Status
*
* DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
* (DSDT points to either the BIOS or a buffer.)
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsLoadNamespace (
void)
{
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
 
 
/* There must be at least a DSDT installed */
 
if (AcpiGbl_DSDT == NULL)
{
ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
return_ACPI_STATUS (AE_NO_ACPI_TABLES);
}
 
/*
* Load the namespace. The DSDT is required,
* but the SSDT and PSDT tables are optional.
*/
Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Ignore exceptions from these */
 
(void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
(void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
 
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
"ACPI Namespace successfully loaded at root %p\n",
AcpiGbl_RootNode));
 
return_ACPI_STATUS (Status);
}
#endif
 
#ifdef ACPI_FUTURE_IMPLEMENTATION
/*******************************************************************************
*
* FUNCTION: AcpiNsDeleteSubtree
*
* PARAMETERS: StartHandle - Handle in namespace where search begins
*
* RETURNS Status
*
* DESCRIPTION: Walks the namespace starting at the given handle and deletes
* all objects, entries, and scopes in the entire subtree.
*
* Namespace/Interpreter should be locked or the subsystem should
* be in shutdown before this routine is called.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsDeleteSubtree (
ACPI_HANDLE StartHandle)
{
ACPI_STATUS Status;
ACPI_HANDLE ChildHandle;
ACPI_HANDLE ParentHandle;
ACPI_HANDLE NextChildHandle;
ACPI_HANDLE Dummy;
UINT32 Level;
 
 
ACPI_FUNCTION_TRACE (NsDeleteSubtree);
 
 
ParentHandle = StartHandle;
ChildHandle = NULL;
Level = 1;
 
/*
* Traverse the tree of objects until we bubble back up
* to where we started.
*/
while (Level > 0)
{
/* Attempt to get the next object in this scope */
 
Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
ChildHandle, &NextChildHandle);
 
ChildHandle = NextChildHandle;
 
/* Did we get a new object? */
 
if (ACPI_SUCCESS (Status))
{
/* Check if this object has any children */
 
if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
NULL, &Dummy)))
{
/*
* There is at least one child of this object,
* visit the object
*/
Level++;
ParentHandle = ChildHandle;
ChildHandle = NULL;
}
}
else
{
/*
* No more children in this object, go back up to
* the object's parent
*/
Level--;
 
/* Delete all children now */
 
AcpiNsDeleteChildren (ChildHandle);
 
ChildHandle = ParentHandle;
Status = AcpiGetParent (ParentHandle, &ParentHandle);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
}
}
 
/* Now delete the starting object, and we are done */
 
AcpiNsRemoveNode (ChildHandle);
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsUnloadNameSpace
*
* PARAMETERS: Handle - Root of namespace subtree to be deleted
*
* RETURN: Status
*
* DESCRIPTION: Shrinks the namespace, typically in response to an undocking
* event. Deletes an entire subtree starting from (and
* including) the given handle.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsUnloadNamespace (
ACPI_HANDLE Handle)
{
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
 
 
/* Parameter validation */
 
if (!AcpiGbl_RootNode)
{
return_ACPI_STATUS (AE_NO_NAMESPACE);
}
 
if (!Handle)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* This function does the real work */
 
Status = AcpiNsDeleteSubtree (Handle);
 
return_ACPI_STATUS (Status);
}
#endif
#endif
 
/drivers/devman/acpica/namespace/nsnames.c
0,0 → 1,375
/*******************************************************************************
*
* Module Name: nsnames - Name manipulation and search
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSNAMES_C__
 
#include "acpi.h"
#include "accommon.h"
#include "amlcode.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsnames")
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsBuildExternalPath
*
* PARAMETERS: Node - NS node whose pathname is needed
* Size - Size of the pathname
* *NameBuffer - Where to return the pathname
*
* RETURN: Status
* Places the pathname into the NameBuffer, in external format
* (name segments separated by path separators)
*
* DESCRIPTION: Generate a full pathaname
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsBuildExternalPath (
ACPI_NAMESPACE_NODE *Node,
ACPI_SIZE Size,
char *NameBuffer)
{
ACPI_SIZE Index;
ACPI_NAMESPACE_NODE *ParentNode;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
/* Special case for root */
 
Index = Size - 1;
if (Index < ACPI_NAME_SIZE)
{
NameBuffer[0] = AML_ROOT_PREFIX;
NameBuffer[1] = 0;
return (AE_OK);
}
 
/* Store terminator byte, then build name backwards */
 
ParentNode = Node;
NameBuffer[Index] = 0;
 
while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
{
Index -= ACPI_NAME_SIZE;
 
/* Put the name into the buffer */
 
ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
ParentNode = ParentNode->Parent;
 
/* Prefix name with the path separator */
 
Index--;
NameBuffer[Index] = ACPI_PATH_SEPARATOR;
}
 
/* Overwrite final separator with the root prefix character */
 
NameBuffer[Index] = AML_ROOT_PREFIX;
 
if (Index != 0)
{
ACPI_ERROR ((AE_INFO,
"Could not construct external pathname; index=%u, size=%u, Path=%s",
(UINT32) Index, (UINT32) Size, &NameBuffer[Size]));
 
return (AE_BAD_PARAMETER);
}
 
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetExternalPathname
*
* PARAMETERS: Node - Namespace node whose pathname is needed
*
* RETURN: Pointer to storage containing the fully qualified name of
* the node, In external format (name segments separated by path
* separators.)
*
* DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
* for error and debug statements.
*
******************************************************************************/
 
char *
AcpiNsGetExternalPathname (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_STATUS Status;
char *NameBuffer;
ACPI_SIZE Size;
 
 
ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
 
 
/* Calculate required buffer size based on depth below root */
 
Size = AcpiNsGetPathnameLength (Node);
if (!Size)
{
return_PTR (NULL);
}
 
/* Allocate a buffer to be returned to caller */
 
NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
if (!NameBuffer)
{
ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
return_PTR (NULL);
}
 
/* Build the path in the allocated buffer */
 
Status = AcpiNsBuildExternalPath (Node, Size, NameBuffer);
if (ACPI_FAILURE (Status))
{
ACPI_FREE (NameBuffer);
return_PTR (NULL);
}
 
return_PTR (NameBuffer);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetPathnameLength
*
* PARAMETERS: Node - Namespace node
*
* RETURN: Length of path, including prefix
*
* DESCRIPTION: Get the length of the pathname string for this node
*
******************************************************************************/
 
ACPI_SIZE
AcpiNsGetPathnameLength (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_SIZE Size;
ACPI_NAMESPACE_NODE *NextNode;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
/*
* Compute length of pathname as 5 * number of name segments.
* Go back up the parent tree to the root
*/
Size = 0;
NextNode = Node;
 
while (NextNode && (NextNode != AcpiGbl_RootNode))
{
if (ACPI_GET_DESCRIPTOR_TYPE (NextNode) != ACPI_DESC_TYPE_NAMED)
{
ACPI_ERROR ((AE_INFO,
"Invalid Namespace Node (%p) while traversing namespace",
NextNode));
return 0;
}
Size += ACPI_PATH_SEGMENT_LENGTH;
NextNode = NextNode->Parent;
}
 
if (!Size)
{
Size = 1; /* Root node case */
}
 
return (Size + 1); /* +1 for null string terminator */
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsHandleToPathname
*
* PARAMETERS: TargetHandle - Handle of named object whose name is
* to be found
* Buffer - Where the pathname is returned
*
* RETURN: Status, Buffer is filled with pathname if status is AE_OK
*
* DESCRIPTION: Build and return a full namespace pathname
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsHandleToPathname (
ACPI_HANDLE TargetHandle,
ACPI_BUFFER *Buffer)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
ACPI_SIZE RequiredSize;
 
 
ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
 
 
Node = AcpiNsValidateHandle (TargetHandle);
if (!Node)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Determine size required for the caller buffer */
 
RequiredSize = AcpiNsGetPathnameLength (Node);
if (!RequiredSize)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Validate/Allocate/Clear caller buffer */
 
Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Build the path in the caller buffer */
 
Status = AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
(char *) Buffer->Pointer, (UINT32) RequiredSize));
return_ACPI_STATUS (AE_OK);
}
 
 
/drivers/devman/acpica/namespace/nsobject.c
0,0 → 1,577
/*******************************************************************************
*
* Module Name: nsobject - Utilities for objects attached to namespace
* table entries
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSOBJECT_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsobject")
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsAttachObject
*
* PARAMETERS: Node - Parent Node
* Object - Object to be attached
* Type - Type of object, or ACPI_TYPE_ANY if not
* known
*
* RETURN: Status
*
* DESCRIPTION: Record the given object as the value associated with the
* name whose ACPI_HANDLE is passed. If Object is NULL
* and Type is ACPI_TYPE_ANY, set the name as having no value.
* Note: Future may require that the Node->Flags field be passed
* as a parameter.
*
* MUTEX: Assumes namespace is locked
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsAttachObject (
ACPI_NAMESPACE_NODE *Node,
ACPI_OPERAND_OBJECT *Object,
ACPI_OBJECT_TYPE Type)
{
ACPI_OPERAND_OBJECT *ObjDesc;
ACPI_OPERAND_OBJECT *LastObjDesc;
ACPI_OBJECT_TYPE ObjectType = ACPI_TYPE_ANY;
 
 
ACPI_FUNCTION_TRACE (NsAttachObject);
 
 
/*
* Parameter validation
*/
if (!Node)
{
/* Invalid handle */
 
ACPI_ERROR ((AE_INFO, "Null NamedObj handle"));
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
if (!Object && (ACPI_TYPE_ANY != Type))
{
/* Null object */
 
ACPI_ERROR ((AE_INFO,
"Null object, but type not ACPI_TYPE_ANY"));
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
{
/* Not a name handle */
 
ACPI_ERROR ((AE_INFO, "Invalid handle %p [%s]",
Node, AcpiUtGetDescriptorName (Node)));
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Check if this object is already attached */
 
if (Node->Object == Object)
{
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
"Obj %p already installed in NameObj %p\n",
Object, Node));
 
return_ACPI_STATUS (AE_OK);
}
 
/* If null object, we will just install it */
 
if (!Object)
{
ObjDesc = NULL;
ObjectType = ACPI_TYPE_ANY;
}
 
/*
* If the source object is a namespace Node with an attached object,
* we will use that (attached) object
*/
else if ((ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED) &&
((ACPI_NAMESPACE_NODE *) Object)->Object)
{
/*
* Value passed is a name handle and that name has a
* non-null value. Use that name's value and type.
*/
ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;
ObjectType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
}
 
/*
* Otherwise, we will use the parameter object, but we must type
* it first
*/
else
{
ObjDesc = (ACPI_OPERAND_OBJECT *) Object;
 
/* Use the given type */
 
ObjectType = Type;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Installing %p into Node %p [%4.4s]\n",
ObjDesc, Node, AcpiUtGetNodeName (Node)));
 
/* Detach an existing attached object if present */
 
if (Node->Object)
{
AcpiNsDetachObject (Node);
}
 
if (ObjDesc)
{
/*
* Must increment the new value's reference count
* (if it is an internal object)
*/
AcpiUtAddReference (ObjDesc);
 
/*
* Handle objects with multiple descriptors - walk
* to the end of the descriptor list
*/
LastObjDesc = ObjDesc;
while (LastObjDesc->Common.NextObject)
{
LastObjDesc = LastObjDesc->Common.NextObject;
}
 
/* Install the object at the front of the object list */
 
LastObjDesc->Common.NextObject = Node->Object;
}
 
Node->Type = (UINT8) ObjectType;
Node->Object = ObjDesc;
 
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDetachObject
*
* PARAMETERS: Node - A Namespace node whose object will be detached
*
* RETURN: None.
*
* DESCRIPTION: Detach/delete an object associated with a namespace node.
* if the object is an allocated object, it is freed.
* Otherwise, the field is simply cleared.
*
******************************************************************************/
 
void
AcpiNsDetachObject (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_OPERAND_OBJECT *ObjDesc;
 
 
ACPI_FUNCTION_TRACE (NsDetachObject);
 
 
ObjDesc = Node->Object;
 
if (!ObjDesc ||
(ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA))
{
return_VOID;
}
 
if (Node->Flags & ANOBJ_ALLOCATED_BUFFER)
{
/* Free the dynamic aml buffer */
 
if (ObjDesc->Common.Type == ACPI_TYPE_METHOD)
{
ACPI_FREE (ObjDesc->Method.AmlStart);
}
}
 
/* Clear the entry in all cases */
 
Node->Object = NULL;
if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
{
Node->Object = ObjDesc->Common.NextObject;
if (Node->Object &&
((Node->Object)->Common.Type != ACPI_TYPE_LOCAL_DATA))
{
Node->Object = Node->Object->Common.NextObject;
}
}
 
/* Reset the node type to untyped */
 
Node->Type = ACPI_TYPE_ANY;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Node %p [%4.4s] Object %p\n",
Node, AcpiUtGetNodeName (Node), ObjDesc));
 
/* Remove one reference on the object (and all subobjects) */
 
AcpiUtRemoveReference (ObjDesc);
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetAttachedObject
*
* PARAMETERS: Node - Namespace node
*
* RETURN: Current value of the object field from the Node whose
* handle is passed
*
* DESCRIPTION: Obtain the object attached to a namespace node.
*
******************************************************************************/
 
ACPI_OPERAND_OBJECT *
AcpiNsGetAttachedObject (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_FUNCTION_TRACE_PTR (NsGetAttachedObject, Node);
 
 
if (!Node)
{
ACPI_WARNING ((AE_INFO, "Null Node ptr"));
return_PTR (NULL);
}
 
if (!Node->Object ||
((ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_OPERAND) &&
(ACPI_GET_DESCRIPTOR_TYPE (Node->Object) != ACPI_DESC_TYPE_NAMED)) ||
((Node->Object)->Common.Type == ACPI_TYPE_LOCAL_DATA))
{
return_PTR (NULL);
}
 
return_PTR (Node->Object);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetSecondaryObject
*
* PARAMETERS: Node - Namespace node
*
* RETURN: Current value of the object field from the Node whose
* handle is passed.
*
* DESCRIPTION: Obtain a secondary object associated with a namespace node.
*
******************************************************************************/
 
ACPI_OPERAND_OBJECT *
AcpiNsGetSecondaryObject (
ACPI_OPERAND_OBJECT *ObjDesc)
{
ACPI_FUNCTION_TRACE_PTR (NsGetSecondaryObject, ObjDesc);
 
 
if ((!ObjDesc) ||
(ObjDesc->Common.Type== ACPI_TYPE_LOCAL_DATA) ||
(!ObjDesc->Common.NextObject) ||
((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA))
{
return_PTR (NULL);
}
 
return_PTR (ObjDesc->Common.NextObject);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsAttachData
*
* PARAMETERS: Node - Namespace node
* Handler - Handler to be associated with the data
* Data - Data to be attached
*
* RETURN: Status
*
* DESCRIPTION: Low-level attach data. Create and attach a Data object.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsAttachData (
ACPI_NAMESPACE_NODE *Node,
ACPI_OBJECT_HANDLER Handler,
void *Data)
{
ACPI_OPERAND_OBJECT *PrevObjDesc;
ACPI_OPERAND_OBJECT *ObjDesc;
ACPI_OPERAND_OBJECT *DataDesc;
 
 
/* We only allow one attachment per handler */
 
PrevObjDesc = NULL;
ObjDesc = Node->Object;
while (ObjDesc)
{
if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
(ObjDesc->Data.Handler == Handler))
{
return (AE_ALREADY_EXISTS);
}
 
PrevObjDesc = ObjDesc;
ObjDesc = ObjDesc->Common.NextObject;
}
 
/* Create an internal object for the data */
 
DataDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_DATA);
if (!DataDesc)
{
return (AE_NO_MEMORY);
}
 
DataDesc->Data.Handler = Handler;
DataDesc->Data.Pointer = Data;
 
/* Install the data object */
 
if (PrevObjDesc)
{
PrevObjDesc->Common.NextObject = DataDesc;
}
else
{
Node->Object = DataDesc;
}
 
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsDetachData
*
* PARAMETERS: Node - Namespace node
* Handler - Handler associated with the data
*
* RETURN: Status
*
* DESCRIPTION: Low-level detach data. Delete the data node, but the caller
* is responsible for the actual data.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsDetachData (
ACPI_NAMESPACE_NODE *Node,
ACPI_OBJECT_HANDLER Handler)
{
ACPI_OPERAND_OBJECT *ObjDesc;
ACPI_OPERAND_OBJECT *PrevObjDesc;
 
 
PrevObjDesc = NULL;
ObjDesc = Node->Object;
while (ObjDesc)
{
if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
(ObjDesc->Data.Handler == Handler))
{
if (PrevObjDesc)
{
PrevObjDesc->Common.NextObject = ObjDesc->Common.NextObject;
}
else
{
Node->Object = ObjDesc->Common.NextObject;
}
 
AcpiUtRemoveReference (ObjDesc);
return (AE_OK);
}
 
PrevObjDesc = ObjDesc;
ObjDesc = ObjDesc->Common.NextObject;
}
 
return (AE_NOT_FOUND);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetAttachedData
*
* PARAMETERS: Node - Namespace node
* Handler - Handler associated with the data
* Data - Where the data is returned
*
* RETURN: Status
*
* DESCRIPTION: Low level interface to obtain data previously associated with
* a namespace node.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsGetAttachedData (
ACPI_NAMESPACE_NODE *Node,
ACPI_OBJECT_HANDLER Handler,
void **Data)
{
ACPI_OPERAND_OBJECT *ObjDesc;
 
 
ObjDesc = Node->Object;
while (ObjDesc)
{
if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_DATA) &&
(ObjDesc->Data.Handler == Handler))
{
*Data = ObjDesc->Data.Pointer;
return (AE_OK);
}
 
ObjDesc = ObjDesc->Common.NextObject;
}
 
return (AE_NOT_FOUND);
}
 
 
/drivers/devman/acpica/namespace/nsparse.c
0,0 → 1,297
/******************************************************************************
*
* Module Name: nsparse - namespace interface to AML parser
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSPARSE_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acparser.h"
#include "acdispat.h"
#include "actables.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsparse")
 
 
/*******************************************************************************
*
* FUNCTION: NsOneCompleteParse
*
* PARAMETERS: PassNumber - 1 or 2
* TableDesc - The table to be parsed.
*
* RETURN: Status
*
* DESCRIPTION: Perform one complete parse of an ACPI/AML table.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsOneCompleteParse (
UINT32 PassNumber,
UINT32 TableIndex,
ACPI_NAMESPACE_NODE *StartNode)
{
ACPI_PARSE_OBJECT *ParseRoot;
ACPI_STATUS Status;
UINT32 AmlLength;
UINT8 *AmlStart;
ACPI_WALK_STATE *WalkState;
ACPI_TABLE_HEADER *Table;
ACPI_OWNER_ID OwnerId;
 
 
ACPI_FUNCTION_TRACE (NsOneCompleteParse);
 
 
Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Create and init a Root Node */
 
ParseRoot = AcpiPsCreateScopeOp ();
if (!ParseRoot)
{
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
/* Create and initialize a new walk state */
 
WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
if (!WalkState)
{
AcpiPsFreeOp (ParseRoot);
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
Status = AcpiGetTableByIndex (TableIndex, &Table);
if (ACPI_FAILURE (Status))
{
AcpiDsDeleteWalkState (WalkState);
AcpiPsFreeOp (ParseRoot);
return_ACPI_STATUS (Status);
}
 
/* Table must consist of at least a complete header */
 
if (Table->Length < sizeof (ACPI_TABLE_HEADER))
{
Status = AE_BAD_HEADER;
}
else
{
AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
AmlStart, AmlLength, NULL, (UINT8) PassNumber);
}
 
if (ACPI_FAILURE (Status))
{
AcpiDsDeleteWalkState (WalkState);
goto Cleanup;
}
 
/* StartNode is the default location to load the table */
 
if (StartNode && StartNode != AcpiGbl_RootNode)
{
Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
if (ACPI_FAILURE (Status))
{
AcpiDsDeleteWalkState (WalkState);
goto Cleanup;
}
}
 
/* Parse the AML */
 
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber));
Status = AcpiPsParseAml (WalkState);
 
Cleanup:
AcpiPsDeleteParseTree (ParseRoot);
return_ACPI_STATUS (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsParseTable
*
* PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
* StartNode - Where to enter the table into the namespace
*
* RETURN: Status
*
* DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsParseTable (
UINT32 TableIndex,
ACPI_NAMESPACE_NODE *StartNode)
{
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (NsParseTable);
 
 
/*
* AML Parse, pass 1
*
* In this pass, we load most of the namespace. Control methods
* are not parsed until later. A parse tree is not created. Instead,
* each Parser Op subtree is deleted when it is finished. This saves
* a great deal of memory, and allows a small cache of parse objects
* to service the entire parse. The second pass of the parse then
* performs another complete parse of the AML.
*/
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
TableIndex, StartNode);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/*
* AML Parse, pass 2
*
* In this pass, we resolve forward references and other things
* that could not be completed during the first pass.
* Another complete parse of the AML is performed, but the
* overhead of this is compensated for by the fact that the
* parse objects are all cached.
*/
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
TableIndex, StartNode);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
return_ACPI_STATUS (Status);
}
 
 
/drivers/devman/acpica/namespace/nspredef.c
0,0 → 1,1284
/******************************************************************************
*
* Module Name: nspredef - Validation of ACPI predefined methods and objects
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define ACPI_CREATE_PREDEFINED_TABLE
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acpredef.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nspredef")
 
 
/*******************************************************************************
*
* This module validates predefined ACPI objects that appear in the namespace,
* at the time they are evaluated (via AcpiEvaluateObject). The purpose of this
* validation is to detect problems with BIOS-exposed predefined ACPI objects
* before the results are returned to the ACPI-related drivers.
*
* There are several areas that are validated:
*
* 1) The number of input arguments as defined by the method/object in the
* ASL is validated against the ACPI specification.
* 2) The type of the return object (if any) is validated against the ACPI
* specification.
* 3) For returned package objects, the count of package elements is
* validated, as well as the type of each package element. Nested
* packages are supported.
*
* For any problems found, a warning message is issued.
*
******************************************************************************/
 
 
/* Local prototypes */
 
static ACPI_STATUS
AcpiNsCheckPackage (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
static ACPI_STATUS
AcpiNsCheckPackageList (
ACPI_PREDEFINED_DATA *Data,
const ACPI_PREDEFINED_INFO *Package,
ACPI_OPERAND_OBJECT **Elements,
UINT32 Count);
 
static ACPI_STATUS
AcpiNsCheckPackageElements (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **Elements,
UINT8 Type1,
UINT32 Count1,
UINT8 Type2,
UINT32 Count2,
UINT32 StartIndex);
 
static ACPI_STATUS
AcpiNsCheckObjectType (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr,
UINT32 ExpectedBtypes,
UINT32 PackageIndex);
 
static ACPI_STATUS
AcpiNsCheckReference (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT *ReturnObject);
 
static void
AcpiNsGetExpectedTypes (
char *Buffer,
UINT32 ExpectedBtypes);
 
/*
* Names for the types that can be returned by the predefined objects.
* Used for warning messages. Must be in the same order as the ACPI_RTYPEs
*/
static const char *AcpiRtypeNames[] =
{
"/Integer",
"/String",
"/Buffer",
"/Package",
"/Reference",
};
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckPredefinedNames
*
* PARAMETERS: Node - Namespace node for the method/object
* UserParamCount - Number of parameters actually passed
* ReturnStatus - Status from the object evaluation
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status
*
* DESCRIPTION: Check an ACPI name for a match in the predefined name list.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsCheckPredefinedNames (
ACPI_NAMESPACE_NODE *Node,
UINT32 UserParamCount,
ACPI_STATUS ReturnStatus,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status = AE_OK;
const ACPI_PREDEFINED_INFO *Predefined;
char *Pathname;
ACPI_PREDEFINED_DATA *Data;
 
 
/* Match the name for this method/object against the predefined list */
 
Predefined = AcpiNsCheckForPredefinedName (Node);
 
/* Get the full pathname to the object, for use in warning messages */
 
Pathname = AcpiNsGetExternalPathname (Node);
if (!Pathname)
{
return (AE_OK); /* Could not get pathname, ignore */
}
 
/*
* Check that the parameter count for this method matches the ASL
* definition. For predefined names, ensure that both the caller and
* the method itself are in accordance with the ACPI specification.
*/
AcpiNsCheckParameterCount (Pathname, Node, UserParamCount, Predefined);
 
/* If not a predefined name, we cannot validate the return object */
 
if (!Predefined)
{
goto Cleanup;
}
 
/*
* If the method failed or did not actually return an object, we cannot
* validate the return object
*/
if ((ReturnStatus != AE_OK) && (ReturnStatus != AE_CTRL_RETURN_VALUE))
{
goto Cleanup;
}
 
/*
* If there is no return value, check if we require a return value for
* this predefined name. Either one return value is expected, or none,
* for both methods and other objects.
*
* Exit now if there is no return object. Warning if one was expected.
*/
if (!ReturnObject)
{
if ((Predefined->Info.ExpectedBtypes) &&
(!(Predefined->Info.ExpectedBtypes & ACPI_RTYPE_NONE)))
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
"Missing expected return value"));
 
Status = AE_AML_NO_RETURN_VALUE;
}
goto Cleanup;
}
 
/*
* 1) We have a return value, but if one wasn't expected, just exit, this is
* not a problem. For example, if the "Implicit Return" feature is
* enabled, methods will always return a value.
*
* 2) If the return value can be of any type, then we cannot perform any
* validation, exit.
*/
if ((!Predefined->Info.ExpectedBtypes) ||
(Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
{
goto Cleanup;
}
 
/* Create the parameter data block for object validation */
 
Data = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PREDEFINED_DATA));
if (!Data)
{
goto Cleanup;
}
Data->Predefined = Predefined;
Data->NodeFlags = Node->Flags;
Data->Pathname = Pathname;
 
/*
* Check that the type of the main return object is what is expected
* for this predefined name
*/
Status = AcpiNsCheckObjectType (Data, ReturnObjectPtr,
Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
if (ACPI_FAILURE (Status))
{
goto Exit;
}
 
/*
* For returned Package objects, check the type of all sub-objects.
* Note: Package may have been newly created by call above.
*/
if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
{
Data->ParentPackage = *ReturnObjectPtr;
Status = AcpiNsCheckPackage (Data, ReturnObjectPtr);
if (ACPI_FAILURE (Status))
{
goto Exit;
}
}
 
/*
* The return object was OK, or it was successfully repaired above.
* Now make some additional checks such as verifying that package
* objects are sorted correctly (if required) or buffer objects have
* the correct data width (bytes vs. dwords). These repairs are
* performed on a per-name basis, i.e., the code is specific to
* particular predefined names.
*/
Status = AcpiNsComplexRepairs (Data, Node, Status, ReturnObjectPtr);
 
Exit:
/*
* If the object validation failed or if we successfully repaired one
* or more objects, mark the parent node to suppress further warning
* messages during the next evaluation of the same method/object.
*/
if (ACPI_FAILURE (Status) || (Data->Flags & ACPI_OBJECT_REPAIRED))
{
Node->Flags |= ANOBJ_EVALUATED;
}
ACPI_FREE (Data);
 
Cleanup:
ACPI_FREE (Pathname);
return (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckParameterCount
*
* PARAMETERS: Pathname - Full pathname to the node (for error msgs)
* Node - Namespace node for the method/object
* UserParamCount - Number of args passed in by the caller
* Predefined - Pointer to entry in predefined name table
*
* RETURN: None
*
* DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
* predefined name is what is expected (i.e., what is defined in
* the ACPI specification for this predefined name.)
*
******************************************************************************/
 
void
AcpiNsCheckParameterCount (
char *Pathname,
ACPI_NAMESPACE_NODE *Node,
UINT32 UserParamCount,
const ACPI_PREDEFINED_INFO *Predefined)
{
UINT32 ParamCount;
UINT32 RequiredParamsCurrent;
UINT32 RequiredParamsOld;
 
 
/* Methods have 0-7 parameters. All other types have zero. */
 
ParamCount = 0;
if (Node->Type == ACPI_TYPE_METHOD)
{
ParamCount = Node->Object->Method.ParamCount;
}
 
if (!Predefined)
{
/*
* Check the parameter count for non-predefined methods/objects.
*
* Warning if too few or too many arguments have been passed by the
* caller. An incorrect number of arguments may not cause the method
* to fail. However, the method will fail if there are too few
* arguments and the method attempts to use one of the missing ones.
*/
if (UserParamCount < ParamCount)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
"Insufficient arguments - needs %u, found %u",
ParamCount, UserParamCount));
}
else if (UserParamCount > ParamCount)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
"Excess arguments - needs %u, found %u",
ParamCount, UserParamCount));
}
return;
}
 
/*
* Validate the user-supplied parameter count.
* Allow two different legal argument counts (_SCP, etc.)
*/
RequiredParamsCurrent = Predefined->Info.ParamCount & 0x0F;
RequiredParamsOld = Predefined->Info.ParamCount >> 4;
 
if (UserParamCount != ACPI_UINT32_MAX)
{
if ((UserParamCount != RequiredParamsCurrent) &&
(UserParamCount != RequiredParamsOld))
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
"Parameter count mismatch - "
"caller passed %u, ACPI requires %u",
UserParamCount, RequiredParamsCurrent));
}
}
 
/*
* Check that the ASL-defined parameter count is what is expected for
* this predefined name (parameter count as defined by the ACPI
* specification)
*/
if ((ParamCount != RequiredParamsCurrent) &&
(ParamCount != RequiredParamsOld))
{
ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, Node->Flags,
"Parameter count mismatch - ASL declared %u, ACPI requires %u",
ParamCount, RequiredParamsCurrent));
}
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckForPredefinedName
*
* PARAMETERS: Node - Namespace node for the method/object
*
* RETURN: Pointer to entry in predefined table. NULL indicates not found.
*
* DESCRIPTION: Check an object name against the predefined object list.
*
******************************************************************************/
 
const ACPI_PREDEFINED_INFO *
AcpiNsCheckForPredefinedName (
ACPI_NAMESPACE_NODE *Node)
{
const ACPI_PREDEFINED_INFO *ThisName;
 
 
/* Quick check for a predefined name, first character must be underscore */
 
if (Node->Name.Ascii[0] != '_')
{
return (NULL);
}
 
/* Search info table for a predefined method/object name */
 
ThisName = PredefinedNames;
while (ThisName->Info.Name[0])
{
if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Info.Name))
{
return (ThisName);
}
 
/*
* Skip next entry in the table if this name returns a Package
* (next entry contains the package info)
*/
if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
{
ThisName++;
}
 
ThisName++;
}
 
return (NULL); /* Not found */
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckPackage
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status
*
* DESCRIPTION: Check a returned package object for the correct count and
* correct type of all sub-objects.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckPackage (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
const ACPI_PREDEFINED_INFO *Package;
ACPI_OPERAND_OBJECT **Elements;
ACPI_STATUS Status = AE_OK;
UINT32 ExpectedCount;
UINT32 Count;
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsCheckPackage);
 
 
/* The package info for this name is in the next table entry */
 
Package = Data->Predefined + 1;
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"%s Validating return Package of Type %X, Count %X\n",
Data->Pathname, Package->RetInfo.Type, ReturnObject->Package.Count));
 
/*
* For variable-length Packages, we can safely remove all embedded
* and trailing NULL package elements
*/
AcpiNsRemoveNullElements (Data, Package->RetInfo.Type, ReturnObject);
 
/* Extract package count and elements array */
 
Elements = ReturnObject->Package.Elements;
Count = ReturnObject->Package.Count;
 
/* The package must have at least one element, else invalid */
 
if (!Count)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return Package has no elements (empty)"));
 
return (AE_AML_OPERAND_VALUE);
}
 
/*
* Decode the type of the expected package contents
*
* PTYPE1 packages contain no subpackages
* PTYPE2 packages contain sub-packages
*/
switch (Package->RetInfo.Type)
{
case ACPI_PTYPE1_FIXED:
 
/*
* The package count is fixed and there are no sub-packages
*
* If package is too small, exit.
* If package is larger than expected, issue warning but continue
*/
ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
if (Count < ExpectedCount)
{
goto PackageTooSmall;
}
else if (Count > ExpectedCount)
{
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Return Package is larger than needed - "
"found %u, expected %u\n",
Data->Pathname, Count, ExpectedCount));
}
 
/* Validate all elements of the returned package */
 
Status = AcpiNsCheckPackageElements (Data, Elements,
Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
break;
 
 
case ACPI_PTYPE1_VAR:
 
/*
* The package count is variable, there are no sub-packages, and all
* elements must be of the same type
*/
for (i = 0; i < Count; i++)
{
Status = AcpiNsCheckObjectType (Data, Elements,
Package->RetInfo.ObjectType1, i);
if (ACPI_FAILURE (Status))
{
return (Status);
}
Elements++;
}
break;
 
 
case ACPI_PTYPE1_OPTION:
 
/*
* The package count is variable, there are no sub-packages. There are
* a fixed number of required elements, and a variable number of
* optional elements.
*
* Check if package is at least as large as the minimum required
*/
ExpectedCount = Package->RetInfo3.Count;
if (Count < ExpectedCount)
{
goto PackageTooSmall;
}
 
/* Variable number of sub-objects */
 
for (i = 0; i < Count; i++)
{
if (i < Package->RetInfo3.Count)
{
/* These are the required package elements (0, 1, or 2) */
 
Status = AcpiNsCheckObjectType (Data, Elements,
Package->RetInfo3.ObjectType[i], i);
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
else
{
/* These are the optional package elements */
 
Status = AcpiNsCheckObjectType (Data, Elements,
Package->RetInfo3.TailObjectType, i);
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
Elements++;
}
break;
 
 
case ACPI_PTYPE2_REV_FIXED:
 
/* First element is the (Integer) revision */
 
Status = AcpiNsCheckObjectType (Data, Elements,
ACPI_RTYPE_INTEGER, 0);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
Elements++;
Count--;
 
/* Examine the sub-packages */
 
Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
break;
 
 
case ACPI_PTYPE2_PKG_COUNT:
 
/* First element is the (Integer) count of sub-packages to follow */
 
Status = AcpiNsCheckObjectType (Data, Elements,
ACPI_RTYPE_INTEGER, 0);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/*
* Count cannot be larger than the parent package length, but allow it
* to be smaller. The >= accounts for the Integer above.
*/
ExpectedCount = (UINT32) (*Elements)->Integer.Value;
if (ExpectedCount >= Count)
{
goto PackageTooSmall;
}
 
Count = ExpectedCount;
Elements++;
 
/* Examine the sub-packages */
 
Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
break;
 
 
case ACPI_PTYPE2:
case ACPI_PTYPE2_FIXED:
case ACPI_PTYPE2_MIN:
case ACPI_PTYPE2_COUNT:
 
/*
* These types all return a single Package that consists of a
* variable number of sub-Packages.
*
* First, ensure that the first element is a sub-Package. If not,
* the BIOS may have incorrectly returned the object as a single
* package instead of a Package of Packages (a common error if
* there is only one entry). We may be able to repair this by
* wrapping the returned Package with a new outer Package.
*/
if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
{
/* Create the new outer package and populate it */
 
Status = AcpiNsRepairPackageList (Data, ReturnObjectPtr);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Update locals to point to the new package (of 1 element) */
 
ReturnObject = *ReturnObjectPtr;
Elements = ReturnObject->Package.Elements;
Count = 1;
}
 
/* Examine the sub-packages */
 
Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
break;
 
 
default:
 
/* Should not get here if predefined info table is correct */
 
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Invalid internal return type in table entry: %X",
Package->RetInfo.Type));
 
return (AE_AML_INTERNAL);
}
 
return (Status);
 
 
PackageTooSmall:
 
/* Error exit for the case with an incorrect package count */
 
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return Package is too small - found %u elements, expected %u",
Count, ExpectedCount));
 
return (AE_AML_OPERAND_VALUE);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckPackageList
*
* PARAMETERS: Data - Pointer to validation data structure
* Package - Pointer to package-specific info for method
* Elements - Element list of parent package. All elements
* of this list should be of type Package.
* Count - Count of subpackages
*
* RETURN: Status
*
* DESCRIPTION: Examine a list of subpackages
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckPackageList (
ACPI_PREDEFINED_DATA *Data,
const ACPI_PREDEFINED_INFO *Package,
ACPI_OPERAND_OBJECT **Elements,
UINT32 Count)
{
ACPI_OPERAND_OBJECT *SubPackage;
ACPI_OPERAND_OBJECT **SubElements;
ACPI_STATUS Status;
UINT32 ExpectedCount;
UINT32 i;
UINT32 j;
 
 
/*
* Validate each sub-Package in the parent Package
*
* NOTE: assumes list of sub-packages contains no NULL elements.
* Any NULL elements should have been removed by earlier call
* to AcpiNsRemoveNullElements.
*/
for (i = 0; i < Count; i++)
{
SubPackage = *Elements;
SubElements = SubPackage->Package.Elements;
Data->ParentPackage = SubPackage;
 
/* Each sub-object must be of type Package */
 
Status = AcpiNsCheckObjectType (Data, &SubPackage,
ACPI_RTYPE_PACKAGE, i);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Examine the different types of expected sub-packages */
 
Data->ParentPackage = SubPackage;
switch (Package->RetInfo.Type)
{
case ACPI_PTYPE2:
case ACPI_PTYPE2_PKG_COUNT:
case ACPI_PTYPE2_REV_FIXED:
 
/* Each subpackage has a fixed number of elements */
 
ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
if (SubPackage->Package.Count < ExpectedCount)
{
goto PackageTooSmall;
}
 
Status = AcpiNsCheckPackageElements (Data, SubElements,
Package->RetInfo.ObjectType1,
Package->RetInfo.Count1,
Package->RetInfo.ObjectType2,
Package->RetInfo.Count2, 0);
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
 
 
case ACPI_PTYPE2_FIXED:
 
/* Each sub-package has a fixed length */
 
ExpectedCount = Package->RetInfo2.Count;
if (SubPackage->Package.Count < ExpectedCount)
{
goto PackageTooSmall;
}
 
/* Check the type of each sub-package element */
 
for (j = 0; j < ExpectedCount; j++)
{
Status = AcpiNsCheckObjectType (Data, &SubElements[j],
Package->RetInfo2.ObjectType[j], j);
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
break;
 
 
case ACPI_PTYPE2_MIN:
 
/* Each sub-package has a variable but minimum length */
 
ExpectedCount = Package->RetInfo.Count1;
if (SubPackage->Package.Count < ExpectedCount)
{
goto PackageTooSmall;
}
 
/* Check the type of each sub-package element */
 
Status = AcpiNsCheckPackageElements (Data, SubElements,
Package->RetInfo.ObjectType1,
SubPackage->Package.Count, 0, 0, 0);
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
 
 
case ACPI_PTYPE2_COUNT:
 
/*
* First element is the (Integer) count of elements, including
* the count field (the ACPI name is NumElements)
*/
Status = AcpiNsCheckObjectType (Data, SubElements,
ACPI_RTYPE_INTEGER, 0);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/*
* Make sure package is large enough for the Count and is
* is as large as the minimum size
*/
ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
if (SubPackage->Package.Count < ExpectedCount)
{
goto PackageTooSmall;
}
if (SubPackage->Package.Count < Package->RetInfo.Count1)
{
ExpectedCount = Package->RetInfo.Count1;
goto PackageTooSmall;
}
if (ExpectedCount == 0)
{
/*
* Either the NumEntries element was originally zero or it was
* a NULL element and repaired to an Integer of value zero.
* In either case, repair it by setting NumEntries to be the
* actual size of the subpackage.
*/
ExpectedCount = SubPackage->Package.Count;
(*SubElements)->Integer.Value = ExpectedCount;
}
 
/* Check the type of each sub-package element */
 
Status = AcpiNsCheckPackageElements (Data, (SubElements + 1),
Package->RetInfo.ObjectType1,
(ExpectedCount - 1), 0, 0, 1);
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
 
 
default: /* Should not get here, type was validated by caller */
 
return (AE_AML_INTERNAL);
}
 
Elements++;
}
 
return (AE_OK);
 
 
PackageTooSmall:
 
/* The sub-package count was smaller than required */
 
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return Sub-Package[%u] is too small - found %u elements, expected %u",
i, SubPackage->Package.Count, ExpectedCount));
 
return (AE_AML_OPERAND_VALUE);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckPackageElements
*
* PARAMETERS: Data - Pointer to validation data structure
* Elements - Pointer to the package elements array
* Type1 - Object type for first group
* Count1 - Count for first group
* Type2 - Object type for second group
* Count2 - Count for second group
* StartIndex - Start of the first group of elements
*
* RETURN: Status
*
* DESCRIPTION: Check that all elements of a package are of the correct object
* type. Supports up to two groups of different object types.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckPackageElements (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **Elements,
UINT8 Type1,
UINT32 Count1,
UINT8 Type2,
UINT32 Count2,
UINT32 StartIndex)
{
ACPI_OPERAND_OBJECT **ThisElement = Elements;
ACPI_STATUS Status;
UINT32 i;
 
 
/*
* Up to two groups of package elements are supported by the data
* structure. All elements in each group must be of the same type.
* The second group can have a count of zero.
*/
for (i = 0; i < Count1; i++)
{
Status = AcpiNsCheckObjectType (Data, ThisElement,
Type1, i + StartIndex);
if (ACPI_FAILURE (Status))
{
return (Status);
}
ThisElement++;
}
 
for (i = 0; i < Count2; i++)
{
Status = AcpiNsCheckObjectType (Data, ThisElement,
Type2, (i + Count1 + StartIndex));
if (ACPI_FAILURE (Status))
{
return (Status);
}
ThisElement++;
}
 
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckObjectType
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
* ExpectedBtypes - Bitmap of expected return type(s)
* PackageIndex - Index of object within parent package (if
* applicable - ACPI_NOT_PACKAGE_ELEMENT
* otherwise)
*
* RETURN: Status
*
* DESCRIPTION: Check the type of the return object against the expected object
* type(s). Use of Btype allows multiple expected object types.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckObjectType (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr,
UINT32 ExpectedBtypes,
UINT32 PackageIndex)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status = AE_OK;
UINT32 ReturnBtype;
char TypeBuffer[48]; /* Room for 5 types */
 
 
/*
* If we get a NULL ReturnObject here, it is a NULL package element.
* Since all extraneous NULL package elements were removed earlier by a
* call to AcpiNsRemoveNullElements, this is an unexpected NULL element.
* We will attempt to repair it.
*/
if (!ReturnObject)
{
Status = AcpiNsRepairNullElement (Data, ExpectedBtypes,
PackageIndex, ReturnObjectPtr);
if (ACPI_SUCCESS (Status))
{
return (AE_OK); /* Repair was successful */
}
goto TypeErrorExit;
}
 
/* A Namespace node should not get here, but make sure */
 
if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Invalid return type - Found a Namespace node [%4.4s] type %s",
ReturnObject->Node.Name.Ascii,
AcpiUtGetTypeName (ReturnObject->Node.Type)));
return (AE_AML_OPERAND_TYPE);
}
 
/*
* Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
* The bitmapped type allows multiple possible return types.
*
* Note, the cases below must handle all of the possible types returned
* from all of the predefined names (including elements of returned
* packages)
*/
switch (ReturnObject->Common.Type)
{
case ACPI_TYPE_INTEGER:
ReturnBtype = ACPI_RTYPE_INTEGER;
break;
 
case ACPI_TYPE_BUFFER:
ReturnBtype = ACPI_RTYPE_BUFFER;
break;
 
case ACPI_TYPE_STRING:
ReturnBtype = ACPI_RTYPE_STRING;
break;
 
case ACPI_TYPE_PACKAGE:
ReturnBtype = ACPI_RTYPE_PACKAGE;
break;
 
case ACPI_TYPE_LOCAL_REFERENCE:
ReturnBtype = ACPI_RTYPE_REFERENCE;
break;
 
default:
/* Not one of the supported objects, must be incorrect */
 
goto TypeErrorExit;
}
 
/* Is the object one of the expected types? */
 
if (ReturnBtype & ExpectedBtypes)
{
/* For reference objects, check that the reference type is correct */
 
if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
{
Status = AcpiNsCheckReference (Data, ReturnObject);
}
 
return (Status);
}
 
/* Type mismatch -- attempt repair of the returned object */
 
Status = AcpiNsRepairObject (Data, ExpectedBtypes,
PackageIndex, ReturnObjectPtr);
if (ACPI_SUCCESS (Status))
{
return (AE_OK); /* Repair was successful */
}
 
 
TypeErrorExit:
 
/* Create a string with all expected types for this predefined object */
 
AcpiNsGetExpectedTypes (TypeBuffer, ExpectedBtypes);
 
if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return type mismatch - found %s, expected %s",
AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
}
else
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return Package type mismatch at index %u - "
"found %s, expected %s", PackageIndex,
AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
}
 
return (AE_AML_OPERAND_TYPE);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsCheckReference
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObject - Object returned from the evaluation of a
* method or object
*
* RETURN: Status
*
* DESCRIPTION: Check a returned reference object for the correct reference
* type. The only reference type that can be returned from a
* predefined method is a named reference. All others are invalid.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckReference (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT *ReturnObject)
{
 
/*
* Check the reference object for the correct reference type (opcode).
* The only type of reference that can be converted to an ACPI_OBJECT is
* a reference to a named object (reference class: NAME)
*/
if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
{
return (AE_OK);
}
 
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Return type mismatch - unexpected reference object type [%s] %2.2X",
AcpiUtGetReferenceName (ReturnObject),
ReturnObject->Reference.Class));
 
return (AE_AML_OPERAND_TYPE);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetExpectedTypes
*
* PARAMETERS: Buffer - Pointer to where the string is returned
* ExpectedBtypes - Bitmap of expected return type(s)
*
* RETURN: Buffer is populated with type names.
*
* DESCRIPTION: Translate the expected types bitmap into a string of ascii
* names of expected types, for use in warning messages.
*
******************************************************************************/
 
static void
AcpiNsGetExpectedTypes (
char *Buffer,
UINT32 ExpectedBtypes)
{
UINT32 ThisRtype;
UINT32 i;
UINT32 j;
 
 
j = 1;
Buffer[0] = 0;
ThisRtype = ACPI_RTYPE_INTEGER;
 
for (i = 0; i < ACPI_NUM_RTYPES; i++)
{
/* If one of the expected types, concatenate the name of this type */
 
if (ExpectedBtypes & ThisRtype)
{
ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
j = 0; /* Use name separator from now on */
}
ThisRtype <<= 1; /* Next Rtype */
}
}
/drivers/devman/acpica/namespace/nsrepair.c
0,0 → 1,876
/******************************************************************************
*
* Module Name: nsrepair - Repair for objects returned by predefined methods
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSREPAIR_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acinterp.h"
#include "acpredef.h"
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsrepair")
 
 
/*******************************************************************************
*
* This module attempts to repair or convert objects returned by the
* predefined methods to an object type that is expected, as per the ACPI
* specification. The need for this code is dictated by the many machines that
* return incorrect types for the standard predefined methods. Performing these
* conversions here, in one place, eliminates the need for individual ACPI
* device drivers to do the same. Note: Most of these conversions are different
* than the internal object conversion routines used for implicit object
* conversion.
*
* The following conversions can be performed as necessary:
*
* Integer -> String
* Integer -> Buffer
* String -> Integer
* String -> Buffer
* Buffer -> Integer
* Buffer -> String
* Buffer -> Package of Integers
* Package -> Package of one Package
*
* Additional possible repairs:
*
* Optional/unnecessary NULL package elements removed
* Required package elements that are NULL replaced by Integer/String/Buffer
* Incorrect standalone package wrapped with required outer package
*
******************************************************************************/
 
 
/* Local prototypes */
 
static ACPI_STATUS
AcpiNsConvertToInteger (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject);
 
static ACPI_STATUS
AcpiNsConvertToString (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject);
 
static ACPI_STATUS
AcpiNsConvertToBuffer (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject);
 
static ACPI_STATUS
AcpiNsConvertToPackage (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject);
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsRepairObject
*
* PARAMETERS: Data - Pointer to validation data structure
* ExpectedBtypes - Object types expected
* PackageIndex - Index of object within parent package (if
* applicable - ACPI_NOT_PACKAGE_ELEMENT
* otherwise)
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if repair was successful.
*
* DESCRIPTION: Attempt to repair/convert a return object of a type that was
* not expected.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsRepairObject (
ACPI_PREDEFINED_DATA *Data,
UINT32 ExpectedBtypes,
UINT32 PackageIndex,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_OPERAND_OBJECT *NewObject;
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_NAME (NsRepairObject);
 
 
/*
* At this point, we know that the type of the returned object was not
* one of the expected types for this predefined name. Attempt to
* repair the object by converting it to one of the expected object
* types for this predefined name.
*/
if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
{
Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
if (ACPI_SUCCESS (Status))
{
goto ObjectRepaired;
}
}
if (ExpectedBtypes & ACPI_RTYPE_STRING)
{
Status = AcpiNsConvertToString (ReturnObject, &NewObject);
if (ACPI_SUCCESS (Status))
{
goto ObjectRepaired;
}
}
if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
{
Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
if (ACPI_SUCCESS (Status))
{
goto ObjectRepaired;
}
}
if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
{
Status = AcpiNsConvertToPackage (ReturnObject, &NewObject);
if (ACPI_SUCCESS (Status))
{
goto ObjectRepaired;
}
}
 
/* We cannot repair this object */
 
return (AE_AML_OPERAND_TYPE);
 
 
ObjectRepaired:
 
/* Object was successfully repaired */
 
/*
* If the original object is a package element, we need to:
* 1. Set the reference count of the new object to match the
* reference count of the old object.
* 2. Decrement the reference count of the original object.
*/
if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
{
NewObject->Common.ReferenceCount =
ReturnObject->Common.ReferenceCount;
 
if (ReturnObject->Common.ReferenceCount > 1)
{
ReturnObject->Common.ReferenceCount--;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Converted %s to expected %s at index %u\n",
Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
AcpiUtGetObjectTypeName (NewObject), PackageIndex));
}
else
{
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Converted %s to expected %s\n",
Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
AcpiUtGetObjectTypeName (NewObject)));
}
 
/* Delete old object, install the new return object */
 
AcpiUtRemoveReference (ReturnObject);
*ReturnObjectPtr = NewObject;
Data->Flags |= ACPI_OBJECT_REPAIRED;
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsConvertToInteger
*
* PARAMETERS: OriginalObject - Object to be converted
* ReturnObject - Where the new converted object is returned
*
* RETURN: Status. AE_OK if conversion was successful.
*
* DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsConvertToInteger (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject)
{
ACPI_OPERAND_OBJECT *NewObject;
ACPI_STATUS Status;
UINT64 Value = 0;
UINT32 i;
 
 
switch (OriginalObject->Common.Type)
{
case ACPI_TYPE_STRING:
 
/* String-to-Integer conversion */
 
Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer,
ACPI_ANY_BASE, &Value);
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
 
case ACPI_TYPE_BUFFER:
 
/* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
 
if (OriginalObject->Buffer.Length > 8)
{
return (AE_AML_OPERAND_TYPE);
}
 
/* Extract each buffer byte to create the integer */
 
for (i = 0; i < OriginalObject->Buffer.Length; i++)
{
Value |= ((UINT64) OriginalObject->Buffer.Pointer[i] << (i * 8));
}
break;
 
default:
return (AE_AML_OPERAND_TYPE);
}
 
NewObject = AcpiUtCreateIntegerObject (Value);
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
*ReturnObject = NewObject;
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsConvertToString
*
* PARAMETERS: OriginalObject - Object to be converted
* ReturnObject - Where the new converted object is returned
*
* RETURN: Status. AE_OK if conversion was successful.
*
* DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsConvertToString (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject)
{
ACPI_OPERAND_OBJECT *NewObject;
ACPI_SIZE Length;
ACPI_STATUS Status;
 
 
switch (OriginalObject->Common.Type)
{
case ACPI_TYPE_INTEGER:
/*
* Integer-to-String conversion. Commonly, convert
* an integer of value 0 to a NULL string. The last element of
* _BIF and _BIX packages occasionally need this fix.
*/
if (OriginalObject->Integer.Value == 0)
{
/* Allocate a new NULL string object */
 
NewObject = AcpiUtCreateStringObject (0);
if (!NewObject)
{
return (AE_NO_MEMORY);
}
}
else
{
Status = AcpiExConvertToString (OriginalObject, &NewObject,
ACPI_IMPLICIT_CONVERT_HEX);
if (ACPI_FAILURE (Status))
{
return (Status);
}
}
break;
 
case ACPI_TYPE_BUFFER:
/*
* Buffer-to-String conversion. Use a ToString
* conversion, no transform performed on the buffer data. The best
* example of this is the _BIF method, where the string data from
* the battery is often (incorrectly) returned as buffer object(s).
*/
Length = 0;
while ((Length < OriginalObject->Buffer.Length) &&
(OriginalObject->Buffer.Pointer[Length]))
{
Length++;
}
 
/* Allocate a new string object */
 
NewObject = AcpiUtCreateStringObject (Length);
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
/*
* Copy the raw buffer data with no transform. String is already NULL
* terminated at Length+1.
*/
ACPI_MEMCPY (NewObject->String.Pointer,
OriginalObject->Buffer.Pointer, Length);
break;
 
default:
return (AE_AML_OPERAND_TYPE);
}
 
*ReturnObject = NewObject;
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsConvertToBuffer
*
* PARAMETERS: OriginalObject - Object to be converted
* ReturnObject - Where the new converted object is returned
*
* RETURN: Status. AE_OK if conversion was successful.
*
* DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsConvertToBuffer (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject)
{
ACPI_OPERAND_OBJECT *NewObject;
ACPI_STATUS Status;
ACPI_OPERAND_OBJECT **Elements;
UINT32 *DwordBuffer;
UINT32 Count;
UINT32 i;
 
 
switch (OriginalObject->Common.Type)
{
case ACPI_TYPE_INTEGER:
/*
* Integer-to-Buffer conversion.
* Convert the Integer to a packed-byte buffer. _MAT and other
* objects need this sometimes, if a read has been performed on a
* Field object that is less than or equal to the global integer
* size (32 or 64 bits).
*/
Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
if (ACPI_FAILURE (Status))
{
return (Status);
}
break;
 
case ACPI_TYPE_STRING:
 
/* String-to-Buffer conversion. Simple data copy */
 
NewObject = AcpiUtCreateBufferObject (OriginalObject->String.Length);
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
ACPI_MEMCPY (NewObject->Buffer.Pointer,
OriginalObject->String.Pointer, OriginalObject->String.Length);
break;
 
case ACPI_TYPE_PACKAGE:
/*
* This case is often seen for predefined names that must return a
* Buffer object with multiple DWORD integers within. For example,
* _FDE and _GTM. The Package can be converted to a Buffer.
*/
 
/* All elements of the Package must be integers */
 
Elements = OriginalObject->Package.Elements;
Count = OriginalObject->Package.Count;
 
for (i = 0; i < Count; i++)
{
if ((!*Elements) ||
((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
{
return (AE_AML_OPERAND_TYPE);
}
Elements++;
}
 
/* Create the new buffer object to replace the Package */
 
NewObject = AcpiUtCreateBufferObject (ACPI_MUL_4 (Count));
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
/* Copy the package elements (integers) to the buffer as DWORDs */
 
Elements = OriginalObject->Package.Elements;
DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
 
for (i = 0; i < Count; i++)
{
*DwordBuffer = (UINT32) (*Elements)->Integer.Value;
DwordBuffer++;
Elements++;
}
break;
 
default:
return (AE_AML_OPERAND_TYPE);
}
 
*ReturnObject = NewObject;
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsConvertToPackage
*
* PARAMETERS: OriginalObject - Object to be converted
* ReturnObject - Where the new converted object is returned
*
* RETURN: Status. AE_OK if conversion was successful.
*
* DESCRIPTION: Attempt to convert a Buffer object to a Package. Each byte of
* the buffer is converted to a single integer package element.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsConvertToPackage (
ACPI_OPERAND_OBJECT *OriginalObject,
ACPI_OPERAND_OBJECT **ReturnObject)
{
ACPI_OPERAND_OBJECT *NewObject;
ACPI_OPERAND_OBJECT **Elements;
UINT32 Length;
UINT8 *Buffer;
 
 
switch (OriginalObject->Common.Type)
{
case ACPI_TYPE_BUFFER:
 
/* Buffer-to-Package conversion */
 
Length = OriginalObject->Buffer.Length;
NewObject = AcpiUtCreatePackageObject (Length);
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
/* Convert each buffer byte to an integer package element */
 
Elements = NewObject->Package.Elements;
Buffer = OriginalObject->Buffer.Pointer;
 
while (Length--)
{
*Elements = AcpiUtCreateIntegerObject ((UINT64) *Buffer);
if (!*Elements)
{
AcpiUtRemoveReference (NewObject);
return (AE_NO_MEMORY);
}
Elements++;
Buffer++;
}
break;
 
default:
return (AE_AML_OPERAND_TYPE);
}
 
*ReturnObject = NewObject;
return (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsRepairNullElement
*
* PARAMETERS: Data - Pointer to validation data structure
* ExpectedBtypes - Object types expected
* PackageIndex - Index of object within parent package (if
* applicable - ACPI_NOT_PACKAGE_ELEMENT
* otherwise)
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if repair was successful.
*
* DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsRepairNullElement (
ACPI_PREDEFINED_DATA *Data,
UINT32 ExpectedBtypes,
UINT32 PackageIndex,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_OPERAND_OBJECT *NewObject;
 
 
ACPI_FUNCTION_NAME (NsRepairNullElement);
 
 
/* No repair needed if return object is non-NULL */
 
if (ReturnObject)
{
return (AE_OK);
}
 
/*
* Attempt to repair a NULL element of a Package object. This applies to
* predefined names that return a fixed-length package and each element
* is required. It does not apply to variable-length packages where NULL
* elements are allowed, especially at the end of the package.
*/
if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
{
/* Need an Integer - create a zero-value integer */
 
NewObject = AcpiUtCreateIntegerObject (0);
}
else if (ExpectedBtypes & ACPI_RTYPE_STRING)
{
/* Need a String - create a NULL string */
 
NewObject = AcpiUtCreateStringObject (0);
}
else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
{
/* Need a Buffer - create a zero-length buffer */
 
NewObject = AcpiUtCreateBufferObject (0);
}
else
{
/* Error for all other expected types */
 
return (AE_AML_OPERAND_TYPE);
}
 
if (!NewObject)
{
return (AE_NO_MEMORY);
}
 
/* Set the reference count according to the parent Package object */
 
NewObject->Common.ReferenceCount = Data->ParentPackage->Common.ReferenceCount;
 
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Converted NULL package element to expected %s at index %u\n",
Data->Pathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
 
*ReturnObjectPtr = NewObject;
Data->Flags |= ACPI_OBJECT_REPAIRED;
return (AE_OK);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsRemoveNullElements
*
* PARAMETERS: Data - Pointer to validation data structure
* PackageType - An AcpiReturnPackageTypes value
* ObjDesc - A Package object
*
* RETURN: None.
*
* DESCRIPTION: Remove all NULL package elements from packages that contain
* a variable number of sub-packages. For these types of
* packages, NULL elements can be safely removed.
*
*****************************************************************************/
 
void
AcpiNsRemoveNullElements (
ACPI_PREDEFINED_DATA *Data,
UINT8 PackageType,
ACPI_OPERAND_OBJECT *ObjDesc)
{
ACPI_OPERAND_OBJECT **Source;
ACPI_OPERAND_OBJECT **Dest;
UINT32 Count;
UINT32 NewCount;
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsRemoveNullElements);
 
 
/*
* PTYPE1 packages contain no subpackages.
* PTYPE2 packages contain a variable number of sub-packages. We can
* safely remove all NULL elements from the PTYPE2 packages.
*/
switch (PackageType)
{
case ACPI_PTYPE1_FIXED:
case ACPI_PTYPE1_VAR:
case ACPI_PTYPE1_OPTION:
return;
 
case ACPI_PTYPE2:
case ACPI_PTYPE2_COUNT:
case ACPI_PTYPE2_PKG_COUNT:
case ACPI_PTYPE2_FIXED:
case ACPI_PTYPE2_MIN:
case ACPI_PTYPE2_REV_FIXED:
break;
 
default:
return;
}
 
Count = ObjDesc->Package.Count;
NewCount = Count;
 
Source = ObjDesc->Package.Elements;
Dest = Source;
 
/* Examine all elements of the package object, remove nulls */
 
for (i = 0; i < Count; i++)
{
if (!*Source)
{
NewCount--;
}
else
{
*Dest = *Source;
Dest++;
}
Source++;
}
 
/* Update parent package if any null elements were removed */
 
if (NewCount < Count)
{
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Found and removed %u NULL elements\n",
Data->Pathname, (Count - NewCount)));
 
/* NULL terminate list and update the package count */
 
*Dest = NULL;
ObjDesc->Package.Count = NewCount;
}
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsRepairPackageList
*
* PARAMETERS: Data - Pointer to validation data structure
* ObjDescPtr - Pointer to the object to repair. The new
* package object is returned here,
* overwriting the old object.
*
* RETURN: Status, new object in *ObjDescPtr
*
* DESCRIPTION: Repair a common problem with objects that are defined to return
* a variable-length Package of Packages. If the variable-length
* is one, some BIOS code mistakenly simply declares a single
* Package instead of a Package with one sub-Package. This
* function attempts to repair this error by wrapping a Package
* object around the original Package, creating the correct
* Package with one sub-Package.
*
* Names that can be repaired in this manner include:
* _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsRepairPackageList (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ObjDescPtr)
{
ACPI_OPERAND_OBJECT *PkgObjDesc;
 
 
ACPI_FUNCTION_NAME (NsRepairPackageList);
 
 
/*
* Create the new outer package and populate it. The new package will
* have a single element, the lone subpackage.
*/
PkgObjDesc = AcpiUtCreatePackageObject (1);
if (!PkgObjDesc)
{
return (AE_NO_MEMORY);
}
 
PkgObjDesc->Package.Elements[0] = *ObjDescPtr;
 
/* Return the new object in the object pointer */
 
*ObjDescPtr = PkgObjDesc;
Data->Flags |= ACPI_OBJECT_REPAIRED;
 
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Repaired incorrectly formed Package\n", Data->Pathname));
 
return (AE_OK);
}
/drivers/devman/acpica/namespace/nsrepair2.c
0,0 → 1,703
/******************************************************************************
*
* Module Name: nsrepair2 - Repair for objects returned by specific
* predefined methods
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSREPAIR2_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsrepair2")
 
 
/*
* Information structure and handler for ACPI predefined names that can
* be repaired on a per-name basis.
*/
typedef
ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
typedef struct acpi_repair_info
{
char Name[ACPI_NAME_SIZE];
ACPI_REPAIR_FUNCTION RepairFunction;
 
} ACPI_REPAIR_INFO;
 
 
/* Local prototypes */
 
static const ACPI_REPAIR_INFO *
AcpiNsMatchRepairableName (
ACPI_NAMESPACE_NODE *Node);
 
static ACPI_STATUS
AcpiNsRepair_ALR (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
static ACPI_STATUS
AcpiNsRepair_FDE (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
static ACPI_STATUS
AcpiNsRepair_PSS (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
static ACPI_STATUS
AcpiNsRepair_TSS (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr);
 
static ACPI_STATUS
AcpiNsCheckSortedList (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT *ReturnObject,
UINT32 ExpectedCount,
UINT32 SortIndex,
UINT8 SortDirection,
char *SortKeyName);
 
static void
AcpiNsSortList (
ACPI_OPERAND_OBJECT **Elements,
UINT32 Count,
UINT32 Index,
UINT8 SortDirection);
 
/* Values for SortDirection above */
 
#define ACPI_SORT_ASCENDING 0
#define ACPI_SORT_DESCENDING 1
 
 
/*
* This table contains the names of the predefined methods for which we can
* perform more complex repairs.
*
* As necessary:
*
* _ALR: Sort the list ascending by AmbientIlluminance
* _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
* _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
* _PSS: Sort the list descending by Power
* _TSS: Sort the list descending by Power
*
* Names that must be packages, but cannot be sorted:
*
* _BCL: Values are tied to the Package index where they appear, and cannot
* be moved or sorted. These index values are used for _BQC and _BCM.
* However, we can fix the case where a buffer is returned, by converting
* it to a Package of integers.
*/
static const ACPI_REPAIR_INFO AcpiNsRepairableNames[] =
{
{"_ALR", AcpiNsRepair_ALR},
{"_FDE", AcpiNsRepair_FDE},
{"_GTM", AcpiNsRepair_FDE}, /* _GTM has same repair as _FDE */
{"_PSS", AcpiNsRepair_PSS},
{"_TSS", AcpiNsRepair_TSS},
{{0,0,0,0}, NULL} /* Table terminator */
};
 
 
#define ACPI_FDE_FIELD_COUNT 5
#define ACPI_FDE_BYTE_BUFFER_SIZE 5
#define ACPI_FDE_DWORD_BUFFER_SIZE (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsComplexRepairs
*
* PARAMETERS: Data - Pointer to validation data structure
* Node - Namespace node for the method/object
* ValidateStatus - Original status of earlier validation
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if repair was successful. If name is not
* matched, ValidateStatus is returned.
*
* DESCRIPTION: Attempt to repair/convert a return object of a type that was
* not expected.
*
*****************************************************************************/
 
ACPI_STATUS
AcpiNsComplexRepairs (
ACPI_PREDEFINED_DATA *Data,
ACPI_NAMESPACE_NODE *Node,
ACPI_STATUS ValidateStatus,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
const ACPI_REPAIR_INFO *Predefined;
ACPI_STATUS Status;
 
 
/* Check if this name is in the list of repairable names */
 
Predefined = AcpiNsMatchRepairableName (Node);
if (!Predefined)
{
return (ValidateStatus);
}
 
Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
return (Status);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsMatchRepairableName
*
* PARAMETERS: Node - Namespace node for the method/object
*
* RETURN: Pointer to entry in repair table. NULL indicates not found.
*
* DESCRIPTION: Check an object name against the repairable object list.
*
*****************************************************************************/
 
static const ACPI_REPAIR_INFO *
AcpiNsMatchRepairableName (
ACPI_NAMESPACE_NODE *Node)
{
const ACPI_REPAIR_INFO *ThisName;
 
 
/* Search info table for a repairable predefined method/object name */
 
ThisName = AcpiNsRepairableNames;
while (ThisName->RepairFunction)
{
if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
{
return (ThisName);
}
ThisName++;
}
 
return (NULL); /* Not found */
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsRepair_ALR
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if object is OK or was repaired successfully
*
* DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
* ascending by the ambient illuminance values.
*
*****************************************************************************/
 
static ACPI_STATUS
AcpiNsRepair_ALR (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status;
 
 
Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
ACPI_SORT_ASCENDING, "AmbientIlluminance");
 
return (Status);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsRepair_FDE
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if object is OK or was repaired successfully
*
* DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
* value is a Buffer of 5 DWORDs. This function repairs a common
* problem where the return value is a Buffer of BYTEs, not
* DWORDs.
*
*****************************************************************************/
 
static ACPI_STATUS
AcpiNsRepair_FDE (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_OPERAND_OBJECT *BufferObject;
UINT8 *ByteBuffer;
UINT32 *DwordBuffer;
UINT32 i;
 
 
ACPI_FUNCTION_NAME (NsRepair_FDE);
 
 
switch (ReturnObject->Common.Type)
{
case ACPI_TYPE_BUFFER:
 
/* This is the expected type. Length should be (at least) 5 DWORDs */
 
if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
{
return (AE_OK);
}
 
/* We can only repair if we have exactly 5 BYTEs */
 
if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"Incorrect return buffer length %u, expected %u",
ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
 
return (AE_AML_OPERAND_TYPE);
}
 
/* Create the new (larger) buffer object */
 
BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
if (!BufferObject)
{
return (AE_NO_MEMORY);
}
 
/* Expand each byte to a DWORD */
 
ByteBuffer = ReturnObject->Buffer.Pointer;
DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
 
for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
{
*DwordBuffer = (UINT32) *ByteBuffer;
DwordBuffer++;
ByteBuffer++;
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s Expanded Byte Buffer to expected DWord Buffer\n",
Data->Pathname));
break;
 
default:
return (AE_AML_OPERAND_TYPE);
}
 
/* Delete the original return object, return the new buffer object */
 
AcpiUtRemoveReference (ReturnObject);
*ReturnObjectPtr = BufferObject;
 
Data->Flags |= ACPI_OBJECT_REPAIRED;
return (AE_OK);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsRepair_TSS
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if object is OK or was repaired successfully
*
* DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
* descending by the power dissipation values.
*
*****************************************************************************/
 
static ACPI_STATUS
AcpiNsRepair_TSS (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_STATUS Status;
 
 
Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
ACPI_SORT_DESCENDING, "PowerDissipation");
 
return (Status);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsRepair_PSS
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObjectPtr - Pointer to the object returned from the
* evaluation of a method or object
*
* RETURN: Status. AE_OK if object is OK or was repaired successfully
*
* DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
* by the CPU frequencies. Check that the power dissipation values
* are all proportional to CPU frequency (i.e., sorting by
* frequency should be the same as sorting by power.)
*
*****************************************************************************/
 
static ACPI_STATUS
AcpiNsRepair_PSS (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT **ReturnObjectPtr)
{
ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
ACPI_OPERAND_OBJECT **OuterElements;
UINT32 OuterElementCount;
ACPI_OPERAND_OBJECT **Elements;
ACPI_OPERAND_OBJECT *ObjDesc;
UINT32 PreviousValue;
ACPI_STATUS Status;
UINT32 i;
 
 
/*
* Entries (sub-packages) in the _PSS Package must be sorted by power
* dissipation, in descending order. If it appears that the list is
* incorrectly sorted, sort it. We sort by CpuFrequency, since this
* should be proportional to the power.
*/
Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
ACPI_SORT_DESCENDING, "CpuFrequency");
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/*
* We now know the list is correctly sorted by CPU frequency. Check if
* the power dissipation values are proportional.
*/
PreviousValue = ACPI_UINT32_MAX;
OuterElements = ReturnObject->Package.Elements;
OuterElementCount = ReturnObject->Package.Count;
 
for (i = 0; i < OuterElementCount; i++)
{
Elements = (*OuterElements)->Package.Elements;
ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
 
if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
{
ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
"SubPackage[%u,%u] - suspicious power dissipation values",
i-1, i));
}
 
PreviousValue = (UINT32) ObjDesc->Integer.Value;
OuterElements++;
}
 
return (AE_OK);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsCheckSortedList
*
* PARAMETERS: Data - Pointer to validation data structure
* ReturnObject - Pointer to the top-level returned object
* ExpectedCount - Minimum length of each sub-package
* SortIndex - Sub-package entry to sort on
* SortDirection - Ascending or descending
* SortKeyName - Name of the SortIndex field
*
* RETURN: Status. AE_OK if the list is valid and is sorted correctly or
* has been repaired by sorting the list.
*
* DESCRIPTION: Check if the package list is valid and sorted correctly by the
* SortIndex. If not, then sort the list.
*
*****************************************************************************/
 
static ACPI_STATUS
AcpiNsCheckSortedList (
ACPI_PREDEFINED_DATA *Data,
ACPI_OPERAND_OBJECT *ReturnObject,
UINT32 ExpectedCount,
UINT32 SortIndex,
UINT8 SortDirection,
char *SortKeyName)
{
UINT32 OuterElementCount;
ACPI_OPERAND_OBJECT **OuterElements;
ACPI_OPERAND_OBJECT **Elements;
ACPI_OPERAND_OBJECT *ObjDesc;
UINT32 i;
UINT32 PreviousValue;
 
 
ACPI_FUNCTION_NAME (NsCheckSortedList);
 
 
/* The top-level object must be a package */
 
if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
{
return (AE_AML_OPERAND_TYPE);
}
 
/*
* NOTE: assumes list of sub-packages contains no NULL elements.
* Any NULL elements should have been removed by earlier call
* to AcpiNsRemoveNullElements.
*/
OuterElements = ReturnObject->Package.Elements;
OuterElementCount = ReturnObject->Package.Count;
if (!OuterElementCount)
{
return (AE_AML_PACKAGE_LIMIT);
}
 
PreviousValue = 0;
if (SortDirection == ACPI_SORT_DESCENDING)
{
PreviousValue = ACPI_UINT32_MAX;
}
 
/* Examine each subpackage */
 
for (i = 0; i < OuterElementCount; i++)
{
/* Each element of the top-level package must also be a package */
 
if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
{
return (AE_AML_OPERAND_TYPE);
}
 
/* Each sub-package must have the minimum length */
 
if ((*OuterElements)->Package.Count < ExpectedCount)
{
return (AE_AML_PACKAGE_LIMIT);
}
 
Elements = (*OuterElements)->Package.Elements;
ObjDesc = Elements[SortIndex];
 
if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
{
return (AE_AML_OPERAND_TYPE);
}
 
/*
* The list must be sorted in the specified order. If we detect a
* discrepancy, sort the entire list.
*/
if (((SortDirection == ACPI_SORT_ASCENDING) &&
(ObjDesc->Integer.Value < PreviousValue)) ||
((SortDirection == ACPI_SORT_DESCENDING) &&
(ObjDesc->Integer.Value > PreviousValue)))
{
AcpiNsSortList (ReturnObject->Package.Elements,
OuterElementCount, SortIndex, SortDirection);
 
Data->Flags |= ACPI_OBJECT_REPAIRED;
 
ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
"%s: Repaired unsorted list - now sorted by %s\n",
Data->Pathname, SortKeyName));
return (AE_OK);
}
 
PreviousValue = (UINT32) ObjDesc->Integer.Value;
OuterElements++;
}
 
return (AE_OK);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsSortList
*
* PARAMETERS: Elements - Package object element list
* Count - Element count for above
* Index - Sort by which package element
* SortDirection - Ascending or Descending sort
*
* RETURN: None
*
* DESCRIPTION: Sort the objects that are in a package element list.
*
* NOTE: Assumes that all NULL elements have been removed from the package,
* and that all elements have been verified to be of type Integer.
*
*****************************************************************************/
 
static void
AcpiNsSortList (
ACPI_OPERAND_OBJECT **Elements,
UINT32 Count,
UINT32 Index,
UINT8 SortDirection)
{
ACPI_OPERAND_OBJECT *ObjDesc1;
ACPI_OPERAND_OBJECT *ObjDesc2;
ACPI_OPERAND_OBJECT *TempObj;
UINT32 i;
UINT32 j;
 
 
/* Simple bubble sort */
 
for (i = 1; i < Count; i++)
{
for (j = (Count - 1); j >= i; j--)
{
ObjDesc1 = Elements[j-1]->Package.Elements[Index];
ObjDesc2 = Elements[j]->Package.Elements[Index];
 
if (((SortDirection == ACPI_SORT_ASCENDING) &&
(ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
 
((SortDirection == ACPI_SORT_DESCENDING) &&
(ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
{
TempObj = Elements[j-1];
Elements[j-1] = Elements[j];
Elements[j] = TempObj;
}
}
}
}
/drivers/devman/acpica/namespace/nssearch.c
0,0 → 1,496
/*******************************************************************************
*
* Module Name: nssearch - Namespace search
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSSEARCH_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
#ifdef ACPI_ASL_COMPILER
#include "amlcode.h"
#endif
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nssearch")
 
/* Local prototypes */
 
static ACPI_STATUS
AcpiNsSearchParentTree (
UINT32 TargetName,
ACPI_NAMESPACE_NODE *Node,
ACPI_OBJECT_TYPE Type,
ACPI_NAMESPACE_NODE **ReturnNode);
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsSearchOneScope
*
* PARAMETERS: TargetName - Ascii ACPI name to search for
* ParentNode - Starting node where search will begin
* Type - Object type to match
* ReturnNode - Where the matched Named obj is returned
*
* RETURN: Status
*
* DESCRIPTION: Search a single level of the namespace. Performs a
* simple search of the specified level, and does not add
* entries or search parents.
*
*
* Named object lists are built (and subsequently dumped) in the
* order in which the names are encountered during the namespace load;
*
* All namespace searching is linear in this implementation, but
* could be easily modified to support any improved search
* algorithm. However, the linear search was chosen for simplicity
* and because the trees are small and the other interpreter
* execution overhead is relatively high.
*
* Note: CPU execution analysis has shown that the AML interpreter spends
* a very small percentage of its time searching the namespace. Therefore,
* the linear search seems to be sufficient, as there would seem to be
* little value in improving the search.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsSearchOneScope (
UINT32 TargetName,
ACPI_NAMESPACE_NODE *ParentNode,
ACPI_OBJECT_TYPE Type,
ACPI_NAMESPACE_NODE **ReturnNode)
{
ACPI_NAMESPACE_NODE *Node;
 
 
ACPI_FUNCTION_TRACE (NsSearchOneScope);
 
 
#ifdef ACPI_DEBUG_OUTPUT
if (ACPI_LV_NAMES & AcpiDbgLevel)
{
char *ScopeName;
 
ScopeName = AcpiNsGetExternalPathname (ParentNode);
if (ScopeName)
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Searching %s (%p) For [%4.4s] (%s)\n",
ScopeName, ParentNode, ACPI_CAST_PTR (char, &TargetName),
AcpiUtGetTypeName (Type)));
 
ACPI_FREE (ScopeName);
}
}
#endif
 
/*
* Search for name at this namespace level, which is to say that we
* must search for the name among the children of this object
*/
Node = ParentNode->Child;
while (Node)
{
/* Check for match against the name */
 
if (Node->Name.Integer == TargetName)
{
/* Resolve a control method alias if any */
 
if (AcpiNsGetType (Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS)
{
Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object);
}
 
/* Found matching entry */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Name [%4.4s] (%s) %p found in scope [%4.4s] %p\n",
ACPI_CAST_PTR (char, &TargetName),
AcpiUtGetTypeName (Node->Type),
Node, AcpiUtGetNodeName (ParentNode), ParentNode));
 
*ReturnNode = Node;
return_ACPI_STATUS (AE_OK);
}
 
/* Didn't match name, move on to the next peer object */
 
Node = Node->Peer;
}
 
/* Searched entire namespace level, not found */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Name [%4.4s] (%s) not found in search in scope [%4.4s] "
"%p first child %p\n",
ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type),
AcpiUtGetNodeName (ParentNode), ParentNode, ParentNode->Child));
 
return_ACPI_STATUS (AE_NOT_FOUND);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsSearchParentTree
*
* PARAMETERS: TargetName - Ascii ACPI name to search for
* Node - Starting node where search will begin
* Type - Object type to match
* ReturnNode - Where the matched Node is returned
*
* RETURN: Status
*
* DESCRIPTION: Called when a name has not been found in the current namespace
* level. Before adding it or giving up, ACPI scope rules require
* searching enclosing scopes in cases identified by AcpiNsLocal().
*
* "A name is located by finding the matching name in the current
* name space, and then in the parent name space. If the parent
* name space does not contain the name, the search continues
* recursively until either the name is found or the name space
* does not have a parent (the root of the name space). This
* indicates that the name is not found" (From ACPI Specification,
* section 5.3)
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsSearchParentTree (
UINT32 TargetName,
ACPI_NAMESPACE_NODE *Node,
ACPI_OBJECT_TYPE Type,
ACPI_NAMESPACE_NODE **ReturnNode)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *ParentNode;
 
 
ACPI_FUNCTION_TRACE (NsSearchParentTree);
 
 
ParentNode = Node->Parent;
 
/*
* If there is no parent (i.e., we are at the root) or type is "local",
* we won't be searching the parent tree.
*/
if (!ParentNode)
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "[%4.4s] has no parent\n",
ACPI_CAST_PTR (char, &TargetName)));
return_ACPI_STATUS (AE_NOT_FOUND);
}
 
if (AcpiNsLocal (Type))
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"[%4.4s] type [%s] must be local to this scope (no parent search)\n",
ACPI_CAST_PTR (char, &TargetName), AcpiUtGetTypeName (Type)));
return_ACPI_STATUS (AE_NOT_FOUND);
}
 
/* Search the parent tree */
 
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"Searching parent [%4.4s] for [%4.4s]\n",
AcpiUtGetNodeName (ParentNode), ACPI_CAST_PTR (char, &TargetName)));
 
/* Search parents until target is found or we have backed up to the root */
 
while (ParentNode)
{
/*
* Search parent scope. Use TYPE_ANY because we don't care about the
* object type at this point, we only care about the existence of
* the actual name we are searching for. Typechecking comes later.
*/
Status = AcpiNsSearchOneScope (
TargetName, ParentNode, ACPI_TYPE_ANY, ReturnNode);
if (ACPI_SUCCESS (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Not found here, go up another level (until we reach the root) */
 
ParentNode = ParentNode->Parent;
}
 
/* Not found in parent tree */
 
return_ACPI_STATUS (AE_NOT_FOUND);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsSearchAndEnter
*
* PARAMETERS: TargetName - Ascii ACPI name to search for (4 chars)
* WalkState - Current state of the walk
* Node - Starting node where search will begin
* InterpreterMode - Add names only in ACPI_MODE_LOAD_PASS_x.
* Otherwise,search only.
* Type - Object type to match
* Flags - Flags describing the search restrictions
* ReturnNode - Where the Node is returned
*
* RETURN: Status
*
* DESCRIPTION: Search for a name segment in a single namespace level,
* optionally adding it if it is not found. If the passed
* Type is not Any and the type previously stored in the
* entry was Any (i.e. unknown), update the stored type.
*
* In ACPI_IMODE_EXECUTE, search only.
* In other modes, search and add if not found.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsSearchAndEnter (
UINT32 TargetName,
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE *Node,
ACPI_INTERPRETER_MODE InterpreterMode,
ACPI_OBJECT_TYPE Type,
UINT32 Flags,
ACPI_NAMESPACE_NODE **ReturnNode)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *NewNode;
 
 
ACPI_FUNCTION_TRACE (NsSearchAndEnter);
 
 
/* Parameter validation */
 
if (!Node || !TargetName || !ReturnNode)
{
ACPI_ERROR ((AE_INFO,
"Null parameter: Node %p Name 0x%X ReturnNode %p",
Node, TargetName, ReturnNode));
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/*
* Name must consist of valid ACPI characters. We will repair the name if
* necessary because we don't want to abort because of this, but we want
* all namespace names to be printable. A warning message is appropriate.
*
* This issue came up because there are in fact machines that exhibit
* this problem, and we want to be able to enable ACPI support for them,
* even though there are a few bad names.
*/
AcpiUtRepairName (ACPI_CAST_PTR (char, &TargetName));
 
/* Try to find the name in the namespace level specified by the caller */
 
*ReturnNode = ACPI_ENTRY_NOT_FOUND;
Status = AcpiNsSearchOneScope (TargetName, Node, Type, ReturnNode);
if (Status != AE_NOT_FOUND)
{
/*
* If we found it AND the request specifies that a find is an error,
* return the error
*/
if ((Status == AE_OK) &&
(Flags & ACPI_NS_ERROR_IF_FOUND))
{
Status = AE_ALREADY_EXISTS;
}
 
#ifdef ACPI_ASL_COMPILER
if (*ReturnNode && (*ReturnNode)->Type == ACPI_TYPE_ANY)
{
(*ReturnNode)->Flags |= ANOBJ_IS_EXTERNAL;
}
#endif
 
/* Either found it or there was an error: finished either way */
 
return_ACPI_STATUS (Status);
}
 
/*
* The name was not found. If we are NOT performing the first pass
* (name entry) of loading the namespace, search the parent tree (all the
* way to the root if necessary.) We don't want to perform the parent
* search when the namespace is actually being loaded. We want to perform
* the search when namespace references are being resolved (load pass 2)
* and during the execution phase.
*/
if ((InterpreterMode != ACPI_IMODE_LOAD_PASS1) &&
(Flags & ACPI_NS_SEARCH_PARENT))
{
/*
* Not found at this level - search parent tree according to the
* ACPI specification
*/
Status = AcpiNsSearchParentTree (TargetName, Node, Type, ReturnNode);
if (ACPI_SUCCESS (Status))
{
return_ACPI_STATUS (Status);
}
}
 
/* In execute mode, just search, never add names. Exit now */
 
if (InterpreterMode == ACPI_IMODE_EXECUTE)
{
ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
"%4.4s Not found in %p [Not adding]\n",
ACPI_CAST_PTR (char, &TargetName), Node));
 
return_ACPI_STATUS (AE_NOT_FOUND);
}
 
/* Create the new named object */
 
NewNode = AcpiNsCreateNode (TargetName);
if (!NewNode)
{
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
#ifdef ACPI_ASL_COMPILER
 
/* Node is an object defined by an External() statement */
 
if (Flags & ACPI_NS_EXTERNAL ||
(WalkState && WalkState->Opcode == AML_SCOPE_OP))
{
NewNode->Flags |= ANOBJ_IS_EXTERNAL;
}
#endif
 
if (Flags & ACPI_NS_TEMPORARY)
{
NewNode->Flags |= ANOBJ_TEMPORARY;
}
 
/* Install the new object into the parent's list of children */
 
AcpiNsInstallNode (WalkState, Node, NewNode, Type);
*ReturnNode = NewNode;
return_ACPI_STATUS (AE_OK);
}
 
/drivers/devman/acpica/namespace/nsutils.c
0,0 → 1,1059
/******************************************************************************
*
* Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
* parents and siblings and Scope manipulation
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSUTILS_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "amlcode.h"
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsutils")
 
/* Local prototypes */
 
static BOOLEAN
AcpiNsValidPathSeparator (
char Sep);
 
#ifdef ACPI_OBSOLETE_FUNCTIONS
ACPI_NAME
AcpiNsFindParentName (
ACPI_NAMESPACE_NODE *NodeToSearch);
#endif
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsReportError
*
* PARAMETERS: ModuleName - Caller's module name (for error output)
* LineNumber - Caller's line number (for error output)
* InternalName - Name or path of the namespace node
* LookupStatus - Exception code from NS lookup
*
* RETURN: None
*
* DESCRIPTION: Print warning message with full pathname
*
******************************************************************************/
 
void
AcpiNsReportError (
const char *ModuleName,
UINT32 LineNumber,
const char *InternalName,
ACPI_STATUS LookupStatus)
{
ACPI_STATUS Status;
UINT32 BadName;
char *Name = NULL;
 
 
AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
 
if (LookupStatus == AE_BAD_CHARACTER)
{
/* There is a non-ascii character in the name */
 
ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
AcpiOsPrintf ("[0x%4.4X] (NON-ASCII)", BadName);
}
else
{
/* Convert path to external format */
 
Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
InternalName, NULL, &Name);
 
/* Print target name */
 
if (ACPI_SUCCESS (Status))
{
AcpiOsPrintf ("[%s]", Name);
}
else
{
AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
}
 
if (Name)
{
ACPI_FREE (Name);
}
}
 
AcpiOsPrintf (" Namespace lookup failure, %s\n",
AcpiFormatException (LookupStatus));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsReportMethodError
*
* PARAMETERS: ModuleName - Caller's module name (for error output)
* LineNumber - Caller's line number (for error output)
* Message - Error message to use on failure
* PrefixNode - Prefix relative to the path
* Path - Path to the node (optional)
* MethodStatus - Execution status
*
* RETURN: None
*
* DESCRIPTION: Print warning message with full pathname
*
******************************************************************************/
 
void
AcpiNsReportMethodError (
const char *ModuleName,
UINT32 LineNumber,
const char *Message,
ACPI_NAMESPACE_NODE *PrefixNode,
const char *Path,
ACPI_STATUS MethodStatus)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node = PrefixNode;
 
 
AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
 
if (Path)
{
Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
&Node);
if (ACPI_FAILURE (Status))
{
AcpiOsPrintf ("[Could not get node by pathname]");
}
}
 
AcpiNsPrintNodePathname (Node, Message);
AcpiOsPrintf (", %s\n", AcpiFormatException (MethodStatus));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsPrintNodePathname
*
* PARAMETERS: Node - Object
* Message - Prefix message
*
* DESCRIPTION: Print an object's full namespace pathname
* Manages allocation/freeing of a pathname buffer
*
******************************************************************************/
 
void
AcpiNsPrintNodePathname (
ACPI_NAMESPACE_NODE *Node,
const char *Message)
{
ACPI_BUFFER Buffer;
ACPI_STATUS Status;
 
 
if (!Node)
{
AcpiOsPrintf ("[NULL NAME]");
return;
}
 
/* Convert handle to full pathname and print it (with supplied message) */
 
Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
 
Status = AcpiNsHandleToPathname (Node, &Buffer);
if (ACPI_SUCCESS (Status))
{
if (Message)
{
AcpiOsPrintf ("%s ", Message);
}
 
AcpiOsPrintf ("[%s] (Node %p)", (char *) Buffer.Pointer, Node);
ACPI_FREE (Buffer.Pointer);
}
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsValidRootPrefix
*
* PARAMETERS: Prefix - Character to be checked
*
* RETURN: TRUE if a valid prefix
*
* DESCRIPTION: Check if a character is a valid ACPI Root prefix
*
******************************************************************************/
 
BOOLEAN
AcpiNsValidRootPrefix (
char Prefix)
{
 
return ((BOOLEAN) (Prefix == '\\'));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsValidPathSeparator
*
* PARAMETERS: Sep - Character to be checked
*
* RETURN: TRUE if a valid path separator
*
* DESCRIPTION: Check if a character is a valid ACPI path separator
*
******************************************************************************/
 
static BOOLEAN
AcpiNsValidPathSeparator (
char Sep)
{
 
return ((BOOLEAN) (Sep == '.'));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetType
*
* PARAMETERS: Node - Parent Node to be examined
*
* RETURN: Type field from Node whose handle is passed
*
* DESCRIPTION: Return the type of a Namespace node
*
******************************************************************************/
 
ACPI_OBJECT_TYPE
AcpiNsGetType (
ACPI_NAMESPACE_NODE *Node)
{
ACPI_FUNCTION_TRACE (NsGetType);
 
 
if (!Node)
{
ACPI_WARNING ((AE_INFO, "Null Node parameter"));
return_UINT32 (ACPI_TYPE_ANY);
}
 
return_UINT32 ((ACPI_OBJECT_TYPE) Node->Type);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsLocal
*
* PARAMETERS: Type - A namespace object type
*
* RETURN: LOCAL if names must be found locally in objects of the
* passed type, 0 if enclosing scopes should be searched
*
* DESCRIPTION: Returns scope rule for the given object type.
*
******************************************************************************/
 
UINT32
AcpiNsLocal (
ACPI_OBJECT_TYPE Type)
{
ACPI_FUNCTION_TRACE (NsLocal);
 
 
if (!AcpiUtValidObjectType (Type))
{
/* Type code out of range */
 
ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
return_UINT32 (ACPI_NS_NORMAL);
}
 
return_UINT32 ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetInternalNameLength
*
* PARAMETERS: Info - Info struct initialized with the
* external name pointer.
*
* RETURN: None
*
* DESCRIPTION: Calculate the length of the internal (AML) namestring
* corresponding to the external (ASL) namestring.
*
******************************************************************************/
 
void
AcpiNsGetInternalNameLength (
ACPI_NAMESTRING_INFO *Info)
{
const char *NextExternalChar;
UINT32 i;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
NextExternalChar = Info->ExternalName;
Info->NumCarats = 0;
Info->NumSegments = 0;
Info->FullyQualified = FALSE;
 
/*
* For the internal name, the required length is 4 bytes per segment, plus
* 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null
* (which is not really needed, but no there's harm in putting it there)
*
* strlen() + 1 covers the first NameSeg, which has no path separator
*/
if (AcpiNsValidRootPrefix (*NextExternalChar))
{
Info->FullyQualified = TRUE;
NextExternalChar++;
 
/* Skip redundant RootPrefix, like \\_SB.PCI0.SBRG.EC0 */
 
while (AcpiNsValidRootPrefix (*NextExternalChar))
{
NextExternalChar++;
}
}
else
{
/* Handle Carat prefixes */
 
while (*NextExternalChar == '^')
{
Info->NumCarats++;
NextExternalChar++;
}
}
 
/*
* Determine the number of ACPI name "segments" by counting the number of
* path separators within the string. Start with one segment since the
* segment count is [(# separators) + 1], and zero separators is ok.
*/
if (*NextExternalChar)
{
Info->NumSegments = 1;
for (i = 0; NextExternalChar[i]; i++)
{
if (AcpiNsValidPathSeparator (NextExternalChar[i]))
{
Info->NumSegments++;
}
}
}
 
Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
4 + Info->NumCarats;
 
Info->NextExternalChar = NextExternalChar;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsBuildInternalName
*
* PARAMETERS: Info - Info struct fully initialized
*
* RETURN: Status
*
* DESCRIPTION: Construct the internal (AML) namestring
* corresponding to the external (ASL) namestring.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsBuildInternalName (
ACPI_NAMESTRING_INFO *Info)
{
UINT32 NumSegments = Info->NumSegments;
char *InternalName = Info->InternalName;
const char *ExternalName = Info->NextExternalChar;
char *Result = NULL;
UINT32 i;
 
 
ACPI_FUNCTION_TRACE (NsBuildInternalName);
 
 
/* Setup the correct prefixes, counts, and pointers */
 
if (Info->FullyQualified)
{
InternalName[0] = '\\';
 
if (NumSegments <= 1)
{
Result = &InternalName[1];
}
else if (NumSegments == 2)
{
InternalName[1] = AML_DUAL_NAME_PREFIX;
Result = &InternalName[2];
}
else
{
InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
InternalName[2] = (char) NumSegments;
Result = &InternalName[3];
}
}
else
{
/*
* Not fully qualified.
* Handle Carats first, then append the name segments
*/
i = 0;
if (Info->NumCarats)
{
for (i = 0; i < Info->NumCarats; i++)
{
InternalName[i] = '^';
}
}
 
if (NumSegments <= 1)
{
Result = &InternalName[i];
}
else if (NumSegments == 2)
{
InternalName[i] = AML_DUAL_NAME_PREFIX;
Result = &InternalName[(ACPI_SIZE) i+1];
}
else
{
InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
InternalName[(ACPI_SIZE) i+1] = (char) NumSegments;
Result = &InternalName[(ACPI_SIZE) i+2];
}
}
 
/* Build the name (minus path separators) */
 
for (; NumSegments; NumSegments--)
{
for (i = 0; i < ACPI_NAME_SIZE; i++)
{
if (AcpiNsValidPathSeparator (*ExternalName) ||
(*ExternalName == 0))
{
/* Pad the segment with underscore(s) if segment is short */
 
Result[i] = '_';
}
else
{
/* Convert the character to uppercase and save it */
 
Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
ExternalName++;
}
}
 
/* Now we must have a path separator, or the pathname is bad */
 
if (!AcpiNsValidPathSeparator (*ExternalName) &&
(*ExternalName != 0))
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Move on the next segment */
 
ExternalName++;
Result += ACPI_NAME_SIZE;
}
 
/* Terminate the string */
 
*Result = 0;
 
if (Info->FullyQualified)
{
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
InternalName, InternalName));
}
else
{
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
InternalName, InternalName));
}
 
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsInternalizeName
*
* PARAMETERS: *ExternalName - External representation of name
* **Converted Name - Where to return the resulting
* internal represention of the name
*
* RETURN: Status
*
* DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
* to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
*
*******************************************************************************/
 
ACPI_STATUS
AcpiNsInternalizeName (
const char *ExternalName,
char **ConvertedName)
{
char *InternalName;
ACPI_NAMESTRING_INFO Info;
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (NsInternalizeName);
 
 
if ((!ExternalName) ||
(*ExternalName == 0) ||
(!ConvertedName))
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Get the length of the new internal name */
 
Info.ExternalName = ExternalName;
AcpiNsGetInternalNameLength (&Info);
 
/* We need a segment to store the internal name */
 
InternalName = ACPI_ALLOCATE_ZEROED (Info.Length);
if (!InternalName)
{
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
/* Build the name */
 
Info.InternalName = InternalName;
Status = AcpiNsBuildInternalName (&Info);
if (ACPI_FAILURE (Status))
{
ACPI_FREE (InternalName);
return_ACPI_STATUS (Status);
}
 
*ConvertedName = InternalName;
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsExternalizeName
*
* PARAMETERS: InternalNameLength - Lenth of the internal name below
* InternalName - Internal representation of name
* ConvertedNameLength - Where the length is returned
* ConvertedName - Where the resulting external name
* is returned
*
* RETURN: Status
*
* DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
* to its external (printable) form (e.g. "\_PR_.CPU0")
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsExternalizeName (
UINT32 InternalNameLength,
const char *InternalName,
UINT32 *ConvertedNameLength,
char **ConvertedName)
{
UINT32 NamesIndex = 0;
UINT32 NumSegments = 0;
UINT32 RequiredLength;
UINT32 PrefixLength = 0;
UINT32 i = 0;
UINT32 j = 0;
 
 
ACPI_FUNCTION_TRACE (NsExternalizeName);
 
 
if (!InternalNameLength ||
!InternalName ||
!ConvertedName)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/* Check for a prefix (one '\' | one or more '^') */
 
switch (InternalName[0])
{
case '\\':
PrefixLength = 1;
break;
 
case '^':
for (i = 0; i < InternalNameLength; i++)
{
if (InternalName[i] == '^')
{
PrefixLength = i + 1;
}
else
{
break;
}
}
 
if (i == InternalNameLength)
{
PrefixLength = i;
}
 
break;
 
default:
break;
}
 
/*
* Check for object names. Note that there could be 0-255 of these
* 4-byte elements.
*/
if (PrefixLength < InternalNameLength)
{
switch (InternalName[PrefixLength])
{
case AML_MULTI_NAME_PREFIX_OP:
 
/* <count> 4-byte names */
 
NamesIndex = PrefixLength + 2;
NumSegments = (UINT8)
InternalName[(ACPI_SIZE) PrefixLength + 1];
break;
 
case AML_DUAL_NAME_PREFIX:
 
/* Two 4-byte names */
 
NamesIndex = PrefixLength + 1;
NumSegments = 2;
break;
 
case 0:
 
/* NullName */
 
NamesIndex = 0;
NumSegments = 0;
break;
 
default:
 
/* one 4-byte name */
 
NamesIndex = PrefixLength;
NumSegments = 1;
break;
}
}
 
/*
* Calculate the length of ConvertedName, which equals the length
* of the prefix, length of all object names, length of any required
* punctuation ('.') between object names, plus the NULL terminator.
*/
RequiredLength = PrefixLength + (4 * NumSegments) +
((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
 
/*
* Check to see if we're still in bounds. If not, there's a problem
* with InternalName (invalid format).
*/
if (RequiredLength > InternalNameLength)
{
ACPI_ERROR ((AE_INFO, "Invalid internal name"));
return_ACPI_STATUS (AE_BAD_PATHNAME);
}
 
/* Build the ConvertedName */
 
*ConvertedName = ACPI_ALLOCATE_ZEROED (RequiredLength);
if (!(*ConvertedName))
{
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
j = 0;
 
for (i = 0; i < PrefixLength; i++)
{
(*ConvertedName)[j++] = InternalName[i];
}
 
if (NumSegments > 0)
{
for (i = 0; i < NumSegments; i++)
{
if (i > 0)
{
(*ConvertedName)[j++] = '.';
}
 
(*ConvertedName)[j++] = InternalName[NamesIndex++];
(*ConvertedName)[j++] = InternalName[NamesIndex++];
(*ConvertedName)[j++] = InternalName[NamesIndex++];
(*ConvertedName)[j++] = InternalName[NamesIndex++];
}
}
 
if (ConvertedNameLength)
{
*ConvertedNameLength = (UINT32) RequiredLength;
}
 
return_ACPI_STATUS (AE_OK);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsValidateHandle
*
* PARAMETERS: Handle - Handle to be validated and typecast to a
* namespace node.
*
* RETURN: A pointer to a namespace node
*
* DESCRIPTION: Convert a namespace handle to a namespace node. Handles special
* cases for the root node.
*
* NOTE: Real integer handles would allow for more verification
* and keep all pointers within this subsystem - however this introduces
* more overhead and has not been necessary to this point. Drivers
* holding handles are typically notified before a node becomes invalid
* due to a table unload.
*
******************************************************************************/
 
ACPI_NAMESPACE_NODE *
AcpiNsValidateHandle (
ACPI_HANDLE Handle)
{
 
ACPI_FUNCTION_ENTRY ();
 
 
/* Parameter validation */
 
if ((!Handle) || (Handle == ACPI_ROOT_OBJECT))
{
return (AcpiGbl_RootNode);
}
 
/* We can at least attempt to verify the handle */
 
if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
{
return (NULL);
}
 
return (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle));
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsTerminate
*
* PARAMETERS: none
*
* RETURN: none
*
* DESCRIPTION: free memory allocated for namespace and ACPI table storage.
*
******************************************************************************/
 
void
AcpiNsTerminate (
void)
{
ACPI_OPERAND_OBJECT *ObjDesc;
 
 
ACPI_FUNCTION_TRACE (NsTerminate);
 
 
/*
* 1) Free the entire namespace -- all nodes and objects
*
* Delete all object descriptors attached to namepsace nodes
*/
AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
 
/* Detach any objects attached to the root */
 
ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
if (ObjDesc)
{
AcpiNsDetachObject (AcpiGbl_RootNode);
}
 
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
return_VOID;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsOpensScope
*
* PARAMETERS: Type - A valid namespace type
*
* RETURN: NEWSCOPE if the passed type "opens a name scope" according
* to the ACPI specification, else 0
*
******************************************************************************/
 
UINT32
AcpiNsOpensScope (
ACPI_OBJECT_TYPE Type)
{
ACPI_FUNCTION_TRACE_STR (NsOpensScope, AcpiUtGetTypeName (Type));
 
 
if (!AcpiUtValidObjectType (Type))
{
/* type code out of range */
 
ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
return_UINT32 (ACPI_NS_NORMAL);
}
 
return_UINT32 (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetNode
*
* PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
* \ (backslash) and ^ (carat) prefixes, and the
* . (period) to separate segments are supported.
* PrefixNode - Root of subtree to be searched, or NS_ALL for the
* root of the name space. If Name is fully
* qualified (first INT8 is '\'), the passed value
* of Scope will not be accessed.
* Flags - Used to indicate whether to perform upsearch or
* not.
* ReturnNode - Where the Node is returned
*
* DESCRIPTION: Look up a name relative to a given scope and return the
* corresponding Node. NOTE: Scope can be null.
*
* MUTEX: Locks namespace
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsGetNode (
ACPI_NAMESPACE_NODE *PrefixNode,
const char *Pathname,
UINT32 Flags,
ACPI_NAMESPACE_NODE **ReturnNode)
{
ACPI_GENERIC_STATE ScopeInfo;
ACPI_STATUS Status;
char *InternalPath;
 
 
ACPI_FUNCTION_TRACE_PTR (NsGetNode, ACPI_CAST_PTR (char, Pathname));
 
 
if (!Pathname)
{
*ReturnNode = PrefixNode;
if (!PrefixNode)
{
*ReturnNode = AcpiGbl_RootNode;
}
return_ACPI_STATUS (AE_OK);
}
 
/* Convert path to internal representation */
 
Status = AcpiNsInternalizeName (Pathname, &InternalPath);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Must lock namespace during lookup */
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
goto Cleanup;
}
 
/* Setup lookup scope (search starting point) */
 
ScopeInfo.Scope.Node = PrefixNode;
 
/* Lookup the name in the namespace */
 
Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
ACPI_IMODE_EXECUTE, (Flags | ACPI_NS_DONT_OPEN_SCOPE),
NULL, ReturnNode);
if (ACPI_FAILURE (Status))
{
ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s, %s\n",
Pathname, AcpiFormatException (Status)));
}
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 
Cleanup:
ACPI_FREE (InternalPath);
return_ACPI_STATUS (Status);
}
/drivers/devman/acpica/namespace/nswalk.c
0,0 → 1,458
/******************************************************************************
*
* Module Name: nswalk - Functions for walking the ACPI namespace
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSWALK_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nswalk")
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetNextNode
*
* PARAMETERS: ParentNode - Parent node whose children we are
* getting
* ChildNode - Previous child that was found.
* The NEXT child will be returned
*
* RETURN: ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
* none is found.
*
* DESCRIPTION: Return the next peer node within the namespace. If Handle
* is valid, Scope is ignored. Otherwise, the first node
* within Scope is returned.
*
******************************************************************************/
 
ACPI_NAMESPACE_NODE *
AcpiNsGetNextNode (
ACPI_NAMESPACE_NODE *ParentNode,
ACPI_NAMESPACE_NODE *ChildNode)
{
ACPI_FUNCTION_ENTRY ();
 
 
if (!ChildNode)
{
/* It's really the parent's _scope_ that we want */
 
return (ParentNode->Child);
}
 
/* Otherwise just return the next peer */
 
return (ChildNode->Peer);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetNextNodeTyped
*
* PARAMETERS: Type - Type of node to be searched for
* ParentNode - Parent node whose children we are
* getting
* ChildNode - Previous child that was found.
* The NEXT child will be returned
*
* RETURN: ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
* none is found.
*
* DESCRIPTION: Return the next peer node within the namespace. If Handle
* is valid, Scope is ignored. Otherwise, the first node
* within Scope is returned.
*
******************************************************************************/
 
ACPI_NAMESPACE_NODE *
AcpiNsGetNextNodeTyped (
ACPI_OBJECT_TYPE Type,
ACPI_NAMESPACE_NODE *ParentNode,
ACPI_NAMESPACE_NODE *ChildNode)
{
ACPI_NAMESPACE_NODE *NextNode = NULL;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
NextNode = AcpiNsGetNextNode (ParentNode, ChildNode);
 
/* If any type is OK, we are done */
 
if (Type == ACPI_TYPE_ANY)
{
/* NextNode is NULL if we are at the end-of-list */
 
return (NextNode);
}
 
/* Must search for the node -- but within this scope only */
 
while (NextNode)
{
/* If type matches, we are done */
 
if (NextNode->Type == Type)
{
return (NextNode);
}
 
/* Otherwise, move on to the next peer node */
 
NextNode = NextNode->Peer;
}
 
/* Not found */
 
return (NULL);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsWalkNamespace
*
* PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
* StartNode - Handle in namespace where search begins
* MaxDepth - Depth to which search is to reach
* Flags - Whether to unlock the NS before invoking
* the callback routine
* PreOrderVisit - Called during tree pre-order visit
* when an object of "Type" is found
* PostOrderVisit - Called during tree post-order visit
* when an object of "Type" is found
* Context - Passed to user function(s) above
* ReturnValue - from the UserFunction if terminated
* early. Otherwise, returns NULL.
* RETURNS: Status
*
* DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
* starting (and ending) at the node specified by StartHandle.
* The callback function is called whenever a node that matches
* the type parameter is found. If the callback function returns
* a non-zero value, the search is terminated immediately and
* this value is returned to the caller.
*
* The point of this procedure is to provide a generic namespace
* walk routine that can be called from multiple places to
* provide multiple services; the callback function(s) can be
* tailored to each task, whether it is a print function,
* a compare function, etc.
*
******************************************************************************/
 
ACPI_STATUS
AcpiNsWalkNamespace (
ACPI_OBJECT_TYPE Type,
ACPI_HANDLE StartNode,
UINT32 MaxDepth,
UINT32 Flags,
ACPI_WALK_CALLBACK PreOrderVisit,
ACPI_WALK_CALLBACK PostOrderVisit,
void *Context,
void **ReturnValue)
{
ACPI_STATUS Status;
ACPI_STATUS MutexStatus;
ACPI_NAMESPACE_NODE *ChildNode;
ACPI_NAMESPACE_NODE *ParentNode;
ACPI_OBJECT_TYPE ChildType;
UINT32 Level;
BOOLEAN NodePreviouslyVisited = FALSE;
 
 
ACPI_FUNCTION_TRACE (NsWalkNamespace);
 
 
/* Special case for the namespace Root Node */
 
if (StartNode == ACPI_ROOT_OBJECT)
{
StartNode = AcpiGbl_RootNode;
}
 
/* Null child means "get first node" */
 
ParentNode = StartNode;
ChildNode = AcpiNsGetNextNode (ParentNode, NULL);
ChildType = ACPI_TYPE_ANY;
Level = 1;
 
/*
* Traverse the tree of nodes until we bubble back up to where we
* started. When Level is zero, the loop is done because we have
* bubbled up to (and passed) the original parent handle (StartEntry)
*/
while (Level > 0 && ChildNode)
{
Status = AE_OK;
 
/* Found next child, get the type if we are not searching for ANY */
 
if (Type != ACPI_TYPE_ANY)
{
ChildType = ChildNode->Type;
}
 
/*
* Ignore all temporary namespace nodes (created during control
* method execution) unless told otherwise. These temporary nodes
* can cause a race condition because they can be deleted during
* the execution of the user function (if the namespace is
* unlocked before invocation of the user function.) Only the
* debugger namespace dump will examine the temporary nodes.
*/
if ((ChildNode->Flags & ANOBJ_TEMPORARY) &&
!(Flags & ACPI_NS_WALK_TEMP_NODES))
{
Status = AE_CTRL_DEPTH;
}
 
/* Type must match requested type */
 
else if (ChildType == Type)
{
/*
* Found a matching node, invoke the user callback function.
* Unlock the namespace if flag is set.
*/
if (Flags & ACPI_NS_WALK_UNLOCK)
{
MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (MutexStatus))
{
return_ACPI_STATUS (MutexStatus);
}
}
 
/*
* Invoke the user function, either pre-order or post-order
* or both.
*/
if (!NodePreviouslyVisited)
{
if (PreOrderVisit)
{
Status = PreOrderVisit (ChildNode, Level,
Context, ReturnValue);
}
}
else
{
if (PostOrderVisit)
{
Status = PostOrderVisit (ChildNode, Level,
Context, ReturnValue);
}
}
 
if (Flags & ACPI_NS_WALK_UNLOCK)
{
MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (MutexStatus))
{
return_ACPI_STATUS (MutexStatus);
}
}
 
switch (Status)
{
case AE_OK:
case AE_CTRL_DEPTH:
 
/* Just keep going */
break;
 
case AE_CTRL_TERMINATE:
 
/* Exit now, with OK status */
 
return_ACPI_STATUS (AE_OK);
 
default:
 
/* All others are valid exceptions */
 
return_ACPI_STATUS (Status);
}
}
 
/*
* Depth first search: Attempt to go down another level in the
* namespace if we are allowed to. Don't go any further if we have
* reached the caller specified maximum depth or if the user
* function has specified that the maximum depth has been reached.
*/
if (!NodePreviouslyVisited &&
(Level < MaxDepth) &&
(Status != AE_CTRL_DEPTH))
{
if (ChildNode->Child)
{
/* There is at least one child of this node, visit it */
 
Level++;
ParentNode = ChildNode;
ChildNode = AcpiNsGetNextNode (ParentNode, NULL);
continue;
}
}
 
/* No more children, re-visit this node */
 
if (!NodePreviouslyVisited)
{
NodePreviouslyVisited = TRUE;
continue;
}
 
/* No more children, visit peers */
 
ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
if (ChildNode)
{
NodePreviouslyVisited = FALSE;
}
 
/* No peers, re-visit parent */
 
else
{
/*
* No more children of this node (AcpiNsGetNextNode failed), go
* back upwards in the namespace tree to the node's parent.
*/
Level--;
ChildNode = ParentNode;
ParentNode = ParentNode->Parent;
 
NodePreviouslyVisited = TRUE;
}
}
 
/* Complete walk, not terminated by user function */
 
return_ACPI_STATUS (AE_OK);
}
 
 
/drivers/devman/acpica/namespace/nsxfeval.c
0,0 → 1,1032
/*******************************************************************************
*
* Module Name: nsxfeval - Public interfaces to the ACPI subsystem
* ACPI Object evaluation interfaces
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSXFEVAL_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acinterp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsxfeval")
 
/* Local prototypes */
 
static void
AcpiNsResolveReferences (
ACPI_EVALUATE_INFO *Info);
 
 
/*******************************************************************************
*
* FUNCTION: AcpiEvaluateObjectTyped
*
* PARAMETERS: Handle - Object handle (optional)
* Pathname - Object pathname (optional)
* ExternalParams - List of parameters to pass to method,
* terminated by NULL. May be NULL
* if no parameters are being passed.
* ReturnBuffer - Where to put method's return value (if
* any). If NULL, no value is returned.
* ReturnType - Expected type of return object
*
* RETURN: Status
*
* DESCRIPTION: Find and evaluate the given object, passing the given
* parameters if necessary. One of "Handle" or "Pathname" must
* be valid (non-null)
*
******************************************************************************/
 
ACPI_STATUS
AcpiEvaluateObjectTyped (
ACPI_HANDLE Handle,
ACPI_STRING Pathname,
ACPI_OBJECT_LIST *ExternalParams,
ACPI_BUFFER *ReturnBuffer,
ACPI_OBJECT_TYPE ReturnType)
{
ACPI_STATUS Status;
BOOLEAN MustFree = FALSE;
 
 
ACPI_FUNCTION_TRACE (AcpiEvaluateObjectTyped);
 
 
/* Return buffer must be valid */
 
if (!ReturnBuffer)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
if (ReturnBuffer->Length == ACPI_ALLOCATE_BUFFER)
{
MustFree = TRUE;
}
 
/* Evaluate the object */
 
Status = AcpiEvaluateObject (Handle, Pathname, ExternalParams, ReturnBuffer);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
/* Type ANY means "don't care" */
 
if (ReturnType == ACPI_TYPE_ANY)
{
return_ACPI_STATUS (AE_OK);
}
 
if (ReturnBuffer->Length == 0)
{
/* Error because caller specifically asked for a return value */
 
ACPI_ERROR ((AE_INFO, "No return value"));
return_ACPI_STATUS (AE_NULL_OBJECT);
}
 
/* Examine the object type returned from EvaluateObject */
 
if (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type == ReturnType)
{
return_ACPI_STATUS (AE_OK);
}
 
/* Return object type does not match requested type */
 
ACPI_ERROR ((AE_INFO,
"Incorrect return type [%s] requested [%s]",
AcpiUtGetTypeName (((ACPI_OBJECT *) ReturnBuffer->Pointer)->Type),
AcpiUtGetTypeName (ReturnType)));
 
if (MustFree)
{
/* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
 
AcpiOsFree (ReturnBuffer->Pointer);
ReturnBuffer->Pointer = NULL;
}
 
ReturnBuffer->Length = 0;
return_ACPI_STATUS (AE_TYPE);
}
 
ACPI_EXPORT_SYMBOL (AcpiEvaluateObjectTyped)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiEvaluateObject
*
* PARAMETERS: Handle - Object handle (optional)
* Pathname - Object pathname (optional)
* ExternalParams - List of parameters to pass to method,
* terminated by NULL. May be NULL
* if no parameters are being passed.
* ReturnBuffer - Where to put method's return value (if
* any). If NULL, no value is returned.
*
* RETURN: Status
*
* DESCRIPTION: Find and evaluate the given object, passing the given
* parameters if necessary. One of "Handle" or "Pathname" must
* be valid (non-null)
*
******************************************************************************/
 
ACPI_STATUS
AcpiEvaluateObject (
ACPI_HANDLE Handle,
ACPI_STRING Pathname,
ACPI_OBJECT_LIST *ExternalParams,
ACPI_BUFFER *ReturnBuffer)
{
ACPI_STATUS Status;
ACPI_EVALUATE_INFO *Info;
ACPI_SIZE BufferSpaceNeeded;
UINT32 i;
 
 
ACPI_FUNCTION_TRACE (AcpiEvaluateObject);
 
 
/* Allocate and initialize the evaluation information block */
 
Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
if (!Info)
{
return_ACPI_STATUS (AE_NO_MEMORY);
}
 
Info->Pathname = Pathname;
 
/* Convert and validate the device handle */
 
Info->PrefixNode = AcpiNsValidateHandle (Handle);
if (!Info->PrefixNode)
{
Status = AE_BAD_PARAMETER;
goto Cleanup;
}
 
/*
* If there are parameters to be passed to a control method, the external
* objects must all be converted to internal objects
*/
if (ExternalParams && ExternalParams->Count)
{
/*
* Allocate a new parameter block for the internal objects
* Add 1 to count to allow for null terminated internal list
*/
Info->Parameters = ACPI_ALLOCATE_ZEROED (
((ACPI_SIZE) ExternalParams->Count + 1) * sizeof (void *));
if (!Info->Parameters)
{
Status = AE_NO_MEMORY;
goto Cleanup;
}
 
/* Convert each external object in the list to an internal object */
 
for (i = 0; i < ExternalParams->Count; i++)
{
Status = AcpiUtCopyEobjectToIobject (
&ExternalParams->Pointer[i], &Info->Parameters[i]);
if (ACPI_FAILURE (Status))
{
goto Cleanup;
}
}
Info->Parameters[ExternalParams->Count] = NULL;
}
 
/*
* Three major cases:
* 1) Fully qualified pathname
* 2) No handle, not fully qualified pathname (error)
* 3) Valid handle
*/
if ((Pathname) &&
(AcpiNsValidRootPrefix (Pathname[0])))
{
/* The path is fully qualified, just evaluate by name */
 
Info->PrefixNode = NULL;
Status = AcpiNsEvaluate (Info);
}
else if (!Handle)
{
/*
* A handle is optional iff a fully qualified pathname is specified.
* Since we've already handled fully qualified names above, this is
* an error
*/
if (!Pathname)
{
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"Both Handle and Pathname are NULL"));
}
else
{
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"Null Handle with relative pathname [%s]", Pathname));
}
 
Status = AE_BAD_PARAMETER;
}
else
{
/* We have a namespace a node and a possible relative path */
 
Status = AcpiNsEvaluate (Info);
}
 
/*
* If we are expecting a return value, and all went well above,
* copy the return value to an external object.
*/
if (ReturnBuffer)
{
if (!Info->ReturnObject)
{
ReturnBuffer->Length = 0;
}
else
{
if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) ==
ACPI_DESC_TYPE_NAMED)
{
/*
* If we received a NS Node as a return object, this means that
* the object we are evaluating has nothing interesting to
* return (such as a mutex, etc.) We return an error because
* these types are essentially unsupported by this interface.
* We don't check up front because this makes it easier to add
* support for various types at a later date if necessary.
*/
Status = AE_TYPE;
Info->ReturnObject = NULL; /* No need to delete a NS Node */
ReturnBuffer->Length = 0;
}
 
if (ACPI_SUCCESS (Status))
{
/* Dereference Index and RefOf references */
 
AcpiNsResolveReferences (Info);
 
/* Get the size of the returned object */
 
Status = AcpiUtGetObjectSize (Info->ReturnObject,
&BufferSpaceNeeded);
if (ACPI_SUCCESS (Status))
{
/* Validate/Allocate/Clear caller buffer */
 
Status = AcpiUtInitializeBuffer (ReturnBuffer,
BufferSpaceNeeded);
if (ACPI_FAILURE (Status))
{
/*
* Caller's buffer is too small or a new one can't
* be allocated
*/
ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
"Needed buffer size %X, %s\n",
(UINT32) BufferSpaceNeeded,
AcpiFormatException (Status)));
}
else
{
/* We have enough space for the object, build it */
 
Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject,
ReturnBuffer);
}
}
}
}
}
 
if (Info->ReturnObject)
{
/*
* Delete the internal return object. NOTE: Interpreter must be
* locked to avoid race condition.
*/
AcpiExEnterInterpreter ();
 
/* Remove one reference on the return object (should delete it) */
 
AcpiUtRemoveReference (Info->ReturnObject);
AcpiExExitInterpreter ();
}
 
 
Cleanup:
 
/* Free the input parameter list (if we created one) */
 
if (Info->Parameters)
{
/* Free the allocated parameter block */
 
AcpiUtDeleteInternalObjectList (Info->Parameters);
}
 
ACPI_FREE (Info);
return_ACPI_STATUS (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiEvaluateObject)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsResolveReferences
*
* PARAMETERS: Info - Evaluation info block
*
* RETURN: Info->ReturnObject is replaced with the dereferenced object
*
* DESCRIPTION: Dereference certain reference objects. Called before an
* internal return object is converted to an external ACPI_OBJECT.
*
* Performs an automatic dereference of Index and RefOf reference objects.
* These reference objects are not supported by the ACPI_OBJECT, so this is a
* last resort effort to return something useful. Also, provides compatibility
* with other ACPI implementations.
*
* NOTE: does not handle references within returned package objects or nested
* references, but this support could be added later if found to be necessary.
*
******************************************************************************/
 
static void
AcpiNsResolveReferences (
ACPI_EVALUATE_INFO *Info)
{
ACPI_OPERAND_OBJECT *ObjDesc = NULL;
ACPI_NAMESPACE_NODE *Node;
 
 
/* We are interested in reference objects only */
 
if ((Info->ReturnObject)->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
{
return;
}
 
/*
* Two types of references are supported - those created by Index and
* RefOf operators. A name reference (AML_NAMEPATH_OP) can be converted
* to an ACPI_OBJECT, so it is not dereferenced here. A DdbHandle
* (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
* an ACPI_OBJECT.
*/
switch (Info->ReturnObject->Reference.Class)
{
case ACPI_REFCLASS_INDEX:
 
ObjDesc = *(Info->ReturnObject->Reference.Where);
break;
 
case ACPI_REFCLASS_REFOF:
 
Node = Info->ReturnObject->Reference.Object;
if (Node)
{
ObjDesc = Node->Object;
}
break;
 
default:
return;
}
 
/* Replace the existing reference object */
 
if (ObjDesc)
{
AcpiUtAddReference (ObjDesc);
AcpiUtRemoveReference (Info->ReturnObject);
Info->ReturnObject = ObjDesc;
}
 
return;
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiWalkNamespace
*
* PARAMETERS: Type - ACPI_OBJECT_TYPE to search for
* StartObject - Handle in namespace where search begins
* MaxDepth - Depth to which search is to reach
* PreOrderVisit - Called during tree pre-order visit
* when an object of "Type" is found
* PostOrderVisit - Called during tree post-order visit
* when an object of "Type" is found
* Context - Passed to user function(s) above
* ReturnValue - Location where return value of
* UserFunction is put if terminated early
*
* RETURNS Return value from the UserFunction if terminated early.
* Otherwise, returns NULL.
*
* DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
* starting (and ending) at the object specified by StartHandle.
* The callback function is called whenever an object that matches
* the type parameter is found. If the callback function returns
* a non-zero value, the search is terminated immediately and this
* value is returned to the caller.
*
* The point of this procedure is to provide a generic namespace
* walk routine that can be called from multiple places to
* provide multiple services; the callback function(s) can be
* tailored to each task, whether it is a print function,
* a compare function, etc.
*
******************************************************************************/
 
ACPI_STATUS
AcpiWalkNamespace (
ACPI_OBJECT_TYPE Type,
ACPI_HANDLE StartObject,
UINT32 MaxDepth,
ACPI_WALK_CALLBACK PreOrderVisit,
ACPI_WALK_CALLBACK PostOrderVisit,
void *Context,
void **ReturnValue)
{
ACPI_STATUS Status;
 
 
ACPI_FUNCTION_TRACE (AcpiWalkNamespace);
 
 
/* Parameter validation */
 
if ((Type > ACPI_TYPE_LOCAL_MAX) ||
(!MaxDepth) ||
(!PreOrderVisit && !PostOrderVisit))
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/*
* Need to acquire the namespace reader lock to prevent interference
* with any concurrent table unloads (which causes the deletion of
* namespace objects). We cannot allow the deletion of a namespace node
* while the user function is using it. The exception to this are the
* nodes created and deleted during control method execution -- these
* nodes are marked as temporary nodes and are ignored by the namespace
* walk. Thus, control methods can be executed while holding the
* namespace deletion lock (and the user function can execute control
* methods.)
*/
Status = AcpiUtAcquireReadLock (&AcpiGbl_NamespaceRwLock);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/*
* Lock the namespace around the walk. The namespace will be
* unlocked/locked around each call to the user function - since the user
* function must be allowed to make ACPICA calls itself (for example, it
* will typically execute control methods during device enumeration.)
*/
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
goto UnlockAndExit;
}
 
Status = AcpiNsWalkNamespace (Type, StartObject, MaxDepth,
ACPI_NS_WALK_UNLOCK, PreOrderVisit,
PostOrderVisit, Context, ReturnValue);
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 
UnlockAndExit:
(void) AcpiUtReleaseReadLock (&AcpiGbl_NamespaceRwLock);
return_ACPI_STATUS (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiWalkNamespace)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiNsGetDeviceCallback
*
* PARAMETERS: Callback from AcpiGetDevice
*
* RETURN: Status
*
* DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
* present devices, or if they specified a HID, it filters based
* on that.
*
******************************************************************************/
 
static ACPI_STATUS
AcpiNsGetDeviceCallback (
ACPI_HANDLE ObjHandle,
UINT32 NestingLevel,
void *Context,
void **ReturnValue)
{
ACPI_GET_DEVICES_INFO *Info = Context;
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
UINT32 Flags;
ACPI_DEVICE_ID *Hid;
ACPI_DEVICE_ID_LIST *Cid;
UINT32 i;
BOOLEAN Found;
int NoMatch;
 
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
Node = AcpiNsValidateHandle (ObjHandle);
Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
if (!Node)
{
return (AE_BAD_PARAMETER);
}
 
/*
* First, filter based on the device HID and CID.
*
* 01/2010: For this case where a specific HID is requested, we don't
* want to run _STA until we have an actual HID match. Thus, we will
* not unnecessarily execute _STA on devices for which the caller
* doesn't care about. Previously, _STA was executed unconditionally
* on all devices found here.
*
* A side-effect of this change is that now we will continue to search
* for a matching HID even under device trees where the parent device
* would have returned a _STA that indicates it is not present or
* not functioning (thus aborting the search on that branch).
*/
if (Info->Hid != NULL)
{
Status = AcpiUtExecute_HID (Node, &Hid);
if (Status == AE_NOT_FOUND)
{
return (AE_OK);
}
else if (ACPI_FAILURE (Status))
{
return (AE_CTRL_DEPTH);
}
 
NoMatch = ACPI_STRCMP (Hid->String, Info->Hid);
ACPI_FREE (Hid);
 
if (NoMatch)
{
/*
* HID does not match, attempt match within the
* list of Compatible IDs (CIDs)
*/
Status = AcpiUtExecute_CID (Node, &Cid);
if (Status == AE_NOT_FOUND)
{
return (AE_OK);
}
else if (ACPI_FAILURE (Status))
{
return (AE_CTRL_DEPTH);
}
 
/* Walk the CID list */
 
Found = FALSE;
for (i = 0; i < Cid->Count; i++)
{
if (ACPI_STRCMP (Cid->Ids[i].String, Info->Hid) == 0)
{
/* Found a matching CID */
 
Found = TRUE;
break;
}
}
 
ACPI_FREE (Cid);
if (!Found)
{
return (AE_OK);
}
}
}
 
/* Run _STA to determine if device is present */
 
Status = AcpiUtExecute_STA (Node, &Flags);
if (ACPI_FAILURE (Status))
{
return (AE_CTRL_DEPTH);
}
 
if (!(Flags & ACPI_STA_DEVICE_PRESENT) &&
!(Flags & ACPI_STA_DEVICE_FUNCTIONING))
{
/*
* Don't examine the children of the device only when the
* device is neither present nor functional. See ACPI spec,
* description of _STA for more information.
*/
return (AE_CTRL_DEPTH);
}
 
/* We have a valid device, invoke the user function */
 
Status = Info->UserFunction (ObjHandle, NestingLevel, Info->Context,
ReturnValue);
return (Status);
}
 
 
/*******************************************************************************
*
* FUNCTION: AcpiGetDevices
*
* PARAMETERS: HID - HID to search for. Can be NULL.
* UserFunction - Called when a matching object is found
* Context - Passed to user function
* ReturnValue - Location where return value of
* UserFunction is put if terminated early
*
* RETURNS Return value from the UserFunction if terminated early.
* Otherwise, returns NULL.
*
* DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
* starting (and ending) at the object specified by StartHandle.
* The UserFunction is called whenever an object of type
* Device is found. If the user function returns
* a non-zero value, the search is terminated immediately and this
* value is returned to the caller.
*
* This is a wrapper for WalkNamespace, but the callback performs
* additional filtering. Please see AcpiNsGetDeviceCallback.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetDevices (
char *HID,
ACPI_WALK_CALLBACK UserFunction,
void *Context,
void **ReturnValue)
{
ACPI_STATUS Status;
ACPI_GET_DEVICES_INFO Info;
 
 
ACPI_FUNCTION_TRACE (AcpiGetDevices);
 
 
/* Parameter validation */
 
if (!UserFunction)
{
return_ACPI_STATUS (AE_BAD_PARAMETER);
}
 
/*
* We're going to call their callback from OUR callback, so we need
* to know what it is, and their context parameter.
*/
Info.Hid = HID;
Info.Context = Context;
Info.UserFunction = UserFunction;
 
/*
* Lock the namespace around the walk.
* The namespace will be unlocked/locked around each call
* to the user function - since this function
* must be allowed to make Acpi calls itself.
*/
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
 
Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
AcpiNsGetDeviceCallback, NULL, &Info, ReturnValue);
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return_ACPI_STATUS (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetDevices)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiAttachData
*
* PARAMETERS: ObjHandle - Namespace node
* Handler - Handler for this attachment
* Data - Pointer to data to be attached
*
* RETURN: Status
*
* DESCRIPTION: Attach arbitrary data and handler to a namespace node.
*
******************************************************************************/
 
ACPI_STATUS
AcpiAttachData (
ACPI_HANDLE ObjHandle,
ACPI_OBJECT_HANDLER Handler,
void *Data)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
 
 
/* Parameter validation */
 
if (!ObjHandle ||
!Handler ||
!Data)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Convert and validate the handle */
 
Node = AcpiNsValidateHandle (ObjHandle);
if (!Node)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
 
Status = AcpiNsAttachData (Node, Handler, Data);
 
UnlockAndExit:
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiAttachData)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiDetachData
*
* PARAMETERS: ObjHandle - Namespace node handle
* Handler - Handler used in call to AcpiAttachData
*
* RETURN: Status
*
* DESCRIPTION: Remove data that was previously attached to a node.
*
******************************************************************************/
 
ACPI_STATUS
AcpiDetachData (
ACPI_HANDLE ObjHandle,
ACPI_OBJECT_HANDLER Handler)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
 
 
/* Parameter validation */
 
if (!ObjHandle ||
!Handler)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Convert and validate the handle */
 
Node = AcpiNsValidateHandle (ObjHandle);
if (!Node)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
 
Status = AcpiNsDetachData (Node, Handler);
 
UnlockAndExit:
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiDetachData)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiGetData
*
* PARAMETERS: ObjHandle - Namespace node
* Handler - Handler used in call to AttachData
* Data - Where the data is returned
*
* RETURN: Status
*
* DESCRIPTION: Retrieve data that was previously attached to a namespace node.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetData (
ACPI_HANDLE ObjHandle,
ACPI_OBJECT_HANDLER Handler,
void **Data)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
 
 
/* Parameter validation */
 
if (!ObjHandle ||
!Handler ||
!Data)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Convert and validate the handle */
 
Node = AcpiNsValidateHandle (ObjHandle);
if (!Node)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
 
Status = AcpiNsGetAttachedData (Node, Handler, Data);
 
UnlockAndExit:
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetData)
 
 
/drivers/devman/acpica/namespace/nsxfname.c
0,0 → 1,776
/******************************************************************************
*
* Module Name: nsxfname - Public interfaces to the ACPI subsystem
* ACPI Namespace oriented interfaces
*
*****************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
#define __NSXFNAME_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acparser.h"
#include "amlcode.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsxfname")
 
/* Local prototypes */
 
static char *
AcpiNsCopyDeviceId (
ACPI_DEVICE_ID *Dest,
ACPI_DEVICE_ID *Source,
char *StringArea);
 
 
/******************************************************************************
*
* FUNCTION: AcpiGetHandle
*
* PARAMETERS: Parent - Object to search under (search scope).
* Pathname - Pointer to an asciiz string containing the
* name
* RetHandle - Where the return handle is returned
*
* RETURN: Status
*
* DESCRIPTION: This routine will search for a caller specified name in the
* name space. The caller can restrict the search region by
* specifying a non NULL parent. The parent value is itself a
* namespace handle.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetHandle (
ACPI_HANDLE Parent,
ACPI_STRING Pathname,
ACPI_HANDLE *RetHandle)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node = NULL;
ACPI_NAMESPACE_NODE *PrefixNode = NULL;
 
 
ACPI_FUNCTION_ENTRY ();
 
 
/* Parameter Validation */
 
if (!RetHandle || !Pathname)
{
return (AE_BAD_PARAMETER);
}
 
/* Convert a parent handle to a prefix node */
 
if (Parent)
{
PrefixNode = AcpiNsValidateHandle (Parent);
if (!PrefixNode)
{
return (AE_BAD_PARAMETER);
}
}
 
/*
* Valid cases are:
* 1) Fully qualified pathname
* 2) Parent + Relative pathname
*
* Error for <null Parent + relative path>
*/
if (AcpiNsValidRootPrefix (Pathname[0]))
{
/* Pathname is fully qualified (starts with '\') */
 
/* Special case for root-only, since we can't search for it */
 
if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH))
{
*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, AcpiGbl_RootNode);
return (AE_OK);
}
}
else if (!PrefixNode)
{
/* Relative path with null prefix is disallowed */
 
return (AE_BAD_PARAMETER);
}
 
/* Find the Node and convert to a handle */
 
Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node);
if (ACPI_SUCCESS (Status))
{
*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
}
 
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetHandle)
 
 
/******************************************************************************
*
* FUNCTION: AcpiGetName
*
* PARAMETERS: Handle - Handle to be converted to a pathname
* NameType - Full pathname or single segment
* Buffer - Buffer for returned path
*
* RETURN: Pointer to a string containing the fully qualified Name.
*
* DESCRIPTION: This routine returns the fully qualified name associated with
* the Handle parameter. This and the AcpiPathnameToHandle are
* complementary functions.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetName (
ACPI_HANDLE Handle,
UINT32 NameType,
ACPI_BUFFER *Buffer)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
 
 
/* Parameter validation */
 
if (NameType > ACPI_NAME_TYPE_MAX)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtValidateBuffer (Buffer);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
if (NameType == ACPI_FULL_PATHNAME)
{
/* Get the full pathname (From the namespace root) */
 
Status = AcpiNsHandleToPathname (Handle, Buffer);
return (Status);
}
 
/*
* Wants the single segment ACPI name.
* Validate handle and convert to a namespace Node
*/
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
Node = AcpiNsValidateHandle (Handle);
if (!Node)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
 
/* Validate/Allocate/Clear caller buffer */
 
Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
if (ACPI_FAILURE (Status))
{
goto UnlockAndExit;
}
 
/* Just copy the ACPI name from the Node and zero terminate it */
 
ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node),
ACPI_NAME_SIZE);
((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
Status = AE_OK;
 
 
UnlockAndExit:
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetName)
 
 
/******************************************************************************
*
* FUNCTION: AcpiNsCopyDeviceId
*
* PARAMETERS: Dest - Pointer to the destination DEVICE_ID
* Source - Pointer to the source DEVICE_ID
* StringArea - Pointer to where to copy the dest string
*
* RETURN: Pointer to the next string area
*
* DESCRIPTION: Copy a single DEVICE_ID, including the string data.
*
******************************************************************************/
 
static char *
AcpiNsCopyDeviceId (
ACPI_DEVICE_ID *Dest,
ACPI_DEVICE_ID *Source,
char *StringArea)
{
/* Create the destination DEVICE_ID */
 
Dest->String = StringArea;
Dest->Length = Source->Length;
 
/* Copy actual string and return a pointer to the next string area */
 
ACPI_MEMCPY (StringArea, Source->String, Source->Length);
return (StringArea + Source->Length);
}
 
 
/******************************************************************************
*
* FUNCTION: AcpiGetObjectInfo
*
* PARAMETERS: Handle - Object Handle
* ReturnBuffer - Where the info is returned
*
* RETURN: Status
*
* DESCRIPTION: Returns information about an object as gleaned from the
* namespace node and possibly by running several standard
* control methods (Such as in the case of a device.)
*
* For Device and Processor objects, run the Device _HID, _UID, _CID, _STA,
* _ADR, _SxW, and _SxD methods.
*
* Note: Allocates the return buffer, must be freed by the caller.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetObjectInfo (
ACPI_HANDLE Handle,
ACPI_DEVICE_INFO **ReturnBuffer)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_DEVICE_INFO *Info;
ACPI_DEVICE_ID_LIST *CidList = NULL;
ACPI_DEVICE_ID *Hid = NULL;
ACPI_DEVICE_ID *Uid = NULL;
char *NextIdString;
ACPI_OBJECT_TYPE Type;
ACPI_NAME Name;
UINT8 ParamCount= 0;
UINT8 Valid = 0;
UINT32 InfoSize;
UINT32 i;
ACPI_STATUS Status;
 
 
/* Parameter validation */
 
if (!Handle || !ReturnBuffer)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
goto Cleanup;
}
 
Node = AcpiNsValidateHandle (Handle);
if (!Node)
{
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (AE_BAD_PARAMETER);
}
 
/* Get the namespace node data while the namespace is locked */
 
InfoSize = sizeof (ACPI_DEVICE_INFO);
Type = Node->Type;
Name = Node->Name.Integer;
 
if (Node->Type == ACPI_TYPE_METHOD)
{
ParamCount = Node->Object->Method.ParamCount;
}
 
Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
if ((Type == ACPI_TYPE_DEVICE) ||
(Type == ACPI_TYPE_PROCESSOR))
{
/*
* Get extra info for ACPI Device/Processor objects only:
* Run the Device _HID, _UID, and _CID methods.
*
* Note: none of these methods are required, so they may or may
* not be present for this device. The Info->Valid bitfield is used
* to indicate which methods were found and run successfully.
*/
 
/* Execute the Device._HID method */
 
Status = AcpiUtExecute_HID (Node, &Hid);
if (ACPI_SUCCESS (Status))
{
InfoSize += Hid->Length;
Valid |= ACPI_VALID_HID;
}
 
/* Execute the Device._UID method */
 
Status = AcpiUtExecute_UID (Node, &Uid);
if (ACPI_SUCCESS (Status))
{
InfoSize += Uid->Length;
Valid |= ACPI_VALID_UID;
}
 
/* Execute the Device._CID method */
 
Status = AcpiUtExecute_CID (Node, &CidList);
if (ACPI_SUCCESS (Status))
{
/* Add size of CID strings and CID pointer array */
 
InfoSize += (CidList->ListSize - sizeof (ACPI_DEVICE_ID_LIST));
Valid |= ACPI_VALID_CID;
}
}
 
/*
* Now that we have the variable-length data, we can allocate the
* return buffer
*/
Info = ACPI_ALLOCATE_ZEROED (InfoSize);
if (!Info)
{
Status = AE_NO_MEMORY;
goto Cleanup;
}
 
/* Get the fixed-length data */
 
if ((Type == ACPI_TYPE_DEVICE) ||
(Type == ACPI_TYPE_PROCESSOR))
{
/*
* Get extra info for ACPI Device/Processor objects only:
* Run the _STA, _ADR and, SxW, and _SxD methods.
*
* Note: none of these methods are required, so they may or may
* not be present for this device. The Info->Valid bitfield is used
* to indicate which methods were found and run successfully.
*/
 
/* Execute the Device._STA method */
 
Status = AcpiUtExecute_STA (Node, &Info->CurrentStatus);
if (ACPI_SUCCESS (Status))
{
Valid |= ACPI_VALID_STA;
}
 
/* Execute the Device._ADR method */
 
Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, Node,
&Info->Address);
if (ACPI_SUCCESS (Status))
{
Valid |= ACPI_VALID_ADR;
}
 
/* Execute the Device._SxW methods */
 
Status = AcpiUtExecutePowerMethods (Node,
AcpiGbl_LowestDstateNames, ACPI_NUM_SxW_METHODS,
Info->LowestDstates);
if (ACPI_SUCCESS (Status))
{
Valid |= ACPI_VALID_SXWS;
}
 
/* Execute the Device._SxD methods */
 
Status = AcpiUtExecutePowerMethods (Node,
AcpiGbl_HighestDstateNames, ACPI_NUM_SxD_METHODS,
Info->HighestDstates);
if (ACPI_SUCCESS (Status))
{
Valid |= ACPI_VALID_SXDS;
}
}
 
/*
* Create a pointer to the string area of the return buffer.
* Point to the end of the base ACPI_DEVICE_INFO structure.
*/
NextIdString = ACPI_CAST_PTR (char, Info->CompatibleIdList.Ids);
if (CidList)
{
/* Point past the CID DEVICE_ID array */
 
NextIdString += ((ACPI_SIZE) CidList->Count * sizeof (ACPI_DEVICE_ID));
}
 
/*
* Copy the HID, UID, and CIDs to the return buffer. The variable-length
* strings are copied to the reserved area at the end of the buffer.
*
* For HID and CID, check if the ID is a PCI Root Bridge.
*/
if (Hid)
{
NextIdString = AcpiNsCopyDeviceId (&Info->HardwareId,
Hid, NextIdString);
 
if (AcpiUtIsPciRootBridge (Hid->String))
{
Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
}
}
 
if (Uid)
{
NextIdString = AcpiNsCopyDeviceId (&Info->UniqueId,
Uid, NextIdString);
}
 
if (CidList)
{
Info->CompatibleIdList.Count = CidList->Count;
Info->CompatibleIdList.ListSize = CidList->ListSize;
 
/* Copy each CID */
 
for (i = 0; i < CidList->Count; i++)
{
NextIdString = AcpiNsCopyDeviceId (&Info->CompatibleIdList.Ids[i],
&CidList->Ids[i], NextIdString);
 
if (AcpiUtIsPciRootBridge (CidList->Ids[i].String))
{
Info->Flags |= ACPI_PCI_ROOT_BRIDGE;
}
}
}
 
/* Copy the fixed-length data */
 
Info->InfoSize = InfoSize;
Info->Type = Type;
Info->Name = Name;
Info->ParamCount = ParamCount;
Info->Valid = Valid;
 
*ReturnBuffer = Info;
Status = AE_OK;
 
 
Cleanup:
if (Hid)
{
ACPI_FREE (Hid);
}
if (Uid)
{
ACPI_FREE (Uid);
}
if (CidList)
{
ACPI_FREE (CidList);
}
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetObjectInfo)
 
 
/******************************************************************************
*
* FUNCTION: AcpiInstallMethod
*
* PARAMETERS: Buffer - An ACPI table containing one control method
*
* RETURN: Status
*
* DESCRIPTION: Install a control method into the namespace. If the method
* name already exists in the namespace, it is overwritten. The
* input buffer must contain a valid DSDT or SSDT containing a
* single control method.
*
******************************************************************************/
 
ACPI_STATUS
AcpiInstallMethod (
UINT8 *Buffer)
{
ACPI_TABLE_HEADER *Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Buffer);
UINT8 *AmlBuffer;
UINT8 *AmlStart;
char *Path;
ACPI_NAMESPACE_NODE *Node;
ACPI_OPERAND_OBJECT *MethodObj;
ACPI_PARSE_STATE ParserState;
UINT32 AmlLength;
UINT16 Opcode;
UINT8 MethodFlags;
ACPI_STATUS Status;
 
 
/* Parameter validation */
 
if (!Buffer)
{
return (AE_BAD_PARAMETER);
}
 
/* Table must be a DSDT or SSDT */
 
if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT) &&
!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_SSDT))
{
return (AE_BAD_HEADER);
}
 
/* First AML opcode in the table must be a control method */
 
ParserState.Aml = Buffer + sizeof (ACPI_TABLE_HEADER);
Opcode = AcpiPsPeekOpcode (&ParserState);
if (Opcode != AML_METHOD_OP)
{
return (AE_BAD_PARAMETER);
}
 
/* Extract method information from the raw AML */
 
ParserState.Aml += AcpiPsGetOpcodeSize (Opcode);
ParserState.PkgEnd = AcpiPsGetNextPackageEnd (&ParserState);
Path = AcpiPsGetNextNamestring (&ParserState);
MethodFlags = *ParserState.Aml++;
AmlStart = ParserState.Aml;
AmlLength = ACPI_PTR_DIFF (ParserState.PkgEnd, AmlStart);
 
/*
* Allocate resources up-front. We don't want to have to delete a new
* node from the namespace if we cannot allocate memory.
*/
AmlBuffer = ACPI_ALLOCATE (AmlLength);
if (!AmlBuffer)
{
return (AE_NO_MEMORY);
}
 
MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
if (!MethodObj)
{
ACPI_FREE (AmlBuffer);
return (AE_NO_MEMORY);
}
 
/* Lock namespace for AcpiNsLookup, we may be creating a new node */
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
goto ErrorExit;
}
 
/* The lookup either returns an existing node or creates a new one */
 
Status = AcpiNsLookup (NULL, Path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND, NULL, &Node);
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
 
if (ACPI_FAILURE (Status)) /* NsLookup */
{
if (Status != AE_ALREADY_EXISTS)
{
goto ErrorExit;
}
 
/* Node existed previously, make sure it is a method node */
 
if (Node->Type != ACPI_TYPE_METHOD)
{
Status = AE_TYPE;
goto ErrorExit;
}
}
 
/* Copy the method AML to the local buffer */
 
ACPI_MEMCPY (AmlBuffer, AmlStart, AmlLength);
 
/* Initialize the method object with the new method's information */
 
MethodObj->Method.AmlStart = AmlBuffer;
MethodObj->Method.AmlLength = AmlLength;
 
MethodObj->Method.ParamCount = (UINT8)
(MethodFlags & AML_METHOD_ARG_COUNT);
 
MethodObj->Method.MethodFlags = (UINT8)
(MethodFlags & ~AML_METHOD_ARG_COUNT);
 
if (MethodFlags & AML_METHOD_SERIALIZED)
{
MethodObj->Method.SyncLevel = (UINT8)
((MethodFlags & AML_METHOD_SYNC_LEVEL) >> 4);
}
 
/*
* Now that it is complete, we can attach the new method object to
* the method Node (detaches/deletes any existing object)
*/
Status = AcpiNsAttachObject (Node, MethodObj,
ACPI_TYPE_METHOD);
 
/*
* Flag indicates AML buffer is dynamic, must be deleted later.
* Must be set only after attach above.
*/
Node->Flags |= ANOBJ_ALLOCATED_BUFFER;
 
/* Remove local reference to the method object */
 
AcpiUtRemoveReference (MethodObj);
return (Status);
 
 
ErrorExit:
 
ACPI_FREE (AmlBuffer);
ACPI_FREE (MethodObj);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiInstallMethod)
/drivers/devman/acpica/namespace/nsxfobj.c
0,0 → 1,357
/*******************************************************************************
*
* Module Name: nsxfobj - Public interfaces to the ACPI subsystem
* ACPI Object oriented interfaces
*
******************************************************************************/
 
/******************************************************************************
*
* 1. Copyright Notice
*
* Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
* All rights reserved.
*
* 2. License
*
* 2.1. This is your license from Intel Corp. under its intellectual property
* rights. You may have additional license terms from the party that provided
* you this software, covering your right to use that party's intellectual
* property rights.
*
* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
* copy of the source code appearing in this file ("Covered Code") an
* irrevocable, perpetual, worldwide license under Intel's copyrights in the
* base code distributed originally by Intel ("Original Intel Code") to copy,
* make derivatives, distribute, use and display any portion of the Covered
* Code in any form, with the right to sublicense such rights; and
*
* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
* license (with the right to sublicense), under only those claims of Intel
* patents that are infringed by the Original Intel Code, to make, use, sell,
* offer to sell, and import the Covered Code and derivative works thereof
* solely to the minimum extent necessary to exercise the above copyright
* license, and in no event shall the patent license extend to any additions
* to or modifications of the Original Intel Code. No other license or right
* is granted directly or by implication, estoppel or otherwise;
*
* The above copyright and patent license is granted only if the following
* conditions are met:
*
* 3. Conditions
*
* 3.1. Redistribution of Source with Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification with rights to further distribute source must include
* the above Copyright Notice, the above License, this list of Conditions,
* and the following Disclaimer and Export Compliance provision. In addition,
* Licensee must cause all Covered Code to which Licensee contributes to
* contain a file documenting the changes Licensee made to create that Covered
* Code and the date of any change. Licensee must include in that file the
* documentation of any changes made by any predecessor Licensee. Licensee
* must include a prominent statement that the modification is derived,
* directly or indirectly, from Original Intel Code.
*
* 3.2. Redistribution of Source with no Rights to Further Distribute Source.
* Redistribution of source code of any substantial portion of the Covered
* Code or modification without rights to further distribute source must
* include the following Disclaimer and Export Compliance provision in the
* documentation and/or other materials provided with distribution. In
* addition, Licensee may not authorize further sublicense of source of any
* portion of the Covered Code, and must include terms to the effect that the
* license from Licensee to its licensee is limited to the intellectual
* property embodied in the software Licensee provides to its licensee, and
* not to intellectual property embodied in modifications its licensee may
* make.
*
* 3.3. Redistribution of Executable. Redistribution in executable form of any
* substantial portion of the Covered Code or modification must reproduce the
* above Copyright Notice, and the following Disclaimer and Export Compliance
* provision in the documentation and/or other materials provided with the
* distribution.
*
* 3.4. Intel retains all right, title, and interest in and to the Original
* Intel Code.
*
* 3.5. Neither the name Intel nor any other trademark owned or controlled by
* Intel shall be used in advertising or otherwise to promote the sale, use or
* other dealings in products derived from or relating to the Covered Code
* without prior written authorization from Intel.
*
* 4. Disclaimer and Export Compliance
*
* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
* LIMITED REMEDY.
*
* 4.3. Licensee shall not export, either directly or indirectly, any of this
* software or system incorporating such software without first obtaining any
* required license or other approval from the U. S. Department of Commerce or
* any other agency or department of the United States Government. In the
* event Licensee exports any such software from the United States or
* re-exports any such software from a foreign destination, Licensee shall
* ensure that the distribution and export/re-export of the software is in
* compliance with all laws, regulations, orders, or other restrictions of the
* U.S. Export Administration Regulations. Licensee agrees that neither it nor
* any of its subsidiaries will export/re-export any technical data, process,
* software, or service, directly or indirectly, to any country for which the
* United States government or any agency thereof requires an export license,
* other governmental approval, or letter of assurance, without first obtaining
* such license, approval or letter.
*
*****************************************************************************/
 
 
#define __NSXFOBJ_C__
 
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
 
 
#define _COMPONENT ACPI_NAMESPACE
ACPI_MODULE_NAME ("nsxfobj")
 
/*******************************************************************************
*
* FUNCTION: AcpiGetType
*
* PARAMETERS: Handle - Handle of object whose type is desired
* RetType - Where the type will be placed
*
* RETURN: Status
*
* DESCRIPTION: This routine returns the type associatd with a particular handle
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetType (
ACPI_HANDLE Handle,
ACPI_OBJECT_TYPE *RetType)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_STATUS Status;
 
 
/* Parameter Validation */
 
if (!RetType)
{
return (AE_BAD_PARAMETER);
}
 
/*
* Special case for the predefined Root Node
* (return type ANY)
*/
if (Handle == ACPI_ROOT_OBJECT)
{
*RetType = ACPI_TYPE_ANY;
return (AE_OK);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Convert and validate the handle */
 
Node = AcpiNsValidateHandle (Handle);
if (!Node)
{
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (AE_BAD_PARAMETER);
}
 
*RetType = Node->Type;
 
 
Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetType)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiGetParent
*
* PARAMETERS: Handle - Handle of object whose parent is desired
* RetHandle - Where the parent handle will be placed
*
* RETURN: Status
*
* DESCRIPTION: Returns a handle to the parent of the object represented by
* Handle.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetParent (
ACPI_HANDLE Handle,
ACPI_HANDLE *RetHandle)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_NAMESPACE_NODE *ParentNode;
ACPI_STATUS Status;
 
 
if (!RetHandle)
{
return (AE_BAD_PARAMETER);
}
 
/* Special case for the predefined Root Node (no parent) */
 
if (Handle == ACPI_ROOT_OBJECT)
{
return (AE_NULL_ENTRY);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* Convert and validate the handle */
 
Node = AcpiNsValidateHandle (Handle);
if (!Node)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
 
/* Get the parent entry */
 
ParentNode = Node->Parent;
*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
 
/* Return exception if parent is null */
 
if (!ParentNode)
{
Status = AE_NULL_ENTRY;
}
 
 
UnlockAndExit:
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetParent)
 
 
/*******************************************************************************
*
* FUNCTION: AcpiGetNextObject
*
* PARAMETERS: Type - Type of object to be searched for
* Parent - Parent object whose children we are getting
* LastChild - Previous child that was found.
* The NEXT child will be returned
* RetHandle - Where handle to the next object is placed
*
* RETURN: Status
*
* DESCRIPTION: Return the next peer object within the namespace. If Handle is
* valid, Scope is ignored. Otherwise, the first object within
* Scope is returned.
*
******************************************************************************/
 
ACPI_STATUS
AcpiGetNextObject (
ACPI_OBJECT_TYPE Type,
ACPI_HANDLE Parent,
ACPI_HANDLE Child,
ACPI_HANDLE *RetHandle)
{
ACPI_STATUS Status;
ACPI_NAMESPACE_NODE *Node;
ACPI_NAMESPACE_NODE *ParentNode = NULL;
ACPI_NAMESPACE_NODE *ChildNode = NULL;
 
 
/* Parameter validation */
 
if (Type > ACPI_TYPE_EXTERNAL_MAX)
{
return (AE_BAD_PARAMETER);
}
 
Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
if (ACPI_FAILURE (Status))
{
return (Status);
}
 
/* If null handle, use the parent */
 
if (!Child)
{
/* Start search at the beginning of the specified scope */
 
ParentNode = AcpiNsValidateHandle (Parent);
if (!ParentNode)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
}
else
{
/* Non-null handle, ignore the parent */
/* Convert and validate the handle */
 
ChildNode = AcpiNsValidateHandle (Child);
if (!ChildNode)
{
Status = AE_BAD_PARAMETER;
goto UnlockAndExit;
}
}
 
/* Internal function does the real work */
 
Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
if (!Node)
{
Status = AE_NOT_FOUND;
goto UnlockAndExit;
}
 
if (RetHandle)
{
*RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
}
 
 
UnlockAndExit:
 
(void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
return (Status);
}
 
ACPI_EXPORT_SYMBOL (AcpiGetNextObject)