ACPICA: Clarify ACPI_FREE_BUFFER usage.
[deliverable/linux.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:
1d1ea1b7 123
96db255c
BM
124 acpi_rs_out_string(name,
125 ACPI_CAST_PTR(char, table->pointer));
0897831b 126 break;
bda663d3 127
0897831b 128 case ACPI_RSD_STRING:
1d1ea1b7 129
96db255c 130 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
0897831b 131 break;
bda663d3 132
0897831b 133 /* Data items, 8/16/32/64 bit */
bda663d3 134
0897831b 135 case ACPI_RSD_UINT8:
1d1ea1b7 136
e0fe0a8d
LM
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));
144 }
0897831b 145 break;
bda663d3 146
0897831b 147 case ACPI_RSD_UINT16:
1d1ea1b7 148
c51a4de8 149 acpi_rs_out_integer16(name, ACPI_GET16(target));
0897831b
BM
150 break;
151
152 case ACPI_RSD_UINT32:
1d1ea1b7 153
c51a4de8 154 acpi_rs_out_integer32(name, ACPI_GET32(target));
0897831b 155 break;
50eca3eb 156
0897831b 157 case ACPI_RSD_UINT64:
1d1ea1b7 158
c51a4de8 159 acpi_rs_out_integer64(name, ACPI_GET64(target));
0897831b
BM
160 break;
161
162 /* Flags: 1-bit and 2-bit flags supported */
163
164 case ACPI_RSD_1BITFLAG:
1d1ea1b7 165
96db255c
BM
166 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
167 table->
168 pointer[*target &
169 0x01]));
0897831b
BM
170 break;
171
172 case ACPI_RSD_2BITFLAG:
1d1ea1b7 173
96db255c
BM
174 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
175 table->
176 pointer[*target &
177 0x03]));
0897831b
BM
178 break;
179
e0fe0a8d 180 case ACPI_RSD_3BITFLAG:
1d1ea1b7 181
e0fe0a8d
LM
182 acpi_rs_out_string(name, ACPI_CAST_PTR(char,
183 table->
184 pointer[*target &
185 0x07]));
186 break;
187
0897831b
BM
188 case ACPI_RSD_SHORTLIST:
189 /*
190 * Short byte list (single line output) for DMA and IRQ resources
191 * Note: The list length is obtained from the previous table entry
192 */
193 if (previous_target) {
194 acpi_rs_out_title(name);
96db255c
BM
195 acpi_rs_dump_short_byte_list(*previous_target,
196 target);
0897831b
BM
197 }
198 break;
199
e0fe0a8d
LM
200 case ACPI_RSD_SHORTLISTX:
201 /*
202 * Short byte list (single line output) for GPIO vendor data
203 * Note: The list length is obtained from the previous table entry
204 */
205 if (previous_target) {
206 acpi_rs_out_title(name);
207 acpi_rs_dump_short_byte_list(*previous_target,
208 *
209 (ACPI_CAST_INDIRECT_PTR
210 (u8, target)));
211 }
212 break;
213
0897831b
BM
214 case ACPI_RSD_LONGLIST:
215 /*
216 * Long byte list for Vendor resource data
217 * Note: The list length is obtained from the previous table entry
218 */
219 if (previous_target) {
c51a4de8
BM
220 acpi_rs_dump_byte_list(ACPI_GET16
221 (previous_target),
96db255c 222 target);
0897831b
BM
223 }
224 break;
225
226 case ACPI_RSD_DWORDLIST:
227 /*
228 * Dword list for Extended Interrupt resources
229 * Note: The list length is obtained from the previous table entry
230 */
231 if (previous_target) {
96db255c
BM
232 acpi_rs_dump_dword_list(*previous_target,
233 ACPI_CAST_PTR(u32,
234 target));
0897831b
BM
235 }
236 break;
237
e0fe0a8d
LM
238 case ACPI_RSD_WORDLIST:
239 /*
240 * Word list for GPIO Pin Table
241 * Note: The list length is obtained from the previous table entry
242 */
243 if (previous_target) {
244 acpi_rs_dump_word_list(*previous_target,
245 *(ACPI_CAST_INDIRECT_PTR
246 (u16, target)));
247 }
248 break;
249
0897831b
BM
250 case ACPI_RSD_ADDRESS:
251 /*
252 * Common flags for all Address resources
253 */
96db255c
BM
254 acpi_rs_dump_address_common(ACPI_CAST_PTR
255 (union acpi_resource_data,
256 target));
0897831b
BM
257 break;
258
259 case ACPI_RSD_SOURCE:
260 /*
261 * Optional resource_source for Address resources
262 */
3e8214e5
LZ
263 acpi_rs_dump_resource_source(ACPI_CAST_PTR
264 (struct
fd350943
LB
265 acpi_resource_source,
266 target));
0897831b
BM
267 break;
268
269 default:
1d1ea1b7 270
0897831b
BM
271 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
272 table->opcode);
273 return;
274 }
275
276 table++;
277 count--;
278 }
50eca3eb
BM
279}
280
bda663d3
RM
281/*******************************************************************************
282 *
283 * FUNCTION: acpi_rs_dump_resource_source
1da177e4 284 *
bda663d3 285 * PARAMETERS: resource_source - Pointer to a Resource Source struct
1da177e4
LT
286 *
287 * RETURN: None
288 *
bda663d3
RM
289 * DESCRIPTION: Common routine for dumping the optional resource_source and the
290 * corresponding resource_source_index.
1da177e4
LT
291 *
292 ******************************************************************************/
293
bda663d3
RM
294static void
295acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
1da177e4 296{
50eca3eb 297 ACPI_FUNCTION_ENTRY();
1da177e4 298
bda663d3
RM
299 if (resource_source->index == 0xFF) {
300 return;
301 }
302
0897831b 303 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
bda663d3
RM
304
305 acpi_rs_out_string("Resource Source",
306 resource_source->string_ptr ?
307 resource_source->string_ptr : "[Not Specified]");
308}
309
310/*******************************************************************************
311 *
312 * FUNCTION: acpi_rs_dump_address_common
313 *
ba494bee 314 * PARAMETERS: resource - Pointer to an internal resource descriptor
bda663d3
RM
315 *
316 * RETURN: None
317 *
318 * DESCRIPTION: Dump the fields that are common to all Address resource
319 * descriptors
320 *
321 ******************************************************************************/
322
323static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
324{
4be44fcd 325 ACPI_FUNCTION_ENTRY();
1da177e4 326
bda663d3
RM
327 /* Decode the type-specific flags */
328
329 switch (resource->address.resource_type) {
330 case ACPI_MEMORY_RANGE:
1da177e4 331
0897831b 332 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
bda663d3
RM
333 break;
334
335 case ACPI_IO_RANGE:
336
0897831b 337 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
bda663d3
RM
338 break;
339
340 case ACPI_BUS_NUMBER_RANGE:
341
342 acpi_rs_out_string("Resource Type", "Bus Number Range");
343 break;
344
345 default:
346
347 acpi_rs_out_integer8("Resource Type",
348 (u8) resource->address.resource_type);
349 break;
1da177e4
LT
350 }
351
bda663d3
RM
352 /* Decode the general flags */
353
0897831b 354 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
1da177e4
LT
355}
356
1da177e4
LT
357/*******************************************************************************
358 *
bda663d3 359 * FUNCTION: acpi_rs_dump_resource_list
1da177e4 360 *
bda663d3 361 * PARAMETERS: resource_list - Pointer to a resource descriptor list
1da177e4
LT
362 *
363 * RETURN: None
364 *
bda663d3 365 * DESCRIPTION: Dispatches the structure to the correct dump routine.
1da177e4
LT
366 *
367 ******************************************************************************/
368
bda663d3 369void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
1da177e4 370{
bda663d3 371 u32 count = 0;
0897831b 372 u32 type;
1da177e4 373
4be44fcd 374 ACPI_FUNCTION_ENTRY();
1da177e4 375
10e9e759
BM
376 /* Check if debug output enabled */
377
378 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
bda663d3
RM
379 return;
380 }
381
0897831b 382 /* Walk list and dump all resource descriptors (END_TAG terminates) */
bda663d3 383
0897831b 384 do {
bda663d3 385 acpi_os_printf("\n[%02X] ", count);
0897831b 386 count++;
bda663d3
RM
387
388 /* Validate Type before dispatch */
389
0897831b
BM
390 type = resource_list->type;
391 if (type > ACPI_RESOURCE_TYPE_MAX) {
bda663d3
RM
392 acpi_os_printf
393 ("Invalid descriptor type (%X) in resource list\n",
394 resource_list->type);
395 return;
396 }
397
c13085e5
BM
398 /* Sanity check the length. It must not be zero, or we loop forever */
399
400 if (!resource_list->length) {
401 acpi_os_printf
402 ("Invalid zero length descriptor in resource list\n");
403 return;
404 }
405
bda663d3
RM
406 /* Dump the resource descriptor */
407
e0fe0a8d
LM
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]);
417 }
bda663d3 418
0897831b 419 /* Point to the next resource structure */
bda663d3 420
e0fe0a8d 421 resource_list = ACPI_NEXT_RESOURCE(resource_list);
bda663d3 422
0897831b 423 /* Exit when END_TAG descriptor is reached */
bda663d3 424
0897831b 425 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
bda663d3
RM
426}
427
428/*******************************************************************************
429 *
0897831b 430 * FUNCTION: acpi_rs_dump_irq_list
bda663d3 431 *
0897831b 432 * PARAMETERS: route_table - Pointer to the routing table to dump.
bda663d3
RM
433 *
434 * RETURN: None
435 *
0897831b 436 * DESCRIPTION: Print IRQ routing table
bda663d3
RM
437 *
438 ******************************************************************************/
439
0897831b 440void acpi_rs_dump_irq_list(u8 * route_table)
bda663d3 441{
0897831b
BM
442 struct acpi_pci_routing_table *prt_element;
443 u8 count;
1da177e4 444
4be44fcd 445 ACPI_FUNCTION_ENTRY();
1da177e4 446
10e9e759
BM
447 /* Check if debug output enabled */
448
449 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
0897831b 450 return;
1da177e4
LT
451 }
452
0897831b 453 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
1da177e4 454
0897831b 455 /* Dump all table elements, Exit on zero length element */
1da177e4 456
0897831b
BM
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);
1da177e4 461
c51a4de8
BM
462 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
463 prt_element, prt_element->length);
1da177e4 464 }
1da177e4
LT
465}
466
1da177e4
LT
467/*******************************************************************************
468 *
0897831b 469 * FUNCTION: acpi_rs_out*
1da177e4 470 *
ba494bee
BM
471 * PARAMETERS: title - Name of the resource field
472 * value - Value of the resource field
1da177e4
LT
473 *
474 * RETURN: None
475 *
0897831b
BM
476 * DESCRIPTION: Miscellaneous helper functions to consistently format the
477 * output of the resource dump routines
1da177e4
LT
478 *
479 ******************************************************************************/
480
0897831b 481static void acpi_rs_out_string(char *title, char *value)
1da177e4 482{
b8e4d893
BM
483 acpi_os_printf("%27s : %s", title, value);
484 if (!*value) {
485 acpi_os_printf("[NULL NAMESTRING]");
486 }
487 acpi_os_printf("\n");
1da177e4
LT
488}
489
0897831b 490static void acpi_rs_out_integer8(char *title, u8 value)
1da177e4 491{
0897831b 492 acpi_os_printf("%27s : %2.2X\n", title, value);
1da177e4
LT
493}
494
0897831b 495static void acpi_rs_out_integer16(char *title, u16 value)
1da177e4 496{
0897831b 497 acpi_os_printf("%27s : %4.4X\n", title, value);
1da177e4
LT
498}
499
0897831b 500static void acpi_rs_out_integer32(char *title, u32 value)
50eca3eb 501{
0897831b 502 acpi_os_printf("%27s : %8.8X\n", title, value);
50eca3eb
BM
503}
504
0897831b 505static void acpi_rs_out_integer64(char *title, u64 value)
1da177e4 506{
0897831b 507 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
1da177e4
LT
508}
509
0897831b 510static void acpi_rs_out_title(char *title)
1da177e4 511{
0897831b 512 acpi_os_printf("%27s : ", title);
bda663d3 513}
1da177e4 514
bda663d3
RM
515/*******************************************************************************
516 *
0897831b 517 * FUNCTION: acpi_rs_dump*List
bda663d3 518 *
ba494bee
BM
519 * PARAMETERS: length - Number of elements in the list
520 * data - Start of the list
bda663d3
RM
521 *
522 * RETURN: None
523 *
0897831b 524 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
bda663d3
RM
525 *
526 ******************************************************************************/
1da177e4 527
0897831b 528static void acpi_rs_dump_byte_list(u16 length, u8 * data)
bda663d3 529{
0897831b 530 u8 i;
1da177e4 531
0897831b
BM
532 for (i = 0; i < length; i++) {
533 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
534 }
bda663d3 535}
1da177e4 536
0897831b 537static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
bda663d3 538{
0897831b 539 u8 i;
1da177e4 540
0897831b
BM
541 for (i = 0; i < length; i++) {
542 acpi_os_printf("%X ", data[i]);
543 }
544 acpi_os_printf("\n");
1da177e4
LT
545}
546
0897831b 547static void acpi_rs_dump_dword_list(u8 length, u32 * data)
1da177e4 548{
0897831b 549 u8 i;
1da177e4 550
0897831b
BM
551 for (i = 0; i < length; i++) {
552 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
1da177e4 553 }
1da177e4
LT
554}
555
e0fe0a8d
LM
556static void acpi_rs_dump_word_list(u16 length, u16 *data)
557{
558 u16 i;
559
560 for (i = 0; i < length; i++) {
561 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);
562 }
563}
564
1da177e4 565#endif
This page took 0.617302 seconds and 5 git commands to generate.