Merge tag 'v3.9-rc3' into drm-intel-next-queued
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / acpica / rsdump.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: rsdump - Functions to display the resource structures.
4 *
5 ******************************************************************************/
6
7/*
25f044e6 8 * Copyright (C) 2000 - 2013, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acresrc.h"
1da177e4
LT
47
48#define _COMPONENT ACPI_RESOURCES
4be44fcd 49ACPI_MODULE_NAME("rsdump")
6f42ccf2 50#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
44f6c012 51/* Local prototypes */
bda663d3
RM
52static void acpi_rs_out_string(char *title, char *value);
53
54static void acpi_rs_out_integer8(char *title, u8 value);
55
56static void acpi_rs_out_integer16(char *title, u16 value);
57
58static void acpi_rs_out_integer32(char *title, u32 value);
59
60static void acpi_rs_out_integer64(char *title, u64 value);
61
62static void acpi_rs_out_title(char *title);
63
e0fe0a8d 64static void acpi_rs_dump_byte_list(u16 length, u8 *data);
bda663d3 65
e0fe0a8d 66static void acpi_rs_dump_word_list(u16 length, u16 *data);
bda663d3 67
e0fe0a8d
LM
68static void acpi_rs_dump_dword_list(u8 length, u32 *data);
69
70static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
bda663d3
RM
71
72static void
73acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
74
75static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
76
0897831b
BM
77static void
78acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
79
bda663d3
RM
80/*******************************************************************************
81 *
0897831b 82 * FUNCTION: acpi_rs_dump_descriptor
bda663d3 83 *
42f8fb75
BM
84 * PARAMETERS: resource - Buffer containing the resource
85 * table - Table entry to decode the resource
bda663d3
RM
86 *
87 * RETURN: None
88 *
42f8fb75 89 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
bda663d3
RM
90 *
91 ******************************************************************************/
92
0897831b
BM
93static void
94acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
bda663d3 95{
96db255c
BM
96 u8 *target = NULL;
97 u8 *previous_target;
0897831b
BM
98 char *name;
99 u8 count;
100
101 /* First table entry must contain the table length (# of table entries) */
102
103 count = table->offset;
104
105 while (count) {
106 previous_target = target;
c51a4de8 107 target = ACPI_ADD_PTR(u8, resource, table->offset);
0897831b
BM
108 name = table->name;
109
110 switch (table->opcode) {
111 case ACPI_RSD_TITLE:
112 /*
113 * Optional resource title
114 */
115 if (table->name) {
116 acpi_os_printf("%s Resource\n", name);
117 }
118 break;
bda663d3 119
0897831b 120 /* Strings */
bda663d3 121
0897831b 122 case ACPI_RSD_LITERAL:
96db255c
BM
123 acpi_rs_out_string(name,
124 ACPI_CAST_PTR(char, table->pointer));
0897831b 125 break;
bda663d3 126
0897831b 127 case ACPI_RSD_STRING:
96db255c 128 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
0897831b 129 break;
bda663d3 130
0897831b 131 /* Data items, 8/16/32/64 bit */
bda663d3 132
0897831b 133 case ACPI_RSD_UINT8:
e0fe0a8d
LM
134 if (table->pointer) {
135 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
136 table->
137 pointer
138 [*target]));
139 } else {
140 acpi_rs_out_integer8(name, ACPI_GET8(target));
141 }
0897831b 142 break;
bda663d3 143
0897831b 144 case ACPI_RSD_UINT16:
c51a4de8 145 acpi_rs_out_integer16(name, ACPI_GET16(target));
0897831b
BM
146 break;
147
148 case ACPI_RSD_UINT32:
c51a4de8 149 acpi_rs_out_integer32(name, ACPI_GET32(target));
0897831b 150 break;
50eca3eb 151
0897831b 152 case ACPI_RSD_UINT64:
c51a4de8 153 acpi_rs_out_integer64(name, ACPI_GET64(target));
0897831b
BM
154 break;
155
156 /* Flags: 1-bit and 2-bit flags supported */
157
158 case ACPI_RSD_1BITFLAG:
96db255c
BM
159 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
160 table->
161 pointer[*target &
162 0x01]));
0897831b
BM
163 break;
164
165 case ACPI_RSD_2BITFLAG:
96db255c
BM
166 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
167 table->
168 pointer[*target &
169 0x03]));
0897831b
BM
170 break;
171
e0fe0a8d
LM
172 case ACPI_RSD_3BITFLAG:
173 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
174 table->
175 pointer[*target &
176 0x07]));
177 break;
178
0897831b
BM
179 case ACPI_RSD_SHORTLIST:
180 /*
181 * Short byte list (single line output) for DMA and IRQ resources
182 * Note: The list length is obtained from the previous table entry
183 */
184 if (previous_target) {
185 acpi_rs_out_title(name);
96db255c
BM
186 acpi_rs_dump_short_byte_list(*previous_target,
187 target);
0897831b
BM
188 }
189 break;
190
e0fe0a8d
LM
191 case ACPI_RSD_SHORTLISTX:
192 /*
193 * Short byte list (single line output) for GPIO vendor data
194 * Note: The list length is obtained from the previous table entry
195 */
196 if (previous_target) {
197 acpi_rs_out_title(name);
198 acpi_rs_dump_short_byte_list(*previous_target,
199 *
200 (ACPI_CAST_INDIRECT_PTR
201 (u8, target)));
202 }
203 break;
204
0897831b
BM
205 case ACPI_RSD_LONGLIST:
206 /*
207 * Long byte list for Vendor resource data
208 * Note: The list length is obtained from the previous table entry
209 */
210 if (previous_target) {
c51a4de8
BM
211 acpi_rs_dump_byte_list(ACPI_GET16
212 (previous_target),
96db255c 213 target);
0897831b
BM
214 }
215 break;
216
217 case ACPI_RSD_DWORDLIST:
218 /*
219 * Dword list for Extended Interrupt resources
220 * Note: The list length is obtained from the previous table entry
221 */
222 if (previous_target) {
96db255c
BM
223 acpi_rs_dump_dword_list(*previous_target,
224 ACPI_CAST_PTR(u32,
225 target));
0897831b
BM
226 }
227 break;
228
e0fe0a8d
LM
229 case ACPI_RSD_WORDLIST:
230 /*
231 * Word list for GPIO Pin Table
232 * Note: The list length is obtained from the previous table entry
233 */
234 if (previous_target) {
235 acpi_rs_dump_word_list(*previous_target,
236 *(ACPI_CAST_INDIRECT_PTR
237 (u16, target)));
238 }
239 break;
240
0897831b
BM
241 case ACPI_RSD_ADDRESS:
242 /*
243 * Common flags for all Address resources
244 */
96db255c
BM
245 acpi_rs_dump_address_common(ACPI_CAST_PTR
246 (union acpi_resource_data,
247 target));
0897831b
BM
248 break;
249
250 case ACPI_RSD_SOURCE:
251 /*
252 * Optional resource_source for Address resources
253 */
3e8214e5
LZ
254 acpi_rs_dump_resource_source(ACPI_CAST_PTR
255 (struct
fd350943
LB
256 acpi_resource_source,
257 target));
0897831b
BM
258 break;
259
260 default:
261 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
262 table->opcode);
263 return;
264 }
265
266 table++;
267 count--;
268 }
50eca3eb
BM
269}
270
bda663d3
RM
271/*******************************************************************************
272 *
273 * FUNCTION: acpi_rs_dump_resource_source
1da177e4 274 *
bda663d3 275 * PARAMETERS: resource_source - Pointer to a Resource Source struct
1da177e4
LT
276 *
277 * RETURN: None
278 *
bda663d3
RM
279 * DESCRIPTION: Common routine for dumping the optional resource_source and the
280 * corresponding resource_source_index.
1da177e4
LT
281 *
282 ******************************************************************************/
283
bda663d3
RM
284static void
285acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
1da177e4 286{
50eca3eb 287 ACPI_FUNCTION_ENTRY();
1da177e4 288
bda663d3
RM
289 if (resource_source->index == 0xFF) {
290 return;
291 }
292
0897831b 293 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
bda663d3
RM
294
295 acpi_rs_out_string("Resource Source",
296 resource_source->string_ptr ?
297 resource_source->string_ptr : "[Not Specified]");
298}
299
300/*******************************************************************************
301 *
302 * FUNCTION: acpi_rs_dump_address_common
303 *
ba494bee 304 * PARAMETERS: resource - Pointer to an internal resource descriptor
bda663d3
RM
305 *
306 * RETURN: None
307 *
308 * DESCRIPTION: Dump the fields that are common to all Address resource
309 * descriptors
310 *
311 ******************************************************************************/
312
313static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
314{
4be44fcd 315 ACPI_FUNCTION_ENTRY();
1da177e4 316
bda663d3
RM
317 /* Decode the type-specific flags */
318
319 switch (resource->address.resource_type) {
320 case ACPI_MEMORY_RANGE:
1da177e4 321
0897831b 322 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
bda663d3
RM
323 break;
324
325 case ACPI_IO_RANGE:
326
0897831b 327 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
bda663d3
RM
328 break;
329
330 case ACPI_BUS_NUMBER_RANGE:
331
332 acpi_rs_out_string("Resource Type", "Bus Number Range");
333 break;
334
335 default:
336
337 acpi_rs_out_integer8("Resource Type",
338 (u8) resource->address.resource_type);
339 break;
1da177e4
LT
340 }
341
bda663d3
RM
342 /* Decode the general flags */
343
0897831b 344 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
1da177e4
LT
345}
346
1da177e4
LT
347/*******************************************************************************
348 *
bda663d3 349 * FUNCTION: acpi_rs_dump_resource_list
1da177e4 350 *
bda663d3 351 * PARAMETERS: resource_list - Pointer to a resource descriptor list
1da177e4
LT
352 *
353 * RETURN: None
354 *
bda663d3 355 * DESCRIPTION: Dispatches the structure to the correct dump routine.
1da177e4
LT
356 *
357 ******************************************************************************/
358
bda663d3 359void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
1da177e4 360{
bda663d3 361 u32 count = 0;
0897831b 362 u32 type;
1da177e4 363
4be44fcd 364 ACPI_FUNCTION_ENTRY();
1da177e4 365
10e9e759
BM
366 /* Check if debug output enabled */
367
368 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
bda663d3
RM
369 return;
370 }
371
0897831b 372 /* Walk list and dump all resource descriptors (END_TAG terminates) */
bda663d3 373
0897831b 374 do {
bda663d3 375 acpi_os_printf("\n[%02X] ", count);
0897831b 376 count++;
bda663d3
RM
377
378 /* Validate Type before dispatch */
379
0897831b
BM
380 type = resource_list->type;
381 if (type > ACPI_RESOURCE_TYPE_MAX) {
bda663d3
RM
382 acpi_os_printf
383 ("Invalid descriptor type (%X) in resource list\n",
384 resource_list->type);
385 return;
386 }
387
388 /* Dump the resource descriptor */
389
e0fe0a8d
LM
390 if (type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
391 acpi_rs_dump_descriptor(&resource_list->data,
392 acpi_gbl_dump_serial_bus_dispatch
393 [resource_list->data.
394 common_serial_bus.type]);
395 } else {
396 acpi_rs_dump_descriptor(&resource_list->data,
397 acpi_gbl_dump_resource_dispatch
398 [type]);
399 }
bda663d3 400
0897831b 401 /* Point to the next resource structure */
bda663d3 402
e0fe0a8d 403 resource_list = ACPI_NEXT_RESOURCE(resource_list);
bda663d3 404
0897831b 405 /* Exit when END_TAG descriptor is reached */
bda663d3 406
0897831b 407 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
bda663d3
RM
408}
409
410/*******************************************************************************
411 *
0897831b 412 * FUNCTION: acpi_rs_dump_irq_list
bda663d3 413 *
0897831b 414 * PARAMETERS: route_table - Pointer to the routing table to dump.
bda663d3
RM
415 *
416 * RETURN: None
417 *
0897831b 418 * DESCRIPTION: Print IRQ routing table
bda663d3
RM
419 *
420 ******************************************************************************/
421
0897831b 422void acpi_rs_dump_irq_list(u8 * route_table)
bda663d3 423{
0897831b
BM
424 struct acpi_pci_routing_table *prt_element;
425 u8 count;
1da177e4 426
4be44fcd 427 ACPI_FUNCTION_ENTRY();
1da177e4 428
10e9e759
BM
429 /* Check if debug output enabled */
430
431 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
0897831b 432 return;
1da177e4
LT
433 }
434
0897831b 435 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
1da177e4 436
0897831b 437 /* Dump all table elements, Exit on zero length element */
1da177e4 438
0897831b
BM
439 for (count = 0; prt_element->length; count++) {
440 acpi_os_printf("\n[%02X] PCI IRQ Routing Table Package\n",
441 count);
442 acpi_rs_dump_descriptor(prt_element, acpi_rs_dump_prt);
1da177e4 443
c51a4de8
BM
444 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
445 prt_element, prt_element->length);
1da177e4 446 }
1da177e4
LT
447}
448
1da177e4
LT
449/*******************************************************************************
450 *
0897831b 451 * FUNCTION: acpi_rs_out*
1da177e4 452 *
ba494bee
BM
453 * PARAMETERS: title - Name of the resource field
454 * value - Value of the resource field
1da177e4
LT
455 *
456 * RETURN: None
457 *
0897831b
BM
458 * DESCRIPTION: Miscellaneous helper functions to consistently format the
459 * output of the resource dump routines
1da177e4
LT
460 *
461 ******************************************************************************/
462
0897831b 463static void acpi_rs_out_string(char *title, char *value)
1da177e4 464{
b8e4d893
BM
465 acpi_os_printf("%27s : %s", title, value);
466 if (!*value) {
467 acpi_os_printf("[NULL NAMESTRING]");
468 }
469 acpi_os_printf("\n");
1da177e4
LT
470}
471
0897831b 472static void acpi_rs_out_integer8(char *title, u8 value)
1da177e4 473{
0897831b 474 acpi_os_printf("%27s : %2.2X\n", title, value);
1da177e4
LT
475}
476
0897831b 477static void acpi_rs_out_integer16(char *title, u16 value)
1da177e4 478{
0897831b 479 acpi_os_printf("%27s : %4.4X\n", title, value);
1da177e4
LT
480}
481
0897831b 482static void acpi_rs_out_integer32(char *title, u32 value)
50eca3eb 483{
0897831b 484 acpi_os_printf("%27s : %8.8X\n", title, value);
50eca3eb
BM
485}
486
0897831b 487static void acpi_rs_out_integer64(char *title, u64 value)
1da177e4 488{
0897831b 489 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
1da177e4
LT
490}
491
0897831b 492static void acpi_rs_out_title(char *title)
1da177e4 493{
0897831b 494 acpi_os_printf("%27s : ", title);
bda663d3 495}
1da177e4 496
bda663d3
RM
497/*******************************************************************************
498 *
0897831b 499 * FUNCTION: acpi_rs_dump*List
bda663d3 500 *
ba494bee
BM
501 * PARAMETERS: length - Number of elements in the list
502 * data - Start of the list
bda663d3
RM
503 *
504 * RETURN: None
505 *
0897831b 506 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
bda663d3
RM
507 *
508 ******************************************************************************/
1da177e4 509
0897831b 510static void acpi_rs_dump_byte_list(u16 length, u8 * data)
bda663d3 511{
0897831b 512 u8 i;
1da177e4 513
0897831b
BM
514 for (i = 0; i < length; i++) {
515 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
516 }
bda663d3 517}
1da177e4 518
0897831b 519static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
bda663d3 520{
0897831b 521 u8 i;
1da177e4 522
0897831b
BM
523 for (i = 0; i < length; i++) {
524 acpi_os_printf("%X ", data[i]);
525 }
526 acpi_os_printf("\n");
1da177e4
LT
527}
528
0897831b 529static void acpi_rs_dump_dword_list(u8 length, u32 * data)
1da177e4 530{
0897831b 531 u8 i;
1da177e4 532
0897831b
BM
533 for (i = 0; i < length; i++) {
534 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
1da177e4 535 }
1da177e4
LT
536}
537
e0fe0a8d
LM
538static void acpi_rs_dump_word_list(u16 length, u16 *data)
539{
540 u16 i;
541
542 for (i = 0; i < length; i++) {
543 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
544 }
545}
546
1da177e4 547#endif