1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: rsdump - AML debugger support for resource structures.
6 ******************************************************************************/
12 #define _COMPONENT ACPI_RESOURCES
13 ACPI_MODULE_NAME("rsdump")
16 * All functions in this module are used by the AML Debugger only
18 /* Local prototypes */
19 static void acpi_rs_out_string(const char *title, const char *value);
21 static void acpi_rs_out_integer8(const char *title, u8 value);
23 static void acpi_rs_out_integer16(const char *title, u16 value);
25 static void acpi_rs_out_integer32(const char *title, u32 value);
27 static void acpi_rs_out_integer64(const char *title, u64 value);
29 static void acpi_rs_out_title(const char *title);
31 static void acpi_rs_dump_byte_list(u16 length, u8 *data);
33 static void acpi_rs_dump_word_list(u16 length, u16 *data);
35 static void acpi_rs_dump_dword_list(u8 length, u32 *data);
37 static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
40 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
43 acpi_rs_dump_resource_label(char *title,
44 struct acpi_resource_label *resource_label);
46 static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
49 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
52 /*******************************************************************************
54 * FUNCTION: acpi_rs_dump_resource_list
56 * PARAMETERS: resource_list - Pointer to a resource descriptor list
60 * DESCRIPTION: Dispatches the structure to the correct dump routine.
62 ******************************************************************************/
64 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
69 ACPI_FUNCTION_ENTRY();
71 /* Check if debug output enabled */
73 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
77 /* Walk list and dump all resource descriptors (END_TAG terminates) */
80 acpi_os_printf("\n[%02X] ", count);
83 /* Validate Type before dispatch */
85 type = resource_list->type;
86 if (type > ACPI_RESOURCE_TYPE_MAX) {
88 ("Invalid descriptor type (%X) in resource list\n",
91 } else if (!resource_list->type) {
92 ACPI_ERROR((AE_INFO, "Invalid Zero Resource Type"));
96 /* Sanity check the length. It must not be zero, or we loop forever */
98 if (!resource_list->length) {
100 ("Invalid zero length descriptor in resource list\n");
104 /* Dump the resource descriptor */
106 if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
107 acpi_rs_dump_descriptor(&resource_list->data,
108 acpi_gbl_dump_serial_bus_dispatch
109 [resource_list->data.
110 common_serial_bus.type]);
112 acpi_rs_dump_descriptor(&resource_list->data,
113 acpi_gbl_dump_resource_dispatch
117 /* Point to the next resource structure */
119 resource_list = ACPI_NEXT_RESOURCE(resource_list);
121 /* Exit when END_TAG descriptor is reached */
123 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
126 /*******************************************************************************
128 * FUNCTION: acpi_rs_dump_irq_list
130 * PARAMETERS: route_table - Pointer to the routing table to dump.
134 * DESCRIPTION: Print IRQ routing table
136 ******************************************************************************/
138 void acpi_rs_dump_irq_list(u8 *route_table)
140 struct acpi_pci_routing_table *prt_element;
143 ACPI_FUNCTION_ENTRY();
145 /* Check if debug output enabled */
147 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
151 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
153 /* Dump all table elements, Exit on zero length element */
155 for (count = 0; prt_element->length; count++) {
156 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
158 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
160 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
161 prt_element, prt_element->length);
166 /*******************************************************************************
168 * FUNCTION: acpi_rs_dump_descriptor
170 * PARAMETERS: resource - Buffer containing the resource
171 * table - Table entry to decode the resource
175 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
177 ******************************************************************************/
180 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
187 /* First table entry must contain the table length (# of table entries) */
189 count = table->offset;
192 previous_target = target;
193 target = ACPI_ADD_PTR(u8, resource, table->offset);
196 switch (table->opcode) {
199 * Optional resource title
202 acpi_os_printf("%s Resource\n", name);
208 case ACPI_RSD_LITERAL:
210 acpi_rs_out_string(name,
211 ACPI_CAST_PTR(char, table->pointer));
214 case ACPI_RSD_STRING:
216 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
219 /* Data items, 8/16/32/64 bit */
223 if (table->pointer) {
224 acpi_rs_out_string(name,
225 table->pointer[*target]);
227 acpi_rs_out_integer8(name, ACPI_GET8(target));
231 case ACPI_RSD_UINT16:
233 acpi_rs_out_integer16(name, ACPI_GET16(target));
236 case ACPI_RSD_UINT32:
238 acpi_rs_out_integer32(name, ACPI_GET32(target));
241 case ACPI_RSD_UINT64:
243 acpi_rs_out_integer64(name, ACPI_GET64(target));
246 /* Flags: 1-bit and 2-bit flags supported */
248 case ACPI_RSD_1BITFLAG:
250 acpi_rs_out_string(name,
251 table->pointer[*target & 0x01]);
254 case ACPI_RSD_2BITFLAG:
256 acpi_rs_out_string(name,
257 table->pointer[*target & 0x03]);
260 case ACPI_RSD_3BITFLAG:
262 acpi_rs_out_string(name,
263 table->pointer[*target & 0x07]);
266 case ACPI_RSD_6BITFLAG:
268 acpi_rs_out_integer8(name, (ACPI_GET8(target) & 0x3F));
271 case ACPI_RSD_SHORTLIST:
273 * Short byte list (single line output) for DMA and IRQ resources
274 * Note: The list length is obtained from the previous table entry
276 if (previous_target) {
277 acpi_rs_out_title(name);
278 acpi_rs_dump_short_byte_list(*previous_target,
283 case ACPI_RSD_SHORTLISTX:
285 * Short byte list (single line output) for GPIO vendor data
286 * Note: The list length is obtained from the previous table entry
288 if (previous_target) {
289 acpi_rs_out_title(name);
290 acpi_rs_dump_short_byte_list(*previous_target,
292 (ACPI_CAST_INDIRECT_PTR
297 case ACPI_RSD_LONGLIST:
299 * Long byte list for Vendor resource data
300 * Note: The list length is obtained from the previous table entry
302 if (previous_target) {
303 acpi_rs_dump_byte_list(ACPI_GET16
309 case ACPI_RSD_DWORDLIST:
311 * Dword list for Extended Interrupt resources
312 * Note: The list length is obtained from the previous table entry
314 if (previous_target) {
315 acpi_rs_dump_dword_list(*previous_target,
321 case ACPI_RSD_WORDLIST:
323 * Word list for GPIO Pin Table
324 * Note: The list length is obtained from the previous table entry
326 if (previous_target) {
327 acpi_rs_dump_word_list(*previous_target,
328 *(ACPI_CAST_INDIRECT_PTR
333 case ACPI_RSD_ADDRESS:
335 * Common flags for all Address resources
337 acpi_rs_dump_address_common(ACPI_CAST_PTR
338 (union acpi_resource_data,
342 case ACPI_RSD_SOURCE:
344 * Optional resource_source for Address resources
346 acpi_rs_dump_resource_source(ACPI_CAST_PTR
348 acpi_resource_source,
356 acpi_rs_dump_resource_label("Resource Label",
362 case ACPI_RSD_SOURCE_LABEL:
364 * resource_source_label
366 acpi_rs_dump_resource_label("Resource Source Label",
374 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
384 /*******************************************************************************
386 * FUNCTION: acpi_rs_dump_resource_source
388 * PARAMETERS: resource_source - Pointer to a Resource Source struct
392 * DESCRIPTION: Common routine for dumping the optional resource_source and the
393 * corresponding resource_source_index.
395 ******************************************************************************/
398 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
400 ACPI_FUNCTION_ENTRY();
402 if (resource_source->index == 0xFF) {
406 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
408 acpi_rs_out_string("Resource Source",
409 resource_source->string_ptr ?
410 resource_source->string_ptr : "[Not Specified]");
413 /*******************************************************************************
415 * FUNCTION: acpi_rs_dump_resource_label
417 * PARAMETERS: title - Title of the dumped resource field
418 * resource_label - Pointer to a Resource Label struct
422 * DESCRIPTION: Common routine for dumping the resource_label
424 ******************************************************************************/
427 acpi_rs_dump_resource_label(char *title,
428 struct acpi_resource_label *resource_label)
430 ACPI_FUNCTION_ENTRY();
432 acpi_rs_out_string(title,
433 resource_label->string_ptr ?
434 resource_label->string_ptr : "[Not Specified]");
437 /*******************************************************************************
439 * FUNCTION: acpi_rs_dump_address_common
441 * PARAMETERS: resource - Pointer to an internal resource descriptor
445 * DESCRIPTION: Dump the fields that are common to all Address resource
448 ******************************************************************************/
450 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
452 ACPI_FUNCTION_ENTRY();
454 /* Decode the type-specific flags */
456 switch (resource->address.resource_type) {
457 case ACPI_MEMORY_RANGE:
459 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
464 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
467 case ACPI_BUS_NUMBER_RANGE:
469 acpi_rs_out_string("Resource Type", "Bus Number Range");
474 acpi_rs_out_integer8("Resource Type",
475 (u8) resource->address.resource_type);
479 /* Decode the general flags */
481 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
484 /*******************************************************************************
486 * FUNCTION: acpi_rs_out*
488 * PARAMETERS: title - Name of the resource field
489 * value - Value of the resource field
493 * DESCRIPTION: Miscellaneous helper functions to consistently format the
494 * output of the resource dump routines
496 ******************************************************************************/
498 static void acpi_rs_out_string(const char *title, const char *value)
501 acpi_os_printf("%27s : %s", title, value);
503 acpi_os_printf("[NULL NAMESTRING]");
505 acpi_os_printf("\n");
508 static void acpi_rs_out_integer8(const char *title, u8 value)
510 acpi_os_printf("%27s : %2.2X\n", title, value);
513 static void acpi_rs_out_integer16(const char *title, u16 value)
516 acpi_os_printf("%27s : %4.4X\n", title, value);
519 static void acpi_rs_out_integer32(const char *title, u32 value)
522 acpi_os_printf("%27s : %8.8X\n", title, value);
525 static void acpi_rs_out_integer64(const char *title, u64 value)
528 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
531 static void acpi_rs_out_title(const char *title)
534 acpi_os_printf("%27s : ", title);
537 /*******************************************************************************
539 * FUNCTION: acpi_rs_dump*List
541 * PARAMETERS: length - Number of elements in the list
542 * data - Start of the list
546 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
548 ******************************************************************************/
550 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
554 for (i = 0; i < length; i++) {
555 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
559 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
563 for (i = 0; i < length; i++) {
564 acpi_os_printf("%X ", data[i]);
567 acpi_os_printf("\n");
570 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
574 for (i = 0; i < length; i++) {
575 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
579 static void acpi_rs_dump_word_list(u16 length, u16 *data)
583 for (i = 0; i < length; i++) {
584 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);