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)
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2011, Intel Corp.
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
 * 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>
L
Len Brown 已提交
45 46 47
#include "accommon.h"
#include "acparser.h"
#include "amlcode.h"
L
Linus Torvalds 已提交
48 49

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

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

L
Len Brown 已提交
67
	scope_op = acpi_ps_alloc_op(AML_SCOPE_OP);
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
	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 已提交
83
 * RETURN:      None
L
Linus Torvalds 已提交
84
 *
R
Robert Moore 已提交
85
 * DESCRIPTION: Initialize a parse (Op) object
L
Linus Torvalds 已提交
86 87 88
 *
 ******************************************************************************/

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

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

L
Len Brown 已提交
96 97 98 99
	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 已提交
100 101 102 103 104 105 106 107
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ps_alloc_op
 *
 * PARAMETERS:  Opcode          - Opcode that will be stored in the new Op
 *
R
Robert Moore 已提交
108
 * RETURN:      Pointer to the new Op, null on failure
L
Linus Torvalds 已提交
109 110 111 112 113 114 115
 *
 * 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 已提交
116
union acpi_parse_object *acpi_ps_alloc_op(u16 opcode)
L
Linus Torvalds 已提交
117
{
L
Len Brown 已提交
118 119 120
	union acpi_parse_object *op;
	const struct acpi_opcode_info *op_info;
	u8 flags = ACPI_PARSEOP_GENERIC;
L
Linus Torvalds 已提交
121

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

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

	/* Determine type of parse_op required */

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

	/* Allocate the minimum required size object */

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

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

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

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

	/* Initialize the Op */

	if (op) {
L
Len Brown 已提交
152
		acpi_ps_init_op(op, opcode);
L
Linus Torvalds 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
		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 已提交
172
void acpi_ps_free_op(union acpi_parse_object *op)
L
Linus Torvalds 已提交
173
{
B
Bob Moore 已提交
174
	ACPI_FUNCTION_NAME(ps_free_op);
L
Linus Torvalds 已提交
175 176

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

	if (op->common.flags & ACPI_PARSEOP_GENERIC) {
L
Len Brown 已提交
182 183 184
		(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 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198
	}
}

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

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

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

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

	/* 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 已提交
229
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
230 231 232 233

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

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

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

	op->named.name = name;
}