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