xref: /freebsd/sys/contrib/dev/acpica/compiler/asllookup.c (revision a9d8d09c46ec699e45f3fd46ca9abcf02e5baca9)
153289f6aSNate Lawson /******************************************************************************
253289f6aSNate Lawson  *
3efcc2a30SJung-uk Kim  * Module Name: asllookup- Namespace lookup functions
453289f6aSNate Lawson  *
553289f6aSNate Lawson  *****************************************************************************/
653289f6aSNate Lawson 
7d244b227SJung-uk Kim /*
8efcc2a30SJung-uk Kim  * Copyright (C) 2000 - 2013, 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 
4453289f6aSNate Lawson 
45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
4653289f6aSNate Lawson #include "aslcompiler.y.h"
47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
5153289f6aSNate Lawson 
5253289f6aSNate Lawson 
5353289f6aSNate Lawson #define _COMPONENT          ACPI_COMPILER
5453289f6aSNate Lawson         ACPI_MODULE_NAME    ("asllookup")
5553289f6aSNate Lawson 
56fba7fc7eSJung-uk Kim /* Local prototypes */
57fba7fc7eSJung-uk Kim 
58fba7fc7eSJung-uk Kim static ACPI_STATUS
591a39cfb0SJung-uk Kim LkIsObjectUsed (
601a39cfb0SJung-uk Kim     ACPI_HANDLE             ObjHandle,
611a39cfb0SJung-uk Kim     UINT32                  Level,
621a39cfb0SJung-uk Kim     void                    *Context,
631a39cfb0SJung-uk Kim     void                    **ReturnValue);
641a39cfb0SJung-uk Kim 
6542fecd12SJung-uk Kim static ACPI_PARSE_OBJECT *
66a9f12690SJung-uk Kim LkGetNameOp (
67a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op);
68a9f12690SJung-uk Kim 
6953289f6aSNate Lawson 
7053289f6aSNate Lawson /*******************************************************************************
7153289f6aSNate Lawson  *
72efcc2a30SJung-uk Kim  * FUNCTION:    LkFindUnreferencedObjects
7353289f6aSNate Lawson  *
74efcc2a30SJung-uk Kim  * PARAMETERS:  None
75a9f12690SJung-uk Kim  *
76a9f12690SJung-uk Kim  * RETURN:      None
77a9f12690SJung-uk Kim  *
78efcc2a30SJung-uk Kim  * DESCRIPTION: Namespace walk to find objects that are not referenced in any
79efcc2a30SJung-uk Kim  *              way. Must be called after the namespace has been cross
80efcc2a30SJung-uk Kim  *              referenced.
81a9f12690SJung-uk Kim  *
82a9f12690SJung-uk Kim  ******************************************************************************/
83a9f12690SJung-uk Kim 
841a39cfb0SJung-uk Kim void
85efcc2a30SJung-uk Kim LkFindUnreferencedObjects (
8653289f6aSNate Lawson     void)
8753289f6aSNate Lawson {
8853289f6aSNate Lawson 
8953289f6aSNate Lawson     /* Walk entire namespace from the supplied root */
9053289f6aSNate Lawson 
91efcc2a30SJung-uk Kim     (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
92efcc2a30SJung-uk Kim                 ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
93efcc2a30SJung-uk Kim                 NULL, NULL);
941a39cfb0SJung-uk Kim }
951a39cfb0SJung-uk Kim 
961a39cfb0SJung-uk Kim 
971a39cfb0SJung-uk Kim /*******************************************************************************
981a39cfb0SJung-uk Kim  *
991a39cfb0SJung-uk Kim  * FUNCTION:    LkIsObjectUsed
1001a39cfb0SJung-uk Kim  *
1011a39cfb0SJung-uk Kim  * PARAMETERS:  ACPI_WALK_CALLBACK
1021a39cfb0SJung-uk Kim  *
1031a39cfb0SJung-uk Kim  * RETURN:      Status
1041a39cfb0SJung-uk Kim  *
1051a39cfb0SJung-uk Kim  * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
1061a39cfb0SJung-uk Kim  *              We have to be careful, because some types and names are
1071a39cfb0SJung-uk Kim  *              typically or always unreferenced, we don't want to issue
1081a39cfb0SJung-uk Kim  *              excessive warnings.
1091a39cfb0SJung-uk Kim  *
1101a39cfb0SJung-uk Kim  ******************************************************************************/
1111a39cfb0SJung-uk Kim 
1121a39cfb0SJung-uk Kim static ACPI_STATUS
1131a39cfb0SJung-uk Kim LkIsObjectUsed (
1141a39cfb0SJung-uk Kim     ACPI_HANDLE             ObjHandle,
1151a39cfb0SJung-uk Kim     UINT32                  Level,
1161a39cfb0SJung-uk Kim     void                    *Context,
1171a39cfb0SJung-uk Kim     void                    **ReturnValue)
1181a39cfb0SJung-uk Kim {
1191a39cfb0SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
1201a39cfb0SJung-uk Kim 
1211a39cfb0SJung-uk Kim 
1221a39cfb0SJung-uk Kim     /* Referenced flag is set during the namespace xref */
1231a39cfb0SJung-uk Kim 
1241a39cfb0SJung-uk Kim     if (Node->Flags & ANOBJ_IS_REFERENCED)
1251a39cfb0SJung-uk Kim     {
1261a39cfb0SJung-uk Kim         return (AE_OK);
1271a39cfb0SJung-uk Kim     }
1281a39cfb0SJung-uk Kim 
1291a39cfb0SJung-uk Kim     /*
1301a39cfb0SJung-uk Kim      * Ignore names that start with an underscore,
1311a39cfb0SJung-uk Kim      * these are the reserved ACPI names and are typically not referenced,
1321a39cfb0SJung-uk Kim      * they are called by the host OS.
1331a39cfb0SJung-uk Kim      */
1341a39cfb0SJung-uk Kim     if (Node->Name.Ascii[0] == '_')
1351a39cfb0SJung-uk Kim     {
1361a39cfb0SJung-uk Kim         return (AE_OK);
1371a39cfb0SJung-uk Kim     }
1381a39cfb0SJung-uk Kim 
1391a39cfb0SJung-uk Kim     /* There are some types that are typically not referenced, ignore them */
1401a39cfb0SJung-uk Kim 
1411a39cfb0SJung-uk Kim     switch (Node->Type)
1421a39cfb0SJung-uk Kim     {
1431a39cfb0SJung-uk Kim     case ACPI_TYPE_DEVICE:
1441a39cfb0SJung-uk Kim     case ACPI_TYPE_PROCESSOR:
1451a39cfb0SJung-uk Kim     case ACPI_TYPE_POWER:
1461a39cfb0SJung-uk Kim     case ACPI_TYPE_LOCAL_RESOURCE:
147*a9d8d09cSJung-uk Kim 
1481a39cfb0SJung-uk Kim         return (AE_OK);
1491a39cfb0SJung-uk Kim 
1501a39cfb0SJung-uk Kim     default:
151*a9d8d09cSJung-uk Kim 
1521a39cfb0SJung-uk Kim         break;
1531a39cfb0SJung-uk Kim     }
1541a39cfb0SJung-uk Kim 
1551a39cfb0SJung-uk Kim     /* All others are valid unreferenced namespace objects */
1561a39cfb0SJung-uk Kim 
1571a39cfb0SJung-uk Kim     if (Node->Op)
1581a39cfb0SJung-uk Kim     {
1591a39cfb0SJung-uk Kim         AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, LkGetNameOp (Node->Op), NULL);
1601a39cfb0SJung-uk Kim     }
1611a39cfb0SJung-uk Kim     return (AE_OK);
1621a39cfb0SJung-uk Kim }
1631a39cfb0SJung-uk Kim 
1641a39cfb0SJung-uk Kim 
1651a39cfb0SJung-uk Kim /*******************************************************************************
1661a39cfb0SJung-uk Kim  *
167efcc2a30SJung-uk Kim  * FUNCTION:    LkGetNameOp
1681a39cfb0SJung-uk Kim  *
169efcc2a30SJung-uk Kim  * PARAMETERS:  Op              - Current Op
1701a39cfb0SJung-uk Kim  *
171efcc2a30SJung-uk Kim  * RETURN:      NameOp associated with the input op
1721a39cfb0SJung-uk Kim  *
173efcc2a30SJung-uk Kim  * DESCRIPTION: Find the name declaration op associated with the operator
1741a39cfb0SJung-uk Kim  *
1751a39cfb0SJung-uk Kim  ******************************************************************************/
1761a39cfb0SJung-uk Kim 
177efcc2a30SJung-uk Kim static ACPI_PARSE_OBJECT *
178efcc2a30SJung-uk Kim LkGetNameOp (
179efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *Op)
1801a39cfb0SJung-uk Kim {
18153289f6aSNate Lawson     const ACPI_OPCODE_INFO  *OpInfo;
182efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *NameOp = Op;
18353289f6aSNate Lawson 
18453289f6aSNate Lawson 
18553289f6aSNate Lawson     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
18653289f6aSNate Lawson 
18753289f6aSNate Lawson 
18853289f6aSNate Lawson     /* Get the NamePath from the appropriate place */
18953289f6aSNate Lawson 
19053289f6aSNate Lawson     if (OpInfo->Flags & AML_NAMED)
19153289f6aSNate Lawson     {
1921a39cfb0SJung-uk Kim         /* For nearly all NAMED operators, the name reference is the first child */
19353289f6aSNate Lawson 
194efcc2a30SJung-uk Kim         NameOp = Op->Asl.Child;
19553289f6aSNate Lawson         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
19653289f6aSNate Lawson         {
19753289f6aSNate Lawson             /*
19853289f6aSNate Lawson              * ALIAS is the only oddball opcode, the name declaration
19953289f6aSNate Lawson              * (alias name) is the second operand
20053289f6aSNate Lawson              */
201efcc2a30SJung-uk Kim             NameOp = Op->Asl.Child->Asl.Next;
20253289f6aSNate Lawson         }
20353289f6aSNate Lawson     }
20453289f6aSNate Lawson     else if (OpInfo->Flags & AML_CREATE)
20553289f6aSNate Lawson     {
20653289f6aSNate Lawson         /* Name must appear as the last parameter */
20753289f6aSNate Lawson 
208efcc2a30SJung-uk Kim         NameOp = Op->Asl.Child;
209efcc2a30SJung-uk Kim         while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
21053289f6aSNate Lawson         {
211efcc2a30SJung-uk Kim             NameOp = NameOp->Asl.Next;
21253289f6aSNate Lawson         }
21353289f6aSNate Lawson     }
21453289f6aSNate Lawson 
215efcc2a30SJung-uk Kim     return (NameOp);
21653289f6aSNate Lawson }
217