1 /*******************************************************************************
3 * Module Name: dbcmds - Miscellaneous debug commands and output routines
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acevents.h>
155 #include <contrib/dev/acpica/include/acdebug.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include <contrib/dev/acpica/include/acresrc.h>
158 #include <contrib/dev/acpica/include/actables.h>
161 #define _COMPONENT ACPI_CA_DEBUGGER
162 ACPI_MODULE_NAME ("dbcmds")
165 /* Local prototypes */
168 AcpiDmCompareAmlResources (
170 ACPI_RSDESC_SIZE Aml1BufferLength,
172 ACPI_RSDESC_SIZE Aml2BufferLength);
175 AcpiDmTestResourceConversion (
176 ACPI_NAMESPACE_NODE *Node,
180 AcpiDbResourceCallback (
181 ACPI_RESOURCE *Resource,
185 AcpiDbDeviceResources (
186 ACPI_HANDLE ObjHandle,
192 AcpiDbDoOneSleepState (
196 static char *AcpiDbTraceMethodName = NULL;
199 /*******************************************************************************
201 * FUNCTION: AcpiDbConvertToNode
203 * PARAMETERS: InString - String to convert
205 * RETURN: Pointer to a NS node
207 * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or
208 * alphanumeric strings.
210 ******************************************************************************/
212 ACPI_NAMESPACE_NODE *
213 AcpiDbConvertToNode (
216 ACPI_NAMESPACE_NODE *Node;
220 if ((*InString >= 0x30) && (*InString <= 0x39))
222 /* Numeric argument, convert */
224 Address = strtoul (InString, NULL, 16);
225 Node = ACPI_TO_POINTER (Address);
226 if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
228 AcpiOsPrintf ("Address %p is invalid", Node);
232 /* Make sure pointer is valid NS node */
234 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
236 AcpiOsPrintf ("Address %p is not a valid namespace node [%s]\n",
237 Node, AcpiUtGetDescriptorName (Node));
244 * Alpha argument: The parameter is a name string that must be
245 * resolved to a Namespace object.
247 Node = AcpiDbLocalNsLookup (InString);
251 "Could not find [%s] in namespace, defaulting to root node\n",
253 Node = AcpiGbl_RootNode;
261 /*******************************************************************************
263 * FUNCTION: AcpiDbSleep
265 * PARAMETERS: ObjectArg - Desired sleep state (0-5). NULL means
266 * invoke all possible sleep states.
270 * DESCRIPTION: Simulate sleep/wake sequences
272 ******************************************************************************/
282 ACPI_FUNCTION_TRACE (AcpiDbSleep);
285 /* Null input (no arguments) means to invoke all sleep states */
289 AcpiOsPrintf ("Invoking all possible sleep states, 0-%d\n",
292 for (i = 0; i <= ACPI_S_STATES_MAX; i++)
294 AcpiDbDoOneSleepState ((UINT8) i);
297 return_ACPI_STATUS (AE_OK);
300 /* Convert argument to binary and invoke the sleep state */
302 SleepState = (UINT8) strtoul (ObjectArg, NULL, 0);
303 AcpiDbDoOneSleepState (SleepState);
304 return_ACPI_STATUS (AE_OK);
308 /*******************************************************************************
310 * FUNCTION: AcpiDbDoOneSleepState
312 * PARAMETERS: SleepState - Desired sleep state (0-5)
316 * DESCRIPTION: Simulate a sleep/wake sequence
318 ******************************************************************************/
321 AcpiDbDoOneSleepState (
329 /* Validate parameter */
331 if (SleepState > ACPI_S_STATES_MAX)
333 AcpiOsPrintf ("Sleep state %d out of range (%d max)\n",
334 SleepState, ACPI_S_STATES_MAX);
338 AcpiOsPrintf ("\n---- Invoking sleep state S%d (%s):\n",
339 SleepState, AcpiGbl_SleepStateNames[SleepState]);
341 /* Get the values for the sleep type registers (for display only) */
343 Status = AcpiGetSleepTypeData (SleepState, &SleepTypeA, &SleepTypeB);
344 if (ACPI_FAILURE (Status))
346 AcpiOsPrintf ("Could not evaluate [%s] method, %s\n",
347 AcpiGbl_SleepStateNames[SleepState],
348 AcpiFormatException (Status));
353 "Register values for sleep state S%d: Sleep-A: %.2X, Sleep-B: %.2X\n",
354 SleepState, SleepTypeA, SleepTypeB);
356 /* Invoke the various sleep/wake interfaces */
358 AcpiOsPrintf ("**** Sleep: Prepare to sleep (S%d) ****\n",
360 Status = AcpiEnterSleepStatePrep (SleepState);
361 if (ACPI_FAILURE (Status))
366 AcpiOsPrintf ("**** Sleep: Going to sleep (S%d) ****\n",
368 Status = AcpiEnterSleepState (SleepState);
369 if (ACPI_FAILURE (Status))
374 AcpiOsPrintf ("**** Wake: Prepare to return from sleep (S%d) ****\n",
376 Status = AcpiLeaveSleepStatePrep (SleepState);
377 if (ACPI_FAILURE (Status))
382 AcpiOsPrintf ("**** Wake: Return from sleep (S%d) ****\n",
384 Status = AcpiLeaveSleepState (SleepState);
385 if (ACPI_FAILURE (Status))
394 ACPI_EXCEPTION ((AE_INFO, Status, "During invocation of sleep state S%d",
399 /*******************************************************************************
401 * FUNCTION: AcpiDbDisplayLocks
407 * DESCRIPTION: Display information about internal mutexes.
409 ******************************************************************************/
418 for (i = 0; i < ACPI_MAX_MUTEX; i++)
420 AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
421 AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED
422 ? "Locked" : "Unlocked");
427 /*******************************************************************************
429 * FUNCTION: AcpiDbDisplayTableInfo
431 * PARAMETERS: TableArg - Name of table to be displayed
435 * DESCRIPTION: Display information about loaded tables. Current
436 * implementation displays all loaded tables.
438 ******************************************************************************/
441 AcpiDbDisplayTableInfo (
445 ACPI_TABLE_DESC *TableDesc;
451 AcpiOsPrintf ("Idx ID Status Type "
452 "TableHeader (Sig, Address, Length, Misc)\n");
454 /* Walk the entire root table list */
456 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
458 TableDesc = &AcpiGbl_RootTableList.Tables[i];
460 /* Index and Table ID */
462 AcpiOsPrintf ("%3u %.2u ", i, TableDesc->OwnerId);
464 /* Decode the table flags */
466 if (!(TableDesc->Flags & ACPI_TABLE_IS_LOADED))
468 AcpiOsPrintf ("NotLoaded ");
472 AcpiOsPrintf (" Loaded ");
475 switch (TableDesc->Flags & ACPI_TABLE_ORIGIN_MASK)
477 case ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL:
479 AcpiOsPrintf ("External/virtual ");
482 case ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL:
484 AcpiOsPrintf ("Internal/physical ");
487 case ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL:
489 AcpiOsPrintf ("Internal/virtual ");
494 AcpiOsPrintf ("INVALID TYPE ");
498 /* Make sure that the table is mapped */
500 Status = AcpiTbValidateTable (TableDesc);
501 if (ACPI_FAILURE (Status))
506 /* Dump the table header */
508 if (TableDesc->Pointer)
510 AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);
514 /* If the pointer is null, the table has been unloaded */
516 ACPI_INFO (("%4.4s - Table has been unloaded",
517 TableDesc->Signature.Ascii));
523 /*******************************************************************************
525 * FUNCTION: AcpiDbUnloadAcpiTable
527 * PARAMETERS: ObjectName - Namespace pathname for an object that
528 * is owned by the table to be unloaded
532 * DESCRIPTION: Unload an ACPI table, via any namespace node that is owned
535 ******************************************************************************/
538 AcpiDbUnloadAcpiTable (
541 ACPI_NAMESPACE_NODE *Node;
545 /* Translate name to an Named object */
547 Node = AcpiDbConvertToNode (ObjectName);
553 Status = AcpiUnloadParentTable (ACPI_CAST_PTR (ACPI_HANDLE, Node));
554 if (ACPI_SUCCESS (Status))
556 AcpiOsPrintf ("Parent of [%s] (%p) unloaded and uninstalled\n",
561 AcpiOsPrintf ("%s, while unloading parent table of [%s]\n",
562 AcpiFormatException (Status), ObjectName);
567 /*******************************************************************************
569 * FUNCTION: AcpiDbSendNotify
571 * PARAMETERS: Name - Name of ACPI object where to send notify
572 * Value - Value of the notify to send.
576 * DESCRIPTION: Send an ACPI notification. The value specified is sent to the
577 * named object as an ACPI notify.
579 ******************************************************************************/
586 ACPI_NAMESPACE_NODE *Node;
590 /* Translate name to an Named object */
592 Node = AcpiDbConvertToNode (Name);
598 /* Dispatch the notify if legal */
600 if (AcpiEvIsNotifyObject (Node))
602 Status = AcpiEvQueueNotifyRequest (Node, Value);
603 if (ACPI_FAILURE (Status))
605 AcpiOsPrintf ("Could not queue notify\n");
611 "Named object [%4.4s] Type %s, "
612 "must be Device/Thermal/Processor type\n",
613 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type));
618 /*******************************************************************************
620 * FUNCTION: AcpiDbDisplayInterfaces
622 * PARAMETERS: ActionArg - Null, "install", or "remove"
623 * InterfaceNameArg - Name for install/remove options
627 * DESCRIPTION: Display or modify the global _OSI interface list
629 ******************************************************************************/
632 AcpiDbDisplayInterfaces (
634 char *InterfaceNameArg)
636 ACPI_INTERFACE_INFO *NextInterface;
641 /* If no arguments, just display current interface list */
645 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex, ACPI_WAIT_FOREVER);
647 NextInterface = AcpiGbl_SupportedInterfaces;
648 while (NextInterface)
650 if (!(NextInterface->Flags & ACPI_OSI_INVALID))
652 AcpiOsPrintf ("%s\n", NextInterface->Name);
655 NextInterface = NextInterface->Next;
658 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
662 /* If ActionArg exists, so must InterfaceNameArg */
664 if (!InterfaceNameArg)
666 AcpiOsPrintf ("Missing Interface Name argument\n");
670 /* Uppercase the action for match below */
672 AcpiUtStrupr (ActionArg);
674 /* Install - install an interface */
676 SubString = strstr ("INSTALL", ActionArg);
679 Status = AcpiInstallInterface (InterfaceNameArg);
680 if (ACPI_FAILURE (Status))
682 AcpiOsPrintf ("%s, while installing \"%s\"\n",
683 AcpiFormatException (Status), InterfaceNameArg);
688 /* Remove - remove an interface */
690 SubString = strstr ("REMOVE", ActionArg);
693 Status = AcpiRemoveInterface (InterfaceNameArg);
694 if (ACPI_FAILURE (Status))
696 AcpiOsPrintf ("%s, while removing \"%s\"\n",
697 AcpiFormatException (Status), InterfaceNameArg);
702 /* Invalid ActionArg */
704 AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg);
709 /*******************************************************************************
711 * FUNCTION: AcpiDbDisplayTemplate
713 * PARAMETERS: BufferArg - Buffer name or address
717 * DESCRIPTION: Dump a buffer that contains a resource template
719 ******************************************************************************/
722 AcpiDbDisplayTemplate (
725 ACPI_NAMESPACE_NODE *Node;
727 ACPI_BUFFER ReturnBuffer;
730 /* Translate BufferArg to an Named object */
732 Node = AcpiDbConvertToNode (BufferArg);
733 if (!Node || (Node == AcpiGbl_RootNode))
735 AcpiOsPrintf ("Invalid argument: %s\n", BufferArg);
739 /* We must have a buffer object */
741 if (Node->Type != ACPI_TYPE_BUFFER)
743 AcpiOsPrintf ("Not a Buffer object, cannot be a template: %s\n",
748 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
749 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
751 /* Attempt to convert the raw buffer to a resource list */
753 Status = AcpiRsCreateResourceList (Node->Object, &ReturnBuffer);
755 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
756 AcpiDbgLevel |= ACPI_LV_RESOURCES;
758 if (ACPI_FAILURE (Status))
761 "Could not convert Buffer to a resource list: %s, %s\n",
762 BufferArg, AcpiFormatException (Status));
766 /* Now we can dump the resource list */
768 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
769 ReturnBuffer.Pointer));
772 AcpiOsPrintf ("\nRaw data buffer:\n");
773 AcpiUtDebugDumpBuffer ((UINT8 *) Node->Object->Buffer.Pointer,
774 Node->Object->Buffer.Length,
775 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
777 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
782 /*******************************************************************************
784 * FUNCTION: AcpiDmCompareAmlResources
786 * PARAMETERS: Aml1Buffer - Contains first resource list
787 * Aml1BufferLength - Length of first resource list
788 * Aml2Buffer - Contains second resource list
789 * Aml2BufferLength - Length of second resource list
793 * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
794 * order to isolate a miscompare to an individual resource)
796 ******************************************************************************/
799 AcpiDmCompareAmlResources (
801 ACPI_RSDESC_SIZE Aml1BufferLength,
803 ACPI_RSDESC_SIZE Aml2BufferLength)
809 ACPI_RSDESC_SIZE Aml1Length;
810 ACPI_RSDESC_SIZE Aml2Length;
811 ACPI_RSDESC_SIZE Offset = 0;
817 /* Compare overall buffer sizes (may be different due to size rounding) */
819 if (Aml1BufferLength != Aml2BufferLength)
822 "**** Buffer length mismatch in converted "
823 "AML: Original %X, New %X ****\n",
824 Aml1BufferLength, Aml2BufferLength);
829 Aml1End = Aml1Buffer + Aml1BufferLength;
830 Aml2End = Aml2Buffer + Aml2BufferLength;
832 /* Walk the descriptor lists, comparing each descriptor */
834 while ((Aml1 < Aml1End) && (Aml2 < Aml2End))
836 /* Get the lengths of each descriptor */
838 Aml1Length = AcpiUtGetDescriptorLength (Aml1);
839 Aml2Length = AcpiUtGetDescriptorLength (Aml2);
840 ResourceType = AcpiUtGetResourceType (Aml1);
842 /* Check for descriptor length match */
844 if (Aml1Length != Aml2Length)
847 "**** Length mismatch in descriptor [%.2X] type %2.2X, "
848 "Offset %8.8X Len1 %X, Len2 %X ****\n",
849 Count, ResourceType, Offset, Aml1Length, Aml2Length);
852 /* Check for descriptor byte match */
854 else if (memcmp (Aml1, Aml2, Aml1Length))
857 "**** Data mismatch in descriptor [%.2X] type %2.2X, "
858 "Offset %8.8X ****\n",
859 Count, ResourceType, Offset);
861 for (i = 0; i < Aml1Length; i++)
863 if (Aml1[i] != Aml2[i])
866 "Mismatch at byte offset %.2X: is %2.2X, "
868 i, Aml2[i], Aml1[i]);
873 /* Exit on EndTag descriptor */
875 if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)
880 /* Point to next descriptor in each buffer */
883 Offset += Aml1Length;
890 /*******************************************************************************
892 * FUNCTION: AcpiDmTestResourceConversion
894 * PARAMETERS: Node - Parent device node
895 * Name - resource method name (_CRS)
899 * DESCRIPTION: Compare the original AML with a conversion of the AML to
900 * internal resource list, then back to AML.
902 ******************************************************************************/
905 AcpiDmTestResourceConversion (
906 ACPI_NAMESPACE_NODE *Node,
910 ACPI_BUFFER ReturnBuffer;
911 ACPI_BUFFER ResourceBuffer;
913 ACPI_OBJECT *OriginalAml;
916 AcpiOsPrintf ("Resource Conversion Comparison:\n");
918 NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
919 ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
920 ResourceBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
922 /* Get the original _CRS AML resource template */
924 Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnBuffer);
925 if (ACPI_FAILURE (Status))
927 AcpiOsPrintf ("Could not obtain %s: %s\n",
928 Name, AcpiFormatException (Status));
932 /* Get the AML resource template, converted to internal resource structs */
934 Status = AcpiGetCurrentResources (Node, &ResourceBuffer);
935 if (ACPI_FAILURE (Status))
937 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
938 AcpiFormatException (Status));
942 /* Convert internal resource list to external AML resource template */
944 Status = AcpiRsCreateAmlResources (&ResourceBuffer, &NewAml);
945 if (ACPI_FAILURE (Status))
947 AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",
948 AcpiFormatException (Status));
952 /* Compare original AML to the newly created AML resource list */
954 OriginalAml = ReturnBuffer.Pointer;
956 AcpiDmCompareAmlResources (OriginalAml->Buffer.Pointer,
957 (ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length,
958 NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length);
960 /* Cleanup and exit */
962 ACPI_FREE (NewAml.Pointer);
964 ACPI_FREE (ResourceBuffer.Pointer);
966 ACPI_FREE (ReturnBuffer.Pointer);
971 /*******************************************************************************
973 * FUNCTION: AcpiDbResourceCallback
975 * PARAMETERS: ACPI_WALK_RESOURCE_CALLBACK
979 * DESCRIPTION: Simple callback to exercise AcpiWalkResources and
980 * AcpiWalkResourceBuffer.
982 ******************************************************************************/
985 AcpiDbResourceCallback (
986 ACPI_RESOURCE *Resource,
994 /*******************************************************************************
996 * FUNCTION: AcpiDbDeviceResources
998 * PARAMETERS: ACPI_WALK_CALLBACK
1002 * DESCRIPTION: Display the _PRT/_CRS/_PRS resources for a device object.
1004 ******************************************************************************/
1007 AcpiDbDeviceResources (
1008 ACPI_HANDLE ObjHandle,
1009 UINT32 NestingLevel,
1013 ACPI_NAMESPACE_NODE *Node;
1014 ACPI_NAMESPACE_NODE *PrtNode = NULL;
1015 ACPI_NAMESPACE_NODE *CrsNode = NULL;
1016 ACPI_NAMESPACE_NODE *PrsNode = NULL;
1017 ACPI_NAMESPACE_NODE *AeiNode = NULL;
1019 ACPI_BUFFER ReturnBuffer;
1023 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
1024 ParentPath = AcpiNsGetNormalizedPathname (Node, TRUE);
1027 return (AE_NO_MEMORY);
1030 /* Get handles to the resource methods for this device */
1032 (void) AcpiGetHandle (Node, METHOD_NAME__PRT,
1033 ACPI_CAST_PTR (ACPI_HANDLE, &PrtNode));
1034 (void) AcpiGetHandle (Node, METHOD_NAME__CRS,
1035 ACPI_CAST_PTR (ACPI_HANDLE, &CrsNode));
1036 (void) AcpiGetHandle (Node, METHOD_NAME__PRS,
1037 ACPI_CAST_PTR (ACPI_HANDLE, &PrsNode));
1038 (void) AcpiGetHandle (Node, METHOD_NAME__AEI,
1039 ACPI_CAST_PTR (ACPI_HANDLE, &AeiNode));
1041 if (!PrtNode && !CrsNode && !PrsNode && !AeiNode)
1043 goto Cleanup; /* Nothing to do */
1046 AcpiOsPrintf ("\nDevice: %s\n", ParentPath);
1048 /* Prepare for a return object of arbitrary size */
1050 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1051 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1058 AcpiOsPrintf ("Evaluating _PRT\n");
1060 Status = AcpiEvaluateObject (PrtNode, NULL, NULL, &ReturnBuffer);
1061 if (ACPI_FAILURE (Status))
1063 AcpiOsPrintf ("Could not evaluate _PRT: %s\n",
1064 AcpiFormatException (Status));
1068 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1069 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1071 Status = AcpiGetIrqRoutingTable (Node, &ReturnBuffer);
1072 if (ACPI_FAILURE (Status))
1074 AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",
1075 AcpiFormatException (Status));
1079 AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer));
1088 AcpiOsPrintf ("Evaluating _CRS\n");
1090 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1091 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1093 Status = AcpiEvaluateObject (CrsNode, NULL, NULL, &ReturnBuffer);
1094 if (ACPI_FAILURE (Status))
1096 AcpiOsPrintf ("Could not evaluate _CRS: %s\n",
1097 AcpiFormatException (Status));
1101 /* This code exercises the AcpiWalkResources interface */
1103 Status = AcpiWalkResources (Node, METHOD_NAME__CRS,
1104 AcpiDbResourceCallback, NULL);
1105 if (ACPI_FAILURE (Status))
1107 AcpiOsPrintf ("AcpiWalkResources failed: %s\n",
1108 AcpiFormatException (Status));
1112 /* Get the _CRS resource list (test ALLOCATE buffer) */
1114 ReturnBuffer.Pointer = NULL;
1115 ReturnBuffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1117 Status = AcpiGetCurrentResources (Node, &ReturnBuffer);
1118 if (ACPI_FAILURE (Status))
1120 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
1121 AcpiFormatException (Status));
1125 /* This code exercises the AcpiWalkResourceBuffer interface */
1127 Status = AcpiWalkResourceBuffer (&ReturnBuffer,
1128 AcpiDbResourceCallback, NULL);
1129 if (ACPI_FAILURE (Status))
1131 AcpiOsPrintf ("AcpiWalkResourceBuffer failed: %s\n",
1132 AcpiFormatException (Status));
1136 /* Dump the _CRS resource list */
1138 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
1139 ReturnBuffer.Pointer));
1142 * Perform comparison of original AML to newly created AML. This
1143 * tests both the AML->Resource conversion and the Resource->AML
1146 (void) AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);
1148 /* Execute _SRS with the resource list */
1150 AcpiOsPrintf ("Evaluating _SRS\n");
1152 Status = AcpiSetCurrentResources (Node, &ReturnBuffer);
1153 if (ACPI_FAILURE (Status))
1155 AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",
1156 AcpiFormatException (Status));
1161 ACPI_FREE (ReturnBuffer.Pointer);
1170 AcpiOsPrintf ("Evaluating _PRS\n");
1172 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1173 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1175 Status = AcpiEvaluateObject (PrsNode, NULL, NULL, &ReturnBuffer);
1176 if (ACPI_FAILURE (Status))
1178 AcpiOsPrintf ("Could not evaluate _PRS: %s\n",
1179 AcpiFormatException (Status));
1183 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1184 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1186 Status = AcpiGetPossibleResources (Node, &ReturnBuffer);
1187 if (ACPI_FAILURE (Status))
1189 AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",
1190 AcpiFormatException (Status));
1194 AcpiRsDumpResourceList (ACPI_CAST_PTR (
1195 ACPI_RESOURCE, AcpiGbl_DbBuffer));
1204 AcpiOsPrintf ("Evaluating _AEI\n");
1206 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1207 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1209 Status = AcpiEvaluateObject (AeiNode, NULL, NULL, &ReturnBuffer);
1210 if (ACPI_FAILURE (Status))
1212 AcpiOsPrintf ("Could not evaluate _AEI: %s\n",
1213 AcpiFormatException (Status));
1217 ReturnBuffer.Pointer = AcpiGbl_DbBuffer;
1218 ReturnBuffer.Length = ACPI_DEBUG_BUFFER_SIZE;
1220 Status = AcpiGetEventResources (Node, &ReturnBuffer);
1221 if (ACPI_FAILURE (Status))
1223 AcpiOsPrintf ("AcpiGetEventResources failed: %s\n",
1224 AcpiFormatException (Status));
1228 AcpiRsDumpResourceList (ACPI_CAST_PTR (
1229 ACPI_RESOURCE, AcpiGbl_DbBuffer));
1234 ACPI_FREE (ParentPath);
1239 /*******************************************************************************
1241 * FUNCTION: AcpiDbDisplayResources
1243 * PARAMETERS: ObjectArg - String object name or object pointer.
1244 * NULL or "*" means "display resources for
1249 * DESCRIPTION: Display the resource objects associated with a device.
1251 ******************************************************************************/
1254 AcpiDbDisplayResources (
1257 ACPI_NAMESPACE_NODE *Node;
1260 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1261 AcpiDbgLevel |= ACPI_LV_RESOURCES;
1263 /* Asterisk means "display resources for all devices" */
1265 if (!ObjectArg || (!strcmp (ObjectArg, "*")))
1267 (void) AcpiWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1268 ACPI_UINT32_MAX, AcpiDbDeviceResources, NULL, NULL, NULL);
1272 /* Convert string to object pointer */
1274 Node = AcpiDbConvertToNode (ObjectArg);
1277 if (Node->Type != ACPI_TYPE_DEVICE)
1280 "%4.4s: Name is not a device object (%s)\n",
1281 Node->Name.Ascii, AcpiUtGetTypeName (Node->Type));
1285 (void) AcpiDbDeviceResources (Node, 0, NULL, NULL);
1290 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1294 #if (!ACPI_REDUCED_HARDWARE)
1295 /*******************************************************************************
1297 * FUNCTION: AcpiDbGenerateGpe
1299 * PARAMETERS: GpeArg - Raw GPE number, ascii string
1300 * BlockArg - GPE block number, ascii string
1301 * 0 or 1 for FADT GPE blocks
1305 * DESCRIPTION: Simulate firing of a GPE
1307 ******************************************************************************/
1314 UINT32 BlockNumber = 0;
1316 ACPI_GPE_EVENT_INFO *GpeEventInfo;
1319 GpeNumber = strtoul (GpeArg, NULL, 0);
1322 * If no block arg, or block arg == 0 or 1, use the FADT-defined
1327 BlockNumber = strtoul (BlockArg, NULL, 0);
1328 if (BlockNumber == 1)
1334 GpeEventInfo = AcpiEvGetGpeEventInfo (
1335 ACPI_TO_POINTER (BlockNumber), GpeNumber);
1338 AcpiOsPrintf ("Invalid GPE\n");
1342 (void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber);
1346 /*******************************************************************************
1348 * FUNCTION: AcpiDbGenerateSci
1354 * DESCRIPTION: Simulate an SCI -- just call the SCI dispatch.
1356 ******************************************************************************/
1362 AcpiEvSciDispatch ();
1365 #endif /* !ACPI_REDUCED_HARDWARE */
1368 /*******************************************************************************
1370 * FUNCTION: AcpiDbTrace
1372 * PARAMETERS: EnableArg - ENABLE/AML to enable tracer
1373 * DISABLE to disable tracer
1374 * MethodArg - Method to trace
1375 * OnceArg - Whether trace once
1379 * DESCRIPTION: Control method tracing facility
1381 ******************************************************************************/
1389 UINT32 DebugLevel = 0;
1390 UINT32 DebugLayer = 0;
1394 AcpiUtStrupr (EnableArg);
1395 AcpiUtStrupr (OnceArg);
1399 if (AcpiDbTraceMethodName)
1401 ACPI_FREE (AcpiDbTraceMethodName);
1402 AcpiDbTraceMethodName = NULL;
1405 AcpiDbTraceMethodName = ACPI_ALLOCATE (strlen (MethodArg) + 1);
1406 if (!AcpiDbTraceMethodName)
1408 AcpiOsPrintf ("Failed to allocate method name (%s)\n",
1413 strcpy (AcpiDbTraceMethodName, MethodArg);
1416 if (!strcmp (EnableArg, "ENABLE") ||
1417 !strcmp (EnableArg, "METHOD") ||
1418 !strcmp (EnableArg, "OPCODE"))
1420 if (!strcmp (EnableArg, "ENABLE"))
1422 /* Inherit current console settings */
1424 DebugLevel = AcpiGbl_DbConsoleDebugLevel;
1425 DebugLayer = AcpiDbgLayer;
1429 /* Restrict console output to trace points only */
1431 DebugLevel = ACPI_LV_TRACE_POINT;
1432 DebugLayer = ACPI_EXECUTER;
1435 Flags = ACPI_TRACE_ENABLED;
1437 if (!strcmp (EnableArg, "OPCODE"))
1439 Flags |= ACPI_TRACE_OPCODE;
1442 if (OnceArg && !strcmp (OnceArg, "ONCE"))
1444 Flags |= ACPI_TRACE_ONESHOT;
1448 (void) AcpiDebugTrace (AcpiDbTraceMethodName,
1449 DebugLevel, DebugLayer, Flags);