xref: /freebsd/sys/contrib/dev/acpica/compiler/aslnamesp.c (revision 8d20be1e22095c27faf8fe8b2f0d089739cc742e)
1 /******************************************************************************
2  *
3  * Module Name: aslnamesp - Namespace output file generation
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 
45 #include <contrib/dev/acpica/compiler/aslcompiler.h>
46 #include "aslcompiler.y.h"
47 #include <contrib/dev/acpica/include/acnamesp.h>
48 
49 
50 #define _COMPONENT          ACPI_COMPILER
51         ACPI_MODULE_NAME    ("aslnamesp")
52 
53 /* Local prototypes */
54 
55 static ACPI_STATUS
56 NsDoOneNamespaceObject (
57     ACPI_HANDLE             ObjHandle,
58     UINT32                  Level,
59     void                    *Context,
60     void                    **ReturnValue);
61 
62 static ACPI_STATUS
63 NsDoOnePathname (
64     ACPI_HANDLE             ObjHandle,
65     UINT32                  Level,
66     void                    *Context,
67     void                    **ReturnValue);
68 
69 
70 /*******************************************************************************
71  *
72  * FUNCTION:    NsSetupNamespaceListing
73  *
74  * PARAMETERS:  Handle          - local file handle
75  *
76  * RETURN:      None
77  *
78  * DESCRIPTION: Set the namespace output file to the input handle
79  *
80  ******************************************************************************/
81 
82 void
83 NsSetupNamespaceListing (
84     void                    *Handle)
85 {
86 
87     Gbl_NsOutputFlag = TRUE;
88     Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
89 }
90 
91 
92 /*******************************************************************************
93  *
94  * FUNCTION:    NsDisplayNamespace
95  *
96  * PARAMETERS:  None
97  *
98  * RETURN:      Status
99  *
100  * DESCRIPTION: Walk the namespace an display information about each node
101  *              in the tree. Information is written to the optional
102  *              namespace output file.
103  *
104  ******************************************************************************/
105 
106 ACPI_STATUS
107 NsDisplayNamespace (
108     void)
109 {
110     ACPI_STATUS             Status;
111 
112 
113     if (!Gbl_NsOutputFlag)
114     {
115         return (AE_OK);
116     }
117 
118     Gbl_NumNamespaceObjects = 0;
119 
120     /* File header */
121 
122     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
123     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count  Depth    Name - Type\n\n");
124 
125     /* Walk entire namespace from the root */
126 
127     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
128                 ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
129                 NULL, NULL);
130 
131     /* Print the full pathname for each namespace node */
132 
133     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
134 
135     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
136                 ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
137                 NULL, NULL);
138 
139     return (Status);
140 }
141 
142 
143 /*******************************************************************************
144  *
145  * FUNCTION:    NsDoOneNamespaceObject
146  *
147  * PARAMETERS:  ACPI_WALK_CALLBACK
148  *
149  * RETURN:      Status
150  *
151  * DESCRIPTION: Dump a namespace object to the namespace output file.
152  *              Called during the walk of the namespace to dump all objects.
153  *
154  ******************************************************************************/
155 
156 static ACPI_STATUS
157 NsDoOneNamespaceObject (
158     ACPI_HANDLE             ObjHandle,
159     UINT32                  Level,
160     void                    *Context,
161     void                    **ReturnValue)
162 {
163     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
164     ACPI_OPERAND_OBJECT     *ObjDesc;
165     ACPI_PARSE_OBJECT       *Op;
166 
167 
168     Gbl_NumNamespaceObjects++;
169 
170     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u  [%u]  %*s %4.4s - %s",
171         Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
172         &Node->Name,
173         AcpiUtGetTypeName (Node->Type));
174 
175     Op = Node->Op;
176     ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
177 
178     if (!Op)
179     {
180         FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
181         return (AE_OK);
182     }
183 
184 
185     if ((ObjDesc) &&
186         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
187     {
188         switch (Node->Type)
189         {
190         case ACPI_TYPE_INTEGER:
191 
192             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
193                 "       [Initial Value   0x%8.8X%8.8X]",
194                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
195             break;
196 
197         case ACPI_TYPE_STRING:
198 
199             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
200                 "        [Initial Value   \"%s\"]",
201                 ObjDesc->String.Pointer);
202             break;
203 
204         default:
205 
206             /* Nothing to do for other types */
207 
208             break;
209         }
210 
211     }
212     else
213     {
214         switch (Node->Type)
215         {
216         case ACPI_TYPE_INTEGER:
217 
218             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
219             {
220                 Op = Op->Asl.Child;
221             }
222             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
223                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
224             {
225                 Op = Op->Asl.Next;
226             }
227             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
228                 "       [Initial Value   0x%8.8X%8.8X]",
229                 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
230             break;
231 
232         case ACPI_TYPE_STRING:
233 
234             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
235             {
236                 Op = Op->Asl.Child;
237             }
238             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
239                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
240             {
241                 Op = Op->Asl.Next;
242             }
243             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
244                 "        [Initial Value   \"%s\"]",
245                 Op->Asl.Value.String);
246             break;
247 
248         case ACPI_TYPE_LOCAL_REGION_FIELD:
249 
250             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
251                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
252             {
253                 Op = Op->Asl.Child;
254             }
255             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
256                 "   [Offset 0x%04X   Length 0x%04X bits]",
257                 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
258             break;
259 
260         case ACPI_TYPE_BUFFER_FIELD:
261 
262             switch (Op->Asl.ParseOpcode)
263             {
264             case PARSEOP_CREATEBYTEFIELD:
265 
266                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BYTE  ( 8 bit)]");
267                 break;
268 
269             case PARSEOP_CREATEDWORDFIELD:
270 
271                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [DWORD (32 bit)]");
272                 break;
273 
274             case PARSEOP_CREATEQWORDFIELD:
275 
276                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [QWORD (64 bit)]");
277                 break;
278 
279             case PARSEOP_CREATEWORDFIELD:
280 
281                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [WORD  (16 bit)]");
282                 break;
283 
284             case PARSEOP_CREATEBITFIELD:
285 
286                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BIT   ( 1 bit)]");
287                 break;
288 
289             case PARSEOP_CREATEFIELD:
290 
291                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [Arbitrary Bit Field]");
292                 break;
293 
294             default:
295 
296                 break;
297 
298             }
299             break;
300 
301         case ACPI_TYPE_PACKAGE:
302 
303             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
304             {
305                 Op = Op->Asl.Child;
306             }
307             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
308                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
309             {
310                 Op = Op->Asl.Next;
311             }
312             Op = Op->Asl.Child;
313 
314             if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
315                 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
316             {
317                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
318                     "       [Initial Length  0x%.2X elements]",
319                     Op->Asl.Value.Integer);
320             }
321             break;
322 
323         case ACPI_TYPE_BUFFER:
324 
325             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
326             {
327                 Op = Op->Asl.Child;
328             }
329             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
330                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
331             {
332                 Op = Op->Asl.Next;
333             }
334             Op = Op->Asl.Child;
335 
336             if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
337             {
338                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
339                     "        [Initial Length  0x%.2X bytes]",
340                     Op->Asl.Value.Integer);
341             }
342             break;
343 
344         case ACPI_TYPE_METHOD:
345 
346             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
347                 "        [Code Length     0x%.4X bytes]",
348                 Op->Asl.AmlSubtreeLength);
349             break;
350 
351         case ACPI_TYPE_LOCAL_RESOURCE:
352 
353             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
354                 "  [Desc Offset     0x%.4X Bytes]", Node->Value);
355             break;
356 
357         case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
358 
359             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
360                 "   [Field Offset    0x%.4X Bits 0x%.4X Bytes] ",
361                 Node->Value, Node->Value / 8);
362 
363             if (Node->Flags & ANOBJ_IS_REFERENCED)
364             {
365                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
366                     "Referenced");
367             }
368             else
369             {
370                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
371                     "Name not referenced");
372             }
373             break;
374 
375         default:
376 
377             /* Nothing to do for other types */
378 
379             break;
380         }
381     }
382 
383     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
384     return (AE_OK);
385 }
386 
387 
388 /*******************************************************************************
389  *
390  * FUNCTION:    NsDoOnePathname
391  *
392  * PARAMETERS:  ACPI_WALK_CALLBACK
393  *
394  * RETURN:      Status
395  *
396  * DESCRIPTION: Print the full pathname for a namespace node.
397  *
398  ******************************************************************************/
399 
400 static ACPI_STATUS
401 NsDoOnePathname (
402     ACPI_HANDLE             ObjHandle,
403     UINT32                  Level,
404     void                    *Context,
405     void                    **ReturnValue)
406 {
407     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
408     ACPI_STATUS             Status;
409     ACPI_BUFFER             TargetPath;
410 
411 
412     TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
413     Status = AcpiNsHandleToPathname (Node, &TargetPath);
414     if (ACPI_FAILURE (Status))
415     {
416         return (Status);
417     }
418 
419     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
420     ACPI_FREE (TargetPath.Pointer);
421 
422     return (AE_OK);
423 }
424