1 /******************************************************************************
3 * Module Name: psutils - Parser miscellaneous utilities (Parser only)
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #define _COMPONENT ACPI_PARSER
32 MODULE_NAME ("psutils")
35 #define PARSEOP_GENERIC 0x01
36 #define PARSEOP_NAMED 0x02
37 #define PARSEOP_DEFERRED 0x04
38 #define PARSEOP_BYTELIST 0x08
39 #define PARSEOP_IN_CACHE 0x80
42 /*******************************************************************************
44 * FUNCTION: Acpi_ps_init_op
46 * PARAMETERS: Op - A newly allocated Op object
47 * Opcode - Opcode to store in the Op
51 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
54 ******************************************************************************/
58 acpi_parse_object *op,
61 const acpi_opcode_info *aml_op;
67 op->data_type = ACPI_DESC_TYPE_PARSER;
70 aml_op = acpi_ps_get_opcode_info (opcode);
72 DEBUG_ONLY_MEMBERS (STRNCPY (op->op_name, aml_op->name,
73 sizeof (op->op_name)));
77 /*******************************************************************************
79 * FUNCTION: Acpi_ps_alloc_op
81 * PARAMETERS: Opcode - Opcode that will be stored in the new Op
83 * RETURN: Pointer to the new Op.
85 * DESCRIPTION: Allocate an acpi_op, choose op type (and thus size) based on
86 * opcode. A cache of opcodes is available for the pure
87 * GENERIC_OP, since this is by far the most commonly used.
89 ******************************************************************************/
95 acpi_parse_object *op = NULL;
98 const acpi_opcode_info *op_info;
104 op_info = acpi_ps_get_opcode_info (opcode);
106 /* Allocate the minimum required size object */
108 if (op_info->flags & AML_DEFER) {
109 size = sizeof (acpi_parse2_object);
110 flags = PARSEOP_DEFERRED;
113 else if (op_info->flags & AML_NAMED) {
114 size = sizeof (acpi_parse2_object);
115 flags = PARSEOP_NAMED;
118 else if (opcode == AML_INT_BYTELIST_OP) {
119 size = sizeof (acpi_parse2_object);
120 flags = PARSEOP_BYTELIST;
124 size = sizeof (acpi_parse_object);
125 flags = PARSEOP_GENERIC;
129 if (size == sizeof (acpi_parse_object)) {
131 * The generic op is by far the most common (16 to 1)
133 op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE);
137 op = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_PSNODE_EXT);
140 /* Initialize the Op */
143 acpi_ps_init_op (op, opcode);
151 /*******************************************************************************
153 * FUNCTION: Acpi_ps_free_op
155 * PARAMETERS: Op - Op to be freed
159 * DESCRIPTION: Free an Op object. Either put it on the GENERIC_OP cache list
160 * or actually free it.
162 ******************************************************************************/
166 acpi_parse_object *op)
168 PROC_NAME ("Ps_free_op");
171 if (op->opcode == AML_INT_RETURN_VALUE_OP) {
172 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Free retval op: %p\n", op));
175 if (op->flags == PARSEOP_GENERIC) {
176 acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE, op);
180 acpi_ut_release_to_cache (ACPI_MEM_LIST_PSNODE_EXT, op);
185 /*******************************************************************************
187 * FUNCTION: Acpi_ps_delete_parse_cache
193 * DESCRIPTION: Free all objects that are on the parse cache list.
195 ******************************************************************************/
198 acpi_ps_delete_parse_cache (
201 FUNCTION_TRACE ("Ps_delete_parse_cache");
204 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE);
205 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_PSNODE_EXT);
210 /*******************************************************************************
212 * FUNCTION: Utility functions
214 * DESCRIPTION: Low level character and object functions
216 ******************************************************************************/
220 * Is "c" a namestring lead character?
223 acpi_ps_is_leading_char (
226 return ((u8) (c == '_' || (c >= 'A' && c <= 'Z')));
231 * Is "c" a namestring prefix character?
234 acpi_ps_is_prefix_char (
237 return ((u8) (c == '\\' || c == '^'));
242 * Get op's name (4-byte name segment) or 0 if unnamed
246 acpi_parse_object *op)
250 /* The "generic" object has no name associated with it */
252 if (op->flags & PARSEOP_GENERIC) {
256 /* Only the "Extended" parse objects have a name */
258 return (((acpi_parse2_object *) op)->name);
267 acpi_parse_object *op,
271 /* The "generic" object has no name associated with it */
273 if (op->flags & PARSEOP_GENERIC) {
277 ((acpi_parse2_object *) op)->name = name;