Skip to content

Commit 669b792

Browse files
rgetzBryan Wu
authored andcommitted
Blackfin arch: Clean up trace buffer handling, No major functional changes.
Turns on trace earlier, so crashes at kernel start should print out a trace, making things easier to debug. Signed-off-by: Robin Getz <robin.getz@analog.com> Signed-off-by: Mike Frysinger <michael.frysinger@analog.com> Signed-off-by: Bryan Wu <bryan.wu@analog.com>
1 parent 29440a2 commit 669b792

9 files changed

Lines changed: 97 additions & 43 deletions

File tree

‎arch/blackfin/kernel/setup.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ void __init setup_arch(char **cmdline_p)
194194
/* this give a chance to get printk() working before crash. */
195195
#endif
196196

197+
printk(KERN_INFO "Hardware Trace ");
198+
if (bfin_read_TBUFCTL() & 0x1 )
199+
printk("Active ");
200+
else
201+
printk("Off ");
202+
if (bfin_read_TBUFCTL() & 0x2)
203+
printk("and Enabled\n");
204+
else
205+
printk("and Disabled\n");
206+
207+
197208
#if defined(CONFIG_CHR_DEV_FLASH) || defined(CONFIG_BLK_DEV_FLASH)
198209
/* we need to initialize the Flashrom device here since we might
199210
* do things with flash early on in the boot
@@ -397,9 +408,6 @@ void __init setup_arch(char **cmdline_p)
397408
_bfin_swrst = bfin_read_SWRST();
398409
#endif
399410

400-
printk(KERN_INFO "Hardware Trace Enabled\n");
401-
bfin_write_TBUFCTL(0x03);
402-
403411
/* Copy atomic sequences to their fixed location, and sanity check that
404412
these locations are the ones that we advertise to userspace. */
405413
memcpy((void *)FIXED_CODE_START, &fixed_code_start,

‎arch/blackfin/kernel/traps.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/blackfin.h>
3434
#include <asm/uaccess.h>
3535
#include <asm/irq_handler.h>
36+
#include <asm/trace.h>
3637
#include <linux/interrupt.h>
3738
#include <linux/module.h>
3839
#include <linux/kallsyms.h>
@@ -131,16 +132,6 @@ static int printk_address(unsigned long address)
131132
return printk("[<0x%p>]", (void*)address);
132133
}
133134

