rsdump.c revision 246849
1/*******************************************************************************
2 *
3 * Module Name: rsdump - Functions to display the resource structures.
4 *
5 ******************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2013, 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
45#define __RSDUMP_C__
46
47#include <contrib/dev/acpica/include/acpi.h>
48#include <contrib/dev/acpica/include/accommon.h>
49#include <contrib/dev/acpica/include/acresrc.h>
50
51#define _COMPONENT          ACPI_RESOURCES
52        ACPI_MODULE_NAME    ("rsdump")
53
54
55#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56
57/* Local prototypes */
58
59static void
60AcpiRsOutString (
61    char                    *Title,
62    char                    *Value);
63
64static void
65AcpiRsOutInteger8 (
66    char                    *Title,
67    UINT8                   Value);
68
69static void
70AcpiRsOutInteger16 (
71    char                    *Title,
72    UINT16                  Value);
73
74static void
75AcpiRsOutInteger32 (
76    char                    *Title,
77    UINT32                  Value);
78
79static void
80AcpiRsOutInteger64 (
81    char                    *Title,
82    UINT64                  Value);
83
84static void
85AcpiRsOutTitle (
86    char                    *Title);
87
88static void
89AcpiRsDumpByteList (
90    UINT16                  Length,
91    UINT8                   *Data);
92
93static void
94AcpiRsDumpWordList (
95    UINT16                   Length,
96    UINT16                   *Data);
97
98static void
99AcpiRsDumpDwordList (
100    UINT8                   Length,
101    UINT32                  *Data);
102
103static void
104AcpiRsDumpShortByteList (
105    UINT8                  Length,
106    UINT8                  *Data);
107
108static void
109AcpiRsDumpResourceSource (
110    ACPI_RESOURCE_SOURCE    *ResourceSource);
111
112static void
113AcpiRsDumpAddressCommon (
114    ACPI_RESOURCE_DATA      *Resource);
115
116static void
117AcpiRsDumpDescriptor (
118    void                    *Resource,
119    ACPI_RSDUMP_INFO *Table);
120
121
122/*******************************************************************************
123 *
124 * FUNCTION:    AcpiRsDumpDescriptor
125 *
126 * PARAMETERS:  Resource            - Buffer containing the resource
127 *              Table               - Table entry to decode the resource
128 *
129 * RETURN:      None
130 *
131 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
132 *
133 ******************************************************************************/
134
135static void
136AcpiRsDumpDescriptor (
137    void                    *Resource,
138    ACPI_RSDUMP_INFO        *Table)
139{
140    UINT8                   *Target = NULL;
141    UINT8                   *PreviousTarget;
142    char                    *Name;
143    UINT8                    Count;
144
145
146    /* First table entry must contain the table length (# of table entries) */
147
148    Count = Table->Offset;
149
150    while (Count)
151    {
152        PreviousTarget = Target;
153        Target = ACPI_ADD_PTR (UINT8, Resource, Table->Offset);
154        Name = Table->Name;
155
156        switch (Table->Opcode)
157        {
158        case ACPI_RSD_TITLE:
159            /*
160             * Optional resource title
161             */
162            if (Table->Name)
163            {
164                AcpiOsPrintf ("%s Resource\n", Name);
165            }
166            break;
167
168        /* Strings */
169
170        case ACPI_RSD_LITERAL:
171            AcpiRsOutString (Name, ACPI_CAST_PTR (char, Table->Pointer));
172            break;
173
174        case ACPI_RSD_STRING:
175            AcpiRsOutString (Name, ACPI_CAST_PTR (char, Target));
176            break;
177
178        /* Data items, 8/16/32/64 bit */
179
180        case ACPI_RSD_UINT8:
181            if (Table->Pointer)
182            {
183                AcpiRsOutString (Name, ACPI_CAST_PTR (char,
184                    Table->Pointer [*Target]));
185            }
186            else
187            {
188                AcpiRsOutInteger8 (Name, ACPI_GET8 (Target));
189            }
190            break;
191
192        case ACPI_RSD_UINT16:
193            AcpiRsOutInteger16 (Name, ACPI_GET16 (Target));
194            break;
195
196        case ACPI_RSD_UINT32:
197            AcpiRsOutInteger32 (Name, ACPI_GET32 (Target));
198            break;
199
200        case ACPI_RSD_UINT64:
201            AcpiRsOutInteger64 (Name, ACPI_GET64 (Target));
202            break;
203
204        /* Flags: 1-bit and 2-bit flags supported */
205
206        case ACPI_RSD_1BITFLAG:
207            AcpiRsOutString (Name, ACPI_CAST_PTR (char,
208                Table->Pointer [*Target & 0x01]));
209            break;
210
211        case ACPI_RSD_2BITFLAG:
212            AcpiRsOutString (Name, ACPI_CAST_PTR (char,
213                Table->Pointer [*Target & 0x03]));
214            break;
215
216        case ACPI_RSD_3BITFLAG:
217            AcpiRsOutString (Name, ACPI_CAST_PTR (char,
218                Table->Pointer [*Target & 0x07]));
219            break;
220
221        case ACPI_RSD_SHORTLIST:
222            /*
223             * Short byte list (single line output) for DMA and IRQ resources
224             * Note: The list length is obtained from the previous table entry
225             */
226            if (PreviousTarget)
227            {
228                AcpiRsOutTitle (Name);
229                AcpiRsDumpShortByteList (*PreviousTarget, Target);
230            }
231            break;
232
233        case ACPI_RSD_SHORTLISTX:
234            /*
235             * Short byte list (single line output) for GPIO vendor data
236             * Note: The list length is obtained from the previous table entry
237             */
238            if (PreviousTarget)
239            {
240                AcpiRsOutTitle (Name);
241                AcpiRsDumpShortByteList (*PreviousTarget,
242                    *(ACPI_CAST_INDIRECT_PTR (UINT8, Target)));
243            }
244            break;
245
246        case ACPI_RSD_LONGLIST:
247            /*
248             * Long byte list for Vendor resource data
249             * Note: The list length is obtained from the previous table entry
250             */
251            if (PreviousTarget)
252            {
253                AcpiRsDumpByteList (ACPI_GET16 (PreviousTarget), Target);
254            }
255            break;
256
257        case ACPI_RSD_DWORDLIST:
258            /*
259             * Dword list for Extended Interrupt resources
260             * Note: The list length is obtained from the previous table entry
261             */
262            if (PreviousTarget)
263            {
264                AcpiRsDumpDwordList (*PreviousTarget,
265                    ACPI_CAST_PTR (UINT32, Target));
266            }
267            break;
268
269        case ACPI_RSD_WORDLIST:
270            /*
271             * Word list for GPIO Pin Table
272             * Note: The list length is obtained from the previous table entry
273             */
274            if (PreviousTarget)
275            {
276                AcpiRsDumpWordList (*PreviousTarget,
277                    *(ACPI_CAST_INDIRECT_PTR (UINT16, Target)));
278            }
279            break;
280
281        case ACPI_RSD_ADDRESS:
282            /*
283             * Common flags for all Address resources
284             */
285            AcpiRsDumpAddressCommon (ACPI_CAST_PTR (ACPI_RESOURCE_DATA, Target));
286            break;
287
288        case ACPI_RSD_SOURCE:
289            /*
290             * Optional ResourceSource for Address resources
291             */
292            AcpiRsDumpResourceSource (ACPI_CAST_PTR (ACPI_RESOURCE_SOURCE, Target));
293            break;
294
295        default:
296            AcpiOsPrintf ("**** Invalid table opcode [%X] ****\n",
297                Table->Opcode);
298            return;
299        }
300
301        Table++;
302        Count--;
303    }
304}
305
306
307/*******************************************************************************
308 *
309 * FUNCTION:    AcpiRsDumpResourceSource
310 *
311 * PARAMETERS:  ResourceSource      - Pointer to a Resource Source struct
312 *
313 * RETURN:      None
314 *
315 * DESCRIPTION: Common routine for dumping the optional ResourceSource and the
316 *              corresponding ResourceSourceIndex.
317 *
318 ******************************************************************************/
319
320static void
321AcpiRsDumpResourceSource (
322    ACPI_RESOURCE_SOURCE    *ResourceSource)
323{
324    ACPI_FUNCTION_ENTRY ();
325
326
327    if (ResourceSource->Index == 0xFF)
328    {
329        return;
330    }
331
332    AcpiRsOutInteger8 ("Resource Source Index",
333        ResourceSource->Index);
334
335    AcpiRsOutString ("Resource Source",
336        ResourceSource->StringPtr ?
337            ResourceSource->StringPtr : "[Not Specified]");
338}
339
340
341/*******************************************************************************
342 *
343 * FUNCTION:    AcpiRsDumpAddressCommon
344 *
345 * PARAMETERS:  Resource        - Pointer to an internal resource descriptor
346 *
347 * RETURN:      None
348 *
349 * DESCRIPTION: Dump the fields that are common to all Address resource
350 *              descriptors
351 *
352 ******************************************************************************/
353
354static void
355AcpiRsDumpAddressCommon (
356    ACPI_RESOURCE_DATA      *Resource)
357{
358    ACPI_FUNCTION_ENTRY ();
359
360
361   /* Decode the type-specific flags */
362
363    switch (Resource->Address.ResourceType)
364    {
365    case ACPI_MEMORY_RANGE:
366
367        AcpiRsDumpDescriptor (Resource, AcpiRsDumpMemoryFlags);
368        break;
369
370    case ACPI_IO_RANGE:
371
372        AcpiRsDumpDescriptor (Resource, AcpiRsDumpIoFlags);
373        break;
374
375    case ACPI_BUS_NUMBER_RANGE:
376
377        AcpiRsOutString ("Resource Type", "Bus Number Range");
378        break;
379
380    default:
381
382        AcpiRsOutInteger8 ("Resource Type",
383            (UINT8) Resource->Address.ResourceType);
384        break;
385    }
386
387    /* Decode the general flags */
388
389    AcpiRsDumpDescriptor (Resource, AcpiRsDumpGeneralFlags);
390}
391
392
393/*******************************************************************************
394 *
395 * FUNCTION:    AcpiRsDumpResourceList
396 *
397 * PARAMETERS:  ResourceList        - Pointer to a resource descriptor list
398 *
399 * RETURN:      None
400 *
401 * DESCRIPTION: Dispatches the structure to the correct dump routine.
402 *
403 ******************************************************************************/
404
405void
406AcpiRsDumpResourceList (
407    ACPI_RESOURCE           *ResourceList)
408{
409    UINT32                  Count = 0;
410    UINT32                  Type;
411
412
413    ACPI_FUNCTION_ENTRY ();
414
415
416    /* Check if debug output enabled */
417
418    if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_RESOURCES, _COMPONENT))
419    {
420        return;
421    }
422
423    /* Walk list and dump all resource descriptors (END_TAG terminates) */
424
425    do
426    {
427        AcpiOsPrintf ("\n[%02X] ", Count);
428        Count++;
429
430        /* Validate Type before dispatch */
431
432        Type = ResourceList->Type;
433        if (Type > ACPI_RESOURCE_TYPE_MAX)
434        {
435            AcpiOsPrintf (
436                "Invalid descriptor type (%X) in resource list\n",
437                ResourceList->Type);
438            return;
439        }
440
441        /* Sanity check the length. It must not be zero, or we loop forever */
442
443        if (!ResourceList->Length)
444        {
445            AcpiOsPrintf (
446                "Invalid zero length descriptor in resource list\n");
447            return;
448        }
449
450        /* Dump the resource descriptor */
451
452        if (Type == ACPI_RESOURCE_TYPE_SERIAL_BUS)
453        {
454            AcpiRsDumpDescriptor (&ResourceList->Data,
455                AcpiGbl_DumpSerialBusDispatch[ResourceList->Data.CommonSerialBus.Type]);
456        }
457        else
458        {
459            AcpiRsDumpDescriptor (&ResourceList->Data,
460                AcpiGbl_DumpResourceDispatch[Type]);
461        }
462
463        /* Point to the next resource structure */
464
465        ResourceList = ACPI_NEXT_RESOURCE (ResourceList);
466
467        /* Exit when END_TAG descriptor is reached */
468
469    } while (Type != ACPI_RESOURCE_TYPE_END_TAG);
470}
471
472
473/*******************************************************************************
474 *
475 * FUNCTION:    AcpiRsDumpIrqList
476 *
477 * PARAMETERS:  RouteTable      - Pointer to the routing table to dump.
478 *
479 * RETURN:      None
480 *
481 * DESCRIPTION: Print IRQ routing table
482 *
483 ******************************************************************************/
484
485void
486AcpiRsDumpIrqList (
487    UINT8                   *RouteTable)
488{
489    ACPI_PCI_ROUTING_TABLE  *PrtElement;
490    UINT8                   Count;
491
492
493    ACPI_FUNCTION_ENTRY ();
494
495
496    /* Check if debug output enabled */
497
498    if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_RESOURCES, _COMPONENT))
499    {
500        return;
501    }
502
503    PrtElement = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, RouteTable);
504
505    /* Dump all table elements, Exit on zero length element */
506
507    for (Count = 0; PrtElement->Length; Count++)
508    {
509        AcpiOsPrintf ("\n[%02X] PCI IRQ Routing Table Package\n", Count);
510        AcpiRsDumpDescriptor (PrtElement, AcpiRsDumpPrt);
511
512        PrtElement = ACPI_ADD_PTR (ACPI_PCI_ROUTING_TABLE,
513                        PrtElement, PrtElement->Length);
514    }
515}
516
517
518/*******************************************************************************
519 *
520 * FUNCTION:    AcpiRsOut*
521 *
522 * PARAMETERS:  Title       - Name of the resource field
523 *              Value       - Value of the resource field
524 *
525 * RETURN:      None
526 *
527 * DESCRIPTION: Miscellaneous helper functions to consistently format the
528 *              output of the resource dump routines
529 *
530 ******************************************************************************/
531
532static void
533AcpiRsOutString (
534    char                    *Title,
535    char                    *Value)
536{
537    AcpiOsPrintf ("%27s : %s", Title, Value);
538    if (!*Value)
539    {
540        AcpiOsPrintf ("[NULL NAMESTRING]");
541    }
542    AcpiOsPrintf ("\n");
543}
544
545static void
546AcpiRsOutInteger8 (
547    char                    *Title,
548    UINT8                   Value)
549{
550    AcpiOsPrintf ("%27s : %2.2X\n", Title, Value);
551}
552
553static void
554AcpiRsOutInteger16 (
555    char                    *Title,
556    UINT16                  Value)
557{
558    AcpiOsPrintf ("%27s : %4.4X\n", Title, Value);
559}
560
561static void
562AcpiRsOutInteger32 (
563    char                    *Title,
564    UINT32                  Value)
565{
566    AcpiOsPrintf ("%27s : %8.8X\n", Title, Value);
567}
568
569static void
570AcpiRsOutInteger64 (
571    char                    *Title,
572    UINT64                  Value)
573{
574    AcpiOsPrintf ("%27s : %8.8X%8.8X\n", Title,
575        ACPI_FORMAT_UINT64 (Value));
576}
577
578static void
579AcpiRsOutTitle (
580    char                    *Title)
581{
582    AcpiOsPrintf ("%27s : ", Title);
583}
584
585
586/*******************************************************************************
587 *
588 * FUNCTION:    AcpiRsDump*List
589 *
590 * PARAMETERS:  Length      - Number of elements in the list
591 *              Data        - Start of the list
592 *
593 * RETURN:      None
594 *
595 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
596 *
597 ******************************************************************************/
598
599static void
600AcpiRsDumpByteList (
601    UINT16                  Length,
602    UINT8                   *Data)
603{
604    UINT8                   i;
605
606
607    for (i = 0; i < Length; i++)
608    {
609        AcpiOsPrintf ("%25s%2.2X : %2.2X\n",
610            "Byte", i, Data[i]);
611    }
612}
613
614static void
615AcpiRsDumpShortByteList (
616    UINT8                  Length,
617    UINT8                  *Data)
618{
619    UINT8                   i;
620
621
622    for (i = 0; i < Length; i++)
623    {
624        AcpiOsPrintf ("%X ", Data[i]);
625    }
626    AcpiOsPrintf ("\n");
627}
628
629static void
630AcpiRsDumpDwordList (
631    UINT8                   Length,
632    UINT32                  *Data)
633{
634    UINT8                   i;
635
636
637    for (i = 0; i < Length; i++)
638    {
639        AcpiOsPrintf ("%25s%2.2X : %8.8X\n",
640            "Dword", i, Data[i]);
641    }
642}
643
644static void
645AcpiRsDumpWordList (
646    UINT16                  Length,
647    UINT16                  *Data)
648{
649    UINT16                  i;
650
651
652    for (i = 0; i < Length; i++)
653    {
654        AcpiOsPrintf ("%25s%2.2X : %4.4X\n",
655            "Word", i, Data[i]);
656    }
657}
658
659#endif
660