psutils.c revision 99146
1219820Sjeff/******************************************************************************
2219820Sjeff *
3219820Sjeff * Module Name: psutils - Parser miscellaneous utilities (Parser only)
4219820Sjeff *              $Revision: 50 $
5219820Sjeff *
6219820Sjeff *****************************************************************************/
7219820Sjeff
8219820Sjeff/******************************************************************************
9219820Sjeff *
10219820Sjeff * 1. Copyright Notice
11219820Sjeff *
12219820Sjeff * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13219820Sjeff * All rights reserved.
14219820Sjeff *
15219820Sjeff * 2. License
16219820Sjeff *
17219820Sjeff * 2.1. This is your license from Intel Corp. under its intellectual property
18219820Sjeff * rights.  You may have additional license terms from the party that provided
19219820Sjeff * you this software, covering your right to use that party's intellectual
20219820Sjeff * property rights.
21219820Sjeff *
22219820Sjeff * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23219820Sjeff * copy of the source code appearing in this file ("Covered Code") an
24219820Sjeff * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25219820Sjeff * base code distributed originally by Intel ("Original Intel Code") to copy,
26219820Sjeff * make derivatives, distribute, use and display any portion of the Covered
27219820Sjeff * Code in any form, with the right to sublicense such rights; and
28219820Sjeff *
29219820Sjeff * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30219820Sjeff * license (with the right to sublicense), under only those claims of Intel
31219820Sjeff * patents that are infringed by the Original Intel Code, to make, use, sell,
32219820Sjeff * offer to sell, and import the Covered Code and derivative works thereof
33219820Sjeff * solely to the minimum extent necessary to exercise the above copyright
34219820Sjeff * license, and in no event shall the patent license extend to any additions
35219820Sjeff * to or modifications of the Original Intel Code.  No other license or right
36219820Sjeff * is granted directly or by implication, estoppel or otherwise;
37219820Sjeff *
38219820Sjeff * The above copyright and patent license is granted only if the following
39219820Sjeff * conditions are met:
40219820Sjeff *
41219820Sjeff * 3. Conditions
42219820Sjeff *
43219820Sjeff * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44219820Sjeff * Redistribution of source code of any substantial portion of the Covered
45219820Sjeff * Code or modification with rights to further distribute source must include
46219820Sjeff * the above Copyright Notice, the above License, this list of Conditions,
47219820Sjeff * and the following Disclaimer and Export Compliance provision.  In addition,
48219820Sjeff * Licensee must cause all Covered Code to which Licensee contributes to
49219820Sjeff * contain a file documenting the changes Licensee made to create that Covered
50219820Sjeff * Code and the date of any change.  Licensee must include in that file the
51219820Sjeff * documentation of any changes made by any predecessor Licensee.  Licensee
52219820Sjeff * must include a prominent statement that the modification is derived,
53219820Sjeff * directly or indirectly, from Original Intel Code.
54219820Sjeff *
55219820Sjeff * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56219820Sjeff * Redistribution of source code of any substantial portion of the Covered
57219820Sjeff * Code or modification without rights to further distribute source must
58219820Sjeff * include the following Disclaimer and Export Compliance provision in the
59219820Sjeff * documentation and/or other materials provided with distribution.  In
60219820Sjeff * addition, Licensee may not authorize further sublicense of source of any
61219820Sjeff * portion of the Covered Code, and must include terms to the effect that the
62219820Sjeff * license from Licensee to its licensee is limited to the intellectual
63219820Sjeff * property embodied in the software Licensee provides to its licensee, and
64219820Sjeff * not to intellectual property embodied in modifications its licensee may
65219820Sjeff * make.
66219820Sjeff *
67219820Sjeff * 3.3. Redistribution of Executable. Redistribution in executable form of any
68219820Sjeff * substantial portion of the Covered Code or modification must reproduce the
69219820Sjeff * above Copyright Notice, and the following Disclaimer and Export Compliance
70219820Sjeff * provision in the documentation and/or other materials provided with the
71219820Sjeff * distribution.
72219820Sjeff *
73219820Sjeff * 3.4. Intel retains all right, title, and interest in and to the Original
74219820Sjeff * Intel Code.
75219820Sjeff *
76219820Sjeff * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77219820Sjeff * Intel shall be used in advertising or otherwise to promote the sale, use or
78219820Sjeff * other dealings in products derived from or relating to the Covered Code
79219820Sjeff * without prior written authorization from Intel.
80219820Sjeff *
81219820Sjeff * 4. Disclaimer and Export Compliance
82219820Sjeff *
83219820Sjeff * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84219820Sjeff * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85219820Sjeff * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86219820Sjeff * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87219820Sjeff * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88219820Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89219820Sjeff * PARTICULAR PURPOSE.
90219820Sjeff *
91219820Sjeff * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92219820Sjeff * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93219820Sjeff * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94219820Sjeff * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95219820Sjeff * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96219820Sjeff * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97219820Sjeff * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98219820Sjeff * LIMITED REMEDY.
99219820Sjeff *
100219820Sjeff * 4.3. Licensee shall not export, either directly or indirectly, any of this
101219820Sjeff * software or system incorporating such software without first obtaining any
102219820Sjeff * required license or other approval from the U. S. Department of Commerce or
103219820Sjeff * any other agency or department of the United States Government.  In the
104219820Sjeff * event Licensee exports any such software from the United States or
105219820Sjeff * re-exports any such software from a foreign destination, Licensee shall
106219820Sjeff * ensure that the distribution and export/re-export of the software is in
107219820Sjeff * compliance with all laws, regulations, orders, or other restrictions of the
108219820Sjeff * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109219820Sjeff * any of its subsidiaries will export/re-export any technical data, process,
110219820Sjeff * software, or service, directly or indirectly, to any country for which the
111219820Sjeff * United States government or any agency thereof requires an export license,
112219820Sjeff * other governmental approval, or letter of assurance, without first obtaining
113219820Sjeff * such license, approval or letter.
114219820Sjeff *
115219820Sjeff *****************************************************************************/
116219820Sjeff
117219820Sjeff
118219820Sjeff#include "acpi.h"
119219820Sjeff#include "acparser.h"
120219820Sjeff#include "amlcode.h"
121219820Sjeff
122219820Sjeff#define _COMPONENT          ACPI_PARSER
123219820Sjeff        ACPI_MODULE_NAME    ("psutils")
124219820Sjeff
125219820Sjeff
126219820Sjeff/*******************************************************************************
127219820Sjeff *
128219820Sjeff * FUNCTION:    AcpiPsInitOp
129219820Sjeff *
130219820Sjeff * PARAMETERS:  Op              - A newly allocated Op object
131219820Sjeff *              Opcode          - Opcode to store in the Op
132219820Sjeff *
133219820Sjeff * RETURN:      Status
134219820Sjeff *
135219820Sjeff * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
136219820Sjeff *              opcode
137219820Sjeff *
138219820Sjeff ******************************************************************************/
139219820Sjeff
140219820Sjeffvoid
141219820SjeffAcpiPsInitOp (
142219820Sjeff    ACPI_PARSE_OBJECT       *Op,
143219820Sjeff    UINT16                  Opcode)
144219820Sjeff{
145219820Sjeff    ACPI_FUNCTION_ENTRY ();
146219820Sjeff
147219820Sjeff
148219820Sjeff    Op->DataType = ACPI_DESC_TYPE_PARSER;
149219820Sjeff    Op->Opcode = Opcode;
150219820Sjeff
151219820Sjeff    ACPI_DEBUG_ONLY_MEMBERS (ACPI_STRNCPY (Op->OpName,
152219820Sjeff            (AcpiPsGetOpcodeInfo (Opcode))->Name, sizeof (Op->OpName)));
153219820Sjeff}
154219820Sjeff
155219820Sjeff
156219820Sjeff/*******************************************************************************
157219820Sjeff *
158219820Sjeff * FUNCTION:    AcpiPsAllocOp
159219820Sjeff *
160219820Sjeff * PARAMETERS:  Opcode          - Opcode that will be stored in the new Op
161219820Sjeff *
162219820Sjeff * RETURN:      Pointer to the new Op.
163219820Sjeff *
164219820Sjeff * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
165219820Sjeff *              opcode.  A cache of opcodes is available for the pure
166219820Sjeff *              GENERIC_OP, since this is by far the most commonly used.
167219820Sjeff *
168219820Sjeff ******************************************************************************/
169219820Sjeff
170219820SjeffACPI_PARSE_OBJECT*
171219820SjeffAcpiPsAllocOp (
172219820Sjeff    UINT16                  Opcode)
173219820Sjeff{
174219820Sjeff    ACPI_PARSE_OBJECT       *Op = NULL;
175219820Sjeff    UINT32                  Size;
176219820Sjeff    UINT8                   Flags;
177219820Sjeff    const ACPI_OPCODE_INFO  *OpInfo;
178219820Sjeff
179219820Sjeff
180219820Sjeff    ACPI_FUNCTION_ENTRY ();
181219820Sjeff
182219820Sjeff
183219820Sjeff    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
184219820Sjeff
185219820Sjeff    /* Allocate the minimum required size object */
186219820Sjeff
187219820Sjeff    if (OpInfo->Flags & AML_DEFER)
188219820Sjeff    {
189219820Sjeff        Size = sizeof (ACPI_PARSE2_OBJECT);
190219820Sjeff        Flags = ACPI_PARSEOP_DEFERRED;
191219820Sjeff    }
192219820Sjeff    else if (OpInfo->Flags & AML_NAMED)
193219820Sjeff    {
194219820Sjeff        Size = sizeof (ACPI_PARSE2_OBJECT);
195219820Sjeff        Flags = ACPI_PARSEOP_NAMED;
196219820Sjeff    }
197219820Sjeff    else if (Opcode == AML_INT_BYTELIST_OP)
198219820Sjeff    {
199219820Sjeff        Size = sizeof (ACPI_PARSE2_OBJECT);
200219820Sjeff        Flags = ACPI_PARSEOP_BYTELIST;
201219820Sjeff    }
202219820Sjeff    else
203219820Sjeff    {
204219820Sjeff        Size = sizeof (ACPI_PARSE_OBJECT);
205219820Sjeff        Flags = ACPI_PARSEOP_GENERIC;
206219820Sjeff    }
207219820Sjeff
208219820Sjeff    if (Size == sizeof (ACPI_PARSE_OBJECT))
209219820Sjeff    {
210219820Sjeff        /*
211219820Sjeff         * The generic op is by far the most common (16 to 1)
212219820Sjeff         */
213219820Sjeff        Op = AcpiUtAcquireFromCache (ACPI_MEM_LIST_PSNODE);
214219820Sjeff    }
215219820Sjeff    else
216219820Sjeff    {
217219820Sjeff        Op = AcpiUtAcquireFromCache (ACPI_MEM_LIST_PSNODE_EXT);
218219820Sjeff    }
219219820Sjeff
220219820Sjeff    /* Initialize the Op */
221219820Sjeff
222219820Sjeff    if (Op)
223219820Sjeff    {
224219820Sjeff        AcpiPsInitOp (Op, Opcode);
225219820Sjeff        Op->Flags = Flags;
226219820Sjeff    }
227219820Sjeff
228219820Sjeff    return (Op);
229219820Sjeff}
230219820Sjeff
231219820Sjeff
232219820Sjeff/*******************************************************************************
233219820Sjeff *
234219820Sjeff * FUNCTION:    AcpiPsFreeOp
235219820Sjeff *
236219820Sjeff * PARAMETERS:  Op              - Op to be freed
237219820Sjeff *
238219820Sjeff * RETURN:      None.
239219820Sjeff *
240219820Sjeff * DESCRIPTION: Free an Op object.  Either put it on the GENERIC_OP cache list
241219820Sjeff *              or actually free it.
242219820Sjeff *
243219820Sjeff ******************************************************************************/
244219820Sjeff
245219820Sjeffvoid
246219820SjeffAcpiPsFreeOp (
247219820Sjeff    ACPI_PARSE_OBJECT       *Op)
248219820Sjeff{
249219820Sjeff    ACPI_FUNCTION_NAME ("PsFreeOp");
250219820Sjeff
251219820Sjeff
252219820Sjeff    if (Op->Opcode == AML_INT_RETURN_VALUE_OP)
253219820Sjeff    {
254219820Sjeff        ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n", Op));
255219820Sjeff    }
256219820Sjeff
257219820Sjeff    if (Op->Flags == ACPI_PARSEOP_GENERIC)
258219820Sjeff    {
259219820Sjeff        AcpiUtReleaseToCache (ACPI_MEM_LIST_PSNODE, Op);
260219820Sjeff    }
261219820Sjeff    else
262219820Sjeff    {
263219820Sjeff        AcpiUtReleaseToCache (ACPI_MEM_LIST_PSNODE_EXT, Op);
264219820Sjeff    }
265219820Sjeff}
266219820Sjeff
267219820Sjeff
268219820Sjeff/*******************************************************************************
269219820Sjeff *
270219820Sjeff * FUNCTION:    AcpiPsDeleteParseCache
271219820Sjeff *
272219820Sjeff * PARAMETERS:  None
273219820Sjeff *
274219820Sjeff * RETURN:      None
275219820Sjeff *
276219820Sjeff * DESCRIPTION: Free all objects that are on the parse cache list.
277219820Sjeff *
278219820Sjeff ******************************************************************************/
279219820Sjeff
280219820Sjeffvoid
281219820SjeffAcpiPsDeleteParseCache (
282219820Sjeff    void)
283219820Sjeff{
284219820Sjeff    ACPI_FUNCTION_TRACE ("PsDeleteParseCache");
285219820Sjeff
286219820Sjeff
287219820Sjeff    AcpiUtDeleteGenericCache (ACPI_MEM_LIST_PSNODE);
288219820Sjeff    AcpiUtDeleteGenericCache (ACPI_MEM_LIST_PSNODE_EXT);
289219820Sjeff    return_VOID;
290219820Sjeff}
291219820Sjeff
292219820Sjeff
293219820Sjeff/*******************************************************************************
294219820Sjeff *
295219820Sjeff * FUNCTION:    Utility functions
296219820Sjeff *
297219820Sjeff * DESCRIPTION: Low level character and object functions
298219820Sjeff *
299219820Sjeff ******************************************************************************/
300219820Sjeff
301219820Sjeff
302219820Sjeff/*
303219820Sjeff * Is "c" a namestring lead character?
304219820Sjeff */
305219820SjeffBOOLEAN
306219820SjeffAcpiPsIsLeadingChar (
307219820Sjeff    UINT32                  c)
308219820Sjeff{
309219820Sjeff    return ((BOOLEAN) (c == '_' || (c >= 'A' && c <= 'Z')));
310219820Sjeff}
311219820Sjeff
312219820Sjeff
313219820Sjeff/*
314219820Sjeff * Is "c" a namestring prefix character?
315219820Sjeff */
316219820SjeffBOOLEAN
317219820SjeffAcpiPsIsPrefixChar (
318219820Sjeff    UINT32                  c)
319219820Sjeff{
320219820Sjeff    return ((BOOLEAN) (c == '\\' || c == '^'));
321219820Sjeff}
322219820Sjeff
323219820Sjeff
324219820Sjeff/*
325219820Sjeff * Get op's name (4-byte name segment) or 0 if unnamed
326219820Sjeff */
327219820SjeffUINT32
328219820SjeffAcpiPsGetName (
329219820Sjeff    ACPI_PARSE_OBJECT       *Op)
330219820Sjeff{
331219820Sjeff
332219820Sjeff
333219820Sjeff    /* The "generic" object has no name associated with it */
334219820Sjeff
335219820Sjeff    if (Op->Flags & ACPI_PARSEOP_GENERIC)
336219820Sjeff    {
337219820Sjeff        return (0);
338219820Sjeff    }
339219820Sjeff
340219820Sjeff    /* Only the "Extended" parse objects have a name */
341219820Sjeff
342219820Sjeff    return (((ACPI_PARSE2_OBJECT *) Op)->Name);
343219820Sjeff}
344219820Sjeff
345219820Sjeff
346219820Sjeff/*
347219820Sjeff * Set op's name
348219820Sjeff */
349219820Sjeffvoid
350219820SjeffAcpiPsSetName (
351219820Sjeff    ACPI_PARSE_OBJECT       *Op,
352219820Sjeff    UINT32                  name)
353219820Sjeff{
354219820Sjeff
355219820Sjeff    /* The "generic" object has no name associated with it */
356219820Sjeff
357219820Sjeff    if (Op->Flags & ACPI_PARSEOP_GENERIC)
358219820Sjeff    {
359219820Sjeff        return;
360219820Sjeff    }
361219820Sjeff
362219820Sjeff    ((ACPI_PARSE2_OBJECT *) Op)->Name = name;
363219820Sjeff}
364219820Sjeff
365219820Sjeff