1 /******************************************************************************
3 * Module Name: asloffset - Generate a C "offset table" for BIOS use.
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/compiler/aslcompiler.h>
153 #include "aslcompiler.y.h"
154 #include <contrib/dev/acpica/include/amlcode.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
158 #define _COMPONENT ACPI_COMPILER
159 ACPI_MODULE_NAME ("asloffset")
162 /* Local prototypes */
165 LsEmitOffsetTableEntry (
167 ACPI_NAMESPACE_NODE *Node,
168 UINT32 NamepathOffset,
173 UINT16 ParentOpcode);
176 /*******************************************************************************
178 * FUNCTION: LsAmlOffsetWalk
180 * PARAMETERS: ASL_WALK_CALLBACK
184 * DESCRIPTION: Process one node during a offset table file generation.
186 * Three types of objects are currently emitted to the offset table:
187 * 1) Tagged (named) resource descriptors
188 * 2) Named integer objects with constant integer values
189 * 3) Named package objects
190 * 4) Operation Regions that have constant Offset (address) parameters
193 * The offset table allows the BIOS to dynamically update the values of these
194 * objects at boot time.
196 ******************************************************************************/
200 ACPI_PARSE_OBJECT *Op,
204 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
205 ACPI_NAMESPACE_NODE *Node;
207 UINT32 NamepathOffset;
209 ACPI_PARSE_OBJECT *NextOp;
212 /* Ignore actual data blocks for resource descriptors */
214 if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DATA)
216 return (AE_OK); /* Do NOT update the global AML offset */
219 /* We are only interested in named objects (have a namespace node) */
224 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
228 /* Named resource descriptor (has a descriptor tag) */
230 if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE) &&
231 (Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC))
233 LsEmitOffsetTableEntry (FileId, Node, 0, Gbl_CurrentAmlOffset,
234 Op->Asl.ParseOpName, 0, Op->Asl.Extra, AML_BUFFER_OP);
236 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
240 switch (Op->Asl.AmlOpcode)
244 /* Named object -- Name (NameString, DataRefObject) */
248 FlPrintFile (FileId, "%s NO CHILD!\n", MsgBuffer);
252 Length = Op->Asl.FinalAmlLength;
254 /* Get to the NameSeg/NamePath Op (and length of the name) */
258 /* Get offset of last nameseg and the actual data */
260 NamepathOffset = Gbl_CurrentAmlOffset + Length +
261 (Op->Asl.FinalAmlLength - ACPI_NAME_SIZE);
263 DataOffset = Gbl_CurrentAmlOffset + Length +
264 Op->Asl.FinalAmlLength;
266 /* Get actual value associated with the name */
269 switch (Op->Asl.AmlOpcode)
276 /* The +1 is to handle the integer size prefix (opcode) */
278 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
279 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
280 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
287 /* For these, offset will point to the opcode */
289 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
290 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
291 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
295 case AML_VARIABLE_PACKAGE_OP:
297 /* Get the package element count */
299 NextOp = Op->Asl.Child;
301 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
302 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
303 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
310 Gbl_CurrentAmlOffset += Length;
315 /* OperationRegion (NameString, RegionSpace, RegionOffset, RegionLength) */
317 Length = Op->Asl.FinalAmlLength;
319 /* Get the name/namepath node */
321 NextOp = Op->Asl.Child;
323 /* Get offset of last nameseg and the actual data */
325 NamepathOffset = Gbl_CurrentAmlOffset + Length +
326 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
328 DataOffset = Gbl_CurrentAmlOffset + Length +
329 (NextOp->Asl.FinalAmlLength + 1);
331 /* Get the SpaceId node, then the Offset (address) node */
333 NextOp = NextOp->Asl.Next;
334 NextOp = NextOp->Asl.Next;
336 switch (NextOp->Asl.AmlOpcode)
339 * We are only interested in integer constants that can be changed
340 * at boot time. Note, the One/Ones/Zero opcodes are considered
341 * non-changeable, so we ignore them here.
348 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
349 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
350 (UINT8) NextOp->Asl.AmlOpcode, AML_REGION_OP);
352 Gbl_CurrentAmlOffset += Length;
362 /* Method (Namepath, ...) */
364 Length = Op->Asl.FinalAmlLength;
366 /* Get the NameSeg/NamePath Op */
368 NextOp = Op->Asl.Child;
370 /* Get offset of last nameseg and the actual data (flags byte) */
372 NamepathOffset = Gbl_CurrentAmlOffset + Length +
373 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
375 DataOffset = Gbl_CurrentAmlOffset + Length +
376 NextOp->Asl.FinalAmlLength;
378 /* Get the flags byte Op */
380 NextOp = NextOp->Asl.Next;
382 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
383 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
384 (UINT8) Op->Asl.AmlOpcode, AML_METHOD_OP);
387 case AML_PROCESSOR_OP:
389 /* Processor (Namepath, ProcessorId, Address, Length) */
391 Length = Op->Asl.FinalAmlLength;
392 NextOp = Op->Asl.Child; /* Get Namepath */
394 /* Get offset of last nameseg and the actual data (PBlock address) */
396 NamepathOffset = Gbl_CurrentAmlOffset + Length +
397 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
399 DataOffset = Gbl_CurrentAmlOffset + Length +
400 (NextOp->Asl.FinalAmlLength + 1);
402 NextOp = NextOp->Asl.Next; /* Get ProcessorID (BYTE) */
403 NextOp = NextOp->Asl.Next; /* Get Address (DWORD) */
405 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
406 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
407 (UINT8) AML_DWORD_OP, AML_PROCESSOR_OP);
412 case AML_THERMAL_ZONE_OP:
414 /* Device/Scope/ThermalZone (Namepath) */
416 Length = Op->Asl.FinalAmlLength;
417 NextOp = Op->Asl.Child; /* Get Namepath */
419 /* Get offset of last nameseg */
421 NamepathOffset = Gbl_CurrentAmlOffset + Length +
422 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
424 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, 0,
425 Op->Asl.ParseOpName, 0, (UINT8) 0, Op->Asl.AmlOpcode);
432 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
437 /*******************************************************************************
439 * FUNCTION: LsEmitOffsetTableEntry
441 * PARAMETERS: FileId - ID of current listing file
442 * Node - Namespace node associated with the name
443 * Offset - Offset of the value within the AML table
444 * OpName - Name of the AML opcode
445 * Value - Current value of the AML field
446 * AmlOpcode - Opcode associated with the field
447 * ObjectType - ACPI object type
451 * DESCRIPTION: Emit a line of the offset table (-so option)
453 ******************************************************************************/
456 LsEmitOffsetTableEntry (
458 ACPI_NAMESPACE_NODE *Node,
459 UINT32 NamepathOffset,
466 ACPI_BUFFER TargetPath;
470 /* Get the full pathname to the namespace node */
472 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
473 Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
474 if (ACPI_FAILURE (Status))
479 /* [1] - Skip the opening backslash for the path */
481 strcpy (MsgBuffer, "\"");
482 strcat (MsgBuffer, &((char *) TargetPath.Pointer)[1]);
483 strcat (MsgBuffer, "\",");
484 ACPI_FREE (TargetPath.Pointer);
487 * Max offset is 4G, constrained by 32-bit ACPI table length.
488 * Max Length for Integers is 8 bytes.
491 " {%-29s 0x%4.4X, 0x%8.8X, 0x%2.2X, 0x%8.8X, 0x%8.8X%8.8X}, /* %s */\n",
492 MsgBuffer, ParentOpcode, NamepathOffset, AmlOpcode,
493 Offset, ACPI_FORMAT_UINT64 (Value), OpName);
497 /*******************************************************************************
499 * FUNCTION: LsDoOffsetTableHeader, LsDoOffsetTableFooter
501 * PARAMETERS: FileId - ID of current listing file
505 * DESCRIPTION: Header and footer for the offset table file.
507 ******************************************************************************/
510 LsDoOffsetTableHeader (
515 "#ifndef __AML_OFFSET_TABLE_H\n"
516 "#define __AML_OFFSET_TABLE_H\n\n");
518 FlPrintFile (FileId, "typedef struct {\n"
519 " char *Pathname; /* Full pathname (from root) to the object */\n"
520 " unsigned short ParentOpcode; /* AML opcode for the parent object */\n"
521 " unsigned long NamesegOffset; /* Offset of last nameseg in the parent namepath */\n"
522 " unsigned char Opcode; /* AML opcode for the data */\n"
523 " unsigned long Offset; /* Offset for the data */\n"
524 " unsigned long long Value; /* Original value of the data (as applicable) */\n"
525 "} AML_OFFSET_TABLE_ENTRY;\n\n");
528 "#endif /* __AML_OFFSET_TABLE_H */\n\n");
532 " * Information specific to the supported object types:\n"
535 " * Opcode is the integer prefix, indicates length of the data\n"
536 " * (One of: BYTE, WORD, DWORD, QWORD, ZERO, ONE, ONES)\n"
537 " * Offset points to the actual integer data\n"
538 " * Value is the existing value in the AML\n"
541 " * Opcode is the package or var_package opcode\n"
542 " * Offset points to the package opcode\n"
543 " * Value is the package element count\n"
545 " * Operation Regions:\n"
546 " * Opcode is the address integer prefix, indicates length of the data\n"
547 " * Offset points to the region address\n"
548 " * Value is the existing address value in the AML\n"
550 " * Control Methods:\n"
551 " * Offset points to the method flags byte\n"
552 " * Value is the existing flags value in the AML\n"
555 " * Offset points to the first byte of the PBlock Address\n"
557 " * Resource Descriptors:\n"
558 " * Opcode is the descriptor type\n"
559 " * Offset points to the start of the descriptor\n"
561 " * Scopes/Devices/ThermalZones:\n"
562 " * Nameseg offset only\n"
566 "AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n",
567 Gbl_TableSignature, Gbl_TableId);
572 LsDoOffsetTableFooter (
577 " {NULL,0,0,0,0,0} /* Table terminator */\n};\n\n");
578 Gbl_CurrentAmlOffset = 0;