aslnamesp.c revision 285797
1227825Stheraven/******************************************************************************
2227825Stheraven *
3227825Stheraven * Module Name: aslnamesp - Namespace output file generation
4227825Stheraven *
5227825Stheraven *****************************************************************************/
6227825Stheraven
7227825Stheraven/*
8227825Stheraven * Copyright (C) 2000 - 2015, Intel Corp.
9227825Stheraven * All rights reserved.
10227825Stheraven *
11227825Stheraven * Redistribution and use in source and binary forms, with or without
12227825Stheraven * modification, are permitted provided that the following conditions
13227825Stheraven * are met:
14227825Stheraven * 1. Redistributions of source code must retain the above copyright
15227825Stheraven *    notice, this list of conditions, and the following disclaimer,
16227825Stheraven *    without modification.
17227825Stheraven * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18227825Stheraven *    substantially similar to the "NO WARRANTY" disclaimer below
19227825Stheraven *    ("Disclaimer") and any redistribution must be conditioned upon
20227825Stheraven *    including a substantially similar Disclaimer requirement for further
21227825Stheraven *    binary redistribution.
22227825Stheraven * 3. Neither the names of the above-listed copyright holders nor the names
23227825Stheraven *    of any contributors may be used to endorse or promote products derived
24227825Stheraven *    from this software without specific prior written permission.
25227825Stheraven *
26227825Stheraven * Alternatively, this software may be distributed under the terms of the
27227825Stheraven * GNU General Public License ("GPL") version 2 as published by the Free
28227825Stheraven * Software Foundation.
29227825Stheraven *
30227825Stheraven * NO WARRANTY
31227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32227825Stheraven * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33227825Stheraven * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34227825Stheraven * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35227825Stheraven * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39227825Stheraven * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40227825Stheraven * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41227825Stheraven * POSSIBILITY OF SUCH DAMAGES.
42227825Stheraven */
43227825Stheraven
44227825Stheraven#include <contrib/dev/acpica/compiler/aslcompiler.h>
45227825Stheraven#include "aslcompiler.y.h"
46227825Stheraven#include <contrib/dev/acpica/include/acnamesp.h>
47227825Stheraven
48227825Stheraven
49227825Stheraven#define _COMPONENT          ACPI_COMPILER
50227825Stheraven        ACPI_MODULE_NAME    ("aslnamesp")
51227825Stheraven
52227825Stheraven/* Local prototypes */
53227825Stheraven
54227825Stheravenstatic ACPI_STATUS
55227825StheravenNsDoOneNamespaceObject (
56227825Stheraven    ACPI_HANDLE             ObjHandle,
57227825Stheraven    UINT32                  Level,
58227825Stheraven    void                    *Context,
59227825Stheraven    void                    **ReturnValue);
60227825Stheraven
61227825Stheravenstatic ACPI_STATUS
62227825StheravenNsDoOnePathname (
63227825Stheraven    ACPI_HANDLE             ObjHandle,
64227825Stheraven    UINT32                  Level,
65227825Stheraven    void                    *Context,
66227825Stheraven    void                    **ReturnValue);
67227825Stheraven
68227825Stheraven
69227825Stheraven/*******************************************************************************
70227825Stheraven *
71227825Stheraven * FUNCTION:    NsSetupNamespaceListing
72227825Stheraven *
73227825Stheraven * PARAMETERS:  Handle          - local file handle
74227825Stheraven *
75227825Stheraven * RETURN:      None
76227825Stheraven *
77227825Stheraven * DESCRIPTION: Set the namespace output file to the input handle
78227825Stheraven *
79227825Stheraven ******************************************************************************/
80227825Stheraven
81227825Stheravenvoid
82227825StheravenNsSetupNamespaceListing (
83227825Stheraven    void                    *Handle)
84227825Stheraven{
85227825Stheraven
86227825Stheraven    Gbl_NsOutputFlag = TRUE;
87227825Stheraven    Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
88227825Stheraven}
89227825Stheraven
90227825Stheraven
91227825Stheraven/*******************************************************************************
92227825Stheraven *
93227825Stheraven * FUNCTION:    NsDisplayNamespace
94227825Stheraven *
95227825Stheraven * PARAMETERS:  None
96227825Stheraven *
97227825Stheraven * RETURN:      Status
98227825Stheraven *
99227825Stheraven * DESCRIPTION: Walk the namespace an display information about each node
100227825Stheraven *              in the tree. Information is written to the optional
101227825Stheraven *              namespace output file.
102227825Stheraven *
103227825Stheraven ******************************************************************************/
104227825Stheraven
105227825StheravenACPI_STATUS
106227825StheravenNsDisplayNamespace (
107227825Stheraven    void)
108227825Stheraven{
109227825Stheraven    ACPI_STATUS             Status;
110227825Stheraven
111227825Stheraven
112227825Stheraven    if (!Gbl_NsOutputFlag)
113227825Stheraven    {
114227825Stheraven        return (AE_OK);
115227825Stheraven    }
116227825Stheraven
117227825Stheraven    Gbl_NumNamespaceObjects = 0;
118227825Stheraven
119227825Stheraven    /* File header */
120227825Stheraven
121227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
122227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count  Depth    Name - Type\n\n");
123227825Stheraven
124227825Stheraven    /* Walk entire namespace from the root */
125227825Stheraven
126227825Stheraven    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
127227825Stheraven                ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
128227825Stheraven                NULL, NULL);
129227825Stheraven
130227825Stheraven    /* Print the full pathname for each namespace node */
131227825Stheraven
132227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
133227825Stheraven
134227825Stheraven    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
135227825Stheraven                ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
136227825Stheraven                NULL, NULL);
137227825Stheraven
138227825Stheraven    return (Status);
139227825Stheraven}
140227825Stheraven
141227825Stheraven
142227825Stheraven/*******************************************************************************
143227825Stheraven *
144227825Stheraven * FUNCTION:    NsDoOneNamespaceObject
145227825Stheraven *
146227825Stheraven * PARAMETERS:  ACPI_WALK_CALLBACK
147227825Stheraven *
148227825Stheraven * RETURN:      Status
149227825Stheraven *
150227825Stheraven * DESCRIPTION: Dump a namespace object to the namespace output file.
151227825Stheraven *              Called during the walk of the namespace to dump all objects.
152227825Stheraven *
153227825Stheraven ******************************************************************************/
154227825Stheraven
155227825Stheravenstatic ACPI_STATUS
156227825StheravenNsDoOneNamespaceObject (
157227825Stheraven    ACPI_HANDLE             ObjHandle,
158227825Stheraven    UINT32                  Level,
159227825Stheraven    void                    *Context,
160227825Stheraven    void                    **ReturnValue)
161227825Stheraven{
162227825Stheraven    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
163227825Stheraven    ACPI_OPERAND_OBJECT     *ObjDesc;
164227825Stheraven    ACPI_PARSE_OBJECT       *Op;
165227825Stheraven
166227825Stheraven
167227825Stheraven    Gbl_NumNamespaceObjects++;
168227825Stheraven
169227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u  [%u]  %*s %4.4s - %s",
170227825Stheraven        Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
171227825Stheraven        &Node->Name,
172227825Stheraven        AcpiUtGetTypeName (Node->Type));
173227825Stheraven
174227825Stheraven    Op = Node->Op;
175227825Stheraven    ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
176227825Stheraven
177227825Stheraven    if (!Op)
178227825Stheraven    {
179227825Stheraven        FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
180241903Sdim        return (AE_OK);
181227825Stheraven    }
182227825Stheraven
183241903Sdim
184227825Stheraven    if ((ObjDesc) &&
185227825Stheraven        (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
186227825Stheraven    {
187227825Stheraven        switch (Node->Type)
188241903Sdim        {
189227825Stheraven        case ACPI_TYPE_INTEGER:
190227825Stheraven
191227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
192227825Stheraven                "       [Initial Value   0x%8.8X%8.8X]",
193227825Stheraven                ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
194227825Stheraven            break;
195227825Stheraven
196227825Stheraven        case ACPI_TYPE_STRING:
197227825Stheraven
198227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
199227825Stheraven                "        [Initial Value   \"%s\"]",
200227825Stheraven                ObjDesc->String.Pointer);
201227825Stheraven            break;
202227825Stheraven
203227825Stheraven        default:
204227825Stheraven
205227825Stheraven            /* Nothing to do for other types */
206227825Stheraven
207227825Stheraven            break;
208227825Stheraven        }
209227825Stheraven
210227825Stheraven    }
211227825Stheraven    else
212227825Stheraven    {
213227825Stheraven        switch (Node->Type)
214227825Stheraven        {
215227825Stheraven        case ACPI_TYPE_INTEGER:
216227825Stheraven
217227825Stheraven            if (Op->Asl.ParseOpcode == PARSEOP_NAME)
218227825Stheraven            {
219227825Stheraven                Op = Op->Asl.Child;
220227825Stheraven            }
221227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
222227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
223227825Stheraven            {
224227825Stheraven                Op = Op->Asl.Next;
225227825Stheraven            }
226227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
227227825Stheraven                "       [Initial Value   0x%8.8X%8.8X]",
228227825Stheraven                ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
229227825Stheraven            break;
230227825Stheraven
231227825Stheraven        case ACPI_TYPE_STRING:
232227825Stheraven
233227825Stheraven            if (Op->Asl.ParseOpcode == PARSEOP_NAME)
234227825Stheraven            {
235227825Stheraven                Op = Op->Asl.Child;
236227825Stheraven            }
237227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
238227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
239227825Stheraven            {
240227825Stheraven                Op = Op->Asl.Next;
241227825Stheraven            }
242227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
243227825Stheraven                "        [Initial Value   \"%s\"]",
244227825Stheraven                Op->Asl.Value.String);
245227825Stheraven            break;
246227825Stheraven
247227825Stheraven        case ACPI_TYPE_LOCAL_REGION_FIELD:
248227825Stheraven
249227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
250227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
251227825Stheraven            {
252227825Stheraven                Op = Op->Asl.Child;
253227825Stheraven            }
254227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
255227825Stheraven                "   [Offset 0x%04X   Length 0x%04X bits]",
256227825Stheraven                Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
257227825Stheraven            break;
258227825Stheraven
259227825Stheraven        case ACPI_TYPE_BUFFER_FIELD:
260227825Stheraven
261227825Stheraven            switch (Op->Asl.ParseOpcode)
262227825Stheraven            {
263227825Stheraven            case PARSEOP_CREATEBYTEFIELD:
264227825Stheraven
265227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BYTE  ( 8 bit)]");
266227825Stheraven                break;
267227825Stheraven
268227825Stheraven            case PARSEOP_CREATEDWORDFIELD:
269227825Stheraven
270227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [DWORD (32 bit)]");
271227825Stheraven                break;
272227825Stheraven
273227825Stheraven            case PARSEOP_CREATEQWORDFIELD:
274227825Stheraven
275227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [QWORD (64 bit)]");
276227825Stheraven                break;
277227825Stheraven
278227825Stheraven            case PARSEOP_CREATEWORDFIELD:
279227825Stheraven
280227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [WORD  (16 bit)]");
281227825Stheraven                break;
282227825Stheraven
283227825Stheraven            case PARSEOP_CREATEBITFIELD:
284227825Stheraven
285227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BIT   ( 1 bit)]");
286227825Stheraven                break;
287227825Stheraven
288227825Stheraven            case PARSEOP_CREATEFIELD:
289227825Stheraven
290227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [Arbitrary Bit Field]");
291227825Stheraven                break;
292227825Stheraven
293227825Stheraven            default:
294227825Stheraven
295227825Stheraven                break;
296227825Stheraven
297227825Stheraven            }
298227825Stheraven            break;
299227825Stheraven
300227825Stheraven        case ACPI_TYPE_PACKAGE:
301227825Stheraven
302227825Stheraven            if (Op->Asl.ParseOpcode == PARSEOP_NAME)
303227825Stheraven            {
304227825Stheraven                Op = Op->Asl.Child;
305227825Stheraven            }
306227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
307227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
308227825Stheraven            {
309227825Stheraven                Op = Op->Asl.Next;
310227825Stheraven            }
311227825Stheraven            Op = Op->Asl.Child;
312227825Stheraven
313227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
314227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
315227825Stheraven            {
316227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
317227825Stheraven                    "       [Initial Length  0x%.2X elements]",
318227825Stheraven                    Op->Asl.Value.Integer);
319227825Stheraven            }
320227825Stheraven            break;
321227825Stheraven
322227825Stheraven        case ACPI_TYPE_BUFFER:
323227825Stheraven
324227825Stheraven            if (Op->Asl.ParseOpcode == PARSEOP_NAME)
325227825Stheraven            {
326227825Stheraven                Op = Op->Asl.Child;
327227825Stheraven            }
328227825Stheraven            if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
329227825Stheraven                (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
330227825Stheraven            {
331227825Stheraven                Op = Op->Asl.Next;
332227825Stheraven            }
333227825Stheraven            Op = Op->Asl.Child;
334227825Stheraven
335227825Stheraven            if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
336227825Stheraven            {
337227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
338227825Stheraven                    "        [Initial Length  0x%.2X bytes]",
339227825Stheraven                    Op->Asl.Value.Integer);
340227825Stheraven            }
341227825Stheraven            break;
342227825Stheraven
343227825Stheraven        case ACPI_TYPE_METHOD:
344227825Stheraven
345227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
346227825Stheraven                "        [Code Length     0x%.4X bytes]",
347227825Stheraven                Op->Asl.AmlSubtreeLength);
348227825Stheraven            break;
349227825Stheraven
350227825Stheraven        case ACPI_TYPE_LOCAL_RESOURCE:
351227825Stheraven
352227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
353227825Stheraven                "  [Desc Offset     0x%.4X Bytes]", Node->Value);
354227825Stheraven            break;
355227825Stheraven
356227825Stheraven        case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
357227825Stheraven
358227825Stheraven            FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
359227825Stheraven                "   [Field Offset    0x%.4X Bits 0x%.4X Bytes] ",
360227825Stheraven                Node->Value, Node->Value / 8);
361227825Stheraven
362227825Stheraven            if (Node->Flags & ANOBJ_IS_REFERENCED)
363227825Stheraven            {
364227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
365227825Stheraven                    "Referenced");
366227825Stheraven            }
367227825Stheraven            else
368227825Stheraven            {
369227825Stheraven                FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
370227825Stheraven                    "Name not referenced");
371227825Stheraven            }
372227825Stheraven            break;
373227825Stheraven
374227825Stheraven        default:
375227825Stheraven
376227825Stheraven            /* Nothing to do for other types */
377227825Stheraven
378227825Stheraven            break;
379227825Stheraven        }
380227825Stheraven    }
381227825Stheraven
382227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
383227825Stheraven    return (AE_OK);
384227825Stheraven}
385227825Stheraven
386227825Stheraven
387227825Stheraven/*******************************************************************************
388227825Stheraven *
389227825Stheraven * FUNCTION:    NsDoOnePathname
390227825Stheraven *
391227825Stheraven * PARAMETERS:  ACPI_WALK_CALLBACK
392227825Stheraven *
393227825Stheraven * RETURN:      Status
394227825Stheraven *
395227825Stheraven * DESCRIPTION: Print the full pathname for a namespace node.
396227825Stheraven *
397227825Stheraven ******************************************************************************/
398227825Stheraven
399227825Stheravenstatic ACPI_STATUS
400227825StheravenNsDoOnePathname (
401227825Stheraven    ACPI_HANDLE             ObjHandle,
402227825Stheraven    UINT32                  Level,
403227825Stheraven    void                    *Context,
404227825Stheraven    void                    **ReturnValue)
405227825Stheraven{
406227825Stheraven    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
407227825Stheraven    ACPI_STATUS             Status;
408227825Stheraven    ACPI_BUFFER             TargetPath;
409227825Stheraven
410227825Stheraven
411227825Stheraven    TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
412227825Stheraven    Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
413227825Stheraven    if (ACPI_FAILURE (Status))
414227825Stheraven    {
415227825Stheraven        return (Status);
416227825Stheraven    }
417227825Stheraven
418227825Stheraven    FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
419227825Stheraven    ACPI_FREE (TargetPath.Pointer);
420227825Stheraven
421227825Stheraven    return (AE_OK);
422227825Stheraven}
423227825Stheraven