Merge tag 'devicetree-for-linus' of git://git.secretlab.ca/git/linux
[linux-2.6.git] / drivers / acpi / acpica / rsdump.c
blob8a2d4986b0aa576695ed2f479703cfa8dc4fd139
1 /*******************************************************************************
3 * Module Name: rsdump - Functions to display the resource structures.
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, 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")
50 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
51 /* Local prototypes */
52 static void acpi_rs_out_string(char *title, char *value);
54 static void acpi_rs_out_integer8(char *title, u8 value);
56 static void acpi_rs_out_integer16(char *title, u16 value);
58 static void acpi_rs_out_integer32(char *title, u32 value);
60 static void acpi_rs_out_integer64(char *title, u64 value);
62 static void acpi_rs_out_title(char *title);
64 static void acpi_rs_dump_byte_list(u16 length, u8 *data);
66 static void acpi_rs_dump_word_list(u16 length, u16 *data);
68 static void acpi_rs_dump_dword_list(u8 length, u32 *data);
70 static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
72 static void
73 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
75 static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
77 static void
78 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
80 /*******************************************************************************
82 * FUNCTION: acpi_rs_dump_descriptor
84 * PARAMETERS: resource - Buffer containing the resource
85 * table - Table entry to decode the resource
87 * RETURN: None
89 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
91 ******************************************************************************/
93 static void
94 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
96 u8 *target = NULL;
97 u8 *previous_target;
98 char *name;
99 u8 count;
101 /* First table entry must contain the table length (# of table entries) */
103 count = table->offset;
105 while (count) {
106 previous_target = target;
107 target = ACPI_ADD_PTR(u8, resource, table->offset);
108 name = table->name;
110 switch (table->opcode) {
111 case ACPI_RSD_TITLE:
113 * Optional resource title
115 if (table->name) {
116 acpi_os_printf("%s Resource\n", name);
118 break;
120 /* Strings */
122 case ACPI_RSD_LITERAL:
124 acpi_rs_out_string(name,
125 ACPI_CAST_PTR(char, table->pointer));
126 break;
128 case ACPI_RSD_STRING:
130 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
131 break;
133 /* Data items, 8/16/32/64 bit */
135 case ACPI_RSD_UINT8:
137 if (table->pointer) {
138 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
139 table->
140 pointer
141 [*target]));
142 } else {
143 acpi_rs_out_integer8(name, ACPI_GET8(target));
145 break;
147 case ACPI_RSD_UINT16:
149 acpi_rs_out_integer16(name, ACPI_GET16(target));
150 break;
152 case ACPI_RSD_UINT32:
154 acpi_rs_out_integer32(name, ACPI_GET32(target));
155 break;
157 case ACPI_RSD_UINT64:
159 acpi_rs_out_integer64(name, ACPI_GET64(target));
160 break;
162 /* Flags: 1-bit and 2-bit flags supported */
164 case ACPI_RSD_1BITFLAG:
166 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
167 table->
168 pointer[*target &
169 0x01]));
170 break;
172 case ACPI_RSD_2BITFLAG:
174 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
175 table->
176 pointer[*target &
177 0x03]));
178 break;
180 case ACPI_RSD_3BITFLAG:
182 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
183 table->
184 pointer[*target &
185 0x07]));
186 break;
188 case ACPI_RSD_SHORTLIST:
190 * Short byte list (single line output) for DMA and IRQ resources
191 * Note: The list length is obtained from the previous table entry
193 if (previous_target) {
194 acpi_rs_out_title(name);
195 acpi_rs_dump_short_byte_list(*previous_target,
196 target);
198 break;
200 case ACPI_RSD_SHORTLISTX:
202 * Short byte list (single line output) for GPIO vendor data
203 * Note: The list length is obtained from the previous table entry
205 if (previous_target) {
206 acpi_rs_out_title(name);
207 acpi_rs_dump_short_byte_list(*previous_target,
209 (ACPI_CAST_INDIRECT_PTR
210 (u8, target)));
212 break;
214 case ACPI_RSD_LONGLIST:
216 * Long byte list for Vendor resource data
217 * Note: The list length is obtained from the previous table entry
219 if (previous_target) {
220 acpi_rs_dump_byte_list(ACPI_GET16
221 (previous_target),
222 target);
224 break;
226 case ACPI_RSD_DWORDLIST:
228 * Dword list for Extended Interrupt resources
229 * Note: The list length is obtained from the previous table entry
231 if (previous_target) {
232 acpi_rs_dump_dword_list(*previous_target,
233 ACPI_CAST_PTR(u32,
234 target));
236 break;
238 case ACPI_RSD_WORDLIST:
240 * Word list for GPIO Pin Table
241 * Note: The list length is obtained from the previous table entry
243 if (previous_target) {
244 acpi_rs_dump_word_list(*previous_target,
245 *(ACPI_CAST_INDIRECT_PTR
246 (u16, target)));
248 break;
250 case ACPI_RSD_ADDRESS:
252 * Common flags for all Address resources
254 acpi_rs_dump_address_common(ACPI_CAST_PTR
255 (union acpi_resource_data,
256 target));
257 break;
259 case ACPI_RSD_SOURCE:
261 * Optional resource_source for Address resources
263 acpi_rs_dump_resource_source(ACPI_CAST_PTR
264 (struct
265 acpi_resource_source,
266 target));
267 break;
269 default:
271 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
272 table->opcode);
273 return;
276 table++;
277 count--;
281 /*******************************************************************************
283 * FUNCTION: acpi_rs_dump_resource_source
285 * PARAMETERS: resource_source - Pointer to a Resource Source struct
287 * RETURN: None
289 * DESCRIPTION: Common routine for dumping the optional resource_source and the
290 * corresponding resource_source_index.
292 ******************************************************************************/
294 static void
295 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
297 ACPI_FUNCTION_ENTRY();
299 if (resource_source->index == 0xFF) {
300 return;
303 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
305 acpi_rs_out_string("Resource Source",
306 resource_source->string_ptr ?
307 resource_source->string_ptr : "[Not Specified]");
310 /*******************************************************************************
312 * FUNCTION: acpi_rs_dump_address_common
314 * PARAMETERS: resource - Pointer to an internal resource descriptor
316 * RETURN: None
318 * DESCRIPTION: Dump the fields that are common to all Address resource
319 * descriptors
321 ******************************************************************************/
323 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
325 ACPI_FUNCTION_ENTRY();
327 /* Decode the type-specific flags */
329 switch (resource->address.resource_type) {
330 case ACPI_MEMORY_RANGE:
332 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
333 break;
335 case ACPI_IO_RANGE:
337 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
338 break;
340 case ACPI_BUS_NUMBER_RANGE:
342 acpi_rs_out_string("Resource Type", "Bus Number Range");
343 break;
345 default:
347 acpi_rs_out_integer8("Resource Type",
348 (u8) resource->address.resource_type);
349 break;
352 /* Decode the general flags */
354 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
357 /*******************************************************************************
359 * FUNCTION: acpi_rs_dump_resource_list
361 * PARAMETERS: resource_list - Pointer to a resource descriptor list
363 * RETURN: None
365 * DESCRIPTION: Dispatches the structure to the correct dump routine.
367 ******************************************************************************/
369 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
371 u32 count = 0;
372 u32 type;
374 ACPI_FUNCTION_ENTRY();
376 /* Check if debug output enabled */
378 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
379 return;
382 /* Walk list and dump all resource descriptors (END_TAG terminates) */
384 do {
385 acpi_os_printf("\n[%02X] ", count);
386 count++;
388 /* Validate Type before dispatch */
390 type = resource_list->type;
391 if (type > ACPI_RESOURCE_TYPE_MAX) {
392 acpi_os_printf
393 ("Invalid descriptor type (%X) in resource list\n",
394 resource_list->type);
395 return;
398 /* Sanity check the length. It must not be zero, or we loop forever */
400 if (!resource_list->length) {
401 acpi_os_printf
402 ("Invalid zero length descriptor in resource list\n");
403 return;
406 /* Dump the resource descriptor */
408 if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
409 acpi_rs_dump_descriptor(&resource_list->data,
410 acpi_gbl_dump_serial_bus_dispatch
411 [resource_list->data.
412 common_serial_bus.type]);
413 } else {
414 acpi_rs_dump_descriptor(&resource_list->data,
415 acpi_gbl_dump_resource_dispatch
416 [type]);
419 /* Point to the next resource structure */
421 resource_list = ACPI_NEXT_RESOURCE(resource_list);
423 /* Exit when END_TAG descriptor is reached */
425 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
428 /*******************************************************************************
430 * FUNCTION: acpi_rs_dump_irq_list
432 * PARAMETERS: route_table - Pointer to the routing table to dump.
434 * RETURN: None
436 * DESCRIPTION: Print IRQ routing table
438 ******************************************************************************/
440 void acpi_rs_dump_irq_list(u8 * route_table)
442 struct acpi_pci_routing_table *prt_element;
443 u8 count;
445 ACPI_FUNCTION_ENTRY();
447 /* Check if debug output enabled */
449 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
450 return;
453 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
455 /* Dump all table elements, Exit on zero length element */
457 for (count = 0; prt_element->length; count++) {
458 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
459 count);
460 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
462 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
463 prt_element, prt_element->length);
467 /*******************************************************************************
469 * FUNCTION: acpi_rs_out*
471 * PARAMETERS: title - Name of the resource field
472 * value - Value of the resource field
474 * RETURN: None
476 * DESCRIPTION: Miscellaneous helper functions to consistently format the
477 * output of the resource dump routines
479 ******************************************************************************/
481 static void acpi_rs_out_string(char *title, char *value)
483 acpi_os_printf("%27s : %s", title, value);
484 if (!*value) {
485 acpi_os_printf("[NULL NAMESTRING]");
487 acpi_os_printf("\n");
490 static void acpi_rs_out_integer8(char *title, u8 value)
492 acpi_os_printf("%27s : %2.2X\n", title, value);
495 static void acpi_rs_out_integer16(char *title, u16 value)
497 acpi_os_printf("%27s : %4.4X\n", title, value);
500 static void acpi_rs_out_integer32(char *title, u32 value)
502 acpi_os_printf("%27s : %8.8X\n", title, value);
505 static void acpi_rs_out_integer64(char *title, u64 value)
507 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
510 static void acpi_rs_out_title(char *title)
512 acpi_os_printf("%27s : ", title);
515 /*******************************************************************************
517 * FUNCTION: acpi_rs_dump*List
519 * PARAMETERS: length - Number of elements in the list
520 * data - Start of the list
522 * RETURN: None
524 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
526 ******************************************************************************/
528 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
530 u8 i;
532 for (i = 0; i < length; i++) {
533 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
537 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
539 u8 i;
541 for (i = 0; i < length; i++) {
542 acpi_os_printf("%X ", data[i]);
544 acpi_os_printf("\n");
547 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
549 u8 i;
551 for (i = 0; i < length; i++) {
552 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
556 static void acpi_rs_dump_word_list(u16 length, u16 *data)
558 u16 i;
560 for (i = 0; i < length; i++) {
561 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
565 #endif