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