dbcmds.c revision 102550
1/*******************************************************************************
2 *
3 * Module Name: dbcmds - debug commands and output routines
4 *              $Revision: 87 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, 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 "acdispat.h"
120#include "amlcode.h"
121#include "acnamesp.h"
122#include "acevents.h"
123#include "acdebug.h"
124#include "acresrc.h"
125#include "acdisasm.h"
126
127#ifdef ACPI_DEBUGGER
128
129#define _COMPONENT          ACPI_CA_DEBUGGER
130        ACPI_MODULE_NAME    ("dbcmds")
131
132
133/*
134 * Arguments for the Objects command
135 * These object types map directly to the ACPI_TYPES
136 */
137
138static ARGUMENT_INFO        AcpiDbObjectTypes [] =
139{
140    {"ANY"},
141    {"NUMBERS"},
142    {"STRINGS"},
143    {"BUFFERS"},
144    {"PACKAGES"},
145    {"FIELDS"},
146    {"DEVICES"},
147    {"EVENTS"},
148    {"METHODS"},
149    {"MUTEXES"},
150    {"REGIONS"},
151    {"POWERRESOURCES"},
152    {"PROCESSORS"},
153    {"THERMALZONES"},
154    {"BUFFERFIELDS"},
155    {"DDBHANDLES"},
156    {NULL}           /* Must be null terminated */
157};
158
159
160/*******************************************************************************
161 *
162 * FUNCTION:    AcpiDbWalkForReferences
163 *
164 * PARAMETERS:  Callback from WalkNamespace
165 *
166 * RETURN:      Status
167 *
168 * DESCRIPTION: Check if this namespace object refers to the target object
169 *              that is passed in as the context value.
170 *
171 * Note: Currently doesn't check subobjects within the Node's object
172 *
173 ******************************************************************************/
174
175ACPI_STATUS
176AcpiDbWalkForReferences (
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.Ascii);
191    }
192
193    /* Check for match against the object attached to the node */
194
195    if (AcpiNsGetAttachedObject (Node) == ObjDesc)
196    {
197        AcpiOsPrintf ("Reference at Node->Object %p [%4.4s]\n", Node, Node->Name.Ascii);
198    }
199
200    return (AE_OK);
201}
202
203
204/*******************************************************************************
205 *
206 * FUNCTION:    AcpiDbFindReferences
207 *
208 * PARAMETERS:  ObjectArg       - String with hex value of the object
209 *
210 * RETURN:      None
211 *
212 * DESCRIPTION: Search namespace for all references to the input object
213 *
214 ******************************************************************************/
215
216void
217AcpiDbFindReferences (
218    NATIVE_CHAR             *ObjectArg)
219{
220    ACPI_OPERAND_OBJECT     *ObjDesc;
221
222
223    /* Convert string to object pointer */
224
225    ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
226
227    /* Search all nodes in namespace */
228
229    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
230                    AcpiDbWalkForReferences, (void *) ObjDesc, NULL);
231}
232
233
234/*******************************************************************************
235 *
236 * FUNCTION:    AcpiDbDisplayLocks
237 *
238 * PARAMETERS:  None
239 *
240 * RETURN:      None
241 *
242 * DESCRIPTION: Display information about internal mutexes.
243 *
244 ******************************************************************************/
245
246void
247AcpiDbDisplayLocks (void)
248{
249    UINT32                  i;
250
251
252    for (i = 0; i < MAX_MTX; i++)
253    {
254        AcpiOsPrintf ("%26s : %s\n", AcpiUtGetMutexName (i),
255                    AcpiGbl_AcpiMutexInfo[i].OwnerId == ACPI_MUTEX_NOT_ACQUIRED
256                        ? "Locked" : "Unlocked");
257    }
258}
259
260
261/*******************************************************************************
262 *
263 * FUNCTION:    AcpiDbDisplayTableInfo
264 *
265 * PARAMETERS:  TableArg        - String with name of table to be displayed
266 *
267 * RETURN:      None
268 *
269 * DESCRIPTION: Display information about loaded tables.  Current
270 *              implementation displays all loaded tables.
271 *
272 ******************************************************************************/
273
274void
275AcpiDbDisplayTableInfo (
276    NATIVE_CHAR             *TableArg)
277{
278    UINT32                  i;
279
280
281    for (i = 0; i < NUM_ACPI_TABLES; i++)
282    {
283        if (AcpiGbl_AcpiTables[i].Pointer)
284        {
285            AcpiOsPrintf ("%s at %p length %X\n", AcpiGbl_AcpiTableData[i].Name,
286                        AcpiGbl_AcpiTables[i].Pointer, AcpiGbl_AcpiTables[i].Length);
287        }
288    }
289}
290
291
292/*******************************************************************************
293 *
294 * FUNCTION:    AcpiDbUnloadAcpiTable
295 *
296 * PARAMETERS:  TableArg        - Name of the table to be unloaded
297 *              InstanceArg     - Which instance of the table to unload (if
298 *                                there are multiple tables of the same type)
299 *
300 * RETURN:      Nonde
301 *
302 * DESCRIPTION: Unload an ACPI table.
303 *              Instance is not implemented
304 *
305 ******************************************************************************/
306
307void
308AcpiDbUnloadAcpiTable (
309    NATIVE_CHAR             *TableArg,
310    NATIVE_CHAR             *InstanceArg)
311{
312    UINT32                  i;
313    ACPI_STATUS             Status;
314
315
316    /* Search all tables for the target type */
317
318    for (i = 0; i < NUM_ACPI_TABLES; i++)
319    {
320        if (!ACPI_STRNCMP (TableArg, AcpiGbl_AcpiTableData[i].Signature,
321                AcpiGbl_AcpiTableData[i].SigLength))
322        {
323            /* Found the table, unload it */
324
325            Status = AcpiUnloadTable (i);
326            if (ACPI_SUCCESS (Status))
327            {
328                AcpiOsPrintf ("[%s] unloaded and uninstalled\n", TableArg);
329            }
330            else
331            {
332                AcpiOsPrintf ("%s, while unloading [%s]\n",
333                    AcpiFormatException (Status), TableArg);
334            }
335
336            return;
337        }
338    }
339
340    AcpiOsPrintf ("Unknown table type [%s]\n", TableArg);
341}
342
343
344/*******************************************************************************
345 *
346 * FUNCTION:    AcpiDbSetMethodBreakpoint
347 *
348 * PARAMETERS:  Location            - AML offset of breakpoint
349 *              WalkState           - Current walk info
350 *              Op                  - Current Op (from parse walk)
351 *
352 * RETURN:      None
353 *
354 * DESCRIPTION: Set a breakpoint in a control method at the specified
355 *              AML offset
356 *
357 ******************************************************************************/
358
359void
360AcpiDbSetMethodBreakpoint (
361    NATIVE_CHAR             *Location,
362    ACPI_WALK_STATE         *WalkState,
363    ACPI_PARSE_OBJECT       *Op)
364{
365    UINT32                  Address;
366
367
368    if (!Op)
369    {
370        AcpiOsPrintf ("There is no method currently executing\n");
371        return;
372    }
373
374    /* Get and verify the breakpoint address */
375
376    Address = ACPI_STRTOUL (Location, NULL, 16);
377    if (Address <= Op->Common.AmlOffset)
378    {
379        AcpiOsPrintf ("Breakpoint %X is beyond current address %X\n", Address, Op->Common.AmlOffset);
380    }
381
382    /* Save breakpoint in current walk */
383
384    WalkState->UserBreakpoint = Address;
385    AcpiOsPrintf ("Breakpoint set at AML offset %X\n", Address);
386}
387
388
389/*******************************************************************************
390 *
391 * FUNCTION:    AcpiDbSetMethodCallBreakpoint
392 *
393 * PARAMETERS:  Op                  - Current Op (from parse walk)
394 *
395 * RETURN:      None
396 *
397 * DESCRIPTION: Set a breakpoint in a control method at the specified
398 *              AML offset
399 *
400 ******************************************************************************/
401
402void
403AcpiDbSetMethodCallBreakpoint (
404    ACPI_PARSE_OBJECT       *Op)
405{
406
407
408    if (!Op)
409    {
410        AcpiOsPrintf ("There is no method currently executing\n");
411        return;
412    }
413
414
415    AcpiGbl_StepToNextCall = TRUE;
416}
417
418
419/*******************************************************************************
420 *
421 * FUNCTION:    AcpiDbDisassembleAml
422 *
423 * PARAMETERS:  Statements          - Number of statements to disassemble
424 *              Op                  - Current Op (from parse walk)
425 *
426 * RETURN:      None
427 *
428 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
429 *              of statements specified.
430 *
431 ******************************************************************************/
432
433void
434AcpiDbDisassembleAml (
435    NATIVE_CHAR             *Statements,
436    ACPI_PARSE_OBJECT       *Op)
437{
438    UINT32                  NumStatements = 8;
439
440
441    if (!Op)
442    {
443        AcpiOsPrintf ("There is no method currently executing\n");
444        return;
445    }
446
447    if (Statements)
448    {
449        NumStatements = ACPI_STRTOUL (Statements, NULL, 0);
450    }
451
452    AcpiDmDisassemble (NULL, Op, NumStatements);
453}
454
455
456/*******************************************************************************
457 *
458 * FUNCTION:    AcpiDbDumpNamespace
459 *
460 * PARAMETERS:  StartArg        - Node to begin namespace dump
461 *              DepthArg        - Maximum tree depth to be dumped
462 *
463 * RETURN:      None
464 *
465 * DESCRIPTION: Dump entire namespace or a subtree.  Each node is displayed
466 *              with type and other information.
467 *
468 ******************************************************************************/
469
470void
471AcpiDbDumpNamespace (
472    NATIVE_CHAR             *StartArg,
473    NATIVE_CHAR             *DepthArg)
474{
475    ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
476    UINT32                  MaxDepth = ACPI_UINT32_MAX;
477
478
479    /* No argument given, just start at the root and dump entire namespace */
480
481    if (StartArg)
482    {
483        /* Check if numeric argument, must be a Node */
484
485        if ((StartArg[0] >= 0x30) && (StartArg[0] <= 0x39))
486        {
487            SubtreeEntry = ACPI_TO_POINTER (ACPI_STRTOUL (StartArg, NULL, 16));
488            if (!AcpiOsReadable (SubtreeEntry, sizeof (ACPI_NAMESPACE_NODE)))
489            {
490                AcpiOsPrintf ("Address %p is invalid in this address space\n", SubtreeEntry);
491                return;
492            }
493
494            if (ACPI_GET_DESCRIPTOR_TYPE (SubtreeEntry) != ACPI_DESC_TYPE_NAMED)
495            {
496                AcpiOsPrintf ("Address %p is not a valid Named object\n", SubtreeEntry);
497                return;
498            }
499        }
500
501        /* Alpha argument */
502
503        else
504        {
505            /* The parameter is a name string that must be resolved to a Named obj*/
506
507            SubtreeEntry = AcpiDbLocalNsLookup (StartArg);
508            if (!SubtreeEntry)
509            {
510                SubtreeEntry = AcpiGbl_RootNode;
511            }
512        }
513
514        /* Now we can check for the depth argument */
515
516        if (DepthArg)
517        {
518            MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
519        }
520    }
521
522    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
523    AcpiOsPrintf ("ACPI Namespace (from %p subtree):\n", SubtreeEntry);
524
525    /* Display the subtree */
526
527    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
528    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, ACPI_UINT32_MAX, SubtreeEntry);
529    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
530}
531
532
533/*******************************************************************************
534 *
535 * FUNCTION:    AcpiDbDumpNamespaceByOwner
536 *
537 * PARAMETERS:  OwnerArg        - Owner ID whose nodes will be displayed
538 *              DepthArg        - Maximum tree depth to be dumped
539 *
540 * RETURN:      None
541 *
542 * DESCRIPTION: Dump elements of the namespace that are owned by the OwnerId.
543 *
544 ******************************************************************************/
545
546void
547AcpiDbDumpNamespaceByOwner (
548    NATIVE_CHAR             *OwnerArg,
549    NATIVE_CHAR             *DepthArg)
550{
551    ACPI_HANDLE             SubtreeEntry = AcpiGbl_RootNode;
552    UINT32                  MaxDepth = ACPI_UINT32_MAX;
553    UINT16                  OwnerId;
554
555
556    OwnerId = (UINT16) ACPI_STRTOUL (OwnerArg, NULL, 0);
557
558    /* Now we can check for the depth argument */
559
560    if (DepthArg)
561    {
562        MaxDepth = ACPI_STRTOUL (DepthArg, NULL, 0);
563    }
564
565    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
566    AcpiOsPrintf ("ACPI Namespace by owner %X:\n", OwnerId);
567
568    /* Display the subtree */
569
570    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
571    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, MaxDepth, OwnerId, SubtreeEntry);
572    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
573}
574
575
576/*******************************************************************************
577 *
578 * FUNCTION:    AcpiDbSendNotify
579 *
580 * PARAMETERS:  Name            - Name of ACPI object to send the notify to
581 *              Value           - Value of the notify to send.
582 *
583 * RETURN:      None
584 *
585 * DESCRIPTION: Send an ACPI notification.  The value specified is sent to the
586 *              named object as an ACPI notify.
587 *
588 ******************************************************************************/
589
590void
591AcpiDbSendNotify (
592    NATIVE_CHAR             *Name,
593    UINT32                  Value)
594{
595    ACPI_NAMESPACE_NODE     *Node;
596    ACPI_STATUS             Status;
597
598
599    /* Translate name to an Named object */
600
601    Node = AcpiDbLocalNsLookup (Name);
602    if (!Node)
603    {
604        return;
605    }
606
607    /* Decode Named object type */
608
609    switch (Node->Type)
610    {
611    case ACPI_TYPE_DEVICE:
612    case ACPI_TYPE_THERMAL:
613
614         /* Send the notify */
615
616        Status = AcpiEvQueueNotifyRequest (Node, Value);
617        if (ACPI_FAILURE (Status))
618        {
619            AcpiOsPrintf ("Could not queue notify\n");
620        }
621        break;
622
623    default:
624        AcpiOsPrintf ("Named object is not a device or a thermal object\n");
625        break;
626    }
627
628}
629
630
631/*******************************************************************************
632 *
633 * FUNCTION:    AcpiDbSetMethodData
634 *
635 * PARAMETERS:  TypeArg         - L for local, A for argument
636 *              IndexArg        - which one
637 *              ValueArg        - Value to set.
638 *
639 * RETURN:      None
640 *
641 * DESCRIPTION: Set a local or argument for the running control method.
642 *              NOTE: only object supported is Number.
643 *
644 ******************************************************************************/
645
646void
647AcpiDbSetMethodData (
648    NATIVE_CHAR             *TypeArg,
649    NATIVE_CHAR             *IndexArg,
650    NATIVE_CHAR             *ValueArg)
651{
652    NATIVE_CHAR             Type;
653    UINT32                  Index;
654    UINT32                  Value;
655    ACPI_WALK_STATE         *WalkState;
656    ACPI_OPERAND_OBJECT     *ObjDesc;
657    ACPI_STATUS             Status;
658
659
660    /* Validate TypeArg */
661
662    ACPI_STRUPR (TypeArg);
663    Type = TypeArg[0];
664    if ((Type != 'L') &&
665        (Type != 'A'))
666    {
667        AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg);
668        return;
669    }
670
671    /* Get the index and value */
672
673    Index = ACPI_STRTOUL (IndexArg, NULL, 16);
674    Value = ACPI_STRTOUL (ValueArg, NULL, 16);
675
676    WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList);
677    if (!WalkState)
678    {
679        AcpiOsPrintf ("There is no method currently executing\n");
680        return;
681    }
682
683
684    /* Create and initialize the new object */
685
686    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
687    if (!ObjDesc)
688    {
689        AcpiOsPrintf ("Could not create an internal object\n");
690        return;
691    }
692
693    ObjDesc->Integer.Value = Value;
694
695
696    /* Store the new object into the target */
697
698    switch (Type)
699    {
700    case 'A':
701
702        /* Set a method argument */
703
704        if (Index > MTH_MAX_ARG)
705        {
706            AcpiOsPrintf ("Arg%d - Invalid argument name\n", Index);
707            return;
708        }
709
710        Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, ObjDesc, WalkState);
711        if (ACPI_FAILURE (Status))
712        {
713            return;
714        }
715
716        ObjDesc = WalkState->Arguments[Index].Object;
717
718        AcpiOsPrintf ("Arg%d: ", Index);
719        AcpiDbDisplayInternalObject (ObjDesc, WalkState);
720        break;
721
722    case 'L':
723
724        /* Set a method local */
725
726        if (Index > MTH_MAX_LOCAL)
727        {
728            AcpiOsPrintf ("Local%d - Invalid local variable name\n", Index);
729            return;
730        }
731
732        Status = AcpiDsStoreObjectToLocal (AML_LOCAL_OP, Index, ObjDesc, WalkState);
733        if (ACPI_FAILURE (Status))
734        {
735            return;
736        }
737
738        ObjDesc = WalkState->LocalVariables[Index].Object;
739
740        AcpiOsPrintf ("Local%d: ", Index);
741        AcpiDbDisplayInternalObject (ObjDesc, WalkState);
742        break;
743
744    default:
745        break;
746    }
747}
748
749
750/*******************************************************************************
751 *
752 * FUNCTION:    AcpiDbWalkForSpecificObjects
753 *
754 * PARAMETERS:  Callback from WalkNamespace
755 *
756 * RETURN:      Status
757 *
758 * DESCRIPTION: Display short info about objects in the namespace
759 *
760 ******************************************************************************/
761
762ACPI_STATUS
763AcpiDbWalkForSpecificObjects (
764    ACPI_HANDLE             ObjHandle,
765    UINT32                  NestingLevel,
766    void                    *Context,
767    void                    **ReturnValue)
768{
769    ACPI_OPERAND_OBJECT     *ObjDesc;
770    ACPI_STATUS             Status;
771    ACPI_BUFFER             Buffer;
772
773
774    ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjHandle);
775
776    /* Get and display the full pathname to this object */
777
778    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
779    Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
780    if (ACPI_FAILURE (Status))
781    {
782        AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
783        return (AE_OK);
784    }
785
786    AcpiOsPrintf ("%32s", Buffer.Pointer);
787    ACPI_MEM_FREE (Buffer.Pointer);
788
789
790    /* Display short information about the object */
791
792    if (ObjDesc)
793    {
794        switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
795        {
796        case ACPI_TYPE_METHOD:
797            AcpiOsPrintf ("  #Args %d  Concurrency %X", ObjDesc->Method.ParamCount, ObjDesc->Method.Concurrency);
798            break;
799
800        case ACPI_TYPE_INTEGER:
801            AcpiOsPrintf ("  Value %X", ObjDesc->Integer.Value);
802            break;
803
804        case ACPI_TYPE_STRING:
805            AcpiOsPrintf ("  \"%s\"", ObjDesc->String.Pointer);
806            break;
807
808        case ACPI_TYPE_REGION:
809            AcpiOsPrintf ("  SpaceId %X Address %X Length %X", ObjDesc->Region.SpaceId, ObjDesc->Region.Address, ObjDesc->Region.Length);
810            break;
811
812        case ACPI_TYPE_PACKAGE:
813            AcpiOsPrintf ("  #Elements %X", ObjDesc->Package.Count);
814            break;
815
816        case ACPI_TYPE_BUFFER:
817            AcpiOsPrintf ("  Length %X", ObjDesc->Buffer.Length);
818            break;
819
820        default:
821            /* Ignore other object types */
822            break;
823        }
824    }
825
826    AcpiOsPrintf ("\n");
827    return (AE_OK);
828}
829
830
831/*******************************************************************************
832 *
833 * FUNCTION:    AcpiDbDisplayObjects
834 *
835 * PARAMETERS:  ObjTypeArg          - Type of object to display
836 *              DisplayCountArg     - Max depth to display
837 *
838 * RETURN:      None
839 *
840 * DESCRIPTION: Display objects in the namespace of the requested type
841 *
842 ******************************************************************************/
843
844ACPI_STATUS
845AcpiDbDisplayObjects (
846    NATIVE_CHAR             *ObjTypeArg,
847    NATIVE_CHAR             *DisplayCountArg)
848{
849    ACPI_OBJECT_TYPE        Type;
850
851
852    /* Get the object type */
853
854    Type = AcpiDbMatchArgument (ObjTypeArg, AcpiDbObjectTypes);
855    if (Type == ACPI_TYPE_NOT_FOUND)
856    {
857        AcpiOsPrintf ("Invalid or unsupported argument\n");
858        return (AE_OK);
859    }
860
861    AcpiDbSetOutputDestination (ACPI_DB_DUPLICATE_OUTPUT);
862    AcpiOsPrintf ("Objects of type [%s] defined in the current ACPI Namespace: \n",
863        AcpiUtGetTypeName (Type));
864
865    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
866
867    /* Walk the namespace from the root */
868
869    (void) AcpiWalkNamespace (Type, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
870                        AcpiDbWalkForSpecificObjects, (void *) &Type, NULL);
871
872    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
873    return (AE_OK);
874}
875
876
877/*******************************************************************************
878 *
879 * FUNCTION:    AcpiDbWalkAndMatchName
880 *
881 * PARAMETERS:  Callback from WalkNamespace
882 *
883 * RETURN:      Status
884 *
885 * DESCRIPTION: Find a particular name/names within the namespace.  Wildcards
886 *              are supported -- '?' matches any character.
887 *
888 ******************************************************************************/
889
890ACPI_STATUS
891AcpiDbWalkAndMatchName (
892    ACPI_HANDLE             ObjHandle,
893    UINT32                  NestingLevel,
894    void                    *Context,
895    void                    **ReturnValue)
896{
897    ACPI_STATUS             Status;
898    NATIVE_CHAR             *RequestedName = (NATIVE_CHAR *) Context;
899    UINT32                  i;
900    ACPI_BUFFER             Buffer;
901
902
903    /* Check for a name match */
904
905    for (i = 0; i < 4; i++)
906    {
907        /* Wildcard support */
908
909        if ((RequestedName[i] != '?') &&
910            (RequestedName[i] != ((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Ascii[i]))
911        {
912            /* No match, just exit */
913
914            return (AE_OK);
915        }
916    }
917
918
919    /* Get the full pathname to this object */
920
921    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
922    Status = AcpiNsHandleToPathname (ObjHandle, &Buffer);
923    if (ACPI_FAILURE (Status))
924    {
925        AcpiOsPrintf ("Could Not get pathname for object %p\n", ObjHandle);
926    }
927    else
928    {
929        AcpiOsPrintf ("%32s (%p) - %s\n", Buffer.Pointer, ObjHandle,
930            AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) ObjHandle)->Type));
931        ACPI_MEM_FREE (Buffer.Pointer);
932    }
933
934    return (AE_OK);
935}
936
937
938/*******************************************************************************
939 *
940 * FUNCTION:    AcpiDbFindNameInNamespace
941 *
942 * PARAMETERS:  NameArg         - The 4-character ACPI name to find.
943 *                                wildcards are supported.
944 *
945 * RETURN:      None
946 *
947 * DESCRIPTION: Search the namespace for a given name (with wildcards)
948 *
949 ******************************************************************************/
950
951ACPI_STATUS
952AcpiDbFindNameInNamespace (
953    NATIVE_CHAR             *NameArg)
954{
955
956    if (ACPI_STRLEN (NameArg) > 4)
957    {
958        AcpiOsPrintf ("Name must be no longer than 4 characters\n");
959        return (AE_OK);
960    }
961
962    /* Walk the namespace from the root */
963
964    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
965                        AcpiDbWalkAndMatchName, NameArg, NULL);
966
967    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
968    return (AE_OK);
969}
970
971
972/*******************************************************************************
973 *
974 * FUNCTION:    AcpiDbSetScope
975 *
976 * PARAMETERS:  Name                - New scope path
977 *
978 * RETURN:      Status
979 *
980 * DESCRIPTION: Set the "current scope" as maintained by this utility.
981 *              The scope is used as a prefix to ACPI paths.
982 *
983 ******************************************************************************/
984
985void
986AcpiDbSetScope (
987    NATIVE_CHAR             *Name)
988{
989    ACPI_STATUS             Status;
990    ACPI_NAMESPACE_NODE     *Node;
991
992
993    if (!Name || Name[0] == 0)
994    {
995        AcpiOsPrintf ("Current scope: %s\n", AcpiGbl_DbScopeBuf);
996        return;
997    }
998
999    AcpiDbPrepNamestring (Name);
1000
1001
1002    if (Name[0] == '\\')
1003    {
1004        /* Validate new scope from the root */
1005
1006        Status = AcpiNsGetNodeByPath (Name, AcpiGbl_RootNode, ACPI_NS_NO_UPSEARCH, &Node);
1007        if (ACPI_FAILURE (Status))
1008        {
1009            goto ErrorExit;
1010        }
1011
1012        ACPI_STRCPY (AcpiGbl_DbScopeBuf, Name);
1013        ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1014    }
1015    else
1016    {
1017        /* Validate new scope relative to old scope */
1018
1019        Status = AcpiNsGetNodeByPath (Name, AcpiGbl_DbScopeNode, ACPI_NS_NO_UPSEARCH, &Node);
1020        if (ACPI_FAILURE (Status))
1021        {
1022            goto ErrorExit;
1023        }
1024
1025        ACPI_STRCAT (AcpiGbl_DbScopeBuf, Name);
1026        ACPI_STRCAT (AcpiGbl_DbScopeBuf, "\\");
1027    }
1028
1029    AcpiGbl_DbScopeNode = Node;
1030    AcpiOsPrintf ("New scope: %s\n", AcpiGbl_DbScopeBuf);
1031    return;
1032
1033
1034ErrorExit:
1035
1036    AcpiOsPrintf ("Could not attach scope: %s, %s\n", Name, AcpiFormatException (Status));
1037}
1038
1039
1040/*******************************************************************************
1041 *
1042 * FUNCTION:    AcpiDbDisplayResources
1043 *
1044 * PARAMETERS:  ObjectArg       - String with hex value of the object
1045 *
1046 * RETURN:      None
1047 *
1048 * DESCRIPTION:
1049 *
1050 ******************************************************************************/
1051
1052void
1053AcpiDbDisplayResources (
1054    NATIVE_CHAR             *ObjectArg)
1055{
1056#if ACPI_MACHINE_WIDTH != 16
1057
1058    ACPI_OPERAND_OBJECT     *ObjDesc;
1059    ACPI_STATUS             Status;
1060    ACPI_BUFFER             ReturnObj;
1061
1062
1063    AcpiDbSetOutputDestination (ACPI_DB_REDIRECTABLE_OUTPUT);
1064    AcpiDbgLevel |= ACPI_LV_RESOURCES;
1065
1066    /* Convert string to object pointer */
1067
1068    ObjDesc = ACPI_TO_POINTER (ACPI_STRTOUL (ObjectArg, NULL, 16));
1069
1070    /* Prepare for a return object of arbitrary size */
1071
1072    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1073    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1074
1075    /* _PRT */
1076
1077    AcpiOsPrintf ("Evaluating _PRT\n");
1078
1079    Status = AcpiEvaluateObject (ObjDesc, "_PRT", NULL, &ReturnObj);
1080    if (ACPI_FAILURE (Status))
1081    {
1082        AcpiOsPrintf ("Could not obtain _PRT: %s\n", AcpiFormatException (Status));
1083        goto GetCrs;
1084    }
1085
1086    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1087    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1088
1089    Status = AcpiGetIrqRoutingTable (ObjDesc, &ReturnObj);
1090    if (ACPI_FAILURE (Status))
1091    {
1092        AcpiOsPrintf ("GetIrqRoutingTable failed: %s\n", AcpiFormatException (Status));
1093    }
1094
1095    else
1096    {
1097        AcpiRsDumpIrqList ((UINT8 *) AcpiGbl_DbBuffer);
1098    }
1099
1100
1101    /* _CRS */
1102
1103GetCrs:
1104    AcpiOsPrintf ("Evaluating _CRS\n");
1105
1106    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1107    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1108
1109    Status = AcpiEvaluateObject (ObjDesc, "_CRS", NULL, &ReturnObj);
1110    if (ACPI_FAILURE (Status))
1111    {
1112        AcpiOsPrintf ("Could not obtain _CRS: %s\n", AcpiFormatException (Status));
1113        goto GetPrs;
1114    }
1115
1116    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1117    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1118
1119    Status = AcpiGetCurrentResources (ObjDesc, &ReturnObj);
1120    if (ACPI_FAILURE (Status))
1121    {
1122        AcpiOsPrintf ("AcpiGetCurrentResources failed: %s\n", AcpiFormatException (Status));
1123        goto GetPrs;
1124    }
1125
1126    else
1127    {
1128        AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1129    }
1130
1131    Status = AcpiSetCurrentResources (ObjDesc, &ReturnObj);
1132    if (ACPI_FAILURE (Status))
1133    {
1134        AcpiOsPrintf ("AcpiSetCurrentResources failed: %s\n", AcpiFormatException (Status));
1135        goto GetPrs;
1136    }
1137
1138
1139    /* _PRS */
1140
1141GetPrs:
1142    AcpiOsPrintf ("Evaluating _PRS\n");
1143
1144    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1145    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1146
1147    Status = AcpiEvaluateObject (ObjDesc, "_PRS", NULL, &ReturnObj);
1148    if (ACPI_FAILURE (Status))
1149    {
1150        AcpiOsPrintf ("Could not obtain _PRS: %s\n", AcpiFormatException (Status));
1151        goto Cleanup;
1152    }
1153
1154    ReturnObj.Pointer           = AcpiGbl_DbBuffer;
1155    ReturnObj.Length            = ACPI_DEBUG_BUFFER_SIZE;
1156
1157    Status = AcpiGetPossibleResources (ObjDesc, &ReturnObj);
1158    if (ACPI_FAILURE (Status))
1159    {
1160        AcpiOsPrintf ("AcpiGetPossibleResources failed: %s\n", AcpiFormatException (Status));
1161    }
1162
1163    else
1164    {
1165        AcpiRsDumpResourceList (ACPI_CAST_PTR (ACPI_RESOURCE, AcpiGbl_DbBuffer));
1166    }
1167
1168
1169Cleanup:
1170
1171    AcpiDbSetOutputDestination (ACPI_DB_CONSOLE_OUTPUT);
1172    return;
1173#endif
1174
1175}
1176
1177
1178typedef struct
1179{
1180    UINT32              Nodes;
1181    UINT32              Objects;
1182} ACPI_INTEGRITY_INFO;
1183
1184/*******************************************************************************
1185 *
1186 * FUNCTION:    AcpiDbIntegrityWalk
1187 *
1188 * PARAMETERS:  Callback from WalkNamespace
1189 *
1190 * RETURN:      Status
1191 *
1192 * DESCRIPTION: Examine one NS node for valid values.
1193 *
1194 ******************************************************************************/
1195
1196ACPI_STATUS
1197AcpiDbIntegrityWalk (
1198    ACPI_HANDLE             ObjHandle,
1199    UINT32                  NestingLevel,
1200    void                    *Context,
1201    void                    **ReturnValue)
1202{
1203    ACPI_INTEGRITY_INFO     *Info = (ACPI_INTEGRITY_INFO *) Context;
1204    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
1205    ACPI_OPERAND_OBJECT     *Object;
1206
1207
1208    Info->Nodes++;
1209    if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
1210    {
1211        AcpiOsPrintf ("Invalid Descriptor Type for Node %p, Type = %X\n",
1212            Node, ACPI_GET_DESCRIPTOR_TYPE (Node));
1213    }
1214
1215    if (Node->Type > INTERNAL_TYPE_MAX)
1216    {
1217        AcpiOsPrintf ("Invalid Object Type for Node %p, Type = %X\n",
1218            Node, Node->Type);
1219    }
1220
1221    if (!AcpiUtValidAcpiName (Node->Name.Integer))
1222    {
1223        AcpiOsPrintf ("Invalid AcpiName for Node %p\n", Node);
1224    }
1225
1226    Object = AcpiNsGetAttachedObject (Node);
1227    if (Object)
1228    {
1229        Info->Objects++;
1230        if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
1231        {
1232            AcpiOsPrintf ("Invalid Descriptor Type for Object %p, Type = %X\n",
1233                Object, ACPI_GET_DESCRIPTOR_TYPE (Object));
1234        }
1235    }
1236
1237
1238    return (AE_OK);
1239}
1240
1241
1242/*******************************************************************************
1243 *
1244 * FUNCTION:    AcpiDbCheckIntegrity
1245 *
1246 * PARAMETERS:  None
1247 *
1248 * RETURN:      None
1249 *
1250 * DESCRIPTION: Check entire namespace for data structure integrity
1251 *
1252 ******************************************************************************/
1253
1254void
1255AcpiDbCheckIntegrity (void)
1256{
1257    ACPI_INTEGRITY_INFO     Info = {0,0};
1258
1259    /* Search all nodes in namespace */
1260
1261    (void) AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
1262                    AcpiDbIntegrityWalk, (void *) &Info, NULL);
1263
1264    AcpiOsPrintf ("Verified %d namespace nodes with %d Objects\n", Info.Nodes, Info.Objects);
1265
1266}
1267
1268#endif /* ACPI_DEBUGGER */
1269