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