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 - 2017, 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 & NODE_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 & NODE_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;
253 NamepathOffset = Gbl_CurrentAmlOffset + Length;
255 /* Get to the NameSeg/NamePath Op (and length of the name) */
259 /* Get offset of last nameseg and the actual data */
261 NamepathOffset = Gbl_CurrentAmlOffset + Length +
262 (Op->Asl.FinalAmlLength - ACPI_NAME_SIZE);
264 DataOffset = Gbl_CurrentAmlOffset + Length +
265 Op->Asl.FinalAmlLength;
267 /* Get actual value associated with the name */
270 switch (Op->Asl.AmlOpcode)
277 /* The +1 is to handle the integer size prefix (opcode) */
279 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
280 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
281 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
288 /* For these, offset will point to the opcode */
290 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
291 Op->Asl.ParseOpName, Op->Asl.Value.Integer,
292 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
296 case AML_VARIABLE_PACKAGE_OP:
298 /* Get the package element count */
300 NextOp = Op->Asl.Child;
302 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
303 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
304 (UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);
311 Gbl_CurrentAmlOffset += Length;
316 /* OperationRegion (NameString, RegionSpace, RegionOffset, RegionLength) */
318 Length = Op->Asl.FinalAmlLength;
320 /* Get the name/namepath node */
322 NextOp = Op->Asl.Child;
324 /* Get offset of last nameseg and the actual data */
326 NamepathOffset = Gbl_CurrentAmlOffset + Length +
327 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
329 DataOffset = Gbl_CurrentAmlOffset + Length +
330 (NextOp->Asl.FinalAmlLength + 1);
332 /* Get the SpaceId node, then the Offset (address) node */
334 NextOp = NextOp->Asl.Next;
335 NextOp = NextOp->Asl.Next;
337 switch (NextOp->Asl.AmlOpcode)
340 * We are only interested in integer constants that can be changed
341 * at boot time. Note, the One/Ones/Zero opcodes are considered
342 * non-changeable, so we ignore them here.
349 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),
350 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
351 (UINT8) NextOp->Asl.AmlOpcode, AML_REGION_OP);
353 Gbl_CurrentAmlOffset += Length;
363 /* Method (Namepath, ...) */
365 Length = Op->Asl.FinalAmlLength;
367 /* Get the NameSeg/NamePath Op */
369 NextOp = Op->Asl.Child;
371 /* Get offset of last nameseg and the actual data (flags byte) */
373 NamepathOffset = Gbl_CurrentAmlOffset + Length +
374 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
376 DataOffset = Gbl_CurrentAmlOffset + Length +
377 NextOp->Asl.FinalAmlLength;
379 /* Get the flags byte Op */
381 NextOp = NextOp->Asl.Next;
383 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
384 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
385 (UINT8) Op->Asl.AmlOpcode, AML_METHOD_OP);
388 case AML_PROCESSOR_OP:
390 /* Processor (Namepath, ProcessorId, Address, Length) */
392 Length = Op->Asl.FinalAmlLength;
393 NextOp = Op->Asl.Child; /* Get Namepath */
395 /* Get offset of last nameseg and the actual data (PBlock address) */
397 NamepathOffset = Gbl_CurrentAmlOffset + Length +
398 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
400 DataOffset = Gbl_CurrentAmlOffset + Length +
401 (NextOp->Asl.FinalAmlLength + 1);
403 NextOp = NextOp->Asl.Next; /* Get ProcessorID (BYTE) */
404 NextOp = NextOp->Asl.Next; /* Get Address (DWORD) */
406 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,
407 Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,
408 (UINT8) AML_DWORD_OP, AML_PROCESSOR_OP);
413 case AML_THERMAL_ZONE_OP:
415 /* Device/Scope/ThermalZone (Namepath) */
417 Length = Op->Asl.FinalAmlLength;
418 NextOp = Op->Asl.Child; /* Get Namepath */
420 /* Get offset of last nameseg */
422 NamepathOffset = Gbl_CurrentAmlOffset + Length +
423 (NextOp->Asl.FinalAmlLength - ACPI_NAME_SIZE);
425 LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, 0,
426 Op->Asl.ParseOpName, 0, (UINT8) 0, Op->Asl.AmlOpcode);
433 Gbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;
438 /*******************************************************************************
440 * FUNCTION: LsEmitOffsetTableEntry
442 * PARAMETERS: FileId - ID of current listing file
443 * Node - Namespace node associated with the name
444 * Offset - Offset of the value within the AML table
445 * OpName - Name of the AML opcode
446 * Value - Current value of the AML field
447 * AmlOpcode - Opcode associated with the field
448 * ObjectType - ACPI object type
452 * DESCRIPTION: Emit a line of the offset table (-so option)
454 ******************************************************************************/
457 LsEmitOffsetTableEntry (
459 ACPI_NAMESPACE_NODE *Node,
460 UINT32 NamepathOffset,
467 ACPI_BUFFER TargetPath;
471 /* Get the full pathname to the namespace node */
473 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
474 Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);
475 if (ACPI_FAILURE (Status))
480 /* [1] - Skip the opening backslash for the path */
482 strcpy (MsgBuffer, "\"");
483 strcat (MsgBuffer, &((char *) TargetPath.Pointer)[1]);
484 strcat (MsgBuffer, "\",");
485 ACPI_FREE (TargetPath.Pointer);
488 * Max offset is 4G, constrained by 32-bit ACPI table length.
489 * Max Length for Integers is 8 bytes.
492 " {%-29s 0x%4.4X, 0x%8.8X, 0x%2.2X, 0x%8.8X, 0x%8.8X%8.8X}, /* %s */\n",
493 MsgBuffer, ParentOpcode, NamepathOffset, AmlOpcode,
494 Offset, ACPI_FORMAT_UINT64 (Value), OpName);
498 /*******************************************************************************
500 * FUNCTION: LsDoOffsetTableHeader, LsDoOffsetTableFooter
502 * PARAMETERS: FileId - ID of current listing file
506 * DESCRIPTION: Header and footer for the offset table file.
508 ******************************************************************************/
511 LsDoOffsetTableHeader (
516 "#ifndef __AML_OFFSET_TABLE_H\n"
517 "#define __AML_OFFSET_TABLE_H\n\n");
519 FlPrintFile (FileId, "typedef struct {\n"
520 " char *Pathname; /* Full pathname (from root) to the object */\n"
521 " unsigned short ParentOpcode; /* AML opcode for the parent object */\n"
522 " unsigned long NamesegOffset; /* Offset of last nameseg in the parent namepath */\n"
523 " unsigned char Opcode; /* AML opcode for the data */\n"
524 " unsigned long Offset; /* Offset for the data */\n"
525 " unsigned long long Value; /* Original value of the data (as applicable) */\n"
526 "} AML_OFFSET_TABLE_ENTRY;\n\n");
529 "#endif /* __AML_OFFSET_TABLE_H */\n\n");
533 " * Information specific to the supported object types:\n"
536 " * Opcode is the integer prefix, indicates length of the data\n"
537 " * (One of: BYTE, WORD, DWORD, QWORD, ZERO, ONE, ONES)\n"
538 " * Offset points to the actual integer data\n"
539 " * Value is the existing value in the AML\n"
542 " * Opcode is the package or var_package opcode\n"
543 " * Offset points to the package opcode\n"
544 " * Value is the package element count\n"
546 " * Operation Regions:\n"
547 " * Opcode is the address integer prefix, indicates length of the data\n"
548 " * Offset points to the region address\n"
549 " * Value is the existing address value in the AML\n"
551 " * Control Methods:\n"
552 " * Offset points to the method flags byte\n"
553 " * Value is the existing flags value in the AML\n"
556 " * Offset points to the first byte of the PBlock Address\n"
558 " * Resource Descriptors:\n"
559 " * Opcode is the descriptor type\n"
560 " * Offset points to the start of the descriptor\n"
562 " * Scopes/Devices/ThermalZones:\n"
563 " * Nameseg offset only\n"
567 "AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n",
568 Gbl_TableSignature, Gbl_TableId);
573 LsDoOffsetTableFooter (
578 " {NULL,0,0,0,0,0} /* Table terminator */\n};\n\n");
579 Gbl_CurrentAmlOffset = 0;