1114239Snjl/******************************************************************************
2114239Snjl *
3114239Snjl * Module Name: dsinit - Object initialization namespace walk
4114239Snjl *
5114239Snjl *****************************************************************************/
6114239Snjl
7217365Sjkim/*
8217365Sjkim * Copyright (C) 2000 - 2011, Intel Corp.
9114239Snjl * All rights reserved.
10114239Snjl *
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.
25114239Snjl *
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.
29114239Snjl *
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 */
43114239Snjl
44114239Snjl#define __DSINIT_C__
45114239Snjl
46193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
47193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
48193341Sjkim#include <contrib/dev/acpica/include/acdispat.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
50193341Sjkim#include <contrib/dev/acpica/include/actables.h>
51114239Snjl
52114239Snjl#define _COMPONENT          ACPI_DISPATCHER
53114239Snjl        ACPI_MODULE_NAME    ("dsinit")
54114239Snjl
55151937Sjkim/* Local prototypes */
56114239Snjl
57151937Sjkimstatic ACPI_STATUS
58151937SjkimAcpiDsInitOneObject (
59151937Sjkim    ACPI_HANDLE             ObjHandle,
60151937Sjkim    UINT32                  Level,
61151937Sjkim    void                    *Context,
62151937Sjkim    void                    **ReturnValue);
63151937Sjkim
64151937Sjkim
65114239Snjl/*******************************************************************************
66114239Snjl *
67114239Snjl * FUNCTION:    AcpiDsInitOneObject
68114239Snjl *
69151937Sjkim * PARAMETERS:  ObjHandle       - Node for the object
70114239Snjl *              Level           - Current nesting level
71114239Snjl *              Context         - Points to a init info struct
72114239Snjl *              ReturnValue     - Not used
73114239Snjl *
74114239Snjl * RETURN:      Status
75114239Snjl *
76114239Snjl * DESCRIPTION: Callback from AcpiWalkNamespace.  Invoked for every object
77114239Snjl *              within the namespace.
78114239Snjl *
79114239Snjl *              Currently, the only objects that require initialization are:
80114239Snjl *              1) Methods
81114239Snjl *              2) Operation Regions
82114239Snjl *
83114239Snjl ******************************************************************************/
84114239Snjl
85151937Sjkimstatic ACPI_STATUS
86114239SnjlAcpiDsInitOneObject (
87114239Snjl    ACPI_HANDLE             ObjHandle,
88114239Snjl    UINT32                  Level,
89114239Snjl    void                    *Context,
90114239Snjl    void                    **ReturnValue)
91114239Snjl{
92151937Sjkim    ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
93151937Sjkim    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
94114239Snjl    ACPI_OBJECT_TYPE        Type;
95114239Snjl    ACPI_STATUS             Status;
96114239Snjl
97114239Snjl
98167802Sjkim    ACPI_FUNCTION_ENTRY ();
99114239Snjl
100114239Snjl
101114239Snjl    /*
102151937Sjkim     * We are only interested in NS nodes owned by the table that
103114239Snjl     * was just loaded
104114239Snjl     */
105167802Sjkim    if (Node->OwnerId != Info->OwnerId)
106114239Snjl    {
107114239Snjl        return (AE_OK);
108114239Snjl    }
109114239Snjl
110114239Snjl    Info->ObjectCount++;
111114239Snjl
112114239Snjl    /* And even then, we are only interested in a few object types */
113114239Snjl
114114239Snjl    Type = AcpiNsGetType (ObjHandle);
115114239Snjl
116114239Snjl    switch (Type)
117114239Snjl    {
118114239Snjl    case ACPI_TYPE_REGION:
119114239Snjl
120114239Snjl        Status = AcpiDsInitializeRegion (ObjHandle);
121114239Snjl        if (ACPI_FAILURE (Status))
122114239Snjl        {
123167802Sjkim            ACPI_EXCEPTION ((AE_INFO, Status,
124167802Sjkim                "During Region initialization %p [%4.4s]",
125167802Sjkim                ObjHandle, AcpiUtGetNodeName (ObjHandle)));
126114239Snjl        }
127114239Snjl
128114239Snjl        Info->OpRegionCount++;
129114239Snjl        break;
130114239Snjl
131114239Snjl
132114239Snjl    case ACPI_TYPE_METHOD:
133114239Snjl
134151937Sjkim        Info->MethodCount++;
135114239Snjl        break;
136114239Snjl
137114239Snjl
138114239Snjl    case ACPI_TYPE_DEVICE:
139114239Snjl
140114239Snjl        Info->DeviceCount++;
141114239Snjl        break;
142114239Snjl
143114239Snjl
144114239Snjl    default:
145114239Snjl        break;
146114239Snjl    }
147114239Snjl
148114239Snjl    /*
149114239Snjl     * We ignore errors from above, and always return OK, since
150114239Snjl     * we don't want to abort the walk on a single error.
151114239Snjl     */
152114239Snjl    return (AE_OK);
153114239Snjl}
154114239Snjl
155114239Snjl
156114239Snjl/*******************************************************************************
157114239Snjl *
158114239Snjl * FUNCTION:    AcpiDsInitializeObjects
159114239Snjl *
160114239Snjl * PARAMETERS:  TableDesc       - Descriptor for parent ACPI table
161114239Snjl *              StartNode       - Root of subtree to be initialized.
162114239Snjl *
163114239Snjl * RETURN:      Status
164114239Snjl *
165114239Snjl * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
166114239Snjl *              necessary initialization on the objects found therein
167114239Snjl *
168114239Snjl ******************************************************************************/
169114239Snjl
170114239SnjlACPI_STATUS
171114239SnjlAcpiDsInitializeObjects (
172193267Sjkim    UINT32                  TableIndex,
173114239Snjl    ACPI_NAMESPACE_NODE     *StartNode)
174114239Snjl{
175114239Snjl    ACPI_STATUS             Status;
176114239Snjl    ACPI_INIT_WALK_INFO     Info;
177167802Sjkim    ACPI_TABLE_HEADER       *Table;
178167802Sjkim    ACPI_OWNER_ID           OwnerId;
179114239Snjl
180114239Snjl
181167802Sjkim    ACPI_FUNCTION_TRACE (DsInitializeObjects);
182114239Snjl
183114239Snjl
184167802Sjkim    Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
185167802Sjkim    if (ACPI_FAILURE (Status))
186167802Sjkim    {
187167802Sjkim        return_ACPI_STATUS (Status);
188167802Sjkim    }
189167802Sjkim
190114239Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
191114239Snjl        "**** Starting initialization of namespace objects ****\n"));
192114239Snjl    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "Parsing all Control Methods:"));
193114239Snjl
194209746Sjkim    /* Set all init info to zero */
195114239Snjl
196209746Sjkim    ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
197209746Sjkim
198209746Sjkim    Info.OwnerId = OwnerId;
199209746Sjkim    Info.TableIndex = TableIndex;
200209746Sjkim
201114239Snjl    /* Walk entire namespace from the supplied root */
202114239Snjl
203193267Sjkim    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
204114239Snjl    if (ACPI_FAILURE (Status))
205114239Snjl    {
206193267Sjkim        return_ACPI_STATUS (Status);
207193267Sjkim    }
208193267Sjkim
209193267Sjkim    /*
210193267Sjkim     * We don't use AcpiWalkNamespace since we do not want to acquire
211193267Sjkim     * the namespace reader lock.
212193267Sjkim     */
213193267Sjkim    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
214199337Sjkim                ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
215193267Sjkim    if (ACPI_FAILURE (Status))
216193267Sjkim    {
217167802Sjkim        ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
218114239Snjl    }
219193267Sjkim    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
220114239Snjl
221167802Sjkim    Status = AcpiGetTableByIndex (TableIndex, &Table);
222167802Sjkim    if (ACPI_FAILURE (Status))
223167802Sjkim    {
224167802Sjkim        return_ACPI_STATUS (Status);
225167802Sjkim    }
226167802Sjkim
227114239Snjl    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
228209746Sjkim        "\nTable [%4.4s](id %4.4X) - %u Objects with %u Devices %u Methods %u Regions\n",
229167802Sjkim        Table->Signature, OwnerId, Info.ObjectCount,
230114239Snjl        Info.DeviceCount, Info.MethodCount, Info.OpRegionCount));
231114239Snjl
232114239Snjl    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
233209746Sjkim        "%u Methods, %u Regions\n", Info.MethodCount, Info.OpRegionCount));
234114239Snjl
235114239Snjl    return_ACPI_STATUS (AE_OK);
236114239Snjl}
237114239Snjl
238114239Snjl
239