Path: blob/main/sys/contrib/dev/acpica/compiler/aslmapoutput.c
48371 views
/******************************************************************************1*2* Module Name: aslmapoutput - Output/emit the resource descriptor/device maps3*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/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acapps.h>154#include <contrib/dev/acpica/compiler/aslcompiler.h>155#include "aslcompiler.y.h"156#include <contrib/dev/acpica/include/acinterp.h>157#include <contrib/dev/acpica/include/acparser.h>158#include <contrib/dev/acpica/include/acnamesp.h>159#include <contrib/dev/acpica/include/amlcode.h>160161/* This module used for application-level code only */162163#define _COMPONENT ACPI_COMPILER164ACPI_MODULE_NAME ("aslmapoutput")165166/* Local prototypes */167168static void169MpEmitGpioInfo (170void);171172static void173MpEmitSerialInfo (174void);175176static void177MpEmitDeviceTree (178void);179180static ACPI_STATUS181MpEmitOneDevice (182ACPI_HANDLE ObjHandle,183UINT32 NestingLevel,184void *Context,185void **ReturnValue);186187static void188MpXrefDevices (189ACPI_GPIO_INFO *Info);190191static ACPI_STATUS192MpNamespaceXrefBegin (193ACPI_PARSE_OBJECT *Op,194UINT32 Level,195void *Context);196197198/* Strings used to decode flag bits */199200const char *DirectionDecode[] =201{202"Both I/O ",203"InputOnly ",204"OutputOnly ",205"Preserve "206};207208const char *PolarityDecode[] =209{210"ActiveHigh",211"ActiveLow ",212"ActiveBoth",213"Reserved "214};215216217/*******************************************************************************218*219* FUNCTION: MpEmitMappingInfo220*221* PARAMETERS: None222*223* RETURN: None224*225* DESCRIPTION: External interface.226* Map file has already been opened. Emit all of the collected227* hardware mapping information. Includes: GPIO information,228* Serial information, and a dump of the entire ACPI device tree.229*230******************************************************************************/231232void233MpEmitMappingInfo (234void)235{236237/* Mapfile option enabled? */238239if (!AslGbl_MapfileFlag)240{241return;242}243244if (!AslGbl_GpioList)245{246FlPrintFile (ASL_FILE_MAP_OUTPUT,247"\nNo GPIO devices found\n");248}249250if (!AslGbl_SerialList)251{252FlPrintFile (ASL_FILE_MAP_OUTPUT,253"\nNo Serial devices found (I2C/SPI/UART)\n");254}255256if (!AslGbl_GpioList && !AslGbl_SerialList)257{258return;259}260261/* Headers */262263FlPrintFile (ASL_FILE_MAP_OUTPUT, "\nResource Descriptor Connectivity Map\n");264FlPrintFile (ASL_FILE_MAP_OUTPUT, "------------------------------------\n");265266/* Emit GPIO and Serial descriptors, then entire ACPI device tree */267268MpEmitGpioInfo ();269MpEmitSerialInfo ();270MpEmitDeviceTree ();271272/* Clear the lists - no need to free memory here */273274AslGbl_SerialList = NULL;275AslGbl_GpioList = NULL;276}277278279/*******************************************************************************280*281* FUNCTION: MpEmitGpioInfo282*283* PARAMETERS: None284*285* RETURN: None286*287* DESCRIPTION: Emit the info about all GPIO devices found during the288* compile or disassembly.289*290******************************************************************************/291292static void293MpEmitGpioInfo (294void)295{296ACPI_GPIO_INFO *Info;297char *Type;298char *PrevDeviceName = NULL;299const char *Direction;300const char *Polarity;301char *ParentPathname;302const char *Description;303char *HidString;304const AH_DEVICE_ID *HidInfo;305306307/* Walk the GPIO descriptor list */308309Info = AslGbl_GpioList;310while (Info)311{312HidString = MpGetHidViaNamestring (Info->DeviceName);313314/* Print header info for the controller itself */315316if (!PrevDeviceName ||317strcmp (PrevDeviceName, Info->DeviceName))318{319FlPrintFile (ASL_FILE_MAP_OUTPUT,320"\n\nGPIO Controller: %-8s %-28s",321HidString, Info->DeviceName);322323HidInfo = AcpiAhMatchHardwareId (HidString);324if (HidInfo)325{326FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",327HidInfo->Description);328}329330FlPrintFile (ASL_FILE_MAP_OUTPUT,331"\n\nPin Type Direction Polarity"332" Dest _HID Destination\n");333}334335PrevDeviceName = Info->DeviceName;336337/* Setup various strings based upon the type (GpioInt or GpioIo) */338339switch (Info->Type)340{341case AML_RESOURCE_GPIO_TYPE_INT:342343Type = "GpioInt";344Direction = "-Interrupt-";345Polarity = PolarityDecode[Info->Polarity];346break;347348case AML_RESOURCE_GPIO_TYPE_IO:349350Type = "GpioIo ";351Direction = DirectionDecode[Info->Direction];352Polarity = " ";353break;354355default:356continue;357}358359/* Emit the GPIO info */360361FlPrintFile (ASL_FILE_MAP_OUTPUT, "%4.4X %s %s %s ",362Info->PinNumber, Type, Direction, Polarity);363364ParentPathname = NULL;365HidString = MpGetConnectionInfo (Info->Op, Info->PinIndex,366&Info->TargetNode, &ParentPathname);367if (HidString)368{369/*370* This is a Connection() field371* Attempt to find all references to the field.372*/373FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",374HidString, ParentPathname);375376MpXrefDevices (Info);377}378else379{380/*381* For Devices, attempt to get the _HID description string.382* Failing that (many _HIDs are not recognized), attempt to383* get the _DDN description string.384*/385HidString = MpGetParentDeviceHid (Info->Op, &Info->TargetNode,386&ParentPathname);387388FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",389HidString, ParentPathname);390391/* Get the _HID description or _DDN string */392393HidInfo = AcpiAhMatchHardwareId (HidString);394if (HidInfo)395{396FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",397HidInfo->Description);398}399else if ((Description = MpGetDdnValue (ParentPathname)))400{401FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)",402Description);403}404}405406FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");407ACPI_FREE (ParentPathname);408Info = Info->Next;409}410}411412413/*******************************************************************************414*415* FUNCTION: MpEmitSerialInfo416*417* PARAMETERS: None418*419* RETURN: None420*421* DESCRIPTION: Emit the info about all Serial devices found during the422* compile or disassembly.423*424******************************************************************************/425426static void427MpEmitSerialInfo (428void)429{430ACPI_SERIAL_INFO *Info;431char *Type;432char *ParentPathname;433char *PrevDeviceName = NULL;434char *HidString;435const AH_DEVICE_ID *HidInfo;436const char *Description;437AML_RESOURCE *Resource;438439440/* Walk the constructed serial descriptor list */441442Info = AslGbl_SerialList;443while (Info)444{445Resource = Info->Resource;446switch (Resource->CommonSerialBus.Type)447{448case AML_RESOURCE_I2C_SERIALBUSTYPE:449Type = "I2C ";450break;451452case AML_RESOURCE_SPI_SERIALBUSTYPE:453Type = "SPI ";454break;455456case AML_RESOURCE_UART_SERIALBUSTYPE:457Type = "UART";458break;459460default:461Type = "UNKN";462break;463}464465HidString = MpGetHidViaNamestring (Info->DeviceName);466467/* Print header info for the controller itself */468469if (!PrevDeviceName ||470strcmp (PrevDeviceName, Info->DeviceName))471{472FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\n%s Controller: ",473Type);474FlPrintFile (ASL_FILE_MAP_OUTPUT, "%-8s %-28s",475HidString, Info->DeviceName);476477HidInfo = AcpiAhMatchHardwareId (HidString);478if (HidInfo)479{480FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",481HidInfo->Description);482}483484FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\n");485FlPrintFile (ASL_FILE_MAP_OUTPUT,486"Type Address Speed Dest _HID Destination\n");487}488489PrevDeviceName = Info->DeviceName;490491FlPrintFile (ASL_FILE_MAP_OUTPUT, "%s %4.4X %8.8X ",492Type, Info->Address, Info->Speed);493494ParentPathname = NULL;495HidString = MpGetConnectionInfo (Info->Op, 0, &Info->TargetNode,496&ParentPathname);497if (HidString)498{499/*500* This is a Connection() field501* Attempt to find all references to the field.502*/503FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",504HidString, ParentPathname);505}506else507{508/* Normal resource template */509510HidString = MpGetParentDeviceHid (Info->Op, &Info->TargetNode,511&ParentPathname);512FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s %-28s",513HidString, ParentPathname);514515/* Get the _HID description or _DDN string */516517HidInfo = AcpiAhMatchHardwareId (HidString);518if (HidInfo)519{520FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",521HidInfo->Description);522}523else if ((Description = MpGetDdnValue (ParentPathname)))524{525FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)",526Description);527}528}529530FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");531ACPI_FREE (ParentPathname);532Info = Info->Next;533}534}535536537/*******************************************************************************538*539* FUNCTION: MpEmitDeviceTree540*541* PARAMETERS: None542*543* RETURN: None544*545* DESCRIPTION: Emit information about all devices within the ACPI namespace.546*547******************************************************************************/548549static void550MpEmitDeviceTree (551void)552{553554FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n\nACPI Device Tree\n");555FlPrintFile (ASL_FILE_MAP_OUTPUT, "----------------\n\n");556557FlPrintFile (ASL_FILE_MAP_OUTPUT, "Device Pathname "558"_HID Description\n\n");559560/* Walk the namespace from the root */561562(void) AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,563ACPI_UINT32_MAX, FALSE, MpEmitOneDevice, NULL, NULL, NULL);564}565566567/*******************************************************************************568*569* FUNCTION: MpEmitOneDevice570*571* PARAMETERS: ACPI_NAMESPACE_WALK callback572*573* RETURN: Status574*575* DESCRIPTION: Emit information about one ACPI device in the namespace. Used576* during dump of all device objects within the namespace.577*578******************************************************************************/579580static ACPI_STATUS581MpEmitOneDevice (582ACPI_HANDLE ObjHandle,583UINT32 NestingLevel,584void *Context,585void **ReturnValue)586{587char *DevicePathname;588char *DdnString;589char *HidString;590const AH_DEVICE_ID *HidInfo;591592593/* Device pathname */594595DevicePathname = AcpiNsGetExternalPathname (596ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle));597598FlPrintFile (ASL_FILE_MAP_OUTPUT, "%-32s", DevicePathname);599600/* _HID or _DDN */601602HidString = MpGetHidValue (603ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle));604FlPrintFile (ASL_FILE_MAP_OUTPUT, "%8s", HidString);605606HidInfo = AcpiAhMatchHardwareId (HidString);607if (HidInfo)608{609FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s",610HidInfo->Description);611}612else if ((DdnString = MpGetDdnValue (DevicePathname)))613{614FlPrintFile (ASL_FILE_MAP_OUTPUT, " // %s (_DDN)", DdnString);615}616617FlPrintFile (ASL_FILE_MAP_OUTPUT, "\n");618ACPI_FREE (DevicePathname);619return (AE_OK);620}621622623/*******************************************************************************624*625* FUNCTION: MpXrefDevices626*627* PARAMETERS: Info - A GPIO Info block628*629* RETURN: None630*631* DESCRIPTION: Cross-reference the parse tree and find all references to the632* specified GPIO device.633*634******************************************************************************/635636static void637MpXrefDevices (638ACPI_GPIO_INFO *Info)639{640641/* Walk the entire parse tree */642643TrWalkParseTree (AslGbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,644MpNamespaceXrefBegin, NULL, Info);645646if (!Info->References)647{648FlPrintFile (ASL_FILE_MAP_OUTPUT, " // **** No references in table");649}650}651652653/*******************************************************************************654*655* FUNCTION: MpNamespaceXrefBegin656*657* PARAMETERS: WALK_PARSE_TREE callback658*659* RETURN: Status660*661* DESCRIPTION: Walk parse tree callback used to cross-reference GPIO pins.662*663******************************************************************************/664665static ACPI_STATUS666MpNamespaceXrefBegin (667ACPI_PARSE_OBJECT *Op,668UINT32 Level,669void *Context)670{671ACPI_GPIO_INFO *Info = ACPI_CAST_PTR (ACPI_GPIO_INFO, Context);672const ACPI_OPCODE_INFO *OpInfo;673char *DevicePathname;674ACPI_PARSE_OBJECT *ParentOp;675char *HidString;676677678ACPI_FUNCTION_TRACE_PTR (MpNamespaceXrefBegin, Op);679680/*681* If this node is the actual declaration of a name682* [such as the XXXX name in "Method (XXXX)"],683* we are not interested in it here. We only care about names that684* are references to other objects within the namespace and the685* parent objects of name declarations686*/687if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION)688{689return (AE_OK);690}691692/* We are only interested in opcodes that have an associated name */693694OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);695696if ((OpInfo->Flags & AML_NAMED) ||697(OpInfo->Flags & AML_CREATE))698{699return (AE_OK);700}701702if ((Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&703(Op->Asl.ParseOpcode != PARSEOP_NAMESEG) &&704(Op->Asl.ParseOpcode != PARSEOP_METHODCALL))705{706return (AE_OK);707}708709if (!Op->Asl.Node)710{711return (AE_OK);712}713714ParentOp = Op->Asl.Parent;715if (ParentOp->Asl.ParseOpcode == PARSEOP_FIELD)716{717return (AE_OK);718}719720if (Op->Asl.Node == Info->TargetNode)721{722while (ParentOp && (!ParentOp->Asl.Node))723{724ParentOp = ParentOp->Asl.Parent;725}726727if (ParentOp)728{729DevicePathname = AcpiNsGetExternalPathname (730ParentOp->Asl.Node);731732if (!Info->References)733{734FlPrintFile (ASL_FILE_MAP_OUTPUT, " // References:");735}736737HidString = MpGetHidViaNamestring (DevicePathname);738739FlPrintFile (ASL_FILE_MAP_OUTPUT, " %s [%s]",740DevicePathname, HidString);741742Info->References++;743744ACPI_FREE (DevicePathname);745}746}747748return (AE_OK);749}750751752