aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorDavid Daney <ddaney@avtrex.com>2008-09-23 03:05:54 -0400
committerRalf Baechle <ralf@linux-mips.org>2008-10-11 11:18:56 -0400
commit6aa3524c182c01b8b8b7c21c4da20c742a9b4d86 (patch)
tree245fc4e9f26ad9e7a95e83087bfcc79528d1352e /arch
parent8192c9ea9ac44213d1266ecb64615519443979b3 (diff)
MIPS: Add HARDWARE_WATCHPOINTS definitions and support code.
This is the main support code for the patch. Here we just add the code, the following patches hook it up. Signed-off-by: David Daney <ddaney@avtrex.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org> create mode 100644 arch/mips/include/asm/watch.h create mode 100644 arch/mips/kernel/watch.c
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/include/asm/cpu-info.h6
-rw-r--r--arch/mips/include/asm/processor.h20
-rw-r--r--arch/mips/include/asm/thread_info.h2
-rw-r--r--arch/mips/include/asm/watch.h32
-rw-r--r--arch/mips/kernel/Makefile2
-rw-r--r--arch/mips/kernel/watch.c188
6 files changed, 249 insertions, 1 deletions
diff --git a/arch/mips/include/asm/cpu-info.h b/arch/mips/include/asm/cpu-info.h
index 2de73dbb2e9e..744cd8fb107f 100644
--- a/arch/mips/include/asm/cpu-info.h
+++ b/arch/mips/include/asm/cpu-info.h
@@ -12,6 +12,8 @@
12#ifndef __ASM_CPU_INFO_H 12#ifndef __ASM_CPU_INFO_H
13#define __ASM_CPU_INFO_H 13#define __ASM_CPU_INFO_H
14 14
15#include <linux/types.h>
16
15#include <asm/cache.h> 17#include <asm/cache.h>
16 18
17/* 19/*
@@ -69,6 +71,10 @@ struct cpuinfo_mips {
69 int tc_id; /* Thread Context number */ 71 int tc_id; /* Thread Context number */
70#endif 72#endif
71 void *data; /* Additional data */ 73 void *data; /* Additional data */
74 unsigned int watch_reg_count; /* Number that exist */
75 unsigned int watch_reg_use_cnt; /* Usable by ptrace */
76#define NUM_WATCH_REGS 4
77 u16 watch_reg_masks[NUM_WATCH_REGS];
72} __attribute__((aligned(SMP_CACHE_BYTES))); 78} __attribute__((aligned(SMP_CACHE_BYTES)));
73 79
74extern struct cpuinfo_mips cpu_data[]; 80extern struct cpuinfo_mips cpu_data[];
diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h
index a1e4453469f9..18ee58e39445 100644
--- a/arch/mips/include/asm/processor.h
+++ b/arch/mips/include/asm/processor.h
@@ -105,6 +105,19 @@ struct mips_dsp_state {
105 {0,} \ 105 {0,} \
106} 106}
107 107
108struct mips3264_watch_reg_state {
109 /* The width of watchlo is 32 in a 32 bit kernel and 64 in a
110 64 bit kernel. We use unsigned long as it has the same
111 property. */
112 unsigned long watchlo[NUM_WATCH_REGS];
113 /* Only the mask and IRW bits from watchhi. */
114 u16 watchhi[NUM_WATCH_REGS];
115};
116
117union mips_watch_reg_state {
118 struct mips3264_watch_reg_state mips3264;
119};
120
108typedef struct { 121typedef struct {
109 unsigned long seg; 122 unsigned long seg;
110} mm_segment_t; 123} mm_segment_t;
@@ -137,6 +150,9 @@ struct thread_struct {
137 /* Saved state of the DSP ASE, if available. */ 150 /* Saved state of the DSP ASE, if available. */
138 struct mips_dsp_state dsp; 151 struct mips_dsp_state dsp;
139 152
153 /* Saved watch register state, if available. */
154 union mips_watch_reg_state watch;
155
140 /* Other stuff associated with the thread. */ 156 /* Other stuff associated with the thread. */
141 unsigned long cp0_badvaddr; /* Last user fault */ 157 unsigned long cp0_badvaddr; /* Last user fault */
142 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */ 158 unsigned long cp0_baduaddr; /* Last kernel fault accessing USEG */
@@ -193,6 +209,10 @@ struct thread_struct {
193 .dspcontrol = 0, \ 209 .dspcontrol = 0, \
194 }, \ 210 }, \
195 /* \ 211 /* \
212 * saved watch register stuff \
213 */ \
214 .watch = {{{0,},},}, \
215 /* \
196 * Other stuff associated with the process \ 216 * Other stuff associated with the process \
197 */ \ 217 */ \
198 .cp0_badvaddr = 0, \ 218 .cp0_badvaddr = 0, \
diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
index bb3060699df2..3f76de73c943 100644
--- a/arch/mips/include/asm/thread_info.h
+++ b/arch/mips/include/asm/thread_info.h
@@ -124,6 +124,7 @@ register struct thread_info *__current_thread_info __asm__("$28");
124#define TIF_32BIT_REGS 22 /* also implies 16/32 fprs */ 124#define TIF_32BIT_REGS 22 /* also implies 16/32 fprs */
125#define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */ 125#define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
126#define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */ 126#define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
127#define TIF_LOAD_WATCH 25 /* If set, load watch registers */
127#define TIF_SYSCALL_TRACE 31 /* syscall trace active */ 128#define TIF_SYSCALL_TRACE 31 /* syscall trace active */
128 129
129#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 130#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
@@ -140,6 +141,7 @@ register struct thread_info *__current_thread_info __asm__("$28");
140#define _TIF_32BIT_REGS (1<<TIF_32BIT_REGS) 141#define _TIF_32BIT_REGS (1<<TIF_32BIT_REGS)
141#define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR) 142#define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
142#define _TIF_FPUBOUND (1<<TIF_FPUBOUND) 143#define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
144#define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
143 145
144/* work to do on interrupt/exception return */ 146/* work to do on interrupt/exception return */
145#define _TIF_WORK_MASK (0x0000ffef & ~_TIF_SECCOMP) 147#define _TIF_WORK_MASK (0x0000ffef & ~_TIF_SECCOMP)
diff --git a/arch/mips/include/asm/watch.h b/arch/mips/include/asm/watch.h
new file mode 100644
index 000000000000..20126ec79359
--- /dev/null
+++ b/arch/mips/include/asm/watch.h
@@ -0,0 +1,32 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 David Daney
7 */
8#ifndef _ASM_WATCH_H
9#define _ASM_WATCH_H
10
11#include <linux/bitops.h>
12
13#include <asm/mipsregs.h>
14
15void mips_install_watch_registers(void);
16void mips_read_watch_registers(void);
17void mips_clear_watch_registers(void);
18void mips_probe_watch_registers(struct cpuinfo_mips *c);
19
20#ifdef CONFIG_HARDWARE_WATCHPOINTS
21#define __restore_watch() do { \
22 if (unlikely(test_bit(TIF_LOAD_WATCH, \
23 &current_thread_info()->flags))) { \
24 mips_install_watch_registers(); \
25 } \
26} while (0)
27
28#else
29#define __restore_watch() do {} while (0)
30#endif
31
32#endif /* _ASM_WATCH_H */
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index 25775cb54000..d9da7112aaf8 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -6,7 +6,7 @@ extra-y := head.o init_task.o vmlinux.lds
6 6
7obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \ 7obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \
8 ptrace.o reset.o setup.o signal.o syscall.o \ 8 ptrace.o reset.o setup.o signal.o syscall.o \
9 time.o topology.o traps.o unaligned.o 9 time.o topology.o traps.o unaligned.o watch.o
10 10
11obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o 11obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o
12obj-$(CONFIG_CEVT_R4K) += cevt-r4k.o 12obj-$(CONFIG_CEVT_R4K) += cevt-r4k.o
diff --git a/arch/mips/kernel/watch.c b/arch/mips/kernel/watch.c
new file mode 100644
index 000000000000..c15406968030
--- /dev/null
+++ b/arch/mips/kernel/watch.c
@@ -0,0 +1,188 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 David Daney
7 */
8
9#include <linux/sched.h>
10
11#include <asm/processor.h>
12#include <asm/watch.h>
13
14/*
15 * Install the watch registers for the current thread. A maximum of
16 * four registers are installed although the machine may have more.
17 */
18void mips_install_watch_registers(void)
19{
20 struct mips3264_watch_reg_state *watches =
21 &current->thread.watch.mips3264;
22 switch (current_cpu_data.watch_reg_use_cnt) {
23 default:
24 BUG();
25 case 4:
26 write_c0_watchlo3(watches->watchlo[3]);
27 /* Write 1 to the I, R, and W bits to clear them, and
28 1 to G so all ASIDs are trapped. */
29 write_c0_watchhi3(0x40000007 | watches->watchhi[3]);
30 case 3:
31 write_c0_watchlo2(watches->watchlo[2]);
32 write_c0_watchhi2(0x40000007 | watches->watchhi[2]);
33 case 2:
34 write_c0_watchlo1(watches->watchlo[1]);
35 write_c0_watchhi1(0x40000007 | watches->watchhi[1]);
36 case 1:
37 write_c0_watchlo0(watches->watchlo[0]);
38 write_c0_watchhi0(0x40000007 | watches->watchhi[0]);
39 }
40}
41
42/*
43 * Read back the watchhi registers so the user space debugger has
44 * access to the I, R, and W bits. A maximum of four registers are
45 * read although the machine may have more.
46 */
47void mips_read_watch_registers(void)
48{
49 struct mips3264_watch_reg_state *watches =
50 &current->thread.watch.mips3264;
51 switch (current_cpu_data.watch_reg_use_cnt) {
52 default:
53 BUG();
54 case 4:
55 watches->watchhi[3] = (read_c0_watchhi3() & 0x0fff);
56 case 3:
57 watches->watchhi[2] = (read_c0_watchhi2() & 0x0fff);
58 case 2:
59 watches->watchhi[1] = (read_c0_watchhi1() & 0x0fff);
60 case 1:
61 watches->watchhi[0] = (read_c0_watchhi0() & 0x0fff);
62 }
63 if (current_cpu_data.watch_reg_use_cnt == 1 &&
64 (watches->watchhi[0] & 7) == 0) {
65 /* Pathological case of release 1 architecture that
66 * doesn't set the condition bits. We assume that
67 * since we got here, the watch condition was met and
68 * signal that the conditions requested in watchlo
69 * were met. */
70 watches->watchhi[0] |= (watches->watchlo[0] & 7);
71 }
72 }
73
74/*
75 * Disable all watch registers. Although only four registers are
76 * installed, all are cleared to eliminate the possibility of endless
77 * looping in the watch handler.
78 */
79void mips_clear_watch_registers(void)
80{
81 switch (current_cpu_data.watch_reg_count) {
82 default:
83 BUG();
84 case 8:
85 write_c0_watchlo7(0);
86 case 7:
87 write_c0_watchlo6(0);
88 case 6:
89 write_c0_watchlo5(0);
90 case 5:
91 write_c0_watchlo4(0);
92 case 4:
93 write_c0_watchlo3(0);
94 case 3:
95 write_c0_watchlo2(0);
96 case 2:
97 write_c0_watchlo1(0);
98 case 1:
99 write_c0_watchlo0(0);
100 }
101}
102
103__cpuinit void mips_probe_watch_registers(struct cpuinfo_mips *c)
104{
105 unsigned int t;
106
107 if ((c->options & MIPS_CPU_WATCH) == 0)
108 return;
109 /*
110 * Check which of the I,R and W bits are supported, then
111 * disable the register.
112 */
113 write_c0_watchlo0(7);
114 t = read_c0_watchlo0();
115 write_c0_watchlo0(0);
116 c->watch_reg_masks[0] = t & 7;
117
118 /* Write the mask bits and read them back to determine which
119 * can be used. */
120 c->watch_reg_count = 1;
121 c->watch_reg_use_cnt = 1;
122 t = read_c0_watchhi0();
123 write_c0_watchhi0(t | 0xff8);
124 t = read_c0_watchhi0();
125 c->watch_reg_masks[0] |= (t & 0xff8);
126 if ((t & 0x80000000) == 0)
127 return;
128
129 write_c0_watchlo1(7);
130 t = read_c0_watchlo1();
131 write_c0_watchlo1(0);
132 c->watch_reg_masks[1] = t & 7;
133
134 c->watch_reg_count = 2;
135 c->watch_reg_use_cnt = 2;
136 t = read_c0_watchhi1();
137 write_c0_watchhi1(t | 0xff8);
138 t = read_c0_watchhi1();
139 c->watch_reg_masks[1] |= (t & 0xff8);
140 if ((t & 0x80000000) == 0)
141 return;
142
143 write_c0_watchlo2(7);
144 t = read_c0_watchlo2();
145 write_c0_watchlo2(0);
146 c->watch_reg_masks[2] = t & 7;
147
148 c->watch_reg_count = 3;
149 c->watch_reg_use_cnt = 3;
150 t = read_c0_watchhi2();
151 write_c0_watchhi2(t | 0xff8);
152 t = read_c0_watchhi2();
153 c->watch_reg_masks[2] |= (t & 0xff8);
154 if ((t & 0x80000000) == 0)
155 return;
156
157 write_c0_watchlo3(7);
158 t = read_c0_watchlo3();
159 write_c0_watchlo3(0);
160 c->watch_reg_masks[3] = t & 7;
161
162 c->watch_reg_count = 4;
163 c->watch_reg_use_cnt = 4;
164 t = read_c0_watchhi3();
165 write_c0_watchhi3(t | 0xff8);
166 t = read_c0_watchhi3();
167 c->watch_reg_masks[3] |= (t & 0xff8);
168 if ((t & 0x80000000) == 0)
169 return;
170
171 /* We use at most 4, but probe and report up to 8. */
172 c->watch_reg_count = 5;
173 t = read_c0_watchhi4();
174 if ((t & 0x80000000) == 0)
175 return;
176
177 c->watch_reg_count = 6;
178 t = read_c0_watchhi5();
179 if ((t & 0x80000000) == 0)
180 return;
181
182 c->watch_reg_count = 7;
183 t = read_c0_watchhi6();
184 if ((t & 0x80000000) == 0)
185 return;
186
187 c->watch_reg_count = 8;
188}