s390/ptrace: get rid of long longs in psw_bits
[linux/fpc-iii.git] / drivers / acpi / acpica / rsdump.c
blob2a09288e7c57c3d1a6df3a0f93dc9a3b49ed24ac
1 /*******************************************************************************
3 * Module Name: rsdump - AML debugger support for resource structures.
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2015, 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(char *title, char *value);
57 static void acpi_rs_out_integer8(char *title, u8 value);
59 static void acpi_rs_out_integer16(char *title, u16 value);
61 static void acpi_rs_out_integer32(char *title, u32 value);
63 static void acpi_rs_out_integer64(char *title, u64 value);
65 static void acpi_rs_out_title(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 acpi_rs_dump_address_common(union acpi_resource_data *resource);
80 static void
81 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
83 /*******************************************************************************
85 * FUNCTION: acpi_rs_dump_resource_list
87 * PARAMETERS: resource_list - Pointer to a resource descriptor list
89 * RETURN: None
91 * DESCRIPTION: Dispatches the structure to the correct dump routine.
93 ******************************************************************************/
95 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
97 u32 count = 0;
98 u32 type;
100 ACPI_FUNCTION_ENTRY();
102 /* Check if debug output enabled */
104 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
105 return;
108 /* Walk list and dump all resource descriptors (END_TAG terminates) */
110 do {
111 acpi_os_printf("\n[%02X] ", count);
112 count++;
114 /* Validate Type before dispatch */
116 type = resource_list->type;
117 if (type > ACPI_RESOURCE_TYPE_MAX) {
118 acpi_os_printf
119 ("Invalid descriptor type (%X) in resource list\n",
120 resource_list->type);
121 return;
124 /* Sanity check the length. It must not be zero, or we loop forever */
126 if (!resource_list->length) {
127 acpi_os_printf
128 ("Invalid zero length descriptor in resource list\n");
129 return;
132 /* Dump the resource descriptor */
134 if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
135 acpi_rs_dump_descriptor(&resource_list->data,
136 acpi_gbl_dump_serial_bus_dispatch
137 [resource_list->data.
138 common_serial_bus.type]);
139 } else {
140 acpi_rs_dump_descriptor(&resource_list->data,
141 acpi_gbl_dump_resource_dispatch
142 [type]);
145 /* Point to the next resource structure */
147 resource_list = ACPI_NEXT_RESOURCE(resource_list);
149 /* Exit when END_TAG descriptor is reached */
151 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
154 /*******************************************************************************
156 * FUNCTION: acpi_rs_dump_irq_list
158 * PARAMETERS: route_table - Pointer to the routing table to dump.
160 * RETURN: None
162 * DESCRIPTION: Print IRQ routing table
164 ******************************************************************************/
166 void acpi_rs_dump_irq_list(u8 *route_table)
168 struct acpi_pci_routing_table *prt_element;
169 u8 count;
171 ACPI_FUNCTION_ENTRY();
173 /* Check if debug output enabled */
175 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
176 return;
179 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
181 /* Dump all table elements, Exit on zero length element */
183 for (count = 0; prt_element->length; count++) {
184 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
185 count);
186 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
188 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
189 prt_element, prt_element->length);
193 /*******************************************************************************
195 * FUNCTION: acpi_rs_dump_descriptor
197 * PARAMETERS: resource - Buffer containing the resource
198 * table - Table entry to decode the resource
200 * RETURN: None
202 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
204 ******************************************************************************/
206 static void
207 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
209 u8 *target = NULL;
210 u8 *previous_target;
211 char *name;
212 u8 count;
214 /* First table entry must contain the table length (# of table entries) */
216 count = table->offset;
218 while (count) {
219 previous_target = target;
220 target = ACPI_ADD_PTR(u8, resource, table->offset);
221 name = table->name;
223 switch (table->opcode) {
224 case ACPI_RSD_TITLE:
226 * Optional resource title
228 if (table->name) {
229 acpi_os_printf("%s Resource\n", name);
231 break;
233 /* Strings */
235 case ACPI_RSD_LITERAL:
237 acpi_rs_out_string(name,
238 ACPI_CAST_PTR(char, table->pointer));
239 break;
241 case ACPI_RSD_STRING:
243 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
244 break;
246 /* Data items, 8/16/32/64 bit */
248 case ACPI_RSD_UINT8:
250 if (table->pointer) {
251 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
252 table->
253 pointer
254 [*target]));
255 } else {
256 acpi_rs_out_integer8(name, ACPI_GET8(target));
258 break;
260 case ACPI_RSD_UINT16:
262 acpi_rs_out_integer16(name, ACPI_GET16(target));
263 break;
265 case ACPI_RSD_UINT32:
267 acpi_rs_out_integer32(name, ACPI_GET32(target));
268 break;
270 case ACPI_RSD_UINT64:
272 acpi_rs_out_integer64(name, ACPI_GET64(target));
273 break;
275 /* Flags: 1-bit and 2-bit flags supported */
277 case ACPI_RSD_1BITFLAG:
279 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
280 table->
281 pointer[*target &
282 0x01]));
283 break;
285 case ACPI_RSD_2BITFLAG:
287 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
288 table->
289 pointer[*target &
290 0x03]));
291 break;
293 case ACPI_RSD_3BITFLAG:
295 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
296 table->
297 pointer[*target &
298 0x07]));
299 break;
301 case ACPI_RSD_SHORTLIST:
303 * Short byte list (single line output) for DMA and IRQ resources
304 * Note: The list length is obtained from the previous table entry
306 if (previous_target) {
307 acpi_rs_out_title(name);
308 acpi_rs_dump_short_byte_list(*previous_target,
309 target);
311 break;
313 case ACPI_RSD_SHORTLISTX:
315 * Short byte list (single line output) for GPIO vendor data
316 * Note: The list length is obtained from the previous table entry
318 if (previous_target) {
319 acpi_rs_out_title(name);
320 acpi_rs_dump_short_byte_list(*previous_target,
322 (ACPI_CAST_INDIRECT_PTR
323 (u8, target)));
325 break;
327 case ACPI_RSD_LONGLIST:
329 * Long byte list for Vendor resource data
330 * Note: The list length is obtained from the previous table entry
332 if (previous_target) {
333 acpi_rs_dump_byte_list(ACPI_GET16
334 (previous_target),
335 target);
337 break;
339 case ACPI_RSD_DWORDLIST:
341 * Dword list for Extended Interrupt resources
342 * Note: The list length is obtained from the previous table entry
344 if (previous_target) {
345 acpi_rs_dump_dword_list(*previous_target,
346 ACPI_CAST_PTR(u32,
347 target));
349 break;
351 case ACPI_RSD_WORDLIST:
353 * Word list for GPIO Pin Table
354 * Note: The list length is obtained from the previous table entry
356 if (previous_target) {
357 acpi_rs_dump_word_list(*previous_target,
358 *(ACPI_CAST_INDIRECT_PTR
359 (u16, target)));
361 break;
363 case ACPI_RSD_ADDRESS:
365 * Common flags for all Address resources
367 acpi_rs_dump_address_common(ACPI_CAST_PTR
368 (union acpi_resource_data,
369 target));
370 break;
372 case ACPI_RSD_SOURCE:
374 * Optional resource_source for Address resources
376 acpi_rs_dump_resource_source(ACPI_CAST_PTR
377 (struct
378 acpi_resource_source,
379 target));
380 break;
382 default:
384 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
385 table->opcode);
386 return;
389 table++;
390 count--;
394 /*******************************************************************************
396 * FUNCTION: acpi_rs_dump_resource_source
398 * PARAMETERS: resource_source - Pointer to a Resource Source struct
400 * RETURN: None
402 * DESCRIPTION: Common routine for dumping the optional resource_source and the
403 * corresponding resource_source_index.
405 ******************************************************************************/
407 static void
408 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
410 ACPI_FUNCTION_ENTRY();
412 if (resource_source->index == 0xFF) {
413 return;
416 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
418 acpi_rs_out_string("Resource Source",
419 resource_source->string_ptr ?
420 resource_source->string_ptr : "[Not Specified]");
423 /*******************************************************************************
425 * FUNCTION: acpi_rs_dump_address_common
427 * PARAMETERS: resource - Pointer to an internal resource descriptor
429 * RETURN: None
431 * DESCRIPTION: Dump the fields that are common to all Address resource
432 * descriptors
434 ******************************************************************************/
436 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
438 ACPI_FUNCTION_ENTRY();
440 /* Decode the type-specific flags */
442 switch (resource->address.resource_type) {
443 case ACPI_MEMORY_RANGE:
445 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
446 break;
448 case ACPI_IO_RANGE:
450 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
451 break;
453 case ACPI_BUS_NUMBER_RANGE:
455 acpi_rs_out_string("Resource Type", "Bus Number Range");
456 break;
458 default:
460 acpi_rs_out_integer8("Resource Type",
461 (u8) resource->address.resource_type);
462 break;
465 /* Decode the general flags */
467 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
470 /*******************************************************************************
472 * FUNCTION: acpi_rs_out*
474 * PARAMETERS: title - Name of the resource field
475 * value - Value of the resource field
477 * RETURN: None
479 * DESCRIPTION: Miscellaneous helper functions to consistently format the
480 * output of the resource dump routines
482 ******************************************************************************/
484 static void acpi_rs_out_string(char *title, char *value)
486 acpi_os_printf("%27s : %s", title, value);
487 if (!*value) {
488 acpi_os_printf("[NULL NAMESTRING]");
490 acpi_os_printf("\n");
493 static void acpi_rs_out_integer8(char *title, u8 value)
495 acpi_os_printf("%27s : %2.2X\n", title, value);
498 static void acpi_rs_out_integer16(char *title, u16 value)
500 acpi_os_printf("%27s : %4.4X\n", title, value);
503 static void acpi_rs_out_integer32(char *title, u32 value)
505 acpi_os_printf("%27s : %8.8X\n", title, value);
508 static void acpi_rs_out_integer64(char *title, u64 value)
510 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
513 static void acpi_rs_out_title(char *title)
515 acpi_os_printf("%27s : ", title);
518 /*******************************************************************************
520 * FUNCTION: acpi_rs_dump*List
522 * PARAMETERS: length - Number of elements in the list
523 * data - Start of the list
525 * RETURN: None
527 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
529 ******************************************************************************/
531 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
533 u8 i;
535 for (i = 0; i < length; i++) {
536 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
540 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
542 u8 i;
544 for (i = 0; i < length; i++) {
545 acpi_os_printf("%X ", data[i]);
547 acpi_os_printf("\n");
550 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
552 u8 i;
554 for (i = 0; i < length; i++) {
555 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
559 static void acpi_rs_dump_word_list(u16 length, u16 *data)
561 u16 i;
563 for (i = 0; i < length; i++) {
564 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);