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