nsparse.c revision ec3153fb0e96988dc7e378b3ab01e05131ba713b
11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/****************************************************************************** 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Module Name: nsparse - namespace interface to AML parser 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *****************************************************************************/ 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 84a90c7e86202f46fa9af011bdbcdf36e355d1721Bob Moore * Copyright (C) 2000 - 2006, R. Byron Moore 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All rights reserved. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redistribution and use in source and binary forms, with or without 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modification, are permitted provided that the following conditions 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are met: 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1. Redistributions of source code must retain the above copyright 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * notice, this list of conditions, and the following disclaimer, 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * without modification. 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * substantially similar to the "NO WARRANTY" disclaimer below 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ("Disclaimer") and any redistribution must be conditioned upon 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * including a substantially similar Disclaimer requirement for further 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * binary redistribution. 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of any contributors may be used to endorse or promote products derived 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * from this software without specific prior written permission. 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alternatively, this software may be distributed under the terms of the 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software Foundation. 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NO WARRANTY 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * POSSIBILITY OF SUCH DAMAGES. 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acpi.h> 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acnamesp.h> 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acparser.h> 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <acpi/acdispat.h> 48f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore#include <acpi/actables.h> 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _COMPONENT ACPI_NAMESPACE 514be44fcd3bf648b782f4460fd06dfae6c42ded4bLen BrownACPI_MODULE_NAME("nsparse") 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************************************* 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FUNCTION: ns_one_complete_parse 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PARAMETERS: pass_number - 1 or 2 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * table_desc - The table to be parsed. 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RETURN: Status 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DESCRIPTION: Perform one complete parse of an ACPI/AML table. 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ******************************************************************************/ 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsacpi_status 66f3d2e7865c816258c699ff965768e46b50d536d3Bob Mooreacpi_ns_one_complete_parse(acpi_native_uint pass_number, 67f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_native_uint table_index) 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 694be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown union acpi_parse_object *parse_root; 704be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_status status; 71f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_native_uint aml_length; 72f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore u8 *aml_start; 734be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown struct acpi_walk_state *walk_state; 74f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore struct acpi_table_header *table; 75f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_owner_id owner_id; 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 77b229cf92eee616c7cb5ad8cdb35a19b119f00bc8Bob Moore ACPI_FUNCTION_TRACE(ns_one_complete_parse); 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 79f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore status = acpi_tb_get_owner_id(table_index, &owner_id); 80f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore if (ACPI_FAILURE(status)) { 81f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore return_ACPI_STATUS(status); 82f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore } 83f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Create and init a Root Node */ 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 864be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown parse_root = acpi_ps_create_scope_op(); 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!parse_root) { 884be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(AE_NO_MEMORY); 891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Create and initialize a new walk state */ 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 93f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore walk_state = acpi_ds_create_walk_state(owner_id, NULL, NULL, NULL); 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!walk_state) { 954be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_ps_free_op(parse_root); 964be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(AE_NO_MEMORY); 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 99f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore status = acpi_get_table_by_index(table_index, &table); 100f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore if (ACPI_FAILURE(status)) { 101f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_ds_delete_walk_state(walk_state); 102f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_ps_free_op(parse_root); 103f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore return_ACPI_STATUS(status); 104f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore } 105f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore 106f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore /* Table must consist of at least a complete header */ 107f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore 108f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore if (table->length < sizeof(struct acpi_table_header)) { 109f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore status = AE_BAD_HEADER; 110f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore } else { 111f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore aml_start = (u8 *) table + sizeof(struct acpi_table_header); 112f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore aml_length = table->length - sizeof(struct acpi_table_header); 113f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, 114f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore aml_start, aml_length, NULL, 115f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore (u8) pass_number); 116f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore } 117f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore 1184be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown if (ACPI_FAILURE(status)) { 1194be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_ds_delete_walk_state(walk_state); 120f3d2e7865c816258c699ff965768e46b50d536d3Bob Moore acpi_ps_delete_parse_tree(parse_root); 1214be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(status); 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Parse the AML */ 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1264be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "*PARSE* pass %d parse\n", 1274be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown pass_number)); 1284be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown status = acpi_ps_parse_aml(walk_state); 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1304be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_ps_delete_parse_tree(parse_root); 1314be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(status); 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/******************************************************************************* 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * FUNCTION: acpi_ns_parse_table 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * PARAMETERS: table_desc - An ACPI table descriptor for table to parse 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * start_node - Where to enter the table into the namespace 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * RETURN: Status 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ******************************************************************************/ 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsacpi_status 148f3d2e7865c816258c699ff965768e46b50d536d3Bob Mooreacpi_ns_parse_table(acpi_native_uint table_index, 1494be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown struct acpi_namespace_node *start_node) 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1514be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown acpi_status status; 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 153b229cf92eee616c7cb5ad8cdb35a19b119f00bc8Bob Moore ACPI_FUNCTION_TRACE(ns_parse_table); 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * AML Parse, pass 1 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * In this pass, we load most of the namespace. Control methods 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are not parsed until later. A parse tree is not created. Instead, 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * each Parser Op subtree is deleted when it is finished. This saves 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * a great deal of memory, and allows a small cache of parse objects 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * to service the entire parse. The second pass of the parse then 163ec3153fb0e96988dc7e378b3ab01e05131ba713bBob Moore * performs another complete parse of the AML. 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1654be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n")); 166ec3153fb0e96988dc7e378b3ab01e05131ba713bBob Moore status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index); 1674be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown if (ACPI_FAILURE(status)) { 1684be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(status); 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * AML Parse, pass 2 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * In this pass, we resolve forward references and other things 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * that could not be completed during the first pass. 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Another complete parse of the AML is performed, but the 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * overhead of this is compensated for by the fact that the 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * parse objects are all cached. 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1804be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n")); 181ec3153fb0e96988dc7e378b3ab01e05131ba713bBob Moore status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index); 1824be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown if (ACPI_FAILURE(status)) { 1834be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(status); 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1864be44fcd3bf648b782f4460fd06dfae6c42ded4bLen Brown return_ACPI_STATUS(status); 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 188