nsparse.c 6.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: nsparse - namespace interface to AML parser
 *
 *****************************************************************************/

/*
L
Len Brown 已提交
8
 * Copyright (C) 2000 - 2008, 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>
45
#include <acpi/accommon.h>
L
Linus Torvalds 已提交
46 47 48
#include <acpi/acnamesp.h>
#include <acpi/acparser.h>
#include <acpi/acdispat.h>
49
#include <acpi/actables.h>
L
Linus Torvalds 已提交
50 51

#define _COMPONENT          ACPI_NAMESPACE
L
Len Brown 已提交
52
ACPI_MODULE_NAME("nsparse")
L
Linus Torvalds 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66

/*******************************************************************************
 *
 * FUNCTION:    ns_one_complete_parse
 *
 * PARAMETERS:  pass_number             - 1 or 2
 *              table_desc              - The table to be parsed.
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
 *
 ******************************************************************************/
acpi_status
67 68 69
acpi_ns_one_complete_parse(u32 pass_number,
			   u32 table_index,
			   struct acpi_namespace_node *start_node)
L
Linus Torvalds 已提交
70
{
L
Len Brown 已提交
71 72
	union acpi_parse_object *parse_root;
	acpi_status status;
73
       u32 aml_length;
74
	u8 *aml_start;
L
Len Brown 已提交
75
	struct acpi_walk_state *walk_state;
76 77
	struct acpi_table_header *table;
	acpi_owner_id owner_id;
L
Linus Torvalds 已提交
78

B
Bob Moore 已提交
79
	ACPI_FUNCTION_TRACE(ns_one_complete_parse);
L
Linus Torvalds 已提交
80

81 82 83 84 85
	status = acpi_tb_get_owner_id(table_index, &owner_id);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

L
Linus Torvalds 已提交
86 87
	/* Create and init a Root Node */

L
Len Brown 已提交
88
	parse_root = acpi_ps_create_scope_op();
L
Linus Torvalds 已提交
89
	if (!parse_root) {
L
Len Brown 已提交
90
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
91 92 93 94
	}

	/* Create and initialize a new walk state */

95
	walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL);
L
Linus Torvalds 已提交
96
	if (!walk_state) {
L
Len Brown 已提交
97 98
		acpi_ps_free_op(parse_root);
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
99 100
	}

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	status = acpi_get_table_by_index(table_index, &table);
	if (ACPI_FAILURE(status)) {
		acpi_ds_delete_walk_state(walk_state);
		acpi_ps_free_op(parse_root);
		return_ACPI_STATUS(status);
	}

	/* Table must consist of at least a complete header */

	if (table->length < sizeof(struct acpi_table_header)) {
		status = AE_BAD_HEADER;
	} else {
		aml_start = (u8 *) table + sizeof(struct acpi_table_header);
		aml_length = table->length - sizeof(struct acpi_table_header);
		status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
116 117
					       aml_start, aml_length, NULL,
					       (u8) pass_number);
118 119
	}

L
Len Brown 已提交
120 121
	if (ACPI_FAILURE(status)) {
		acpi_ds_delete_walk_state(walk_state);
122
		goto cleanup;
L
Linus Torvalds 已提交
123 124
	}

125 126 127
	/* start_node is the default location to load the table */

	if (start_node && start_node != acpi_gbl_root_node) {
128 129 130 131 132 133 134
		status =
		    acpi_ds_scope_stack_push(start_node, ACPI_TYPE_METHOD,
					     walk_state);
		if (ACPI_FAILURE(status)) {
			acpi_ds_delete_walk_state(walk_state);
			goto cleanup;
		}
135 136
	}

L
Linus Torvalds 已提交
137 138
	/* Parse the AML */

L
Len Brown 已提交
139
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %d parse\n",
140
			  (unsigned)pass_number));
L
Len Brown 已提交
141
	status = acpi_ps_parse_aml(walk_state);
L
Linus Torvalds 已提交
142

143
      cleanup:
L
Len Brown 已提交
144 145
	acpi_ps_delete_parse_tree(parse_root);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ns_parse_table
 *
 * PARAMETERS:  table_desc      - An ACPI table descriptor for table to parse
 *              start_node      - Where to enter the table into the namespace
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
 *
 ******************************************************************************/

acpi_status
162
acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
L
Linus Torvalds 已提交
163
{
L
Len Brown 已提交
164
	acpi_status status;
L
Linus Torvalds 已提交
165

B
Bob Moore 已提交
166
	ACPI_FUNCTION_TRACE(ns_parse_table);
L
Linus Torvalds 已提交
167 168 169 170 171 172 173 174 175

	/*
	 * AML Parse, pass 1
	 *
	 * In this pass, we load most of the namespace.  Control methods
	 * are not parsed until later.  A parse tree is not created.  Instead,
	 * each Parser Op subtree is deleted when it is finished.  This saves
	 * a great deal of memory, and allows a small cache of parse objects
	 * to service the entire parse.  The second pass of the parse then
176
	 * performs another complete parse of the AML.
L
Linus Torvalds 已提交
177
	 */
L
Len Brown 已提交
178
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
179 180 181
	status =
	    acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index,
				       start_node);
L
Len Brown 已提交
182 183
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191 192 193 194
	}

	/*
	 * AML Parse, pass 2
	 *
	 * In this pass, we resolve forward references and other things
	 * that could not be completed during the first pass.
	 * Another complete parse of the AML is performed, but the
	 * overhead of this is compensated for by the fact that the
	 * parse objects are all cached.
	 */
L
Len Brown 已提交
195
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
196 197 198
	status =
	    acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index,
				       start_node);
L
Len Brown 已提交
199 200
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
201 202
	}

L
Len Brown 已提交
203
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
204
}