1
2
3
4
5
6
7
8
9
10#define EXPORT_ACPI_INTERFACES
11
12#include <acpi/acpi.h>
13#include "accommon.h"
14#include "acinterp.h"
15
16#define _COMPONENT ACPI_UTILITIES
17ACPI_MODULE_NAME("utdebug")
18
19#ifdef ACPI_DEBUG_OUTPUT
20static acpi_thread_id acpi_gbl_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF;
21static const char *acpi_gbl_function_entry_prefix = "----Entry";
22static const char *acpi_gbl_function_exit_prefix = "----Exit-";
23
24
25
26
27
28
29
30
31
32
33
34
35
36void acpi_ut_init_stack_ptr_trace(void)
37{
38 acpi_size current_sp;
39
40 acpi_gbl_entry_stack_pointer = ¤t_sp;
41}
42
43
44
45
46
47
48
49
50
51
52
53
54
55void acpi_ut_track_stack_ptr(void)
56{
57 acpi_size current_sp;
58
59 if (¤t_sp < acpi_gbl_lowest_stack_pointer) {
60 acpi_gbl_lowest_stack_pointer = ¤t_sp;
61 }
62
63 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
64 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
65 }
66}
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82static const char *acpi_ut_trim_function_name(const char *function_name)
83{
84
85
86
87 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
88
89
90
91 return (function_name + 4);
92 }
93
94 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
95
96
97
98 return (function_name + 5);
99 }
100
101 return (function_name);
102}
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123void ACPI_INTERNAL_VAR_XFACE
124acpi_debug_print(u32 requested_debug_level,
125 u32 line_number,
126 const char *function_name,
127 const char *module_name,
128 u32 component_id, const char *format, ...)
129{
130 acpi_thread_id thread_id;
131 va_list args;
132#ifdef ACPI_APPLICATION
133 int fill_count;
134#endif
135
136
137
138 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
139 return;
140 }
141
142
143
144
145 thread_id = acpi_os_get_thread_id();
146 if (thread_id != acpi_gbl_previous_thread_id) {
147 if (ACPI_LV_THREADS & acpi_dbg_level) {
148 acpi_os_printf
149 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
150 (u32)acpi_gbl_previous_thread_id, (u32)thread_id);
151 }
152
153 acpi_gbl_previous_thread_id = thread_id;
154 acpi_gbl_nesting_level = 0;
155 }
156
157
158
159
160
161 acpi_os_printf("%9s-%04d ", module_name, line_number);
162
163#ifdef ACPI_APPLICATION
164
165
166
167
168
169
170 if (ACPI_LV_THREADS & acpi_dbg_level) {
171 acpi_os_printf("[%u] ", (u32)thread_id);
172 }
173
174 fill_count = 48 - acpi_gbl_nesting_level -
175 strlen(acpi_ut_trim_function_name(function_name));
176 if (fill_count < 0) {
177 fill_count = 0;
178 }
179
180 acpi_os_printf("[%02d] %*s",
181 acpi_gbl_nesting_level, acpi_gbl_nesting_level + 1, " ");
182 acpi_os_printf("%s%*s: ",
183 acpi_ut_trim_function_name(function_name), fill_count,
184 " ");
185
186#else
187 acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
188#endif
189
190 va_start(args, format);
191 acpi_os_vprintf(format, args);
192 va_end(args);
193}
194
195ACPI_EXPORT_SYMBOL(acpi_debug_print)
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215void ACPI_INTERNAL_VAR_XFACE
216acpi_debug_print_raw(u32 requested_debug_level,
217 u32 line_number,
218 const char *function_name,
219 const char *module_name,
220 u32 component_id, const char *format, ...)
221{
222 va_list args;
223
224
225
226 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
227 return;
228 }
229
230 va_start(args, format);
231 acpi_os_vprintf(format, args);
232 va_end(args);
233}
234
235ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252void
253acpi_ut_trace(u32 line_number,
254 const char *function_name,
255 const char *module_name, u32 component_id)
256{
257
258 acpi_gbl_nesting_level++;
259 acpi_ut_track_stack_ptr();
260
261
262
263 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
264 acpi_debug_print(ACPI_LV_FUNCTIONS,
265 line_number, function_name, module_name,
266 component_id, "%s\n",
267 acpi_gbl_function_entry_prefix);
268 }
269}
270
271ACPI_EXPORT_SYMBOL(acpi_ut_trace)
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289void
290acpi_ut_trace_ptr(u32 line_number,
291 const char *function_name,
292 const char *module_name,
293 u32 component_id, const void *pointer)
294{
295
296 acpi_gbl_nesting_level++;
297 acpi_ut_track_stack_ptr();
298
299
300
301 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
302 acpi_debug_print(ACPI_LV_FUNCTIONS,
303 line_number, function_name, module_name,
304 component_id, "%s %p\n",
305 acpi_gbl_function_entry_prefix, pointer);
306 }
307}
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326void
327acpi_ut_trace_str(u32 line_number,
328 const char *function_name,
329 const char *module_name, u32 component_id, const char *string)
330{
331
332 acpi_gbl_nesting_level++;
333 acpi_ut_track_stack_ptr();
334
335
336
337 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
338 acpi_debug_print(ACPI_LV_FUNCTIONS,
339 line_number, function_name, module_name,
340 component_id, "%s %s\n",
341 acpi_gbl_function_entry_prefix, string);
342 }
343}
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362void
363acpi_ut_trace_u32(u32 line_number,
364 const char *function_name,
365 const char *module_name, u32 component_id, u32 integer)
366{
367
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr();
370
371
372
373 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
374 acpi_debug_print(ACPI_LV_FUNCTIONS,
375 line_number, function_name, module_name,
376 component_id, "%s %08X\n",
377 acpi_gbl_function_entry_prefix, integer);
378 }
379}
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397void
398acpi_ut_exit(u32 line_number,
399 const char *function_name,
400 const char *module_name, u32 component_id)
401{
402
403
404
405 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
406 acpi_debug_print(ACPI_LV_FUNCTIONS,
407 line_number, function_name, module_name,
408 component_id, "%s\n",
409 acpi_gbl_function_exit_prefix);
410 }
411
412 if (acpi_gbl_nesting_level) {
413 acpi_gbl_nesting_level--;
414 }
415}
416
417ACPI_EXPORT_SYMBOL(acpi_ut_exit)
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435void
436acpi_ut_status_exit(u32 line_number,
437 const char *function_name,
438 const char *module_name,
439 u32 component_id, acpi_status status)
440{
441
442
443
444 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
445 if (ACPI_SUCCESS(status)) {
446 acpi_debug_print(ACPI_LV_FUNCTIONS,
447 line_number, function_name,
448 module_name, component_id, "%s %s\n",
449 acpi_gbl_function_exit_prefix,
450 acpi_format_exception(status));
451 } else {
452 acpi_debug_print(ACPI_LV_FUNCTIONS,
453 line_number, function_name,
454 module_name, component_id,
455 "%s ****Exception****: %s\n",
456 acpi_gbl_function_exit_prefix,
457 acpi_format_exception(status));
458 }
459 }
460
461 if (acpi_gbl_nesting_level) {
462 acpi_gbl_nesting_level--;
463 }
464}
465
466ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484void
485acpi_ut_value_exit(u32 line_number,
486 const char *function_name,
487 const char *module_name, u32 component_id, u64 value)
488{
489
490
491
492 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
493 acpi_debug_print(ACPI_LV_FUNCTIONS,
494 line_number, function_name, module_name,
495 component_id, "%s %8.8X%8.8X\n",
496 acpi_gbl_function_exit_prefix,
497 ACPI_FORMAT_UINT64(value));
498 }
499
500 if (acpi_gbl_nesting_level) {
501 acpi_gbl_nesting_level--;
502 }
503}
504
505ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523void
524acpi_ut_ptr_exit(u32 line_number,
525 const char *function_name,
526 const char *module_name, u32 component_id, u8 *ptr)
527{
528
529
530
531 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
532 acpi_debug_print(ACPI_LV_FUNCTIONS,
533 line_number, function_name, module_name,
534 component_id, "%s %p\n",
535 acpi_gbl_function_exit_prefix, ptr);
536 }
537
538 if (acpi_gbl_nesting_level) {
539 acpi_gbl_nesting_level--;
540 }
541}
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560void
561acpi_ut_str_exit(u32 line_number,
562 const char *function_name,
563 const char *module_name, u32 component_id, const char *string)
564{
565
566
567
568 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
569 acpi_debug_print(ACPI_LV_FUNCTIONS,
570 line_number, function_name, module_name,
571 component_id, "%s %s\n",
572 acpi_gbl_function_exit_prefix, string);
573 }
574
575 if (acpi_gbl_nesting_level) {
576 acpi_gbl_nesting_level--;
577 }
578}
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596void
597acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
598{
599
600 ACPI_FUNCTION_ENTRY();
601
602 acpi_ex_trace_point(type, begin, aml, pathname);
603
604#ifdef ACPI_USE_SYSTEM_TRACER
605 acpi_os_trace_point(type, begin, aml, pathname);
606#endif
607}
608
609ACPI_EXPORT_SYMBOL(acpi_trace_point)
610
611#endif
612