Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / asloffset.c
blobb2fe775d84bbf13d997f6d429a1779b3a502fda7
1 /******************************************************************************
3 * Module Name: asloffset - Generate a C "offset table" for BIOS use.
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
46 #include "amlcode.h"
47 #include "acnamesp.h"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("asloffset")
54 /* Local prototypes */
56 static void
57 LsEmitOffsetTableEntry (
58 UINT32 FileId,
59 ACPI_NAMESPACE_NODE *Node,
60 UINT32 NamepathOffset,
61 UINT32 Offset,
62 char *OpName,
63 UINT64 Value,
64 UINT8 AmlOpcode,
65 UINT16 ParentOpcode);
68 /*******************************************************************************
70 * FUNCTION: LsAmlOffsetWalk
72 * PARAMETERS: ASL_WALK_CALLBACK
74 * RETURN: Status
76 * DESCRIPTION: Process one node during a offset table file generation.
78 * Three types of objects are currently emitted to the offset table:
79 * 1) Tagged (named) resource descriptors
80 * 2) Named integer objects with constant integer values
81 * 3) Named package objects
82 * 4) Operation Regions that have constant Offset (address) parameters
83 * 5) Control methods
85 * The offset table allows the BIOS to dynamically update the values of these
86 * objects at boot time.
88 ******************************************************************************/
90 ACPI_STATUS
91 LsAmlOffsetWalk (
92 ACPI_PARSE_OBJECT *Op,
93 UINT32 Level,
94 void *Context)
96 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
97 ACPI_NAMESPACE_NODE *Node;
98 UINT32 Length;
99 UINT32 NamepathOffset;
100 UINT32 DataOffset;
101 ACPI_PARSE_OBJECT *NextOp;
104 /* Ignore actual data blocks for resource descriptors */
106 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
108 return (AE_OK); /* Do NOT update the global AML offset */
111 /* We are only interested in named objects (have a namespace node) */
113 Node = Op->Asl.Node;
114 if (!Node)
116 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
117 return (AE_OK);
120 /* Named resource descriptor (has a descriptor tag) */
122 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE) &&
123 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
125 LsEmitOffsetTableEntry (FileId, Node, 0, Gbl_CurrentAmlOffset,
126 Op->Asl.ParseOpName, 0, Op->Asl.Extra, AML_BUFFER_OP);
128 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
129 return (AE_OK);
132 switch (Op->Asl.AmlOpcode)
134 case AML_NAME_OP:
136 /* Named object -- Name (NameString, DataRefObject) */
138 if (!Op->Asl.Child)
140 FlPrintFile (FileId, "%s NO CHILD!\n", MsgBuffer);
141 return (AE_OK);
144 Length = Op->Asl.FinalAmlLength;
145 NamepathOffset = Gbl_CurrentAmlOffset + Length;
147 /* Get to the NameSeg/NamePath Op (and length of the name) */
149 Op = Op->Asl.Child;
151 /* Get offset of last nameseg and the actual data */
153 NamepathOffset = Gbl_CurrentAmlOffset + Length +
154 (Op->Asl.FinalAmlLength - ACPI_NAME_SIZE);
156 DataOffset = Gbl_CurrentAmlOffset + Length +
157 Op->Asl.FinalAmlLength;
159 /* Get actual value associated with the name */
161 Op = Op->Asl.Next;
162 switch (Op->Asl.AmlOpcode)
164 case AML_BYTE_OP:
165 case AML_WORD_OP:
166 case AML_DWORD_OP:
167 case AML_QWORD_OP:
169 /* The +1 is to handle the integer size prefix (opcode) */
171 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
172 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
173 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
174 break;
176 case AML_ONE_OP:
177 case AML_ONES_OP:
178 case AML_ZERO_OP:
180 /* For these, offset will point to the opcode */
182 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
183 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
184 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
185 break;
187 case AML_PACKAGE_OP:
188 case AML_VAR_PACKAGE_OP:
190 /* Get the package element count */
192 NextOp = Op->Asl.Child;
194 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
195 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
196 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
197 break;
199 default:
200 break;
203 Gbl_CurrentAmlOffset += Length;
204 return (AE_OK);
206 case AML_REGION_OP:
208 /* OperationRegion (NameString, RegionSpace, RegionOffset, RegionLength) */
210 Length = Op->Asl.FinalAmlLength;
212 /* Get the name/namepath node */
214 NextOp = Op->Asl.Child;
216 /* Get offset of last nameseg and the actual data */
218 NamepathOffset = Gbl_CurrentAmlOffset + Length +
219 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
221 DataOffset = Gbl_CurrentAmlOffset + Length +
222 (NextOp->Asl.FinalAmlLength + 1);
224 /* Get the SpaceId node, then the Offset (address) node */
226 NextOp = NextOp->Asl.Next;
227 NextOp = NextOp->Asl.Next;
229 switch (NextOp->Asl.AmlOpcode)
232 * We are only interested in integer constants that can be changed
233 * at boot time. Note, the One/Ones/Zero opcodes are considered
234 * non-changeable, so we ignore them here.
236 case AML_BYTE_OP:
237 case AML_WORD_OP:
238 case AML_DWORD_OP:
239 case AML_QWORD_OP:
241 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
242 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
243 (UINT8) NextOp->Asl.AmlOpcode, AML_REGION_OP);
245 Gbl_CurrentAmlOffset += Length;
246 return (AE_OK);
248 default:
249 break;
251 break;
253 case AML_METHOD_OP:
255 /* Method (Namepath, ...) */
257 Length = Op->Asl.FinalAmlLength;
259 /* Get the NameSeg/NamePath Op */
261 NextOp = Op->Asl.Child;
263 /* Get offset of last nameseg and the actual data (flags byte) */
265 NamepathOffset = Gbl_CurrentAmlOffset + Length +
266 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
268 DataOffset = Gbl_CurrentAmlOffset + Length +
269 NextOp->Asl.FinalAmlLength;
271 /* Get the flags byte Op */
273 NextOp = NextOp->Asl.Next;
275 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
276 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
277 (UINT8) Op->Asl.AmlOpcode, AML_METHOD_OP);
278 break;
280 case AML_PROCESSOR_OP:
282 /* Processor (Namepath, ProcessorId, Address, Length) */
284 Length = Op->Asl.FinalAmlLength;
285 NextOp = Op->Asl.Child; /* Get Namepath */
287 /* Get offset of last nameseg and the actual data (PBlock address) */
289 NamepathOffset = Gbl_CurrentAmlOffset + Length +
290 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
292 DataOffset = Gbl_CurrentAmlOffset + Length +
293 (NextOp->Asl.FinalAmlLength + 1);
295 NextOp = NextOp->Asl.Next; /* Get ProcessorID (BYTE) */
296 NextOp = NextOp->Asl.Next; /* Get Address (DWORD) */
298 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
299 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
300 (UINT8) AML_DWORD_OP, AML_PROCESSOR_OP);
301 break;
303 case AML_DEVICE_OP:
304 case AML_SCOPE_OP:
305 case AML_THERMAL_ZONE_OP:
307 /* Device/Scope/ThermalZone (Namepath) */
309 Length = Op->Asl.FinalAmlLength;
310 NextOp = Op->Asl.Child; /* Get Namepath */
312 /* Get offset of last nameseg */
314 NamepathOffset = Gbl_CurrentAmlOffset + Length +
315 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
317 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, 0,
318 Op->Asl.ParseOpName, 0, (UINT8) 0, Op->Asl.AmlOpcode);
319 break;
321 default:
322 break;
325 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
326 return (AE_OK);
330 /*******************************************************************************
332 * FUNCTION: LsEmitOffsetTableEntry
334 * PARAMETERS: FileId - ID of current listing file
335 * Node - Namespace node associated with the name
336 * Offset - Offset of the value within the AML table
337 * OpName - Name of the AML opcode
338 * Value - Current value of the AML field
339 * AmlOpcode - Opcode associated with the field
340 * ObjectType - ACPI object type
342 * RETURN: None
344 * DESCRIPTION: Emit a line of the offset table (-so option)
346 ******************************************************************************/
348 static void
349 LsEmitOffsetTableEntry (
350 UINT32 FileId,
351 ACPI_NAMESPACE_NODE *Node,
352 UINT32 NamepathOffset,
353 UINT32 Offset,
354 char *OpName,
355 UINT64 Value,
356 UINT8 AmlOpcode,
357 UINT16 ParentOpcode)
359 ACPI_BUFFER TargetPath;
360 ACPI_STATUS Status;
363 /* Get the full pathname to the namespace node */
365 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
366 Status = AcpiNsHandleToPathname (Node, &TargetPath);
367 if (ACPI_FAILURE (Status))
369 return;
372 /* [1] - Skip the opening backslash for the path */
374 strcpy (MsgBuffer, "\"");
375 strcat (MsgBuffer, &((char *) TargetPath.Pointer)[1]);
376 strcat (MsgBuffer, "\",");
377 ACPI_FREE (TargetPath.Pointer);
380 * Max offset is 4G, constrained by 32-bit ACPI table length.
381 * Max Length for Integers is 8 bytes.
383 FlPrintFile (FileId,
384 " {%-29s 0x%4.4X, 0x%8.8X, 0x%2.2X, 0x%8.8X, 0x%8.8X%8.8X}, /* %s */\n",
385 MsgBuffer, ParentOpcode, NamepathOffset, AmlOpcode,
386 Offset, ACPI_FORMAT_UINT64 (Value), OpName);
390 /*******************************************************************************
392 * FUNCTION: LsDoOffsetTableHeader, LsDoOffsetTableFooter
394 * PARAMETERS: FileId - ID of current listing file
396 * RETURN: None
398 * DESCRIPTION: Header and footer for the offset table file.
400 ******************************************************************************/
402 void
403 LsDoOffsetTableHeader (
404 UINT32 FileId)
407 FlPrintFile (FileId,
408 "#ifndef __AML_OFFSET_TABLE_H\n"
409 "#define __AML_OFFSET_TABLE_H\n\n");
411 FlPrintFile (FileId, "typedef struct {\n"
412 " char *Pathname; /* Full pathname (from root) to the object */\n"
413 " unsigned short ParentOpcode; /* AML opcode for the parent object */\n"
414 " unsigned long NamesegOffset; /* Offset of last nameseg in the parent namepath */\n"
415 " unsigned char Opcode; /* AML opcode for the data */\n"
416 " unsigned long Offset; /* Offset for the data */\n"
417 " unsigned long long Value; /* Original value of the data (as applicable) */\n"
418 "} AML_OFFSET_TABLE_ENTRY;\n\n");
420 FlPrintFile (FileId,
421 "#endif /* __AML_OFFSET_TABLE_H */\n\n");
423 FlPrintFile (FileId,
424 "/*\n"
425 " * Information specific to the supported object types:\n"
426 " *\n"
427 " * Integers:\n"
428 " * Opcode is the integer prefix, indicates length of the data\n"
429 " * (One of: BYTE, WORD, DWORD, QWORD, ZERO, ONE, ONES)\n"
430 " * Offset points to the actual integer data\n"
431 " * Value is the existing value in the AML\n"
432 " *\n"
433 " * Packages:\n"
434 " * Opcode is the package or var_package opcode\n"
435 " * Offset points to the package opcode\n"
436 " * Value is the package element count\n"
437 " *\n"
438 " * Operation Regions:\n"
439 " * Opcode is the address integer prefix, indicates length of the data\n"
440 " * Offset points to the region address\n"
441 " * Value is the existing address value in the AML\n"
442 " *\n"
443 " * Control Methods:\n"
444 " * Offset points to the method flags byte\n"
445 " * Value is the existing flags value in the AML\n"
446 " *\n"
447 " * Processors:\n"
448 " * Offset points to the first byte of the PBlock Address\n"
449 " *\n"
450 " * Resource Descriptors:\n"
451 " * Opcode is the descriptor type\n"
452 " * Offset points to the start of the descriptor\n"
453 " *\n"
454 " * Scopes/Devices/ThermalZones:\n"
455 " * Nameseg offset only\n"
456 " */\n");
458 FlPrintFile (FileId,
459 "AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n",
460 Gbl_TableSignature, Gbl_TableId);
464 void
465 LsDoOffsetTableFooter (
466 UINT32 FileId)
469 FlPrintFile (FileId,
470 " {NULL,0,0,0,0,0} /* Table terminator */\n};\n\n");
471 Gbl_CurrentAmlOffset = 0;