1db2bae30SDana Myers /******************************************************************************
2db2bae30SDana Myers *
3db2bae30SDana Myers * Module Name: psutils - Parser miscellaneous utilities (Parser only)
4db2bae30SDana Myers *
5db2bae30SDana Myers *****************************************************************************/
6db2bae30SDana Myers
726f3cdf0SGordon Ross /*
8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
9db2bae30SDana Myers * All rights reserved.
10db2bae30SDana Myers *
1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross * are met:
1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross * without modification.
1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross * binary redistribution.
2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross * from this software without specific prior written permission.
25db2bae30SDana Myers *
2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross * Software Foundation.
29db2bae30SDana Myers *
3026f3cdf0SGordon Ross * NO WARRANTY
3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross */
43db2bae30SDana Myers
44db2bae30SDana Myers #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46db2bae30SDana Myers #include "acparser.h"
47db2bae30SDana Myers #include "amlcode.h"
48db2bae30SDana Myers
49db2bae30SDana Myers #define _COMPONENT ACPI_PARSER
50db2bae30SDana Myers ACPI_MODULE_NAME ("psutils")
51db2bae30SDana Myers
52db2bae30SDana Myers
53db2bae30SDana Myers /*******************************************************************************
54db2bae30SDana Myers *
55db2bae30SDana Myers * FUNCTION: AcpiPsCreateScopeOp
56db2bae30SDana Myers *
57db2bae30SDana Myers * PARAMETERS: None
58db2bae30SDana Myers *
59db2bae30SDana Myers * RETURN: A new Scope object, null on failure
60db2bae30SDana Myers *
61db2bae30SDana Myers * DESCRIPTION: Create a Scope and associated namepath op with the root name
62db2bae30SDana Myers *
63db2bae30SDana Myers ******************************************************************************/
64db2bae30SDana Myers
65db2bae30SDana Myers ACPI_PARSE_OBJECT *
AcpiPsCreateScopeOp(UINT8 * Aml)66db2bae30SDana Myers AcpiPsCreateScopeOp (
67*cb565728SJerry Jelinek UINT8 *Aml)
68db2bae30SDana Myers {
69db2bae30SDana Myers ACPI_PARSE_OBJECT *ScopeOp;
70db2bae30SDana Myers
71db2bae30SDana Myers
72*cb565728SJerry Jelinek ScopeOp = AcpiPsAllocOp (AML_SCOPE_OP, Aml);
73db2bae30SDana Myers if (!ScopeOp)
74db2bae30SDana Myers {
75db2bae30SDana Myers return (NULL);
76db2bae30SDana Myers }
77db2bae30SDana Myers
78db2bae30SDana Myers ScopeOp->Named.Name = ACPI_ROOT_NAME;
79db2bae30SDana Myers return (ScopeOp);
80db2bae30SDana Myers }
81db2bae30SDana Myers
82db2bae30SDana Myers
83db2bae30SDana Myers /*******************************************************************************
84db2bae30SDana Myers *
85db2bae30SDana Myers * FUNCTION: AcpiPsInitOp
86db2bae30SDana Myers *
87db2bae30SDana Myers * PARAMETERS: Op - A newly allocated Op object
88db2bae30SDana Myers * Opcode - Opcode to store in the Op
89db2bae30SDana Myers *
90db2bae30SDana Myers * RETURN: None
91db2bae30SDana Myers *
92db2bae30SDana Myers * DESCRIPTION: Initialize a parse (Op) object
93db2bae30SDana Myers *
94db2bae30SDana Myers ******************************************************************************/
95db2bae30SDana Myers
96db2bae30SDana Myers void
AcpiPsInitOp(ACPI_PARSE_OBJECT * Op,UINT16 Opcode)97db2bae30SDana Myers AcpiPsInitOp (
98db2bae30SDana Myers ACPI_PARSE_OBJECT *Op,
99db2bae30SDana Myers UINT16 Opcode)
100db2bae30SDana Myers {
101db2bae30SDana Myers ACPI_FUNCTION_ENTRY ();
102db2bae30SDana Myers
103db2bae30SDana Myers
104db2bae30SDana Myers Op->Common.DescriptorType = ACPI_DESC_TYPE_PARSER;
105db2bae30SDana Myers Op->Common.AmlOpcode = Opcode;
106db2bae30SDana Myers
107*cb565728SJerry Jelinek ACPI_DISASM_ONLY_MEMBERS (strncpy (Op->Common.AmlOpName,
108db2bae30SDana Myers (AcpiPsGetOpcodeInfo (Opcode))->Name,
109db2bae30SDana Myers sizeof (Op->Common.AmlOpName)));
110db2bae30SDana Myers }
111db2bae30SDana Myers
112db2bae30SDana Myers
113db2bae30SDana Myers /*******************************************************************************
114db2bae30SDana Myers *
115db2bae30SDana Myers * FUNCTION: AcpiPsAllocOp
116db2bae30SDana Myers *
117db2bae30SDana Myers * PARAMETERS: Opcode - Opcode that will be stored in the new Op
118*cb565728SJerry Jelinek * Aml - Address of the opcode
119db2bae30SDana Myers *
120db2bae30SDana Myers * RETURN: Pointer to the new Op, null on failure
121db2bae30SDana Myers *
122db2bae30SDana Myers * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
123db2bae30SDana Myers * opcode. A cache of opcodes is available for the pure
124db2bae30SDana Myers * GENERIC_OP, since this is by far the most commonly used.
125db2bae30SDana Myers *
126db2bae30SDana Myers ******************************************************************************/
127db2bae30SDana Myers
128db2bae30SDana Myers ACPI_PARSE_OBJECT*
AcpiPsAllocOp(UINT16 Opcode,UINT8 * Aml)129db2bae30SDana Myers AcpiPsAllocOp (
130*cb565728SJerry Jelinek UINT16 Opcode,
131*cb565728SJerry Jelinek UINT8 *Aml)
132db2bae30SDana Myers {
133db2bae30SDana Myers ACPI_PARSE_OBJECT *Op;
134db2bae30SDana Myers const ACPI_OPCODE_INFO *OpInfo;
135db2bae30SDana Myers UINT8 Flags = ACPI_PARSEOP_GENERIC;
136db2bae30SDana Myers
137db2bae30SDana Myers
138db2bae30SDana Myers ACPI_FUNCTION_ENTRY ();
139db2bae30SDana Myers
140db2bae30SDana Myers
141db2bae30SDana Myers OpInfo = AcpiPsGetOpcodeInfo (Opcode);
142db2bae30SDana Myers
143db2bae30SDana Myers /* Determine type of ParseOp required */
144db2bae30SDana Myers
145db2bae30SDana Myers if (OpInfo->Flags & AML_DEFER)
146db2bae30SDana Myers {
147db2bae30SDana Myers Flags = ACPI_PARSEOP_DEFERRED;
148db2bae30SDana Myers }
149db2bae30SDana Myers else if (OpInfo->Flags & AML_NAMED)
150db2bae30SDana Myers {
151*cb565728SJerry Jelinek Flags = ACPI_PARSEOP_NAMED_OBJECT;
152db2bae30SDana Myers }
153db2bae30SDana Myers else if (Opcode == AML_INT_BYTELIST_OP)
154db2bae30SDana Myers {
155db2bae30SDana Myers Flags = ACPI_PARSEOP_BYTELIST;
156db2bae30SDana Myers }
157db2bae30SDana Myers
158db2bae30SDana Myers /* Allocate the minimum required size object */
159db2bae30SDana Myers
160db2bae30SDana Myers if (Flags == ACPI_PARSEOP_GENERIC)
161db2bae30SDana Myers {
162db2bae30SDana Myers /* The generic op (default) is by far the most common (16 to 1) */
163db2bae30SDana Myers
164db2bae30SDana Myers Op = AcpiOsAcquireObject (AcpiGbl_PsNodeCache);
165db2bae30SDana Myers }
166db2bae30SDana Myers else
167db2bae30SDana Myers {
168db2bae30SDana Myers /* Extended parseop */
169db2bae30SDana Myers
170db2bae30SDana Myers Op = AcpiOsAcquireObject (AcpiGbl_PsNodeExtCache);
171db2bae30SDana Myers }
172db2bae30SDana Myers
173db2bae30SDana Myers /* Initialize the Op */
174db2bae30SDana Myers
175db2bae30SDana Myers if (Op)
176db2bae30SDana Myers {
177db2bae30SDana Myers AcpiPsInitOp (Op, Opcode);
178*cb565728SJerry Jelinek Op->Common.Aml = Aml;
179db2bae30SDana Myers Op->Common.Flags = Flags;
180db2bae30SDana Myers }
181db2bae30SDana Myers
182db2bae30SDana Myers return (Op);
183db2bae30SDana Myers }
184db2bae30SDana Myers
185db2bae30SDana Myers
186db2bae30SDana Myers /*******************************************************************************
187db2bae30SDana Myers *
188db2bae30SDana Myers * FUNCTION: AcpiPsFreeOp
189db2bae30SDana Myers *
190db2bae30SDana Myers * PARAMETERS: Op - Op to be freed
191db2bae30SDana Myers *
192db2bae30SDana Myers * RETURN: None.
193db2bae30SDana Myers *
194db2bae30SDana Myers * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list
195db2bae30SDana Myers * or actually free it.
196db2bae30SDana Myers *
197db2bae30SDana Myers ******************************************************************************/
198db2bae30SDana Myers
199db2bae30SDana Myers void
AcpiPsFreeOp(ACPI_PARSE_OBJECT * Op)200db2bae30SDana Myers AcpiPsFreeOp (
201db2bae30SDana Myers ACPI_PARSE_OBJECT *Op)
202db2bae30SDana Myers {
203db2bae30SDana Myers ACPI_FUNCTION_NAME (PsFreeOp);
204db2bae30SDana Myers
205db2bae30SDana Myers
206db2bae30SDana Myers if (Op->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
207db2bae30SDana Myers {
208*cb565728SJerry Jelinek ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
209*cb565728SJerry Jelinek "Free retval op: %p\n", Op));
210db2bae30SDana Myers }
211db2bae30SDana Myers
212db2bae30SDana Myers if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
213db2bae30SDana Myers {
214db2bae30SDana Myers (void) AcpiOsReleaseObject (AcpiGbl_PsNodeCache, Op);
215db2bae30SDana Myers }
216db2bae30SDana Myers else
217db2bae30SDana Myers {
218db2bae30SDana Myers (void) AcpiOsReleaseObject (AcpiGbl_PsNodeExtCache, Op);
219db2bae30SDana Myers }
220db2bae30SDana Myers }
221db2bae30SDana Myers
222db2bae30SDana Myers
223db2bae30SDana Myers /*******************************************************************************
224db2bae30SDana Myers *
225db2bae30SDana Myers * FUNCTION: Utility functions
226db2bae30SDana Myers *
227db2bae30SDana Myers * DESCRIPTION: Low level character and object functions
228db2bae30SDana Myers *
229db2bae30SDana Myers ******************************************************************************/
230db2bae30SDana Myers
231db2bae30SDana Myers
232db2bae30SDana Myers /*
233db2bae30SDana Myers * Is "c" a namestring lead character?
234db2bae30SDana Myers */
235db2bae30SDana Myers BOOLEAN
AcpiPsIsLeadingChar(UINT32 c)236db2bae30SDana Myers AcpiPsIsLeadingChar (
237db2bae30SDana Myers UINT32 c)
238db2bae30SDana Myers {
239db2bae30SDana Myers return ((BOOLEAN) (c == '_' || (c >= 'A' && c <= 'Z')));
240db2bae30SDana Myers }
241db2bae30SDana Myers
242db2bae30SDana Myers
243db2bae30SDana Myers /*
244db2bae30SDana Myers * Get op's name (4-byte name segment) or 0 if unnamed
245db2bae30SDana Myers */
246db2bae30SDana Myers UINT32
AcpiPsGetName(ACPI_PARSE_OBJECT * Op)247db2bae30SDana Myers AcpiPsGetName (
248db2bae30SDana Myers ACPI_PARSE_OBJECT *Op)
249db2bae30SDana Myers {
250db2bae30SDana Myers
251db2bae30SDana Myers /* The "generic" object has no name associated with it */
252db2bae30SDana Myers
253db2bae30SDana Myers if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
254db2bae30SDana Myers {
255db2bae30SDana Myers return (0);
256db2bae30SDana Myers }
257db2bae30SDana Myers
258db2bae30SDana Myers /* Only the "Extended" parse objects have a name */
259db2bae30SDana Myers
260db2bae30SDana Myers return (Op->Named.Name);
261db2bae30SDana Myers }
262db2bae30SDana Myers
263db2bae30SDana Myers
264db2bae30SDana Myers /*
265db2bae30SDana Myers * Set op's name
266db2bae30SDana Myers */
267db2bae30SDana Myers void
AcpiPsSetName(ACPI_PARSE_OBJECT * Op,UINT32 name)268db2bae30SDana Myers AcpiPsSetName (
269db2bae30SDana Myers ACPI_PARSE_OBJECT *Op,
270db2bae30SDana Myers UINT32 name)
271db2bae30SDana Myers {
272db2bae30SDana Myers
273db2bae30SDana Myers /* The "generic" object has no name associated with it */
274db2bae30SDana Myers
275db2bae30SDana Myers if (Op->Common.Flags & ACPI_PARSEOP_GENERIC)
276db2bae30SDana Myers {
277db2bae30SDana Myers return;
278db2bae30SDana Myers }
279db2bae30SDana Myers
280db2bae30SDana Myers Op->Named.Name = name;
281db2bae30SDana Myers }
282