1 /*******************************************************************************
3 * Module Name: dbnames - Debugger commands for the acpi namespace
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, 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>
53 #define _COMPONENT ACPI_CA_DEBUGGER
54 ACPI_MODULE_NAME ("dbnames")
57 /* Local prototypes */
60 AcpiDbWalkAndMatchName (
61 ACPI_HANDLE ObjHandle,
67 AcpiDbWalkForPredefinedNames (
68 ACPI_HANDLE ObjHandle,
74 AcpiDbWalkForSpecificObjects (
75 ACPI_HANDLE ObjHandle,
82 ACPI_HANDLE ObjHandle,
88 AcpiDbWalkForReferences (
89 ACPI_HANDLE ObjHandle,
96 ACPI_HANDLE ObjHandle,
102 * Arguments for the Objects command
103 * These object types map directly to the ACPI_TYPES
105 static ARGUMENT_INFO AcpiDbObjectTypes [] =
129 {NULL} /* Must be null terminated */
133 /*******************************************************************************
135 * FUNCTION: AcpiDbSetScope
137 * PARAMETERS: Name - New scope path
141 * DESCRIPTION: Set the "current scope" as maintained by this utility.
142 * The scope is used as a prefix to ACPI paths.
144 ******************************************************************************/
151 ACPI_NAMESPACE_NODE *Node;
154 if (!Name || Name[0] == 0)
156 AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
160 AcpiDbPrepNamestring (Name);
164 /* Validate new scope from the root */
166 Status = AcpiNsGetNode (AcpiGbl_RootNode, Name, ACPI_NS_NO_UPSEARCH,
168 if (ACPI_FAILURE (Status))
173 ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
174 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
178 /* Validate new scope relative to old scope */
180 Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name, ACPI_NS_NO_UPSEARCH,
182 if (ACPI_FAILURE (Status))
187 ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
188 ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
191 AcpiGbl_DbScopeNode = Node;
192 AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
197 AcpiOsPrintf ("Could not attach scope: %s, %s\n",
198 Name, AcpiFormatException (Status));
202 /*******************************************************************************
204 * FUNCTION: AcpiDbDumpNamespace
206 * PARAMETERS: StartArg - Node to begin namespace dump
207 * DepthArg - Maximum tree depth to be dumped
211 * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
212 * with type and other information.
214 ******************************************************************************/
217 AcpiDbDumpNamespace (
221 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
222 UINT32 MaxDepth = ACPI_UINT32_MAX;
225 /* No argument given, just start at the root and dump entire namespace */
229 SubtreeEntry = AcpiDbConvertToNode (StartArg);
235 /* Now we can check for the depth argument */
239 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
243 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
244 AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
245 ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
247 /* Display the subtree */
249 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
250 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
251 ACPI_OWNER_ID_MAX, SubtreeEntry);
252 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
256 /*******************************************************************************
258 * FUNCTION: AcpiDbDumpNamespaceByOwner
260 * PARAMETERS: OwnerArg - Owner ID whose nodes will be displayed
261 * DepthArg - Maximum tree depth to be dumped
265 * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
267 ******************************************************************************/
270 AcpiDbDumpNamespaceByOwner (
274 ACPI_HANDLE SubtreeEntry = AcpiGbl_RootNode;
275 UINT32 MaxDepth = ACPI_UINT32_MAX;
276 ACPI_OWNER_ID OwnerId;
279 OwnerId = (ACPI_OWNER_ID) ACPI_STRTOUL (OwnerArg, NULL, 0);
281 /* Now we can check for the depth argument */
285 MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
288 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
289 AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
291 /* Display the subtree */
293 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
294 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId,
296 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
300 /*******************************************************************************
302 * FUNCTION: AcpiDbWalkAndMatchName
304 * PARAMETERS: Callback from WalkNamespace
308 * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
309 * are supported -- '?' matches any character.
311 ******************************************************************************/
314 AcpiDbWalkAndMatchName (
315 ACPI_HANDLE ObjHandle,
321 char *RequestedName = (char *) Context;
327 /* Check for a name match */
329 for (i = 0; i < 4; i++)
331 /* Wildcard support */
333 if ((RequestedName[i] != '?') &&
334 (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
336 /* No match, just exit */
342 /* Get the full pathname to this object */
344 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
345 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
346 if (ACPI_FAILURE (Status))
348 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
352 Info.OwnerId = ACPI_OWNER_ID_MAX;
353 Info.DebugLevel = ACPI_UINT32_MAX;
354 Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
356 AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
357 (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
358 ACPI_FREE (Buffer.Pointer);
365 /*******************************************************************************
367 * FUNCTION: AcpiDbFindNameInNamespace
369 * PARAMETERS: NameArg - The 4-character ACPI name to find.
370 * wildcards are supported.
374 * DESCRIPTION: Search the namespace for a given name (with wildcards)
376 ******************************************************************************/
379 AcpiDbFindNameInNamespace (
382 char AcpiName[5] = "____";
383 char *AcpiNamePtr = AcpiName;
386 if (ACPI_STRLEN (NameArg) > 4)
388 AcpiOsPrintf ("Name must be no longer than 4 characters\n");
392 /* Pad out name with underscores as necessary to create a 4-char name */
394 AcpiUtStrupr (NameArg);
397 *AcpiNamePtr = *NameArg;
402 /* Walk the namespace from the root */
404 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
405 AcpiDbWalkAndMatchName, NULL, AcpiName, NULL);
407 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
412 /*******************************************************************************
414 * FUNCTION: AcpiDbWalkForPredefinedNames
416 * PARAMETERS: Callback from WalkNamespace
420 * DESCRIPTION: Detect and display predefined ACPI names (names that start with
423 ******************************************************************************/
426 AcpiDbWalkForPredefinedNames (
427 ACPI_HANDLE ObjHandle,
432 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
433 UINT32 *Count = (UINT32 *) Context;
434 const ACPI_PREDEFINED_INFO *Predefined;
435 const ACPI_PREDEFINED_INFO *Package = NULL;
439 Predefined = AcpiNsCheckForPredefinedName (Node);
445 Pathname = AcpiNsGetExternalPathname (Node);
451 /* If method returns a package, the info is in the next table entry */
453 if (Predefined->Info.ExpectedBtypes & ACPI_BTYPE_PACKAGE)
455 Package = Predefined + 1;
458 AcpiOsPrintf ("%-32s arg %X ret %2.2X", Pathname,
459 Predefined->Info.ParamCount, Predefined->Info.ExpectedBtypes);
463 AcpiOsPrintf (" PkgType %2.2X ObjType %2.2X Count %2.2X",
464 Package->RetInfo.Type, Package->RetInfo.ObjectType1,
465 Package->RetInfo.Count1);
470 AcpiNsCheckParameterCount (Pathname, Node, ACPI_UINT32_MAX, Predefined);
471 ACPI_FREE (Pathname);
478 /*******************************************************************************
480 * FUNCTION: AcpiDbCheckPredefinedNames
486 * DESCRIPTION: Validate all predefined names in the namespace
488 ******************************************************************************/
491 AcpiDbCheckPredefinedNames (
497 /* Search all nodes in namespace */
499 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
500 AcpiDbWalkForPredefinedNames, NULL, (void *) &Count, NULL);
502 AcpiOsPrintf ("Found %u predefined names in the namespace\n", Count);
506 /*******************************************************************************
508 * FUNCTION: AcpiDbWalkForSpecificObjects
510 * PARAMETERS: Callback from WalkNamespace
514 * DESCRIPTION: Display short info about objects in the namespace
516 ******************************************************************************/
519 AcpiDbWalkForSpecificObjects (
520 ACPI_HANDLE ObjHandle,
525 ACPI_WALK_INFO *Info = (ACPI_WALK_INFO *) Context;
532 /* Get and display the full pathname to this object */
534 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
535 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
536 if (ACPI_FAILURE (Status))
538 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
542 AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
543 ACPI_FREE (Buffer.Pointer);
545 /* Dump short info about the object */
547 (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
552 /*******************************************************************************
554 * FUNCTION: AcpiDbDisplayObjects
556 * PARAMETERS: ObjTypeArg - Type of object to display
557 * DisplayCountArg - Max depth to display
561 * DESCRIPTION: Display objects in the namespace of the requested type
563 ******************************************************************************/
566 AcpiDbDisplayObjects (
568 char *DisplayCountArg)
571 ACPI_OBJECT_TYPE Type;
574 /* Get the object type */
576 Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
577 if (Type == ACPI_TYPE_NOT_FOUND)
579 AcpiOsPrintf ("Invalid or unsupported argument\n");
583 AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
585 "Objects of type [%s] defined in the current ACPI Namespace:\n",
586 AcpiUtGetTypeName (Type));
588 AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
591 Info.OwnerId = ACPI_OWNER_ID_MAX;
592 Info.DebugLevel = ACPI_UINT32_MAX;
593 Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
595 /* Walk the namespace from the root */
597 (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
598 AcpiDbWalkForSpecificObjects, NULL, (void *) &Info, NULL);
601 "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
602 Info.Count, AcpiUtGetTypeName (Type));
604 AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
609 /*******************************************************************************
611 * FUNCTION: AcpiDbIntegrityWalk
613 * PARAMETERS: Callback from WalkNamespace
617 * DESCRIPTION: Examine one NS node for valid values.
619 ******************************************************************************/
622 AcpiDbIntegrityWalk (
623 ACPI_HANDLE ObjHandle,
628 ACPI_INTEGRITY_INFO *Info = (ACPI_INTEGRITY_INFO *) Context;
629 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
630 ACPI_OPERAND_OBJECT *Object;
631 BOOLEAN Alias = TRUE;
636 /* Verify the NS node, and dereference aliases */
640 if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
642 AcpiOsPrintf ("Invalid Descriptor Type for Node %p [%s] - is %2.2X should be %2.2X\n",
643 Node, AcpiUtGetDescriptorName (Node), ACPI_GET_DESCRIPTOR_TYPE (Node),
644 ACPI_DESC_TYPE_NAMED);
648 if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS) ||
649 (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
651 Node = (ACPI_NAMESPACE_NODE *) Node->Object;
659 if (Node->Type > ACPI_TYPE_LOCAL_MAX)
661 AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
666 if (!AcpiUtValidAcpiName (Node->Name.Integer))
668 AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
672 Object = AcpiNsGetAttachedObject (Node);
676 if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
678 AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
679 Object, AcpiUtGetDescriptorName (Object));
687 /*******************************************************************************
689 * FUNCTION: AcpiDbCheckIntegrity
695 * DESCRIPTION: Check entire namespace for data structure integrity
697 ******************************************************************************/
700 AcpiDbCheckIntegrity (
703 ACPI_INTEGRITY_INFO Info = {0,0};
705 /* Search all nodes in namespace */
707 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
708 AcpiDbIntegrityWalk, NULL, (void *) &Info, NULL);
710 AcpiOsPrintf ("Verified %u namespace nodes with %u Objects\n",
711 Info.Nodes, Info.Objects);
715 /*******************************************************************************
717 * FUNCTION: AcpiDbWalkForReferences
719 * PARAMETERS: Callback from WalkNamespace
723 * DESCRIPTION: Check if this namespace object refers to the target object
724 * that is passed in as the context value.
726 * Note: Currently doesn't check subobjects within the Node's object
728 ******************************************************************************/
731 AcpiDbWalkForReferences (
732 ACPI_HANDLE ObjHandle,
737 ACPI_OPERAND_OBJECT *ObjDesc = (ACPI_OPERAND_OBJECT *) Context;
738 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
741 /* Check for match against the namespace node itself */
743 if (Node == (void *) ObjDesc)
745 AcpiOsPrintf ("Object is a Node [%4.4s]\n",
746 AcpiUtGetNodeName (Node));
749 /* Check for match against the object attached to the node */
751 if (AcpiNsGetAttachedObject (Node) == ObjDesc)
753 AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
754 Node, AcpiUtGetNodeName (Node));
761 /*******************************************************************************
763 * FUNCTION: AcpiDbFindReferences
765 * PARAMETERS: ObjectArg - String with hex value of the object
769 * DESCRIPTION: Search namespace for all references to the input object
771 ******************************************************************************/
774 AcpiDbFindReferences (
777 ACPI_OPERAND_OBJECT *ObjDesc;
780 /* Convert string to object pointer */
782 ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
784 /* Search all nodes in namespace */
786 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
787 AcpiDbWalkForReferences, NULL, (void *) ObjDesc, NULL);
791 /*******************************************************************************
793 * FUNCTION: AcpiDbBusWalk
795 * PARAMETERS: Callback from WalkNamespace
799 * DESCRIPTION: Display info about device objects that have a corresponding
802 ******************************************************************************/
806 ACPI_HANDLE ObjHandle,
811 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
814 ACPI_NAMESPACE_NODE *TempNode;
815 ACPI_DEVICE_INFO *Info;
819 if ((Node->Type != ACPI_TYPE_DEVICE) &&
820 (Node->Type != ACPI_TYPE_PROCESSOR))
825 /* Exit if there is no _PRT under this device */
827 Status = AcpiGetHandle (Node, METHOD_NAME__PRT,
828 ACPI_CAST_PTR (ACPI_HANDLE, &TempNode));
829 if (ACPI_FAILURE (Status))
834 /* Get the full path to this device object */
836 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
837 Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
838 if (ACPI_FAILURE (Status))
840 AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
844 Status = AcpiGetObjectInfo (ObjHandle, &Info);
845 if (ACPI_FAILURE (Status))
850 /* Display the full path */
852 AcpiOsPrintf ("%-32s Type %X", (char *) Buffer.Pointer, Node->Type);
853 ACPI_FREE (Buffer.Pointer);
855 if (Info->Flags & ACPI_PCI_ROOT_BRIDGE)
857 AcpiOsPrintf (" - Is PCI Root Bridge");
863 AcpiOsPrintf ("_PRT: %p\n", TempNode);
865 /* Dump _ADR, _HID, _UID, _CID */
867 if (Info->Valid & ACPI_VALID_ADR)
869 AcpiOsPrintf ("_ADR: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Info->Address));
873 AcpiOsPrintf ("_ADR: <Not Present>\n");
876 if (Info->Valid & ACPI_VALID_HID)
878 AcpiOsPrintf ("_HID: %s\n", Info->HardwareId.String);
882 AcpiOsPrintf ("_HID: <Not Present>\n");
885 if (Info->Valid & ACPI_VALID_UID)
887 AcpiOsPrintf ("_UID: %s\n", Info->UniqueId.String);
891 AcpiOsPrintf ("_UID: <Not Present>\n");
894 if (Info->Valid & ACPI_VALID_CID)
896 for (i = 0; i < Info->CompatibleIdList.Count; i++)
898 AcpiOsPrintf ("_CID: %s\n",
899 Info->CompatibleIdList.Ids[i].String);
904 AcpiOsPrintf ("_CID: <Not Present>\n");
912 /*******************************************************************************
914 * FUNCTION: AcpiDbGetBusInfo
920 * DESCRIPTION: Display info about system busses.
922 ******************************************************************************/
928 /* Search all nodes in namespace */
930 (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
931 AcpiDbBusWalk, NULL, NULL, NULL);
934 #endif /* ACPI_DEBUGGER */