Path: blob/main/sys/contrib/dev/acpica/components/debugger/dbcmds.c
48406 views
/*******************************************************************************1*2* Module Name: dbcmds - Miscellaneous debug commands and output routines3*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/acevents.h>154#include <contrib/dev/acpica/include/acdebug.h>155#include <contrib/dev/acpica/include/acnamesp.h>156#include <contrib/dev/acpica/include/acresrc.h>157#include <contrib/dev/acpica/include/actables.h>158159#define _COMPONENT ACPI_CA_DEBUGGER160ACPI_MODULE_NAME ("dbcmds")161162163/* Local prototypes */164165static void166AcpiDmCompareAmlResources (167UINT8 *Aml1Buffer,168ACPI_RSDESC_SIZE Aml1BufferLength,169UINT8 *Aml2Buffer,170ACPI_RSDESC_SIZE Aml2BufferLength);171172static ACPI_STATUS173AcpiDmTestResourceConversion (174ACPI_NAMESPACE_NODE *Node,175char *Name);176177static ACPI_STATUS178AcpiDbResourceCallback (179ACPI_RESOURCE *Resource,180void *Context);181182static ACPI_STATUS183AcpiDbDeviceResources (184ACPI_HANDLE ObjHandle,185UINT32 NestingLevel,186void *Context,187void **ReturnValue);188189static void190AcpiDbDoOneSleepState (191UINT8 SleepState);192193194static char *AcpiDbTraceMethodName = NULL;195196197/*******************************************************************************198*199* FUNCTION: AcpiDbConvertToNode200*201* PARAMETERS: InString - String to convert202*203* RETURN: Pointer to a NS node204*205* DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or206* alphanumeric strings.207*208******************************************************************************/209210ACPI_NAMESPACE_NODE *211AcpiDbConvertToNode (212char *InString)213{214ACPI_NAMESPACE_NODE *Node;215ACPI_SIZE Address;216217218if ((*InString >= 0x30) && (*InString <= 0x39))219{220/* Numeric argument, convert */221222Address = strtoul (InString, NULL, 16);223Node = ACPI_TO_POINTER (Address);224if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))225{226AcpiOsPrintf ("Address %p is invalid", Node);227return (NULL);228}229230/* Make sure pointer is valid NS node */231232if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)233{234AcpiOsPrintf ("Address %p is not a valid namespace node [%s]\n",235Node, AcpiUtGetDescriptorName (Node));236return (NULL);237}238}239else240{241/*242* Alpha argument: The parameter is a name string that must be243* resolved to a Namespace object.244*/245Node = AcpiDbLocalNsLookup (InString);246if (!Node)247{248AcpiOsPrintf (249"Could not find [%s] in namespace, defaulting to root node\n",250InString);251Node = AcpiGbl_RootNode;252}253}254255return (Node);256}257258259/*******************************************************************************260*261* FUNCTION: AcpiDbSleep262*263* PARAMETERS: ObjectArg - Desired sleep state (0-5). NULL means264* invoke all possible sleep states.265*266* RETURN: Status267*268* DESCRIPTION: Simulate sleep/wake sequences269*270******************************************************************************/271272ACPI_STATUS273AcpiDbSleep (274char *ObjectArg)275{276UINT8 SleepState;277UINT32 i;278279280ACPI_FUNCTION_TRACE (AcpiDbSleep);281282283/* Null input (no arguments) means to invoke all sleep states */284285if (!ObjectArg)286{287AcpiOsPrintf ("Invoking all possible sleep states, 0-%d\n",288ACPI_S_STATES_MAX);289290for (i = 0; i <= ACPI_S_STATES_MAX; i++)291{292AcpiDbDoOneSleepState ((UINT8) i);293}294295return_ACPI_STATUS (AE_OK);296}297298/* Convert argument to binary and invoke the sleep state */299300SleepState = (UINT8) strtoul (ObjectArg, NULL, 0);301AcpiDbDoOneSleepState (SleepState);302return_ACPI_STATUS (AE_OK);303}304305306/*******************************************************************************307*308* FUNCTION: AcpiDbDoOneSleepState309*310* PARAMETERS: SleepState - Desired sleep state (0-5)311*312* RETURN: None313*314* DESCRIPTION: Simulate a sleep/wake sequence315*316******************************************************************************/317318static void319AcpiDbDoOneSleepState (320UINT8 SleepState)321{322ACPI_STATUS Status;323UINT8 SleepTypeA;324UINT8 SleepTypeB;325326327/* Validate parameter */328329if (SleepState > ACPI_S_STATES_MAX)330{331AcpiOsPrintf ("Sleep state %d out of range (%d max)\n",332SleepState, ACPI_S_STATES_MAX);333return;334}335336AcpiOsPrintf ("\n---- Invoking sleep state S%d (%s):\n",337SleepState, AcpiGbl_SleepStateNames[SleepState]);338339/* Get the values for the sleep type registers (for display only) */340341Status = AcpiGetSleepTypeData (SleepState, &SleepTypeA, &SleepTypeB);342if (ACPI_FAILURE (Status))343{344AcpiOsPrintf ("Could not evaluate [%s] method, %s\n",345AcpiGbl_SleepStateNames[SleepState],346AcpiFormatException (Status));347return;348}349350AcpiOsPrintf (351"Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n",352SleepState, SleepTypeA, SleepTypeB);353354/* Invoke the various sleep/wake interfaces */355356AcpiOsPrintf ("**** Sleep: Prepare to sleep (S%d) ****\n",357SleepState);358Status = AcpiEnterSleepStatePrep (SleepState);359if (ACPI_FAILURE (Status))360{361goto ErrorExit;362}363364AcpiOsPrintf ("**** Sleep: Going to sleep (S%d) ****\n",365SleepState);366Status = AcpiEnterSleepState (SleepState);367if (ACPI_FAILURE (Status))368{369goto ErrorExit;370}371372AcpiOsPrintf ("**** Wake: Prepare to return from sleep (S%d) ****\n",373SleepState);374Status = AcpiLeaveSleepStatePrep (SleepState);375if (ACPI_FAILURE (Status))376{377goto ErrorExit;378}379380AcpiOsPrintf ("**** Wake: Return from sleep (S%d) ****\n",381SleepState);382Status = AcpiLeaveSleepState (SleepState);383if (ACPI_FAILURE (Status))384{385goto ErrorExit;386}387388return;389390391ErrorExit:392ACPI_EXCEPTION ((AE_INFO, Status, "During invocation of sleep state S%d",393SleepState));394}395396397/*******************************************************************************398*399* FUNCTION: AcpiDbDisplayLocks400*401* PARAMETERS: None402*403* RETURN: None404*405* DESCRIPTION: Display information about internal mutexes.406*407******************************************************************************/408409void410AcpiDbDisplayLocks (411void)412{413UINT32 i;414415416for (i = 0; i < ACPI_MAX_MUTEX; i++)417{418AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),419AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED420? "Locked" : "Unlocked");421}422}423424425/*******************************************************************************426*427* FUNCTION: AcpiDbDisplayTableInfo428*429* PARAMETERS: TableArg - Name of table to be displayed430*431* RETURN: None432*433* DESCRIPTION: Display information about loaded tables. Current434* implementation displays all loaded tables.435*436******************************************************************************/437438void439AcpiDbDisplayTableInfo (440char *TableArg)441{442UINT32 i;443ACPI_TABLE_DESC *TableDesc;444ACPI_STATUS Status;445446447/* Header */448449AcpiOsPrintf ("Idx ID Status Type "450"TableHeader (Sig, Address, Length, Misc)\n");451452/* Walk the entire root table list */453454for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)455{456TableDesc = &AcpiGbl_RootTableList.Tables[i];457458/* Index and Table ID */459460AcpiOsPrintf ("%3u %.2u ", i, TableDesc->OwnerId);461462/* Decode the table flags */463464if (!(TableDesc->Flags & ACPI_TABLE_IS_LOADED))465{466AcpiOsPrintf ("NotLoaded ");467}468else469{470AcpiOsPrintf (" Loaded ");471}472473switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)474{475case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:476477AcpiOsPrintf ("External/virtual ");478break;479480case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:481482AcpiOsPrintf ("Internal/physical ");483break;484485case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:486487AcpiOsPrintf ("Internal/virtual ");488break;489490default:491492AcpiOsPrintf ("INVALID TYPE ");493break;494}495496/* Make sure that the table is mapped */497498Status = AcpiTbValidateTable (TableDesc);499if (ACPI_FAILURE (Status))500{501return;502}503504/* Dump the table header */505506if (TableDesc->Pointer)507{508AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);509}510else511{512/* If the pointer is null, the table has been unloaded */513514ACPI_INFO (("%4.4s - Table has been unloaded",515TableDesc->Signature.Ascii));516}517}518}519520521/*******************************************************************************522*523* FUNCTION: AcpiDbUnloadAcpiTable524*525* PARAMETERS: ObjectName - Namespace pathname for an object that526* is owned by the table to be unloaded527*528* RETURN: None529*530* DESCRIPTION: Unload an ACPI table, via any namespace node that is owned531* by the table.532*533******************************************************************************/534535void536AcpiDbUnloadAcpiTable (537char *ObjectName)538{539ACPI_NAMESPACE_NODE *Node;540ACPI_STATUS Status;541542543/* Translate name to an Named object */544545Node = AcpiDbConvertToNode (ObjectName);546if (!Node)547{548return;549}550551Status = AcpiUnloadParentTable (ACPI_CAST_PTR (ACPI_HANDLE, Node));552if (ACPI_SUCCESS (Status))553{554AcpiOsPrintf ("Parent of [%s] (%p) unloaded and uninstalled\n",555ObjectName, Node);556}557else558{559AcpiOsPrintf ("%s, while unloading parent table of [%s]\n",560AcpiFormatException (Status), ObjectName);561}562}563564565/*******************************************************************************566*567* FUNCTION: AcpiDbSendNotify568*569* PARAMETERS: Name - Name of ACPI object where to send notify570* Value - Value of the notify to send.571*572* RETURN: None573*574* DESCRIPTION: Send an ACPI notification. The value specified is sent to the575* named object as an ACPI notify.576*577******************************************************************************/578579void580AcpiDbSendNotify (581char *Name,582UINT32 Value)583{584ACPI_NAMESPACE_NODE *Node;585ACPI_STATUS Status;586587588/* Translate name to an Named object */589590Node = AcpiDbConvertToNode (Name);591if (!Node)592{593return;594}595596/* Dispatch the notify if legal */597598if (AcpiEvIsNotifyObject (Node))599{600Status = AcpiEvQueueNotifyRequest (Node, Value);601if (ACPI_FAILURE (Status))602{603AcpiOsPrintf ("Could not queue notify\n");604}605}606else607{608AcpiOsPrintf (609"Named object [%4.4s] Type %s, "610"must be Device/Thermal/Processor type\n",611AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type));612}613}614615616/*******************************************************************************617*618* FUNCTION: AcpiDbDisplayInterfaces619*620* PARAMETERS: ActionArg - Null, "install", or "remove"621* InterfaceNameArg - Name for install/remove options622*623* RETURN: None624*625* DESCRIPTION: Display or modify the global _OSI interface list626*627******************************************************************************/628629void630AcpiDbDisplayInterfaces (631char *ActionArg,632char *InterfaceNameArg)633{634ACPI_INTERFACE_INFO *NextInterface;635char *SubString;636ACPI_STATUS Status;637638639/* If no arguments, just display current interface list */640641if (!ActionArg)642{643(void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);644645NextInterface = AcpiGbl_SupportedInterfaces;646while (NextInterface)647{648if (!(NextInterface->Flags & ACPI_OSI_INVALID))649{650AcpiOsPrintf ("%s\n", NextInterface->Name);651}652653NextInterface = NextInterface->Next;654}655656AcpiOsReleaseMutex (AcpiGbl_OsiMutex);657return;658}659660/* If ActionArg exists, so must InterfaceNameArg */661662if (!InterfaceNameArg)663{664AcpiOsPrintf ("Missing Interface Name argument\n");665return;666}667668/* Uppercase the action for match below */669670AcpiUtStrupr (ActionArg);671672/* Install - install an interface */673674SubString = strstr ("INSTALL", ActionArg);675if (SubString)676{677Status = AcpiInstallInterface (InterfaceNameArg);678if (ACPI_FAILURE (Status))679{680AcpiOsPrintf ("%s, while installing \"%s\"\n",681AcpiFormatException (Status), InterfaceNameArg);682}683return;684}685686/* Remove - remove an interface */687688SubString = strstr ("REMOVE", ActionArg);689if (SubString)690{691Status = AcpiRemoveInterface (InterfaceNameArg);692if (ACPI_FAILURE (Status))693{694AcpiOsPrintf ("%s, while removing \"%s\"\n",695AcpiFormatException (Status), InterfaceNameArg);696}697return;698}699700/* Invalid ActionArg */701702AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg);703return;704}705706707/*******************************************************************************708*709* FUNCTION: AcpiDbDisplayTemplate710*711* PARAMETERS: BufferArg - Buffer name or address712*713* RETURN: None714*715* DESCRIPTION: Dump a buffer that contains a resource template716*717******************************************************************************/718719void720AcpiDbDisplayTemplate (721char *BufferArg)722{723ACPI_NAMESPACE_NODE *Node;724ACPI_STATUS Status;725ACPI_BUFFER ReturnBuffer;726727728/* Translate BufferArg to an Named object */729730Node = AcpiDbConvertToNode (BufferArg);731if (!Node || (Node == AcpiGbl_RootNode))732{733AcpiOsPrintf ("Invalid argument: %s\n", BufferArg);734return;735}736737/* We must have a buffer object */738739if (Node->Type != ACPI_TYPE_BUFFER)740{741AcpiOsPrintf ("Not a Buffer object, cannot be a template: %s\n",742BufferArg);743return;744}745746ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;747ReturnBuffer.Pointer = AcpiGbl_DbBuffer;748749/* Attempt to convert the raw buffer to a resource list */750751Status = AcpiRsCreateResourceList (Node->Object, &ReturnBuffer);752753AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);754AcpiDbgLevel |= ACPI_LV_RESOURCES;755756if (ACPI_FAILURE (Status))757{758AcpiOsPrintf (759"Could not convert Buffer to a resource list: %s, %s\n",760BufferArg, AcpiFormatException (Status));761goto DumpBuffer;762}763764/* Now we can dump the resource list */765766AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,767ReturnBuffer.Pointer));768769DumpBuffer:770AcpiOsPrintf ("\nRaw data buffer:\n");771AcpiUtDebugDumpBuffer ((UINT8 *) Node->Object->Buffer.Pointer,772Node->Object->Buffer.Length,773DB_BYTE_DISPLAY, ACPI_UINT32_MAX);774775AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);776return;777}778779780/*******************************************************************************781*782* FUNCTION: AcpiDmCompareAmlResources783*784* PARAMETERS: Aml1Buffer - Contains first resource list785* Aml1BufferLength - Length of first resource list786* Aml2Buffer - Contains second resource list787* Aml2BufferLength - Length of second resource list788*789* RETURN: None790*791* DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in792* order to isolate a miscompare to an individual resource)793*794******************************************************************************/795796static void797AcpiDmCompareAmlResources (798UINT8 *Aml1Buffer,799ACPI_RSDESC_SIZE Aml1BufferLength,800UINT8 *Aml2Buffer,801ACPI_RSDESC_SIZE Aml2BufferLength)802{803UINT8 *Aml1;804UINT8 *Aml2;805UINT8 *Aml1End;806UINT8 *Aml2End;807ACPI_RSDESC_SIZE Aml1Length;808ACPI_RSDESC_SIZE Aml2Length;809ACPI_RSDESC_SIZE Offset = 0;810UINT8 ResourceType;811UINT32 Count = 0;812UINT32 i;813814815/* Compare overall buffer sizes (may be different due to size rounding) */816817if (Aml1BufferLength != Aml2BufferLength)818{819AcpiOsPrintf (820"**** Buffer length mismatch in converted "821"AML: Original %X, New %X ****\n",822Aml1BufferLength, Aml2BufferLength);823}824825Aml1 = Aml1Buffer;826Aml2 = Aml2Buffer;827Aml1End = Aml1Buffer + Aml1BufferLength;828Aml2End = Aml2Buffer + Aml2BufferLength;829830/* Walk the descriptor lists, comparing each descriptor */831832while ((Aml1 < Aml1End) && (Aml2 < Aml2End))833{834/* Get the lengths of each descriptor */835836Aml1Length = AcpiUtGetDescriptorLength (Aml1);837Aml2Length = AcpiUtGetDescriptorLength (Aml2);838ResourceType = AcpiUtGetResourceType (Aml1);839840/* Check for descriptor length match */841842if (Aml1Length != Aml2Length)843{844AcpiOsPrintf (845"**** Length mismatch in descriptor [%.2X] type %2.2X, "846"Offset %8.8X Len1 %X, Len2 %X ****\n",847Count, ResourceType, Offset, Aml1Length, Aml2Length);848}849850/* Check for descriptor byte match */851852else if (memcmp (Aml1, Aml2, Aml1Length))853{854AcpiOsPrintf (855"**** Data mismatch in descriptor [%.2X] type %2.2X, "856"Offset %8.8X ****\n",857Count, ResourceType, Offset);858859for (i = 0; i < Aml1Length; i++)860{861if (Aml1[i] != Aml2[i])862{863AcpiOsPrintf (864"Mismatch at byte offset %.2X: is %2.2X, "865"should be %2.2X\n",866i, Aml2[i], Aml1[i]);867}868}869}870871/* Exit on EndTag descriptor */872873if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)874{875return;876}877878/* Point to next descriptor in each buffer */879880Count++;881Offset += Aml1Length;882Aml1 += Aml1Length;883Aml2 += Aml2Length;884}885}886887888/*******************************************************************************889*890* FUNCTION: AcpiDmTestResourceConversion891*892* PARAMETERS: Node - Parent device node893* Name - resource method name (_CRS)894*895* RETURN: Status896*897* DESCRIPTION: Compare the original AML with a conversion of the AML to898* internal resource list, then back to AML.899*900******************************************************************************/901902static ACPI_STATUS903AcpiDmTestResourceConversion (904ACPI_NAMESPACE_NODE *Node,905char *Name)906{907ACPI_STATUS Status;908ACPI_BUFFER ReturnBuffer;909ACPI_BUFFER ResourceBuffer;910ACPI_BUFFER NewAml;911ACPI_OBJECT *OriginalAml;912913914AcpiOsPrintf ("Resource Conversion Comparison:\n");915916NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;917ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;918ResourceBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;919920/* Get the original _CRS AML resource template */921922Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnBuffer);923if (ACPI_FAILURE (Status))924{925AcpiOsPrintf ("Could not obtain %s: %s\n",926Name, AcpiFormatException (Status));927return (Status);928}929930/* Get the AML resource template, converted to internal resource structs */931932Status = AcpiGetCurrentResources (Node, &ResourceBuffer);933if (ACPI_FAILURE (Status))934{935AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",936AcpiFormatException (Status));937goto Exit1;938}939940/* Convert internal resource list to external AML resource template */941942Status = AcpiRsCreateAmlResources (&ResourceBuffer, &NewAml);943if (ACPI_FAILURE (Status))944{945AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",946AcpiFormatException (Status));947goto Exit2;948}949950/* Compare original AML to the newly created AML resource list */951952OriginalAml = ReturnBuffer.Pointer;953954AcpiDmCompareAmlResources (OriginalAml->Buffer.Pointer,955(ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length,956NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length);957958/* Cleanup and exit */959960ACPI_FREE (NewAml.Pointer);961Exit2:962ACPI_FREE (ResourceBuffer.Pointer);963Exit1:964ACPI_FREE (ReturnBuffer.Pointer);965return (Status);966}967968969/*******************************************************************************970*971* FUNCTION: AcpiDbResourceCallback972*973* PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK974*975* RETURN: Status976*977* DESCRIPTION: Simple callback to exercise AcpiWalkResources and978* AcpiWalkResourceBuffer.979*980******************************************************************************/981982static ACPI_STATUS983AcpiDbResourceCallback (984ACPI_RESOURCE *Resource,985void *Context)986{987988return (AE_OK);989}990991992/*******************************************************************************993*994* FUNCTION: AcpiDbDeviceResources995*996* PARAMETERS: ACPI_WALK_CALLBACK997*998* RETURN: Status999*1000* DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object.1001*1002******************************************************************************/10031004static ACPI_STATUS1005AcpiDbDeviceResources (1006ACPI_HANDLE ObjHandle,1007UINT32 NestingLevel,1008void *Context,1009void **ReturnValue)1010{1011ACPI_NAMESPACE_NODE *Node;1012ACPI_NAMESPACE_NODE *PrtNode = NULL;1013ACPI_NAMESPACE_NODE *CrsNode = NULL;1014ACPI_NAMESPACE_NODE *PrsNode = NULL;1015ACPI_NAMESPACE_NODE *AeiNode = NULL;1016char *ParentPath;1017ACPI_BUFFER ReturnBuffer;1018ACPI_STATUS Status;101910201021Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);1022ParentPath = AcpiNsGetNormalizedPathname (Node, TRUE);1023if (!ParentPath)1024{1025return (AE_NO_MEMORY);1026}10271028/* Get handles to the resource methods for this device */10291030(void) AcpiGetHandle (Node, METHOD_NAME__PRT,1031ACPI_CAST_PTR (ACPI_HANDLE, &PrtNode));1032(void) AcpiGetHandle (Node, METHOD_NAME__CRS,1033ACPI_CAST_PTR (ACPI_HANDLE, &CrsNode));1034(void) AcpiGetHandle (Node, METHOD_NAME__PRS,1035ACPI_CAST_PTR (ACPI_HANDLE, &PrsNode));1036(void) AcpiGetHandle (Node, METHOD_NAME__AEI,1037ACPI_CAST_PTR (ACPI_HANDLE, &AeiNode));10381039if (!PrtNode && !CrsNode && !PrsNode && !AeiNode)1040{1041goto Cleanup; /* Nothing to do */1042}10431044AcpiOsPrintf ("\nDevice: %s\n", ParentPath);10451046/* Prepare for a return object of arbitrary size */10471048ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1049ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;105010511052/* _PRT */10531054if (PrtNode)1055{1056AcpiOsPrintf ("Evaluating _PRT\n");10571058Status = AcpiEvaluateObject (PrtNode, NULL, NULL, &ReturnBuffer);1059if (ACPI_FAILURE (Status))1060{1061AcpiOsPrintf ("Could not evaluate _PRT: %s\n",1062AcpiFormatException (Status));1063goto GetCrs;1064}10651066ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1067ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;10681069Status = AcpiGetIrqRoutingTable (Node, &ReturnBuffer);1070if (ACPI_FAILURE (Status))1071{1072AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",1073AcpiFormatException (Status));1074goto GetCrs;1075}10761077AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer));1078}107910801081/* _CRS */10821083GetCrs:1084if (CrsNode)1085{1086AcpiOsPrintf ("Evaluating _CRS\n");10871088ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1089ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;10901091Status = AcpiEvaluateObject (CrsNode, NULL, NULL, &ReturnBuffer);1092if (ACPI_FAILURE (Status))1093{1094AcpiOsPrintf ("Could not evaluate _CRS: %s\n",1095AcpiFormatException (Status));1096goto GetPrs;1097}10981099/* This code exercises the AcpiWalkResources interface */11001101Status = AcpiWalkResources (Node, METHOD_NAME__CRS,1102AcpiDbResourceCallback, NULL);1103if (ACPI_FAILURE (Status))1104{1105AcpiOsPrintf ("AcpiWalkResources failed: %s\n",1106AcpiFormatException (Status));1107goto GetPrs;1108}11091110/* Get the _CRS resource list (test ALLOCATE buffer) */11111112ReturnBuffer.Pointer = NULL;1113ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;11141115Status = AcpiGetCurrentResources (Node, &ReturnBuffer);1116if (ACPI_FAILURE (Status))1117{1118AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",1119AcpiFormatException (Status));1120goto GetPrs;1121}11221123/* This code exercises the AcpiWalkResourceBuffer interface */11241125Status = AcpiWalkResourceBuffer (&ReturnBuffer,1126AcpiDbResourceCallback, NULL);1127if (ACPI_FAILURE (Status))1128{1129AcpiOsPrintf ("AcpiWalkResourceBuffer failed: %s\n",1130AcpiFormatException (Status));1131goto EndCrs;1132}11331134/* Dump the _CRS resource list */11351136AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,1137ReturnBuffer.Pointer));11381139/*1140* Perform comparison of original AML to newly created AML. This1141* tests both the AML->Resource conversion and the Resource->AML1142* conversion.1143*/1144(void) AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);11451146/* Execute _SRS with the resource list */11471148AcpiOsPrintf ("Evaluating _SRS\n");11491150Status = AcpiSetCurrentResources (Node, &ReturnBuffer);1151if (ACPI_FAILURE (Status))1152{1153AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",1154AcpiFormatException (Status));1155goto EndCrs;1156}11571158EndCrs:1159ACPI_FREE (ReturnBuffer.Pointer);1160}116111621163/* _PRS */11641165GetPrs:1166if (PrsNode)1167{1168AcpiOsPrintf ("Evaluating _PRS\n");11691170ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1171ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;11721173Status = AcpiEvaluateObject (PrsNode, NULL, NULL, &ReturnBuffer);1174if (ACPI_FAILURE (Status))1175{1176AcpiOsPrintf ("Could not evaluate _PRS: %s\n",1177AcpiFormatException (Status));1178goto GetAei;1179}11801181ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1182ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;11831184Status = AcpiGetPossibleResources (Node, &ReturnBuffer);1185if (ACPI_FAILURE (Status))1186{1187AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",1188AcpiFormatException (Status));1189goto GetAei;1190}11911192AcpiRsDumpResourceList (ACPI_CAST_PTR (1193ACPI_RESOURCE, AcpiGbl_DbBuffer));1194}119511961197/* _AEI */11981199GetAei:1200if (AeiNode)1201{1202AcpiOsPrintf ("Evaluating _AEI\n");12031204ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1205ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;12061207Status = AcpiEvaluateObject (AeiNode, NULL, NULL, &ReturnBuffer);1208if (ACPI_FAILURE (Status))1209{1210AcpiOsPrintf ("Could not evaluate _AEI: %s\n",1211AcpiFormatException (Status));1212goto Cleanup;1213}12141215ReturnBuffer.Pointer = AcpiGbl_DbBuffer;1216ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;12171218Status = AcpiGetEventResources (Node, &ReturnBuffer);1219if (ACPI_FAILURE (Status))1220{1221AcpiOsPrintf ("AcpiGetEventResources failed: %s\n",1222AcpiFormatException (Status));1223goto Cleanup;1224}12251226AcpiRsDumpResourceList (ACPI_CAST_PTR (1227ACPI_RESOURCE, AcpiGbl_DbBuffer));1228}122912301231Cleanup:1232ACPI_FREE (ParentPath);1233return (AE_OK);1234}123512361237/*******************************************************************************1238*1239* FUNCTION: AcpiDbDisplayResources1240*1241* PARAMETERS: ObjectArg - String object name or object pointer.1242* NULL or "*" means "display resources for1243* all devices"1244*1245* RETURN: None1246*1247* DESCRIPTION: Display the resource objects associated with a device.1248*1249******************************************************************************/12501251void1252AcpiDbDisplayResources (1253char *ObjectArg)1254{1255ACPI_NAMESPACE_NODE *Node;125612571258AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);1259AcpiDbgLevel |= ACPI_LV_RESOURCES;12601261/* Asterisk means "display resources for all devices" */12621263if (!ObjectArg || (!strcmp (ObjectArg, "*")))1264{1265(void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,1266ACPI_UINT32_MAX, AcpiDbDeviceResources, NULL, NULL, NULL);1267}1268else1269{1270/* Convert string to object pointer */12711272Node = AcpiDbConvertToNode (ObjectArg);1273if (Node)1274{1275if (Node->Type != ACPI_TYPE_DEVICE)1276{1277AcpiOsPrintf (1278"%4.4s: Name is not a device object (%s)\n",1279Node->Name.Ascii, AcpiUtGetTypeName (Node->Type));1280}1281else1282{1283(void) AcpiDbDeviceResources (Node, 0, NULL, NULL);1284}1285}1286}12871288AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);1289}129012911292/*******************************************************************************1293*1294* FUNCTION: AcpiDbGenerateGed1295*1296* PARAMETERS: GedArg - Raw GED number, ascii string1297*1298* RETURN: None1299*1300* DESCRIPTION: Simulate firing of a GED1301*1302******************************************************************************/13031304void1305AcpiDbGenerateInterrupt (1306char *GsivArg)1307{1308UINT32 GsivNumber;1309ACPI_GED_HANDLER_INFO *GedInfo = AcpiGbl_GedHandlerList;13101311if (!GedInfo) {1312AcpiOsPrintf ("No GED handling present\n");1313}13141315GsivNumber = strtoul (GsivArg, NULL, 0);13161317while (GedInfo) {13181319if (GedInfo->IntId == GsivNumber) {1320ACPI_OBJECT_LIST ArgList;1321ACPI_OBJECT Arg0;1322ACPI_HANDLE EvtHandle = GedInfo->EvtMethod;1323ACPI_STATUS Status;13241325AcpiOsPrintf ("Evaluate GED _EVT (GSIV=%d)\n", GsivNumber);13261327if (!EvtHandle) {1328AcpiOsPrintf ("Undefined _EVT method\n");1329return;1330}13311332Arg0.Integer.Type = ACPI_TYPE_INTEGER;1333Arg0.Integer.Value = GsivNumber;13341335ArgList.Count = 1;1336ArgList.Pointer = &Arg0;13371338Status = AcpiEvaluateObject (EvtHandle, NULL, &ArgList, NULL);1339if (ACPI_FAILURE (Status))1340{1341AcpiOsPrintf ("Could not evaluate _EVT\n");1342return;1343}13441345}1346GedInfo = GedInfo->Next;1347}1348}13491350#if (!ACPI_REDUCED_HARDWARE)1351/*******************************************************************************1352*1353* FUNCTION: AcpiDbGenerateGpe1354*1355* PARAMETERS: GpeArg - Raw GPE number, ascii string1356* BlockArg - GPE block number, ascii string1357* 0 or 1 for FADT GPE blocks1358*1359* RETURN: None1360*1361* DESCRIPTION: Simulate firing of a GPE1362*1363******************************************************************************/13641365void1366AcpiDbGenerateGpe (1367char *GpeArg,1368char *BlockArg)1369{1370UINT32 BlockNumber = 0;1371UINT32 GpeNumber;1372ACPI_GPE_EVENT_INFO *GpeEventInfo;137313741375GpeNumber = strtoul (GpeArg, NULL, 0);13761377/*1378* If no block arg, or block arg == 0 or 1, use the FADT-defined1379* GPE blocks.1380*/1381if (BlockArg)1382{1383BlockNumber = strtoul (BlockArg, NULL, 0);1384if (BlockNumber == 1)1385{1386BlockNumber = 0;1387}1388}13891390GpeEventInfo = AcpiEvGetGpeEventInfo (1391ACPI_TO_POINTER (BlockNumber), GpeNumber);1392if (!GpeEventInfo)1393{1394AcpiOsPrintf ("Invalid GPE\n");1395return;1396}13971398(void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber);1399}140014011402/*******************************************************************************1403*1404* FUNCTION: AcpiDbGenerateSci1405*1406* PARAMETERS: None1407*1408* RETURN: None1409*1410* DESCRIPTION: Simulate an SCI -- just call the SCI dispatch.1411*1412******************************************************************************/14131414void1415AcpiDbGenerateSci (1416void)1417{1418AcpiEvSciDispatch ();1419}14201421#endif /* !ACPI_REDUCED_HARDWARE */142214231424/*******************************************************************************1425*1426* FUNCTION: AcpiDbTrace1427*1428* PARAMETERS: EnableArg - ENABLE/AML to enable tracer1429* DISABLE to disable tracer1430* MethodArg - Method to trace1431* OnceArg - Whether trace once1432*1433* RETURN: None1434*1435* DESCRIPTION: Control method tracing facility1436*1437******************************************************************************/14381439void1440AcpiDbTrace (1441char *EnableArg,1442char *MethodArg,1443char *OnceArg)1444{1445UINT32 DebugLevel = 0;1446UINT32 DebugLayer = 0;1447UINT32 Flags = 0;144814491450AcpiUtStrupr (EnableArg);1451AcpiUtStrupr (OnceArg);14521453if (MethodArg)1454{1455if (AcpiDbTraceMethodName)1456{1457ACPI_FREE (AcpiDbTraceMethodName);1458AcpiDbTraceMethodName = NULL;1459}14601461AcpiDbTraceMethodName = ACPI_ALLOCATE (strlen (MethodArg) + 1);1462if (!AcpiDbTraceMethodName)1463{1464AcpiOsPrintf ("Failed to allocate method name (%s)\n",1465MethodArg);1466return;1467}14681469strcpy (AcpiDbTraceMethodName, MethodArg);1470}14711472if (!strcmp (EnableArg, "ENABLE") ||1473!strcmp (EnableArg, "METHOD") ||1474!strcmp (EnableArg, "OPCODE"))1475{1476if (!strcmp (EnableArg, "ENABLE"))1477{1478/* Inherit current console settings */14791480DebugLevel = AcpiGbl_DbConsoleDebugLevel;1481DebugLayer = AcpiDbgLayer;1482}1483else1484{1485/* Restrict console output to trace points only */14861487DebugLevel = ACPI_LV_TRACE_POINT;1488DebugLayer = ACPI_EXECUTER;1489}14901491Flags = ACPI_TRACE_ENABLED;14921493if (!strcmp (EnableArg, "OPCODE"))1494{1495Flags |= ACPI_TRACE_OPCODE;1496}14971498if (OnceArg && !strcmp (OnceArg, "ONCE"))1499{1500Flags |= ACPI_TRACE_ONESHOT;1501}1502}15031504(void) AcpiDebugTrace (AcpiDbTraceMethodName,1505DebugLevel, DebugLayer, Flags);1506}150715081509