exdump.c revision 229989
1/******************************************************************************
2 *
3 * Module Name: exdump - Interpreter debug output routines
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#define __EXDUMP_C__
45
46#include <contrib/dev/acpica/include/acpi.h>
47#include <contrib/dev/acpica/include/accommon.h>
48#include <contrib/dev/acpica/include/acinterp.h>
49#include <contrib/dev/acpica/include/amlcode.h>
50#include <contrib/dev/acpica/include/acnamesp.h>
51
52
53#define _COMPONENT          ACPI_EXECUTER
54        ACPI_MODULE_NAME    ("exdump")
55
56/*
57 * The following routines are used for debug output only
58 */
59#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
60
61/* Local prototypes */
62
63static void
64AcpiExOutString (
65    char                    *Title,
66    char                    *Value);
67
68static void
69AcpiExOutPointer (
70    char                    *Title,
71    void                    *Value);
72
73static void
74AcpiExDumpObject (
75    ACPI_OPERAND_OBJECT     *ObjDesc,
76    ACPI_EXDUMP_INFO        *Info);
77
78static void
79AcpiExDumpReferenceObj (
80    ACPI_OPERAND_OBJECT     *ObjDesc);
81
82static void
83AcpiExDumpPackageObj (
84    ACPI_OPERAND_OBJECT     *ObjDesc,
85    UINT32                  Level,
86    UINT32                  Index);
87
88
89/*******************************************************************************
90 *
91 * Object Descriptor info tables
92 *
93 * Note: The first table entry must be an INIT opcode and must contain
94 * the table length (number of table entries)
95 *
96 ******************************************************************************/
97
98static ACPI_EXDUMP_INFO     AcpiExDumpInteger[2] =
99{
100    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpInteger),        NULL},
101    {ACPI_EXD_UINT64,   ACPI_EXD_OFFSET (Integer.Value),                "Value"}
102};
103
104static ACPI_EXDUMP_INFO     AcpiExDumpString[4] =
105{
106    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpString),         NULL},
107    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (String.Length),                "Length"},
108    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (String.Pointer),               "Pointer"},
109    {ACPI_EXD_STRING,   0,                                              NULL}
110};
111
112static ACPI_EXDUMP_INFO     AcpiExDumpBuffer[5] =
113{
114    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpBuffer),         NULL},
115    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (Buffer.Length),                "Length"},
116    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Buffer.Pointer),               "Pointer"},
117    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Buffer.Node),                  "Parent Node"},
118    {ACPI_EXD_BUFFER,   0,                                              NULL}
119};
120
121static ACPI_EXDUMP_INFO     AcpiExDumpPackage[5] =
122{
123    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpPackage),        NULL},
124    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Package.Flags),                "Flags"},
125    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (Package.Count),                "Elements"},
126    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Package.Elements),             "Element List"},
127    {ACPI_EXD_PACKAGE,  0,                                              NULL}
128};
129
130static ACPI_EXDUMP_INFO     AcpiExDumpDevice[4] =
131{
132    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpDevice),         NULL},
133    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Device.Handler),               "Handler"},
134    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Device.SystemNotify),          "System Notify"},
135    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Device.DeviceNotify),          "Device Notify"}
136};
137
138static ACPI_EXDUMP_INFO     AcpiExDumpEvent[2] =
139{
140    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpEvent),          NULL},
141    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Event.OsSemaphore),            "OsSemaphore"}
142};
143
144static ACPI_EXDUMP_INFO     AcpiExDumpMethod[9] =
145{
146    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpMethod),         NULL},
147    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Method.InfoFlags),             "Info Flags"},
148    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Method.ParamCount),            "Parameter Count"},
149    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Method.SyncLevel),             "Sync Level"},
150    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Method.Mutex),                 "Mutex"},
151    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Method.OwnerId),               "Owner Id"},
152    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Method.ThreadCount),           "Thread Count"},
153    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (Method.AmlLength),             "Aml Length"},
154    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Method.AmlStart),              "Aml Start"}
155};
156
157static ACPI_EXDUMP_INFO     AcpiExDumpMutex[5] =
158{
159    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpMutex),          NULL},
160    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Mutex.SyncLevel),              "Sync Level"},
161    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Mutex.OwnerThread),            "Owner Thread"},
162    {ACPI_EXD_UINT16,   ACPI_EXD_OFFSET (Mutex.AcquisitionDepth),       "Acquire Depth"},
163    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Mutex.OsMutex),                "OsMutex"}
164};
165
166static ACPI_EXDUMP_INFO     AcpiExDumpRegion[7] =
167{
168    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpRegion),         NULL},
169    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Region.SpaceId),               "Space Id"},
170    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Region.Flags),                 "Flags"},
171    {ACPI_EXD_ADDRESS,  ACPI_EXD_OFFSET (Region.Address),               "Address"},
172    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (Region.Length),                "Length"},
173    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Region.Handler),               "Handler"},
174    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Region.Next),                  "Next"}
175};
176
177static ACPI_EXDUMP_INFO     AcpiExDumpPower[5] =
178{
179    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpPower),          NULL},
180    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (PowerResource.SystemLevel),    "System Level"},
181    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (PowerResource.ResourceOrder),  "Resource Order"},
182    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (PowerResource.SystemNotify),   "System Notify"},
183    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (PowerResource.DeviceNotify),   "Device Notify"}
184};
185
186static ACPI_EXDUMP_INFO     AcpiExDumpProcessor[7] =
187{
188    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpProcessor),      NULL},
189    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Processor.ProcId),             "Processor ID"},
190    {ACPI_EXD_UINT8 ,   ACPI_EXD_OFFSET (Processor.Length),             "Length"},
191    {ACPI_EXD_ADDRESS,  ACPI_EXD_OFFSET (Processor.Address),            "Address"},
192    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Processor.SystemNotify),       "System Notify"},
193    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Processor.DeviceNotify),       "Device Notify"},
194    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Processor.Handler),            "Handler"}
195};
196
197static ACPI_EXDUMP_INFO     AcpiExDumpThermal[4] =
198{
199    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpThermal),        NULL},
200    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (ThermalZone.SystemNotify),     "System Notify"},
201    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (ThermalZone.DeviceNotify),     "Device Notify"},
202    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (ThermalZone.Handler),          "Handler"}
203};
204
205static ACPI_EXDUMP_INFO     AcpiExDumpBufferField[3] =
206{
207    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpBufferField),    NULL},
208    {ACPI_EXD_FIELD,    0,                                              NULL},
209    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (BufferField.BufferObj),        "Buffer Object"}
210};
211
212static ACPI_EXDUMP_INFO     AcpiExDumpRegionField[5] =
213{
214    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpRegionField),    NULL},
215    {ACPI_EXD_FIELD,    0,                                              NULL},
216    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Field.AccessLength),           "AccessLength"},
217    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Field.RegionObj),              "Region Object"},
218    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Field.ResourceBuffer),         "ResourceBuffer"}
219};
220
221static ACPI_EXDUMP_INFO     AcpiExDumpBankField[5] =
222{
223    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpBankField),      NULL},
224    {ACPI_EXD_FIELD,    0,                                              NULL},
225    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (BankField.Value),              "Value"},
226    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (BankField.RegionObj),          "Region Object"},
227    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (BankField.BankObj),            "Bank Object"}
228};
229
230static ACPI_EXDUMP_INFO     AcpiExDumpIndexField[5] =
231{
232    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpBankField),      NULL},
233    {ACPI_EXD_FIELD,    0,                                              NULL},
234    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (IndexField.Value),             "Value"},
235    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (IndexField.IndexObj),          "Index Object"},
236    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (IndexField.DataObj),           "Data Object"}
237};
238
239static ACPI_EXDUMP_INFO     AcpiExDumpReference[8] =
240{
241    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpReference),       NULL},
242    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Reference.Class),              "Class"},
243    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Reference.TargetType),         "Target Type"},
244    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (Reference.Value),              "Value"},
245    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Reference.Object),             "Object Desc"},
246    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Reference.Node),               "Node"},
247    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Reference.Where),              "Where"},
248    {ACPI_EXD_REFERENCE,0,                                              NULL}
249};
250
251static ACPI_EXDUMP_INFO     AcpiExDumpAddressHandler[6] =
252{
253    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpAddressHandler), NULL},
254    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (AddressSpace.SpaceId),         "Space Id"},
255    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (AddressSpace.Next),            "Next"},
256    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (AddressSpace.RegionList),      "Region List"},
257    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (AddressSpace.Node),            "Node"},
258    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (AddressSpace.Context),         "Context"}
259};
260
261static ACPI_EXDUMP_INFO     AcpiExDumpNotify[3] =
262{
263    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpNotify),         NULL},
264    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Notify.Node),                  "Node"},
265    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (Notify.Context),               "Context"}
266};
267
268
269/* Miscellaneous tables */
270
271static ACPI_EXDUMP_INFO     AcpiExDumpCommon[4] =
272{
273    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpCommon),         NULL},
274    {ACPI_EXD_TYPE ,    0,                                              NULL},
275    {ACPI_EXD_UINT16,   ACPI_EXD_OFFSET (Common.ReferenceCount),        "Reference Count"},
276    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (Common.Flags),                 "Flags"}
277};
278
279static ACPI_EXDUMP_INFO     AcpiExDumpFieldCommon[7] =
280{
281    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpFieldCommon),    NULL},
282    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (CommonField.FieldFlags),       "Field Flags"},
283    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (CommonField.AccessByteWidth),  "Access Byte Width"},
284    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (CommonField.BitLength),        "Bit Length"},
285    {ACPI_EXD_UINT8,    ACPI_EXD_OFFSET (CommonField.StartFieldBitOffset),"Field Bit Offset"},
286    {ACPI_EXD_UINT32,   ACPI_EXD_OFFSET (CommonField.BaseByteOffset),   "Base Byte Offset"},
287    {ACPI_EXD_POINTER,  ACPI_EXD_OFFSET (CommonField.Node),             "Parent Node"}
288};
289
290static ACPI_EXDUMP_INFO     AcpiExDumpNode[5] =
291{
292    {ACPI_EXD_INIT,     ACPI_EXD_TABLE_SIZE (AcpiExDumpNode),           NULL},
293    {ACPI_EXD_UINT8,    ACPI_EXD_NSOFFSET (Flags),                      "Flags"},
294    {ACPI_EXD_UINT8,    ACPI_EXD_NSOFFSET (OwnerId),                    "Owner Id"},
295    {ACPI_EXD_POINTER,  ACPI_EXD_NSOFFSET (Child),                      "Child List"},
296    {ACPI_EXD_POINTER,  ACPI_EXD_NSOFFSET (Peer),                       "Next Peer"}
297};
298
299
300/* Dispatch table, indexed by object type */
301
302static ACPI_EXDUMP_INFO     *AcpiExDumpInfo[] =
303{
304    NULL,
305    AcpiExDumpInteger,
306    AcpiExDumpString,
307    AcpiExDumpBuffer,
308    AcpiExDumpPackage,
309    NULL,
310    AcpiExDumpDevice,
311    AcpiExDumpEvent,
312    AcpiExDumpMethod,
313    AcpiExDumpMutex,
314    AcpiExDumpRegion,
315    AcpiExDumpPower,
316    AcpiExDumpProcessor,
317    AcpiExDumpThermal,
318    AcpiExDumpBufferField,
319    NULL,
320    NULL,
321    AcpiExDumpRegionField,
322    AcpiExDumpBankField,
323    AcpiExDumpIndexField,
324    AcpiExDumpReference,
325    NULL,
326    NULL,
327    AcpiExDumpNotify,
328    AcpiExDumpAddressHandler,
329    NULL,
330    NULL,
331    NULL
332};
333
334
335/*******************************************************************************
336 *
337 * FUNCTION:    AcpiExDumpObject
338 *
339 * PARAMETERS:  ObjDesc             - Descriptor to dump
340 *              Info                - Info table corresponding to this object
341 *                                    type
342 *
343 * RETURN:      None
344 *
345 * DESCRIPTION: Walk the info table for this object
346 *
347 ******************************************************************************/
348
349static void
350AcpiExDumpObject (
351    ACPI_OPERAND_OBJECT     *ObjDesc,
352    ACPI_EXDUMP_INFO        *Info)
353{
354    UINT8                   *Target;
355    char                    *Name;
356    UINT8                   Count;
357
358
359    if (!Info)
360    {
361        AcpiOsPrintf (
362            "ExDumpObject: Display not implemented for object type %s\n",
363            AcpiUtGetObjectTypeName (ObjDesc));
364        return;
365    }
366
367    /* First table entry must contain the table length (# of table entries) */
368
369    Count = Info->Offset;
370
371    while (Count)
372    {
373        Target = ACPI_ADD_PTR (UINT8, ObjDesc, Info->Offset);
374        Name = Info->Name;
375
376        switch (Info->Opcode)
377        {
378        case ACPI_EXD_INIT:
379            break;
380
381        case ACPI_EXD_TYPE:
382
383            AcpiExOutString  ("Type", AcpiUtGetObjectTypeName (ObjDesc));
384            break;
385
386        case ACPI_EXD_UINT8:
387
388            AcpiOsPrintf ("%20s : %2.2X\n", Name, *Target);
389            break;
390
391        case ACPI_EXD_UINT16:
392
393            AcpiOsPrintf ("%20s : %4.4X\n", Name, ACPI_GET16 (Target));
394            break;
395
396        case ACPI_EXD_UINT32:
397
398            AcpiOsPrintf ("%20s : %8.8X\n", Name, ACPI_GET32 (Target));
399            break;
400
401        case ACPI_EXD_UINT64:
402
403            AcpiOsPrintf ("%20s : %8.8X%8.8X\n", "Value",
404                ACPI_FORMAT_UINT64 (ACPI_GET64 (Target)));
405            break;
406
407        case ACPI_EXD_POINTER:
408        case ACPI_EXD_ADDRESS:
409
410            AcpiExOutPointer (Name, *ACPI_CAST_PTR (void *, Target));
411            break;
412
413        case ACPI_EXD_STRING:
414
415            AcpiUtPrintString (ObjDesc->String.Pointer, ACPI_UINT8_MAX);
416            AcpiOsPrintf ("\n");
417            break;
418
419        case ACPI_EXD_BUFFER:
420
421            ACPI_DUMP_BUFFER (ObjDesc->Buffer.Pointer, ObjDesc->Buffer.Length);
422            break;
423
424        case ACPI_EXD_PACKAGE:
425
426            /* Dump the package contents */
427
428            AcpiOsPrintf ("\nPackage Contents:\n");
429            AcpiExDumpPackageObj (ObjDesc, 0, 0);
430            break;
431
432        case ACPI_EXD_FIELD:
433
434            AcpiExDumpObject (ObjDesc, AcpiExDumpFieldCommon);
435            break;
436
437        case ACPI_EXD_REFERENCE:
438
439            AcpiExOutString ("Class Name",
440                ACPI_CAST_PTR (char, AcpiUtGetReferenceName (ObjDesc)));
441            AcpiExDumpReferenceObj (ObjDesc);
442            break;
443
444        default:
445
446            AcpiOsPrintf ("**** Invalid table opcode [%X] ****\n",
447                Info->Opcode);
448            return;
449        }
450
451        Info++;
452        Count--;
453    }
454}
455
456
457/*******************************************************************************
458 *
459 * FUNCTION:    AcpiExDumpOperand
460 *
461 * PARAMETERS:  *ObjDesc        - Pointer to entry to be dumped
462 *              Depth           - Current nesting depth
463 *
464 * RETURN:      None
465 *
466 * DESCRIPTION: Dump an operand object
467 *
468 ******************************************************************************/
469
470void
471AcpiExDumpOperand (
472    ACPI_OPERAND_OBJECT     *ObjDesc,
473    UINT32                  Depth)
474{
475    UINT32                  Length;
476    UINT32                  Index;
477
478
479    ACPI_FUNCTION_NAME (ExDumpOperand)
480
481
482    if (!((ACPI_LV_EXEC & AcpiDbgLevel) && (_COMPONENT & AcpiDbgLayer)))
483    {
484        return;
485    }
486
487    if (!ObjDesc)
488    {
489        /* This could be a null element of a package */
490
491        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Null Object Descriptor\n"));
492        return;
493    }
494
495    if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
496    {
497        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p Namespace Node: ", ObjDesc));
498        ACPI_DUMP_ENTRY (ObjDesc, ACPI_LV_EXEC);
499        return;
500    }
501
502    if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
503    {
504        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
505            "%p is not a node or operand object: [%s]\n",
506            ObjDesc, AcpiUtGetDescriptorName (ObjDesc)));
507        ACPI_DUMP_BUFFER (ObjDesc, sizeof (ACPI_OPERAND_OBJECT));
508        return;
509    }
510
511    /* ObjDesc is a valid object */
512
513    if (Depth > 0)
514    {
515        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%*s[%u] %p ",
516            Depth, " ", Depth, ObjDesc));
517    }
518    else
519    {
520        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%p ", ObjDesc));
521    }
522
523    /* Decode object type */
524
525    switch (ObjDesc->Common.Type)
526    {
527    case ACPI_TYPE_LOCAL_REFERENCE:
528
529        AcpiOsPrintf ("Reference: [%s] ", AcpiUtGetReferenceName (ObjDesc));
530
531        switch (ObjDesc->Reference.Class)
532        {
533        case ACPI_REFCLASS_DEBUG:
534
535            AcpiOsPrintf ("\n");
536            break;
537
538
539        case ACPI_REFCLASS_INDEX:
540
541            AcpiOsPrintf ("%p\n", ObjDesc->Reference.Object);
542            break;
543
544
545        case ACPI_REFCLASS_TABLE:
546
547            AcpiOsPrintf ("Table Index %X\n", ObjDesc->Reference.Value);
548            break;
549
550
551        case ACPI_REFCLASS_REFOF:
552
553            AcpiOsPrintf ("%p [%s]\n", ObjDesc->Reference.Object,
554                AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT *)
555                    ObjDesc->Reference.Object)->Common.Type));
556            break;
557
558
559        case ACPI_REFCLASS_NAME:
560
561            AcpiOsPrintf ("- [%4.4s]\n", ObjDesc->Reference.Node->Name.Ascii);
562            break;
563
564
565        case ACPI_REFCLASS_ARG:
566        case ACPI_REFCLASS_LOCAL:
567
568            AcpiOsPrintf ("%X\n", ObjDesc->Reference.Value);
569            break;
570
571
572        default:    /* Unknown reference class */
573
574            AcpiOsPrintf ("%2.2X\n", ObjDesc->Reference.Class);
575            break;
576        }
577        break;
578
579
580    case ACPI_TYPE_BUFFER:
581
582        AcpiOsPrintf ("Buffer length %.2X @ %p\n",
583            ObjDesc->Buffer.Length, ObjDesc->Buffer.Pointer);
584
585        /* Debug only -- dump the buffer contents */
586
587        if (ObjDesc->Buffer.Pointer)
588        {
589            Length = ObjDesc->Buffer.Length;
590            if (Length > 128)
591            {
592                Length = 128;
593            }
594
595            AcpiOsPrintf ("Buffer Contents: (displaying length 0x%.2X)\n",
596                Length);
597            ACPI_DUMP_BUFFER (ObjDesc->Buffer.Pointer, Length);
598        }
599        break;
600
601
602    case ACPI_TYPE_INTEGER:
603
604        AcpiOsPrintf ("Integer %8.8X%8.8X\n",
605            ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
606        break;
607
608
609    case ACPI_TYPE_PACKAGE:
610
611        AcpiOsPrintf ("Package [Len %X] ElementArray %p\n",
612            ObjDesc->Package.Count, ObjDesc->Package.Elements);
613
614        /*
615         * If elements exist, package element pointer is valid,
616         * and debug_level exceeds 1, dump package's elements.
617         */
618        if (ObjDesc->Package.Count &&
619            ObjDesc->Package.Elements &&
620            AcpiDbgLevel > 1)
621        {
622            for (Index = 0; Index < ObjDesc->Package.Count; Index++)
623            {
624                AcpiExDumpOperand (ObjDesc->Package.Elements[Index], Depth+1);
625            }
626        }
627        break;
628
629
630    case ACPI_TYPE_REGION:
631
632        AcpiOsPrintf ("Region %s (%X)",
633            AcpiUtGetRegionName (ObjDesc->Region.SpaceId),
634            ObjDesc->Region.SpaceId);
635
636        /*
637         * If the address and length have not been evaluated,
638         * don't print them.
639         */
640        if (!(ObjDesc->Region.Flags & AOPOBJ_DATA_VALID))
641        {
642            AcpiOsPrintf ("\n");
643        }
644        else
645        {
646            AcpiOsPrintf (" base %8.8X%8.8X Length %X\n",
647                ACPI_FORMAT_NATIVE_UINT (ObjDesc->Region.Address),
648                ObjDesc->Region.Length);
649        }
650        break;
651
652
653    case ACPI_TYPE_STRING:
654
655        AcpiOsPrintf ("String length %X @ %p ",
656            ObjDesc->String.Length,
657            ObjDesc->String.Pointer);
658
659        AcpiUtPrintString (ObjDesc->String.Pointer, ACPI_UINT8_MAX);
660        AcpiOsPrintf ("\n");
661        break;
662
663
664    case ACPI_TYPE_LOCAL_BANK_FIELD:
665
666        AcpiOsPrintf ("BankField\n");
667        break;
668
669
670    case ACPI_TYPE_LOCAL_REGION_FIELD:
671
672        AcpiOsPrintf ("RegionField: Bits=%X AccWidth=%X Lock=%X Update=%X at "
673            "byte=%X bit=%X of below:\n",
674            ObjDesc->Field.BitLength,
675            ObjDesc->Field.AccessByteWidth,
676            ObjDesc->Field.FieldFlags & AML_FIELD_LOCK_RULE_MASK,
677            ObjDesc->Field.FieldFlags & AML_FIELD_UPDATE_RULE_MASK,
678            ObjDesc->Field.BaseByteOffset,
679            ObjDesc->Field.StartFieldBitOffset);
680
681        AcpiExDumpOperand (ObjDesc->Field.RegionObj, Depth+1);
682        break;
683
684
685    case ACPI_TYPE_LOCAL_INDEX_FIELD:
686
687        AcpiOsPrintf ("IndexField\n");
688        break;
689
690
691    case ACPI_TYPE_BUFFER_FIELD:
692
693        AcpiOsPrintf ("BufferField: %X bits at byte %X bit %X of\n",
694            ObjDesc->BufferField.BitLength,
695            ObjDesc->BufferField.BaseByteOffset,
696            ObjDesc->BufferField.StartFieldBitOffset);
697
698        if (!ObjDesc->BufferField.BufferObj)
699        {
700            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*NULL*\n"));
701        }
702        else if ((ObjDesc->BufferField.BufferObj)->Common.Type !=
703                    ACPI_TYPE_BUFFER)
704        {
705            AcpiOsPrintf ("*not a Buffer*\n");
706        }
707        else
708        {
709            AcpiExDumpOperand (ObjDesc->BufferField.BufferObj, Depth+1);
710        }
711        break;
712
713
714    case ACPI_TYPE_EVENT:
715
716        AcpiOsPrintf ("Event\n");
717        break;
718
719
720    case ACPI_TYPE_METHOD:
721
722        AcpiOsPrintf ("Method(%X) @ %p:%X\n",
723            ObjDesc->Method.ParamCount,
724            ObjDesc->Method.AmlStart,
725            ObjDesc->Method.AmlLength);
726        break;
727
728
729    case ACPI_TYPE_MUTEX:
730
731        AcpiOsPrintf ("Mutex\n");
732        break;
733
734
735    case ACPI_TYPE_DEVICE:
736
737        AcpiOsPrintf ("Device\n");
738        break;
739
740
741    case ACPI_TYPE_POWER:
742
743        AcpiOsPrintf ("Power\n");
744        break;
745
746
747    case ACPI_TYPE_PROCESSOR:
748
749        AcpiOsPrintf ("Processor\n");
750        break;
751
752
753    case ACPI_TYPE_THERMAL:
754
755        AcpiOsPrintf ("Thermal\n");
756        break;
757
758
759    default:
760        /* Unknown Type */
761
762        AcpiOsPrintf ("Unknown Type %X\n", ObjDesc->Common.Type);
763        break;
764    }
765
766    return;
767}
768
769
770/*******************************************************************************
771 *
772 * FUNCTION:    AcpiExDumpOperands
773 *
774 * PARAMETERS:  Operands            - A list of Operand objects
775 *              OpcodeName          - AML opcode name
776 *              NumOperands         - Operand count for this opcode
777 *
778 * DESCRIPTION: Dump the operands associated with the opcode
779 *
780 ******************************************************************************/
781
782void
783AcpiExDumpOperands (
784    ACPI_OPERAND_OBJECT     **Operands,
785    const char              *OpcodeName,
786    UINT32                  NumOperands)
787{
788    ACPI_FUNCTION_NAME (ExDumpOperands);
789
790
791    if (!OpcodeName)
792    {
793        OpcodeName = "UNKNOWN";
794    }
795
796    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
797        "**** Start operand dump for opcode [%s], %u operands\n",
798        OpcodeName, NumOperands));
799
800    if (NumOperands == 0)
801    {
802        NumOperands = 1;
803    }
804
805    /* Dump the individual operands */
806
807    while (NumOperands)
808    {
809        AcpiExDumpOperand (*Operands, 0);
810        Operands++;
811        NumOperands--;
812    }
813
814    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
815        "**** End operand dump for [%s]\n", OpcodeName));
816    return;
817}
818
819
820/*******************************************************************************
821 *
822 * FUNCTION:    AcpiExOut* functions
823 *
824 * PARAMETERS:  Title               - Descriptive text
825 *              Value               - Value to be displayed
826 *
827 * DESCRIPTION: Object dump output formatting functions.  These functions
828 *              reduce the number of format strings required and keeps them
829 *              all in one place for easy modification.
830 *
831 ******************************************************************************/
832
833static void
834AcpiExOutString (
835    char                    *Title,
836    char                    *Value)
837{
838    AcpiOsPrintf ("%20s : %s\n", Title, Value);
839}
840
841static void
842AcpiExOutPointer (
843    char                    *Title,
844    void                    *Value)
845{
846    AcpiOsPrintf ("%20s : %p\n", Title, Value);
847}
848
849
850/*******************************************************************************
851 *
852 * FUNCTION:    AcpiExDumpNamespaceNode
853 *
854 * PARAMETERS:  Node                - Descriptor to dump
855 *              Flags               - Force display if TRUE
856 *
857 * DESCRIPTION: Dumps the members of the given.Node
858 *
859 ******************************************************************************/
860
861void
862AcpiExDumpNamespaceNode (
863    ACPI_NAMESPACE_NODE     *Node,
864    UINT32                  Flags)
865{
866
867    ACPI_FUNCTION_ENTRY ();
868
869
870    if (!Flags)
871    {
872        if (!((ACPI_LV_OBJECTS & AcpiDbgLevel) && (_COMPONENT & AcpiDbgLayer)))
873        {
874            return;
875        }
876    }
877
878    AcpiOsPrintf ("%20s : %4.4s\n", "Name", AcpiUtGetNodeName (Node));
879    AcpiExOutString  ("Type", AcpiUtGetTypeName (Node->Type));
880    AcpiExOutPointer ("Attached Object", AcpiNsGetAttachedObject (Node));
881    AcpiExOutPointer ("Parent", Node->Parent);
882
883    AcpiExDumpObject (ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node),
884        AcpiExDumpNode);
885}
886
887
888/*******************************************************************************
889 *
890 * FUNCTION:    AcpiExDumpReferenceObj
891 *
892 * PARAMETERS:  Object              - Descriptor to dump
893 *
894 * DESCRIPTION: Dumps a reference object
895 *
896 ******************************************************************************/
897
898static void
899AcpiExDumpReferenceObj (
900    ACPI_OPERAND_OBJECT     *ObjDesc)
901{
902    ACPI_BUFFER             RetBuf;
903    ACPI_STATUS             Status;
904
905
906    RetBuf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
907
908    if (ObjDesc->Reference.Class == ACPI_REFCLASS_NAME)
909    {
910        AcpiOsPrintf (" %p ", ObjDesc->Reference.Node);
911
912        Status = AcpiNsHandleToPathname (ObjDesc->Reference.Node, &RetBuf);
913        if (ACPI_FAILURE (Status))
914        {
915            AcpiOsPrintf (" Could not convert name to pathname\n");
916        }
917        else
918        {
919           AcpiOsPrintf ("%s\n", (char *) RetBuf.Pointer);
920           ACPI_FREE (RetBuf.Pointer);
921        }
922    }
923    else if (ObjDesc->Reference.Object)
924    {
925        if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)
926        {
927            AcpiOsPrintf (" Target: %p", ObjDesc->Reference.Object);
928            if (ObjDesc->Reference.Class == ACPI_REFCLASS_TABLE)
929            {
930                AcpiOsPrintf (" Table Index: %X\n", ObjDesc->Reference.Value);
931            }
932            else
933            {
934                AcpiOsPrintf (" Target: %p [%s]\n", ObjDesc->Reference.Object,
935                    AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT *)
936                        ObjDesc->Reference.Object)->Common.Type));
937            }
938        }
939        else
940        {
941            AcpiOsPrintf (" Target: %p\n", ObjDesc->Reference.Object);
942        }
943    }
944}
945
946
947/*******************************************************************************
948 *
949 * FUNCTION:    AcpiExDumpPackageObj
950 *
951 * PARAMETERS:  ObjDesc             - Descriptor to dump
952 *              Level               - Indentation Level
953 *              Index               - Package index for this object
954 *
955 * DESCRIPTION: Dumps the elements of the package
956 *
957 ******************************************************************************/
958
959static void
960AcpiExDumpPackageObj (
961    ACPI_OPERAND_OBJECT     *ObjDesc,
962    UINT32                  Level,
963    UINT32                  Index)
964{
965    UINT32                  i;
966
967
968    /* Indentation and index output */
969
970    if (Level > 0)
971    {
972        for (i = 0; i < Level; i++)
973        {
974            AcpiOsPrintf ("  ");
975        }
976
977        AcpiOsPrintf ("[%.2d] ", Index);
978    }
979
980    AcpiOsPrintf ("%p ", ObjDesc);
981
982    /* Null package elements are allowed */
983
984    if (!ObjDesc)
985    {
986        AcpiOsPrintf ("[Null Object]\n");
987        return;
988    }
989
990    /* Packages may only contain a few object types */
991
992    switch (ObjDesc->Common.Type)
993    {
994    case ACPI_TYPE_INTEGER:
995
996        AcpiOsPrintf ("[Integer] = %8.8X%8.8X\n",
997            ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
998        break;
999
1000
1001    case ACPI_TYPE_STRING:
1002
1003        AcpiOsPrintf ("[String]  Value: ");
1004        for (i = 0; i < ObjDesc->String.Length; i++)
1005        {
1006            AcpiOsPrintf ("%c", ObjDesc->String.Pointer[i]);
1007        }
1008        AcpiOsPrintf ("\n");
1009        break;
1010
1011
1012    case ACPI_TYPE_BUFFER:
1013
1014        AcpiOsPrintf ("[Buffer] Length %.2X = ", ObjDesc->Buffer.Length);
1015        if (ObjDesc->Buffer.Length)
1016        {
1017            AcpiUtDumpBuffer (ACPI_CAST_PTR (UINT8, ObjDesc->Buffer.Pointer),
1018                ObjDesc->Buffer.Length, DB_DWORD_DISPLAY, _COMPONENT);
1019        }
1020        else
1021        {
1022            AcpiOsPrintf ("\n");
1023        }
1024        break;
1025
1026
1027    case ACPI_TYPE_PACKAGE:
1028
1029        AcpiOsPrintf ("[Package] Contains %u Elements:\n",
1030            ObjDesc->Package.Count);
1031
1032        for (i = 0; i < ObjDesc->Package.Count; i++)
1033        {
1034            AcpiExDumpPackageObj (ObjDesc->Package.Elements[i], Level+1, i);
1035        }
1036        break;
1037
1038
1039    case ACPI_TYPE_LOCAL_REFERENCE:
1040
1041        AcpiOsPrintf ("[Object Reference] Type [%s] %2.2X",
1042            AcpiUtGetReferenceName (ObjDesc),
1043            ObjDesc->Reference.Class);
1044        AcpiExDumpReferenceObj (ObjDesc);
1045        break;
1046
1047
1048    default:
1049
1050        AcpiOsPrintf ("[Unknown Type] %X\n", ObjDesc->Common.Type);
1051        break;
1052    }
1053}
1054
1055
1056/*******************************************************************************
1057 *
1058 * FUNCTION:    AcpiExDumpObjectDescriptor
1059 *
1060 * PARAMETERS:  ObjDesc             - Descriptor to dump
1061 *              Flags               - Force display if TRUE
1062 *
1063 * DESCRIPTION: Dumps the members of the object descriptor given.
1064 *
1065 ******************************************************************************/
1066
1067void
1068AcpiExDumpObjectDescriptor (
1069    ACPI_OPERAND_OBJECT     *ObjDesc,
1070    UINT32                  Flags)
1071{
1072    ACPI_FUNCTION_TRACE (ExDumpObjectDescriptor);
1073
1074
1075    if (!ObjDesc)
1076    {
1077        return_VOID;
1078    }
1079
1080    if (!Flags)
1081    {
1082        if (!((ACPI_LV_OBJECTS & AcpiDbgLevel) && (_COMPONENT & AcpiDbgLayer)))
1083        {
1084            return_VOID;
1085        }
1086    }
1087
1088    if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED)
1089    {
1090        AcpiExDumpNamespaceNode ((ACPI_NAMESPACE_NODE *) ObjDesc, Flags);
1091
1092        AcpiOsPrintf ("\nAttached Object (%p):\n",
1093            ((ACPI_NAMESPACE_NODE *) ObjDesc)->Object);
1094
1095        AcpiExDumpObjectDescriptor (
1096            ((ACPI_NAMESPACE_NODE *) ObjDesc)->Object, Flags);
1097        return_VOID;
1098    }
1099
1100    if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
1101    {
1102        AcpiOsPrintf (
1103            "ExDumpObjectDescriptor: %p is not an ACPI operand object: [%s]\n",
1104            ObjDesc, AcpiUtGetDescriptorName (ObjDesc));
1105        return_VOID;
1106    }
1107
1108    if (ObjDesc->Common.Type > ACPI_TYPE_NS_NODE_MAX)
1109    {
1110        return_VOID;
1111    }
1112
1113    /* Common Fields */
1114
1115    AcpiExDumpObject (ObjDesc, AcpiExDumpCommon);
1116
1117    /* Object-specific fields */
1118
1119    AcpiExDumpObject (ObjDesc, AcpiExDumpInfo[ObjDesc->Common.Type]);
1120    return_VOID;
1121}
1122
1123#endif
1124
1125