1118611Snjl/******************************************************************************
2118611Snjl *
3245582Sjkim * Module Name: asllookup- Namespace lookup functions
4118611Snjl *
5118611Snjl *****************************************************************************/
6118611Snjl
7217365Sjkim/*
8245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp.
9118611Snjl * All rights reserved.
10118611Snjl *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
25118611Snjl *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
29118611Snjl *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
43118611Snjl
44118611Snjl
45151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
46118611Snjl#include "aslcompiler.y.h"
47193529Sjkim#include <contrib/dev/acpica/include/acparser.h>
48193529Sjkim#include <contrib/dev/acpica/include/amlcode.h>
49193529Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50193529Sjkim#include <contrib/dev/acpica/include/acdispat.h>
51118611Snjl
52118611Snjl
53118611Snjl#define _COMPONENT          ACPI_COMPILER
54118611Snjl        ACPI_MODULE_NAME    ("asllookup")
55118611Snjl
56151937Sjkim/* Local prototypes */
57118611Snjl
58151937Sjkimstatic ACPI_STATUS
59167802SjkimLkIsObjectUsed (
60167802Sjkim    ACPI_HANDLE             ObjHandle,
61167802Sjkim    UINT32                  Level,
62167802Sjkim    void                    *Context,
63167802Sjkim    void                    **ReturnValue);
64151937Sjkim
65212761Sjkimstatic ACPI_PARSE_OBJECT *
66193529SjkimLkGetNameOp (
67193529Sjkim    ACPI_PARSE_OBJECT       *Op);
68193529Sjkim
69193529Sjkim
70118611Snjl/*******************************************************************************
71118611Snjl *
72245582Sjkim * FUNCTION:    LkFindUnreferencedObjects
73118611Snjl *
74245582Sjkim * PARAMETERS:  None
75118611Snjl *
76193529Sjkim * RETURN:      None
77193529Sjkim *
78245582Sjkim * DESCRIPTION: Namespace walk to find objects that are not referenced in any
79245582Sjkim *              way. Must be called after the namespace has been cross
80245582Sjkim *              referenced.
81193529Sjkim *
82193529Sjkim ******************************************************************************/
83193529Sjkim
84167802Sjkimvoid
85245582SjkimLkFindUnreferencedObjects (
86118611Snjl    void)
87118611Snjl{
88118611Snjl
89245582Sjkim    /* Walk entire namespace from the supplied root */
90118611Snjl
91245582Sjkim    (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
92245582Sjkim                ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL,
93151937Sjkim                NULL, NULL);
94118611Snjl}
95118611Snjl
96118611Snjl
97118611Snjl/*******************************************************************************
98118611Snjl *
99167802Sjkim * FUNCTION:    LkIsObjectUsed
100167802Sjkim *
101167802Sjkim * PARAMETERS:  ACPI_WALK_CALLBACK
102167802Sjkim *
103167802Sjkim * RETURN:      Status
104167802Sjkim *
105167802Sjkim * DESCRIPTION: Check for an unreferenced namespace object and emit a warning.
106167802Sjkim *              We have to be careful, because some types and names are
107167802Sjkim *              typically or always unreferenced, we don't want to issue
108167802Sjkim *              excessive warnings.
109167802Sjkim *
110167802Sjkim ******************************************************************************/
111167802Sjkim
112167802Sjkimstatic ACPI_STATUS
113167802SjkimLkIsObjectUsed (
114167802Sjkim    ACPI_HANDLE             ObjHandle,
115167802Sjkim    UINT32                  Level,
116167802Sjkim    void                    *Context,
117167802Sjkim    void                    **ReturnValue)
118167802Sjkim{
119167802Sjkim    ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
120167802Sjkim
121167802Sjkim
122167802Sjkim    /* Referenced flag is set during the namespace xref */
123167802Sjkim
124167802Sjkim    if (Node->Flags & ANOBJ_IS_REFERENCED)
125167802Sjkim    {
126167802Sjkim        return (AE_OK);
127167802Sjkim    }
128167802Sjkim
129167802Sjkim    /*
130167802Sjkim     * Ignore names that start with an underscore,
131167802Sjkim     * these are the reserved ACPI names and are typically not referenced,
132167802Sjkim     * they are called by the host OS.
133167802Sjkim     */
134167802Sjkim    if (Node->Name.Ascii[0] == '_')
135167802Sjkim    {
136167802Sjkim        return (AE_OK);
137167802Sjkim    }
138167802Sjkim
139167802Sjkim    /* There are some types that are typically not referenced, ignore them */
140167802Sjkim
141167802Sjkim    switch (Node->Type)
142167802Sjkim    {
143167802Sjkim    case ACPI_TYPE_DEVICE:
144167802Sjkim    case ACPI_TYPE_PROCESSOR:
145167802Sjkim    case ACPI_TYPE_POWER:
146167802Sjkim    case ACPI_TYPE_LOCAL_RESOURCE:
147250838Sjkim
148167802Sjkim        return (AE_OK);
149167802Sjkim
150167802Sjkim    default:
151250838Sjkim
152167802Sjkim        break;
153167802Sjkim    }
154167802Sjkim
155167802Sjkim    /* All others are valid unreferenced namespace objects */
156167802Sjkim
157167802Sjkim    if (Node->Op)
158167802Sjkim    {
159167802Sjkim        AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, LkGetNameOp (Node->Op), NULL);
160167802Sjkim    }
161167802Sjkim    return (AE_OK);
162167802Sjkim}
163167802Sjkim
164167802Sjkim
165167802Sjkim/*******************************************************************************
166167802Sjkim *
167245582Sjkim * FUNCTION:    LkGetNameOp
168167802Sjkim *
169245582Sjkim * PARAMETERS:  Op              - Current Op
170167802Sjkim *
171245582Sjkim * RETURN:      NameOp associated with the input op
172167802Sjkim *
173245582Sjkim * DESCRIPTION: Find the name declaration op associated with the operator
174167802Sjkim *
175167802Sjkim ******************************************************************************/
176167802Sjkim
177245582Sjkimstatic ACPI_PARSE_OBJECT *
178245582SjkimLkGetNameOp (
179245582Sjkim    ACPI_PARSE_OBJECT       *Op)
180167802Sjkim{
181118611Snjl    const ACPI_OPCODE_INFO  *OpInfo;
182245582Sjkim    ACPI_PARSE_OBJECT       *NameOp = Op;
183118611Snjl
184118611Snjl
185118611Snjl    OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
186118611Snjl
187118611Snjl
188118611Snjl    /* Get the NamePath from the appropriate place */
189118611Snjl
190118611Snjl    if (OpInfo->Flags & AML_NAMED)
191118611Snjl    {
192167802Sjkim        /* For nearly all NAMED operators, the name reference is the first child */
193118611Snjl
194245582Sjkim        NameOp = Op->Asl.Child;
195118611Snjl        if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
196118611Snjl        {
197118611Snjl            /*
198118611Snjl             * ALIAS is the only oddball opcode, the name declaration
199118611Snjl             * (alias name) is the second operand
200118611Snjl             */
201245582Sjkim            NameOp = Op->Asl.Child->Asl.Next;
202118611Snjl        }
203118611Snjl    }
204118611Snjl    else if (OpInfo->Flags & AML_CREATE)
205118611Snjl    {
206118611Snjl        /* Name must appear as the last parameter */
207118611Snjl
208245582Sjkim        NameOp = Op->Asl.Child;
209245582Sjkim        while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
210118611Snjl        {
211245582Sjkim            NameOp = NameOp->Asl.Next;
212118611Snjl        }
213118611Snjl    }
214118611Snjl
215245582Sjkim    return (NameOp);
216118611Snjl}
217