xref: /freebsd/sys/contrib/dev/acpica/components/resources/rsdump.c (revision 8a166cafe0965f6bd72cd3d2f5372704f05cb5e8)
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 
59 static void
60 AcpiRsOutString (
61     char                    *Title,
62     char                    *Value);
63 
64 static void
65 AcpiRsOutInteger8 (
66     char                    *Title,
67     UINT8                   Value);
68 
69 static void
70 AcpiRsOutInteger16 (
71     char                    *Title,
72     UINT16                  Value);
73 
74 static void
75 AcpiRsOutInteger32 (
76     char                    *Title,
77     UINT32                  Value);
78 
79 static void
80 AcpiRsOutInteger64 (
81     char                    *Title,
82     UINT64                  Value);
83 
84 static void
85 AcpiRsOutTitle (
86     char                    *Title);
87 
88 static void
89 AcpiRsDumpByteList (
90     UINT16                  Length,
91     UINT8                   *Data);
92 
93 static void
94 AcpiRsDumpWordList (
95     UINT16                   Length,
96     UINT16                   *Data);
97 
98 static void
99 AcpiRsDumpDwordList (
100     UINT8                   Length,
101     UINT32                  *Data);
102 
103 static void
104 AcpiRsDumpShortByteList (
105     UINT8                  Length,
106     UINT8                  *Data);
107 
108 static void
109 AcpiRsDumpResourceSource (
110     ACPI_RESOURCE_SOURCE    *ResourceSource);
111 
112 static void
113 AcpiRsDumpAddressCommon (
114     ACPI_RESOURCE_DATA      *Resource);
115 
116 static void
117 AcpiRsDumpDescriptor (
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 
135 static void
136 AcpiRsDumpDescriptor (
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 
320 static void
321 AcpiRsDumpResourceSource (
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 
354 static void
355 AcpiRsDumpAddressCommon (
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 
405 void
406 AcpiRsDumpResourceList (
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         /* Dump the resource descriptor */
442 
443         if (Type == ACPI_RESOURCE_TYPE_SERIAL_BUS)
444         {
445             AcpiRsDumpDescriptor (&ResourceList->Data,
446                 AcpiGbl_DumpSerialBusDispatch[ResourceList->Data.CommonSerialBus.Type]);
447         }
448         else
449         {
450             AcpiRsDumpDescriptor (&ResourceList->Data,
451                 AcpiGbl_DumpResourceDispatch[Type]);
452         }
453 
454         /* Point to the next resource structure */
455 
456         ResourceList = ACPI_NEXT_RESOURCE (ResourceList);
457 
458         /* Exit when END_TAG descriptor is reached */
459 
460     } while (Type != ACPI_RESOURCE_TYPE_END_TAG);
461 }
462 
463 
464 /*******************************************************************************
465  *
466  * FUNCTION:    AcpiRsDumpIrqList
467  *
468  * PARAMETERS:  RouteTable      - Pointer to the routing table to dump.
469  *
470  * RETURN:      None
471  *
472  * DESCRIPTION: Print IRQ routing table
473  *
474  ******************************************************************************/
475 
476 void
477 AcpiRsDumpIrqList (
478     UINT8                   *RouteTable)
479 {
480     ACPI_PCI_ROUTING_TABLE  *PrtElement;
481     UINT8                   Count;
482 
483 
484     ACPI_FUNCTION_ENTRY ();
485 
486 
487     /* Check if debug output enabled */
488 
489     if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_RESOURCES, _COMPONENT))
490     {
491         return;
492     }
493 
494     PrtElement = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, RouteTable);
495 
496     /* Dump all table elements, Exit on zero length element */
497 
498     for (Count = 0; PrtElement->Length; Count++)
499     {
500         AcpiOsPrintf ("\n[%02X] PCI IRQ Routing Table Package\n", Count);
501         AcpiRsDumpDescriptor (PrtElement, AcpiRsDumpPrt);
502 
503         PrtElement = ACPI_ADD_PTR (ACPI_PCI_ROUTING_TABLE,
504                         PrtElement, PrtElement->Length);
505     }
506 }
507 
508 
509 /*******************************************************************************
510  *
511  * FUNCTION:    AcpiRsOut*
512  *
513  * PARAMETERS:  Title       - Name of the resource field
514  *              Value       - Value of the resource field
515  *
516  * RETURN:      None
517  *
518  * DESCRIPTION: Miscellaneous helper functions to consistently format the
519  *              output of the resource dump routines
520  *
521  ******************************************************************************/
522 
523 static void
524 AcpiRsOutString (
525     char                    *Title,
526     char                    *Value)
527 {
528     AcpiOsPrintf ("%27s : %s", Title, Value);
529     if (!*Value)
530     {
531         AcpiOsPrintf ("[NULL NAMESTRING]");
532     }
533     AcpiOsPrintf ("\n");
534 }
535 
536 static void
537 AcpiRsOutInteger8 (
538     char                    *Title,
539     UINT8                   Value)
540 {
541     AcpiOsPrintf ("%27s : %2.2X\n", Title, Value);
542 }
543 
544 static void
545 AcpiRsOutInteger16 (
546     char                    *Title,
547     UINT16                  Value)
548 {
549     AcpiOsPrintf ("%27s : %4.4X\n", Title, Value);
550 }
551 
552 static void
553 AcpiRsOutInteger32 (
554     char                    *Title,
555     UINT32                  Value)
556 {
557     AcpiOsPrintf ("%27s : %8.8X\n", Title, Value);
558 }
559 
560 static void
561 AcpiRsOutInteger64 (
562     char                    *Title,
563     UINT64                  Value)
564 {
565     AcpiOsPrintf ("%27s : %8.8X%8.8X\n", Title,
566         ACPI_FORMAT_UINT64 (Value));
567 }
568 
569 static void
570 AcpiRsOutTitle (
571     char                    *Title)
572 {
573     AcpiOsPrintf ("%27s : ", Title);
574 }
575 
576 
577 /*******************************************************************************
578  *
579  * FUNCTION:    AcpiRsDump*List
580  *
581  * PARAMETERS:  Length      - Number of elements in the list
582  *              Data        - Start of the list
583  *
584  * RETURN:      None
585  *
586  * DESCRIPTION: Miscellaneous functions to dump lists of raw data
587  *
588  ******************************************************************************/
589 
590 static void
591 AcpiRsDumpByteList (
592     UINT16                  Length,
593     UINT8                   *Data)
594 {
595     UINT8                   i;
596 
597 
598     for (i = 0; i < Length; i++)
599     {
600         AcpiOsPrintf ("%25s%2.2X : %2.2X\n",
601             "Byte", i, Data[i]);
602     }
603 }
604 
605 static void
606 AcpiRsDumpShortByteList (
607     UINT8                  Length,
608     UINT8                  *Data)
609 {
610     UINT8                   i;
611 
612 
613     for (i = 0; i < Length; i++)
614     {
615         AcpiOsPrintf ("%X ", Data[i]);
616     }
617     AcpiOsPrintf ("\n");
618 }
619 
620 static void
621 AcpiRsDumpDwordList (
622     UINT8                   Length,
623     UINT32                  *Data)
624 {
625     UINT8                   i;
626 
627 
628     for (i = 0; i < Length; i++)
629     {
630         AcpiOsPrintf ("%25s%2.2X : %8.8X\n",
631             "Dword", i, Data[i]);
632     }
633 }
634 
635 static void
636 AcpiRsDumpWordList (
637     UINT16                  Length,
638     UINT16                  *Data)
639 {
640     UINT16                  i;
641 
642 
643     for (i = 0; i < Length; i++)
644     {
645         AcpiOsPrintf ("%25s%2.2X : %4.4X\n",
646             "Word", i, Data[i]);
647     }
648 }
649 
650 #endif
651