psutils.c revision 217365
118316Swollman/****************************************************************************** 218316Swollman * 318316Swollman * Module Name: psutils - Parser miscellaneous utilities (Parser only) 418316Swollman * 518316Swollman *****************************************************************************/ 618316Swollman 718316Swollman/* 818316Swollman * Copyright (C) 2000 - 2011, Intel Corp. 918316Swollman * All rights reserved. 1018316Swollman * 1118316Swollman * Redistribution and use in source and binary forms, with or without 1218316Swollman * modification, are permitted provided that the following conditions 1318316Swollman * are met: 1418316Swollman * 1. Redistributions of source code must retain the above copyright 1518316Swollman * notice, this list of conditions, and the following disclaimer, 1618316Swollman * without modification. 1718316Swollman * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1818316Swollman * substantially similar to the "NO WARRANTY" disclaimer below 1918316Swollman * ("Disclaimer") and any redistribution must be conditioned upon 2018316Swollman * including a substantially similar Disclaimer requirement for further 2118316Swollman * binary redistribution. 2218316Swollman * 3. Neither the names of the above-listed copyright holders nor the names 2318316Swollman * of any contributors may be used to endorse or promote products derived 2418316Swollman * from this software without specific prior written permission. 2518316Swollman * 2618316Swollman * Alternatively, this software may be distributed under the terms of the 2718316Swollman * GNU General Public License ("GPL") version 2 as published by the Free 2818316Swollman * Software Foundation. 2918316Swollman * 3046303Smarkm * NO WARRANTY 3150476Speter * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3218316Swollman * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3318316Swollman * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3446303Smarkm * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3550969Speter * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3646303Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3746303Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3818316Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3918316Swollman * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4018316Swollman * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4118316Swollman * POSSIBILITY OF SUCH DAMAGES. 4218316Swollman */ 4318316Swollman 4418316Swollman 4518316Swollman#include <contrib/dev/acpica/include/acpi.h> 4618316Swollman#include <contrib/dev/acpica/include/accommon.h> 4718316Swollman#include <contrib/dev/acpica/include/acparser.h> 4818316Swollman#include <contrib/dev/acpica/include/amlcode.h> 4918316Swollman 5018316Swollman#define _COMPONENT ACPI_PARSER 5118316Swollman ACPI_MODULE_NAME ("psutils") 5218316Swollman 5318316Swollman 5437908Scharnier/******************************************************************************* 5518316Swollman * 5618316Swollman * FUNCTION: AcpiPsCreateScopeOp 5718316Swollman * 5818316Swollman * PARAMETERS: None 5918316Swollman * 6018316Swollman * RETURN: A new Scope object, null on failure 6118316Swollman * 6218316Swollman * DESCRIPTION: Create a Scope and associated namepath op with the root name 6318316Swollman * 6418316Swollman ******************************************************************************/ 6518316Swollman 6618316SwollmanACPI_PARSE_OBJECT * 6718316SwollmanAcpiPsCreateScopeOp ( 6818316Swollman void) 6918316Swollman{ 7018316Swollman ACPI_PARSE_OBJECT *ScopeOp; 7118316Swollman 7218316Swollman 7318316Swollman ScopeOp = AcpiPsAllocOp (AML_SCOPE_OP); 7418316Swollman if (!ScopeOp) 7518316Swollman { 7646303Smarkm return (NULL); 7746303Smarkm } 7818316Swollman 7918316Swollman ScopeOp->Named.Name = ACPI_ROOT_NAME; 8018316Swollman return (ScopeOp); 8118316Swollman} 8218316Swollman 83190711Sphk 8418316Swollman/******************************************************************************* 8546303Smarkm * 8618316Swollman * FUNCTION: AcpiPsInitOp 8718316Swollman * 8818316Swollman * PARAMETERS: Op - A newly allocated Op object 8946303Smarkm * Opcode - Opcode to store in the Op 9046303Smarkm * 9118316Swollman * RETURN: None 9218316Swollman * 9318316Swollman * DESCRIPTION: Initialize a parse (Op) object 9418316Swollman * 9518316Swollman ******************************************************************************/ 9618316Swollman 9718316Swollmanvoid 9818316SwollmanAcpiPsInitOp ( 9918316Swollman ACPI_PARSE_OBJECT *Op, 100126250Sbms UINT16 Opcode) 101126250Sbms{ 102126250Sbms ACPI_FUNCTION_ENTRY (); 103126250Sbms 104126250Sbms 105126250Sbms Op->Common.DescriptorType = ACPI_DESC_TYPE_PARSER; 10618316Swollman Op->Common.AmlOpcode = Opcode; 10718316Swollman 10818316Swollman ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (Op->Common.AmlOpName, 10918316Swollman (AcpiPsGetOpcodeInfo (Opcode))->Name, 11018316Swollman sizeof (Op->Common.AmlOpName))); 11118316Swollman} 11218316Swollman 11318316Swollman 11418316Swollman/******************************************************************************* 11546303Smarkm * 11646303Smarkm * FUNCTION: AcpiPsAllocOp 11746303Smarkm * 11846303Smarkm * PARAMETERS: Opcode - Opcode that will be stored in the new Op 11918316Swollman * 12018316Swollman * RETURN: Pointer to the new Op, null on failure 12118316Swollman * 12218316Swollman * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on 12318316Swollman * opcode. A cache of opcodes is available for the pure 12418316Swollman * GENERIC_OP, since this is by far the most commonly used. 12520342Swollman * 12620342Swollman ******************************************************************************/ 12718316Swollman 12818316SwollmanACPI_PARSE_OBJECT* 12918316SwollmanAcpiPsAllocOp ( 13018316Swollman UINT16 Opcode) 13118316Swollman{ 13218316Swollman ACPI_PARSE_OBJECT *Op; 13318316Swollman const ACPI_OPCODE_INFO *OpInfo; 13418316Swollman UINT8 Flags = ACPI_PARSEOP_GENERIC; 13518316Swollman 13618316Swollman 13718316Swollman ACPI_FUNCTION_ENTRY (); 13819885Swollman 13919885Swollman 14019885Swollman OpInfo = AcpiPsGetOpcodeInfo (Opcode); 14119885Swollman 14219885Swollman /* Determine type of ParseOp required */ 14319885Swollman 14418316Swollman if (OpInfo->Flags & AML_DEFER) 14519885Swollman { 14618316Swollman Flags = ACPI_PARSEOP_DEFERRED; 14718316Swollman } 14818316Swollman else if (OpInfo->Flags & AML_NAMED) 14918316Swollman { 15018316Swollman Flags = ACPI_PARSEOP_NAMED; 15118316Swollman } 15218316Swollman else if (Opcode == AML_INT_BYTELIST_OP) 15318316Swollman { 15418316Swollman Flags = ACPI_PARSEOP_BYTELIST; 15518316Swollman } 15618316Swollman 15718316Swollman /* Allocate the minimum required size object */ 15818316Swollman 15918316Swollman if (Flags == ACPI_PARSEOP_GENERIC) 16018316Swollman { 16118316Swollman /* The generic op (default) is by far the most common (16 to 1) */ 16218316Swollman 16319885Swollman Op = AcpiOsAcquireObject (AcpiGbl_PsNodeCache); 16419885Swollman } 16519885Swollman else 16619885Swollman { 16718316Swollman /* Extended parseop */ 16818316Swollman 16919885Swollman Op = AcpiOsAcquireObject (AcpiGbl_PsNodeExtCache); 17018316Swollman } 17118316Swollman 17218316Swollman /* Initialize the Op */ 17346303Smarkm 17446303Smarkm if (Op) 17546303Smarkm { 17618316Swollman AcpiPsInitOp (Op, Opcode); 17719885Swollman Op->Common.Flags = Flags; 17819885Swollman } 17918316Swollman 18018316Swollman return (Op); 18118316Swollman} 18218316Swollman 18318316Swollman 18418316Swollman/******************************************************************************* 18518316Swollman * 18618316Swollman * FUNCTION: AcpiPsFreeOp 18718316Swollman * 18818316Swollman * PARAMETERS: Op - Op to be freed 18918316Swollman * 19018316Swollman * RETURN: None. 19118316Swollman * 19218316Swollman * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list 19318316Swollman * or actually free it. 19418316Swollman * 19518316Swollman ******************************************************************************/ 19618316Swollman 19718316Swollmanvoid 19818316SwollmanAcpiPsFreeOp ( 19918316Swollman ACPI_PARSE_OBJECT *Op) 20018316Swollman{ 20118316Swollman ACPI_FUNCTION_NAME (PsFreeOp); 20218316Swollman 20318316Swollman 20418316Swollman if (Op->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP) 20518316Swollman { 20646303Smarkm ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n", Op)); 20718316Swollman } 20818316Swollman 20918316Swollman if (Op->Common.Flags & ACPI_PARSEOP_GENERIC) 21018316Swollman { 21118316Swollman (void) AcpiOsReleaseObject (AcpiGbl_PsNodeCache, Op); 21218316Swollman } 21346303Smarkm else 21446303Smarkm { 21546303Smarkm (void) AcpiOsReleaseObject (AcpiGbl_PsNodeExtCache, Op); 21646303Smarkm } 21746303Smarkm} 21846303Smarkm 21946303Smarkm 22046303Smarkm/******************************************************************************* 22118316Swollman * 22218316Swollman * FUNCTION: Utility functions 22318316Swollman * 22418316Swollman * DESCRIPTION: Low level character and object functions 22518316Swollman * 22618316Swollman ******************************************************************************/ 22718316Swollman 22818316Swollman 22918316Swollman/* 23018316Swollman * Is "c" a namestring lead character? 23118316Swollman */ 23218316SwollmanBOOLEAN 23318316SwollmanAcpiPsIsLeadingChar ( 23418316Swollman UINT32 c) 23518316Swollman{ 23618316Swollman return ((BOOLEAN) (c == '_' || (c >= 'A' && c <= 'Z'))); 23718316Swollman} 23818316Swollman 23918316Swollman 24018316Swollman/* 24118316Swollman * Is "c" a namestring prefix character? 24218316Swollman */ 24318316SwollmanBOOLEAN 24418316SwollmanAcpiPsIsPrefixChar ( 24518316Swollman UINT32 c) 24618316Swollman{ 24718316Swollman return ((BOOLEAN) (c == '\\' || c == '^')); 24846303Smarkm} 24918316Swollman 25018316Swollman 25118316Swollman/* 25218316Swollman * Get op's name (4-byte name segment) or 0 if unnamed 25318316Swollman */ 25418316SwollmanUINT32 25518316SwollmanAcpiPsGetName ( 25618316Swollman ACPI_PARSE_OBJECT *Op) 25718316Swollman{ 25818316Swollman 25918316Swollman /* The "generic" object has no name associated with it */ 26018316Swollman 26118316Swollman if (Op->Common.Flags & ACPI_PARSEOP_GENERIC) 26218316Swollman { 26318316Swollman return (0); 264190711Sphk } 265190713Sphk 26619885Swollman /* Only the "Extended" parse objects have a name */ 26719885Swollman 26819885Swollman return (Op->Named.Name); 26946303Smarkm} 27018316Swollman 27118316Swollman 27218316Swollman/* 27318316Swollman * Set op's name 27418316Swollman */ 27518316Swollmanvoid 27618316SwollmanAcpiPsSetName ( 27718316Swollman ACPI_PARSE_OBJECT *Op, 27818316Swollman UINT32 name) 27918316Swollman{ 28018316Swollman 28118316Swollman /* The "generic" object has no name associated with it */ 28218316Swollman 28318316Swollman if (Op->Common.Flags & ACPI_PARSEOP_GENERIC) 28419885Swollman { 28518316Swollman return; 28618316Swollman } 287126250Sbms 288126250Sbms Op->Named.Name = name; 289126250Sbms} 29018316Swollman 29118316Swollman