1 /****************************************************************************** 2 * 3 * Module Name: nsparse - namespace interface to AML parser 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2015, Intel Corp. 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 44 #include <contrib/dev/acpica/include/acpi.h> 45 #include <contrib/dev/acpica/include/accommon.h> 46 #include <contrib/dev/acpica/include/acnamesp.h> 47 #include <contrib/dev/acpica/include/acparser.h> 48 #include <contrib/dev/acpica/include/acdispat.h> 49 #include <contrib/dev/acpica/include/actables.h> 50 51 52 #define _COMPONENT ACPI_NAMESPACE 53 ACPI_MODULE_NAME ("nsparse") 54 55 56 /******************************************************************************* 57 * 58 * FUNCTION: NsOneCompleteParse 59 * 60 * PARAMETERS: PassNumber - 1 or 2 61 * TableDesc - The table to be parsed. 62 * 63 * RETURN: Status 64 * 65 * DESCRIPTION: Perform one complete parse of an ACPI/AML table. 66 * 67 ******************************************************************************/ 68 69 ACPI_STATUS 70 AcpiNsOneCompleteParse ( 71 UINT32 PassNumber, 72 UINT32 TableIndex, 73 ACPI_NAMESPACE_NODE *StartNode) 74 { 75 ACPI_PARSE_OBJECT *ParseRoot; 76 ACPI_STATUS Status; 77 UINT32 AmlLength; 78 UINT8 *AmlStart; 79 ACPI_WALK_STATE *WalkState; 80 ACPI_TABLE_HEADER *Table; 81 ACPI_OWNER_ID OwnerId; 82 83 84 ACPI_FUNCTION_TRACE (NsOneCompleteParse); 85 86 87 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId); 88 if (ACPI_FAILURE (Status)) 89 { 90 return_ACPI_STATUS (Status); 91 } 92 93 /* Create and init a Root Node */ 94 95 ParseRoot = AcpiPsCreateScopeOp (); 96 if (!ParseRoot) 97 { 98 return_ACPI_STATUS (AE_NO_MEMORY); 99 } 100 101 /* Create and initialize a new walk state */ 102 103 WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL); 104 if (!WalkState) 105 { 106 AcpiPsFreeOp (ParseRoot); 107 return_ACPI_STATUS (AE_NO_MEMORY); 108 } 109 110 Status = AcpiGetTableByIndex (TableIndex, &Table); 111 if (ACPI_FAILURE (Status)) 112 { 113 AcpiDsDeleteWalkState (WalkState); 114 AcpiPsFreeOp (ParseRoot); 115 return_ACPI_STATUS (Status); 116 } 117 118 /* Table must consist of at least a complete header */ 119 120 if (Table->Length < sizeof (ACPI_TABLE_HEADER)) 121 { 122 Status = AE_BAD_HEADER; 123 } 124 else 125 { 126 AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER); 127 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER); 128 Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL, 129 AmlStart, AmlLength, NULL, (UINT8) PassNumber); 130 } 131 132 /* Found OSDT table, enable the namespace override feature */ 133 134 if (ACPI_COMPARE_NAME(Table->Signature, ACPI_SIG_OSDT) && 135 PassNumber == ACPI_IMODE_LOAD_PASS1) 136 { 137 WalkState->NamespaceOverride = TRUE; 138 } 139 140 if (ACPI_FAILURE (Status)) 141 { 142 AcpiDsDeleteWalkState (WalkState); 143 goto Cleanup; 144 } 145 146 /* StartNode is the default location to load the table */ 147 148 if (StartNode && StartNode != AcpiGbl_RootNode) 149 { 150 Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState); 151 if (ACPI_FAILURE (Status)) 152 { 153 AcpiDsDeleteWalkState (WalkState); 154 goto Cleanup; 155 } 156 } 157 158 /* Parse the AML */ 159 160 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber)); 161 Status = AcpiPsParseAml (WalkState); 162 163 Cleanup: 164 AcpiPsDeleteParseTree (ParseRoot); 165 return_ACPI_STATUS (Status); 166 } 167 168 169 /******************************************************************************* 170 * 171 * FUNCTION: AcpiNsParseTable 172 * 173 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse 174 * StartNode - Where to enter the table into the namespace 175 * 176 * RETURN: Status 177 * 178 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops 179 * 180 ******************************************************************************/ 181 182 ACPI_STATUS 183 AcpiNsParseTable ( 184 UINT32 TableIndex, 185 ACPI_NAMESPACE_NODE *StartNode) 186 { 187 ACPI_STATUS Status; 188 189 190 ACPI_FUNCTION_TRACE (NsParseTable); 191 192 193 /* 194 * AML Parse, pass 1 195 * 196 * In this pass, we load most of the namespace. Control methods 197 * are not parsed until later. A parse tree is not created. Instead, 198 * each Parser Op subtree is deleted when it is finished. This saves 199 * a great deal of memory, and allows a small cache of parse objects 200 * to service the entire parse. The second pass of the parse then 201 * performs another complete parse of the AML. 202 */ 203 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n")); 204 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1, 205 TableIndex, StartNode); 206 if (ACPI_FAILURE (Status)) 207 { 208 return_ACPI_STATUS (Status); 209 } 210 211 /* 212 * AML Parse, pass 2 213 * 214 * In this pass, we resolve forward references and other things 215 * that could not be completed during the first pass. 216 * Another complete parse of the AML is performed, but the 217 * overhead of this is compensated for by the fact that the 218 * parse objects are all cached. 219 */ 220 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n")); 221 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, 222 TableIndex, StartNode); 223 if (ACPI_FAILURE (Status)) 224 { 225 return_ACPI_STATUS (Status); 226 } 227 228 return_ACPI_STATUS (Status); 229 } 230