xref: /freebsd/sys/contrib/dev/acpica/compiler/aslnamesp.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /******************************************************************************
2  *
3  * Module Name: aslnamesp - Namespace output file generation
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, 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 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/acnamesp.h>
47 
48 
49 #define _COMPONENT          ACPI_COMPILER
50         ACPI_MODULE_NAME    ("aslnamesp")
51 
52 /* Local prototypes */
53 
54 static ACPI_STATUS
55 NsDoOneNamespaceObject (
56     ACPI_HANDLE             ObjHandle,
57     UINT32                  Level,
58     void                    *Context,
59     void                    **ReturnValue);
60 
61 static ACPI_STATUS
62 NsDoOnePathname (
63     ACPI_HANDLE             ObjHandle,
64     UINT32                  Level,
65     void                    *Context,
66     void                    **ReturnValue);
67 
68 
69 /*******************************************************************************
70  *
71  * FUNCTION:    NsSetupNamespaceListing
72  *
73  * PARAMETERS:  Handle          - local file handle
74  *
75  * RETURN:      None
76  *
77  * DESCRIPTION: Set the namespace output file to the input handle
78  *
79  ******************************************************************************/
80 
81 void
82 NsSetupNamespaceListing (
83     void                    *Handle)
84 {
85 
86     Gbl_NsOutputFlag = TRUE;
87     Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
88 }
89 
90 
91 /*******************************************************************************
92  *
93  * FUNCTION:    NsDisplayNamespace
94  *
95  * PARAMETERS:  None
96  *
97  * RETURN:      Status
98  *
99  * DESCRIPTION: Walk the namespace an display information about each node
100  *              in the tree. Information is written to the optional
101  *              namespace output file.
102  *
103  ******************************************************************************/
104 
105 ACPI_STATUS
106 NsDisplayNamespace (
107     void)
108 {
109     ACPI_STATUS             Status;
110 
111 
112     if (!Gbl_NsOutputFlag)
113     {
114         return (AE_OK);
115     }
116 
117     Gbl_NumNamespaceObjects = 0;
118 
119     /* File header */
120 
121     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
122     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count  Depth    Name - Type\n\n");
123 
124     /* Walk entire namespace from the root */
125 
126     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
127                 ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
128                 NULL, NULL);
129 
130     /* Print the full pathname for each namespace node */
131 
132     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
133 
134     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
135                 ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
136                 NULL, NULL);
137 
138     return (Status);
139 }
140 
141 
142 /*******************************************************************************
143  *
144  * FUNCTION:    NsDoOneNamespaceObject
145  *
146  * PARAMETERS:  ACPI_WALK_CALLBACK
147  *
148  * RETURN:      Status
149  *
150  * DESCRIPTION: Dump a namespace object to the namespace output file.
151  *              Called during the walk of the namespace to dump all objects.
152  *
153  ******************************************************************************/
154 
155 static ACPI_STATUS
156 NsDoOneNamespaceObject (
157     ACPI_HANDLE             ObjHandle,
158     UINT32                  Level,
159     void                    *Context,
160     void                    **ReturnValue)
161 {
162     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
163     ACPI_OPERAND_OBJECT     *ObjDesc;
164     ACPI_PARSE_OBJECT       *Op;
165 
166 
167     Gbl_NumNamespaceObjects++;
168 
169     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u  [%u]  %*s %4.4s - %s",
170         Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
171         &Node->Name,
172         AcpiUtGetTypeName (Node->Type));
173 
174     Op = Node->Op;
175     ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
176 
177     if (!Op)
178     {
179         FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
180         return (AE_OK);
181     }
182 
183 
184     if ((ObjDesc) &&
185         (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
186     {
187         switch (Node->Type)
188         {
189         case ACPI_TYPE_INTEGER:
190 
191             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
192                 "       [Initial Value   0x%8.8X%8.8X]",
193                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
194             break;
195 
196         case ACPI_TYPE_STRING:
197 
198             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
199                 "        [Initial Value   \"%s\"]",
200                 ObjDesc->String.Pointer);
201             break;
202 
203         default:
204 
205             /* Nothing to do for other types */
206 
207             break;
208         }
209 
210     }
211     else
212     {
213         switch (Node->Type)
214         {
215         case ACPI_TYPE_INTEGER:
216 
217             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
218             {
219                 Op = Op->Asl.Child;
220             }
221             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
222                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
223             {
224                 Op = Op->Asl.Next;
225             }
226             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
227                 "       [Initial Value   0x%8.8X%8.8X]",
228                 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
229             break;
230 
231         case ACPI_TYPE_STRING:
232 
233             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
234             {
235                 Op = Op->Asl.Child;
236             }
237             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
238                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
239             {
240                 Op = Op->Asl.Next;
241             }
242             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
243                 "        [Initial Value   \"%s\"]",
244                 Op->Asl.Value.String);
245             break;
246 
247         case ACPI_TYPE_LOCAL_REGION_FIELD:
248 
249             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
250                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
251             {
252                 Op = Op->Asl.Child;
253             }
254             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
255                 "   [Offset 0x%04X   Length 0x%04X bits]",
256                 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
257             break;
258 
259         case ACPI_TYPE_BUFFER_FIELD:
260 
261             switch (Op->Asl.ParseOpcode)
262             {
263             case PARSEOP_CREATEBYTEFIELD:
264 
265                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BYTE  ( 8 bit)]");
266                 break;
267 
268             case PARSEOP_CREATEDWORDFIELD:
269 
270                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [DWORD (32 bit)]");
271                 break;
272 
273             case PARSEOP_CREATEQWORDFIELD:
274 
275                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [QWORD (64 bit)]");
276                 break;
277 
278             case PARSEOP_CREATEWORDFIELD:
279 
280                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [WORD  (16 bit)]");
281                 break;
282 
283             case PARSEOP_CREATEBITFIELD:
284 
285                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [BIT   ( 1 bit)]");
286                 break;
287 
288             case PARSEOP_CREATEFIELD:
289 
290                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "   [Arbitrary Bit Field]");
291                 break;
292 
293             default:
294 
295                 break;
296 
297             }
298             break;
299 
300         case ACPI_TYPE_PACKAGE:
301 
302             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
303             {
304                 Op = Op->Asl.Child;
305             }
306             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
307                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
308             {
309                 Op = Op->Asl.Next;
310             }
311             Op = Op->Asl.Child;
312 
313             if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
314                 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
315             {
316                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
317                     "       [Initial Length  0x%.2X elements]",
318                     Op->Asl.Value.Integer);
319             }
320             break;
321 
322         case ACPI_TYPE_BUFFER:
323 
324             if (Op->Asl.ParseOpcode == PARSEOP_NAME)
325             {
326                 Op = Op->Asl.Child;
327             }
328             if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG)  ||
329                 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
330             {
331                 Op = Op->Asl.Next;
332             }
333             Op = Op->Asl.Child;
334 
335             if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
336             {
337                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
338                     "        [Initial Length  0x%.2X bytes]",
339                     Op->Asl.Value.Integer);
340             }
341             break;
342 
343         case ACPI_TYPE_METHOD:
344 
345             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
346                 "        [Code Length     0x%.4X bytes]",
347                 Op->Asl.AmlSubtreeLength);
348             break;
349 
350         case ACPI_TYPE_LOCAL_RESOURCE:
351 
352             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
353                 "  [Desc Offset     0x%.4X Bytes]", Node->Value);
354             break;
355 
356         case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
357 
358             FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
359                 "   [Field Offset    0x%.4X Bits 0x%.4X Bytes] ",
360                 Node->Value, Node->Value / 8);
361 
362             if (Node->Flags & ANOBJ_IS_REFERENCED)
363             {
364                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
365                     "Referenced");
366             }
367             else
368             {
369                 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
370                     "Name not referenced");
371             }
372             break;
373 
374         default:
375 
376             /* Nothing to do for other types */
377 
378             break;
379         }
380     }
381 
382     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
383     return (AE_OK);
384 }
385 
386 
387 /*******************************************************************************
388  *
389  * FUNCTION:    NsDoOnePathname
390  *
391  * PARAMETERS:  ACPI_WALK_CALLBACK
392  *
393  * RETURN:      Status
394  *
395  * DESCRIPTION: Print the full pathname for a namespace node.
396  *
397  ******************************************************************************/
398 
399 static ACPI_STATUS
400 NsDoOnePathname (
401     ACPI_HANDLE             ObjHandle,
402     UINT32                  Level,
403     void                    *Context,
404     void                    **ReturnValue)
405 {
406     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
407     ACPI_STATUS             Status;
408     ACPI_BUFFER             TargetPath;
409 
410 
411     TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
412     Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
413     if (ACPI_FAILURE (Status))
414     {
415         return (Status);
416     }
417 
418     FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
419     ACPI_FREE (TargetPath.Pointer);
420 
421     return (AE_OK);
422 }
423