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);
51 /*******************************************************************************
53 * FUNCTION: acpi_rs_dump_resource_list
55 * PARAMETERS: resource_list - Pointer to a resource descriptor list
59 * DESCRIPTION: Dispatches the structure to the correct dump routine.
61 ******************************************************************************/
63 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
68 ACPI_FUNCTION_ENTRY();
70 /* Check if debug output enabled */
72 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
76 /* Walk list and dump all resource descriptors (END_TAG terminates) */
79 acpi_os_printf("\n[%02X] ", count);
82 /* Validate Type before dispatch */
84 type = resource_list->type;
85 if (type > ACPI_RESOURCE_TYPE_MAX) {
87 ("Invalid descriptor type (%X) in resource list\n",
90 } else if (!resource_list->type) {
91 ACPI_ERROR((AE_INFO, "Invalid Zero Resource Type"));
95 /* Sanity check the length. It must not be zero, or we loop forever */
97 if (!resource_list->length) {
99 ("Invalid zero length descriptor in resource list\n");
103 /* Dump the resource descriptor */
105 if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
106 acpi_rs_dump_descriptor(&resource_list->data,
107 acpi_gbl_dump_serial_bus_dispatch
108 [resource_list->data.
109 common_serial_bus.type]);
111 acpi_rs_dump_descriptor(&resource_list->data,
112 acpi_gbl_dump_resource_dispatch
116 /* Point to the next resource structure */
118 resource_list = ACPI_NEXT_RESOURCE(resource_list);
120 /* Exit when END_TAG descriptor is reached */
122 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
125 /*******************************************************************************
127 * FUNCTION: acpi_rs_dump_irq_list
129 * PARAMETERS: route_table - Pointer to the routing table to dump.
133 * DESCRIPTION: Print IRQ routing table
135 ******************************************************************************/
137 void acpi_rs_dump_irq_list(u8 *route_table)
139 struct acpi_pci_routing_table *prt_element;
142 ACPI_FUNCTION_ENTRY();
144 /* Check if debug output enabled */
146 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
150 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
152 /* Dump all table elements, Exit on zero length element */
154 for (count = 0; prt_element->length; count++) {
155 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
157 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
159 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
160 prt_element, prt_element->length);
164 /*******************************************************************************
166 * FUNCTION: acpi_rs_dump_descriptor
168 * PARAMETERS: resource - Buffer containing the resource
169 * table - Table entry to decode the resource
173 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
175 ******************************************************************************/
178 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
185 /* First table entry must contain the table length (# of table entries) */
187 count = table->offset;
190 previous_target = target;
191 target = ACPI_ADD_PTR(u8, resource, table->offset);
194 switch (table->opcode) {
197 * Optional resource title
200 acpi_os_printf("%s Resource\n", name);
206 case ACPI_RSD_LITERAL:
208 acpi_rs_out_string(name,
209 ACPI_CAST_PTR(char, table->pointer));
212 case ACPI_RSD_STRING:
214 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
217 /* Data items, 8/16/32/64 bit */
221 if (table->pointer) {
222 acpi_rs_out_string(name,
223 table->pointer[*target]);
225 acpi_rs_out_integer8(name, ACPI_GET8(target));
229 case ACPI_RSD_UINT16:
231 acpi_rs_out_integer16(name, ACPI_GET16(target));
234 case ACPI_RSD_UINT32:
236 acpi_rs_out_integer32(name, ACPI_GET32(target));
239 case ACPI_RSD_UINT64:
241 acpi_rs_out_integer64(name, ACPI_GET64(target));
244 /* Flags: 1-bit and 2-bit flags supported */
246 case ACPI_RSD_1BITFLAG:
248 acpi_rs_out_string(name,
249 table->pointer[*target & 0x01]);
252 case ACPI_RSD_2BITFLAG:
254 acpi_rs_out_string(name,
255 table->pointer[*target & 0x03]);
258 case ACPI_RSD_3BITFLAG:
260 acpi_rs_out_string(name,
261 table->pointer[*target & 0x07]);
264 case ACPI_RSD_6BITFLAG:
266 acpi_rs_out_integer8(name, (ACPI_GET8(target) & 0x3F));
269 case ACPI_RSD_SHORTLIST:
271 * Short byte list (single line output) for DMA and IRQ resources
272 * Note: The list length is obtained from the previous table entry
274 if (previous_target) {
275 acpi_rs_out_title(name);
276 acpi_rs_dump_short_byte_list(*previous_target,
281 case ACPI_RSD_SHORTLISTX:
283 * Short byte list (single line output) for GPIO vendor data
284 * Note: The list length is obtained from the previous table entry
286 if (previous_target) {
287 acpi_rs_out_title(name);
288 acpi_rs_dump_short_byte_list(*previous_target,
290 (ACPI_CAST_INDIRECT_PTR
295 case ACPI_RSD_LONGLIST:
297 * Long byte list for Vendor resource data
298 * Note: The list length is obtained from the previous table entry
300 if (previous_target) {
301 acpi_rs_dump_byte_list(ACPI_GET16
307 case ACPI_RSD_DWORDLIST:
309 * Dword list for Extended Interrupt resources
310 * Note: The list length is obtained from the previous table entry
312 if (previous_target) {
313 acpi_rs_dump_dword_list(*previous_target,
319 case ACPI_RSD_WORDLIST:
321 * Word list for GPIO Pin Table
322 * Note: The list length is obtained from the previous table entry
324 if (previous_target) {
325 acpi_rs_dump_word_list(*previous_target,
326 *(ACPI_CAST_INDIRECT_PTR
331 case ACPI_RSD_ADDRESS:
333 * Common flags for all Address resources
335 acpi_rs_dump_address_common(ACPI_CAST_PTR
336 (union acpi_resource_data,
340 case ACPI_RSD_SOURCE:
342 * Optional resource_source for Address resources
344 acpi_rs_dump_resource_source(ACPI_CAST_PTR
346 acpi_resource_source,
354 acpi_rs_dump_resource_label("Resource Label",
360 case ACPI_RSD_SOURCE_LABEL:
362 * resource_source_label
364 acpi_rs_dump_resource_label("Resource Source Label",
372 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
382 /*******************************************************************************
384 * FUNCTION: acpi_rs_dump_resource_source
386 * PARAMETERS: resource_source - Pointer to a Resource Source struct
390 * DESCRIPTION: Common routine for dumping the optional resource_source and the
391 * corresponding resource_source_index.
393 ******************************************************************************/
396 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
398 ACPI_FUNCTION_ENTRY();
400 if (resource_source->index == 0xFF) {
404 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
406 acpi_rs_out_string("Resource Source",
407 resource_source->string_ptr ?
408 resource_source->string_ptr : "[Not Specified]");
411 /*******************************************************************************
413 * FUNCTION: acpi_rs_dump_resource_label
415 * PARAMETERS: title - Title of the dumped resource field
416 * resource_label - Pointer to a Resource Label struct
420 * DESCRIPTION: Common routine for dumping the resource_label
422 ******************************************************************************/
425 acpi_rs_dump_resource_label(char *title,
426 struct acpi_resource_label *resource_label)
428 ACPI_FUNCTION_ENTRY();
430 acpi_rs_out_string(title,
431 resource_label->string_ptr ?
432 resource_label->string_ptr : "[Not Specified]");
435 /*******************************************************************************
437 * FUNCTION: acpi_rs_dump_address_common
439 * PARAMETERS: resource - Pointer to an internal resource descriptor
443 * DESCRIPTION: Dump the fields that are common to all Address resource
446 ******************************************************************************/
448 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
450 ACPI_FUNCTION_ENTRY();
452 /* Decode the type-specific flags */
454 switch (resource->address.resource_type) {
455 case ACPI_MEMORY_RANGE:
457 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
462 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
465 case ACPI_BUS_NUMBER_RANGE:
467 acpi_rs_out_string("Resource Type", "Bus Number Range");
472 acpi_rs_out_integer8("Resource Type",
473 (u8) resource->address.resource_type);
477 /* Decode the general flags */
479 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
482 /*******************************************************************************
484 * FUNCTION: acpi_rs_out*
486 * PARAMETERS: title - Name of the resource field
487 * value - Value of the resource field
491 * DESCRIPTION: Miscellaneous helper functions to consistently format the
492 * output of the resource dump routines
494 ******************************************************************************/
496 static void acpi_rs_out_string(const char *title, const char *value)
499 acpi_os_printf("%27s : %s", title, value);
501 acpi_os_printf("[NULL NAMESTRING]");
503 acpi_os_printf("\n");
506 static void acpi_rs_out_integer8(const char *title, u8 value)
508 acpi_os_printf("%27s : %2.2X\n", title, value);
511 static void acpi_rs_out_integer16(const char *title, u16 value)
514 acpi_os_printf("%27s : %4.4X\n", title, value);
517 static void acpi_rs_out_integer32(const char *title, u32 value)
520 acpi_os_printf("%27s : %8.8X\n", title, value);
523 static void acpi_rs_out_integer64(const char *title, u64 value)
526 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
529 static void acpi_rs_out_title(const char *title)
532 acpi_os_printf("%27s : ", title);
535 /*******************************************************************************
537 * FUNCTION: acpi_rs_dump*List
539 * PARAMETERS: length - Number of elements in the list
540 * data - Start of the list
544 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
546 ******************************************************************************/
548 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
552 for (i = 0; i < length; i++) {
553 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
557 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
561 for (i = 0; i < length; i++) {
562 acpi_os_printf("%X ", data[i]);
565 acpi_os_printf("\n");
568 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
572 for (i = 0; i < length; i++) {
573 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
577 static void acpi_rs_dump_word_list(u16 length, u16 *data)
581 for (i = 0; i < length; i++) {
582 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);