134-
#define trace_buffer_save(x) \
135-
do { \
136-
(x) = bfin_read_TBUFCTL(); \
137-
bfin_write_TBUFCTL((x) & ~TBUFEN); \
138-
} while (0)
139-
#define trace_buffer_restore(x) \
140-
do { \
141-
bfin_write_TBUFCTL((x)); \
142-
} while (0)
143-
144135
asmlinkage void trap_c(struct pt_regs *fp)
145136
{
146137
int j, sig = 0;

‎arch/blackfin/mach-bf533/head.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/linkage.h>
3131
#include <linux/init.h>
3232
#include <asm/blackfin.h>
33+
#include <asm/trace.h>
3334
#if CONFIG_BFIN_KERNEL_CLOCK
3435
#include <asm/mach/mem_init.h>
3536
#endif
@@ -96,6 +97,10 @@ ENTRY(__start)
9697
M2 = r0;
9798
M3 = r0;
9899

100+
trace_buffer_start(p0,r0);
101+
P0 = R1;
102+
R0 = R1;
103+
99104
#if CONFIG_DEBUG_KERNEL_START
100105

101106
/*

‎arch/blackfin/mach-bf537/head.S‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/linkage.h>
3131
#include <linux/init.h>
3232
#include <asm/blackfin.h>
33+
#include <asm/trace.h>
34+
3335
#if CONFIG_BFIN_KERNEL_CLOCK
3436
#include <asm/mach/mem_init.h>
3537
#endif
@@ -93,6 +95,10 @@ ENTRY(__start)
9395
M2 = r0;
9496
M3 = r0;
9597

98+
trace_buffer_start(p0,r0);
99+
P0 = R1;
100+
R0 = R1;
101+
96102
/* Turn off the icache */
97103
p0.l = (IMEM_CONTROL & 0xFFFF);
98104
p0.h = (IMEM_CONTROL >> 16);

‎arch/blackfin/mach-bf548/head.S‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <linux/linkage.h>
3131
#include <asm/blackfin.h>
32+
#include <asm/trace.h>
3233
#if CONFIG_BFIN_KERNEL_CLOCK
3334
#include <asm/mach/mem_init.h>
3435
#endif
@@ -91,6 +92,10 @@ ENTRY(__stext)
9192
M2 = r0;
9293
M3 = r0;
9394

95+
trace_buffer_start(p0,r0);
96+
P0 = R1;
97+
R0 = R1;
98+
9499
/* Turn off the icache */
95100
p0.l = (IMEM_CONTROL & 0xFFFF);
96101
p0.h = (IMEM_CONTROL >> 16);

‎arch/blackfin/mach-bf561/head.S‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/linkage.h>
3131
#include <linux/init.h>
3232
#include <asm/blackfin.h>
33+
#include <asm/trace.h>
34+
3335
#if CONFIG_BFIN_KERNEL_CLOCK
3436
#include <asm/mach/mem_init.h>
3537
#endif
@@ -93,6 +95,10 @@ ENTRY(__start)
9395
M2 = r0;
9496
M3 = r0;
9597

98+
trace_buffer_start(p0,r0);
99+
P0 = R1;
100+
R0 = R1;
101+
96102
/* Turn off the icache */
97103
p0.l = (IMEM_CONTROL & 0xFFFF);
98104
p0.h = (IMEM_CONTROL >> 16);

‎arch/blackfin/mach-common/entry.S‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,10 @@
5454
#include <asm/errno.h>
5555
#include <asm/thread_info.h> /* TIF_NEED_RESCHED */
5656
#include <asm/asm-offsets.h>
57+
#include <asm/trace.h>
5758

5859
#include <asm/mach-common/context.S>
5960

60-
#ifdef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
61-
/*
62-
* TODO: this should be proper save/restore, but for now
63-
* we'll just cheat and use 0x1/0x13
64-
*/
65-
# define DEBUG_START_HWTRACE \
66-
P5.l = LO(TBUFCTL); \
67-
P5.h = HI(TBUFCTL); \
68-
R7 = 0x13; \
69-
[P5] = R7;
70-
# define DEBUG_STOP_HWTRACE \
71-
P5.l = LO(TBUFCTL); \
72-
P5.h = HI(TBUFCTL); \
73-
R7 = 0x01; \
74-
[P5] = R7;
75-
#else
76-
# define DEBUG_START_HWTRACE
77-
# define DEBUG_STOP_HWTRACE
78-
#endif
79-
8061
#ifdef CONFIG_EXCPT_IRQ_SYSC_L1
8162
.section .l1.text
8263
#else
@@ -110,7 +91,7 @@ ENTRY(_ex_icplb)
11091
ASTAT = [sp++];
11192
SAVE_ALL_SYS
11293
call __cplb_hdr;
113-
DEBUG_START_HWTRACE
94+
DEBUG_START_HWTRACE(p5, r7)
11495
RESTORE_ALL_SYS
11596
SP = RETN;
11697
rtx;
@@ -128,7 +109,7 @@ ENTRY(_ex_spinlock)
128109
ENDPROC(_ex_spinlock)
129110

130111
ENTRY(_ex_syscall)
131-
DEBUG_START_HWTRACE
112+
DEBUG_START_HWTRACE(p5, r7)
132113
(R7:6,P5:4) = [sp++];
133114
ASTAT = [sp++];
134115
raise 15; /* invoked by TRAP #0, for sys call */
@@ -186,7 +167,7 @@ ENTRY(_ex_single_step)
186167
if !cc jump _ex_trap_c;
187168

188169
_return_from_exception:
189-
DEBUG_START_HWTRACE
170+
DEBUG_START_HWTRACE(p5, r7)
190171
#ifdef ANOMALY_05000257
191172
R7=LC0;
192173
LC0=R7;
@@ -208,7 +189,7 @@ ENTRY(_handle_bad_cplb)
208189
* need to make a CPLB exception look like a normal exception
209190
*/
210191

211-
DEBUG_START_HWTRACE
192+
DEBUG_START_HWTRACE(p5, r7)
212193
RESTORE_ALL_SYS
213194
[--sp] = ASTAT;
214195
[--sp] = (R7:6, P5:4);
@@ -251,7 +232,7 @@ ENTRY(_ex_trap_c)
251232
R6 = SEQSTAT;
252233
[P5] = R6;
253234

254-
DEBUG_START_HWTRACE
235+
DEBUG_START_HWTRACE(p5, r7)
255236
(R7:6,P5:4) = [sp++];
256237
ASTAT = [sp++];
257238
SP = RETN;
@@ -335,7 +316,7 @@ ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
335316
/* Try to deal with syscalls quickly. */
336317
[--sp] = ASTAT;
337318
[--sp] = (R7:6, P5:4);
338-
DEBUG_STOP_HWTRACE
319+
DEBUG_STOP_HWTRACE(p5, r7)
339320
r7 = SEQSTAT; /* reason code is in bit 5:0 */
340321
r6.l = lo(SEQSTAT_EXCAUSE);
341322
r6.h = hi(SEQSTAT_EXCAUSE);

‎arch/blackfin/mach-common/interrupt.S‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/linkage.h>
3535
#include <asm/entry.h>
3636
#include <asm/asm-offsets.h>
37+
#include <asm/trace.h>
3738

3839
#include <asm/mach-common/context.S>
3940

@@ -170,10 +171,9 @@ ENTRY(_evt_ivhw)
170171
r7.l = W[p5];
171172
1:
172173
#endif
173-
p0.l = lo(TBUFCTL);
174-
p0.h = hi(TBUFCTL);
175-
r0 = 1;
176-
[p0] = r0;
174+
175+
trace_buffer_stop(p0, r0);
176+
177177
r0 = IRQ_HWERR;
178178
r1 = sp;
179179

‎include/asm-blackfin/trace.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Common header file for blackfin family of processors.
3+
*
4+
*/
5+
6+
#ifndef _BLACKFIN_TRACE_
7+
#define _BLACKFIN_TRACE_
8+
9+
#ifndef __ASSEMBLY__
10+
/* Trace Macros for C files */
11+
12+
#define trace_buffer_save(x) \
13+
do { \
14+
(x) = bfin_read_TBUFCTL(); \
15+
bfin_write_TBUFCTL((x) & ~TBUFEN); \
16+
} while (0)
17+
18+
#define trace_buffer_restore(x) \
19+
do { \
20+
bfin_write_TBUFCTL((x)); \
21+
} while (0)
22+
23+
#else
24+
/* Trace Macros for Assembly files */
25+
26+
#define TRACE_BUFFER_START(preg, dreg) trace_buffer_start(preg, dreg)
27+
#define TRACE_BUFFER_STOP(preg, dreg) trace_buffer_stop(preg, dreg)
28+
29+
#define trace_buffer_stop(preg, dreg) \
30+
preg.L = LO(TBUFCTL); \
31+
preg.H = HI(TBUFCTL); \
32+
dreg = 0x1; \
33+
[preg] = dreg;
34+
35+
#define trace_buffer_start(preg, dreg) \
36+
preg.L = LO(TBUFCTL); \
37+
preg.H = HI(TBUFCTL); \
38+
dreg = 0x13; \
39+
[preg] = dreg;
40+
41+
#ifdef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
42+
# define DEBUG_START_HWTRACE(preg, dreg) trace_buffer_start(preg, dreg)
43+
# define DEBUG_STOP_HWTRACE(preg, dreg) trace_buffer_stop(preg, dreg)
44+
45+
#else
46+
# define DEBUG_START_HWTRACE(preg, dreg)
47+
# define DEBUG_STOP_HWTRACE(preg, dreg)
48+
#endif
49+
50+
#endif /* __ASSEMBLY__ */
51+
52+
#endif /* _BLACKFIN_TRACE_ */

0 commit comments

Comments
 (0)