]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/acpica/nsparse.c
ACPICA: Update for some debug output. No functional change
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / acpica / nsparse.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: nsparse - namespace interface to AML parser
4 *
5 *****************************************************************************/
6
7/*
da6f8320 8 * Copyright (C) 2000 - 2018, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acnamesp.h"
47#include "acparser.h"
48#include "acdispat.h"
49#include "actables.h"
74f51b80 50#include "acinterp.h"
1da177e4 51
1da177e4 52#define _COMPONENT ACPI_NAMESPACE
4be44fcd 53ACPI_MODULE_NAME("nsparse")
1da177e4 54
de56ba95
LZ
55/*******************************************************************************
56 *
57 * FUNCTION: ns_execute_table
58 *
59 * PARAMETERS: table_desc - An ACPI table descriptor for table to parse
60 * start_node - Where to enter the table into the namespace
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Load ACPI/AML table by executing the entire table as a
65 * term_list.
66 *
67 ******************************************************************************/
68acpi_status
69acpi_ns_execute_table(u32 table_index, struct acpi_namespace_node *start_node)
70{
71 acpi_status status;
72 struct acpi_table_header *table;
73 acpi_owner_id owner_id;
74 struct acpi_evaluate_info *info = NULL;
75 u32 aml_length;
76 u8 *aml_start;
77 union acpi_operand_object *method_obj = NULL;
78
79 ACPI_FUNCTION_TRACE(ns_execute_table);
80
81 status = acpi_get_table_by_index(table_index, &table);
82 if (ACPI_FAILURE(status)) {
83 return_ACPI_STATUS(status);
84 }
85
86 /* Table must consist of at least a complete header */
87
88 if (table->length < sizeof(struct acpi_table_header)) {
89 return_ACPI_STATUS(AE_BAD_HEADER);
90 }
91
92 aml_start = (u8 *)table + sizeof(struct acpi_table_header);
93 aml_length = table->length - sizeof(struct acpi_table_header);
94
95 status = acpi_tb_get_owner_id(table_index, &owner_id);
96 if (ACPI_FAILURE(status)) {
97 return_ACPI_STATUS(status);
98 }
99
100 /* Create, initialize, and link a new temporary method object */
101
102 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
103 if (!method_obj) {
104 return_ACPI_STATUS(AE_NO_MEMORY);
105 }
106
107 /* Allocate the evaluation information block */
108
109 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
110 if (!info) {
111 status = AE_NO_MEMORY;
112 goto cleanup;
113 }
114
1ef63231
BM
115 ACPI_DEBUG_PRINT_RAW((ACPI_DB_PARSE,
116 "%s: Create table pseudo-method for [%4.4s] @%p, method %p\n",
117 ACPI_GET_FUNCTION_NAME, table->signature, table,
118 method_obj));
de56ba95
LZ
119
120 method_obj->method.aml_start = aml_start;
121 method_obj->method.aml_length = aml_length;
122 method_obj->method.owner_id = owner_id;
123 method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL;
124
125 info->pass_number = ACPI_IMODE_EXECUTE;
126 info->node = start_node;
127 info->obj_desc = method_obj;
128 info->node_flags = info->node->flags;
129 info->full_pathname = acpi_ns_get_normalized_pathname(info->node, TRUE);
130 if (!info->full_pathname) {
131 status = AE_NO_MEMORY;
132 goto cleanup;
133 }
134
135 status = acpi_ps_execute_table(info);
136
137cleanup:
138 if (info) {
139 ACPI_FREE(info->full_pathname);
140 info->full_pathname = NULL;
141 }
142 ACPI_FREE(info);
143 acpi_ut_remove_reference(method_obj);
144 return_ACPI_STATUS(status);
145}
146
1da177e4
LT
147/*******************************************************************************
148 *
149 * FUNCTION: ns_one_complete_parse
150 *
151 * PARAMETERS: pass_number - 1 or 2
152 * table_desc - The table to be parsed.
153 *
154 * RETURN: Status
155 *
156 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
157 *
158 ******************************************************************************/
de56ba95 159
1da177e4 160acpi_status
67a119f9
BM
161acpi_ns_one_complete_parse(u32 pass_number,
162 u32 table_index,
163 struct acpi_namespace_node *start_node)
1da177e4 164{
4be44fcd
LB
165 union acpi_parse_object *parse_root;
166 acpi_status status;
eb87a052 167 u32 aml_length;
f3d2e786 168 u8 *aml_start;
4be44fcd 169 struct acpi_walk_state *walk_state;
f3d2e786
BM
170 struct acpi_table_header *table;
171 acpi_owner_id owner_id;
1da177e4 172
b229cf92 173 ACPI_FUNCTION_TRACE(ns_one_complete_parse);
1da177e4 174
62eb935b
LZ
175 status = acpi_get_table_by_index(table_index, &table);
176 if (ACPI_FAILURE(status)) {
177 return_ACPI_STATUS(status);
178 }
179
180 /* Table must consist of at least a complete header */
181
182 if (table->length < sizeof(struct acpi_table_header)) {
183 return_ACPI_STATUS(AE_BAD_HEADER);
184 }
185
186 aml_start = (u8 *)table + sizeof(struct acpi_table_header);
187 aml_length = table->length - sizeof(struct acpi_table_header);
188
f3d2e786
BM
189 status = acpi_tb_get_owner_id(table_index, &owner_id);
190 if (ACPI_FAILURE(status)) {
191 return_ACPI_STATUS(status);
192 }
193
1da177e4
LT
194 /* Create and init a Root Node */
195
62eb935b 196 parse_root = acpi_ps_create_scope_op(aml_start);
1da177e4 197 if (!parse_root) {
4be44fcd 198 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
199 }
200
201 /* Create and initialize a new walk state */
202
f3d2e786 203 walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL);
1da177e4 204 if (!walk_state) {
4be44fcd
LB
205 acpi_ps_free_op(parse_root);
206 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
207 }
208
62eb935b
LZ
209 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
210 aml_start, aml_length, NULL,
211 (u8)pass_number);
f3d2e786
BM
212 if (ACPI_FAILURE(status)) {
213 acpi_ds_delete_walk_state(walk_state);
62eb935b 214 goto cleanup;
f3d2e786
BM
215 }
216
fe536995
BM
217 /* Found OSDT table, enable the namespace override feature */
218
219 if (ACPI_COMPARE_NAME(table->signature, ACPI_SIG_OSDT) &&
220 pass_number == ACPI_IMODE_LOAD_PASS1) {
221 walk_state->namespace_override = TRUE;
222 }
223
7f4ac9f9
BM
224 /* start_node is the default location to load the table */
225
226 if (start_node && start_node != acpi_gbl_root_node) {
1d18c058
BM
227 status =
228 acpi_ds_scope_stack_push(start_node, ACPI_TYPE_METHOD,
229 walk_state);
230 if (ACPI_FAILURE(status)) {
231 acpi_ds_delete_walk_state(walk_state);
232 goto cleanup;
233 }
7f4ac9f9
BM
234 }
235
1da177e4
LT
236 /* Parse the AML */
237
1fad8738
BM
238 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
239 "*PARSE* pass %u parse\n", pass_number));
74f51b80 240 acpi_ex_enter_interpreter();
4be44fcd 241 status = acpi_ps_parse_aml(walk_state);
74f51b80 242 acpi_ex_exit_interpreter();
1da177e4 243
10622bf8 244cleanup:
4be44fcd
LB
245 acpi_ps_delete_parse_tree(parse_root);
246 return_ACPI_STATUS(status);
1da177e4
LT
247}
248
1da177e4
LT
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_ns_parse_table
252 *
253 * PARAMETERS: table_desc - An ACPI table descriptor for table to parse
254 * start_node - Where to enter the table into the namespace
255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
259 *
260 ******************************************************************************/
261
262acpi_status
67a119f9 263acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node)
1da177e4 264{
4be44fcd 265 acpi_status status;
1da177e4 266
b229cf92 267 ACPI_FUNCTION_TRACE(ns_parse_table);
1da177e4 268
de56ba95 269 if (acpi_gbl_parse_table_as_term_list) {
1ef63231
BM
270 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
271 "**** Start table execution pass\n"));
1da177e4 272
de56ba95
LZ
273 status = acpi_ns_execute_table(table_index, start_node);
274 if (ACPI_FAILURE(status)) {
275 return_ACPI_STATUS(status);
276 }
277 } else {
278 /*
279 * AML Parse, pass 1
280 *
281 * In this pass, we load most of the namespace. Control methods
282 * are not parsed until later. A parse tree is not created.
283 * Instead, each Parser Op subtree is deleted when it is finished.
284 * This saves a great deal of memory, and allows a small cache of
285 * parse objects to service the entire parse. The second pass of
286 * the parse then performs another complete parse of the AML.
287 */
288 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
289
290 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1,
291 table_index, start_node);
292 if (ACPI_FAILURE(status)) {
293 return_ACPI_STATUS(status);
294 }
295
296 /*
297 * AML Parse, pass 2
298 *
299 * In this pass, we resolve forward references and other things
300 * that could not be completed during the first pass.
301 * Another complete parse of the AML is performed, but the
302 * overhead of this is compensated for by the fact that the
303 * parse objects are all cached.
304 */
305 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
306 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2,
307 table_index, start_node);
308 if (ACPI_FAILURE(status)) {
309 return_ACPI_STATUS(status);
310 }
1da177e4
LT
311 }
312
4be44fcd 313 return_ACPI_STATUS(status);
1da177e4 314}