]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/Subsystem/Debugger/dbcmds.c
Vendor import of Intel ACPI-CA 20041119 with system includes fixups.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / Subsystem / Debugger / dbcmds.c
1 /*******************************************************************************
2  *
3  * Module Name: dbcmds - debug commands and output routines
4  *              $Revision: 46 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117
118 #include "acpi.h"
119 #include "acparser.h"
120 #include "acdispat.h"
121 #include "amlcode.h"
122 #include "acnamesp.h"
123 #include "acparser.h"
124 #include "acevents.h"
125 #include "acinterp.h"
126 #include "acdebug.h"
127 #include "actables.h"
128
129 #ifdef ENABLE_DEBUGGER
130
131 #define _COMPONENT          DEBUGGER
132         MODULE_NAME         ("dbcmds")
133
134
135 /*
136  * Arguments for the Objects command
137  * These object types map directly to the ACPI_TYPES
138  */
139
140 ARGUMENT_INFO               AcpiDbObjectTypes [] =
141 {
142     {"ANY"},
143     {"NUMBERS"},
144     {"STRINGS"},
145     {"BUFFERS"},
146     {"PACKAGES"},
147     {"FIELDS"},
148     {"DEVICES"},
149     {"EVENTS"},
150     {"METHODS"},
151     {"MUTEXES"},
152     {"REGIONS"},
153     {"POWERRESOURCES"},
154     {"PROCESSORS"},
155     {"THERMALZONES"},
156     {"BUFFERFIELDS"},
157     {"DDBHANDLES"},
158     {NULL}           /* Must be null terminated */
159 };
160
161
162 /*******************************************************************************
163  *
164  * FUNCTION:    AcpiDbWalkForReferences
165  *
166  * PARAMETERS:  Callback from WalkNamespace
167  *
168  * RETURN:      Status
169  *
170  * DESCRIPTION: Check if this namespace object refers to the target object
171  *              that is passed in as the context value.
172  *
173  ******************************************************************************/
174
175 ACPI_STATUS
176 AcpiDbWalkForReferences (
177     ACPI_HANDLE             ObjHandle,
178     UINT32                  NestingLevel,
179     void                    *Context,
180     void                    **ReturnValue)
181 {
182     ACPI_OPERAND_OBJECT     *ObjDesc = (ACPI_OPERAND_OBJECT  *) Context;
183     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
184
185
186     /* Check for match against the namespace node itself */
187
188     if (Node == (void *) ObjDesc)
189     {
190         AcpiOsPrintf ("Object is a Node [%4.4s]\n", &Node->Name);
191     }
192
193     /* Check for match against the object attached to the node */
194
195     if (Node->Object == ObjDesc)
196     {
197         AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n", Node, &Node->Name);
198     }
199
200     /* Check first child for a match */
201     /* TBD: [Investigate] probably now obsolete with new datastructure */
202
203     if (Node->Child == (void *) ObjDesc)
204     {
205         AcpiOsPrintf ("Reference at Node->Child %p [%4.4s]\n", Node, &Node->Name);
206     }
207
208     return (AE_OK);
209 }
210
211
212 /*******************************************************************************
213  *
214  * FUNCTION:    AcpiDbFindReferences
215  *
216  * PARAMETERS:  ObjectArg       - String with hex value of the object
217  *
218  * RETURN:      None
219  *
220  * DESCRIPTION: Search namespace for all references to the input object
221  *
222  ******************************************************************************/
223
224 void
225 AcpiDbFindReferences (
226     NATIVE_CHAR             *ObjectArg)
227 {
228     ACPI_OPERAND_OBJECT     *ObjDesc;
229
230
231     /* Convert string to object pointer */
232
233     ObjDesc = (ACPI_OPERAND_OBJECT  *) STRTOUL (ObjectArg, NULL, 16);
234
235     /* Search all nodes in namespace */
236
237     AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
238                     AcpiDbWalkForReferences, (void *) ObjDesc, NULL);
239 }
240
241
242 /*******************************************************************************
243  *
244  * FUNCTION:    AcpiDbDisplayTableInfo
245  *
246  * PARAMETERS:  TableArg        - String with name of table to be displayed
247  *
248  * RETURN:      None
249  *
250  * DESCRIPTION: Display information about loaded tables.  Current
251  *              implementation displays all loaded tables.
252  *
253  ******************************************************************************/
254
255 void
256 AcpiDbDisplayTableInfo (
257     NATIVE_CHAR             *TableArg)
258 {
259     UINT32                  i;
260
261
262     for (i = 0; i < NUM_ACPI_TABLES; i++)
263     {
264         if (AcpiGbl_AcpiTables[i].Pointer)
265         {
266             AcpiOsPrintf ("%s at %p length %X\n", AcpiGbl_AcpiTableData[i].Name,
267                         AcpiGbl_AcpiTables[i].Pointer, AcpiGbl_AcpiTables[i].Length);
268         }
269     }
270 }
271
272
273 /*******************************************************************************
274  *
275  * FUNCTION:    AcpiDbUnloadAcpiTable
276  *
277  * PARAMETERS:  TableArg        - Name of the table to be unloaded
278  *              InstanceArg     - Which instance of the table to unload (if
279  *                                there are multiple tables of the same type)
280  *
281  * RETURN:      Nonde
282  *
283  * DESCRIPTION: Unload an ACPI table.
284  *              Instance is not implemented
285  *
286  ******************************************************************************/
287
288 void
289 AcpiDbUnloadAcpiTable (
290     NATIVE_CHAR             *TableArg,
291     NATIVE_CHAR             *InstanceArg)
292 {
293     UINT32                  i;
294     ACPI_STATUS             Status;
295
296
297     /* Search all tables for the target type */
298
299     for (i = 0; i < NUM_ACPI_TABLES; i++)
300     {
301         if (!STRNCMP (TableArg, AcpiGbl_AcpiTableData[i].Signature, AcpiGbl_AcpiTableData[i].SigLength))
302         {
303             /* Found the table, unload it */
304
305             Status = AcpiUnloadTable (i);
306             if (ACPI_SUCCESS (Status))
307             {
308                 AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
309             }
310             else
311             {
312                 AcpiOsPrintf ("%s, while unloading [%s]\n", AcpiCmFormatException (Status), TableArg);
313             }
314
315             return;
316         }
317     }
318
319     AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
320 }
321
322
323 /*******************************************************************************
324  *
325  * FUNCTION:    AcpiDbSetMethodBreakpoint
326  *
327  * PARAMETERS:  Location            - AML offset of breakpoint
328  *              WalkState           - Current walk info
329  *              Op                  - Current Op (from parse walk)
330  *
331  * RETURN:      None
332  *
333  * DESCRIPTION: Set a breakpoint in a control method at the specified
334  *              AML offset
335  *
336  ******************************************************************************/
337
338 void
339 AcpiDbSetMethodBreakpoint (
340     NATIVE_CHAR             *Location,
341     ACPI_WALK_STATE         *WalkState,
342     ACPI_PARSE_OBJECT       *Op)
343 {
344     UINT32                  Address;
345
346
347     if (!Op)
348     {
349         AcpiOsPrintf ("There is no method currently executing\n");
350         return;
351     }
352
353     /* Get and verify the breakpoint address */
354
355     Address = STRTOUL (Location, NULL, 16);
356     if (Address <= Op->AmlOffset)
357     {
358         AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n", Address, Op->AmlOffset);
359     }
360
361     /* Save breakpoint in current walk */
362
363     WalkState->MethodBreakpoint = Address;
364     AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
365 }
366
367
368 /*******************************************************************************
369  *
370  * FUNCTION:    AcpiDbSetMethodCallBreakpoint
371  *
372  * PARAMETERS:  Op                  - Current Op (from parse walk)
373  *
374  * RETURN:      None
375  *
376  * DESCRIPTION: Set a breakpoint in a control method at the specified
377  *              AML offset
378  *
379  ******************************************************************************/
380
381 void
382 AcpiDbSetMethodCallBreakpoint (
383     ACPI_PARSE_OBJECT       *Op)
384 {
385
386
387     if (!Op)
388     {
389         AcpiOsPrintf ("There is no method currently executing\n");
390         return;
391     }
392
393
394     AcpiGbl_StepToNextCall = TRUE;
395 }
396
397
398 /*******************************************************************************
399  *
400  * FUNCTION:    AcpiDbDisassembleAml
401  *
402  * PARAMETERS:  Statements          - Number of statements to disassemble
403  *              Op                  - Current Op (from parse walk)
404  *
405  * RETURN:      None
406  *
407  * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
408  *              of statements specified.
409  *
410  ******************************************************************************/
411
412 void
413 AcpiDbDisassembleAml (
414     NATIVE_CHAR             *Statements,
415     ACPI_PARSE_OBJECT       *Op)
416 {
417     UINT32                  NumStatements = 8;
418
419
420     if (!Op)
421     {
422         AcpiOsPrintf ("There is no method currently executing\n");
423         return;
424     }
425
426     if (Statements)
427     {
428         NumStatements = STRTOUL (Statements, NULL, 0);
429     }
430
431
432     AcpiDbDisplayOp (NULL, Op, NumStatements);
433 }
434
435
436 /*******************************************************************************
437  *
438  * FUNCTION:    AcpiDbDumpNamespace
439  *
440  * PARAMETERS:  StartArg        - Node to begin namespace dump
441  *              DepthArg        - Maximum tree depth to be dumped
442  *
443  * RETURN:      None
444  *
445  * DESCRIPTION: Dump entire namespace or a subtree.  Each node is displayed
446  *              with type and other information.
447  *
448  ******************************************************************************/
449
450 void
451 AcpiDbDumpNamespace (
452     NATIVE_CHAR             *StartArg,
453     NATIVE_CHAR             *DepthArg)
454 {
455     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
456     UINT32                  MaxDepth = ACPI_UINT32_MAX;
457
458
459     /* No argument given, just start at the root and dump entire namespace */
460
461     if (StartArg)
462     {
463         /* Check if numeric argument, must be a Node */
464
465         if ((StartArg[0] >= 0x30) && (StartArg[0] <= 0x39))
466         {
467             SubtreeEntry = (ACPI_HANDLE) STRTOUL (StartArg, NULL, 16);
468             if (!AcpiOsReadable (SubtreeEntry, sizeof (ACPI_NAMESPACE_NODE)))
469             {
470                 AcpiOsPrintf ("Address %p is invalid in this address space\n", SubtreeEntry);
471                 return;
472             }
473
474             if (!VALID_DESCRIPTOR_TYPE ((SubtreeEntry), ACPI_DESC_TYPE_NAMED))
475             {
476                 AcpiOsPrintf ("Address %p is not a valid Named object\n", SubtreeEntry);
477                 return;
478             }
479         }
480
481         /* Alpha argument */
482
483         else
484         {
485             /* The parameter is a name string that must be resolved to a Named obj*/
486
487             SubtreeEntry = AcpiDbLocalNsLookup (StartArg);
488             if (!SubtreeEntry)
489             {
490                 SubtreeEntry = AcpiGbl_RootNode;
491             }
492         }
493
494         /* Now we can check for the depth argument */
495
496         if (DepthArg)
497         {
498             MaxDepth = STRTOUL (DepthArg, NULL, 0);
499         }
500     }
501
502
503     AcpiDbSetOutputDestination (DB_DUPLICATE_OUTPUT);
504     AcpiOsPrintf ("ACPI Namespace (from %p subtree):\n", SubtreeEntry);
505
506     /* Display the subtree */
507
508     AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT);
509     AcpiNsDumpObjects (ACPI_TYPE_ANY, MaxDepth, ACPI_UINT32_MAX, SubtreeEntry);
510     AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT);
511 }
512
513
514 /*******************************************************************************
515  *
516  * FUNCTION:    AcpiDbDumpNamespaceByOwner
517  *
518  * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
519  *              DepthArg        - Maximum tree depth to be dumped
520  *
521  * RETURN:      None
522  *
523  * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
524  *
525  ******************************************************************************/
526
527 void
528 AcpiDbDumpNamespaceByOwner (
529     NATIVE_CHAR             *OwnerArg,
530     NATIVE_CHAR             *DepthArg)
531 {
532     ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
533     UINT32                  MaxDepth = ACPI_UINT32_MAX;
534     UINT16                  OwnerId;
535
536
537     OwnerId = (UINT16) STRTOUL (OwnerArg, NULL, 0);
538
539
540     /* Now we can check for the depth argument */
541
542     if (DepthArg)
543     {
544         MaxDepth = STRTOUL (DepthArg, NULL, 0);
545     }
546
547
548     AcpiDbSetOutputDestination (DB_DUPLICATE_OUTPUT);
549     AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
550
551     /* Display the subtree */
552
553     AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT);
554     AcpiNsDumpObjects (ACPI_TYPE_ANY, MaxDepth, OwnerId, SubtreeEntry);
555     AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT);
556 }
557
558
559 /*******************************************************************************
560  *
561  * FUNCTION:    AcpiDbSendNotify
562  *
563  * PARAMETERS:  Name            - Name of ACPI object to send the notify to
564  *              Value           - Value of the notify to send.
565  *
566  * RETURN:      None
567  *
568  * DESCRIPTION: Send an ACPI notification.  The value specified is sent to the
569  *              named object as an ACPI notify.
570  *
571  ******************************************************************************/
572
573 void
574 AcpiDbSendNotify (
575     NATIVE_CHAR             *Name,
576     UINT32                  Value)
577 {
578     ACPI_NAMESPACE_NODE     *Node;
579
580
581     /* Translate name to an Named object */
582
583     Node = AcpiDbLocalNsLookup (Name);
584     if (!Node)
585     {
586         return;
587     }
588
589     /* Decode Named object type */
590
591     switch (Node->Type)
592     {
593     case ACPI_TYPE_DEVICE:
594     case ACPI_TYPE_THERMAL:
595
596          /* Send the notify */
597
598         AcpiEvNotifyDispatch (Node, Value);
599         break;
600
601     default:
602         AcpiOsPrintf ("Named object is not a device or a thermal object\n");
603         break;
604     }
605
606 }
607
608
609 /*******************************************************************************
610  *
611  * FUNCTION:    AcpiDbSetMethodData
612  *
613  * PARAMETERS:  TypeArg         - L for local, A for argument
614  *              IndexArg        - which one
615  *              ValueArg        - Value to set.
616  *
617  * RETURN:      None
618  *
619  * DESCRIPTION: Set a local or argument for the running control method.
620  *              NOTE: only object supported is Number.
621  *
622  ******************************************************************************/
623
624 void
625 AcpiDbSetMethodData (
626     NATIVE_CHAR             *TypeArg,
627     NATIVE_CHAR             *IndexArg,
628     NATIVE_CHAR             *ValueArg)
629 {
630     NATIVE_CHAR             Type;
631     UINT32                  Index;
632     UINT32                  Value;
633     ACPI_WALK_STATE         *WalkState;
634     ACPI_OPERAND_OBJECT     *ObjDesc;
635
636
637     /* Validate TypeArg */
638
639     STRUPR (TypeArg);
640     Type = TypeArg[0];
641     if ((Type != 'L') &&
642         (Type != 'A'))
643     {
644         AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
645         return;
646     }
647
648     /* Get the index and value */
649
650     Index = STRTOUL (IndexArg, NULL, 16);
651     Value = STRTOUL (ValueArg, NULL, 16);
652
653     WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
654     if (!WalkState)
655     {
656         AcpiOsPrintf ("There is no method currently executing\n");
657         return;
658     }
659
660
661     /* Create and initialize the new object */
662
663     ObjDesc = AcpiCmCreateInternalObject (ACPI_TYPE_INTEGER);
664     if (!ObjDesc)
665     {
666         AcpiOsPrintf ("Could not create an internal object\n");
667         return;
668     }
669
670     ObjDesc->Integer.Value = Value;
671
672
673     /* Store the new object into the target */
674
675     switch (Type)
676     {
677     case 'A':
678
679         /* Set a method argument */
680
681         if (Index > MTH_NUM_ARGS)
682         {
683             AcpiOsPrintf ("Arg%d - Invalid argument name\n", Index);
684             return;
685         }
686
687         AcpiDsMethodDataSetValue (MTH_TYPE_ARG, Index, ObjDesc, WalkState);
688         ObjDesc = WalkState->Arguments[Index].Object;
689
690         AcpiOsPrintf ("Arg%d: ", Index);
691         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
692         break;
693
694     case 'L':
695
696         /* Set a method local */
697
698         if (Index > MTH_NUM_LOCALS)
699         {
700             AcpiOsPrintf ("Local%d - Invalid local variable name\n", Index);
701             return;
702         }
703
704         AcpiDsMethodDataSetValue (MTH_TYPE_LOCAL, Index, ObjDesc, WalkState);
705         ObjDesc = WalkState->LocalVariables[Index].Object;
706
707         AcpiOsPrintf ("Local%d: ", Index);
708         AcpiDbDisplayInternalObject (ObjDesc, WalkState);
709         break;
710
711     default:
712         break;
713     }
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 ACPI_STATUS
730 AcpiDbWalkForSpecificObjects (
731     ACPI_HANDLE             ObjHandle,
732     UINT32                  NestingLevel,
733     void                    *Context,
734     void                    **ReturnValue)
735 {
736     ACPI_OPERAND_OBJECT     *ObjDesc;
737     ACPI_STATUS             Status;
738     UINT32                  BufSize;
739     NATIVE_CHAR             Buffer[64];
740
741
742     ObjDesc = ((ACPI_NAMESPACE_NODE *)ObjHandle)->Object;
743     BufSize = sizeof (Buffer) / sizeof (*Buffer);
744
745     /* Get and display the full pathname to this object */
746
747     Status = AcpiNsHandleToPathname (ObjHandle, &BufSize, Buffer);
748
749     if (ACPI_FAILURE (Status))
750     {
751         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
752         return (AE_OK);
753     }
754
755     AcpiOsPrintf ("%32s", Buffer);
756
757
758     /* Display short information about the object */
759
760     if (ObjDesc)
761     {
762         switch (ObjDesc->Common.Type)
763         {
764         case ACPI_TYPE_METHOD:
765             AcpiOsPrintf ("  #Args %d  Concurrency %X", ObjDesc->Method.ParamCount, ObjDesc->Method.Concurrency);
766             break;
767
768         case ACPI_TYPE_INTEGER:
769             AcpiOsPrintf ("  Value %X", ObjDesc->Integer.Value);
770             break;
771
772         case ACPI_TYPE_STRING:
773             AcpiOsPrintf ("  \"%s\"", ObjDesc->String.Pointer);
774             break;
775
776         case ACPI_TYPE_REGION:
777             AcpiOsPrintf ("  SpaceId %X Address %X Length %X", ObjDesc->Region.SpaceId, ObjDesc->Region.Address, ObjDesc->Region.Length);
778             break;
779
780         case ACPI_TYPE_PACKAGE:
781             AcpiOsPrintf ("  #Elements %X", ObjDesc->Package.Count);
782             break;
783
784         case ACPI_TYPE_BUFFER:
785             AcpiOsPrintf ("  Length %X", ObjDesc->Buffer.Length);
786             break;
787         }
788     }
789
790     AcpiOsPrintf ("\n");
791     return (AE_OK);
792 }
793
794
795 /*******************************************************************************
796  *
797  * FUNCTION:    AcpiDbDisplayObjects
798  *
799  * PARAMETERS:  ObjTypeArg          - Type of object to display
800  *              DisplayCountArg     - Max depth to display
801  *
802  * RETURN:      None
803  *
804  * DESCRIPTION: Display objects in the namespace of the requested type
805  *
806  ******************************************************************************/
807
808 ACPI_STATUS
809 AcpiDbDisplayObjects (
810     NATIVE_CHAR             *ObjTypeArg,
811     NATIVE_CHAR             *DisplayCountArg)
812 {
813     UINT32                  DisplayCount;
814     OBJECT_TYPE_INTERNAL    Type;
815
816
817     /* Get the object type */
818
819     STRUPR (ObjTypeArg);
820     Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
821     if (Type == ACPI_TYPE_NOT_FOUND)
822     {
823         AcpiOsPrintf ("Invalid or unsupported argument\n");
824         return (AE_OK);
825     }
826
827     /* Get the display depth */
828
829     if (DisplayCountArg)
830     {
831         DisplayCount = STRTOUL (DisplayCountArg, NULL, 0);
832     }
833
834     else
835     {
836         DisplayCount = ACPI_UINT32_MAX;
837     }
838
839     AcpiDbSetOutputDestination (DB_DUPLICATE_OUTPUT);
840     AcpiOsPrintf ("Objects of type [%s] defined in the current ACPI Namespace: \n", AcpiCmGetTypeName (Type));
841
842     AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT);
843
844     /* Walk the namespace from the root */
845
846     AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
847                         AcpiDbWalkForSpecificObjects, (void *) &Type, NULL);
848
849     AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT);
850     return (AE_OK);
851 }
852
853
854 /*******************************************************************************
855  *
856  * FUNCTION:    AcpiDbWalkAndMatchName
857  *
858  * PARAMETERS:  Callback from WalkNamespace
859  *
860  * RETURN:      Status
861  *
862  * DESCRIPTION: Find a particular name/names within the namespace.  Wildcards
863  *              are supported -- '?' matches any character.
864  *
865  ******************************************************************************/
866
867 ACPI_STATUS
868 AcpiDbWalkAndMatchName (
869     ACPI_HANDLE             ObjHandle,
870     UINT32                  NestingLevel,
871     void                    *Context,
872     void                    **ReturnValue)
873 {
874     ACPI_OPERAND_OBJECT     *ObjDesc;
875     ACPI_STATUS             Status;
876     NATIVE_CHAR             *RequestedName = (NATIVE_CHAR *) Context;
877     UINT32                  i;
878     UINT32                  BufSize;
879     NATIVE_CHAR             Buffer[96];
880
881
882     ObjDesc = ((ACPI_NAMESPACE_NODE *)ObjHandle)->Object;
883
884
885     /* Check for a name match */
886
887     for (i = 0; i < 4; i++)
888     {
889         /* Wildcard support */
890
891         if ((RequestedName[i] != '?') &&
892             (RequestedName[i] != ((NATIVE_CHAR *) (&((ACPI_NAMESPACE_NODE *) ObjHandle)->Name))[i]))
893         {
894             /* No match, just exit */
895
896             return (AE_OK);
897         }
898     }
899
900
901     /* Get the full pathname to this object */
902
903     BufSize = sizeof (Buffer) / sizeof (*Buffer);
904
905     Status = AcpiNsHandleToPathname (ObjHandle, &BufSize, Buffer);
906     if (ACPI_FAILURE (Status))
907     {
908         AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
909     }
910
911     else
912     {
913         AcpiOsPrintf ("%32s (%p) - %s\n", Buffer, ObjHandle,
914             AcpiCmGetTypeName (((ACPI_NAMESPACE_NODE *) ObjHandle)->Type));
915     }
916
917     return (AE_OK);
918 }
919
920
921 /*******************************************************************************
922  *
923  * FUNCTION:    AcpiDbFindNameInNamespace
924  *
925  * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
926  *                                wildcards are supported.
927  *
928  * RETURN:      None
929  *
930  * DESCRIPTION: Search the namespace for a given name (with wildcards)
931  *
932  ******************************************************************************/
933
934 ACPI_STATUS
935 AcpiDbFindNameInNamespace (
936     NATIVE_CHAR             *NameArg)
937 {
938
939     if (STRLEN (NameArg) > 4)
940     {
941         AcpiOsPrintf ("Name must be no longer than 4 characters\n");
942         return (AE_OK);
943     }
944
945     /* Walk the namespace from the root */
946
947     AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
948                         AcpiDbWalkAndMatchName, NameArg, NULL);
949
950     AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT);
951     return (AE_OK);
952 }
953
954
955 /*******************************************************************************
956  *
957  * FUNCTION:    AcpiDbSetScope
958  *
959  * PARAMETERS:  Name                - New scope path
960  *
961  * RETURN:      Status
962  *
963  * DESCRIPTION: Set the "current scope" as maintained by this utility.
964  *              The scope is used as a prefix to ACPI paths.
965  *
966  ******************************************************************************/
967
968 void
969 AcpiDbSetScope (
970     NATIVE_CHAR             *Name)
971 {
972
973     if (!Name || Name[0] == 0)
974     {
975         AcpiOsPrintf ("Current scope: %s\n", ScopeBuf);
976         return;
977     }
978
979     AcpiDbPrepNamestring (Name);
980
981     /* TBD: [Future] Validate scope here */
982
983     if (Name[0] == '\\')
984     {
985         STRCPY (ScopeBuf, Name);
986         STRCAT (ScopeBuf, "\\");
987     }
988
989     else
990     {
991         STRCAT (ScopeBuf, Name);
992         STRCAT (ScopeBuf, "\\");
993     }
994
995     AcpiOsPrintf ("New scope: %s\n", ScopeBuf);
996 }
997
998
999 /*******************************************************************************
1000  *
1001  * FUNCTION:    AcpiDbDisplayResources
1002  *
1003  * PARAMETERS:  ObjectArg       - String with hex value of the object
1004  *
1005  * RETURN:      None
1006  *
1007  * DESCRIPTION: 
1008  *
1009  ******************************************************************************/
1010
1011 void
1012 AcpiDbDisplayResources (
1013     NATIVE_CHAR             *ObjectArg)
1014 {
1015     ACPI_OPERAND_OBJECT     *ObjDesc;
1016     ACPI_STATUS             Status;
1017     ACPI_BUFFER             ReturnObj;
1018     PCI_ROUTING_TABLE       *Prt;
1019     UINT32                  i;
1020
1021
1022     AcpiDbSetOutputDestination (DB_REDIRECTABLE_OUTPUT);
1023
1024     /* Convert string to object pointer */
1025
1026     ObjDesc = (ACPI_OPERAND_OBJECT  *) STRTOUL (ObjectArg, NULL, 16);
1027
1028     /* Prepare for a return object of arbitrary size */
1029
1030     ReturnObj.Pointer           = Buffer;
1031     ReturnObj.Length            = BUFFER_SIZE;
1032
1033     Status = AcpiEvaluateObject (ObjDesc, "_PRT", NULL, &ReturnObj);
1034     if (ACPI_FAILURE (Status))
1035     {
1036         AcpiOsPrintf ("Could not obtain _PRT: %s\n", AcpiCmFormatException (Status));
1037         goto Cleanup;
1038     }
1039
1040     ReturnObj.Pointer           = Buffer;
1041     ReturnObj.Length            = BUFFER_SIZE;
1042
1043     Status = AcpiGetIrqRoutingTable (ObjDesc, &ReturnObj);
1044     if (ACPI_FAILURE (Status))
1045     {
1046         AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n", AcpiCmFormatException (Status));
1047         goto Cleanup;
1048     }
1049
1050     Prt = (PCI_ROUTING_TABLE *) Buffer;
1051     i = 0;
1052     while ((char *) Prt < (Buffer + ReturnObj.Length))
1053     {
1054         AcpiOsPrintf ("Prt[%d] Src=%s: Addr=%X\n", i, Prt->Source, Prt->Address);
1055         i++;
1056         Prt = (PCI_ROUTING_TABLE *) (((char *) Prt) + Prt->Length);
1057     }
1058
1059 Cleanup:
1060
1061     AcpiDbSetOutputDestination (DB_CONSOLE_OUTPUT);
1062     return;
1063
1064 }
1065
1066
1067
1068
1069
1070 #endif /* ENABLE_DEBUGGER */