153289f6aSNate Lawson /****************************************************************************** 253289f6aSNate Lawson * 3efcc2a30SJung-uk Kim * Module Name: asllookup- Namespace lookup functions 453289f6aSNate Lawson * 553289f6aSNate Lawson *****************************************************************************/ 653289f6aSNate Lawson 7d244b227SJung-uk Kim /* 8*313a0c13SJung-uk Kim * Copyright (C) 2000 - 2014, Intel Corp. 953289f6aSNate Lawson * All rights reserved. 1053289f6aSNate Lawson * 11d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without 12d244b227SJung-uk Kim * modification, are permitted provided that the following conditions 13d244b227SJung-uk Kim * are met: 14d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 15d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 16d244b227SJung-uk Kim * without modification. 17d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 19d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 20d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further 21d244b227SJung-uk Kim * binary redistribution. 22d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 23d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived 24d244b227SJung-uk Kim * from this software without specific prior written permission. 2553289f6aSNate Lawson * 26d244b227SJung-uk Kim * Alternatively, this software may be distributed under the terms of the 27d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 28d244b227SJung-uk Kim * Software Foundation. 2953289f6aSNate Lawson * 30d244b227SJung-uk Kim * NO WARRANTY 31d244b227SJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32d244b227SJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33d244b227SJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34d244b227SJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35d244b227SJung-uk Kim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36d244b227SJung-uk Kim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37d244b227SJung-uk Kim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38d244b227SJung-uk Kim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39d244b227SJung-uk Kim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40d244b227SJung-uk Kim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41d244b227SJung-uk Kim * POSSIBILITY OF SUCH DAMAGES. 42d244b227SJung-uk Kim */ 4353289f6aSNate Lawson 44ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 4553289f6aSNate Lawson #include "aslcompiler.y.h" 46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h> 5053289f6aSNate Lawson 5153289f6aSNate Lawson 5253289f6aSNate Lawson #define _COMPONENT ACPI_COMPILER 5353289f6aSNate Lawson ACPI_MODULE_NAME ("asllookup") 5453289f6aSNate Lawson 55fba7fc7eSJung-uk Kim /* Local prototypes */ 56fba7fc7eSJung-uk Kim 57fba7fc7eSJung-uk Kim static ACPI_STATUS 581a39cfb0SJung-uk Kim LkIsObjectUsed ( 591a39cfb0SJung-uk Kim ACPI_HANDLE ObjHandle, 601a39cfb0SJung-uk Kim UINT32 Level, 611a39cfb0SJung-uk Kim void *Context, 621a39cfb0SJung-uk Kim void **ReturnValue); 631a39cfb0SJung-uk Kim 6442fecd12SJung-uk Kim static ACPI_PARSE_OBJECT * 65a9f12690SJung-uk Kim LkGetNameOp ( 66a9f12690SJung-uk Kim ACPI_PARSE_OBJECT *Op); 67a9f12690SJung-uk Kim 6853289f6aSNate Lawson 6953289f6aSNate Lawson /******************************************************************************* 7053289f6aSNate Lawson * 71efcc2a30SJung-uk Kim * FUNCTION: LkFindUnreferencedObjects 7253289f6aSNate Lawson * 73efcc2a30SJung-uk Kim * PARAMETERS: None 74a9f12690SJung-uk Kim * 75a9f12690SJung-uk Kim * RETURN: None 76a9f12690SJung-uk Kim * 77efcc2a30SJung-uk Kim * DESCRIPTION: Namespace walk to find objects that are not referenced in any 78efcc2a30SJung-uk Kim * way. Must be called after the namespace has been cross 79efcc2a30SJung-uk Kim * referenced. 80a9f12690SJung-uk Kim * 81a9f12690SJung-uk Kim ******************************************************************************/ 82a9f12690SJung-uk Kim 831a39cfb0SJung-uk Kim void 84efcc2a30SJung-uk Kim LkFindUnreferencedObjects ( 8553289f6aSNate Lawson void) 8653289f6aSNate Lawson { 8753289f6aSNate Lawson 8853289f6aSNate Lawson /* Walk entire namespace from the supplied root */ 8953289f6aSNate Lawson 90efcc2a30SJung-uk Kim (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 91efcc2a30SJung-uk Kim ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL, 92efcc2a30SJung-uk Kim NULL, NULL); 931a39cfb0SJung-uk Kim } 941a39cfb0SJung-uk Kim 951a39cfb0SJung-uk Kim 961a39cfb0SJung-uk Kim /******************************************************************************* 971a39cfb0SJung-uk Kim * 981a39cfb0SJung-uk Kim * FUNCTION: LkIsObjectUsed 991a39cfb0SJung-uk Kim * 1001a39cfb0SJung-uk Kim * PARAMETERS: ACPI_WALK_CALLBACK 1011a39cfb0SJung-uk Kim * 1021a39cfb0SJung-uk Kim * RETURN: Status 1031a39cfb0SJung-uk Kim * 1041a39cfb0SJung-uk Kim * DESCRIPTION: Check for an unreferenced namespace object and emit a warning. 1051a39cfb0SJung-uk Kim * We have to be careful, because some types and names are 1061a39cfb0SJung-uk Kim * typically or always unreferenced, we don't want to issue 107*313a0c13SJung-uk Kim * excessive warnings. Note: Names that are declared within a 108*313a0c13SJung-uk Kim * control method are temporary, so we always issue a remark 109*313a0c13SJung-uk Kim * if they are not referenced. 1101a39cfb0SJung-uk Kim * 1111a39cfb0SJung-uk Kim ******************************************************************************/ 1121a39cfb0SJung-uk Kim 1131a39cfb0SJung-uk Kim static ACPI_STATUS 1141a39cfb0SJung-uk Kim LkIsObjectUsed ( 1151a39cfb0SJung-uk Kim ACPI_HANDLE ObjHandle, 1161a39cfb0SJung-uk Kim UINT32 Level, 1171a39cfb0SJung-uk Kim void *Context, 1181a39cfb0SJung-uk Kim void **ReturnValue) 1191a39cfb0SJung-uk Kim { 1201a39cfb0SJung-uk Kim ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); 121*313a0c13SJung-uk Kim ACPI_NAMESPACE_NODE *Next; 1221a39cfb0SJung-uk Kim 1231a39cfb0SJung-uk Kim 1241a39cfb0SJung-uk Kim /* Referenced flag is set during the namespace xref */ 1251a39cfb0SJung-uk Kim 1261a39cfb0SJung-uk Kim if (Node->Flags & ANOBJ_IS_REFERENCED) 1271a39cfb0SJung-uk Kim { 1281a39cfb0SJung-uk Kim return (AE_OK); 1291a39cfb0SJung-uk Kim } 1301a39cfb0SJung-uk Kim 131*313a0c13SJung-uk Kim if (!Node->Op) 1321a39cfb0SJung-uk Kim { 1331a39cfb0SJung-uk Kim return (AE_OK); 1341a39cfb0SJung-uk Kim } 1351a39cfb0SJung-uk Kim 136*313a0c13SJung-uk Kim /* These types are typically never directly referenced, ignore them */ 1371a39cfb0SJung-uk Kim 1381a39cfb0SJung-uk Kim switch (Node->Type) 1391a39cfb0SJung-uk Kim { 1401a39cfb0SJung-uk Kim case ACPI_TYPE_DEVICE: 1411a39cfb0SJung-uk Kim case ACPI_TYPE_PROCESSOR: 1421a39cfb0SJung-uk Kim case ACPI_TYPE_POWER: 143*313a0c13SJung-uk Kim case ACPI_TYPE_THERMAL: 1441a39cfb0SJung-uk Kim case ACPI_TYPE_LOCAL_RESOURCE: 145a9d8d09cSJung-uk Kim 1461a39cfb0SJung-uk Kim return (AE_OK); 1471a39cfb0SJung-uk Kim 1481a39cfb0SJung-uk Kim default: 149a9d8d09cSJung-uk Kim 1501a39cfb0SJung-uk Kim break; 1511a39cfb0SJung-uk Kim } 1521a39cfb0SJung-uk Kim 153*313a0c13SJung-uk Kim /* Determine if the name is within a control method */ 1541a39cfb0SJung-uk Kim 155*313a0c13SJung-uk Kim Next = Node->Parent; 156*313a0c13SJung-uk Kim while (Next) 1571a39cfb0SJung-uk Kim { 158*313a0c13SJung-uk Kim if (Next->Type == ACPI_TYPE_METHOD) 159*313a0c13SJung-uk Kim { 160*313a0c13SJung-uk Kim /* 161*313a0c13SJung-uk Kim * Name is within a method, therefore it is temporary. 162*313a0c13SJung-uk Kim * Issue a remark even if it is a reserved name (starts 163*313a0c13SJung-uk Kim * with an underscore). 164*313a0c13SJung-uk Kim */ 165*313a0c13SJung-uk Kim sprintf (MsgBuffer, "Name is within method [%4.4s]", 166*313a0c13SJung-uk Kim Next->Name.Ascii); 167*313a0c13SJung-uk Kim AslError (ASL_REMARK, ASL_MSG_NOT_REFERENCED, 168*313a0c13SJung-uk Kim LkGetNameOp (Node->Op), MsgBuffer); 169*313a0c13SJung-uk Kim return (AE_OK); 1701a39cfb0SJung-uk Kim } 171*313a0c13SJung-uk Kim 172*313a0c13SJung-uk Kim Next = Next->Parent; 173*313a0c13SJung-uk Kim } 174*313a0c13SJung-uk Kim 175*313a0c13SJung-uk Kim /* The name is not within a control method */ 176*313a0c13SJung-uk Kim 177*313a0c13SJung-uk Kim /* 178*313a0c13SJung-uk Kim * Ignore names that start with an underscore. These are the reserved 179*313a0c13SJung-uk Kim * ACPI names and are typically not referenced since they are meant 180*313a0c13SJung-uk Kim * to be called by the host OS. 181*313a0c13SJung-uk Kim */ 182*313a0c13SJung-uk Kim if (Node->Name.Ascii[0] == '_') 183*313a0c13SJung-uk Kim { 184*313a0c13SJung-uk Kim return (AE_OK); 185*313a0c13SJung-uk Kim } 186*313a0c13SJung-uk Kim 187*313a0c13SJung-uk Kim /* 188*313a0c13SJung-uk Kim * What remains is an unresolved user name that is not within a method. 189*313a0c13SJung-uk Kim * However, the object could be referenced via another table, so issue 190*313a0c13SJung-uk Kim * the warning at level 2. 191*313a0c13SJung-uk Kim */ 192*313a0c13SJung-uk Kim AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, 193*313a0c13SJung-uk Kim LkGetNameOp (Node->Op), NULL); 1941a39cfb0SJung-uk Kim return (AE_OK); 1951a39cfb0SJung-uk Kim } 1961a39cfb0SJung-uk Kim 1971a39cfb0SJung-uk Kim 1981a39cfb0SJung-uk Kim /******************************************************************************* 1991a39cfb0SJung-uk Kim * 200efcc2a30SJung-uk Kim * FUNCTION: LkGetNameOp 2011a39cfb0SJung-uk Kim * 202efcc2a30SJung-uk Kim * PARAMETERS: Op - Current Op 2031a39cfb0SJung-uk Kim * 204efcc2a30SJung-uk Kim * RETURN: NameOp associated with the input op 2051a39cfb0SJung-uk Kim * 206efcc2a30SJung-uk Kim * DESCRIPTION: Find the name declaration op associated with the operator 2071a39cfb0SJung-uk Kim * 2081a39cfb0SJung-uk Kim ******************************************************************************/ 2091a39cfb0SJung-uk Kim 210efcc2a30SJung-uk Kim static ACPI_PARSE_OBJECT * 211efcc2a30SJung-uk Kim LkGetNameOp ( 212efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *Op) 2131a39cfb0SJung-uk Kim { 21453289f6aSNate Lawson const ACPI_OPCODE_INFO *OpInfo; 215efcc2a30SJung-uk Kim ACPI_PARSE_OBJECT *NameOp = Op; 21653289f6aSNate Lawson 21753289f6aSNate Lawson 21853289f6aSNate Lawson OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); 21953289f6aSNate Lawson 22053289f6aSNate Lawson 22153289f6aSNate Lawson /* Get the NamePath from the appropriate place */ 22253289f6aSNate Lawson 22353289f6aSNate Lawson if (OpInfo->Flags & AML_NAMED) 22453289f6aSNate Lawson { 2251a39cfb0SJung-uk Kim /* For nearly all NAMED operators, the name reference is the first child */ 22653289f6aSNate Lawson 227efcc2a30SJung-uk Kim NameOp = Op->Asl.Child; 22853289f6aSNate Lawson if (Op->Asl.AmlOpcode == AML_ALIAS_OP) 22953289f6aSNate Lawson { 23053289f6aSNate Lawson /* 23153289f6aSNate Lawson * ALIAS is the only oddball opcode, the name declaration 23253289f6aSNate Lawson * (alias name) is the second operand 23353289f6aSNate Lawson */ 234efcc2a30SJung-uk Kim NameOp = Op->Asl.Child->Asl.Next; 23553289f6aSNate Lawson } 23653289f6aSNate Lawson } 23753289f6aSNate Lawson else if (OpInfo->Flags & AML_CREATE) 23853289f6aSNate Lawson { 23953289f6aSNate Lawson /* Name must appear as the last parameter */ 24053289f6aSNate Lawson 241efcc2a30SJung-uk Kim NameOp = Op->Asl.Child; 242efcc2a30SJung-uk Kim while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)) 24353289f6aSNate Lawson { 244efcc2a30SJung-uk Kim NameOp = NameOp->Asl.Next; 24553289f6aSNate Lawson } 24653289f6aSNate Lawson } 24753289f6aSNate Lawson 248efcc2a30SJung-uk Kim return (NameOp); 24953289f6aSNate Lawson } 250