1 /******************************************************************************
3 * Module Name: asloffset - Generate a C "offset table" for BIOS use.
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("asloffset")
54 /* Local prototypes */
57 LsEmitOffsetTableEntry (
59 ACPI_NAMESPACE_NODE
*Node
,
60 UINT32 NamepathOffset
,
68 /*******************************************************************************
70 * FUNCTION: LsAmlOffsetWalk
72 * PARAMETERS: ASL_WALK_CALLBACK
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
85 * The offset table allows the BIOS to dynamically update the values of these
86 * objects at boot time.
88 ******************************************************************************/
92 ACPI_PARSE_OBJECT
*Op
,
96 UINT32 FileId
= (UINT32
) ACPI_TO_INTEGER (Context
);
97 ACPI_NAMESPACE_NODE
*Node
;
99 UINT32 NamepathOffset
;
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) */
116 Gbl_CurrentAmlOffset
+= Op
->Asl
.FinalAmlLength
;
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
;
132 switch (Op
->Asl
.AmlOpcode
)
136 /* Named object -- Name (NameString, DataRefObject) */
140 FlPrintFile (FileId
, "%s NO CHILD!\n", MsgBuffer
);
144 Length
= Op
->Asl
.FinalAmlLength
;
145 NamepathOffset
= Gbl_CurrentAmlOffset
+ Length
;
147 /* Get to the NameSeg/NamePath Op (and length of the name) */
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 */
162 switch (Op
->Asl
.AmlOpcode
)
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
);
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
);
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
);
203 Gbl_CurrentAmlOffset
+= Length
;
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.
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
;
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
);
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
);
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
);
325 Gbl_CurrentAmlOffset
+= Op
->Asl
.FinalAmlLength
;
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
344 * DESCRIPTION: Emit a line of the offset table (-so option)
346 ******************************************************************************/
349 LsEmitOffsetTableEntry (
351 ACPI_NAMESPACE_NODE
*Node
,
352 UINT32 NamepathOffset
,
359 ACPI_BUFFER TargetPath
;
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
))
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.
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
398 * DESCRIPTION: Header and footer for the offset table file.
400 ******************************************************************************/
403 LsDoOffsetTableHeader (
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");
421 "#endif /* __AML_OFFSET_TABLE_H */\n\n");
425 " * Information specific to the supported object types:\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"
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"
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"
443 " * Control Methods:\n"
444 " * Offset points to the method flags byte\n"
445 " * Value is the existing flags value in the AML\n"
448 " * Offset points to the first byte of the PBlock Address\n"
450 " * Resource Descriptors:\n"
451 " * Opcode is the descriptor type\n"
452 " * Offset points to the start of the descriptor\n"
454 " * Scopes/Devices/ThermalZones:\n"
455 " * Nameseg offset only\n"
459 "AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n",
460 Gbl_TableSignature
, Gbl_TableId
);
465 LsDoOffsetTableFooter (
470 " {NULL,0,0,0,0,0} /* Table terminator */\n};\n\n");
471 Gbl_CurrentAmlOffset
= 0;