1 /*******************************************************************************
3 * Module Name: rsdump - AML debugger support for resource structures.
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2017, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME("rsdump")
52 * All functions in this module are used by the AML Debugger only
54 /* Local prototypes */
55 static void acpi_rs_out_string(const char *title, const char *value);
57 static void acpi_rs_out_integer8(const char *title, u8 value);
59 static void acpi_rs_out_integer16(const char *title, u16 value);
61 static void acpi_rs_out_integer32(const char *title, u32 value);
63 static void acpi_rs_out_integer64(const char *title, u64 value);
65 static void acpi_rs_out_title(const char *title);
67 static void acpi_rs_dump_byte_list(u16 length, u8 *data);
69 static void acpi_rs_dump_word_list(u16 length, u16 *data);
71 static void acpi_rs_dump_dword_list(u8 length, u32 *data);
73 static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
76 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
79 acpi_rs_dump_resource_label(char *title,
80 struct acpi_resource_label *resource_label);
82 static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
85 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
87 /*******************************************************************************
89 * FUNCTION: acpi_rs_dump_resource_list
91 * PARAMETERS: resource_list - Pointer to a resource descriptor list
95 * DESCRIPTION: Dispatches the structure to the correct dump routine.
97 ******************************************************************************/
99 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
104 ACPI_FUNCTION_ENTRY();
106 /* Check if debug output enabled */
108 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
112 /* Walk list and dump all resource descriptors (END_TAG terminates) */
115 acpi_os_printf("\n[%02X] ", count);
118 /* Validate Type before dispatch */
120 type = resource_list->type;
121 if (type > ACPI_RESOURCE_TYPE_MAX) {
123 ("Invalid descriptor type (%X) in resource list\n",
124 resource_list->type);
128 /* Sanity check the length. It must not be zero, or we loop forever */
130 if (!resource_list->length) {
132 ("Invalid zero length descriptor in resource list\n");
136 /* Dump the resource descriptor */
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]);
144 acpi_rs_dump_descriptor(&resource_list->data,
145 acpi_gbl_dump_resource_dispatch
149 /* Point to the next resource structure */
151 resource_list = ACPI_NEXT_RESOURCE(resource_list);
153 /* Exit when END_TAG descriptor is reached */
155 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
158 /*******************************************************************************
160 * FUNCTION: acpi_rs_dump_irq_list
162 * PARAMETERS: route_table - Pointer to the routing table to dump.
166 * DESCRIPTION: Print IRQ routing table
168 ******************************************************************************/
170 void acpi_rs_dump_irq_list(u8 *route_table)
172 struct acpi_pci_routing_table *prt_element;
175 ACPI_FUNCTION_ENTRY();
177 /* Check if debug output enabled */
179 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
183 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
185 /* Dump all table elements, Exit on zero length element */
187 for (count = 0; prt_element->length; count++) {
188 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
190 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
192 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
193 prt_element, prt_element->length);
197 /*******************************************************************************
199 * FUNCTION: acpi_rs_dump_descriptor
201 * PARAMETERS: resource - Buffer containing the resource
202 * table - Table entry to decode the resource
206 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
208 ******************************************************************************/
211 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
218 /* First table entry must contain the table length (# of table entries) */
220 count = table->offset;
223 previous_target = target;
224 target = ACPI_ADD_PTR(u8, resource, table->offset);
227 switch (table->opcode) {
230 * Optional resource title
233 acpi_os_printf("%s Resource\n", name);
239 case ACPI_RSD_LITERAL:
241 acpi_rs_out_string(name,
242 ACPI_CAST_PTR(char, table->pointer));
245 case ACPI_RSD_STRING:
247 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
250 /* Data items, 8/16/32/64 bit */
254 if (table->pointer) {
255 acpi_rs_out_string(name,
256 table->pointer[*target]);
258 acpi_rs_out_integer8(name, ACPI_GET8(target));
262 case ACPI_RSD_UINT16:
264 acpi_rs_out_integer16(name, ACPI_GET16(target));
267 case ACPI_RSD_UINT32:
269 acpi_rs_out_integer32(name, ACPI_GET32(target));
272 case ACPI_RSD_UINT64:
274 acpi_rs_out_integer64(name, ACPI_GET64(target));
277 /* Flags: 1-bit and 2-bit flags supported */
279 case ACPI_RSD_1BITFLAG:
281 acpi_rs_out_string(name,
282 table->pointer[*target & 0x01]);
285 case ACPI_RSD_2BITFLAG:
287 acpi_rs_out_string(name,
288 table->pointer[*target & 0x03]);
291 case ACPI_RSD_3BITFLAG:
293 acpi_rs_out_string(name,
294 table->pointer[*target & 0x07]);
297 case ACPI_RSD_SHORTLIST:
299 * Short byte list (single line output) for DMA and IRQ resources
300 * Note: The list length is obtained from the previous table entry
302 if (previous_target) {
303 acpi_rs_out_title(name);
304 acpi_rs_dump_short_byte_list(*previous_target,
309 case ACPI_RSD_SHORTLISTX:
311 * Short byte list (single line output) for GPIO vendor data
312 * Note: The list length is obtained from the previous table entry
314 if (previous_target) {
315 acpi_rs_out_title(name);
316 acpi_rs_dump_short_byte_list(*previous_target,
318 (ACPI_CAST_INDIRECT_PTR
323 case ACPI_RSD_LONGLIST:
325 * Long byte list for Vendor resource data
326 * Note: The list length is obtained from the previous table entry
328 if (previous_target) {
329 acpi_rs_dump_byte_list(ACPI_GET16
335 case ACPI_RSD_DWORDLIST:
337 * Dword list for Extended Interrupt resources
338 * Note: The list length is obtained from the previous table entry
340 if (previous_target) {
341 acpi_rs_dump_dword_list(*previous_target,
347 case ACPI_RSD_WORDLIST:
349 * Word list for GPIO Pin Table
350 * Note: The list length is obtained from the previous table entry
352 if (previous_target) {
353 acpi_rs_dump_word_list(*previous_target,
354 *(ACPI_CAST_INDIRECT_PTR
359 case ACPI_RSD_ADDRESS:
361 * Common flags for all Address resources
363 acpi_rs_dump_address_common(ACPI_CAST_PTR
364 (union acpi_resource_data,
368 case ACPI_RSD_SOURCE:
370 * Optional resource_source for Address resources
372 acpi_rs_dump_resource_source(ACPI_CAST_PTR
374 acpi_resource_source,
382 acpi_rs_dump_resource_label("Resource Label",
390 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
400 /*******************************************************************************
402 * FUNCTION: acpi_rs_dump_resource_source
404 * PARAMETERS: resource_source - Pointer to a Resource Source struct
408 * DESCRIPTION: Common routine for dumping the optional resource_source and the
409 * corresponding resource_source_index.
411 ******************************************************************************/
414 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
416 ACPI_FUNCTION_ENTRY();
418 if (resource_source->index == 0xFF) {
422 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
424 acpi_rs_out_string("Resource Source",
425 resource_source->string_ptr ?
426 resource_source->string_ptr : "[Not Specified]");
429 /*******************************************************************************
431 * FUNCTION: acpi_rs_dump_resource_label
433 * PARAMETERS: title - Title of the dumped resource field
434 * resource_label - Pointer to a Resource Label struct
438 * DESCRIPTION: Common routine for dumping the resource_label
440 ******************************************************************************/
443 acpi_rs_dump_resource_label(char *title,
444 struct acpi_resource_label *resource_label)
446 ACPI_FUNCTION_ENTRY();
448 acpi_rs_out_string(title,
449 resource_label->string_ptr ?
450 resource_label->string_ptr : "[Not Specified]");
453 /*******************************************************************************
455 * FUNCTION: acpi_rs_dump_address_common
457 * PARAMETERS: resource - Pointer to an internal resource descriptor
461 * DESCRIPTION: Dump the fields that are common to all Address resource
464 ******************************************************************************/
466 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
468 ACPI_FUNCTION_ENTRY();
470 /* Decode the type-specific flags */
472 switch (resource->address.resource_type) {
473 case ACPI_MEMORY_RANGE:
475 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
480 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
483 case ACPI_BUS_NUMBER_RANGE:
485 acpi_rs_out_string("Resource Type", "Bus Number Range");
490 acpi_rs_out_integer8("Resource Type",
491 (u8) resource->address.resource_type);
495 /* Decode the general flags */
497 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
500 /*******************************************************************************
502 * FUNCTION: acpi_rs_out*
504 * PARAMETERS: title - Name of the resource field
505 * value - Value of the resource field
509 * DESCRIPTION: Miscellaneous helper functions to consistently format the
510 * output of the resource dump routines
512 ******************************************************************************/
514 static void acpi_rs_out_string(const char *title, const char *value)
517 acpi_os_printf("%27s : %s", title, value);
519 acpi_os_printf("[NULL NAMESTRING]");
521 acpi_os_printf("\n");
524 static void acpi_rs_out_integer8(const char *title, u8 value)
526 acpi_os_printf("%27s : %2.2X\n", title, value);
529 static void acpi_rs_out_integer16(const char *title, u16 value)
532 acpi_os_printf("%27s : %4.4X\n", title, value);
535 static void acpi_rs_out_integer32(const char *title, u32 value)
538 acpi_os_printf("%27s : %8.8X\n", title, value);
541 static void acpi_rs_out_integer64(const char *title, u64 value)
544 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
547 static void acpi_rs_out_title(const char *title)
550 acpi_os_printf("%27s : ", title);
553 /*******************************************************************************
555 * FUNCTION: acpi_rs_dump*List
557 * PARAMETERS: length - Number of elements in the list
558 * data - Start of the list
562 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
564 ******************************************************************************/
566 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
570 for (i = 0; i < length; i++) {
571 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
575 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
579 for (i = 0; i < length; i++) {
580 acpi_os_printf("%X ", data[i]);
583 acpi_os_printf("\n");
586 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
590 for (i = 0; i < length; i++) {
591 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
595 static void acpi_rs_dump_word_list(u16 length, u16 *data)
599 for (i = 0; i < length; i++) {
600 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);