Path: blob/main/sys/contrib/dev/acpica/compiler/asloffset.c
48371 views
/******************************************************************************1*2* Module Name: asloffset - Generate a C "offset table" for BIOS use.3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/compiler/aslcompiler.h>152#include "aslcompiler.y.h"153#include <contrib/dev/acpica/include/amlcode.h>154#include <contrib/dev/acpica/include/acnamesp.h>155156157#define _COMPONENT ACPI_COMPILER158ACPI_MODULE_NAME ("asloffset")159160161/* Local prototypes */162163static void164LsEmitOffsetTableEntry (165UINT32 FileId,166ACPI_NAMESPACE_NODE *Node,167UINT32 NamepathOffset,168UINT32 Offset,169char *OpName,170UINT64 Value,171UINT8 AmlOpcode,172UINT16 ParentOpcode);173174175/*******************************************************************************176*177* FUNCTION: LsAmlOffsetWalk178*179* PARAMETERS: ASL_WALK_CALLBACK180*181* RETURN: Status182*183* DESCRIPTION: Process one node during a offset table file generation.184*185* Three types of objects are currently emitted to the offset table:186* 1) Tagged (named) resource descriptors187* 2) Named integer objects with constant integer values188* 3) Named package objects189* 4) Operation Regions that have constant Offset (address) parameters190* 5) Control methods191*192* The offset table allows the BIOS to dynamically update the values of these193* objects at boot time.194*195******************************************************************************/196197ACPI_STATUS198LsAmlOffsetWalk (199ACPI_PARSE_OBJECT *Op,200UINT32 Level,201void *Context)202{203UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);204ACPI_NAMESPACE_NODE *Node;205UINT32 Length;206UINT32 NamepathOffset;207UINT32 DataOffset;208ACPI_PARSE_OBJECT *NextOp;209210211/* Ignore actual data blocks for resource descriptors */212213if (Op->Asl.CompileFlags & OP_IS_RESOURCE_DATA)214{215return (AE_OK); /* Do NOT update the global AML offset */216}217218/* We are only interested in named objects (have a namespace node) */219220Node = Op->Asl.Node;221if (!Node)222{223AslGbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;224return (AE_OK);225}226227/* Named resource descriptor (has a descriptor tag) */228229if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE) &&230(Op->Asl.CompileFlags & OP_IS_RESOURCE_DESC))231{232LsEmitOffsetTableEntry (FileId, Node, 0, AslGbl_CurrentAmlOffset,233Op->Asl.ParseOpName, 0, Op->Asl.Extra, AML_BUFFER_OP);234235AslGbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;236return (AE_OK);237}238239switch (Op->Asl.AmlOpcode)240{241case AML_NAME_OP:242243/* Named object -- Name (NameString, DataRefObject) */244245if (!Op->Asl.Child)246{247FlPrintFile (FileId, "%s NO CHILD!\n", AslGbl_MsgBuffer);248return (AE_OK);249}250251Length = Op->Asl.FinalAmlLength;252253/* Get to the NameSeg/NamePath Op (and length of the name) */254255Op = Op->Asl.Child;256257/* Get offset of last nameseg and the actual data */258259NamepathOffset = AslGbl_CurrentAmlOffset + Length +260(Op->Asl.FinalAmlLength - ACPI_NAMESEG_SIZE);261262DataOffset = AslGbl_CurrentAmlOffset + Length +263Op->Asl.FinalAmlLength;264265/* Get actual value associated with the name */266267Op = Op->Asl.Next;268switch (Op->Asl.AmlOpcode)269{270case AML_BYTE_OP:271case AML_WORD_OP:272case AML_DWORD_OP:273case AML_QWORD_OP:274275/* The +1 is to handle the integer size prefix (opcode) */276277LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),278Op->Asl.ParseOpName, Op->Asl.Value.Integer,279(UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);280break;281282case AML_ONE_OP:283case AML_ONES_OP:284case AML_ZERO_OP:285286/* For these, offset will point to the opcode */287288LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,289Op->Asl.ParseOpName, Op->Asl.Value.Integer,290(UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);291break;292293case AML_PACKAGE_OP:294case AML_VARIABLE_PACKAGE_OP:295296/* Get the package element count */297298NextOp = Op->Asl.Child;299300LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,301Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,302(UINT8) Op->Asl.AmlOpcode, AML_NAME_OP);303break;304305default:306break;307}308309AslGbl_CurrentAmlOffset += Length;310return (AE_OK);311312case AML_REGION_OP:313314/* OperationRegion (NameString, RegionSpace, RegionOffset, RegionLength) */315316Length = Op->Asl.FinalAmlLength;317318/* Get the name/namepath node */319320NextOp = Op->Asl.Child;321322/* Get offset of last nameseg and the actual data */323324NamepathOffset = AslGbl_CurrentAmlOffset + Length +325(NextOp->Asl.FinalAmlLength - ACPI_NAMESEG_SIZE);326327DataOffset = AslGbl_CurrentAmlOffset + Length +328(NextOp->Asl.FinalAmlLength + 1);329330/* Get the SpaceId node, then the Offset (address) node */331332NextOp = NextOp->Asl.Next;333NextOp = NextOp->Asl.Next;334335switch (NextOp->Asl.AmlOpcode)336{337/*338* We are only interested in integer constants that can be changed339* at boot time. Note, the One/Ones/Zero opcodes are considered340* non-changeable, so we ignore them here.341*/342case AML_BYTE_OP:343case AML_WORD_OP:344case AML_DWORD_OP:345case AML_QWORD_OP:346347LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, (DataOffset + 1),348Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,349(UINT8) NextOp->Asl.AmlOpcode, AML_REGION_OP);350351AslGbl_CurrentAmlOffset += Length;352return (AE_OK);353354default:355break;356}357break;358359case AML_METHOD_OP:360361/* Method (Namepath, ...) */362363Length = Op->Asl.FinalAmlLength;364365/* Get the NameSeg/NamePath Op */366367NextOp = Op->Asl.Child;368369/* Get offset of last nameseg and the actual data (flags byte) */370371NamepathOffset = AslGbl_CurrentAmlOffset + Length +372(NextOp->Asl.FinalAmlLength - ACPI_NAMESEG_SIZE);373374DataOffset = AslGbl_CurrentAmlOffset + Length +375NextOp->Asl.FinalAmlLength;376377/* Get the flags byte Op */378379NextOp = NextOp->Asl.Next;380381LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,382Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,383(UINT8) Op->Asl.AmlOpcode, AML_METHOD_OP);384break;385386case AML_PROCESSOR_OP:387388/* Processor (Namepath, ProcessorId, Address, Length) */389390Length = Op->Asl.FinalAmlLength;391NextOp = Op->Asl.Child; /* Get Namepath */392393/* Get offset of last nameseg and the actual data (PBlock address) */394395NamepathOffset = AslGbl_CurrentAmlOffset + Length +396(NextOp->Asl.FinalAmlLength - ACPI_NAMESEG_SIZE);397398DataOffset = AslGbl_CurrentAmlOffset + Length +399(NextOp->Asl.FinalAmlLength + 1);400401NextOp = NextOp->Asl.Next; /* Get ProcessorID (BYTE) */402NextOp = NextOp->Asl.Next; /* Get Address (DWORD) */403404LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, DataOffset,405Op->Asl.ParseOpName, NextOp->Asl.Value.Integer,406(UINT8) AML_DWORD_OP, AML_PROCESSOR_OP);407break;408409case AML_DEVICE_OP:410case AML_SCOPE_OP:411case AML_THERMAL_ZONE_OP:412413/* Device/Scope/ThermalZone (Namepath) */414415Length = Op->Asl.FinalAmlLength;416NextOp = Op->Asl.Child; /* Get Namepath */417418/* Get offset of last nameseg */419420NamepathOffset = AslGbl_CurrentAmlOffset + Length +421(NextOp->Asl.FinalAmlLength - ACPI_NAMESEG_SIZE);422423LsEmitOffsetTableEntry (FileId, Node, NamepathOffset, 0,424Op->Asl.ParseOpName, 0, (UINT8) 0, Op->Asl.AmlOpcode);425break;426427default:428break;429}430431AslGbl_CurrentAmlOffset += Op->Asl.FinalAmlLength;432return (AE_OK);433}434435436/*******************************************************************************437*438* FUNCTION: LsEmitOffsetTableEntry439*440* PARAMETERS: FileId - ID of current listing file441* Node - Namespace node associated with the name442* Offset - Offset of the value within the AML table443* OpName - Name of the AML opcode444* Value - Current value of the AML field445* AmlOpcode - Opcode associated with the field446* ObjectType - ACPI object type447*448* RETURN: None449*450* DESCRIPTION: Emit a line of the offset table (-so option)451*452******************************************************************************/453454static void455LsEmitOffsetTableEntry (456UINT32 FileId,457ACPI_NAMESPACE_NODE *Node,458UINT32 NamepathOffset,459UINT32 Offset,460char *OpName,461UINT64 Value,462UINT8 AmlOpcode,463UINT16 ParentOpcode)464{465ACPI_BUFFER TargetPath;466ACPI_STATUS Status;467468469/* Get the full pathname to the namespace node */470471TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;472Status = AcpiNsHandleToPathname (Node, &TargetPath, FALSE);473if (ACPI_FAILURE (Status))474{475return;476}477478/* [1] - Skip the opening backslash for the path */479480strcpy (AslGbl_MsgBuffer, "\"");481strcat (AslGbl_MsgBuffer, &((char *) TargetPath.Pointer)[1]);482strcat (AslGbl_MsgBuffer, "\",");483ACPI_FREE (TargetPath.Pointer);484485/*486* Max offset is 4G, constrained by 32-bit ACPI table length.487* Max Length for Integers is 8 bytes.488*/489FlPrintFile (FileId,490" {%-29s 0x%4.4X, 0x%8.8X, 0x%2.2X, 0x%8.8X, 0x%8.8X%8.8X}, /* %s */\n",491AslGbl_MsgBuffer, ParentOpcode, NamepathOffset, AmlOpcode,492Offset, ACPI_FORMAT_UINT64 (Value), OpName);493}494495496/*******************************************************************************497*498* FUNCTION: LsDoOffsetTableHeader, LsDoOffsetTableFooter499*500* PARAMETERS: FileId - ID of current listing file501*502* RETURN: None503*504* DESCRIPTION: Header and footer for the offset table file.505*506******************************************************************************/507508void509LsDoOffsetTableHeader (510UINT32 FileId)511{512513FlPrintFile (FileId,514"#ifndef __AML_OFFSET_TABLE_H\n"515"#define __AML_OFFSET_TABLE_H\n\n");516517FlPrintFile (FileId, "typedef struct {\n"518" char *Pathname; /* Full pathname (from root) to the object */\n"519" unsigned short ParentOpcode; /* AML opcode for the parent object */\n"520" unsigned long NamesegOffset; /* Offset of last nameseg in the parent namepath */\n"521" unsigned char Opcode; /* AML opcode for the data */\n"522" unsigned long Offset; /* Offset for the data */\n"523" unsigned long long Value; /* Original value of the data (as applicable) */\n"524"} AML_OFFSET_TABLE_ENTRY;\n\n");525526FlPrintFile (FileId,527"#endif /* __AML_OFFSET_TABLE_H */\n\n");528529FlPrintFile (FileId,530"/*\n"531" * Information specific to the supported object types:\n"532" *\n"533" * Integers:\n"534" * Opcode is the integer prefix, indicates length of the data\n"535" * (One of: BYTE, WORD, DWORD, QWORD, ZERO, ONE, ONES)\n"536" * Offset points to the actual integer data\n"537" * Value is the existing value in the AML\n"538" *\n"539" * Packages:\n"540" * Opcode is the package or var_package opcode\n"541" * Offset points to the package opcode\n"542" * Value is the package element count\n"543" *\n"544" * Operation Regions:\n"545" * Opcode is the address integer prefix, indicates length of the data\n"546" * Offset points to the region address\n"547" * Value is the existing address value in the AML\n"548" *\n"549" * Control Methods:\n"550" * Offset points to the method flags byte\n"551" * Value is the existing flags value in the AML\n"552" *\n"553" * Processors:\n"554" * Offset points to the first byte of the PBlock Address\n"555" *\n"556" * Resource Descriptors:\n"557" * Opcode is the descriptor type\n"558" * Offset points to the start of the descriptor\n"559" *\n"560" * Scopes/Devices/ThermalZones:\n"561" * Nameseg offset only\n"562" */\n");563564FlPrintFile (FileId,565"AML_OFFSET_TABLE_ENTRY %s_%s_OffsetTable[] =\n{\n",566AslGbl_TableSignature, AslGbl_TableId);567}568569570void571LsDoOffsetTableFooter (572UINT32 FileId)573{574575FlPrintFile (FileId,576" {NULL,0,0,0,0,0} /* Table terminator */\n};\n\n");577AslGbl_CurrentAmlOffset = 0;578}579580581