xref: /openbmc/linux/drivers/acpi/acpica/exdump.c (revision 5bd8e16d)
1 /******************************************************************************
2  *
3  * Module Name: exdump - Interpreter debug output routines
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, 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 "acinterp.h"
47 #include "amlcode.h"
48 #include "acnamesp.h"
49 
50 #define _COMPONENT          ACPI_EXECUTER
51 ACPI_MODULE_NAME("exdump")
52 
53 /*
54  * The following routines are used for debug output only
55  */
56 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
57 /* Local prototypes */
58 static void acpi_ex_out_string(char *title, char *value);
59 
60 static void acpi_ex_out_pointer(char *title, void *value);
61 
62 static void
63 acpi_ex_dump_object(union acpi_operand_object *obj_desc,
64 		    struct acpi_exdump_info *info);
65 
66 static void acpi_ex_dump_reference_obj(union acpi_operand_object *obj_desc);
67 
68 static void
69 acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
70 			 u32 level, u32 index);
71 
72 /*******************************************************************************
73  *
74  * Object Descriptor info tables
75  *
76  * Note: The first table entry must be an INIT opcode and must contain
77  * the table length (number of table entries)
78  *
79  ******************************************************************************/
80 
81 static struct acpi_exdump_info acpi_ex_dump_integer[2] = {
82 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_integer), NULL},
83 	{ACPI_EXD_UINT64, ACPI_EXD_OFFSET(integer.value), "Value"}
84 };
85 
86 static struct acpi_exdump_info acpi_ex_dump_string[4] = {
87 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_string), NULL},
88 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(string.length), "Length"},
89 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(string.pointer), "Pointer"},
90 	{ACPI_EXD_STRING, 0, NULL}
91 };
92 
93 static struct acpi_exdump_info acpi_ex_dump_buffer[5] = {
94 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer), NULL},
95 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(buffer.length), "Length"},
96 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.pointer), "Pointer"},
97 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer.node), "Parent Node"},
98 	{ACPI_EXD_BUFFER, 0, NULL}
99 };
100 
101 static struct acpi_exdump_info acpi_ex_dump_package[5] = {
102 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_package), NULL},
103 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(package.flags), "Flags"},
104 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(package.count), "Elements"},
105 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(package.elements), "Element List"},
106 	{ACPI_EXD_PACKAGE, 0, NULL}
107 };
108 
109 static struct acpi_exdump_info acpi_ex_dump_device[4] = {
110 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_device), NULL},
111 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.handler), "Handler"},
112 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.notify_list[0]),
113 	 "System Notify"},
114 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(device.notify_list[1]),
115 	 "Device Notify"}
116 };
117 
118 static struct acpi_exdump_info acpi_ex_dump_event[2] = {
119 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_event), NULL},
120 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(event.os_semaphore), "OsSemaphore"}
121 };
122 
123 static struct acpi_exdump_info acpi_ex_dump_method[9] = {
124 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_method), NULL},
125 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.info_flags), "Info Flags"},
126 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.param_count),
127 	 "Parameter Count"},
128 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.sync_level), "Sync Level"},
129 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.mutex), "Mutex"},
130 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.owner_id), "Owner Id"},
131 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(method.thread_count), "Thread Count"},
132 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(method.aml_length), "Aml Length"},
133 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(method.aml_start), "Aml Start"}
134 };
135 
136 static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
137 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
138 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
139 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"},
140 	{ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
141 	 "Acquire Depth"},
142 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
143 };
144 
145 static struct acpi_exdump_info acpi_ex_dump_region[7] = {
146 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_region), NULL},
147 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(region.space_id), "Space Id"},
148 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(region.flags), "Flags"},
149 	{ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(region.address), "Address"},
150 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(region.length), "Length"},
151 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(region.handler), "Handler"},
152 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(region.next), "Next"}
153 };
154 
155 static struct acpi_exdump_info acpi_ex_dump_power[5] = {
156 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_power), NULL},
157 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(power_resource.system_level),
158 	 "System Level"},
159 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(power_resource.resource_order),
160 	 "Resource Order"},
161 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(power_resource.notify_list[0]),
162 	 "System Notify"},
163 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(power_resource.notify_list[1]),
164 	 "Device Notify"}
165 };
166 
167 static struct acpi_exdump_info acpi_ex_dump_processor[7] = {
168 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_processor), NULL},
169 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.proc_id), "Processor ID"},
170 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(processor.length), "Length"},
171 	{ACPI_EXD_ADDRESS, ACPI_EXD_OFFSET(processor.address), "Address"},
172 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.notify_list[0]),
173 	 "System Notify"},
174 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.notify_list[1]),
175 	 "Device Notify"},
176 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(processor.handler), "Handler"}
177 };
178 
179 static struct acpi_exdump_info acpi_ex_dump_thermal[4] = {
180 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_thermal), NULL},
181 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.notify_list[0]),
182 	 "System Notify"},
183 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.notify_list[1]),
184 	 "Device Notify"},
185 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(thermal_zone.handler), "Handler"}
186 };
187 
188 static struct acpi_exdump_info acpi_ex_dump_buffer_field[3] = {
189 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_buffer_field), NULL},
190 	{ACPI_EXD_FIELD, 0, NULL},
191 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(buffer_field.buffer_obj),
192 	 "Buffer Object"}
193 };
194 
195 static struct acpi_exdump_info acpi_ex_dump_region_field[5] = {
196 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_region_field), NULL},
197 	{ACPI_EXD_FIELD, 0, NULL},
198 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(field.access_length), "AccessLength"},
199 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(field.region_obj), "Region Object"},
200 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(field.resource_buffer),
201 	 "ResourceBuffer"}
202 };
203 
204 static struct acpi_exdump_info acpi_ex_dump_bank_field[5] = {
205 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_bank_field), NULL},
206 	{ACPI_EXD_FIELD, 0, NULL},
207 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(bank_field.value), "Value"},
208 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(bank_field.region_obj),
209 	 "Region Object"},
210 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(bank_field.bank_obj), "Bank Object"}
211 };
212 
213 static struct acpi_exdump_info acpi_ex_dump_index_field[5] = {
214 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_bank_field), NULL},
215 	{ACPI_EXD_FIELD, 0, NULL},
216 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(index_field.value), "Value"},
217 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(index_field.index_obj),
218 	 "Index Object"},
219 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(index_field.data_obj), "Data Object"}
220 };
221 
222 static struct acpi_exdump_info acpi_ex_dump_reference[8] = {
223 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_reference), NULL},
224 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(reference.class), "Class"},
225 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(reference.target_type), "Target Type"},
226 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(reference.value), "Value"},
227 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.object), "Object Desc"},
228 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.node), "Node"},
229 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(reference.where), "Where"},
230 	{ACPI_EXD_REFERENCE, 0, NULL}
231 };
232 
233 static struct acpi_exdump_info acpi_ex_dump_address_handler[6] = {
234 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_address_handler),
235 	 NULL},
236 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(address_space.space_id), "Space Id"},
237 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.next), "Next"},
238 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.region_list),
239 	 "Region List"},
240 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.node), "Node"},
241 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(address_space.context), "Context"}
242 };
243 
244 static struct acpi_exdump_info acpi_ex_dump_notify[7] = {
245 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_notify), NULL},
246 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.node), "Node"},
247 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(notify.handler_type), "Handler Type"},
248 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.handler), "Handler"},
249 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.context), "Context"},
250 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.next[0]),
251 	 "Next System Notify"},
252 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(notify.next[1]), "Next Device Notify"}
253 };
254 
255 /* Miscellaneous tables */
256 
257 static struct acpi_exdump_info acpi_ex_dump_common[4] = {
258 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_common), NULL},
259 	{ACPI_EXD_TYPE, 0, NULL},
260 	{ACPI_EXD_UINT16, ACPI_EXD_OFFSET(common.reference_count),
261 	 "Reference Count"},
262 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common.flags), "Flags"}
263 };
264 
265 static struct acpi_exdump_info acpi_ex_dump_field_common[7] = {
266 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_field_common), NULL},
267 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.field_flags),
268 	 "Field Flags"},
269 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.access_byte_width),
270 	 "Access Byte Width"},
271 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(common_field.bit_length),
272 	 "Bit Length"},
273 	{ACPI_EXD_UINT8, ACPI_EXD_OFFSET(common_field.start_field_bit_offset),
274 	 "Field Bit Offset"},
275 	{ACPI_EXD_UINT32, ACPI_EXD_OFFSET(common_field.base_byte_offset),
276 	 "Base Byte Offset"},
277 	{ACPI_EXD_POINTER, ACPI_EXD_OFFSET(common_field.node), "Parent Node"}
278 };
279 
280 static struct acpi_exdump_info acpi_ex_dump_node[5] = {
281 	{ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_node), NULL},
282 	{ACPI_EXD_UINT8, ACPI_EXD_NSOFFSET(flags), "Flags"},
283 	{ACPI_EXD_UINT8, ACPI_EXD_NSOFFSET(owner_id), "Owner Id"},
284 	{ACPI_EXD_POINTER, ACPI_EXD_NSOFFSET(child), "Child List"},
285 	{ACPI_EXD_POINTER, ACPI_EXD_NSOFFSET(peer), "Next Peer"}
286 };
287 
288 /* Dispatch table, indexed by object type */
289 
290 static struct acpi_exdump_info *acpi_ex_dump_info[] = {
291 	NULL,
292 	acpi_ex_dump_integer,
293 	acpi_ex_dump_string,
294 	acpi_ex_dump_buffer,
295 	acpi_ex_dump_package,
296 	NULL,
297 	acpi_ex_dump_device,
298 	acpi_ex_dump_event,
299 	acpi_ex_dump_method,
300 	acpi_ex_dump_mutex,
301 	acpi_ex_dump_region,
302 	acpi_ex_dump_power,
303 	acpi_ex_dump_processor,
304 	acpi_ex_dump_thermal,
305 	acpi_ex_dump_buffer_field,
306 	NULL,
307 	NULL,
308 	acpi_ex_dump_region_field,
309 	acpi_ex_dump_bank_field,
310 	acpi_ex_dump_index_field,
311 	acpi_ex_dump_reference,
312 	NULL,
313 	NULL,
314 	acpi_ex_dump_notify,
315 	acpi_ex_dump_address_handler,
316 	NULL,
317 	NULL,
318 	NULL
319 };
320 
321 /*******************************************************************************
322  *
323  * FUNCTION:    acpi_ex_dump_object
324  *
325  * PARAMETERS:  obj_desc            - Descriptor to dump
326  *              info                - Info table corresponding to this object
327  *                                    type
328  *
329  * RETURN:      None
330  *
331  * DESCRIPTION: Walk the info table for this object
332  *
333  ******************************************************************************/
334 
335 static void
336 acpi_ex_dump_object(union acpi_operand_object *obj_desc,
337 		    struct acpi_exdump_info *info)
338 {
339 	u8 *target;
340 	char *name;
341 	const char *reference_name;
342 	u8 count;
343 
344 	if (!info) {
345 		acpi_os_printf
346 		    ("ExDumpObject: Display not implemented for object type %s\n",
347 		     acpi_ut_get_object_type_name(obj_desc));
348 		return;
349 	}
350 
351 	/* First table entry must contain the table length (# of table entries) */
352 
353 	count = info->offset;
354 
355 	while (count) {
356 		target = ACPI_ADD_PTR(u8, obj_desc, info->offset);
357 		name = info->name;
358 
359 		switch (info->opcode) {
360 		case ACPI_EXD_INIT:
361 
362 			break;
363 
364 		case ACPI_EXD_TYPE:
365 
366 			acpi_ex_out_string("Type",
367 					   acpi_ut_get_object_type_name
368 					   (obj_desc));
369 			break;
370 
371 		case ACPI_EXD_UINT8:
372 
373 			acpi_os_printf("%20s : %2.2X\n", name, *target);
374 			break;
375 
376 		case ACPI_EXD_UINT16:
377 
378 			acpi_os_printf("%20s : %4.4X\n", name,
379 				       ACPI_GET16(target));
380 			break;
381 
382 		case ACPI_EXD_UINT32:
383 
384 			acpi_os_printf("%20s : %8.8X\n", name,
385 				       ACPI_GET32(target));
386 			break;
387 
388 		case ACPI_EXD_UINT64:
389 
390 			acpi_os_printf("%20s : %8.8X%8.8X\n", "Value",
391 				       ACPI_FORMAT_UINT64(ACPI_GET64(target)));
392 			break;
393 
394 		case ACPI_EXD_POINTER:
395 		case ACPI_EXD_ADDRESS:
396 
397 			acpi_ex_out_pointer(name,
398 					    *ACPI_CAST_PTR(void *, target));
399 			break;
400 
401 		case ACPI_EXD_STRING:
402 
403 			acpi_ut_print_string(obj_desc->string.pointer,
404 					     ACPI_UINT8_MAX);
405 			acpi_os_printf("\n");
406 			break;
407 
408 		case ACPI_EXD_BUFFER:
409 
410 			ACPI_DUMP_BUFFER(obj_desc->buffer.pointer,
411 					 obj_desc->buffer.length);
412 			break;
413 
414 		case ACPI_EXD_PACKAGE:
415 
416 			/* Dump the package contents */
417 
418 			acpi_os_printf("\nPackage Contents:\n");
419 			acpi_ex_dump_package_obj(obj_desc, 0, 0);
420 			break;
421 
422 		case ACPI_EXD_FIELD:
423 
424 			acpi_ex_dump_object(obj_desc,
425 					    acpi_ex_dump_field_common);
426 			break;
427 
428 		case ACPI_EXD_REFERENCE:
429 
430 			reference_name = acpi_ut_get_reference_name(obj_desc);
431 			acpi_ex_out_string("Class Name",
432 					   ACPI_CAST_PTR(char, reference_name));
433 			acpi_ex_dump_reference_obj(obj_desc);
434 			break;
435 
436 		default:
437 
438 			acpi_os_printf("**** Invalid table opcode [%X] ****\n",
439 				       info->opcode);
440 			return;
441 		}
442 
443 		info++;
444 		count--;
445 	}
446 }
447 
448 /*******************************************************************************
449  *
450  * FUNCTION:    acpi_ex_dump_operand
451  *
452  * PARAMETERS:  *obj_desc       - Pointer to entry to be dumped
453  *              depth           - Current nesting depth
454  *
455  * RETURN:      None
456  *
457  * DESCRIPTION: Dump an operand object
458  *
459  ******************************************************************************/
460 
461 void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
462 {
463 	u32 length;
464 	u32 index;
465 
466 	ACPI_FUNCTION_NAME(ex_dump_operand)
467 
468 	    /* Check if debug output enabled */
469 	    if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_EXEC, _COMPONENT)) {
470 		return;
471 	}
472 
473 	if (!obj_desc) {
474 
475 		/* This could be a null element of a package */
476 
477 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Null Object Descriptor\n"));
478 		return;
479 	}
480 
481 	if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) {
482 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%p Namespace Node: ",
483 				  obj_desc));
484 		ACPI_DUMP_ENTRY(obj_desc, ACPI_LV_EXEC);
485 		return;
486 	}
487 
488 	if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
489 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
490 				  "%p is not a node or operand object: [%s]\n",
491 				  obj_desc,
492 				  acpi_ut_get_descriptor_name(obj_desc)));
493 		ACPI_DUMP_BUFFER(obj_desc, sizeof(union acpi_operand_object));
494 		return;
495 	}
496 
497 	/* obj_desc is a valid object */
498 
499 	if (depth > 0) {
500 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%*s[%u] %p ",
501 				  depth, " ", depth, obj_desc));
502 	} else {
503 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%p ", obj_desc));
504 	}
505 
506 	/* Decode object type */
507 
508 	switch (obj_desc->common.type) {
509 	case ACPI_TYPE_LOCAL_REFERENCE:
510 
511 		acpi_os_printf("Reference: [%s] ",
512 			       acpi_ut_get_reference_name(obj_desc));
513 
514 		switch (obj_desc->reference.class) {
515 		case ACPI_REFCLASS_DEBUG:
516 
517 			acpi_os_printf("\n");
518 			break;
519 
520 		case ACPI_REFCLASS_INDEX:
521 
522 			acpi_os_printf("%p\n", obj_desc->reference.object);
523 			break;
524 
525 		case ACPI_REFCLASS_TABLE:
526 
527 			acpi_os_printf("Table Index %X\n",
528 				       obj_desc->reference.value);
529 			break;
530 
531 		case ACPI_REFCLASS_REFOF:
532 
533 			acpi_os_printf("%p [%s]\n", obj_desc->reference.object,
534 				       acpi_ut_get_type_name(((union
535 							       acpi_operand_object
536 							       *)
537 							      obj_desc->
538 							      reference.
539 							      object)->common.
540 							     type));
541 			break;
542 
543 		case ACPI_REFCLASS_NAME:
544 
545 			acpi_os_printf("- [%4.4s]\n",
546 				       obj_desc->reference.node->name.ascii);
547 			break;
548 
549 		case ACPI_REFCLASS_ARG:
550 		case ACPI_REFCLASS_LOCAL:
551 
552 			acpi_os_printf("%X\n", obj_desc->reference.value);
553 			break;
554 
555 		default:	/* Unknown reference class */
556 
557 			acpi_os_printf("%2.2X\n", obj_desc->reference.class);
558 			break;
559 		}
560 		break;
561 
562 	case ACPI_TYPE_BUFFER:
563 
564 		acpi_os_printf("Buffer length %.2X @ %p\n",
565 			       obj_desc->buffer.length,
566 			       obj_desc->buffer.pointer);
567 
568 		/* Debug only -- dump the buffer contents */
569 
570 		if (obj_desc->buffer.pointer) {
571 			length = obj_desc->buffer.length;
572 			if (length > 128) {
573 				length = 128;
574 			}
575 
576 			acpi_os_printf
577 			    ("Buffer Contents: (displaying length 0x%.2X)\n",
578 			     length);
579 			ACPI_DUMP_BUFFER(obj_desc->buffer.pointer, length);
580 		}
581 		break;
582 
583 	case ACPI_TYPE_INTEGER:
584 
585 		acpi_os_printf("Integer %8.8X%8.8X\n",
586 			       ACPI_FORMAT_UINT64(obj_desc->integer.value));
587 		break;
588 
589 	case ACPI_TYPE_PACKAGE:
590 
591 		acpi_os_printf("Package [Len %X] ElementArray %p\n",
592 			       obj_desc->package.count,
593 			       obj_desc->package.elements);
594 
595 		/*
596 		 * If elements exist, package element pointer is valid,
597 		 * and debug_level exceeds 1, dump package's elements.
598 		 */
599 		if (obj_desc->package.count &&
600 		    obj_desc->package.elements && acpi_dbg_level > 1) {
601 			for (index = 0; index < obj_desc->package.count;
602 			     index++) {
603 				acpi_ex_dump_operand(obj_desc->package.
604 						     elements[index],
605 						     depth + 1);
606 			}
607 		}
608 		break;
609 
610 	case ACPI_TYPE_REGION:
611 
612 		acpi_os_printf("Region %s (%X)",
613 			       acpi_ut_get_region_name(obj_desc->region.
614 						       space_id),
615 			       obj_desc->region.space_id);
616 
617 		/*
618 		 * If the address and length have not been evaluated,
619 		 * don't print them.
620 		 */
621 		if (!(obj_desc->region.flags & AOPOBJ_DATA_VALID)) {
622 			acpi_os_printf("\n");
623 		} else {
624 			acpi_os_printf(" base %8.8X%8.8X Length %X\n",
625 				       ACPI_FORMAT_NATIVE_UINT(obj_desc->region.
626 							       address),
627 				       obj_desc->region.length);
628 		}
629 		break;
630 
631 	case ACPI_TYPE_STRING:
632 
633 		acpi_os_printf("String length %X @ %p ",
634 			       obj_desc->string.length,
635 			       obj_desc->string.pointer);
636 
637 		acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
638 		acpi_os_printf("\n");
639 		break;
640 
641 	case ACPI_TYPE_LOCAL_BANK_FIELD:
642 
643 		acpi_os_printf("BankField\n");
644 		break;
645 
646 	case ACPI_TYPE_LOCAL_REGION_FIELD:
647 
648 		acpi_os_printf
649 		    ("RegionField: Bits=%X AccWidth=%X Lock=%X Update=%X at "
650 		     "byte=%X bit=%X of below:\n", obj_desc->field.bit_length,
651 		     obj_desc->field.access_byte_width,
652 		     obj_desc->field.field_flags & AML_FIELD_LOCK_RULE_MASK,
653 		     obj_desc->field.field_flags & AML_FIELD_UPDATE_RULE_MASK,
654 		     obj_desc->field.base_byte_offset,
655 		     obj_desc->field.start_field_bit_offset);
656 
657 		acpi_ex_dump_operand(obj_desc->field.region_obj, depth + 1);
658 		break;
659 
660 	case ACPI_TYPE_LOCAL_INDEX_FIELD:
661 
662 		acpi_os_printf("IndexField\n");
663 		break;
664 
665 	case ACPI_TYPE_BUFFER_FIELD:
666 
667 		acpi_os_printf("BufferField: %X bits at byte %X bit %X of\n",
668 			       obj_desc->buffer_field.bit_length,
669 			       obj_desc->buffer_field.base_byte_offset,
670 			       obj_desc->buffer_field.start_field_bit_offset);
671 
672 		if (!obj_desc->buffer_field.buffer_obj) {
673 			ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "*NULL*\n"));
674 		} else if ((obj_desc->buffer_field.buffer_obj)->common.type !=
675 			   ACPI_TYPE_BUFFER) {
676 			acpi_os_printf("*not a Buffer*\n");
677 		} else {
678 			acpi_ex_dump_operand(obj_desc->buffer_field.buffer_obj,
679 					     depth + 1);
680 		}
681 		break;
682 
683 	case ACPI_TYPE_EVENT:
684 
685 		acpi_os_printf("Event\n");
686 		break;
687 
688 	case ACPI_TYPE_METHOD:
689 
690 		acpi_os_printf("Method(%X) @ %p:%X\n",
691 			       obj_desc->method.param_count,
692 			       obj_desc->method.aml_start,
693 			       obj_desc->method.aml_length);
694 		break;
695 
696 	case ACPI_TYPE_MUTEX:
697 
698 		acpi_os_printf("Mutex\n");
699 		break;
700 
701 	case ACPI_TYPE_DEVICE:
702 
703 		acpi_os_printf("Device\n");
704 		break;
705 
706 	case ACPI_TYPE_POWER:
707 
708 		acpi_os_printf("Power\n");
709 		break;
710 
711 	case ACPI_TYPE_PROCESSOR:
712 
713 		acpi_os_printf("Processor\n");
714 		break;
715 
716 	case ACPI_TYPE_THERMAL:
717 
718 		acpi_os_printf("Thermal\n");
719 		break;
720 
721 	default:
722 
723 		/* Unknown Type */
724 
725 		acpi_os_printf("Unknown Type %X\n", obj_desc->common.type);
726 		break;
727 	}
728 
729 	return;
730 }
731 
732 /*******************************************************************************
733  *
734  * FUNCTION:    acpi_ex_dump_operands
735  *
736  * PARAMETERS:  operands            - A list of Operand objects
737  *		opcode_name	    - AML opcode name
738  *		num_operands	    - Operand count for this opcode
739  *
740  * DESCRIPTION: Dump the operands associated with the opcode
741  *
742  ******************************************************************************/
743 
744 void
745 acpi_ex_dump_operands(union acpi_operand_object **operands,
746 		      const char *opcode_name, u32 num_operands)
747 {
748 	ACPI_FUNCTION_NAME(ex_dump_operands);
749 
750 	if (!opcode_name) {
751 		opcode_name = "UNKNOWN";
752 	}
753 
754 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
755 			  "**** Start operand dump for opcode [%s], %u operands\n",
756 			  opcode_name, num_operands));
757 
758 	if (num_operands == 0) {
759 		num_operands = 1;
760 	}
761 
762 	/* Dump the individual operands */
763 
764 	while (num_operands) {
765 		acpi_ex_dump_operand(*operands, 0);
766 		operands++;
767 		num_operands--;
768 	}
769 
770 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
771 			  "**** End operand dump for [%s]\n", opcode_name));
772 	return;
773 }
774 
775 /*******************************************************************************
776  *
777  * FUNCTION:    acpi_ex_out* functions
778  *
779  * PARAMETERS:  title               - Descriptive text
780  *              value               - Value to be displayed
781  *
782  * DESCRIPTION: Object dump output formatting functions. These functions
783  *              reduce the number of format strings required and keeps them
784  *              all in one place for easy modification.
785  *
786  ******************************************************************************/
787 
788 static void acpi_ex_out_string(char *title, char *value)
789 {
790 	acpi_os_printf("%20s : %s\n", title, value);
791 }
792 
793 static void acpi_ex_out_pointer(char *title, void *value)
794 {
795 	acpi_os_printf("%20s : %p\n", title, value);
796 }
797 
798 /*******************************************************************************
799  *
800  * FUNCTION:    acpi_ex_dump_namespace_node
801  *
802  * PARAMETERS:  node                - Descriptor to dump
803  *              flags               - Force display if TRUE
804  *
805  * DESCRIPTION: Dumps the members of the given.Node
806  *
807  ******************************************************************************/
808 
809 void acpi_ex_dump_namespace_node(struct acpi_namespace_node *node, u32 flags)
810 {
811 
812 	ACPI_FUNCTION_ENTRY();
813 
814 	if (!flags) {
815 
816 		/* Check if debug output enabled */
817 
818 		if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_OBJECTS, _COMPONENT)) {
819 			return;
820 		}
821 	}
822 
823 	acpi_os_printf("%20s : %4.4s\n", "Name", acpi_ut_get_node_name(node));
824 	acpi_ex_out_string("Type", acpi_ut_get_type_name(node->type));
825 	acpi_ex_out_pointer("Attached Object",
826 			    acpi_ns_get_attached_object(node));
827 	acpi_ex_out_pointer("Parent", node->parent);
828 
829 	acpi_ex_dump_object(ACPI_CAST_PTR(union acpi_operand_object, node),
830 			    acpi_ex_dump_node);
831 }
832 
833 /*******************************************************************************
834  *
835  * FUNCTION:    acpi_ex_dump_reference_obj
836  *
837  * PARAMETERS:  object              - Descriptor to dump
838  *
839  * DESCRIPTION: Dumps a reference object
840  *
841  ******************************************************************************/
842 
843 static void acpi_ex_dump_reference_obj(union acpi_operand_object *obj_desc)
844 {
845 	struct acpi_buffer ret_buf;
846 	acpi_status status;
847 
848 	ret_buf.length = ACPI_ALLOCATE_LOCAL_BUFFER;
849 
850 	if (obj_desc->reference.class == ACPI_REFCLASS_NAME) {
851 		acpi_os_printf(" %p ", obj_desc->reference.node);
852 
853 		status =
854 		    acpi_ns_handle_to_pathname(obj_desc->reference.node,
855 					       &ret_buf);
856 		if (ACPI_FAILURE(status)) {
857 			acpi_os_printf(" Could not convert name to pathname\n");
858 		} else {
859 			acpi_os_printf("%s\n", (char *)ret_buf.pointer);
860 			ACPI_FREE(ret_buf.pointer);
861 		}
862 	} else if (obj_desc->reference.object) {
863 		if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
864 		    ACPI_DESC_TYPE_OPERAND) {
865 			acpi_os_printf(" Target: %p",
866 				       obj_desc->reference.object);
867 			if (obj_desc->reference.class == ACPI_REFCLASS_TABLE) {
868 				acpi_os_printf(" Table Index: %X\n",
869 					       obj_desc->reference.value);
870 			} else {
871 				acpi_os_printf(" Target: %p [%s]\n",
872 					       obj_desc->reference.object,
873 					       acpi_ut_get_type_name(((union
874 								       acpi_operand_object
875 								       *)
876 								      obj_desc->
877 								      reference.
878 								      object)->
879 								     common.
880 								     type));
881 			}
882 		} else {
883 			acpi_os_printf(" Target: %p\n",
884 				       obj_desc->reference.object);
885 		}
886 	}
887 }
888 
889 /*******************************************************************************
890  *
891  * FUNCTION:    acpi_ex_dump_package_obj
892  *
893  * PARAMETERS:  obj_desc            - Descriptor to dump
894  *              level               - Indentation Level
895  *              index               - Package index for this object
896  *
897  * DESCRIPTION: Dumps the elements of the package
898  *
899  ******************************************************************************/
900 
901 static void
902 acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
903 			 u32 level, u32 index)
904 {
905 	u32 i;
906 
907 	/* Indentation and index output */
908 
909 	if (level > 0) {
910 		for (i = 0; i < level; i++) {
911 			acpi_os_printf(" ");
912 		}
913 
914 		acpi_os_printf("[%.2d] ", index);
915 	}
916 
917 	acpi_os_printf("%p ", obj_desc);
918 
919 	/* Null package elements are allowed */
920 
921 	if (!obj_desc) {
922 		acpi_os_printf("[Null Object]\n");
923 		return;
924 	}
925 
926 	/* Packages may only contain a few object types */
927 
928 	switch (obj_desc->common.type) {
929 	case ACPI_TYPE_INTEGER:
930 
931 		acpi_os_printf("[Integer] = %8.8X%8.8X\n",
932 			       ACPI_FORMAT_UINT64(obj_desc->integer.value));
933 		break;
934 
935 	case ACPI_TYPE_STRING:
936 
937 		acpi_os_printf("[String] Value: ");
938 		acpi_ut_print_string(obj_desc->string.pointer, ACPI_UINT8_MAX);
939 		acpi_os_printf("\n");
940 		break;
941 
942 	case ACPI_TYPE_BUFFER:
943 
944 		acpi_os_printf("[Buffer] Length %.2X = ",
945 			       obj_desc->buffer.length);
946 		if (obj_desc->buffer.length) {
947 			acpi_ut_debug_dump_buffer(ACPI_CAST_PTR
948 						  (u8,
949 						   obj_desc->buffer.pointer),
950 						  obj_desc->buffer.length,
951 						  DB_DWORD_DISPLAY, _COMPONENT);
952 		} else {
953 			acpi_os_printf("\n");
954 		}
955 		break;
956 
957 	case ACPI_TYPE_PACKAGE:
958 
959 		acpi_os_printf("[Package] Contains %u Elements:\n",
960 			       obj_desc->package.count);
961 
962 		for (i = 0; i < obj_desc->package.count; i++) {
963 			acpi_ex_dump_package_obj(obj_desc->package.elements[i],
964 						 level + 1, i);
965 		}
966 		break;
967 
968 	case ACPI_TYPE_LOCAL_REFERENCE:
969 
970 		acpi_os_printf("[Object Reference] Type [%s] %2.2X",
971 			       acpi_ut_get_reference_name(obj_desc),
972 			       obj_desc->reference.class);
973 		acpi_ex_dump_reference_obj(obj_desc);
974 		break;
975 
976 	default:
977 
978 		acpi_os_printf("[Unknown Type] %X\n", obj_desc->common.type);
979 		break;
980 	}
981 }
982 
983 /*******************************************************************************
984  *
985  * FUNCTION:    acpi_ex_dump_object_descriptor
986  *
987  * PARAMETERS:  obj_desc            - Descriptor to dump
988  *              flags               - Force display if TRUE
989  *
990  * DESCRIPTION: Dumps the members of the object descriptor given.
991  *
992  ******************************************************************************/
993 
994 void
995 acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags)
996 {
997 	ACPI_FUNCTION_TRACE(ex_dump_object_descriptor);
998 
999 	if (!obj_desc) {
1000 		return_VOID;
1001 	}
1002 
1003 	if (!flags) {
1004 
1005 		/* Check if debug output enabled */
1006 
1007 		if (!ACPI_IS_DEBUG_ENABLED(ACPI_LV_OBJECTS, _COMPONENT)) {
1008 			return_VOID;
1009 		}
1010 	}
1011 
1012 	if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) == ACPI_DESC_TYPE_NAMED) {
1013 		acpi_ex_dump_namespace_node((struct acpi_namespace_node *)
1014 					    obj_desc, flags);
1015 
1016 		acpi_os_printf("\nAttached Object (%p):\n",
1017 			       ((struct acpi_namespace_node *)obj_desc)->
1018 			       object);
1019 
1020 		acpi_ex_dump_object_descriptor(((struct acpi_namespace_node *)
1021 						obj_desc)->object, flags);
1022 		return_VOID;
1023 	}
1024 
1025 	if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
1026 		acpi_os_printf
1027 		    ("ExDumpObjectDescriptor: %p is not an ACPI operand object: [%s]\n",
1028 		     obj_desc, acpi_ut_get_descriptor_name(obj_desc));
1029 		return_VOID;
1030 	}
1031 
1032 	if (obj_desc->common.type > ACPI_TYPE_NS_NODE_MAX) {
1033 		return_VOID;
1034 	}
1035 
1036 	/* Common Fields */
1037 
1038 	acpi_ex_dump_object(obj_desc, acpi_ex_dump_common);
1039 
1040 	/* Object-specific fields */
1041 
1042 	acpi_ex_dump_object(obj_desc, acpi_ex_dump_info[obj_desc->common.type]);
1043 	return_VOID;
1044 }
1045 
1046 #endif
1047