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