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