aslnamesp.c revision 1.1.1.12 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.12 christos * Copyright (C) 2000 - 2020, 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 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
122 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "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 christos /* Print the full pathname for each namespace node */
135 1.1 christos
136 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
137 1.1 christos
138 1.1 christos Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
139 1.1.1.5 christos ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
140 1.1.1.5 christos NULL, NULL);
141 1.1 christos
142 1.1 christos return (Status);
143 1.1 christos }
144 1.1 christos
145 1.1 christos
146 1.1 christos /*******************************************************************************
147 1.1 christos *
148 1.1 christos * FUNCTION: NsDoOneNamespaceObject
149 1.1 christos *
150 1.1 christos * PARAMETERS: ACPI_WALK_CALLBACK
151 1.1 christos *
152 1.1 christos * RETURN: Status
153 1.1 christos *
154 1.1 christos * DESCRIPTION: Dump a namespace object to the namespace output file.
155 1.1 christos * Called during the walk of the namespace to dump all objects.
156 1.1 christos *
157 1.1 christos ******************************************************************************/
158 1.1 christos
159 1.1 christos static ACPI_STATUS
160 1.1 christos NsDoOneNamespaceObject (
161 1.1 christos ACPI_HANDLE ObjHandle,
162 1.1 christos UINT32 Level,
163 1.1 christos void *Context,
164 1.1 christos void **ReturnValue)
165 1.1 christos {
166 1.1 christos ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
167 1.1 christos ACPI_OPERAND_OBJECT *ObjDesc;
168 1.1 christos ACPI_PARSE_OBJECT *Op;
169 1.1 christos
170 1.1 christos
171 1.1.1.8 christos AslGbl_NumNamespaceObjects++;
172 1.1 christos
173 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s",
174 1.1.1.8 christos AslGbl_NumNamespaceObjects, Level, (Level * 3), " ",
175 1.1.1.10 christos &Node->Name.Ascii[0], AcpiUtGetTypeName (Node->Type));
176 1.1 christos
177 1.1 christos Op = Node->Op;
178 1.1 christos ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
179 1.1 christos
180 1.1 christos if (!Op)
181 1.1 christos {
182 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
183 1.1 christos return (AE_OK);
184 1.1 christos }
185 1.1 christos
186 1.1 christos
187 1.1 christos if ((ObjDesc) &&
188 1.1 christos (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
189 1.1 christos {
190 1.1 christos switch (Node->Type)
191 1.1 christos {
192 1.1 christos case ACPI_TYPE_INTEGER:
193 1.1 christos
194 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
195 1.1 christos " [Initial Value 0x%8.8X%8.8X]",
196 1.1 christos ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
197 1.1 christos break;
198 1.1 christos
199 1.1 christos case ACPI_TYPE_STRING:
200 1.1 christos
201 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
202 1.1 christos " [Initial Value \"%s\"]",
203 1.1 christos ObjDesc->String.Pointer);
204 1.1 christos break;
205 1.1 christos
206 1.1 christos default:
207 1.1 christos
208 1.1 christos /* Nothing to do for other types */
209 1.1 christos
210 1.1 christos break;
211 1.1 christos }
212 1.1 christos
213 1.1 christos }
214 1.1 christos else
215 1.1 christos {
216 1.1 christos switch (Node->Type)
217 1.1 christos {
218 1.1 christos case ACPI_TYPE_INTEGER:
219 1.1 christos
220 1.1 christos if (Op->Asl.ParseOpcode == PARSEOP_NAME)
221 1.1 christos {
222 1.1 christos Op = Op->Asl.Child;
223 1.1 christos }
224 1.1.1.5 christos
225 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
226 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
227 1.1 christos {
228 1.1 christos Op = Op->Asl.Next;
229 1.1 christos }
230 1.1.1.5 christos
231 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
232 1.1 christos " [Initial Value 0x%8.8X%8.8X]",
233 1.1 christos ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
234 1.1 christos break;
235 1.1 christos
236 1.1 christos case ACPI_TYPE_STRING:
237 1.1 christos
238 1.1 christos if (Op->Asl.ParseOpcode == PARSEOP_NAME)
239 1.1 christos {
240 1.1 christos Op = Op->Asl.Child;
241 1.1 christos }
242 1.1.1.5 christos
243 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
244 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
245 1.1 christos {
246 1.1 christos Op = Op->Asl.Next;
247 1.1 christos }
248 1.1.1.5 christos
249 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
250 1.1 christos " [Initial Value \"%s\"]",
251 1.1 christos Op->Asl.Value.String);
252 1.1 christos break;
253 1.1 christos
254 1.1 christos case ACPI_TYPE_LOCAL_REGION_FIELD:
255 1.1 christos
256 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
257 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
258 1.1 christos {
259 1.1 christos Op = Op->Asl.Child;
260 1.1 christos }
261 1.1.1.5 christos
262 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
263 1.1 christos " [Offset 0x%04X Length 0x%04X bits]",
264 1.1 christos Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
265 1.1 christos break;
266 1.1 christos
267 1.1 christos case ACPI_TYPE_BUFFER_FIELD:
268 1.1 christos
269 1.1 christos switch (Op->Asl.ParseOpcode)
270 1.1 christos {
271 1.1 christos case PARSEOP_CREATEBYTEFIELD:
272 1.1 christos
273 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]");
274 1.1 christos break;
275 1.1 christos
276 1.1 christos case PARSEOP_CREATEDWORDFIELD:
277 1.1 christos
278 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]");
279 1.1 christos break;
280 1.1 christos
281 1.1 christos case PARSEOP_CREATEQWORDFIELD:
282 1.1 christos
283 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]");
284 1.1 christos break;
285 1.1 christos
286 1.1 christos case PARSEOP_CREATEWORDFIELD:
287 1.1 christos
288 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]");
289 1.1 christos break;
290 1.1 christos
291 1.1 christos case PARSEOP_CREATEBITFIELD:
292 1.1 christos
293 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]");
294 1.1 christos break;
295 1.1 christos
296 1.1 christos case PARSEOP_CREATEFIELD:
297 1.1 christos
298 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]");
299 1.1 christos break;
300 1.1 christos
301 1.1 christos default:
302 1.1 christos
303 1.1 christos break;
304 1.1 christos
305 1.1 christos }
306 1.1 christos break;
307 1.1 christos
308 1.1 christos case ACPI_TYPE_PACKAGE:
309 1.1 christos
310 1.1 christos if (Op->Asl.ParseOpcode == PARSEOP_NAME)
311 1.1 christos {
312 1.1 christos Op = Op->Asl.Child;
313 1.1 christos }
314 1.1.1.5 christos
315 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
316 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
317 1.1 christos {
318 1.1 christos Op = Op->Asl.Next;
319 1.1 christos }
320 1.1.1.5 christos
321 1.1 christos Op = Op->Asl.Child;
322 1.1 christos
323 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
324 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
325 1.1 christos {
326 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
327 1.1 christos " [Initial Length 0x%.2X elements]",
328 1.1.1.10 christos (UINT32) Op->Asl.Value.Integer);
329 1.1 christos }
330 1.1 christos break;
331 1.1 christos
332 1.1 christos case ACPI_TYPE_BUFFER:
333 1.1 christos
334 1.1 christos if (Op->Asl.ParseOpcode == PARSEOP_NAME)
335 1.1 christos {
336 1.1 christos Op = Op->Asl.Child;
337 1.1 christos }
338 1.1.1.5 christos
339 1.1 christos if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
340 1.1 christos (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
341 1.1 christos {
342 1.1 christos Op = Op->Asl.Next;
343 1.1 christos }
344 1.1.1.5 christos
345 1.1 christos Op = Op->Asl.Child;
346 1.1 christos
347 1.1 christos if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
348 1.1 christos {
349 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
350 1.1 christos " [Initial Length 0x%.2X bytes]",
351 1.1.1.10 christos (UINT32) Op->Asl.Value.Integer);
352 1.1 christos }
353 1.1 christos break;
354 1.1 christos
355 1.1 christos case ACPI_TYPE_METHOD:
356 1.1 christos
357 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
358 1.1 christos " [Code Length 0x%.4X bytes]",
359 1.1 christos Op->Asl.AmlSubtreeLength);
360 1.1 christos break;
361 1.1 christos
362 1.1 christos case ACPI_TYPE_LOCAL_RESOURCE:
363 1.1 christos
364 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
365 1.1 christos " [Desc Offset 0x%.4X Bytes]", Node->Value);
366 1.1 christos break;
367 1.1 christos
368 1.1 christos case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
369 1.1 christos
370 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
371 1.1 christos " [Field Offset 0x%.4X Bits 0x%.4X Bytes] ",
372 1.1 christos Node->Value, Node->Value / 8);
373 1.1 christos
374 1.1 christos if (Node->Flags & ANOBJ_IS_REFERENCED)
375 1.1 christos {
376 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
377 1.1 christos "Referenced");
378 1.1 christos }
379 1.1 christos else
380 1.1 christos {
381 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
382 1.1 christos "Name not referenced");
383 1.1 christos }
384 1.1 christos break;
385 1.1 christos
386 1.1 christos default:
387 1.1 christos
388 1.1 christos /* Nothing to do for other types */
389 1.1 christos
390 1.1 christos break;
391 1.1 christos }
392 1.1 christos }
393 1.1 christos
394 1.1 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
395 1.1 christos return (AE_OK);
396 1.1 christos }
397 1.1 christos
398 1.1 christos
399 1.1 christos /*******************************************************************************
400 1.1 christos *
401 1.1 christos * FUNCTION: NsDoOnePathname
402 1.1 christos *
403 1.1 christos * PARAMETERS: ACPI_WALK_CALLBACK
404 1.1 christos *
405 1.1 christos * RETURN: Status
406 1.1 christos *
407 1.1 christos * DESCRIPTION: Print the full pathname for a namespace node.
408 1.1 christos *
409 1.1 christos ******************************************************************************/
410 1.1 christos
411 1.1 christos static ACPI_STATUS
412 1.1 christos NsDoOnePathname (
413 1.1 christos ACPI_HANDLE ObjHandle,
414 1.1 christos UINT32 Level,
415 1.1 christos void *Context,
416 1.1 christos void **ReturnValue)
417 1.1 christos {
418 1.1 christos ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
419 1.1 christos ACPI_STATUS Status;
420 1.1 christos ACPI_BUFFER TargetPath;
421 1.1 christos
422 1.1 christos
423 1.1 christos TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
424 1.1.1.4 christos Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
425 1.1 christos if (ACPI_FAILURE (Status))
426 1.1 christos {
427 1.1 christos return (Status);
428 1.1 christos }
429 1.1 christos
430 1.1.1.10 christos FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n",
431 1.1.1.10 christos ACPI_CAST_PTR (char, TargetPath.Pointer));
432 1.1 christos ACPI_FREE (TargetPath.Pointer);
433 1.1 christos return (AE_OK);
434 1.1 christos }
435