1 /*******************************************************************************
3 * Module Name: dbcmds - Miscellaneous debug commands and output routines
5 ******************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, 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 *****************************************************************************/
118 #include "accommon.h"
119 #include "acevents.h"
122 #include "actables.h"
126 #define _COMPONENT ACPI_CA_DEBUGGER
127 ACPI_MODULE_NAME ("dbcmds")
130 /* Local prototypes */
133 AcpiDmCompareAmlResources (
135 ACPI_RSDESC_SIZE Aml1BufferLength,
137 ACPI_RSDESC_SIZE Aml2BufferLength);
140 AcpiDmTestResourceConversion (
141 ACPI_NAMESPACE_NODE *Node,
145 /*******************************************************************************
147 * FUNCTION: AcpiDbConvertToNode
149 * PARAMETERS: InString - String to convert
151 * RETURN: Pointer to a NS node
153 * DESCRIPTION: Convert a string to a valid NS pointer. Handles numeric or
156 ******************************************************************************/
158 ACPI_NAMESPACE_NODE *
159 AcpiDbConvertToNode (
162 ACPI_NAMESPACE_NODE *Node;
165 if ((*InString >= 0x30) && (*InString <= 0x39))
167 /* Numeric argument, convert */
169 Node = ACPI_TO_POINTER (ACPI_STRTOUL (InString, NULL, 16));
170 if (!AcpiOsReadable (Node, sizeof (ACPI_NAMESPACE_NODE)))
172 AcpiOsPrintf ("Address %p is invalid in this address space\n",
177 /* Make sure pointer is valid NS node */
179 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
181 AcpiOsPrintf ("Address %p is not a valid NS node [%s]\n",
182 Node, AcpiUtGetDescriptorName (Node));
189 /* The parameter is a name string that must be resolved to a
192 Node = AcpiDbLocalNsLookup (InString);
195 Node = AcpiGbl_RootNode;
203 /*******************************************************************************
205 * FUNCTION: AcpiDbSleep
207 * PARAMETERS: ObjectArg - Desired sleep state (0-5)
211 * DESCRIPTION: Simulate a sleep/wake sequence
213 ******************************************************************************/
223 SleepState = (UINT8) ACPI_STRTOUL (ObjectArg, NULL, 0);
225 AcpiOsPrintf ("**** Prepare to sleep ****\n");
226 Status = AcpiEnterSleepStatePrep (SleepState);
227 if (ACPI_FAILURE (Status))
232 AcpiOsPrintf ("**** Going to sleep ****\n");
233 Status = AcpiEnterSleepState (SleepState);
234 if (ACPI_FAILURE (Status))
239 AcpiOsPrintf ("**** returning from sleep ****\n");
240 Status = AcpiLeaveSleepState (SleepState);
245 /*******************************************************************************
247 * FUNCTION: AcpiDbDisplayLocks
253 * DESCRIPTION: Display information about internal mutexes.
255 ******************************************************************************/
264 for (i = 0; i < ACPI_MAX_MUTEX; i++)
266 AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
267 AcpiGbl_MutexInfo[i].ThreadId == ACPI_MUTEX_NOT_ACQUIRED
268 ? "Locked" : "Unlocked");
273 /*******************************************************************************
275 * FUNCTION: AcpiDbDisplayTableInfo
277 * PARAMETERS: TableArg - String with name of table to be displayed
281 * DESCRIPTION: Display information about loaded tables. Current
282 * implementation displays all loaded tables.
284 ******************************************************************************/
287 AcpiDbDisplayTableInfo (
291 ACPI_TABLE_DESC *TableDesc;
295 /* Walk the entire root table list */
297 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
299 TableDesc = &AcpiGbl_RootTableList.Tables[i];
300 AcpiOsPrintf ("%u ", i);
302 /* Make sure that the table is mapped */
304 Status = AcpiTbVerifyTable (TableDesc);
305 if (ACPI_FAILURE (Status))
310 /* Dump the table header */
312 if (TableDesc->Pointer)
314 AcpiTbPrintTableHeader (TableDesc->Address, TableDesc->Pointer);
318 /* If the pointer is null, the table has been unloaded */
320 ACPI_INFO ((AE_INFO, "%4.4s - Table has been unloaded",
321 TableDesc->Signature.Ascii));
327 /*******************************************************************************
329 * FUNCTION: AcpiDbUnloadAcpiTable
331 * PARAMETERS: TableArg - Name of the table to be unloaded
332 * InstanceArg - Which instance of the table to unload (if
333 * there are multiple tables of the same type)
337 * DESCRIPTION: Unload an ACPI table.
338 * Instance is not implemented
340 ******************************************************************************/
343 AcpiDbUnloadAcpiTable (
347 /* TBD: Need to reimplement for new data structures */
354 /* Search all tables for the target type */
356 for (i = 0; i < (ACPI_TABLE_ID_MAX+1); i++)
358 if (!ACPI_STRNCMP (TableArg, AcpiGbl_TableData[i].Signature,
359 AcpiGbl_TableData[i].SigLength))
361 /* Found the table, unload it */
363 Status = AcpiUnloadTable (i);
364 if (ACPI_SUCCESS (Status))
366 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
370 AcpiOsPrintf ("%s, while unloading [%s]\n",
371 AcpiFormatException (Status), TableArg);
378 AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
383 /*******************************************************************************
385 * FUNCTION: AcpiDbSendNotify
387 * PARAMETERS: Name - Name of ACPI object to send the notify to
388 * Value - Value of the notify to send.
392 * DESCRIPTION: Send an ACPI notification. The value specified is sent to the
393 * named object as an ACPI notify.
395 ******************************************************************************/
402 ACPI_NAMESPACE_NODE *Node;
406 /* Translate name to an Named object */
408 Node = AcpiDbConvertToNode (Name);
414 /* Decode Named object type */
418 case ACPI_TYPE_DEVICE:
419 case ACPI_TYPE_THERMAL:
421 /* Send the notify */
423 Status = AcpiEvQueueNotifyRequest (Node, Value);
424 if (ACPI_FAILURE (Status))
426 AcpiOsPrintf ("Could not queue notify\n");
431 AcpiOsPrintf ("Named object is not a device or a thermal object\n");
437 /*******************************************************************************
439 * FUNCTION: AcpiDbDisplayInterfaces
441 * PARAMETERS: ActionArg - Null, "install", or "remove"
442 * InterfaceNameArg - Name for install/remove options
446 * DESCRIPTION: Display or modify the global _OSI interface list
448 ******************************************************************************/
451 AcpiDbDisplayInterfaces (
453 char *InterfaceNameArg)
455 ACPI_INTERFACE_INFO *NextInterface;
460 /* If no arguments, just display current interface list */
464 (void) AcpiOsAcquireMutex (AcpiGbl_OsiMutex,
467 NextInterface = AcpiGbl_SupportedInterfaces;
469 while (NextInterface)
471 if (!(NextInterface->Flags & ACPI_OSI_INVALID))
473 AcpiOsPrintf ("%s\n", NextInterface->Name);
475 NextInterface = NextInterface->Next;
478 AcpiOsReleaseMutex (AcpiGbl_OsiMutex);
482 /* If ActionArg exists, so must InterfaceNameArg */
484 if (!InterfaceNameArg)
486 AcpiOsPrintf ("Missing Interface Name argument\n");
490 /* Uppercase the action for match below */
492 AcpiUtStrupr (ActionArg);
494 /* Install - install an interface */
496 SubString = ACPI_STRSTR ("INSTALL", ActionArg);
499 Status = AcpiInstallInterface (InterfaceNameArg);
500 if (ACPI_FAILURE (Status))
502 AcpiOsPrintf ("%s, while installing \"%s\"\n",
503 AcpiFormatException (Status), InterfaceNameArg);
508 /* Remove - remove an interface */
510 SubString = ACPI_STRSTR ("REMOVE", ActionArg);
513 Status = AcpiRemoveInterface (InterfaceNameArg);
514 if (ACPI_FAILURE (Status))
516 AcpiOsPrintf ("%s, while removing \"%s\"\n",
517 AcpiFormatException (Status), InterfaceNameArg);
522 /* Invalid ActionArg */
524 AcpiOsPrintf ("Invalid action argument: %s\n", ActionArg);
529 /*******************************************************************************
531 * FUNCTION: AcpiDmCompareAmlResources
533 * PARAMETERS: Aml1Buffer - Contains first resource list
534 * Aml1BufferLength - Length of first resource list
535 * Aml2Buffer - Contains second resource list
536 * Aml2BufferLength - Length of second resource list
540 * DESCRIPTION: Compare two AML resource lists, descriptor by descriptor (in
541 * order to isolate a miscompare to an individual resource)
543 ******************************************************************************/
546 AcpiDmCompareAmlResources (
548 ACPI_RSDESC_SIZE Aml1BufferLength,
550 ACPI_RSDESC_SIZE Aml2BufferLength)
554 ACPI_RSDESC_SIZE Aml1Length;
555 ACPI_RSDESC_SIZE Aml2Length;
556 ACPI_RSDESC_SIZE Offset = 0;
561 /* Compare overall buffer sizes (may be different due to size rounding) */
563 if (Aml1BufferLength != Aml2BufferLength)
566 "**** Buffer length mismatch in converted AML: original %X new %X ****\n",
567 Aml1BufferLength, Aml2BufferLength);
573 /* Walk the descriptor lists, comparing each descriptor */
575 while (Aml1 < (Aml1Buffer + Aml1BufferLength))
577 /* Get the lengths of each descriptor */
579 Aml1Length = AcpiUtGetDescriptorLength (Aml1);
580 Aml2Length = AcpiUtGetDescriptorLength (Aml2);
581 ResourceType = AcpiUtGetResourceType (Aml1);
583 /* Check for descriptor length match */
585 if (Aml1Length != Aml2Length)
588 "**** Length mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X L1 %X L2 %X ****\n",
589 Count, ResourceType, Offset, Aml1Length, Aml2Length);
592 /* Check for descriptor byte match */
594 else if (ACPI_MEMCMP (Aml1, Aml2, Aml1Length))
597 "**** Data mismatch in descriptor [%.2X] type %2.2X, Offset %8.8X ****\n",
598 Count, ResourceType, Offset);
601 /* Exit on EndTag descriptor */
603 if (ResourceType == ACPI_RESOURCE_NAME_END_TAG)
608 /* Point to next descriptor in each buffer */
611 Offset += Aml1Length;
618 /*******************************************************************************
620 * FUNCTION: AcpiDmTestResourceConversion
622 * PARAMETERS: Node - Parent device node
623 * Name - resource method name (_CRS)
627 * DESCRIPTION: Compare the original AML with a conversion of the AML to
628 * internal resource list, then back to AML.
630 ******************************************************************************/
633 AcpiDmTestResourceConversion (
634 ACPI_NAMESPACE_NODE *Node,
638 ACPI_BUFFER ReturnObj;
639 ACPI_BUFFER ResourceObj;
641 ACPI_OBJECT *OriginalAml;
644 AcpiOsPrintf ("Resource Conversion Comparison:\n");
646 NewAml.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
647 ReturnObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
648 ResourceObj.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
650 /* Get the original _CRS AML resource template */
652 Status = AcpiEvaluateObject (Node, Name, NULL, &ReturnObj);
653 if (ACPI_FAILURE (Status))
655 AcpiOsPrintf ("Could not obtain %s: %s\n",
656 Name, AcpiFormatException (Status));
660 /* Get the AML resource template, converted to internal resource structs */
662 Status = AcpiGetCurrentResources (Node, &ResourceObj);
663 if (ACPI_FAILURE (Status))
665 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
666 AcpiFormatException (Status));
670 /* Convert internal resource list to external AML resource template */
672 Status = AcpiRsCreateAmlResources (ResourceObj.Pointer, &NewAml);
673 if (ACPI_FAILURE (Status))
675 AcpiOsPrintf ("AcpiRsCreateAmlResources failed: %s\n",
676 AcpiFormatException (Status));
680 /* Compare original AML to the newly created AML resource list */
682 OriginalAml = ReturnObj.Pointer;
684 AcpiDmCompareAmlResources (
685 OriginalAml->Buffer.Pointer, (ACPI_RSDESC_SIZE) OriginalAml->Buffer.Length,
686 NewAml.Pointer, (ACPI_RSDESC_SIZE) NewAml.Length);
688 /* Cleanup and exit */
690 ACPI_FREE (NewAml.Pointer);
692 ACPI_FREE (ResourceObj.Pointer);
694 ACPI_FREE (ReturnObj.Pointer);
699 /*******************************************************************************
701 * FUNCTION: AcpiDbDisplayResources
703 * PARAMETERS: ObjectArg - String with hex value of the object
707 * DESCRIPTION: Display the resource objects associated with a device.
709 ******************************************************************************/
712 AcpiDbDisplayResources (
715 ACPI_NAMESPACE_NODE *Node;
717 ACPI_BUFFER ReturnObj;
720 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
721 AcpiDbgLevel |= ACPI_LV_RESOURCES;
723 /* Convert string to object pointer */
725 Node = AcpiDbConvertToNode (ObjectArg);
731 /* Prepare for a return object of arbitrary size */
733 ReturnObj.Pointer = AcpiGbl_DbBuffer;
734 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
738 AcpiOsPrintf ("Evaluating _PRT\n");
740 /* Check if _PRT exists */
742 Status = AcpiEvaluateObject (Node, METHOD_NAME__PRT, NULL, &ReturnObj);
743 if (ACPI_FAILURE (Status))
745 AcpiOsPrintf ("Could not obtain _PRT: %s\n",
746 AcpiFormatException (Status));
750 ReturnObj.Pointer = AcpiGbl_DbBuffer;
751 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
753 Status = AcpiGetIrqRoutingTable (Node, &ReturnObj);
754 if (ACPI_FAILURE (Status))
756 AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n",
757 AcpiFormatException (Status));
761 AcpiRsDumpIrqList (ACPI_CAST_PTR (UINT8, AcpiGbl_DbBuffer));
767 AcpiOsPrintf ("Evaluating _CRS\n");
769 ReturnObj.Pointer = AcpiGbl_DbBuffer;
770 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
772 /* Check if _CRS exists */
774 Status = AcpiEvaluateObject (Node, METHOD_NAME__CRS, NULL, &ReturnObj);
775 if (ACPI_FAILURE (Status))
777 AcpiOsPrintf ("Could not obtain _CRS: %s\n",
778 AcpiFormatException (Status));
782 /* Get the _CRS resource list */
784 ReturnObj.Pointer = AcpiGbl_DbBuffer;
785 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
787 Status = AcpiGetCurrentResources (Node, &ReturnObj);
788 if (ACPI_FAILURE (Status))
790 AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n",
791 AcpiFormatException (Status));
795 /* Dump the _CRS resource list */
797 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE,
801 * Perform comparison of original AML to newly created AML. This tests both
802 * the AML->Resource conversion and the Resource->Aml conversion.
804 Status = AcpiDmTestResourceConversion (Node, METHOD_NAME__CRS);
806 /* Execute _SRS with the resource list */
808 Status = AcpiSetCurrentResources (Node, &ReturnObj);
809 if (ACPI_FAILURE (Status))
811 AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n",
812 AcpiFormatException (Status));
820 AcpiOsPrintf ("Evaluating _PRS\n");
822 ReturnObj.Pointer = AcpiGbl_DbBuffer;
823 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
825 /* Check if _PRS exists */
827 Status = AcpiEvaluateObject (Node, METHOD_NAME__PRS, NULL, &ReturnObj);
828 if (ACPI_FAILURE (Status))
830 AcpiOsPrintf ("Could not obtain _PRS: %s\n",
831 AcpiFormatException (Status));
835 ReturnObj.Pointer = AcpiGbl_DbBuffer;
836 ReturnObj.Length = ACPI_DEBUG_BUFFER_SIZE;
838 Status = AcpiGetPossibleResources (Node, &ReturnObj);
839 if (ACPI_FAILURE (Status))
841 AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n",
842 AcpiFormatException (Status));
846 AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
850 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
855 /*******************************************************************************
857 * FUNCTION: AcpiDbGenerateGpe
859 * PARAMETERS: GpeArg - Raw GPE number, ascii string
860 * BlockArg - GPE block number, ascii string
861 * 0 or 1 for FADT GPE blocks
865 * DESCRIPTION: Generate a GPE
867 ******************************************************************************/
876 ACPI_GPE_EVENT_INFO *GpeEventInfo;
879 GpeNumber = ACPI_STRTOUL (GpeArg, NULL, 0);
880 BlockNumber = ACPI_STRTOUL (BlockArg, NULL, 0);
883 GpeEventInfo = AcpiEvGetGpeEventInfo (ACPI_TO_POINTER (BlockNumber),
887 AcpiOsPrintf ("Invalid GPE\n");
891 (void) AcpiEvGpeDispatch (NULL, GpeEventInfo, GpeNumber);
894 #endif /* ACPI_DEBUGGER */