psutils.c 6.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: psutils - Parser miscellaneous utilities (Parser only)
 *
 *****************************************************************************/

/*
B
Bob Moore 已提交
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 * All rights reserved.
 *
 * 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.
 */

#include <acpi/acpi.h>
#include <acpi/acparser.h>
#include <acpi/amlcode.h>

#define _COMPONENT          ACPI_PARSER
L
Len Brown 已提交
49
ACPI_MODULE_NAME("psutils")
L
Linus Torvalds 已提交
50 51 52 53 54 55 56

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_create_scope_op
 *
 * PARAMETERS:  None
 *
R
Robert Moore 已提交
57
 * RETURN:      A new Scope object, null on failure
L
Linus Torvalds 已提交
58 59 60 61
 *
 * DESCRIPTION: Create a Scope and associated namepath op with the root name
 *
 ******************************************************************************/
L
Len Brown 已提交
62
union acpi_parse_object *acpi_ps_create_scope_op(void)
L
Linus Torvalds 已提交
63
{
L
Len Brown 已提交
64
	union acpi_parse_object *scope_op;
L
Linus Torvalds 已提交
65

L
Len Brown 已提交
66
	scope_op = acpi_ps_alloc_op(AML_SCOPE_OP);
L
Linus Torvalds 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	if (!scope_op) {
		return (NULL);
	}

	scope_op->named.name = ACPI_ROOT_NAME;
	return (scope_op);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_init_op
 *
 * PARAMETERS:  Op              - A newly allocated Op object
 *              Opcode          - Opcode to store in the Op
 *
R
Robert Moore 已提交
82
 * RETURN:      None
L
Linus Torvalds 已提交
83
 *
R
Robert Moore 已提交
84
 * DESCRIPTION: Initialize a parse (Op) object
L
Linus Torvalds 已提交
85 86 87
 *
 ******************************************************************************/

L
Len Brown 已提交
88
void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode)
L
Linus Torvalds 已提交
89
{
L
Len Brown 已提交
90
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
91

B
Bob Moore 已提交
92
	op->common.descriptor_type = ACPI_DESC_TYPE_PARSER;
L
Linus Torvalds 已提交
93 94
	op->common.aml_opcode = opcode;

L
Len Brown 已提交
95 96 97 98
	ACPI_DISASM_ONLY_MEMBERS(ACPI_STRNCPY(op->common.aml_op_name,
					      (acpi_ps_get_opcode_info
					       (opcode))->name,
					      sizeof(op->common.aml_op_name)));
L
Linus Torvalds 已提交
99 100 101 102 103 104 105 106
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_alloc_op
 *
 * PARAMETERS:  Opcode          - Opcode that will be stored in the new Op
 *
R
Robert Moore 已提交
107
 * RETURN:      Pointer to the new Op, null on failure
L
Linus Torvalds 已提交
108 109 110 111 112 113 114
 *
 * 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.
 *
 ******************************************************************************/

L
Len Brown 已提交
115
union acpi_parse_object *acpi_ps_alloc_op(u16 opcode)
L
Linus Torvalds 已提交
116
{
L
Len Brown 已提交
117 118 119
	union acpi_parse_object *op;
	const struct acpi_opcode_info *op_info;
	u8 flags = ACPI_PARSEOP_GENERIC;
L
Linus Torvalds 已提交
120

L
Len Brown 已提交
121
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
122

L
Len Brown 已提交
123
	op_info = acpi_ps_get_opcode_info(opcode);
L
Linus Torvalds 已提交
124 125 126 127 128

	/* Determine type of parse_op required */

	if (op_info->flags & AML_DEFER) {
		flags = ACPI_PARSEOP_DEFERRED;
L
Len Brown 已提交
129
	} else if (op_info->flags & AML_NAMED) {
L
Linus Torvalds 已提交
130
		flags = ACPI_PARSEOP_NAMED;
L
Len Brown 已提交
131
	} else if (opcode == AML_INT_BYTELIST_OP) {
L
Linus Torvalds 已提交
132 133 134 135 136 137
		flags = ACPI_PARSEOP_BYTELIST;
	}

	/* Allocate the minimum required size object */

	if (flags == ACPI_PARSEOP_GENERIC) {
B
Bob Moore 已提交
138

L
Linus Torvalds 已提交
139 140
		/* The generic op (default) is by far the most common (16 to 1) */

L
Len Brown 已提交
141 142
		op = acpi_os_acquire_object(acpi_gbl_ps_node_cache);
	} else {
L
Linus Torvalds 已提交
143 144
		/* Extended parseop */

L
Len Brown 已提交
145
		op = acpi_os_acquire_object(acpi_gbl_ps_node_ext_cache);
L
Linus Torvalds 已提交
146 147 148 149 150
	}

	/* Initialize the Op */

	if (op) {
L
Len Brown 已提交
151
		acpi_ps_init_op(op, opcode);
L
Linus Torvalds 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
		op->common.flags = flags;
	}

	return (op);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_free_op
 *
 * 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.
 *
 ******************************************************************************/

L
Len Brown 已提交
171
void acpi_ps_free_op(union acpi_parse_object *op)
L
Linus Torvalds 已提交
172
{
B
Bob Moore 已提交
173
	ACPI_FUNCTION_NAME(ps_free_op);
L
Linus Torvalds 已提交
174 175

	if (op->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
L
Len Brown 已提交
176 177
		ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS, "Free retval op: %p\n",
				  op));
L
Linus Torvalds 已提交
178 179 180
	}

	if (op->common.flags & ACPI_PARSEOP_GENERIC) {
L
Len Brown 已提交
181 182 183
		(void)acpi_os_release_object(acpi_gbl_ps_node_cache, op);
	} else {
		(void)acpi_os_release_object(acpi_gbl_ps_node_ext_cache, op);
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197
	}
}

/*******************************************************************************
 *
 * FUNCTION:    Utility functions
 *
 * DESCRIPTION: Low level character and object functions
 *
 ******************************************************************************/

/*
 * Is "c" a namestring lead character?
 */
L
Len Brown 已提交
198
u8 acpi_ps_is_leading_char(u32 c)
L
Linus Torvalds 已提交
199 200 201 202 203 204 205
{
	return ((u8) (c == '_' || (c >= 'A' && c <= 'Z')));
}

/*
 * Is "c" a namestring prefix character?
 */
L
Len Brown 已提交
206
u8 acpi_ps_is_prefix_char(u32 c)
L
Linus Torvalds 已提交
207 208 209 210 211 212 213 214
{
	return ((u8) (c == '\\' || c == '^'));
}

/*
 * Get op's name (4-byte name segment) or 0 if unnamed
 */
#ifdef ACPI_FUTURE_USAGE
L
Len Brown 已提交
215
u32 acpi_ps_get_name(union acpi_parse_object * op)
L
Linus Torvalds 已提交
216 217 218 219 220 221 222 223 224 225 226 227
{

	/* The "generic" object has no name associated with it */

	if (op->common.flags & ACPI_PARSEOP_GENERIC) {
		return (0);
	}

	/* Only the "Extended" parse objects have a name */

	return (op->named.name);
}
L
Len Brown 已提交
228
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
229 230 231 232

/*
 * Set op's name
 */
L
Len Brown 已提交
233
void acpi_ps_set_name(union acpi_parse_object *op, u32 name)
L
Linus Torvalds 已提交
234 235 236 237 238 239 240 241 242 243
{

	/* The "generic" object has no name associated with it */

	if (op->common.flags & ACPI_PARSEOP_GENERIC) {
		return;
	}

	op->named.name = name;
}