Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / acpi / acpica / rsdump.c
blobbc4c4755aeb9edc4b2b4a6dab1519e0c1f42d405
1 /*******************************************************************************
3 * Module Name: rsdump - AML debugger support for resource structures.
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2018, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acresrc.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);
75 static void
76 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
78 static void
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);
84 static void
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
93 * RETURN: None
95 * DESCRIPTION: Dispatches the structure to the correct dump routine.
97 ******************************************************************************/
99 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
101 u32 count = 0;
102 u32 type;
104 ACPI_FUNCTION_ENTRY();
106 /* Check if debug output enabled */
108 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
109 return;
112 /* Walk list and dump all resource descriptors (END_TAG terminates) */
114 do {
115 acpi_os_printf("\n[%02X] ", count);
116 count++;
118 /* Validate Type before dispatch */
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;
128 /* Sanity check the length. It must not be zero, or we loop forever */
130 if (!resource_list->length) {
131 acpi_os_printf
132 ("Invalid zero length descriptor in resource list\n");
133 return;
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]);
143 } else {
144 acpi_rs_dump_descriptor(&resource_list->data,
145 acpi_gbl_dump_resource_dispatch
146 [type]);
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.
164 * RETURN: None
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;
173 u8 count;
175 ACPI_FUNCTION_ENTRY();
177 /* Check if debug output enabled */
179 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
180 return;
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",
189 count);
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
204 * RETURN: None
206 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
208 ******************************************************************************/
210 static void
211 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
213 u8 *target = NULL;
214 u8 *previous_target;
215 const char *name;
216 u8 count;
218 /* First table entry must contain the table length (# of table entries) */
220 count = table->offset;
222 while (count) {
223 previous_target = target;
224 target = ACPI_ADD_PTR(u8, resource, table->offset);
225 name = table->name;
227 switch (table->opcode) {
228 case ACPI_RSD_TITLE:
230 * Optional resource title
232 if (table->name) {
233 acpi_os_printf("%s Resource\n", name);
235 break;
237 /* Strings */
239 case ACPI_RSD_LITERAL:
241 acpi_rs_out_string(name,
242 ACPI_CAST_PTR(char, table->pointer));
243 break;
245 case ACPI_RSD_STRING:
247 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
248 break;
250 /* Data items, 8/16/32/64 bit */
252 case ACPI_RSD_UINT8:
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));
260 break;
262 case ACPI_RSD_UINT16:
264 acpi_rs_out_integer16(name, ACPI_GET16(target));
265 break;
267 case ACPI_RSD_UINT32:
269 acpi_rs_out_integer32(name, ACPI_GET32(target));
270 break;
272 case ACPI_RSD_UINT64:
274 acpi_rs_out_integer64(name, ACPI_GET64(target));
275 break;
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]);
283 break;
285 case ACPI_RSD_2BITFLAG:
287 acpi_rs_out_string(name,
288 table->pointer[*target & 0x03]);
289 break;
291 case ACPI_RSD_3BITFLAG:
293 acpi_rs_out_string(name,
294 table->pointer[*target & 0x07]);
295 break;
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,
305 target);
307 break;
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
319 (u8, target)));
321 break;
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
330 (previous_target),
331 target);
333 break;
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,
342 ACPI_CAST_PTR(u32,
343 target));
345 break;
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
355 (u16, target)));
357 break;
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,
365 target));
366 break;
368 case ACPI_RSD_SOURCE:
370 * Optional resource_source for Address resources
372 acpi_rs_dump_resource_source(ACPI_CAST_PTR
373 (struct
374 acpi_resource_source,
375 target));
376 break;
378 case ACPI_RSD_LABEL:
380 * resource_label
382 acpi_rs_dump_resource_label("Resource Label",
383 ACPI_CAST_PTR(struct
384 acpi_resource_label,
385 target));
386 break;
388 case ACPI_RSD_SOURCE_LABEL:
390 * resource_source_label
392 acpi_rs_dump_resource_label("Resource Source Label",
393 ACPI_CAST_PTR(struct
394 acpi_resource_label,
395 target));
396 break;
398 default:
400 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
401 table->opcode);
402 return;
405 table++;
406 count--;
410 /*******************************************************************************
412 * FUNCTION: acpi_rs_dump_resource_source
414 * PARAMETERS: resource_source - Pointer to a Resource Source struct
416 * RETURN: None
418 * DESCRIPTION: Common routine for dumping the optional resource_source and the
419 * corresponding resource_source_index.
421 ******************************************************************************/
423 static void
424 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
426 ACPI_FUNCTION_ENTRY();
428 if (resource_source->index == 0xFF) {
429 return;
432 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
434 acpi_rs_out_string("Resource Source",
435 resource_source->string_ptr ?
436 resource_source->string_ptr : "[Not Specified]");
439 /*******************************************************************************
441 * FUNCTION: acpi_rs_dump_resource_label
443 * PARAMETERS: title - Title of the dumped resource field
444 * resource_label - Pointer to a Resource Label struct
446 * RETURN: None
448 * DESCRIPTION: Common routine for dumping the resource_label
450 ******************************************************************************/
452 static void
453 acpi_rs_dump_resource_label(char *title,
454 struct acpi_resource_label *resource_label)
456 ACPI_FUNCTION_ENTRY();
458 acpi_rs_out_string(title,
459 resource_label->string_ptr ?
460 resource_label->string_ptr : "[Not Specified]");
463 /*******************************************************************************
465 * FUNCTION: acpi_rs_dump_address_common
467 * PARAMETERS: resource - Pointer to an internal resource descriptor
469 * RETURN: None
471 * DESCRIPTION: Dump the fields that are common to all Address resource
472 * descriptors
474 ******************************************************************************/
476 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
478 ACPI_FUNCTION_ENTRY();
480 /* Decode the type-specific flags */
482 switch (resource->address.resource_type) {
483 case ACPI_MEMORY_RANGE:
485 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
486 break;
488 case ACPI_IO_RANGE:
490 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
491 break;
493 case ACPI_BUS_NUMBER_RANGE:
495 acpi_rs_out_string("Resource Type", "Bus Number Range");
496 break;
498 default:
500 acpi_rs_out_integer8("Resource Type",
501 (u8) resource->address.resource_type);
502 break;
505 /* Decode the general flags */
507 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
510 /*******************************************************************************
512 * FUNCTION: acpi_rs_out*
514 * PARAMETERS: title - Name of the resource field
515 * value - Value of the resource field
517 * RETURN: None
519 * DESCRIPTION: Miscellaneous helper functions to consistently format the
520 * output of the resource dump routines
522 ******************************************************************************/
524 static void acpi_rs_out_string(const char *title, const char *value)
527 acpi_os_printf("%27s : %s", title, value);
528 if (!*value) {
529 acpi_os_printf("[NULL NAMESTRING]");
531 acpi_os_printf("\n");
534 static void acpi_rs_out_integer8(const char *title, u8 value)
536 acpi_os_printf("%27s : %2.2X\n", title, value);
539 static void acpi_rs_out_integer16(const char *title, u16 value)
542 acpi_os_printf("%27s : %4.4X\n", title, value);
545 static void acpi_rs_out_integer32(const char *title, u32 value)
548 acpi_os_printf("%27s : %8.8X\n", title, value);
551 static void acpi_rs_out_integer64(const char *title, u64 value)
554 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
557 static void acpi_rs_out_title(const char *title)
560 acpi_os_printf("%27s : ", title);
563 /*******************************************************************************
565 * FUNCTION: acpi_rs_dump*List
567 * PARAMETERS: length - Number of elements in the list
568 * data - Start of the list
570 * RETURN: None
572 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
574 ******************************************************************************/
576 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
578 u8 i;
580 for (i = 0; i < length; i++) {
581 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
585 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
587 u8 i;
589 for (i = 0; i < length; i++) {
590 acpi_os_printf("%X ", data[i]);
593 acpi_os_printf("\n");
596 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
598 u8 i;
600 for (i = 0; i < length; i++) {
601 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
605 static void acpi_rs_dump_word_list(u16 length, u16 *data)
607 u16 i;
609 for (i = 0; i < length; i++) {
610 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);