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