[ACPI] ACPICA 20050729 from Bob Moore
[deliverable/linux.git] / drivers / acpi / namespace / nsdump.c
1 /******************************************************************************
2 *
3 * Module Name: nsdump - table dumping routines for debug
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acparser.h>
48
49
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsdump")
52
53 /* Local prototypes */
54
55 #ifdef ACPI_OBSOLETE_FUNCTIONS
56 void
57 acpi_ns_dump_root_devices (
58 void);
59
60 static acpi_status
61 acpi_ns_dump_one_device (
62 acpi_handle obj_handle,
63 u32 level,
64 void *context,
65 void **return_value);
66 #endif
67
68
69 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
70 /*******************************************************************************
71 *
72 * FUNCTION: acpi_ns_print_pathname
73 *
74 * PARAMETERS: num_segments - Number of ACPI name segments
75 * Pathname - The compressed (internal) path
76 *
77 * RETURN: None
78 *
79 * DESCRIPTION: Print an object's full namespace pathname
80 *
81 ******************************************************************************/
82
83 void
84 acpi_ns_print_pathname (
85 u32 num_segments,
86 char *pathname)
87 {
88 acpi_native_uint i;
89
90
91 ACPI_FUNCTION_NAME ("ns_print_pathname");
92
93
94 if (!(acpi_dbg_level & ACPI_LV_NAMES) || !(acpi_dbg_layer & ACPI_NAMESPACE)) {
95 return;
96 }
97
98 /* Print the entire name */
99
100 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
101
102 while (num_segments) {
103 for (i = 0; i < 4; i++) {
104 ACPI_IS_PRINT (pathname[i]) ?
105 acpi_os_printf ("%c", pathname[i]) :
106 acpi_os_printf ("?");
107 }
108
109 pathname += ACPI_NAME_SIZE;
110 num_segments--;
111 if (num_segments) {
112 acpi_os_printf (".");
113 }
114 }
115
116 acpi_os_printf ("]\n");
117 }
118
119
120 /*******************************************************************************
121 *
122 * FUNCTION: acpi_ns_dump_pathname
123 *
124 * PARAMETERS: Handle - Object
125 * Msg - Prefix message
126 * Level - Desired debug level
127 * Component - Caller's component ID
128 *
129 * RETURN: None
130 *
131 * DESCRIPTION: Print an object's full namespace pathname
132 * Manages allocation/freeing of a pathname buffer
133 *
134 ******************************************************************************/
135
136 void
137 acpi_ns_dump_pathname (
138 acpi_handle handle,
139 char *msg,
140 u32 level,
141 u32 component)
142 {
143
144 ACPI_FUNCTION_TRACE ("ns_dump_pathname");
145
146
147 /* Do this only if the requested debug level and component are enabled */
148
149 if (!(acpi_dbg_level & level) || !(acpi_dbg_layer & component)) {
150 return_VOID;
151 }
152
153 /* Convert handle to a full pathname and print it (with supplied message) */
154
155 acpi_ns_print_node_pathname (handle, msg);
156 acpi_os_printf ("\n");
157 return_VOID;
158 }
159
160
161 /*******************************************************************************
162 *
163 * FUNCTION: acpi_ns_dump_one_object
164 *
165 * PARAMETERS: obj_handle - Node to be dumped
166 * Level - Nesting level of the handle
167 * Context - Passed into walk_namespace
168 * return_value - Not used
169 *
170 * RETURN: Status
171 *
172 * DESCRIPTION: Dump a single Node
173 * This procedure is a user_function called by acpi_ns_walk_namespace.
174 *
175 ******************************************************************************/
176
177 acpi_status
178 acpi_ns_dump_one_object (
179 acpi_handle obj_handle,
180 u32 level,
181 void *context,
182 void **return_value)
183 {
184 struct acpi_walk_info *info = (struct acpi_walk_info *) context;
185 struct acpi_namespace_node *this_node;
186 union acpi_operand_object *obj_desc = NULL;
187 acpi_object_type obj_type;
188 acpi_object_type type;
189 u32 bytes_to_dump;
190 u32 dbg_level;
191 u32 i;
192
193
194 ACPI_FUNCTION_NAME ("ns_dump_one_object");
195
196
197 /* Is output enabled? */
198
199 if (!(acpi_dbg_level & info->debug_level)) {
200 return (AE_OK);
201 }
202
203 if (!obj_handle) {
204 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
205 return (AE_OK);
206 }
207
208 this_node = acpi_ns_map_handle_to_node (obj_handle);
209 type = this_node->type;
210
211 /* Check if the owner matches */
212
213 if ((info->owner_id != ACPI_OWNER_ID_MAX) &&
214 (info->owner_id != this_node->owner_id)) {
215 return (AE_OK);
216 }
217
218 if (!(info->display_type & ACPI_DISPLAY_SHORT)) {
219 /* Indent the object according to the level */
220
221 acpi_os_printf ("%2d%*s", (u32) level - 1, (int) level * 2, " ");
222
223 /* Check the node type and name */
224
225 if (type > ACPI_TYPE_LOCAL_MAX) {
226 ACPI_REPORT_WARNING (("Invalid ACPI Type %08X\n", type));
227 }
228
229 if (!acpi_ut_valid_acpi_name (this_node->name.integer)) {
230 ACPI_REPORT_WARNING (("Invalid ACPI Name %08X\n",
231 this_node->name.integer));
232 }
233
234 acpi_os_printf ("%4.4s", acpi_ut_get_node_name (this_node));
235 }
236
237 /*
238 * Now we can print out the pertinent information
239 */
240 acpi_os_printf (" %-12s %p ",
241 acpi_ut_get_type_name (type), this_node);
242
243 dbg_level = acpi_dbg_level;
244 acpi_dbg_level = 0;
245 obj_desc = acpi_ns_get_attached_object (this_node);
246 acpi_dbg_level = dbg_level;
247
248 switch (info->display_type & ACPI_DISPLAY_MASK) {
249 case ACPI_DISPLAY_SUMMARY:
250
251 if (!obj_desc) {
252 /* No attached object, we are done */
253
254 acpi_os_printf ("\n");
255 return (AE_OK);
256 }
257
258 switch (type) {
259 case ACPI_TYPE_PROCESSOR:
260
261 acpi_os_printf ("ID %X Len %.4X Addr %p\n",
262 obj_desc->processor.proc_id, obj_desc->processor.length,
263 (char *) obj_desc->processor.address);
264 break;
265
266
267 case ACPI_TYPE_DEVICE:
268
269 acpi_os_printf ("Notify Object: %p\n", obj_desc);
270 break;
271
272
273 case ACPI_TYPE_METHOD:
274
275 acpi_os_printf ("Args %X Len %.4X Aml %p\n",
276 (u32) obj_desc->method.param_count,
277 obj_desc->method.aml_length, obj_desc->method.aml_start);
278 break;
279
280
281 case ACPI_TYPE_INTEGER:
282
283 acpi_os_printf ("= %8.8X%8.8X\n",
284 ACPI_FORMAT_UINT64 (obj_desc->integer.value));
285 break;
286
287
288 case ACPI_TYPE_PACKAGE:
289
290 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
291 acpi_os_printf ("Elements %.2X\n",
292 obj_desc->package.count);
293 }
294 else {
295 acpi_os_printf ("[Length not yet evaluated]\n");
296 }
297 break;
298
299
300 case ACPI_TYPE_BUFFER:
301
302 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
303 acpi_os_printf ("Len %.2X",
304 obj_desc->buffer.length);
305
306 /* Dump some of the buffer */
307
308 if (obj_desc->buffer.length > 0) {
309 acpi_os_printf (" =");
310 for (i = 0; (i < obj_desc->buffer.length && i < 12); i++) {
311 acpi_os_printf (" %.2hX", obj_desc->buffer.pointer[i]);
312 }
313 }
314 acpi_os_printf ("\n");
315 }
316 else {
317 acpi_os_printf ("[Length not yet evaluated]\n");
318 }
319 break;
320
321
322 case ACPI_TYPE_STRING:
323
324 acpi_os_printf ("Len %.2X ", obj_desc->string.length);
325 acpi_ut_print_string (obj_desc->string.pointer, 32);
326 acpi_os_printf ("\n");
327 break;
328
329
330 case ACPI_TYPE_REGION:
331
332 acpi_os_printf ("[%s]",
333 acpi_ut_get_region_name (obj_desc->region.space_id));
334 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
335 acpi_os_printf (" Addr %8.8X%8.8X Len %.4X\n",
336 ACPI_FORMAT_UINT64 (obj_desc->region.address),
337 obj_desc->region.length);
338 }
339 else {
340 acpi_os_printf (" [Address/Length not yet evaluated]\n");
341 }
342 break;
343
344
345 case ACPI_TYPE_LOCAL_REFERENCE:
346
347 acpi_os_printf ("[%s]\n",
348 acpi_ps_get_opcode_name (obj_desc->reference.opcode));
349 break;
350
351
352 case ACPI_TYPE_BUFFER_FIELD:
353
354 if (obj_desc->buffer_field.buffer_obj &&
355 obj_desc->buffer_field.buffer_obj->buffer.node) {
356 acpi_os_printf ("Buf [%4.4s]",
357 acpi_ut_get_node_name (obj_desc->buffer_field.buffer_obj->buffer.node));
358 }
359 break;
360
361
362 case ACPI_TYPE_LOCAL_REGION_FIELD:
363
364 acpi_os_printf ("Rgn [%4.4s]",
365 acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node));
366 break;
367
368
369 case ACPI_TYPE_LOCAL_BANK_FIELD:
370
371 acpi_os_printf ("Rgn [%4.4s] Bnk [%4.4s]",
372 acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node),
373 acpi_ut_get_node_name (obj_desc->bank_field.bank_obj->common_field.node));
374 break;
375
376
377 case ACPI_TYPE_LOCAL_INDEX_FIELD:
378
379 acpi_os_printf ("Idx [%4.4s] Dat [%4.4s]",
380 acpi_ut_get_node_name (obj_desc->index_field.index_obj->common_field.node),
381 acpi_ut_get_node_name (obj_desc->index_field.data_obj->common_field.node));
382 break;
383
384
385 case ACPI_TYPE_LOCAL_ALIAS:
386 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
387
388 acpi_os_printf ("Target %4.4s (%p)\n",
389 acpi_ut_get_node_name (obj_desc), obj_desc);
390 break;
391
392 default:
393
394 acpi_os_printf ("Object %p\n", obj_desc);
395 break;
396 }
397
398 /* Common field handling */
399
400 switch (type) {
401 case ACPI_TYPE_BUFFER_FIELD:
402 case ACPI_TYPE_LOCAL_REGION_FIELD:
403 case ACPI_TYPE_LOCAL_BANK_FIELD:
404 case ACPI_TYPE_LOCAL_INDEX_FIELD:
405
406 acpi_os_printf (" Off %.3X Len %.2X Acc %.2hd\n",
407 (obj_desc->common_field.base_byte_offset * 8)
408 + obj_desc->common_field.start_field_bit_offset,
409 obj_desc->common_field.bit_length,
410 obj_desc->common_field.access_byte_width);
411 break;
412
413 default:
414 break;
415 }
416 break;
417
418
419 case ACPI_DISPLAY_OBJECTS:
420
421 acpi_os_printf ("O:%p", obj_desc);
422 if (!obj_desc) {
423 /* No attached object, we are done */
424
425 acpi_os_printf ("\n");
426 return (AE_OK);
427 }
428
429 acpi_os_printf ("(R%d)", obj_desc->common.reference_count);
430
431 switch (type) {
432 case ACPI_TYPE_METHOD:
433
434 /* Name is a Method and its AML offset/length are set */
435
436 acpi_os_printf (" M:%p-%X\n", obj_desc->method.aml_start,
437 obj_desc->method.aml_length);
438 break;
439
440 case ACPI_TYPE_INTEGER:
441
442 acpi_os_printf (" I:%8.8X8.8%X\n",
443 ACPI_FORMAT_UINT64 (obj_desc->integer.value));
444 break;
445
446 case ACPI_TYPE_STRING:
447
448 acpi_os_printf (" S:%p-%X\n", obj_desc->string.pointer,
449 obj_desc->string.length);
450 break;
451
452 case ACPI_TYPE_BUFFER:
453
454 acpi_os_printf (" B:%p-%X\n", obj_desc->buffer.pointer,
455 obj_desc->buffer.length);
456 break;
457
458 default:
459
460 acpi_os_printf ("\n");
461 break;
462 }
463 break;
464
465
466 default:
467 acpi_os_printf ("\n");
468 break;
469 }
470
471 /* If debug turned off, done */
472
473 if (!(acpi_dbg_level & ACPI_LV_VALUES)) {
474 return (AE_OK);
475 }
476
477
478 /* If there is an attached object, display it */
479
480 dbg_level = acpi_dbg_level;
481 acpi_dbg_level = 0;
482 obj_desc = acpi_ns_get_attached_object (this_node);
483 acpi_dbg_level = dbg_level;
484
485 /* Dump attached objects */
486
487 while (obj_desc) {
488 obj_type = ACPI_TYPE_INVALID;
489 acpi_os_printf ("Attached Object %p: ", obj_desc);
490
491 /* Decode the type of attached object and dump the contents */
492
493 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
494 case ACPI_DESC_TYPE_NAMED:
495
496 acpi_os_printf ("(Ptr to Node)\n");
497 bytes_to_dump = sizeof (struct acpi_namespace_node);
498 ACPI_DUMP_BUFFER (obj_desc, bytes_to_dump);
499 break;
500
501 case ACPI_DESC_TYPE_OPERAND:
502
503 obj_type = ACPI_GET_OBJECT_TYPE (obj_desc);
504
505 if (obj_type > ACPI_TYPE_LOCAL_MAX) {
506 acpi_os_printf ("(Ptr to ACPI Object type %X [UNKNOWN])\n",
507 obj_type);
508 bytes_to_dump = 32;
509 }
510 else {
511 acpi_os_printf ("(Ptr to ACPI Object type %X [%s])\n",
512 obj_type, acpi_ut_get_type_name (obj_type));
513 bytes_to_dump = sizeof (union acpi_operand_object);
514 }
515
516 ACPI_DUMP_BUFFER (obj_desc, bytes_to_dump);
517 break;
518
519 default:
520
521 break;
522 }
523
524 /* If value is NOT an internal object, we are done */
525
526 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) != ACPI_DESC_TYPE_OPERAND) {
527 goto cleanup;
528 }
529
530 /*
531 * Valid object, get the pointer to next level, if any
532 */
533 switch (obj_type) {
534 case ACPI_TYPE_BUFFER:
535 case ACPI_TYPE_STRING:
536 /*
537 * NOTE: takes advantage of common fields between string/buffer
538 */
539 bytes_to_dump = obj_desc->string.length;
540 obj_desc = (void *) obj_desc->string.pointer;
541 acpi_os_printf ( "(Buffer/String pointer %p length %X)\n",
542 obj_desc, bytes_to_dump);
543 ACPI_DUMP_BUFFER (obj_desc, bytes_to_dump);
544 goto cleanup;
545
546 case ACPI_TYPE_BUFFER_FIELD:
547 obj_desc = (union acpi_operand_object *) obj_desc->buffer_field.buffer_obj;
548 break;
549
550 case ACPI_TYPE_PACKAGE:
551 obj_desc = (void *) obj_desc->package.elements;
552 break;
553
554 case ACPI_TYPE_METHOD:
555 obj_desc = (void *) obj_desc->method.aml_start;
556 break;
557
558 case ACPI_TYPE_LOCAL_REGION_FIELD:
559 obj_desc = (void *) obj_desc->field.region_obj;
560 break;
561
562 case ACPI_TYPE_LOCAL_BANK_FIELD:
563 obj_desc = (void *) obj_desc->bank_field.region_obj;
564 break;
565
566 case ACPI_TYPE_LOCAL_INDEX_FIELD:
567 obj_desc = (void *) obj_desc->index_field.index_obj;
568 break;
569
570 default:
571 goto cleanup;
572 }
573
574 obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
575 }
576
577 cleanup:
578 acpi_os_printf ("\n");
579 return (AE_OK);
580 }
581
582
583 #ifdef ACPI_FUTURE_USAGE
584 /*******************************************************************************
585 *
586 * FUNCTION: acpi_ns_dump_objects
587 *
588 * PARAMETERS: Type - Object type to be dumped
589 * display_type - 0 or ACPI_DISPLAY_SUMMARY
590 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
591 * for an effectively unlimited depth.
592 * owner_id - Dump only objects owned by this ID. Use
593 * ACPI_UINT32_MAX to match all owners.
594 * start_handle - Where in namespace to start/end search
595 *
596 * RETURN: None
597 *
598 * DESCRIPTION: Dump typed objects within the loaded namespace.
599 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
600 *
601 ******************************************************************************/
602
603 void
604 acpi_ns_dump_objects (
605 acpi_object_type type,
606 u8 display_type,
607 u32 max_depth,
608 acpi_owner_id owner_id,
609 acpi_handle start_handle)
610 {
611 struct acpi_walk_info info;
612
613
614 ACPI_FUNCTION_ENTRY ();
615
616
617 info.debug_level = ACPI_LV_TABLES;
618 info.owner_id = owner_id;
619 info.display_type = display_type;
620
621 (void) acpi_ns_walk_namespace (type, start_handle, max_depth,
622 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object,
623 (void *) &info, NULL);
624 }
625 #endif /* ACPI_FUTURE_USAGE */
626
627
628 /*******************************************************************************
629 *
630 * FUNCTION: acpi_ns_dump_entry
631 *
632 * PARAMETERS: Handle - Node to be dumped
633 * debug_level - Output level
634 *
635 * RETURN: None
636 *
637 * DESCRIPTION: Dump a single Node
638 *
639 ******************************************************************************/
640
641 void
642 acpi_ns_dump_entry (
643 acpi_handle handle,
644 u32 debug_level)
645 {
646 struct acpi_walk_info info;
647
648
649 ACPI_FUNCTION_ENTRY ();
650
651
652 info.debug_level = debug_level;
653 info.owner_id = ACPI_OWNER_ID_MAX;
654 info.display_type = ACPI_DISPLAY_SUMMARY;
655
656 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
657 }
658
659
660 #ifdef ACPI_ASL_COMPILER
661 /*******************************************************************************
662 *
663 * FUNCTION: acpi_ns_dump_tables
664 *
665 * PARAMETERS: search_base - Root of subtree to be dumped, or
666 * NS_ALL to dump the entire namespace
667 * max_depth - Maximum depth of dump. Use INT_MAX
668 * for an effectively unlimited depth.
669 *
670 * RETURN: None
671 *
672 * DESCRIPTION: Dump the name space, or a portion of it.
673 *
674 ******************************************************************************/
675
676 void
677 acpi_ns_dump_tables (
678 acpi_handle search_base,
679 u32 max_depth)
680 {
681 acpi_handle search_handle = search_base;
682
683
684 ACPI_FUNCTION_TRACE ("ns_dump_tables");
685
686
687 if (!acpi_gbl_root_node) {
688 /*
689 * If the name space has not been initialized,
690 * there is nothing to dump.
691 */
692 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "namespace not initialized!\n"));
693 return_VOID;
694 }
695
696 if (ACPI_NS_ALL == search_base) {
697 /* Entire namespace */
698
699 search_handle = acpi_gbl_root_node;
700 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
701 }
702
703 acpi_ns_dump_objects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, max_depth,
704 ACPI_OWNER_ID_MAX, search_handle);
705 return_VOID;
706 }
707 #endif /* _ACPI_ASL_COMPILER */
708 #endif /* defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) */
This page took 0.045593 seconds and 5 git commands to generate.