1 /******************************************************************************
3 * Module Name: nsdump - table dumping routines for debug
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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/acoutput.h>
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsdump")
55 /* Local prototypes */
57 #ifdef ACPI_OBSOLETE_FUNCTIONS
59 AcpiNsDumpRootDevices (
64 ACPI_HANDLE ObjHandle,
71 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
74 AcpiNsDumpOneObjectPath (
75 ACPI_HANDLE ObjHandle,
82 ACPI_HANDLE ObjHandle,
88 /*******************************************************************************
90 * FUNCTION: AcpiNsPrintPathname
92 * PARAMETERS: NumSegments - Number of ACPI name segments
93 * Pathname - The compressed (internal) path
97 * DESCRIPTION: Print an object's full namespace pathname
99 ******************************************************************************/
102 AcpiNsPrintPathname (
109 ACPI_FUNCTION_NAME (NsPrintPathname);
112 /* Check if debug output enabled */
114 if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_NAMES, ACPI_NAMESPACE))
119 /* Print the entire name */
121 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
125 for (i = 0; i < 4; i++)
127 ACPI_IS_PRINT (Pathname[i]) ?
128 AcpiOsPrintf ("%c", Pathname[i]) :
132 Pathname += ACPI_NAME_SIZE;
140 AcpiOsPrintf ("]\n");
144 /*******************************************************************************
146 * FUNCTION: AcpiNsDumpPathname
148 * PARAMETERS: Handle - Object
149 * Msg - Prefix message
150 * Level - Desired debug level
151 * Component - Caller's component ID
155 * DESCRIPTION: Print an object's full namespace pathname
156 * Manages allocation/freeing of a pathname buffer
158 ******************************************************************************/
168 ACPI_FUNCTION_TRACE (NsDumpPathname);
171 /* Do this only if the requested debug level and component are enabled */
173 if (!ACPI_IS_DEBUG_ENABLED (Level, Component))
178 /* Convert handle to a full pathname and print it (with supplied message) */
180 AcpiNsPrintNodePathname (Handle, Msg);
186 /*******************************************************************************
188 * FUNCTION: AcpiNsDumpOneObject
190 * PARAMETERS: ObjHandle - Node to be dumped
191 * Level - Nesting level of the handle
192 * Context - Passed into WalkNamespace
193 * ReturnValue - Not used
197 * DESCRIPTION: Dump a single Node
198 * This procedure is a UserFunction called by AcpiNsWalkNamespace.
200 ******************************************************************************/
203 AcpiNsDumpOneObject (
204 ACPI_HANDLE ObjHandle,
209 ACPI_WALK_INFO *Info = (ACPI_WALK_INFO *) Context;
210 ACPI_NAMESPACE_NODE *ThisNode;
211 ACPI_OPERAND_OBJECT *ObjDesc = NULL;
212 ACPI_OBJECT_TYPE ObjType;
213 ACPI_OBJECT_TYPE Type;
219 ACPI_FUNCTION_NAME (NsDumpOneObject);
222 /* Is output enabled? */
224 if (!(AcpiDbgLevel & Info->DebugLevel))
231 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
235 ThisNode = AcpiNsValidateHandle (ObjHandle);
238 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Invalid object handle %p\n",
243 Type = ThisNode->Type;
245 /* Check if the owner matches */
247 if ((Info->OwnerId != ACPI_OWNER_ID_MAX) &&
248 (Info->OwnerId != ThisNode->OwnerId))
253 if (!(Info->DisplayType & ACPI_DISPLAY_SHORT))
255 /* Indent the object according to the level */
257 AcpiOsPrintf ("%2d%*s", (UINT32) Level - 1, (int) Level * 2, " ");
259 /* Check the node type and name */
261 if (Type > ACPI_TYPE_LOCAL_MAX)
263 ACPI_WARNING ((AE_INFO, "Invalid ACPI Object Type 0x%08X", Type));
266 AcpiOsPrintf ("%4.4s", AcpiUtGetNodeName (ThisNode));
269 /* Now we can print out the pertinent information */
271 AcpiOsPrintf (" %-12s %p %2.2X ",
272 AcpiUtGetTypeName (Type), ThisNode, ThisNode->OwnerId);
274 DbgLevel = AcpiDbgLevel;
276 ObjDesc = AcpiNsGetAttachedObject (ThisNode);
277 AcpiDbgLevel = DbgLevel;
279 /* Temp nodes are those nodes created by a control method */
281 if (ThisNode->Flags & ANOBJ_TEMPORARY)
283 AcpiOsPrintf ("(T) ");
286 switch (Info->DisplayType & ACPI_DISPLAY_MASK)
288 case ACPI_DISPLAY_SUMMARY:
292 /* No attached object. Some types should always have an object */
296 case ACPI_TYPE_INTEGER:
297 case ACPI_TYPE_PACKAGE:
298 case ACPI_TYPE_BUFFER:
299 case ACPI_TYPE_STRING:
300 case ACPI_TYPE_METHOD:
302 AcpiOsPrintf ("<No attached object>");
316 case ACPI_TYPE_PROCESSOR:
318 AcpiOsPrintf ("ID %02X Len %02X Addr %p\n",
319 ObjDesc->Processor.ProcId, ObjDesc->Processor.Length,
320 ACPI_CAST_PTR (void, ObjDesc->Processor.Address));
323 case ACPI_TYPE_DEVICE:
325 AcpiOsPrintf ("Notify Object: %p\n", ObjDesc);
328 case ACPI_TYPE_METHOD:
330 AcpiOsPrintf ("Args %X Len %.4X Aml %p\n",
331 (UINT32) ObjDesc->Method.ParamCount,
332 ObjDesc->Method.AmlLength, ObjDesc->Method.AmlStart);
335 case ACPI_TYPE_INTEGER:
337 AcpiOsPrintf ("= %8.8X%8.8X\n",
338 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
341 case ACPI_TYPE_PACKAGE:
343 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
345 AcpiOsPrintf ("Elements %.2X\n",
346 ObjDesc->Package.Count);
350 AcpiOsPrintf ("[Length not yet evaluated]\n");
354 case ACPI_TYPE_BUFFER:
356 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
358 AcpiOsPrintf ("Len %.2X",
359 ObjDesc->Buffer.Length);
361 /* Dump some of the buffer */
363 if (ObjDesc->Buffer.Length > 0)
366 for (i = 0; (i < ObjDesc->Buffer.Length && i < 12); i++)
368 AcpiOsPrintf (" %.2hX", ObjDesc->Buffer.Pointer[i]);
375 AcpiOsPrintf ("[Length not yet evaluated]\n");
379 case ACPI_TYPE_STRING:
381 AcpiOsPrintf ("Len %.2X ", ObjDesc->String.Length);
382 AcpiUtPrintString (ObjDesc->String.Pointer, 32);
386 case ACPI_TYPE_REGION:
388 AcpiOsPrintf ("[%s]",
389 AcpiUtGetRegionName (ObjDesc->Region.SpaceId));
390 if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
392 AcpiOsPrintf (" Addr %8.8X%8.8X Len %.4X\n",
393 ACPI_FORMAT_NATIVE_UINT (ObjDesc->Region.Address),
394 ObjDesc->Region.Length);
398 AcpiOsPrintf (" [Address/Length not yet evaluated]\n");
402 case ACPI_TYPE_LOCAL_REFERENCE:
404 AcpiOsPrintf ("[%s]\n", AcpiUtGetReferenceName (ObjDesc));
407 case ACPI_TYPE_BUFFER_FIELD:
409 if (ObjDesc->BufferField.BufferObj &&
410 ObjDesc->BufferField.BufferObj->Buffer.Node)
412 AcpiOsPrintf ("Buf [%4.4s]",
414 ObjDesc->BufferField.BufferObj->Buffer.Node));
418 case ACPI_TYPE_LOCAL_REGION_FIELD:
420 AcpiOsPrintf ("Rgn [%4.4s]",
422 ObjDesc->CommonField.RegionObj->Region.Node));
425 case ACPI_TYPE_LOCAL_BANK_FIELD:
427 AcpiOsPrintf ("Rgn [%4.4s] Bnk [%4.4s]",
429 ObjDesc->CommonField.RegionObj->Region.Node),
431 ObjDesc->BankField.BankObj->CommonField.Node));
434 case ACPI_TYPE_LOCAL_INDEX_FIELD:
436 AcpiOsPrintf ("Idx [%4.4s] Dat [%4.4s]",
438 ObjDesc->IndexField.IndexObj->CommonField.Node),
440 ObjDesc->IndexField.DataObj->CommonField.Node));
443 case ACPI_TYPE_LOCAL_ALIAS:
444 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
446 AcpiOsPrintf ("Target %4.4s (%p)\n",
447 AcpiUtGetNodeName (ObjDesc), ObjDesc);
452 AcpiOsPrintf ("Object %p\n", ObjDesc);
456 /* Common field handling */
460 case ACPI_TYPE_BUFFER_FIELD:
461 case ACPI_TYPE_LOCAL_REGION_FIELD:
462 case ACPI_TYPE_LOCAL_BANK_FIELD:
463 case ACPI_TYPE_LOCAL_INDEX_FIELD:
465 AcpiOsPrintf (" Off %.3X Len %.2X Acc %.2hd\n",
466 (ObjDesc->CommonField.BaseByteOffset * 8)
467 + ObjDesc->CommonField.StartFieldBitOffset,
468 ObjDesc->CommonField.BitLength,
469 ObjDesc->CommonField.AccessByteWidth);
478 case ACPI_DISPLAY_OBJECTS:
480 AcpiOsPrintf ("O:%p", ObjDesc);
483 /* No attached object, we are done */
489 AcpiOsPrintf ("(R%u)", ObjDesc->Common.ReferenceCount);
493 case ACPI_TYPE_METHOD:
495 /* Name is a Method and its AML offset/length are set */
497 AcpiOsPrintf (" M:%p-%X\n", ObjDesc->Method.AmlStart,
498 ObjDesc->Method.AmlLength);
501 case ACPI_TYPE_INTEGER:
503 AcpiOsPrintf (" I:%8.8X8.8%X\n",
504 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
507 case ACPI_TYPE_STRING:
509 AcpiOsPrintf (" S:%p-%X\n", ObjDesc->String.Pointer,
510 ObjDesc->String.Length);
513 case ACPI_TYPE_BUFFER:
515 AcpiOsPrintf (" B:%p-%X\n", ObjDesc->Buffer.Pointer,
516 ObjDesc->Buffer.Length);
531 /* If debug turned off, done */
533 if (!(AcpiDbgLevel & ACPI_LV_VALUES))
538 /* If there is an attached object, display it */
540 DbgLevel = AcpiDbgLevel;
542 ObjDesc = AcpiNsGetAttachedObject (ThisNode);
543 AcpiDbgLevel = DbgLevel;
545 /* Dump attached objects */
549 ObjType = ACPI_TYPE_INVALID;
550 AcpiOsPrintf ("Attached Object %p: ", ObjDesc);
552 /* Decode the type of attached object and dump the contents */
554 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
556 case ACPI_DESC_TYPE_NAMED:
558 AcpiOsPrintf ("(Ptr to Node)\n");
559 BytesToDump = sizeof (ACPI_NAMESPACE_NODE);
560 ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
563 case ACPI_DESC_TYPE_OPERAND:
565 ObjType = ObjDesc->Common.Type;
567 if (ObjType > ACPI_TYPE_LOCAL_MAX)
569 AcpiOsPrintf ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
575 AcpiOsPrintf ("(Pointer to ACPI Object type %.2X [%s])\n",
576 ObjType, AcpiUtGetTypeName (ObjType));
577 BytesToDump = sizeof (ACPI_OPERAND_OBJECT);
580 ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
588 /* If value is NOT an internal object, we are done */
590 if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
595 /* Valid object, get the pointer to next level, if any */
599 case ACPI_TYPE_BUFFER:
600 case ACPI_TYPE_STRING:
602 * NOTE: takes advantage of common fields between string/buffer
604 BytesToDump = ObjDesc->String.Length;
605 ObjDesc = (void *) ObjDesc->String.Pointer;
606 AcpiOsPrintf ( "(Buffer/String pointer %p length %X)\n",
607 ObjDesc, BytesToDump);
608 ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
611 case ACPI_TYPE_BUFFER_FIELD:
613 ObjDesc = (ACPI_OPERAND_OBJECT *) ObjDesc->BufferField.BufferObj;
616 case ACPI_TYPE_PACKAGE:
618 ObjDesc = (void *) ObjDesc->Package.Elements;
621 case ACPI_TYPE_METHOD:
623 ObjDesc = (void *) ObjDesc->Method.AmlStart;
626 case ACPI_TYPE_LOCAL_REGION_FIELD:
628 ObjDesc = (void *) ObjDesc->Field.RegionObj;
631 case ACPI_TYPE_LOCAL_BANK_FIELD:
633 ObjDesc = (void *) ObjDesc->BankField.RegionObj;
636 case ACPI_TYPE_LOCAL_INDEX_FIELD:
638 ObjDesc = (void *) ObjDesc->IndexField.IndexObj;
646 ObjType = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
655 /*******************************************************************************
657 * FUNCTION: AcpiNsDumpObjects
659 * PARAMETERS: Type - Object type to be dumped
660 * DisplayType - 0 or ACPI_DISPLAY_SUMMARY
661 * MaxDepth - Maximum depth of dump. Use ACPI_UINT32_MAX
662 * for an effectively unlimited depth.
663 * OwnerId - Dump only objects owned by this ID. Use
664 * ACPI_UINT32_MAX to match all owners.
665 * StartHandle - Where in namespace to start/end search
669 * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
670 * AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObject.
672 ******************************************************************************/
676 ACPI_OBJECT_TYPE Type,
679 ACPI_OWNER_ID OwnerId,
680 ACPI_HANDLE StartHandle)
686 ACPI_FUNCTION_ENTRY ();
690 * Just lock the entire namespace for the duration of the dump.
691 * We don't want any changes to the namespace during this time,
692 * especially the temporary nodes since we are going to display
695 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
696 if (ACPI_FAILURE (Status))
698 AcpiOsPrintf ("Could not acquire namespace mutex\n");
702 Info.DebugLevel = ACPI_LV_TABLES;
703 Info.OwnerId = OwnerId;
704 Info.DisplayType = DisplayType;
706 (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
707 ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
708 AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
710 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
714 /*******************************************************************************
716 * FUNCTION: AcpiNsDumpOneObjectPath, AcpiNsGetMaxDepth
718 * PARAMETERS: ObjHandle - Node to be dumped
719 * Level - Nesting level of the handle
720 * Context - Passed into WalkNamespace
721 * ReturnValue - Not used
725 * DESCRIPTION: Dump the full pathname to a namespace object. AcpNsGetMaxDepth
726 * computes the maximum nesting depth in the namespace tree, in
727 * order to simplify formatting in AcpiNsDumpOneObjectPath.
728 * These procedures are UserFunctions called by AcpiNsWalkNamespace.
730 ******************************************************************************/
733 AcpiNsDumpOneObjectPath (
734 ACPI_HANDLE ObjHandle,
739 UINT32 MaxLevel = *((UINT32 *) Context);
741 ACPI_NAMESPACE_NODE *Node;
750 Node = AcpiNsValidateHandle (ObjHandle);
751 Pathname = AcpiNsGetExternalPathname (Node);
754 if (Level <= MaxLevel)
756 PathIndent = MaxLevel - Level + 1;
759 AcpiOsPrintf ("%2d%*s%-12s%*s",
760 Level, Level, " ", AcpiUtGetTypeName (Node->Type),
763 AcpiOsPrintf ("%s\n", &Pathname[1]);
764 ACPI_FREE (Pathname);
771 ACPI_HANDLE ObjHandle,
776 UINT32 *MaxLevel = (UINT32 *) Context;
779 if (Level > *MaxLevel)
787 /*******************************************************************************
789 * FUNCTION: AcpiNsDumpObjectPaths
791 * PARAMETERS: Type - Object type to be dumped
792 * DisplayType - 0 or ACPI_DISPLAY_SUMMARY
793 * MaxDepth - Maximum depth of dump. Use ACPI_UINT32_MAX
794 * for an effectively unlimited depth.
795 * OwnerId - Dump only objects owned by this ID. Use
796 * ACPI_UINT32_MAX to match all owners.
797 * StartHandle - Where in namespace to start/end search
801 * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
802 * AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObjectPath.
804 ******************************************************************************/
807 AcpiNsDumpObjectPaths (
808 ACPI_OBJECT_TYPE Type,
811 ACPI_OWNER_ID OwnerId,
812 ACPI_HANDLE StartHandle)
818 ACPI_FUNCTION_ENTRY ();
822 * Just lock the entire namespace for the duration of the dump.
823 * We don't want any changes to the namespace during this time,
824 * especially the temporary nodes since we are going to display
827 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
828 if (ACPI_FAILURE (Status))
830 AcpiOsPrintf ("Could not acquire namespace mutex\n");
834 /* Get the max depth of the namespace tree, for formatting later */
836 (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
837 ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
838 AcpiNsGetMaxDepth, NULL, (void *) &MaxLevel, NULL);
840 /* Now dump the entire namespace */
842 (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
843 ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
844 AcpiNsDumpOneObjectPath, NULL, (void *) &MaxLevel, NULL);
846 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
850 /*******************************************************************************
852 * FUNCTION: AcpiNsDumpEntry
854 * PARAMETERS: Handle - Node to be dumped
855 * DebugLevel - Output level
859 * DESCRIPTION: Dump a single Node
861 ******************************************************************************/
871 ACPI_FUNCTION_ENTRY ();
874 Info.DebugLevel = DebugLevel;
875 Info.OwnerId = ACPI_OWNER_ID_MAX;
876 Info.DisplayType = ACPI_DISPLAY_SUMMARY;
878 (void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
882 #ifdef ACPI_ASL_COMPILER
883 /*******************************************************************************
885 * FUNCTION: AcpiNsDumpTables
887 * PARAMETERS: SearchBase - Root of subtree to be dumped, or
888 * NS_ALL to dump the entire namespace
889 * MaxDepth - Maximum depth of dump. Use INT_MAX
890 * for an effectively unlimited depth.
894 * DESCRIPTION: Dump the name space, or a portion of it.
896 ******************************************************************************/
900 ACPI_HANDLE SearchBase,
903 ACPI_HANDLE SearchHandle = SearchBase;
906 ACPI_FUNCTION_TRACE (NsDumpTables);
909 if (!AcpiGbl_RootNode)
912 * If the name space has not been initialized,
913 * there is nothing to dump.
915 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "namespace not initialized!\n"));
919 if (ACPI_NS_ALL == SearchBase)
921 /* Entire namespace */
923 SearchHandle = AcpiGbl_RootNode;
924 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
927 AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
928 ACPI_OWNER_ID_MAX, SearchHandle);