xref: /freebsd/sys/contrib/dev/acpica/components/debugger/dbnames.c (revision 1c05a6ea6b849ff95e539c31adea887c644a6a01)
1 /*******************************************************************************
2  *
3  * Module Name: dbnames - Debugger commands for the acpi namespace
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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
19  * property rights.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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
64  * make.
65  *
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
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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
88  * PARTICULAR PURPOSE.
89  *
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
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acnamesp.h>
155 #include <contrib/dev/acpica/include/acdebug.h>
156 #include <contrib/dev/acpica/include/acpredef.h>
157 
158 
159 #define _COMPONENT          ACPI_CA_DEBUGGER
160         ACPI_MODULE_NAME    ("dbnames")
161 
162 
163 /* Local prototypes */
164 
165 static ACPI_STATUS
166 AcpiDbWalkAndMatchName (
167     ACPI_HANDLE             ObjHandle,
168     UINT32                  NestingLevel,
169     void                    *Context,
170     void                    **ReturnValue);
171 
172 static ACPI_STATUS
173 AcpiDbWalkForPredefinedNames (
174     ACPI_HANDLE             ObjHandle,
175     UINT32                  NestingLevel,
176     void                    *Context,
177     void                    **ReturnValue);
178 
179 static ACPI_STATUS
180 AcpiDbWalkForSpecificObjects (
181     ACPI_HANDLE             ObjHandle,
182     UINT32                  NestingLevel,
183     void                    *Context,
184     void                    **ReturnValue);
185 
186 static ACPI_STATUS
187 AcpiDbWalkForObjectCounts (
188     ACPI_HANDLE             ObjHandle,
189     UINT32                  NestingLevel,
190     void                    *Context,
191     void                    **ReturnValue);
192 
193 static ACPI_STATUS
194 AcpiDbIntegrityWalk (
195     ACPI_HANDLE             ObjHandle,
196     UINT32                  NestingLevel,
197     void                    *Context,
198     void                    **ReturnValue);
199 
200 static ACPI_STATUS
201 AcpiDbWalkForReferences (
202     ACPI_HANDLE             ObjHandle,
203     UINT32                  NestingLevel,
204     void                    *Context,
205     void                    **ReturnValue);
206 
207 static ACPI_STATUS
208 AcpiDbBusWalk (
209     ACPI_HANDLE             ObjHandle,
210     UINT32                  NestingLevel,
211     void                    *Context,
212     void                    **ReturnValue);
213 
214 /*
215  * Arguments for the Objects command
216  * These object types map directly to the ACPI_TYPES
217  */
218 static ACPI_DB_ARGUMENT_INFO    AcpiDbObjectTypes [] =
219 {
220     {"ANY"},
221     {"INTEGERS"},
222     {"STRINGS"},
223     {"BUFFERS"},
224     {"PACKAGES"},
225     {"FIELDS"},
226     {"DEVICES"},
227     {"EVENTS"},
228     {"METHODS"},
229     {"MUTEXES"},
230     {"REGIONS"},
231     {"POWERRESOURCES"},
232     {"PROCESSORS"},
233     {"THERMALZONES"},
234     {"BUFFERFIELDS"},
235     {"DDBHANDLES"},
236     {"DEBUG"},
237     {"REGIONFIELDS"},
238     {"BANKFIELDS"},
239     {"INDEXFIELDS"},
240     {"REFERENCES"},
241     {"ALIASES"},
242     {"METHODALIASES"},
243     {"NOTIFY"},
244     {"ADDRESSHANDLER"},
245     {"RESOURCE"},
246     {"RESOURCEFIELD"},
247     {"SCOPES"},
248     {NULL}           /* Must be null terminated */
249 };
250 
251 
252 /*******************************************************************************
253  *
254  * FUNCTION:    AcpiDbSetScope
255  *
256  * PARAMETERS:  Name                - New scope path
257  *
258  * RETURN:      Status
259  *
260  * DESCRIPTION: Set the "current scope" as maintained by this utility.
261  *              The scope is used as a prefix to ACPI paths.
262  *
263  ******************************************************************************/
264 
265 void
266 AcpiDbSetScope (
267     char                    *Name)
268 {
269     ACPI_STATUS             Status;
270     ACPI_NAMESPACE_NODE     *Node;
271 
272 
273     if (!Name || Name[0] == 0)
274     {
275         AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
276         return;
277     }
278 
279     AcpiDbPrepNamestring (Name);
280 
281     if (ACPI_IS_ROOT_PREFIX (Name[0]))
282     {
283         /* Validate new scope from the root */
284 
285         Status = AcpiNsGetNode (AcpiGbl_RootNode, Name,
286             ACPI_NS_NO_UPSEARCH, &Node);
287         if (ACPI_FAILURE (Status))
288         {
289             goto ErrorExit;
290         }
291 
292         AcpiGbl_DbScopeBuf[0] = 0;
293     }
294     else
295     {
296         /* Validate new scope relative to old scope */
297 
298         Status = AcpiNsGetNode (AcpiGbl_DbScopeNode, Name,
299             ACPI_NS_NO_UPSEARCH, &Node);
300         if (ACPI_FAILURE (Status))
301         {
302             goto ErrorExit;
303         }
304     }
305 
306     /* Build the final pathname */
307 
308     if (AcpiUtSafeStrcat (AcpiGbl_DbScopeBuf, sizeof (AcpiGbl_DbScopeBuf),
309         Name))
310     {
311         Status = AE_BUFFER_OVERFLOW;
312         goto ErrorExit;
313     }
314 
315     if (AcpiUtSafeStrcat (AcpiGbl_DbScopeBuf, sizeof (AcpiGbl_DbScopeBuf),
316             "\\"))
317     {
318         Status = AE_BUFFER_OVERFLOW;
319         goto ErrorExit;
320     }
321 
322     AcpiGbl_DbScopeNode = Node;
323     AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
324     return;
325 
326 ErrorExit:
327 
328     AcpiOsPrintf ("Could not attach scope: %s, %s\n",
329         Name, AcpiFormatException (Status));
330 }
331 
332 
333 /*******************************************************************************
334  *
335  * FUNCTION:    AcpiDbDumpNamespace
336  *
337  * PARAMETERS:  StartArg        - Node to begin namespace dump
338  *              DepthArg        - Maximum tree depth to be dumped
339  *
340  * RETURN:      None
341  *
342  * DESCRIPTION: Dump entire namespace or a subtree. Each node is displayed
343  *              with type and other information.
344  *
345  ******************************************************************************/
346 
347 void
348 AcpiDbDumpNamespace (
349     char                    *StartArg,
350     char                    *DepthArg)
351 {
352     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
353     UINT32                  MaxDepth = ACPI_UINT32_MAX;
354 
355 
356     /* No argument given, just start at the root and dump entire namespace */
357 
358     if (StartArg)
359     {
360         SubtreeEntry = AcpiDbConvertToNode (StartArg);
361         if (!SubtreeEntry)
362         {
363             return;
364         }
365 
366         /* Now we can check for the depth argument */
367 
368         if (DepthArg)
369         {
370             MaxDepth = strtoul (DepthArg, NULL, 0);
371         }
372     }
373 
374     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
375     AcpiOsPrintf ("ACPI Namespace (from %4.4s (%p) subtree):\n",
376         ((ACPI_NAMESPACE_NODE *) SubtreeEntry)->Name.Ascii, SubtreeEntry);
377 
378     /* Display the subtree */
379 
380     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
381     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
382         ACPI_OWNER_ID_MAX, SubtreeEntry);
383     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
384 }
385 
386 
387 /*******************************************************************************
388  *
389  * FUNCTION:    AcpiDbDumpNamespacePaths
390  *
391  * PARAMETERS:  None
392  *
393  * RETURN:      None
394  *
395  * DESCRIPTION: Dump entire namespace with full object pathnames and object
396  *              type information. Alternative to "namespace" command.
397  *
398  ******************************************************************************/
399 
400 void
401 AcpiDbDumpNamespacePaths (
402     void)
403 {
404 
405     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
406     AcpiOsPrintf ("ACPI Namespace (from root):\n");
407 
408     /* Display the entire namespace */
409 
410     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
411     AcpiNsDumpObjectPaths (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY,
412         ACPI_UINT32_MAX, ACPI_OWNER_ID_MAX, AcpiGbl_RootNode);
413 
414     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
415 }
416 
417 
418 /*******************************************************************************
419  *
420  * FUNCTION:    AcpiDbDumpNamespaceByOwner
421  *
422  * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
423  *              DepthArg        - Maximum tree depth to be dumped
424  *
425  * RETURN:      None
426  *
427  * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
428  *
429  ******************************************************************************/
430 
431 void
432 AcpiDbDumpNamespaceByOwner (
433     char                    *OwnerArg,
434     char                    *DepthArg)
435 {
436     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
437     UINT32                  MaxDepth = ACPI_UINT32_MAX;
438     ACPI_OWNER_ID           OwnerId;
439 
440 
441     OwnerId = (ACPI_OWNER_ID) strtoul (OwnerArg, NULL, 0);
442 
443     /* Now we can check for the depth argument */
444 
445     if (DepthArg)
446     {
447         MaxDepth = strtoul (DepthArg, NULL, 0);
448     }
449 
450     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
451     AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
452 
453     /* Display the subtree */
454 
455     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
456     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth,
457         OwnerId, SubtreeEntry);
458     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
459 }
460 
461 
462 /*******************************************************************************
463  *
464  * FUNCTION:    AcpiDbWalkAndMatchName
465  *
466  * PARAMETERS:  Callback from WalkNamespace
467  *
468  * RETURN:      Status
469  *
470  * DESCRIPTION: Find a particular name/names within the namespace. Wildcards
471  *              are supported -- '?' matches any character.
472  *
473  ******************************************************************************/
474 
475 static ACPI_STATUS
476 AcpiDbWalkAndMatchName (
477     ACPI_HANDLE             ObjHandle,
478     UINT32                  NestingLevel,
479     void                    *Context,
480     void                    **ReturnValue)
481 {
482     ACPI_STATUS             Status;
483     char                    *RequestedName = (char *) Context;
484     UINT32                  i;
485     ACPI_BUFFER             Buffer;
486     ACPI_WALK_INFO          Info;
487 
488 
489     /* Check for a name match */
490 
491     for (i = 0; i < 4; i++)
492     {
493         /* Wildcard support */
494 
495         if ((RequestedName[i] != '?') &&
496             (RequestedName[i] != ((ACPI_NAMESPACE_NODE *)
497                 ObjHandle)->Name.Ascii[i]))
498         {
499             /* No match, just exit */
500 
501             return (AE_OK);
502         }
503     }
504 
505     /* Get the full pathname to this object */
506 
507     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
508     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer, TRUE);
509     if (ACPI_FAILURE (Status))
510     {
511         AcpiOsPrintf ("Could Not get pathname for object %p\n",
512             ObjHandle);
513     }
514     else
515     {
516         Info.OwnerId = ACPI_OWNER_ID_MAX;
517         Info.DebugLevel = ACPI_UINT32_MAX;
518         Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
519 
520         AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
521         (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, &Info, NULL);
522         ACPI_FREE (Buffer.Pointer);
523     }
524 
525     return (AE_OK);
526 }
527 
528 
529 /*******************************************************************************
530  *
531  * FUNCTION:    AcpiDbFindNameInNamespace
532  *
533  * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
534  *                                wildcards are supported.
535  *
536  * RETURN:      None
537  *
538  * DESCRIPTION: Search the namespace for a given name (with wildcards)
539  *
540  ******************************************************************************/
541 
542 ACPI_STATUS
543 AcpiDbFindNameInNamespace (
544     char                    *NameArg)
545 {
546     char                    AcpiName[5] = "____";
547     char                    *AcpiNamePtr = AcpiName;
548 
549 
550     if (strlen (NameArg) > ACPI_NAME_SIZE)
551     {
552         AcpiOsPrintf ("Name must be no longer than 4 characters\n");
553         return (AE_OK);
554     }
555 
556     /* Pad out name with underscores as necessary to create a 4-char name */
557 
558     AcpiUtStrupr (NameArg);
559     while (*NameArg)
560     {
561         *AcpiNamePtr = *NameArg;
562         AcpiNamePtr++;
563         NameArg++;
564     }
565 
566     /* Walk the namespace from the root */
567 
568     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
569         ACPI_UINT32_MAX, AcpiDbWalkAndMatchName, NULL, AcpiName, NULL);
570 
571     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
572     return (AE_OK);
573 }
574 
575 
576 /*******************************************************************************
577  *
578  * FUNCTION:    AcpiDbWalkForPredefinedNames
579  *
580  * PARAMETERS:  Callback from WalkNamespace
581  *
582  * RETURN:      Status
583  *
584  * DESCRIPTION: Detect and display predefined ACPI names (names that start with
585  *              an underscore)
586  *
587  ******************************************************************************/
588 
589 static ACPI_STATUS
590 AcpiDbWalkForPredefinedNames (
591     ACPI_HANDLE             ObjHandle,
592     UINT32                  NestingLevel,
593     void                    *Context,
594     void                    **ReturnValue)
595 {
596     ACPI_NAMESPACE_NODE         *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
597     UINT32                      *Count = (UINT32 *) Context;
598     const ACPI_PREDEFINED_INFO  *Predefined;
599     const ACPI_PREDEFINED_INFO  *Package = NULL;
600     char                        *Pathname;
601     char                        StringBuffer[48];
602 
603 
604     Predefined = AcpiUtMatchPredefinedMethod (Node->Name.Ascii);
605     if (!Predefined)
606     {
607         return (AE_OK);
608     }
609 
610     Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
611     if (!Pathname)
612     {
613         return (AE_OK);
614     }
615 
616     /* If method returns a package, the info is in the next table entry */
617 
618     if (Predefined->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
619     {
620         Package = Predefined + 1;
621     }
622 
623     AcpiUtGetExpectedReturnTypes (StringBuffer,
624         Predefined->Info.ExpectedBtypes);
625 
626     AcpiOsPrintf ("%-32s Arguments %X, Return Types: %s", Pathname,
627         METHOD_GET_ARG_COUNT (Predefined->Info.ArgumentList),
628         StringBuffer);
629 
630     if (Package)
631     {
632         AcpiOsPrintf (" (PkgType %2.2X, ObjType %2.2X, Count %2.2X)",
633             Package->RetInfo.Type, Package->RetInfo.ObjectType1,
634             Package->RetInfo.Count1);
635     }
636 
637     AcpiOsPrintf("\n");
638 
639     /* Check that the declared argument count matches the ACPI spec */
640 
641     AcpiNsCheckAcpiCompliance (Pathname, Node, Predefined);
642 
643     ACPI_FREE (Pathname);
644     (*Count)++;
645     return (AE_OK);
646 }
647 
648 
649 /*******************************************************************************
650  *
651  * FUNCTION:    AcpiDbCheckPredefinedNames
652  *
653  * PARAMETERS:  None
654  *
655  * RETURN:      None
656  *
657  * DESCRIPTION: Validate all predefined names in the namespace
658  *
659  ******************************************************************************/
660 
661 void
662 AcpiDbCheckPredefinedNames (
663     void)
664 {
665     UINT32                  Count = 0;
666 
667 
668     /* Search all nodes in namespace */
669 
670     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
671         ACPI_UINT32_MAX, AcpiDbWalkForPredefinedNames,
672         NULL, (void *) &Count, NULL);
673 
674     AcpiOsPrintf ("Found %u predefined names in the namespace\n", Count);
675 }
676 
677 
678 /*******************************************************************************
679  *
680  * FUNCTION:    AcpiDbWalkForObjectCounts
681  *
682  * PARAMETERS:  Callback from WalkNamespace
683  *
684  * RETURN:      Status
685  *
686  * DESCRIPTION: Display short info about objects in the namespace
687  *
688  ******************************************************************************/
689 
690 static ACPI_STATUS
691 AcpiDbWalkForObjectCounts (
692     ACPI_HANDLE             ObjHandle,
693     UINT32                  NestingLevel,
694     void                    *Context,
695     void                    **ReturnValue)
696 {
697     ACPI_OBJECT_INFO        *Info = (ACPI_OBJECT_INFO *) Context;
698     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
699 
700 
701     if (Node->Type > ACPI_TYPE_NS_NODE_MAX)
702     {
703         AcpiOsPrintf ("[%4.4s]: Unknown object type %X\n",
704             Node->Name.Ascii, Node->Type);
705     }
706     else
707     {
708         Info->Types[Node->Type]++;
709     }
710 
711     return (AE_OK);
712 }
713 
714 
715 /*******************************************************************************
716  *
717  * FUNCTION:    AcpiDbWalkForSpecificObjects
718  *
719  * PARAMETERS:  Callback from WalkNamespace
720  *
721  * RETURN:      Status
722  *
723  * DESCRIPTION: Display short info about objects in the namespace
724  *
725  ******************************************************************************/
726 
727 static ACPI_STATUS
728 AcpiDbWalkForSpecificObjects (
729     ACPI_HANDLE             ObjHandle,
730     UINT32                  NestingLevel,
731     void                    *Context,
732     void                    **ReturnValue)
733 {
734     ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
735     ACPI_BUFFER             Buffer;
736     ACPI_STATUS             Status;
737 
738 
739     Info->Count++;
740 
741     /* Get and display the full pathname to this object */
742 
743     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
744     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer, TRUE);
745     if (ACPI_FAILURE (Status))
746     {
747         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
748         return (AE_OK);
749     }
750 
751     AcpiOsPrintf ("%32s", (char *) Buffer.Pointer);
752     ACPI_FREE (Buffer.Pointer);
753 
754     /* Dump short info about the object */
755 
756     (void) AcpiNsDumpOneObject (ObjHandle, NestingLevel, Info, NULL);
757     return (AE_OK);
758 }
759 
760 
761 /*******************************************************************************
762  *
763  * FUNCTION:    AcpiDbDisplayObjects
764  *
765  * PARAMETERS:  ObjTypeArg          - Type of object to display
766  *              DisplayCountArg     - Max depth to display
767  *
768  * RETURN:      None
769  *
770  * DESCRIPTION: Display objects in the namespace of the requested type
771  *
772  ******************************************************************************/
773 
774 ACPI_STATUS
775 AcpiDbDisplayObjects (
776     char                    *ObjTypeArg,
777     char                    *DisplayCountArg)
778 {
779     ACPI_WALK_INFO          Info;
780     ACPI_OBJECT_TYPE        Type;
781     ACPI_OBJECT_INFO        *ObjectInfo;
782     UINT32                  i;
783     UINT32                  TotalObjects = 0;
784 
785 
786     /* No argument means display summary/count of all object types */
787 
788     if (!ObjTypeArg)
789     {
790         ObjectInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_OBJECT_INFO));
791 
792         /* Walk the namespace from the root */
793 
794         (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
795             ACPI_UINT32_MAX, AcpiDbWalkForObjectCounts, NULL,
796             (void *) ObjectInfo, NULL);
797 
798         AcpiOsPrintf ("\nSummary of namespace objects:\n\n");
799 
800         for (i = 0; i < ACPI_TOTAL_TYPES; i++)
801         {
802             AcpiOsPrintf ("%8u   %s\n", ObjectInfo->Types[i],
803                 AcpiUtGetTypeName (i));
804 
805             TotalObjects += ObjectInfo->Types[i];
806         }
807 
808         AcpiOsPrintf ("\n%8u   Total namespace objects\n\n",
809             TotalObjects);
810 
811         ACPI_FREE (ObjectInfo);
812         return (AE_OK);
813     }
814 
815     /* Get the object type */
816 
817     Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
818     if (Type == ACPI_TYPE_NOT_FOUND)
819     {
820         AcpiOsPrintf ("Invalid or unsupported argument\n");
821         return (AE_OK);
822     }
823 
824     AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
825     AcpiOsPrintf (
826         "Objects of type [%s] defined in the current ACPI Namespace:\n",
827         AcpiUtGetTypeName (Type));
828 
829     AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
830 
831     Info.Count = 0;
832     Info.OwnerId = ACPI_OWNER_ID_MAX;
833     Info.DebugLevel = ACPI_UINT32_MAX;
834     Info.DisplayType = ACPI_DISPLAY_SUMMARY | ACPI_DISPLAY_SHORT;
835 
836     /* Walk the namespace from the root */
837 
838     (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
839         AcpiDbWalkForSpecificObjects, NULL, (void *) &Info, NULL);
840 
841     AcpiOsPrintf (
842         "\nFound %u objects of type [%s] in the current ACPI Namespace\n",
843         Info.Count, AcpiUtGetTypeName (Type));
844 
845     AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
846     return (AE_OK);
847 }
848 
849 
850 /*******************************************************************************
851  *
852  * FUNCTION:    AcpiDbIntegrityWalk
853  *
854  * PARAMETERS:  Callback from WalkNamespace
855  *
856  * RETURN:      Status
857  *
858  * DESCRIPTION: Examine one NS node for valid values.
859  *
860  ******************************************************************************/
861 
862 static ACPI_STATUS
863 AcpiDbIntegrityWalk (
864     ACPI_HANDLE             ObjHandle,
865     UINT32                  NestingLevel,
866     void                    *Context,
867     void                    **ReturnValue)
868 {
869     ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
870     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
871     ACPI_OPERAND_OBJECT     *Object;
872     BOOLEAN                 Alias = TRUE;
873 
874 
875     Info->Nodes++;
876 
877     /* Verify the NS node, and dereference aliases */
878 
879     while (Alias)
880     {
881         if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
882         {
883             AcpiOsPrintf (
884                 "Invalid Descriptor Type for Node %p [%s] - "
885                 "is %2.2X should be %2.2X\n",
886                 Node, AcpiUtGetDescriptorName (Node),
887                 ACPI_GET_DESCRIPTOR_TYPE (Node), ACPI_DESC_TYPE_NAMED);
888             return (AE_OK);
889         }
890 
891         if ((Node->Type == ACPI_TYPE_LOCAL_ALIAS)  ||
892             (Node->Type == ACPI_TYPE_LOCAL_METHOD_ALIAS))
893         {
894             Node = (ACPI_NAMESPACE_NODE *) Node->Object;
895         }
896         else
897         {
898             Alias = FALSE;
899         }
900     }
901 
902     if (Node->Type > ACPI_TYPE_LOCAL_MAX)
903     {
904         AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
905             Node, Node->Type);
906         return (AE_OK);
907     }
908 
909     if (!AcpiUtValidNameseg (Node->Name.Ascii))
910     {
911         AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
912         return (AE_OK);
913     }
914 
915     Object = AcpiNsGetAttachedObject (Node);
916     if (Object)
917     {
918         Info->Objects++;
919         if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
920         {
921             AcpiOsPrintf ("Invalid Descriptor Type for Object %p [%s]\n",
922                 Object, AcpiUtGetDescriptorName (Object));
923         }
924     }
925 
926     return (AE_OK);
927 }
928 
929 
930 /*******************************************************************************
931  *
932  * FUNCTION:    AcpiDbCheckIntegrity
933  *
934  * PARAMETERS:  None
935  *
936  * RETURN:      None
937  *
938  * DESCRIPTION: Check entire namespace for data structure integrity
939  *
940  ******************************************************************************/
941 
942 void
943 AcpiDbCheckIntegrity (
944     void)
945 {
946     ACPI_INTEGRITY_INFO     Info = {0,0};
947 
948     /* Search all nodes in namespace */
949 
950     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
951         ACPI_UINT32_MAX, AcpiDbIntegrityWalk, NULL, (void *) &Info, NULL);
952 
953     AcpiOsPrintf ("Verified %u namespace nodes with %u Objects\n",
954         Info.Nodes, Info.Objects);
955 }
956 
957 
958 /*******************************************************************************
959  *
960  * FUNCTION:    AcpiDbWalkForReferences
961  *
962  * PARAMETERS:  Callback from WalkNamespace
963  *
964  * RETURN:      Status
965  *
966  * DESCRIPTION: Check if this namespace object refers to the target object
967  *              that is passed in as the context value.
968  *
969  * Note: Currently doesn't check subobjects within the Node's object
970  *
971  ******************************************************************************/
972 
973 static ACPI_STATUS
974 AcpiDbWalkForReferences (
975     ACPI_HANDLE             ObjHandle,
976     UINT32                  NestingLevel,
977     void                    *Context,
978     void                    **ReturnValue)
979 {
980     ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
981     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
982 
983 
984     /* Check for match against the namespace node itself */
985 
986     if (Node == (void *) ObjDesc)
987     {
988         AcpiOsPrintf ("Object is a Node [%4.4s]\n",
989             AcpiUtGetNodeName (Node));
990     }
991 
992     /* Check for match against the object attached to the node */
993 
994     if (AcpiNsGetAttachedObject (Node) == ObjDesc)
995     {
996         AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n",
997             Node, AcpiUtGetNodeName (Node));
998     }
999 
1000     return (AE_OK);
1001 }
1002 
1003 
1004 /*******************************************************************************
1005  *
1006  * FUNCTION:    AcpiDbFindReferences
1007  *
1008  * PARAMETERS:  ObjectArg       - String with hex value of the object
1009  *
1010  * RETURN:      None
1011  *
1012  * DESCRIPTION: Search namespace for all references to the input object
1013  *
1014  ******************************************************************************/
1015 
1016 void
1017 AcpiDbFindReferences (
1018     char                    *ObjectArg)
1019 {
1020     ACPI_OPERAND_OBJECT     *ObjDesc;
1021     ACPI_SIZE               Address;
1022 
1023 
1024     /* Convert string to object pointer */
1025 
1026     Address = strtoul (ObjectArg, NULL, 16);
1027     ObjDesc = ACPI_TO_POINTER (Address);
1028 
1029     /* Search all nodes in namespace */
1030 
1031     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
1032         ACPI_UINT32_MAX, AcpiDbWalkForReferences, NULL,
1033         (void *) ObjDesc, NULL);
1034 }
1035 
1036 
1037 /*******************************************************************************
1038  *
1039  * FUNCTION:    AcpiDbBusWalk
1040  *
1041  * PARAMETERS:  Callback from WalkNamespace
1042  *
1043  * RETURN:      Status
1044  *
1045  * DESCRIPTION: Display info about device objects that have a corresponding
1046  *              _PRT method.
1047  *
1048  ******************************************************************************/
1049 
1050 static ACPI_STATUS
1051 AcpiDbBusWalk (
1052     ACPI_HANDLE             ObjHandle,
1053     UINT32                  NestingLevel,
1054     void                    *Context,
1055     void                    **ReturnValue)
1056 {
1057     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1058     ACPI_STATUS             Status;
1059     ACPI_BUFFER             Buffer;
1060     ACPI_NAMESPACE_NODE     *TempNode;
1061     ACPI_DEVICE_INFO        *Info;
1062     UINT32                  i;
1063 
1064 
1065     if ((Node->Type != ACPI_TYPE_DEVICE) &&
1066         (Node->Type != ACPI_TYPE_PROCESSOR))
1067     {
1068         return (AE_OK);
1069     }
1070 
1071     /* Exit if there is no _PRT under this device */
1072 
1073     Status = AcpiGetHandle (Node, METHOD_NAME__PRT,
1074         ACPI_CAST_PTR (ACPI_HANDLE, &TempNode));
1075     if (ACPI_FAILURE (Status))
1076     {
1077         return (AE_OK);
1078     }
1079 
1080     /* Get the full path to this device object */
1081 
1082     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
1083     Status = AcpiNsHandleToPathname (ObjHandle, &Buffer, TRUE);
1084     if (ACPI_FAILURE (Status))
1085     {
1086         AcpiOsPrintf ("Could Not get pathname for object %p\n",
1087             ObjHandle);
1088         return (AE_OK);
1089     }
1090 
1091     Status = AcpiGetObjectInfo (ObjHandle, &Info);
1092     if (ACPI_FAILURE (Status))
1093     {
1094         return (AE_OK);
1095     }
1096 
1097     /* Display the full path */
1098 
1099     AcpiOsPrintf ("%-32s Type %X", (char *) Buffer.Pointer, Node->Type);
1100     ACPI_FREE (Buffer.Pointer);
1101 
1102     if (Info->Flags & ACPI_PCI_ROOT_BRIDGE)
1103     {
1104         AcpiOsPrintf ("  - Is PCI Root Bridge");
1105     }
1106     AcpiOsPrintf ("\n");
1107 
1108     /* _PRT info */
1109 
1110     AcpiOsPrintf ("_PRT: %p\n", TempNode);
1111 
1112     /* Dump _ADR, _HID, _UID, _CID */
1113 
1114     if (Info->Valid & ACPI_VALID_ADR)
1115     {
1116         AcpiOsPrintf ("_ADR: %8.8X%8.8X\n",
1117             ACPI_FORMAT_UINT64 (Info->Address));
1118     }
1119     else
1120     {
1121         AcpiOsPrintf ("_ADR: <Not Present>\n");
1122     }
1123 
1124     if (Info->Valid & ACPI_VALID_HID)
1125     {
1126         AcpiOsPrintf ("_HID: %s\n", Info->HardwareId.String);
1127     }
1128     else
1129     {
1130         AcpiOsPrintf ("_HID: <Not Present>\n");
1131     }
1132 
1133     if (Info->Valid & ACPI_VALID_UID)
1134     {
1135         AcpiOsPrintf ("_UID: %s\n", Info->UniqueId.String);
1136     }
1137     else
1138     {
1139         AcpiOsPrintf ("_UID: <Not Present>\n");
1140     }
1141 
1142     if (Info->Valid & ACPI_VALID_CID)
1143     {
1144         for (i = 0; i < Info->CompatibleIdList.Count; i++)
1145         {
1146             AcpiOsPrintf ("_CID: %s\n",
1147                 Info->CompatibleIdList.Ids[i].String);
1148         }
1149     }
1150     else
1151     {
1152         AcpiOsPrintf ("_CID: <Not Present>\n");
1153     }
1154 
1155     ACPI_FREE (Info);
1156     return (AE_OK);
1157 }
1158 
1159 
1160 /*******************************************************************************
1161  *
1162  * FUNCTION:    AcpiDbGetBusInfo
1163  *
1164  * PARAMETERS:  None
1165  *
1166  * RETURN:      None
1167  *
1168  * DESCRIPTION: Display info about system busses.
1169  *
1170  ******************************************************************************/
1171 
1172 void
1173 AcpiDbGetBusInfo (
1174     void)
1175 {
1176     /* Search all nodes in namespace */
1177 
1178     (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
1179         ACPI_UINT32_MAX, AcpiDbBusWalk, NULL, NULL, NULL);
1180 }
1181