- Create another branch for networking fixes
[reactos.git] / drivers / bus / acpi / utils / cmdebug.c
1 /******************************************************************************
2 *
3 * Module Name: cmdebug - Debug print routines
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26
27 #include <acpi.h>
28
29 #define _COMPONENT ACPI_UTILITIES
30 MODULE_NAME ("cmdebug")
31
32
33 /*****************************************************************************
34 *
35 * FUNCTION: Get/Set debug level
36 *
37 * DESCRIPTION: Get or set value of the debug flag
38 *
39 * These are used to allow user's to get/set the debug level
40 *
41 ****************************************************************************/
42
43
44 u32
45 get_debug_level (void)
46 {
47
48 return (acpi_dbg_level);
49 }
50
51 void
52 set_debug_level (
53 u32 new_debug_level)
54 {
55
56 acpi_dbg_level = new_debug_level;
57 }
58
59
60 /*****************************************************************************
61 *
62 * FUNCTION: Function_trace
63 *
64 * PARAMETERS: Module_name - Caller's module name (for error output)
65 * Line_number - Caller's line number (for error output)
66 * Component_id - Caller's component ID (for error output)
67 * Function_name - Name of Caller's function
68 *
69 * RETURN: None
70 *
71 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
72 * set in Debug_level
73 *
74 ****************************************************************************/
75
76 void
77 function_trace (
78 NATIVE_CHAR *module_name,
79 u32 line_number,
80 u32 component_id,
81 NATIVE_CHAR *function_name)
82 {
83
84 acpi_gbl_nesting_level++;
85
86 debug_print (module_name, line_number, component_id,
87 TRACE_FUNCTIONS,
88 " %2.2ld Entered Function: %s\n",
89 acpi_gbl_nesting_level, function_name);
90 }
91
92
93 /*****************************************************************************
94 *
95 * FUNCTION: Function_trace_ptr
96 *
97 * PARAMETERS: Module_name - Caller's module name (for error output)
98 * Line_number - Caller's line number (for error output)
99 * Component_id - Caller's component ID (for error output)
100 * Function_name - Name of Caller's function
101 * Pointer - Pointer to display
102 *
103 * RETURN: None
104 *
105 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
106 * set in Debug_level
107 *
108 ****************************************************************************/
109
110 void
111 function_trace_ptr (
112 NATIVE_CHAR *module_name,
113 u32 line_number,
114 u32 component_id,
115 NATIVE_CHAR *function_name,
116 void *pointer)
117 {
118
119 acpi_gbl_nesting_level++;
120 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
121 " %2.2ld Entered Function: %s, %p\n",
122 acpi_gbl_nesting_level, function_name, pointer);
123 }
124
125
126 /*****************************************************************************
127 *
128 * FUNCTION: Function_trace_str
129 *
130 * PARAMETERS: Module_name - Caller's module name (for error output)
131 * Line_number - Caller's line number (for error output)
132 * Component_id - Caller's component ID (for error output)
133 * Function_name - Name of Caller's function
134 * String - Additional string to display
135 *
136 * RETURN: None
137 *
138 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
139 * set in Debug_level
140 *
141 ****************************************************************************/
142
143 void
144 function_trace_str (
145 NATIVE_CHAR *module_name,
146 u32 line_number,
147 u32 component_id,
148 NATIVE_CHAR *function_name,
149 NATIVE_CHAR *string)
150 {
151
152 acpi_gbl_nesting_level++;
153 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
154 " %2.2ld Entered Function: %s, %s\n",
155 acpi_gbl_nesting_level, function_name, string);
156 }
157
158
159 /*****************************************************************************
160 *
161 * FUNCTION: Function_trace_u32
162 *
163 * PARAMETERS: Module_name - Caller's module name (for error output)
164 * Line_number - Caller's line number (for error output)
165 * Component_id - Caller's component ID (for error output)
166 * Function_name - Name of Caller's function
167 * Integer - Integer to display
168 *
169 * RETURN: None
170 *
171 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
172 * set in Debug_level
173 *
174 ****************************************************************************/
175
176 void
177 function_trace_u32 (
178 NATIVE_CHAR *module_name,
179 u32 line_number,
180 u32 component_id,
181 NATIVE_CHAR *function_name,
182 u32 integer)
183 {
184
185 acpi_gbl_nesting_level++;
186 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
187 " %2.2ld Entered Function: %s, %lX\n",
188 acpi_gbl_nesting_level, function_name, integer);
189 }
190
191
192 /*****************************************************************************
193 *
194 * FUNCTION: Function_exit
195 *
196 * PARAMETERS: Module_name - Caller's module name (for error output)
197 * Line_number - Caller's line number (for error output)
198 * Component_id - Caller's component ID (for error output)
199 * Function_name - Name of Caller's function
200 *
201 * RETURN: None
202 *
203 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
204 * set in Debug_level
205 *
206 ****************************************************************************/
207
208 void
209 function_exit (
210 NATIVE_CHAR *module_name,
211 u32 line_number,
212 u32 component_id,
213 NATIVE_CHAR *function_name)
214 {
215
216 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
217 " %2.2ld Exiting Function: %s\n",
218 acpi_gbl_nesting_level, function_name);
219
220 acpi_gbl_nesting_level--;
221 }
222
223
224 /*****************************************************************************
225 *
226 * FUNCTION: Function_status_exit
227 *
228 * PARAMETERS: Module_name - Caller's module name (for error output)
229 * Line_number - Caller's line number (for error output)
230 * Component_id - Caller's component ID (for error output)
231 * Function_name - Name of Caller's function
232 * Status - Exit status code
233 *
234 * RETURN: None
235 *
236 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
237 * set in Debug_level. Prints exit status also.
238 *
239 ****************************************************************************/
240
241 void
242 function_status_exit (
243 NATIVE_CHAR *module_name,
244 u32 line_number,
245 u32 component_id,
246 NATIVE_CHAR *function_name,
247 ACPI_STATUS status)
248 {
249
250 debug_print (module_name, line_number, component_id,
251 TRACE_FUNCTIONS,
252 " %2.2ld Exiting Function: %s, %s\n",
253 acpi_gbl_nesting_level,
254 function_name,
255 acpi_cm_format_exception (status));
256
257 acpi_gbl_nesting_level--;
258 }
259
260
261 /*****************************************************************************
262 *
263 * FUNCTION: Function_value_exit
264 *
265 * PARAMETERS: Module_name - Caller's module name (for error output)
266 * Line_number - Caller's line number (for error output)
267 * Component_id - Caller's component ID (for error output)
268 * Function_name - Name of Caller's function
269 * Value - Value to be printed with exit msg
270 *
271 * RETURN: None
272 *
273 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
274 * set in Debug_level. Prints exit value also.
275 *
276 ****************************************************************************/
277
278 void
279 function_value_exit (
280 NATIVE_CHAR *module_name,
281 u32 line_number,
282 u32 component_id,
283 NATIVE_CHAR *function_name,
284 ACPI_INTEGER value)
285 {
286
287 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
288 " %2.2ld Exiting Function: %s, %X\n",
289 acpi_gbl_nesting_level, function_name, value);
290
291 acpi_gbl_nesting_level--;
292 }
293
294
295 /*****************************************************************************
296 *
297 * FUNCTION: Function_ptr_exit
298 *
299 * PARAMETERS: Module_name - Caller's module name (for error output)
300 * Line_number - Caller's line number (for error output)
301 * Component_id - Caller's component ID (for error output)
302 * Function_name - Name of Caller's function
303 * Value - Value to be printed with exit msg
304 *
305 * RETURN: None
306 *
307 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
308 * set in Debug_level. Prints exit value also.
309 *
310 ****************************************************************************/
311
312 void
313 function_ptr_exit (
314 NATIVE_CHAR *module_name,
315 u32 line_number,
316 u32 component_id,
317 NATIVE_CHAR *function_name,
318 u8 *ptr)
319 {
320
321 debug_print (module_name, line_number, component_id, TRACE_FUNCTIONS,
322 " %2.2ld Exiting Function: %s, %p\n",
323 acpi_gbl_nesting_level, function_name, ptr);
324
325 acpi_gbl_nesting_level--;
326 }
327
328
329 /*****************************************************************************
330 *
331 * FUNCTION: Debug_print
332 *
333 * PARAMETERS: Module_name - Caller's module name (for error output)
334 * Line_number - Caller's line number (for error output)
335 * Component_id - Caller's component ID (for error output)
336 * Print_level - Requested debug print level
337 * Format - Printf format field
338 * ... - Optional printf arguments
339 *
340 * RETURN: None
341 *
342 * DESCRIPTION: Print error message with prefix consisting of the module name,
343 * line number, and component ID.
344 *
345 ****************************************************************************/
346
347 void
348 debug_print (
349 NATIVE_CHAR *module_name,
350 u32 line_number,
351 u32 component_id,
352 u32 print_level,
353 NATIVE_CHAR *format,
354 ...)
355 {
356 va_list args;
357
358
359 /* Both the level and the component must be enabled */
360
361 if ((print_level & acpi_dbg_level) &&
362 (component_id & acpi_dbg_layer)) {
363 va_start (args, format);
364
365 acpi_os_printf ("%8s-%04d: ", module_name, line_number);
366 acpi_os_vprintf (format, args);
367 }
368 }
369
370
371 /*****************************************************************************
372 *
373 * FUNCTION: Debug_print_prefix
374 *
375 * PARAMETERS: Module_name - Caller's module name (for error output)
376 * Line_number - Caller's line number (for error output)
377 * Component_id - Caller's component ID (for error output)
378 *
379 * RETURN: None
380 *
381 * DESCRIPTION: Print the prefix part of an error message, consisting of the
382 * module name, and line number
383 *
384 ****************************************************************************/
385
386 void
387 debug_print_prefix (
388 NATIVE_CHAR *module_name,
389 u32 line_number)
390 {
391
392
393 acpi_os_printf ("%8s-%04d: ", module_name, line_number);
394 }
395
396
397 /*****************************************************************************
398 *
399 * FUNCTION: Debug_print_raw
400 *
401 * PARAMETERS: Format - Printf format field
402 * ... - Optional printf arguments
403 *
404 * RETURN: None
405 *
406 * DESCRIPTION: Print error message -- without module/line indentifiers
407 *
408 ****************************************************************************/
409
410 void
411 debug_print_raw (
412 NATIVE_CHAR *format,
413 ...)
414 {
415 va_list args;
416
417
418 va_start (args, format);
419
420 acpi_os_vprintf (format, args);
421
422 va_end (args);
423 }
424
425
426 /*****************************************************************************
427 *
428 * FUNCTION: Acpi_cm_dump_buffer
429 *
430 * PARAMETERS: Buffer - Buffer to dump
431 * Count - Amount to dump, in bytes
432 * Component_iD - Caller's component ID
433 *
434 * RETURN: None
435 *
436 * DESCRIPTION: Generic dump buffer in both hex and ascii.
437 *
438 ****************************************************************************/
439
440 void
441 acpi_cm_dump_buffer (
442 u8 *buffer,
443 u32 count,
444 u32 display,
445 u32 component_id)
446 {
447 u32 i = 0;
448 u32 j;
449 u32 temp32;
450 u8 buf_char;
451
452
453 /* Only dump the buffer if tracing is enabled */
454
455 if (!((TRACE_TABLES & acpi_dbg_level) &&
456 (component_id & acpi_dbg_layer))) {
457 return;
458 }
459
460
461 /*
462 * Nasty little dump buffer routine!
463 */
464 while (i < count) {
465 /* Print current offset */
466
467 acpi_os_printf ("%05X ", i);
468
469
470 /* Print 16 hex chars */
471
472 for (j = 0; j < 16;) {
473 if (i + j >= count) {
474 acpi_os_printf ("\n");
475 return;
476 }
477
478 /* Make sure that the s8 doesn't get sign-extended! */
479
480 switch (display) {
481 /* Default is BYTE display */
482
483 default:
484
485 acpi_os_printf ("%02X ",
486 *((u8 *) &buffer[i + j]));
487 j += 1;
488 break;
489
490
491 case DB_WORD_DISPLAY:
492
493 MOVE_UNALIGNED16_TO_32 (&temp32,
494 &buffer[i + j]);
495 acpi_os_printf ("%04X ", temp32);
496 j += 2;
497 break;
498
499
500 case DB_DWORD_DISPLAY:
501
502 MOVE_UNALIGNED32_TO_32 (&temp32,
503 &buffer[i + j]);
504 acpi_os_printf ("%08X ", temp32);
505 j += 4;
506 break;
507
508
509 case DB_QWORD_DISPLAY:
510
511 MOVE_UNALIGNED32_TO_32 (&temp32,
512 &buffer[i + j]);
513 acpi_os_printf ("%08X", temp32);
514
515 MOVE_UNALIGNED32_TO_32 (&temp32,
516 &buffer[i + j + 4]);
517 acpi_os_printf ("%08X ", temp32);
518 j += 8;
519 break;
520 }
521 }
522
523
524 /*
525 * Print the ASCII equivalent characters
526 * But watch out for the bad unprintable ones...
527 */
528
529 for (j = 0; j < 16; j++) {
530 if (i + j >= count) {
531 acpi_os_printf ("\n");
532 return;
533 }
534
535 buf_char = buffer[i + j];
536 if ((buf_char > 0x1F && buf_char < 0x2E) ||
537 (buf_char > 0x2F && buf_char < 0x61) ||
538 (buf_char > 0x60 && buf_char < 0x7F)) {
539 acpi_os_printf ("%c", buf_char);
540 }
541 else {
542 acpi_os_printf (".");
543 }
544 }
545
546 /* Done with that line. */
547
548 acpi_os_printf ("\n");
549 i += 16;
550 }
551
552 return;
553 }
554
555