2000-10-28 05:01:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: psutils - Parser miscellaneous utilities (Parser only)
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-01-13 16:12:34 +00:00
|
|
|
/*
|
2012-01-11 21:25:42 +00:00
|
|
|
* Copyright (C) 2000 - 2012, Intel Corp.
|
2000-12-21 06:56:46 +00:00
|
|
|
* All rights reserved.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2011-01-13 16:12:34 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* substantially similar to the "NO WARRANTY" disclaimer below
|
|
|
|
* ("Disclaimer") and any redistribution must be conditioned upon
|
|
|
|
* including a substantially similar Disclaimer requirement for further
|
|
|
|
* binary redistribution.
|
|
|
|
* 3. Neither the names of the above-listed copyright holders nor the names
|
|
|
|
* of any contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acpi.h"
|
2009-06-01 21:02:40 +00:00
|
|
|
#include "accommon.h"
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acparser.h"
|
|
|
|
#include "amlcode.h"
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define _COMPONENT ACPI_PARSER
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_MODULE_NAME ("psutils")
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2002-07-30 19:33:39 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsCreateScopeOp
|
|
|
|
*
|
|
|
|
* PARAMETERS: None
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: A new Scope object, null on failure
|
2002-07-30 19:33:39 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Create a Scope and associated namepath op with the root name
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsCreateScopeOp (
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
ACPI_PARSE_OBJECT *ScopeOp;
|
|
|
|
|
|
|
|
|
|
|
|
ScopeOp = AcpiPsAllocOp (AML_SCOPE_OP);
|
|
|
|
if (!ScopeOp)
|
|
|
|
{
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeOp->Named.Name = ACPI_ROOT_NAME;
|
|
|
|
return (ScopeOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsInitOp
|
|
|
|
*
|
|
|
|
* PARAMETERS: Op - A newly allocated Op object
|
|
|
|
* Opcode - Opcode to store in the Op
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: None
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* DESCRIPTION: Initialize a parse (Op) object
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
AcpiPsInitOp (
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
UINT16 Opcode)
|
|
|
|
{
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_FUNCTION_ENTRY ();
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
Op->Common.DescriptorType = ACPI_DESC_TYPE_PARSER;
|
2002-07-09 17:51:31 +00:00
|
|
|
Op->Common.AmlOpcode = Opcode;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-07-30 19:33:39 +00:00
|
|
|
ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (Op->Common.AmlOpName,
|
2005-11-01 22:11:18 +00:00
|
|
|
(AcpiPsGetOpcodeInfo (Opcode))->Name,
|
|
|
|
sizeof (Op->Common.AmlOpName)));
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsAllocOp
|
|
|
|
*
|
|
|
|
* PARAMETERS: Opcode - Opcode that will be stored in the new Op
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: Pointer to the new Op, null on failure
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
|
|
|
|
* opcode. A cache of opcodes is available for the pure
|
|
|
|
* GENERIC_OP, since this is by far the most commonly used.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT*
|
|
|
|
AcpiPsAllocOp (
|
|
|
|
UINT16 Opcode)
|
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
ACPI_PARSE_OBJECT *Op;
|
2001-09-07 01:22:25 +00:00
|
|
|
const ACPI_OPCODE_INFO *OpInfo;
|
2004-12-01 23:14:10 +00:00
|
|
|
UINT8 Flags = ACPI_PARSEOP_GENERIC;
|
2001-09-07 01:22:25 +00:00
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_FUNCTION_ENTRY ();
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
OpInfo = AcpiPsGetOpcodeInfo (Opcode);
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/* Determine type of ParseOp required */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
if (OpInfo->Flags & AML_DEFER)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2002-02-23 05:10:40 +00:00
|
|
|
Flags = ACPI_PARSEOP_DEFERRED;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2001-09-07 01:22:25 +00:00
|
|
|
else if (OpInfo->Flags & AML_NAMED)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2002-02-23 05:10:40 +00:00
|
|
|
Flags = ACPI_PARSEOP_NAMED;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2001-09-07 01:22:25 +00:00
|
|
|
else if (Opcode == AML_INT_BYTELIST_OP)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2002-02-23 05:10:40 +00:00
|
|
|
Flags = ACPI_PARSEOP_BYTELIST;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 23:14:10 +00:00
|
|
|
/* Allocate the minimum required size object */
|
|
|
|
|
|
|
|
if (Flags == ACPI_PARSEOP_GENERIC)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
/* The generic op (default) is by far the most common (16 to 1) */
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Op = AcpiOsAcquireObject (AcpiGbl_PsNodeCache);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-01 23:14:10 +00:00
|
|
|
/* Extended parseop */
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
Op = AcpiOsAcquireObject (AcpiGbl_PsNodeExtCache);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Op */
|
2001-08-26 22:28:18 +00:00
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
if (Op)
|
|
|
|
{
|
|
|
|
AcpiPsInitOp (Op, Opcode);
|
2002-07-09 17:51:31 +00:00
|
|
|
Op->Common.Flags = Flags;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsFreeOp
|
|
|
|
*
|
|
|
|
* PARAMETERS: Op - Op to be freed
|
|
|
|
*
|
|
|
|
* RETURN: None.
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list
|
|
|
|
* or actually free it.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
AcpiPsFreeOp (
|
|
|
|
ACPI_PARSE_OBJECT *Op)
|
|
|
|
{
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_NAME (PsFreeOp);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
if (Op->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2002-06-30 17:50:46 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n", Op));
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2002-07-30 19:33:39 +00:00
|
|
|
if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsReleaseObject (AcpiGbl_PsNodeCache, Op);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
(void) AcpiOsReleaseObject (AcpiGbl_PsNodeExtCache, Op);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: Utility functions
|
|
|
|
*
|
2001-09-07 01:22:25 +00:00
|
|
|
* DESCRIPTION: Low level character and object functions
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is "c" a namestring lead character?
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
AcpiPsIsLeadingChar (
|
|
|
|
UINT32 c)
|
|
|
|
{
|
|
|
|
return ((BOOLEAN) (c == '_' || (c >= 'A' && c <= 'Z')));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is "c" a namestring prefix character?
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
AcpiPsIsPrefixChar (
|
|
|
|
UINT32 c)
|
|
|
|
{
|
|
|
|
return ((BOOLEAN) (c == '\\' || c == '^'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get op's name (4-byte name segment) or 0 if unnamed
|
|
|
|
*/
|
|
|
|
UINT32
|
|
|
|
AcpiPsGetName (
|
|
|
|
ACPI_PARSE_OBJECT *Op)
|
|
|
|
{
|
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
/* The "generic" object has no name associated with it */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
|
2001-09-07 01:22:25 +00:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only the "Extended" parse objects have a name */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
return (Op->Named.Name);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set op's name
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AcpiPsSetName (
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
UINT32 name)
|
|
|
|
{
|
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
/* The "generic" object has no name associated with it */
|
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
|
2000-10-28 05:01:06 +00:00
|
|
|
{
|
2001-09-07 01:22:25 +00:00
|
|
|
return;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
2001-09-07 01:22:25 +00:00
|
|
|
|
2002-07-09 17:51:31 +00:00
|
|
|
Op->Named.Name = name;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|