mm/hmm.c: remove superfluous RCU protection around radix tree lookup
[linux/fpc-iii.git] / drivers / acpi / acpica / rsdump.c
blobb12a0b1cd9ceda6717eddf6c1e00c1f426ef831e
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: rsdump - AML debugger support for resource structures.
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
10 #include "acresrc.h"
12 #define _COMPONENT ACPI_RESOURCES
13 ACPI_MODULE_NAME("rsdump")
16 * All functions in this module are used by the AML Debugger only
18 /* Local prototypes */
19 static void acpi_rs_out_string(const char *title, const char *value);
21 static void acpi_rs_out_integer8(const char *title, u8 value);
23 static void acpi_rs_out_integer16(const char *title, u16 value);
25 static void acpi_rs_out_integer32(const char *title, u32 value);
27 static void acpi_rs_out_integer64(const char *title, u64 value);
29 static void acpi_rs_out_title(const char *title);
31 static void acpi_rs_dump_byte_list(u16 length, u8 *data);
33 static void acpi_rs_dump_word_list(u16 length, u16 *data);
35 static void acpi_rs_dump_dword_list(u8 length, u32 *data);
37 static void acpi_rs_dump_short_byte_list(u8 length, u8 *data);
39 static void
40 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source);
42 static void
43 acpi_rs_dump_resource_label(char *title,
44 struct acpi_resource_label *resource_label);
46 static void acpi_rs_dump_address_common(union acpi_resource_data *resource);
48 static void
49 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
51 /*******************************************************************************
53 * FUNCTION: acpi_rs_dump_resource_list
55 * PARAMETERS: resource_list - Pointer to a resource descriptor list
57 * RETURN: None
59 * DESCRIPTION: Dispatches the structure to the correct dump routine.
61 ******************************************************************************/
63 void acpi_rs_dump_resource_list(struct acpi_resource *resource_list)
65 u32 count = 0;
66 u32 type;
68 ACPI_FUNCTION_ENTRY();
70 /* Check if debug output enabled */
72 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
73 return;
76 /* Walk list and dump all resource descriptors (END_TAG terminates) */
78 do {
79 acpi_os_printf("\n[%02X] ", count);
80 count++;
82 /* Validate Type before dispatch */
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;
92 /* Sanity check the length. It must not be zero, or we loop forever */
94 if (!resource_list->length) {
95 acpi_os_printf
96 ("Invalid zero length descriptor in resource list\n");
97 return;
100 /* Dump the resource descriptor */
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]);
113 /* Point to the next resource structure */
115 resource_list = ACPI_NEXT_RESOURCE(resource_list);
117 /* Exit when END_TAG descriptor is reached */
119 } while (type != ACPI_RESOURCE_TYPE_END_TAG);
122 /*******************************************************************************
124 * FUNCTION: acpi_rs_dump_irq_list
126 * PARAMETERS: route_table - Pointer to the routing table to dump.
128 * RETURN: None
130 * DESCRIPTION: Print IRQ routing table
132 ******************************************************************************/
134 void acpi_rs_dump_irq_list(u8 *route_table)
136 struct acpi_pci_routing_table *prt_element;
137 u8 count;
139 ACPI_FUNCTION_ENTRY();
141 /* Check if debug output enabled */
143 if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_RESOURCES, _COMPONENT)) {
144 return;
147 prt_element = ACPI_CAST_PTR(struct acpi_pci_routing_table, route_table);
149 /* Dump all table elements, Exit on zero length element */
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);
156 prt_element = ACPI_ADD_PTR(struct acpi_pci_routing_table,
157 prt_element, prt_element->length);
161 /*******************************************************************************
163 * FUNCTION: acpi_rs_dump_descriptor
165 * PARAMETERS: resource - Buffer containing the resource
166 * table - Table entry to decode the resource
168 * RETURN: None
170 * DESCRIPTION: Dump a resource descriptor based on a dump table entry.
172 ******************************************************************************/
174 static void
175 acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
177 u8 *target = NULL;
178 u8 *previous_target;
179 const char *name;
180 u8 count;
182 /* First table entry must contain the table length (# of table entries) */
184 count = table->offset;
186 while (count) {
187 previous_target = target;
188 target = ACPI_ADD_PTR(u8, resource, table->offset);
189 name = table->name;
191 switch (table->opcode) {
192 case ACPI_RSD_TITLE:
194 * Optional resource title
196 if (table->name) {
197 acpi_os_printf("%s Resource\n", name);
199 break;
201 /* Strings */
203 case ACPI_RSD_LITERAL:
205 acpi_rs_out_string(name,
206 ACPI_CAST_PTR(char, table->pointer));
207 break;
209 case ACPI_RSD_STRING:
211 acpi_rs_out_string(name, ACPI_CAST_PTR(char, target));
212 break;
214 /* Data items, 8/16/32/64 bit */
216 case ACPI_RSD_UINT8:
218 if (table->pointer) {
219 acpi_rs_out_string(name,
220 table->pointer[*target]);
221 } else {
222 acpi_rs_out_integer8(name, ACPI_GET8(target));
224 break;
226 case ACPI_RSD_UINT16:
228 acpi_rs_out_integer16(name, ACPI_GET16(target));
229 break;
231 case ACPI_RSD_UINT32:
233 acpi_rs_out_integer32(name, ACPI_GET32(target));
234 break;
236 case ACPI_RSD_UINT64:
238 acpi_rs_out_integer64(name, ACPI_GET64(target));
239 break;
241 /* Flags: 1-bit and 2-bit flags supported */
243 case ACPI_RSD_1BITFLAG:
245 acpi_rs_out_string(name,
246 table->pointer[*target & 0x01]);
247 break;
249 case ACPI_RSD_2BITFLAG:
251 acpi_rs_out_string(name,
252 table->pointer[*target & 0x03]);
253 break;
255 case ACPI_RSD_3BITFLAG:
257 acpi_rs_out_string(name,
258 table->pointer[*target & 0x07]);
259 break;
261 case ACPI_RSD_SHORTLIST:
263 * Short byte list (single line output) for DMA and IRQ resources
264 * Note: The list length is obtained from the previous table entry
266 if (previous_target) {
267 acpi_rs_out_title(name);
268 acpi_rs_dump_short_byte_list(*previous_target,
269 target);
271 break;
273 case ACPI_RSD_SHORTLISTX:
275 * Short byte list (single line output) for GPIO vendor data
276 * Note: The list length is obtained from the previous table entry
278 if (previous_target) {
279 acpi_rs_out_title(name);
280 acpi_rs_dump_short_byte_list(*previous_target,
282 (ACPI_CAST_INDIRECT_PTR
283 (u8, target)));
285 break;
287 case ACPI_RSD_LONGLIST:
289 * Long byte list for Vendor resource data
290 * Note: The list length is obtained from the previous table entry
292 if (previous_target) {
293 acpi_rs_dump_byte_list(ACPI_GET16
294 (previous_target),
295 target);
297 break;
299 case ACPI_RSD_DWORDLIST:
301 * Dword list for Extended Interrupt resources
302 * Note: The list length is obtained from the previous table entry
304 if (previous_target) {
305 acpi_rs_dump_dword_list(*previous_target,
306 ACPI_CAST_PTR(u32,
307 target));
309 break;
311 case ACPI_RSD_WORDLIST:
313 * Word list for GPIO Pin Table
314 * Note: The list length is obtained from the previous table entry
316 if (previous_target) {
317 acpi_rs_dump_word_list(*previous_target,
318 *(ACPI_CAST_INDIRECT_PTR
319 (u16, target)));
321 break;
323 case ACPI_RSD_ADDRESS:
325 * Common flags for all Address resources
327 acpi_rs_dump_address_common(ACPI_CAST_PTR
328 (union acpi_resource_data,
329 target));
330 break;
332 case ACPI_RSD_SOURCE:
334 * Optional resource_source for Address resources
336 acpi_rs_dump_resource_source(ACPI_CAST_PTR
337 (struct
338 acpi_resource_source,
339 target));
340 break;
342 case ACPI_RSD_LABEL:
344 * resource_label
346 acpi_rs_dump_resource_label("Resource Label",
347 ACPI_CAST_PTR(struct
348 acpi_resource_label,
349 target));
350 break;
352 case ACPI_RSD_SOURCE_LABEL:
354 * resource_source_label
356 acpi_rs_dump_resource_label("Resource Source Label",
357 ACPI_CAST_PTR(struct
358 acpi_resource_label,
359 target));
360 break;
362 default:
364 acpi_os_printf("**** Invalid table opcode [%X] ****\n",
365 table->opcode);
366 return;
369 table++;
370 count--;
374 /*******************************************************************************
376 * FUNCTION: acpi_rs_dump_resource_source
378 * PARAMETERS: resource_source - Pointer to a Resource Source struct
380 * RETURN: None
382 * DESCRIPTION: Common routine for dumping the optional resource_source and the
383 * corresponding resource_source_index.
385 ******************************************************************************/
387 static void
388 acpi_rs_dump_resource_source(struct acpi_resource_source *resource_source)
390 ACPI_FUNCTION_ENTRY();
392 if (resource_source->index == 0xFF) {
393 return;
396 acpi_rs_out_integer8("Resource Source Index", resource_source->index);
398 acpi_rs_out_string("Resource Source",
399 resource_source->string_ptr ?
400 resource_source->string_ptr : "[Not Specified]");
403 /*******************************************************************************
405 * FUNCTION: acpi_rs_dump_resource_label
407 * PARAMETERS: title - Title of the dumped resource field
408 * resource_label - Pointer to a Resource Label struct
410 * RETURN: None
412 * DESCRIPTION: Common routine for dumping the resource_label
414 ******************************************************************************/
416 static void
417 acpi_rs_dump_resource_label(char *title,
418 struct acpi_resource_label *resource_label)
420 ACPI_FUNCTION_ENTRY();
422 acpi_rs_out_string(title,
423 resource_label->string_ptr ?
424 resource_label->string_ptr : "[Not Specified]");
427 /*******************************************************************************
429 * FUNCTION: acpi_rs_dump_address_common
431 * PARAMETERS: resource - Pointer to an internal resource descriptor
433 * RETURN: None
435 * DESCRIPTION: Dump the fields that are common to all Address resource
436 * descriptors
438 ******************************************************************************/
440 static void acpi_rs_dump_address_common(union acpi_resource_data *resource)
442 ACPI_FUNCTION_ENTRY();
444 /* Decode the type-specific flags */
446 switch (resource->address.resource_type) {
447 case ACPI_MEMORY_RANGE:
449 acpi_rs_dump_descriptor(resource, acpi_rs_dump_memory_flags);
450 break;
452 case ACPI_IO_RANGE:
454 acpi_rs_dump_descriptor(resource, acpi_rs_dump_io_flags);
455 break;
457 case ACPI_BUS_NUMBER_RANGE:
459 acpi_rs_out_string("Resource Type", "Bus Number Range");
460 break;
462 default:
464 acpi_rs_out_integer8("Resource Type",
465 (u8) resource->address.resource_type);
466 break;
469 /* Decode the general flags */
471 acpi_rs_dump_descriptor(resource, acpi_rs_dump_general_flags);
474 /*******************************************************************************
476 * FUNCTION: acpi_rs_out*
478 * PARAMETERS: title - Name of the resource field
479 * value - Value of the resource field
481 * RETURN: None
483 * DESCRIPTION: Miscellaneous helper functions to consistently format the
484 * output of the resource dump routines
486 ******************************************************************************/
488 static void acpi_rs_out_string(const char *title, const char *value)
491 acpi_os_printf("%27s : %s", title, value);
492 if (!*value) {
493 acpi_os_printf("[NULL NAMESTRING]");
495 acpi_os_printf("\n");
498 static void acpi_rs_out_integer8(const char *title, u8 value)
500 acpi_os_printf("%27s : %2.2X\n", title, value);
503 static void acpi_rs_out_integer16(const char *title, u16 value)
506 acpi_os_printf("%27s : %4.4X\n", title, value);
509 static void acpi_rs_out_integer32(const char *title, u32 value)
512 acpi_os_printf("%27s : %8.8X\n", title, value);
515 static void acpi_rs_out_integer64(const char *title, u64 value)
518 acpi_os_printf("%27s : %8.8X%8.8X\n", title, ACPI_FORMAT_UINT64(value));
521 static void acpi_rs_out_title(const char *title)
524 acpi_os_printf("%27s : ", title);
527 /*******************************************************************************
529 * FUNCTION: acpi_rs_dump*List
531 * PARAMETERS: length - Number of elements in the list
532 * data - Start of the list
534 * RETURN: None
536 * DESCRIPTION: Miscellaneous functions to dump lists of raw data
538 ******************************************************************************/
540 static void acpi_rs_dump_byte_list(u16 length, u8 * data)
542 u8 i;
544 for (i = 0; i < length; i++) {
545 acpi_os_printf("%25s%2.2X : %2.2X\n", "Byte", i, data[i]);
549 static void acpi_rs_dump_short_byte_list(u8 length, u8 * data)
551 u8 i;
553 for (i = 0; i < length; i++) {
554 acpi_os_printf("%X ", data[i]);
557 acpi_os_printf("\n");
560 static void acpi_rs_dump_dword_list(u8 length, u32 * data)
562 u8 i;
564 for (i = 0; i < length; i++) {
565 acpi_os_printf("%25s%2.2X : %8.8X\n", "Dword", i, data[i]);
569 static void acpi_rs_dump_word_list(u16 length, u16 *data)
571 u16 i;
573 for (i = 0; i < length; i++) {
574 acpi_os_printf("%25s%2.2X : %4.4X\n", "Word", i, data[i]);