initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / namespace / nsdump.c
blob8afa1dcf7f989e0aff2fe810150ab42e9122b06e
1 /******************************************************************************
3 * Module Name: nsdump - table dumping routines for debug
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acparser.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsdump")
54 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
56 /*******************************************************************************
58 * FUNCTION: acpi_ns_print_pathname
60 * PARAMETERS: num_segment - Number of ACPI name segments
61 * Pathname - The compressed (internal) path
63 * DESCRIPTION: Print an object's full namespace pathname
65 ******************************************************************************/
67 void
68 acpi_ns_print_pathname (
69 u32 num_segments,
70 char *pathname)
72 ACPI_FUNCTION_NAME ("ns_print_pathname");
75 if (!(acpi_dbg_level & ACPI_LV_NAMES) || !(acpi_dbg_layer & ACPI_NAMESPACE)) {
76 return;
79 /* Print the entire name */
81 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
83 while (num_segments) {
84 acpi_os_printf ("%4.4s", pathname);
85 pathname += ACPI_NAME_SIZE;
87 num_segments--;
88 if (num_segments) {
89 acpi_os_printf (".");
93 acpi_os_printf ("]\n");
97 /*******************************************************************************
99 * FUNCTION: acpi_ns_dump_pathname
101 * PARAMETERS: Handle - Object
102 * Msg - Prefix message
103 * Level - Desired debug level
104 * Component - Caller's component ID
106 * DESCRIPTION: Print an object's full namespace pathname
107 * Manages allocation/freeing of a pathname buffer
109 ******************************************************************************/
111 void
112 acpi_ns_dump_pathname (
113 acpi_handle handle,
114 char *msg,
115 u32 level,
116 u32 component)
119 ACPI_FUNCTION_TRACE ("ns_dump_pathname");
122 /* Do this only if the requested debug level and component are enabled */
124 if (!(acpi_dbg_level & level) || !(acpi_dbg_layer & component)) {
125 return_VOID;
128 /* Convert handle to a full pathname and print it (with supplied message) */
130 acpi_ns_print_node_pathname (handle, msg);
131 acpi_os_printf ("\n");
132 return_VOID;
136 /*******************************************************************************
138 * FUNCTION: acpi_ns_dump_one_object
140 * PARAMETERS: Handle - Node to be dumped
141 * Level - Nesting level of the handle
142 * Context - Passed into walk_namespace
144 * DESCRIPTION: Dump a single Node
145 * This procedure is a user_function called by acpi_ns_walk_namespace.
147 ******************************************************************************/
149 acpi_status
150 acpi_ns_dump_one_object (
151 acpi_handle obj_handle,
152 u32 level,
153 void *context,
154 void **return_value)
156 struct acpi_walk_info *info = (struct acpi_walk_info *) context;
157 struct acpi_namespace_node *this_node;
158 union acpi_operand_object *obj_desc = NULL;
159 acpi_object_type obj_type;
160 acpi_object_type type;
161 u32 bytes_to_dump;
162 u32 dbg_level;
163 u32 i;
166 ACPI_FUNCTION_NAME ("ns_dump_one_object");
169 /* Is output enabled? */
171 if (!(acpi_dbg_level & info->debug_level)) {
172 return (AE_OK);
175 if (!obj_handle) {
176 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
177 return (AE_OK);
180 this_node = acpi_ns_map_handle_to_node (obj_handle);
181 type = this_node->type;
183 /* Check if the owner matches */
185 if ((info->owner_id != ACPI_UINT32_MAX) &&
186 (info->owner_id != this_node->owner_id)) {
187 return (AE_OK);
190 /* Indent the object according to the level */
192 acpi_os_printf ("%2d%*s", (u32) level - 1, (int) level * 2, " ");
194 /* Check the node type and name */
196 if (type > ACPI_TYPE_LOCAL_MAX) {
197 ACPI_REPORT_WARNING (("Invalid ACPI Type %08X\n", type));
200 if (!acpi_ut_valid_acpi_name (this_node->name.integer)) {
201 ACPI_REPORT_WARNING (("Invalid ACPI Name %08X\n", this_node->name.integer));
205 * Now we can print out the pertinent information
207 acpi_os_printf ("%4.4s %-12s %p ",
208 acpi_ut_get_node_name (this_node), acpi_ut_get_type_name (type), this_node);
210 dbg_level = acpi_dbg_level;
211 acpi_dbg_level = 0;
212 obj_desc = acpi_ns_get_attached_object (this_node);
213 acpi_dbg_level = dbg_level;
215 switch (info->display_type) {
216 case ACPI_DISPLAY_SUMMARY:
218 if (!obj_desc) {
219 /* No attached object, we are done */
221 acpi_os_printf ("\n");
222 return (AE_OK);
225 switch (type) {
226 case ACPI_TYPE_PROCESSOR:
228 acpi_os_printf ("ID %X Len %.4X Addr %p\n",
229 obj_desc->processor.proc_id,
230 obj_desc->processor.length,
231 (char *) obj_desc->processor.address);
232 break;
235 case ACPI_TYPE_DEVICE:
237 acpi_os_printf ("Notify Object: %p\n", obj_desc);
238 break;
241 case ACPI_TYPE_METHOD:
243 acpi_os_printf ("Args %X Len %.4X Aml %p\n",
244 (u32) obj_desc->method.param_count,
245 obj_desc->method.aml_length,
246 obj_desc->method.aml_start);
247 break;
250 case ACPI_TYPE_INTEGER:
252 acpi_os_printf ("= %8.8X%8.8X\n",
253 ACPI_FORMAT_UINT64 (obj_desc->integer.value));
254 break;
257 case ACPI_TYPE_PACKAGE:
259 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
260 acpi_os_printf ("Elements %.2X\n",
261 obj_desc->package.count);
263 else {
264 acpi_os_printf ("[Length not yet evaluated]\n");
266 break;
269 case ACPI_TYPE_BUFFER:
271 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
272 acpi_os_printf ("Len %.2X",
273 obj_desc->buffer.length);
275 /* Dump some of the buffer */
277 if (obj_desc->buffer.length > 0) {
278 acpi_os_printf (" =");
279 for (i = 0; (i < obj_desc->buffer.length && i < 12); i++) {
280 acpi_os_printf (" %.2hX", obj_desc->buffer.pointer[i]);
283 acpi_os_printf ("\n");
285 else {
286 acpi_os_printf ("[Length not yet evaluated]\n");
288 break;
291 case ACPI_TYPE_STRING:
293 acpi_os_printf ("Len %.2X ", obj_desc->string.length);
294 acpi_ut_print_string (obj_desc->string.pointer, 32);
295 acpi_os_printf ("\n");
296 break;
299 case ACPI_TYPE_REGION:
301 acpi_os_printf ("[%s]", acpi_ut_get_region_name (obj_desc->region.space_id));
302 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
303 acpi_os_printf (" Addr %8.8X%8.8X Len %.4X\n",
304 ACPI_FORMAT_UINT64 (obj_desc->region.address),
305 obj_desc->region.length);
307 else {
308 acpi_os_printf (" [Address/Length not yet evaluated]\n");
310 break;
313 case ACPI_TYPE_LOCAL_REFERENCE:
315 acpi_os_printf ("[%s]\n",
316 acpi_ps_get_opcode_name (obj_desc->reference.opcode));
317 break;
320 case ACPI_TYPE_BUFFER_FIELD:
322 if (obj_desc->buffer_field.buffer_obj &&
323 obj_desc->buffer_field.buffer_obj->buffer.node) {
324 acpi_os_printf ("Buf [%4.4s]",
325 acpi_ut_get_node_name (obj_desc->buffer_field.buffer_obj->buffer.node));
327 break;
330 case ACPI_TYPE_LOCAL_REGION_FIELD:
332 acpi_os_printf ("Rgn [%4.4s]",
333 acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node));
334 break;
337 case ACPI_TYPE_LOCAL_BANK_FIELD:
339 acpi_os_printf ("Rgn [%4.4s] Bnk [%4.4s]",
340 acpi_ut_get_node_name (obj_desc->common_field.region_obj->region.node),
341 acpi_ut_get_node_name (obj_desc->bank_field.bank_obj->common_field.node));
342 break;
345 case ACPI_TYPE_LOCAL_INDEX_FIELD:
347 acpi_os_printf ("Idx [%4.4s] Dat [%4.4s]",
348 acpi_ut_get_node_name (obj_desc->index_field.index_obj->common_field.node),
349 acpi_ut_get_node_name (obj_desc->index_field.data_obj->common_field.node));
350 break;
353 case ACPI_TYPE_LOCAL_ALIAS:
354 case ACPI_TYPE_LOCAL_METHOD_ALIAS:
356 acpi_os_printf ("Target %4.4s (%p)\n", acpi_ut_get_node_name (obj_desc), obj_desc);
357 break;
359 default:
361 acpi_os_printf ("Object %p\n", obj_desc);
362 break;
365 /* Common field handling */
367 switch (type) {
368 case ACPI_TYPE_BUFFER_FIELD:
369 case ACPI_TYPE_LOCAL_REGION_FIELD:
370 case ACPI_TYPE_LOCAL_BANK_FIELD:
371 case ACPI_TYPE_LOCAL_INDEX_FIELD:
373 acpi_os_printf (" Off %.3X Len %.2X Acc %.2hd\n",
374 (obj_desc->common_field.base_byte_offset * 8)
375 + obj_desc->common_field.start_field_bit_offset,
376 obj_desc->common_field.bit_length,
377 obj_desc->common_field.access_byte_width);
378 break;
380 default:
381 break;
383 break;
386 case ACPI_DISPLAY_OBJECTS:
388 acpi_os_printf ("O:%p", obj_desc);
389 if (!obj_desc) {
390 /* No attached object, we are done */
392 acpi_os_printf ("\n");
393 return (AE_OK);
396 acpi_os_printf ("(R%d)",
397 obj_desc->common.reference_count);
399 switch (type) {
400 case ACPI_TYPE_METHOD:
402 /* Name is a Method and its AML offset/length are set */
404 acpi_os_printf (" M:%p-%X\n", obj_desc->method.aml_start,
405 obj_desc->method.aml_length);
406 break;
408 case ACPI_TYPE_INTEGER:
410 acpi_os_printf (" I:%8.8X8.8%X\n",
411 ACPI_FORMAT_UINT64 (obj_desc->integer.value));
412 break;
414 case ACPI_TYPE_STRING:
416 acpi_os_printf (" S:%p-%X\n", obj_desc->string.pointer,
417 obj_desc->string.length);
418 break;
420 case ACPI_TYPE_BUFFER:
422 acpi_os_printf (" B:%p-%X\n", obj_desc->buffer.pointer,
423 obj_desc->buffer.length);
424 break;
426 default:
428 acpi_os_printf ("\n");
429 break;
431 break;
434 default:
435 acpi_os_printf ("\n");
436 break;
439 /* If debug turned off, done */
441 if (!(acpi_dbg_level & ACPI_LV_VALUES)) {
442 return (AE_OK);
446 /* If there is an attached object, display it */
448 dbg_level = acpi_dbg_level;
449 acpi_dbg_level = 0;
450 obj_desc = acpi_ns_get_attached_object (this_node);
451 acpi_dbg_level = dbg_level;
453 /* Dump attached objects */
455 while (obj_desc) {
456 obj_type = ACPI_TYPE_INVALID;
457 acpi_os_printf (" Attached Object %p: ", obj_desc);
459 /* Decode the type of attached object and dump the contents */
461 switch (ACPI_GET_DESCRIPTOR_TYPE (obj_desc)) {
462 case ACPI_DESC_TYPE_NAMED:
464 acpi_os_printf ("(Ptr to Node)\n");
465 bytes_to_dump = sizeof (struct acpi_namespace_node);
466 break;
469 case ACPI_DESC_TYPE_OPERAND:
471 obj_type = ACPI_GET_OBJECT_TYPE (obj_desc);
473 if (obj_type > ACPI_TYPE_LOCAL_MAX) {
474 acpi_os_printf ("(Ptr to ACPI Object type %X [UNKNOWN])\n", obj_type);
475 bytes_to_dump = 32;
477 else {
478 acpi_os_printf ("(Ptr to ACPI Object type %s, %X)\n",
479 acpi_ut_get_type_name (obj_type), obj_type);
480 bytes_to_dump = sizeof (union acpi_operand_object);
482 break;
485 default:
487 acpi_os_printf ("(String or Buffer ptr - not an object descriptor) [%s]\n",
488 acpi_ut_get_descriptor_name (obj_desc));
489 bytes_to_dump = 16;
490 break;
493 ACPI_DUMP_BUFFER (obj_desc, bytes_to_dump);
495 /* If value is NOT an internal object, we are done */
497 if (ACPI_GET_DESCRIPTOR_TYPE (obj_desc) != ACPI_DESC_TYPE_OPERAND) {
498 goto cleanup;
502 * Valid object, get the pointer to next level, if any
504 switch (obj_type) {
505 case ACPI_TYPE_STRING:
506 obj_desc = (void *) obj_desc->string.pointer;
507 break;
509 case ACPI_TYPE_BUFFER:
510 obj_desc = (void *) obj_desc->buffer.pointer;
511 break;
513 case ACPI_TYPE_BUFFER_FIELD:
514 obj_desc = (union acpi_operand_object *) obj_desc->buffer_field.buffer_obj;
515 break;
517 case ACPI_TYPE_PACKAGE:
518 obj_desc = (void *) obj_desc->package.elements;
519 break;
521 case ACPI_TYPE_METHOD:
522 obj_desc = (void *) obj_desc->method.aml_start;
523 break;
525 case ACPI_TYPE_LOCAL_REGION_FIELD:
526 obj_desc = (void *) obj_desc->field.region_obj;
527 break;
529 case ACPI_TYPE_LOCAL_BANK_FIELD:
530 obj_desc = (void *) obj_desc->bank_field.region_obj;
531 break;
533 case ACPI_TYPE_LOCAL_INDEX_FIELD:
534 obj_desc = (void *) obj_desc->index_field.index_obj;
535 break;
537 default:
538 goto cleanup;
541 obj_type = ACPI_TYPE_INVALID; /* Terminate loop after next pass */
544 cleanup:
545 acpi_os_printf ("\n");
546 return (AE_OK);
550 /*******************************************************************************
552 * FUNCTION: acpi_ns_dump_objects
554 * PARAMETERS: Type - Object type to be dumped
555 * max_depth - Maximum depth of dump. Use ACPI_UINT32_MAX
556 * for an effectively unlimited depth.
557 * owner_id - Dump only objects owned by this ID. Use
558 * ACPI_UINT32_MAX to match all owners.
559 * start_handle - Where in namespace to start/end search
561 * DESCRIPTION: Dump typed objects within the loaded namespace.
562 * Uses acpi_ns_walk_namespace in conjunction with acpi_ns_dump_one_object.
564 ******************************************************************************/
566 void
567 acpi_ns_dump_objects (
568 acpi_object_type type,
569 u8 display_type,
570 u32 max_depth,
571 u32 owner_id,
572 acpi_handle start_handle)
574 struct acpi_walk_info info;
577 ACPI_FUNCTION_ENTRY ();
580 info.debug_level = ACPI_LV_TABLES;
581 info.owner_id = owner_id;
582 info.display_type = display_type;
584 (void) acpi_ns_walk_namespace (type, start_handle, max_depth,
585 ACPI_NS_WALK_NO_UNLOCK, acpi_ns_dump_one_object,
586 (void *) &info, NULL);
590 /*******************************************************************************
592 * FUNCTION: acpi_ns_dump_tables
594 * PARAMETERS: search_base - Root of subtree to be dumped, or
595 * NS_ALL to dump the entire namespace
596 * max_depth - Maximum depth of dump. Use INT_MAX
597 * for an effectively unlimited depth.
599 * DESCRIPTION: Dump the name space, or a portion of it.
601 ******************************************************************************/
603 void
604 acpi_ns_dump_tables (
605 acpi_handle search_base,
606 u32 max_depth)
608 acpi_handle search_handle = search_base;
611 ACPI_FUNCTION_TRACE ("ns_dump_tables");
614 if (!acpi_gbl_root_node) {
616 * If the name space has not been initialized,
617 * there is nothing to dump.
619 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "namespace not initialized!\n"));
620 return_VOID;
623 if (ACPI_NS_ALL == search_base) {
624 /* entire namespace */
626 search_handle = acpi_gbl_root_node;
627 ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
630 acpi_ns_dump_objects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, max_depth,
631 ACPI_UINT32_MAX, search_handle);
632 return_VOID;
636 /*******************************************************************************
638 * FUNCTION: acpi_ns_dump_entry
640 * PARAMETERS: Handle - Node to be dumped
641 * debug_level - Output level
643 * DESCRIPTION: Dump a single Node
645 ******************************************************************************/
647 void
648 acpi_ns_dump_entry (
649 acpi_handle handle,
650 u32 debug_level)
652 struct acpi_walk_info info;
655 ACPI_FUNCTION_ENTRY ();
658 info.debug_level = debug_level;
659 info.owner_id = ACPI_UINT32_MAX;
660 info.display_type = ACPI_DISPLAY_SUMMARY;
662 (void) acpi_ns_dump_one_object (handle, 1, &info, NULL);
665 #endif