1 /*******************************************************************************
3 * Module Name: dbnames - Debugger commands for the acpi namespace
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
49 #include <contrib/dev/acpica/include/acpredef.h>
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dbnames")
58 /* Local prototypes */
61 AcpiDbWalkAndMatchName (
62 ACPI_HANDLE ObjHandle,
68 AcpiDbWalkForPredefinedNames (
69 ACPI_HANDLE ObjHandle,
75 AcpiDbWalkForSpecificObjects (
76 ACPI_HANDLE ObjHandle,
83 ACPI_HANDLE ObjHandle,
89 AcpiDbWalkForReferences (
90 ACPI_HANDLE ObjHandle,
97 ACPI_HANDLE ObjHandle,
103 * Arguments for the Objects command
104 * These object types map directly to the ACPI_TYPES
106 static ACPI_DB_ARGUMENT_INFO AcpiDbObjectTypes [] =
130 {NULL} /* Must be null terminated */
134 /*******************************************************************************
136 * FUNCTION: AcpiDbSetScope
138 * PARAMETERS: Name - New scope path
142 * DESCRIPTION: Set the "current scope" as maintained by this utility.
143 * The scope is used as a prefix to ACPI paths.
145 ******************************************************************************/
152 ACPI_NAMESPACE_NODE *Node;
155 if (!Name || Name[0] == 0)
157 AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
161 AcpiDbPrepNamestring (Name);
163 if (ACPI_IS_ROOT_PREFIX (Name[0]))
165 /* Validate new scope from the root */
167 Status = AcpiNsGetNode (AcpiGbl_RootNode, Name, ACPI_NS_NO_UPSEARCH,
169 if (ACPI_FAILURE (Status))
174 ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
175 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
179 /* Validate new scope relative to old scope */
181 Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name, ACPI_NS_NO_UPSEARCH,
183 if (ACPI_FAILURE (Status))
188 ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
189 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
192 AcpiGbl_DbScopeNode = Node;
193 AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
198 AcpiOsPrintf ("Could not attach scope: %s, %s\n",
199 Name, AcpiFormatException (Status));
203 /*******************************************************************************
205 * FUNCTION: AcpiDbDumpNamespace
207 * PARAMETERS: StartArg - Node to begin namespace dump
208 * DepthArg - Maximum tree depth to be dumped
212 * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
213 * with type and other information.
215 ******************************************************************************/
218 AcpiDbDumpNamespace (
222 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
223 UINT32 MaxDepth = ACPI_UINT32_MAX;
226 /* No argument given, just start at the root and dump entire namespace */
230 SubtreeEntry = AcpiDbConvertToNode (StartArg);
236 /* Now we can check for the depth argument */
240 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
244 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
245 AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
246 ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
248 /* Display the subtree */
250 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
251 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
252 ACPI_OWNER_ID_MAX, SubtreeEntry);
253 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
257 /*******************************************************************************
259 * FUNCTION: AcpiDbDumpNamespacePaths
265 * DESCRIPTION: Dump entire namespace with full object pathnames and object
266 * type information. Alternative to "namespace" command.
268 ******************************************************************************/
271 AcpiDbDumpNamespacePaths (
275 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
276 AcpiOsPrintf ("ACPI Namespace (from root):\n");
278 /* Display the entire namespace */
280 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
281 AcpiNsDumpObjectPaths (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY,
282 ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
284 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
288 /*******************************************************************************
290 * FUNCTION: AcpiDbDumpNamespaceByOwner
292 * PARAMETERS: OwnerArg - Owner ID whose nodes will be displayed
293 * DepthArg - Maximum tree depth to be dumped
297 * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
299 ******************************************************************************/
302 AcpiDbDumpNamespaceByOwner (
306 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
307 UINT32 MaxDepth = ACPI_UINT32_MAX;
308 ACPI_OWNER_ID OwnerId;
311 OwnerId = (ACPI_OWNER_ID) ACPI_STRTOUL (OwnerArg, NULL, 0);
313 /* Now we can check for the depth argument */
317 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
320 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
321 AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
323 /* Display the subtree */
325 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
326 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId,
328 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
332 /*******************************************************************************
334 * FUNCTION: AcpiDbWalkAndMatchName
336 * PARAMETERS: Callback from WalkNamespace
340 * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
341 * are supported -- '?' matches any character.
343 ******************************************************************************/
346 AcpiDbWalkAndMatchName (
347 ACPI_HANDLE ObjHandle,
353 char *RequestedName = (char *) Context;
359 /* Check for a name match */
361 for (i = 0; i < 4; i++)
363 /* Wildcard support */
365 if ((RequestedName[i] != '?') &&
366 (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
368 /* No match, just exit */
374 /* Get the full pathname to this object */
376 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
377 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
378 if (ACPI_FAILURE (Status))
380 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
384 Info.OwnerId = ACPI_OWNER_ID_MAX;
385 Info.DebugLevel = ACPI_UINT32_MAX;
386 Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
388 AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
389 (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
390 ACPI_FREE (Buffer.Pointer);
397 /*******************************************************************************
399 * FUNCTION: AcpiDbFindNameInNamespace
401 * PARAMETERS: NameArg - The 4-character ACPI name to find.
402 * wildcards are supported.
406 * DESCRIPTION: Search the namespace for a given name (with wildcards)
408 ******************************************************************************/
411 AcpiDbFindNameInNamespace (
414 char AcpiName[5] = "____";
415 char *AcpiNamePtr = AcpiName;
418 if (ACPI_STRLEN (NameArg) > 4)
420 AcpiOsPrintf ("Name must be no longer than 4 characters\n");
424 /* Pad out name with underscores as necessary to create a 4-char name */
426 AcpiUtStrupr (NameArg);
429 *AcpiNamePtr = *NameArg;
434 /* Walk the namespace from the root */
436 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
437 AcpiDbWalkAndMatchName, NULL, AcpiName, NULL);
439 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
444 /*******************************************************************************
446 * FUNCTION: AcpiDbWalkForPredefinedNames
448 * PARAMETERS: Callback from WalkNamespace
452 * DESCRIPTION: Detect and display predefined ACPI names (names that start with
455 ******************************************************************************/
458 AcpiDbWalkForPredefinedNames (
459 ACPI_HANDLE ObjHandle,
464 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
465 UINT32 *Count = (UINT32 *) Context;
466 const ACPI_PREDEFINED_INFO *Predefined;
467 const ACPI_PREDEFINED_INFO *Package = NULL;
469 char StringBuffer[48];
472 Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
478 Pathname = AcpiNsGetExternalPathname (Node);
484 /* If method returns a package, the info is in the next table entry */
486 if (Predefined->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
488 Package = Predefined + 1;
491 AcpiUtGetExpectedReturnTypes (StringBuffer,
492 Predefined->Info.ExpectedBtypes);
494 AcpiOsPrintf ("%-32s Arguments %X, Return Types: %s", Pathname,
495 METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList),
500 AcpiOsPrintf (" (PkgType %2.2X, ObjType %2.2X, Count %2.2X)",
501 Package->RetInfo.Type, Package->RetInfo.ObjectType1,
502 Package->RetInfo.Count1);
507 /* Check that the declared argument count matches the ACPI spec */
509 AcpiNsCheckAcpiCompliance (Pathname, Node, Predefined);
511 ACPI_FREE (Pathname);
517 /*******************************************************************************
519 * FUNCTION: AcpiDbCheckPredefinedNames
525 * DESCRIPTION: Validate all predefined names in the namespace
527 ******************************************************************************/
530 AcpiDbCheckPredefinedNames (
536 /* Search all nodes in namespace */
538 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
539 AcpiDbWalkForPredefinedNames, NULL, (void *) &Count, NULL);
541 AcpiOsPrintf ("Found %u predefined names in the namespace\n", Count);
545 /*******************************************************************************
547 * FUNCTION: AcpiDbWalkForSpecificObjects
549 * PARAMETERS: Callback from WalkNamespace
553 * DESCRIPTION: Display short info about objects in the namespace
555 ******************************************************************************/
558 AcpiDbWalkForSpecificObjects (
559 ACPI_HANDLE ObjHandle,
564 ACPI_WALK_INFO *Info = (ACPI_WALK_INFO *) Context;
571 /* Get and display the full pathname to this object */
573 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
574 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
575 if (ACPI_FAILURE (Status))
577 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
581 AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
582 ACPI_FREE (Buffer.Pointer);
584 /* Dump short info about the object */
586 (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
591 /*******************************************************************************
593 * FUNCTION: AcpiDbDisplayObjects
595 * PARAMETERS: ObjTypeArg - Type of object to display
596 * DisplayCountArg - Max depth to display
600 * DESCRIPTION: Display objects in the namespace of the requested type
602 ******************************************************************************/
605 AcpiDbDisplayObjects (
607 char *DisplayCountArg)
610 ACPI_OBJECT_TYPE Type;
613 /* Get the object type */
615 Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
616 if (Type == ACPI_TYPE_NOT_FOUND)
618 AcpiOsPrintf ("Invalid or unsupported argument\n");
622 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
624 "Objects of type [%s] defined in the current ACPI Namespace:\n",
625 AcpiUtGetTypeName (Type));
627 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
630 Info.OwnerId = ACPI_OWNER_ID_MAX;
631 Info.DebugLevel = ACPI_UINT32_MAX;
632 Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
634 /* Walk the namespace from the root */
636 (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
637 AcpiDbWalkForSpecificObjects, NULL, (void *) &Info, NULL);
640 "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
641 Info.Count, AcpiUtGetTypeName (Type));
643 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
648 /*******************************************************************************
650 * FUNCTION: AcpiDbIntegrityWalk
652 * PARAMETERS: Callback from WalkNamespace
656 * DESCRIPTION: Examine one NS node for valid values.
658 ******************************************************************************/
661 AcpiDbIntegrityWalk (
662 ACPI_HANDLE ObjHandle,
667 ACPI_INTEGRITY_INFO *Info = (ACPI_INTEGRITY_INFO *) Context;
668 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
669 ACPI_OPERAND_OBJECT *Object;
670 BOOLEAN Alias = TRUE;
675 /* Verify the NS node, and dereference aliases */
679 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
681 AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s] - is %2.2X should be %2.2X\n",
682 Node, AcpiUtGetDescriptorName (Node), ACPI_GET_DESCRIPTOR_TYPE (Node),
683 ACPI_DESC_TYPE_NAMED);
687 if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS) ||
688 (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
690 Node = (ACPI_NAMESPACE_NODE *) Node->Object;
698 if (Node->Type > ACPI_TYPE_LOCAL_MAX)
700 AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
705 if (!AcpiUtValidAcpiName (Node->Name.Ascii))
707 AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
711 Object = AcpiNsGetAttachedObject (Node);
715 if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
717 AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
718 Object, AcpiUtGetDescriptorName (Object));
726 /*******************************************************************************
728 * FUNCTION: AcpiDbCheckIntegrity
734 * DESCRIPTION: Check entire namespace for data structure integrity
736 ******************************************************************************/
739 AcpiDbCheckIntegrity (
742 ACPI_INTEGRITY_INFO Info = {0,0};
744 /* Search all nodes in namespace */
746 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
747 AcpiDbIntegrityWalk, NULL, (void *) &Info, NULL);
749 AcpiOsPrintf ("Verified %u namespace nodes with %u Objects\n",
750 Info.Nodes, Info.Objects);
754 /*******************************************************************************
756 * FUNCTION: AcpiDbWalkForReferences
758 * PARAMETERS: Callback from WalkNamespace
762 * DESCRIPTION: Check if this namespace object refers to the target object
763 * that is passed in as the context value.
765 * Note: Currently doesn't check subobjects within the Node's object
767 ******************************************************************************/
770 AcpiDbWalkForReferences (
771 ACPI_HANDLE ObjHandle,
776 ACPI_OPERAND_OBJECT *ObjDesc = (ACPI_OPERAND_OBJECT *) Context;
777 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
780 /* Check for match against the namespace node itself */
782 if (Node == (void *) ObjDesc)
784 AcpiOsPrintf ("Object is a Node [%4.4s]\n",
785 AcpiUtGetNodeName (Node));
788 /* Check for match against the object attached to the node */
790 if (AcpiNsGetAttachedObject (Node) == ObjDesc)
792 AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
793 Node, AcpiUtGetNodeName (Node));
800 /*******************************************************************************
802 * FUNCTION: AcpiDbFindReferences
804 * PARAMETERS: ObjectArg - String with hex value of the object
808 * DESCRIPTION: Search namespace for all references to the input object
810 ******************************************************************************/
813 AcpiDbFindReferences (
816 ACPI_OPERAND_OBJECT *ObjDesc;
820 /* Convert string to object pointer */
822 Address = ACPI_STRTOUL (ObjectArg, NULL, 16);
823 ObjDesc = ACPI_TO_POINTER (Address);
825 /* Search all nodes in namespace */
827 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
828 AcpiDbWalkForReferences, NULL, (void *) ObjDesc, NULL);
832 /*******************************************************************************
834 * FUNCTION: AcpiDbBusWalk
836 * PARAMETERS: Callback from WalkNamespace
840 * DESCRIPTION: Display info about device objects that have a corresponding
843 ******************************************************************************/
847 ACPI_HANDLE ObjHandle,
852 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
855 ACPI_NAMESPACE_NODE *TempNode;
856 ACPI_DEVICE_INFO *Info;
860 if ((Node->Type != ACPI_TYPE_DEVICE) &&
861 (Node->Type != ACPI_TYPE_PROCESSOR))
866 /* Exit if there is no _PRT under this device */
868 Status = AcpiGetHandle (Node, METHOD_NAME__PRT,
869 ACPI_CAST_PTR (ACPI_HANDLE, &TempNode));
870 if (ACPI_FAILURE (Status))
875 /* Get the full path to this device object */
877 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
878 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
879 if (ACPI_FAILURE (Status))
881 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
885 Status = AcpiGetObjectInfo (ObjHandle, &Info);
886 if (ACPI_FAILURE (Status))
891 /* Display the full path */
893 AcpiOsPrintf ("%-32s Type %X", (char *) Buffer.Pointer, Node->Type);
894 ACPI_FREE (Buffer.Pointer);
896 if (Info->Flags & ACPI_PCI_ROOT_BRIDGE)
898 AcpiOsPrintf (" - Is PCI Root Bridge");
904 AcpiOsPrintf ("_PRT: %p\n", TempNode);
906 /* Dump _ADR, _HID, _UID, _CID */
908 if (Info->Valid & ACPI_VALID_ADR)
910 AcpiOsPrintf ("_ADR: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Info->Address));
914 AcpiOsPrintf ("_ADR: <Not Present>\n");
917 if (Info->Valid & ACPI_VALID_HID)
919 AcpiOsPrintf ("_HID: %s\n", Info->HardwareId.String);
923 AcpiOsPrintf ("_HID: <Not Present>\n");
926 if (Info->Valid & ACPI_VALID_UID)
928 AcpiOsPrintf ("_UID: %s\n", Info->UniqueId.String);
932 AcpiOsPrintf ("_UID: <Not Present>\n");
935 if (Info->Valid & ACPI_VALID_CID)
937 for (i = 0; i < Info->CompatibleIdList.Count; i++)
939 AcpiOsPrintf ("_CID: %s\n",
940 Info->CompatibleIdList.Ids[i].String);
945 AcpiOsPrintf ("_CID: <Not Present>\n");
953 /*******************************************************************************
955 * FUNCTION: AcpiDbGetBusInfo
961 * DESCRIPTION: Display info about system busses.
963 ******************************************************************************/
969 /* Search all nodes in namespace */
971 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
972 AcpiDbBusWalk, NULL, NULL, NULL);
975 #endif /* ACPI_DEBUGGER */