blob: 16921299efb9463eb888a6d3cd5d68326ebd35f9 [file] [log] [blame]
Will Deaconf81ef4a2010-09-03 10:41:08 +01001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14 *
15 * Copyright (C) 2009, 2010 ARM Limited
16 *
17 * Author: Will Deacon <will.deacon@arm.com>
18 */
19
20/*
21 * HW_breakpoint: a unified kernel/user-space hardware breakpoint facility,
22 * using the CPU's debug registers.
23 */
24#define pr_fmt(fmt) "hw-breakpoint: " fmt
25
26#include <linux/errno.h>
Will Deacon7e202692010-11-28 14:57:24 +000027#include <linux/hardirq.h>
Will Deaconf81ef4a2010-09-03 10:41:08 +010028#include <linux/perf_event.h>
29#include <linux/hw_breakpoint.h>
30#include <linux/smp.h>
31
32#include <asm/cacheflush.h>
33#include <asm/cputype.h>
34#include <asm/current.h>
35#include <asm/hw_breakpoint.h>
36#include <asm/kdebug.h>
Will Deaconf81ef4a2010-09-03 10:41:08 +010037#include <asm/traps.h>
38
39/* Breakpoint currently in use for each BRP. */
40static DEFINE_PER_CPU(struct perf_event *, bp_on_reg[ARM_MAX_BRP]);
41
42/* Watchpoint currently in use for each WRP. */
43static DEFINE_PER_CPU(struct perf_event *, wp_on_reg[ARM_MAX_WRP]);
44
45/* Number of BRP/WRP registers on this CPU. */
46static int core_num_brps;
47static int core_num_wrps;
48
49/* Debug architecture version. */
50static u8 debug_arch;
51
52/* Maximum supported watchpoint length. */
53static u8 max_watchpoint_len;
54
Will Deaconf81ef4a2010-09-03 10:41:08 +010055#define READ_WB_REG_CASE(OP2, M, VAL) \
56 case ((OP2 << 4) + M): \
57 ARM_DBG_READ(c ## M, OP2, VAL); \
58 break
59
60#define WRITE_WB_REG_CASE(OP2, M, VAL) \
61 case ((OP2 << 4) + M): \
62 ARM_DBG_WRITE(c ## M, OP2, VAL);\
63 break
64
65#define GEN_READ_WB_REG_CASES(OP2, VAL) \
66 READ_WB_REG_CASE(OP2, 0, VAL); \
67 READ_WB_REG_CASE(OP2, 1, VAL); \
68 READ_WB_REG_CASE(OP2, 2, VAL); \
69 READ_WB_REG_CASE(OP2, 3, VAL); \
70 READ_WB_REG_CASE(OP2, 4, VAL); \
71 READ_WB_REG_CASE(OP2, 5, VAL); \
72 READ_WB_REG_CASE(OP2, 6, VAL); \
73 READ_WB_REG_CASE(OP2, 7, VAL); \
74 READ_WB_REG_CASE(OP2, 8, VAL); \
75 READ_WB_REG_CASE(OP2, 9, VAL); \
76 READ_WB_REG_CASE(OP2, 10, VAL); \
77 READ_WB_REG_CASE(OP2, 11, VAL); \
78 READ_WB_REG_CASE(OP2, 12, VAL); \
79 READ_WB_REG_CASE(OP2, 13, VAL); \
80 READ_WB_REG_CASE(OP2, 14, VAL); \
81 READ_WB_REG_CASE(OP2, 15, VAL)
82
83#define GEN_WRITE_WB_REG_CASES(OP2, VAL) \
84 WRITE_WB_REG_CASE(OP2, 0, VAL); \
85 WRITE_WB_REG_CASE(OP2, 1, VAL); \
86 WRITE_WB_REG_CASE(OP2, 2, VAL); \
87 WRITE_WB_REG_CASE(OP2, 3, VAL); \
88 WRITE_WB_REG_CASE(OP2, 4, VAL); \
89 WRITE_WB_REG_CASE(OP2, 5, VAL); \
90 WRITE_WB_REG_CASE(OP2, 6, VAL); \
91 WRITE_WB_REG_CASE(OP2, 7, VAL); \
92 WRITE_WB_REG_CASE(OP2, 8, VAL); \
93 WRITE_WB_REG_CASE(OP2, 9, VAL); \
94 WRITE_WB_REG_CASE(OP2, 10, VAL); \
95 WRITE_WB_REG_CASE(OP2, 11, VAL); \
96 WRITE_WB_REG_CASE(OP2, 12, VAL); \
97 WRITE_WB_REG_CASE(OP2, 13, VAL); \
98 WRITE_WB_REG_CASE(OP2, 14, VAL); \
99 WRITE_WB_REG_CASE(OP2, 15, VAL)
100
101static u32 read_wb_reg(int n)
102{
103 u32 val = 0;
104
105 switch (n) {
106 GEN_READ_WB_REG_CASES(ARM_OP2_BVR, val);
107 GEN_READ_WB_REG_CASES(ARM_OP2_BCR, val);
108 GEN_READ_WB_REG_CASES(ARM_OP2_WVR, val);
109 GEN_READ_WB_REG_CASES(ARM_OP2_WCR, val);
110 default:
111 pr_warning("attempt to read from unknown breakpoint "
112 "register %d\n", n);
113 }
114
115 return val;
116}
117
118static void write_wb_reg(int n, u32 val)
119{
120 switch (n) {
121 GEN_WRITE_WB_REG_CASES(ARM_OP2_BVR, val);
122 GEN_WRITE_WB_REG_CASES(ARM_OP2_BCR, val);
123 GEN_WRITE_WB_REG_CASES(ARM_OP2_WVR, val);
124 GEN_WRITE_WB_REG_CASES(ARM_OP2_WCR, val);
125 default:
126 pr_warning("attempt to write to unknown breakpoint "
127 "register %d\n", n);
128 }
129 isb();
130}
131
Will Deacon0017ff42010-11-28 15:09:36 +0000132/* Determine debug architecture. */
133static u8 get_debug_arch(void)
134{
135 u32 didr;
136
137 /* Do we implement the extended CPUID interface? */
Will Deacond1244332011-08-04 14:46:23 +0100138 if (((read_cpuid_id() >> 16) & 0xf) != 0xf) {
139 pr_warning("CPUID feature registers not supported. "
140 "Assuming v6 debug is present.\n");
Will Deacon0017ff42010-11-28 15:09:36 +0000141 return ARM_DEBUG_ARCH_V6;
Will Deacond1244332011-08-04 14:46:23 +0100142 }
Will Deacon0017ff42010-11-28 15:09:36 +0000143
144 ARM_DBG_READ(c0, 0, didr);
145 return (didr >> 16) & 0xf;
146}
147
148u8 arch_get_debug_arch(void)
149{
150 return debug_arch;
151}
152
Will Deacon66e1cfe2011-02-11 16:01:42 +0100153static int debug_arch_supported(void)
154{
155 u8 arch = get_debug_arch();
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100156
157 /* We don't support the memory-mapped interface. */
158 return (arch >= ARM_DEBUG_ARCH_V6 && arch <= ARM_DEBUG_ARCH_V7_ECP14) ||
159 arch >= ARM_DEBUG_ARCH_V7_1;
Will Deacon66e1cfe2011-02-11 16:01:42 +0100160}
161
Will Deaconc512de92011-08-02 13:01:17 +0100162/* Determine number of WRP registers available. */
163static int get_num_wrp_resources(void)
164{
165 u32 didr;
166 ARM_DBG_READ(c0, 0, didr);
167 return ((didr >> 28) & 0xf) + 1;
168}
169
170/* Determine number of BRP registers available. */
Will Deacon0017ff42010-11-28 15:09:36 +0000171static int get_num_brp_resources(void)
172{
173 u32 didr;
174 ARM_DBG_READ(c0, 0, didr);
175 return ((didr >> 24) & 0xf) + 1;
176}
177
178/* Does this core support mismatch breakpoints? */
179static int core_has_mismatch_brps(void)
180{
181 return (get_debug_arch() >= ARM_DEBUG_ARCH_V7_ECP14 &&
182 get_num_brp_resources() > 1);
183}
184
185/* Determine number of usable WRPs available. */
186static int get_num_wrps(void)
187{
188 /*
Will Deaconc512de92011-08-02 13:01:17 +0100189 * On debug architectures prior to 7.1, when a watchpoint fires, the
190 * only way to work out which watchpoint it was is by disassembling
191 * the faulting instruction and working out the address of the memory
192 * access.
Will Deacon0017ff42010-11-28 15:09:36 +0000193 *
194 * Furthermore, we can only do this if the watchpoint was precise
195 * since imprecise watchpoints prevent us from calculating register
196 * based addresses.
197 *
198 * Providing we have more than 1 breakpoint register, we only report
199 * a single watchpoint register for the time being. This way, we always
200 * know which watchpoint fired. In the future we can either add a
201 * disassembler and address generation emulator, or we can insert a
202 * check to see if the DFAR is set on watchpoint exception entry
203 * [the ARM ARM states that the DFAR is UNKNOWN, but experience shows
204 * that it is set on some implementations].
205 */
Will Deaconc512de92011-08-02 13:01:17 +0100206 if (get_debug_arch() < ARM_DEBUG_ARCH_V7_1)
207 return 1;
Will Deacon0017ff42010-11-28 15:09:36 +0000208
Will Deaconc512de92011-08-02 13:01:17 +0100209 return get_num_wrp_resources();
Will Deacon0017ff42010-11-28 15:09:36 +0000210}
211
212/* Determine number of usable BRPs available. */
213static int get_num_brps(void)
214{
215 int brps = get_num_brp_resources();
Will Deaconc512de92011-08-02 13:01:17 +0100216 return core_has_mismatch_brps() ? brps - 1 : brps;
Will Deacon0017ff42010-11-28 15:09:36 +0000217}
218
Stephen Boyd5607d222012-09-18 20:23:13 -0700219/* Determine if halting mode is enabled */
220static int halting_mode_enabled(void)
221{
222 u32 dscr;
223
224 ARM_DBG_READ(c1, 0, dscr);
225
226 if (WARN_ONCE(dscr & ARM_DSCR_HDBGEN,
227 "halting debug mode enabled. "
228 "Unable to access hardware resources.\n"))
229 return -EPERM;
230 return 0;
231}
232
Will Deaconf81ef4a2010-09-03 10:41:08 +0100233/*
234 * In order to access the breakpoint/watchpoint control registers,
235 * we must be running in debug monitor mode. Unfortunately, we can
236 * be put into halting debug mode at any time by an external debugger
237 * but there is nothing we can do to prevent that.
238 */
239static int enable_monitor_mode(void)
240{
241 u32 dscr;
Stephen Boyd5607d222012-09-18 20:23:13 -0700242 int ret;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100243
244 ARM_DBG_READ(c1, 0, dscr);
245
246 /* Ensure that halting mode is disabled. */
Stephen Boyd5607d222012-09-18 20:23:13 -0700247 ret = halting_mode_enabled();
248 if (ret)
Will Deaconf81ef4a2010-09-03 10:41:08 +0100249 goto out;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100250
Will Deacon8fbf3972010-12-01 17:37:45 +0000251 /* If monitor mode is already enabled, just return. */
252 if (dscr & ARM_DSCR_MDBGEN)
253 goto out;
254
Will Deaconf81ef4a2010-09-03 10:41:08 +0100255 /* Write to the corresponding DSCR. */
Will Deacon8fbf3972010-12-01 17:37:45 +0000256 switch (get_debug_arch()) {
Will Deaconf81ef4a2010-09-03 10:41:08 +0100257 case ARM_DEBUG_ARCH_V6:
258 case ARM_DEBUG_ARCH_V6_1:
259 ARM_DBG_WRITE(c1, 0, (dscr | ARM_DSCR_MDBGEN));
260 break;
261 case ARM_DEBUG_ARCH_V7_ECP14:
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100262 case ARM_DEBUG_ARCH_V7_1:
Will Deaconf81ef4a2010-09-03 10:41:08 +0100263 ARM_DBG_WRITE(c2, 2, (dscr | ARM_DSCR_MDBGEN));
264 break;
265 default:
266 ret = -ENODEV;
267 goto out;
268 }
269
270 /* Check that the write made it through. */
271 ARM_DBG_READ(c1, 0, dscr);
Will Deacon8fbf3972010-12-01 17:37:45 +0000272 if (!(dscr & ARM_DSCR_MDBGEN))
Will Deaconf81ef4a2010-09-03 10:41:08 +0100273 ret = -EPERM;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100274
275out:
276 return ret;
277}
278
Will Deacon8fbf3972010-12-01 17:37:45 +0000279int hw_breakpoint_slots(int type)
280{
Will Deacon66e1cfe2011-02-11 16:01:42 +0100281 if (!debug_arch_supported())
282 return 0;
283
Will Deacon8fbf3972010-12-01 17:37:45 +0000284 /*
285 * We can be called early, so don't rely on
286 * our static variables being initialised.
287 */
288 switch (type) {
289 case TYPE_INST:
290 return get_num_brps();
291 case TYPE_DATA:
292 return get_num_wrps();
293 default:
294 pr_warning("unknown slot type: %d\n", type);
295 return 0;
296 }
297}
298
Will Deaconf81ef4a2010-09-03 10:41:08 +0100299/*
300 * Check if 8-bit byte-address select is available.
301 * This clobbers WRP 0.
302 */
303static u8 get_max_wp_len(void)
304{
305 u32 ctrl_reg;
306 struct arch_hw_breakpoint_ctrl ctrl;
307 u8 size = 4;
308
309 if (debug_arch < ARM_DEBUG_ARCH_V7_ECP14)
310 goto out;
311
Will Deaconf81ef4a2010-09-03 10:41:08 +0100312 memset(&ctrl, 0, sizeof(ctrl));
313 ctrl.len = ARM_BREAKPOINT_LEN_8;
314 ctrl_reg = encode_ctrl_reg(ctrl);
315
316 write_wb_reg(ARM_BASE_WVR, 0);
317 write_wb_reg(ARM_BASE_WCR, ctrl_reg);
318 if ((read_wb_reg(ARM_BASE_WCR) & ctrl_reg) == ctrl_reg)
319 size = 8;
320
321out:
322 return size;
323}
324
325u8 arch_get_max_wp_len(void)
326{
327 return max_watchpoint_len;
328}
329
330/*
Will Deaconf81ef4a2010-09-03 10:41:08 +0100331 * Install a perf counter breakpoint.
332 */
333int arch_install_hw_breakpoint(struct perf_event *bp)
334{
335 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
336 struct perf_event **slot, **slots;
337 int i, max_slots, ctrl_base, val_base, ret = 0;
Will Deacon93a04a32010-11-29 16:56:01 +0000338 u32 addr, ctrl;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100339
340 /* Ensure that we are in monitor mode and halting mode is disabled. */
341 ret = enable_monitor_mode();
342 if (ret)
343 goto out;
344
Will Deacon93a04a32010-11-29 16:56:01 +0000345 addr = info->address;
346 ctrl = encode_ctrl_reg(info->ctrl) | 0x1;
347
Will Deaconf81ef4a2010-09-03 10:41:08 +0100348 if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE) {
349 /* Breakpoint */
350 ctrl_base = ARM_BASE_BCR;
351 val_base = ARM_BASE_BVR;
Will Deacon4a55c182010-11-29 17:06:53 +0000352 slots = (struct perf_event **)__get_cpu_var(bp_on_reg);
Will Deacon0017ff42010-11-28 15:09:36 +0000353 max_slots = core_num_brps;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100354 } else {
355 /* Watchpoint */
Will Deacon6f26aa02011-08-02 16:16:57 +0100356 ctrl_base = ARM_BASE_WCR;
357 val_base = ARM_BASE_WVR;
Will Deacon4a55c182010-11-29 17:06:53 +0000358 slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100359 max_slots = core_num_wrps;
360 }
361
362 for (i = 0; i < max_slots; ++i) {
363 slot = &slots[i];
364
365 if (!*slot) {
366 *slot = bp;
367 break;
368 }
369 }
370
Stephen Boyd7d85d612011-03-10 05:15:00 +0100371 if (WARN_ONCE(i == max_slots, "Can't find any breakpoint slot\n")) {
Will Deaconf81ef4a2010-09-03 10:41:08 +0100372 ret = -EBUSY;
373 goto out;
374 }
375
Will Deacon6f26aa02011-08-02 16:16:57 +0100376 /* Override the breakpoint data with the step data. */
377 if (info->step_ctrl.enabled) {
378 addr = info->trigger & ~0x3;
379 ctrl = encode_ctrl_reg(info->step_ctrl);
380 if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE) {
381 i = 0;
382 ctrl_base = ARM_BASE_BCR + core_num_brps;
383 val_base = ARM_BASE_BVR + core_num_brps;
384 }
385 }
386
Will Deaconf81ef4a2010-09-03 10:41:08 +0100387 /* Setup the address register. */
Will Deacon93a04a32010-11-29 16:56:01 +0000388 write_wb_reg(val_base + i, addr);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100389
390 /* Setup the control register. */
Will Deacon93a04a32010-11-29 16:56:01 +0000391 write_wb_reg(ctrl_base + i, ctrl);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100392
393out:
394 return ret;
395}
396
397void arch_uninstall_hw_breakpoint(struct perf_event *bp)
398{
399 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
400 struct perf_event **slot, **slots;
401 int i, max_slots, base;
402
403 if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE) {
404 /* Breakpoint */
405 base = ARM_BASE_BCR;
Will Deacon4a55c182010-11-29 17:06:53 +0000406 slots = (struct perf_event **)__get_cpu_var(bp_on_reg);
Will Deacon0017ff42010-11-28 15:09:36 +0000407 max_slots = core_num_brps;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100408 } else {
409 /* Watchpoint */
Will Deacon6f26aa02011-08-02 16:16:57 +0100410 base = ARM_BASE_WCR;
Will Deacon4a55c182010-11-29 17:06:53 +0000411 slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100412 max_slots = core_num_wrps;
413 }
414
415 /* Remove the breakpoint. */
416 for (i = 0; i < max_slots; ++i) {
417 slot = &slots[i];
418
419 if (*slot == bp) {
420 *slot = NULL;
421 break;
422 }
423 }
424
Stephen Boyd7d85d612011-03-10 05:15:00 +0100425 if (WARN_ONCE(i == max_slots, "Can't find any breakpoint slot\n"))
Will Deaconf81ef4a2010-09-03 10:41:08 +0100426 return;
427
Will Deacon6f26aa02011-08-02 16:16:57 +0100428 /* Ensure that we disable the mismatch breakpoint. */
429 if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE &&
430 info->step_ctrl.enabled) {
431 i = 0;
432 base = ARM_BASE_BCR + core_num_brps;
433 }
434
Will Deaconf81ef4a2010-09-03 10:41:08 +0100435 /* Reset the control register. */
436 write_wb_reg(base + i, 0);
437}
438
439static int get_hbp_len(u8 hbp_len)
440{
441 unsigned int len_in_bytes = 0;
442
443 switch (hbp_len) {
444 case ARM_BREAKPOINT_LEN_1:
445 len_in_bytes = 1;
446 break;
447 case ARM_BREAKPOINT_LEN_2:
448 len_in_bytes = 2;
449 break;
450 case ARM_BREAKPOINT_LEN_4:
451 len_in_bytes = 4;
452 break;
453 case ARM_BREAKPOINT_LEN_8:
454 len_in_bytes = 8;
455 break;
456 }
457
458 return len_in_bytes;
459}
460
461/*
462 * Check whether bp virtual address is in kernel space.
463 */
464int arch_check_bp_in_kernelspace(struct perf_event *bp)
465{
466 unsigned int len;
467 unsigned long va;
468 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
469
470 va = info->address;
471 len = get_hbp_len(info->ctrl.len);
472
473 return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE);
474}
475
476/*
477 * Extract generic type and length encodings from an arch_hw_breakpoint_ctrl.
478 * Hopefully this will disappear when ptrace can bypass the conversion
479 * to generic breakpoint descriptions.
480 */
481int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
482 int *gen_len, int *gen_type)
483{
484 /* Type */
485 switch (ctrl.type) {
486 case ARM_BREAKPOINT_EXECUTE:
487 *gen_type = HW_BREAKPOINT_X;
488 break;
489 case ARM_BREAKPOINT_LOAD:
490 *gen_type = HW_BREAKPOINT_R;
491 break;
492 case ARM_BREAKPOINT_STORE:
493 *gen_type = HW_BREAKPOINT_W;
494 break;
495 case ARM_BREAKPOINT_LOAD | ARM_BREAKPOINT_STORE:
496 *gen_type = HW_BREAKPOINT_RW;
497 break;
498 default:
499 return -EINVAL;
500 }
501
502 /* Len */
503 switch (ctrl.len) {
504 case ARM_BREAKPOINT_LEN_1:
505 *gen_len = HW_BREAKPOINT_LEN_1;
506 break;
507 case ARM_BREAKPOINT_LEN_2:
508 *gen_len = HW_BREAKPOINT_LEN_2;
509 break;
510 case ARM_BREAKPOINT_LEN_4:
511 *gen_len = HW_BREAKPOINT_LEN_4;
512 break;
513 case ARM_BREAKPOINT_LEN_8:
514 *gen_len = HW_BREAKPOINT_LEN_8;
515 break;
516 default:
517 return -EINVAL;
518 }
519
520 return 0;
521}
522
523/*
524 * Construct an arch_hw_breakpoint from a perf_event.
525 */
526static int arch_build_bp_info(struct perf_event *bp)
527{
528 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
529
530 /* Type */
531 switch (bp->attr.bp_type) {
532 case HW_BREAKPOINT_X:
533 info->ctrl.type = ARM_BREAKPOINT_EXECUTE;
534 break;
535 case HW_BREAKPOINT_R:
536 info->ctrl.type = ARM_BREAKPOINT_LOAD;
537 break;
538 case HW_BREAKPOINT_W:
539 info->ctrl.type = ARM_BREAKPOINT_STORE;
540 break;
541 case HW_BREAKPOINT_RW:
542 info->ctrl.type = ARM_BREAKPOINT_LOAD | ARM_BREAKPOINT_STORE;
543 break;
544 default:
545 return -EINVAL;
546 }
547
548 /* Len */
549 switch (bp->attr.bp_len) {
550 case HW_BREAKPOINT_LEN_1:
551 info->ctrl.len = ARM_BREAKPOINT_LEN_1;
552 break;
553 case HW_BREAKPOINT_LEN_2:
554 info->ctrl.len = ARM_BREAKPOINT_LEN_2;
555 break;
556 case HW_BREAKPOINT_LEN_4:
557 info->ctrl.len = ARM_BREAKPOINT_LEN_4;
558 break;
559 case HW_BREAKPOINT_LEN_8:
560 info->ctrl.len = ARM_BREAKPOINT_LEN_8;
561 if ((info->ctrl.type != ARM_BREAKPOINT_EXECUTE)
562 && max_watchpoint_len >= 8)
563 break;
564 default:
565 return -EINVAL;
566 }
567
Will Deacon6ee33c272010-11-25 12:01:54 +0000568 /*
569 * Breakpoints must be of length 2 (thumb) or 4 (ARM) bytes.
570 * Watchpoints can be of length 1, 2, 4 or 8 bytes if supported
571 * by the hardware and must be aligned to the appropriate number of
572 * bytes.
573 */
574 if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE &&
575 info->ctrl.len != ARM_BREAKPOINT_LEN_2 &&
576 info->ctrl.len != ARM_BREAKPOINT_LEN_4)
577 return -EINVAL;
578
Will Deaconf81ef4a2010-09-03 10:41:08 +0100579 /* Address */
580 info->address = bp->attr.bp_addr;
581
582 /* Privilege */
583 info->ctrl.privilege = ARM_BREAKPOINT_USER;
Will Deacon93a04a32010-11-29 16:56:01 +0000584 if (arch_check_bp_in_kernelspace(bp))
Will Deaconf81ef4a2010-09-03 10:41:08 +0100585 info->ctrl.privilege |= ARM_BREAKPOINT_PRIV;
586
587 /* Enabled? */
588 info->ctrl.enabled = !bp->attr.disabled;
589
590 /* Mismatch */
591 info->ctrl.mismatch = 0;
592
593 return 0;
594}
595
596/*
597 * Validate the arch-specific HW Breakpoint register settings.
598 */
599int arch_validate_hwbkpt_settings(struct perf_event *bp)
600{
601 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
602 int ret = 0;
Will Deacon6ee33c272010-11-25 12:01:54 +0000603 u32 offset, alignment_mask = 0x3;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100604
605 /* Build the arch_hw_breakpoint. */
606 ret = arch_build_bp_info(bp);
607 if (ret)
608 goto out;
609
610 /* Check address alignment. */
611 if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
612 alignment_mask = 0x7;
Will Deacon6ee33c272010-11-25 12:01:54 +0000613 offset = info->address & alignment_mask;
614 switch (offset) {
615 case 0:
616 /* Aligned */
617 break;
618 case 1:
619 /* Allow single byte watchpoint. */
620 if (info->ctrl.len == ARM_BREAKPOINT_LEN_1)
621 break;
622 case 2:
623 /* Allow halfword watchpoints and breakpoints. */
624 if (info->ctrl.len == ARM_BREAKPOINT_LEN_2)
625 break;
626 default:
627 ret = -EINVAL;
628 goto out;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100629 }
630
Will Deacon6ee33c272010-11-25 12:01:54 +0000631 info->address &= ~alignment_mask;
632 info->ctrl.len <<= offset;
633
Will Deaconf81ef4a2010-09-03 10:41:08 +0100634 /*
635 * Currently we rely on an overflow handler to take
636 * care of single-stepping the breakpoint when it fires.
637 * In the case of userspace breakpoints on a core with V7 debug,
Will Deacon3ce70b22010-12-01 17:05:24 +0000638 * we can use the mismatch feature as a poor-man's hardware
639 * single-step, but this only works for per-task breakpoints.
Will Deaconf81ef4a2010-09-03 10:41:08 +0100640 */
Will Deacond1244332011-08-04 14:46:23 +0100641 if (!bp->overflow_handler && (arch_check_bp_in_kernelspace(bp) ||
642 !core_has_mismatch_brps() || !bp->hw.bp_target)) {
643 pr_warning("overflow handler required but none found\n");
Will Deaconf81ef4a2010-09-03 10:41:08 +0100644 ret = -EINVAL;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100645 }
646out:
647 return ret;
648}
649
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000650/*
651 * Enable/disable single-stepping over the breakpoint bp at address addr.
652 */
653static void enable_single_step(struct perf_event *bp, u32 addr)
Will Deaconf81ef4a2010-09-03 10:41:08 +0100654{
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000655 struct arch_hw_breakpoint *info = counter_arch_bp(bp);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100656
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000657 arch_uninstall_hw_breakpoint(bp);
658 info->step_ctrl.mismatch = 1;
659 info->step_ctrl.len = ARM_BREAKPOINT_LEN_4;
660 info->step_ctrl.type = ARM_BREAKPOINT_EXECUTE;
661 info->step_ctrl.privilege = info->ctrl.privilege;
662 info->step_ctrl.enabled = 1;
663 info->trigger = addr;
664 arch_install_hw_breakpoint(bp);
665}
Will Deaconf81ef4a2010-09-03 10:41:08 +0100666
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000667static void disable_single_step(struct perf_event *bp)
668{
669 arch_uninstall_hw_breakpoint(bp);
670 counter_arch_bp(bp)->step_ctrl.enabled = 0;
671 arch_install_hw_breakpoint(bp);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100672}
673
Will Deacon6f26aa02011-08-02 16:16:57 +0100674static void watchpoint_handler(unsigned long addr, unsigned int fsr,
675 struct pt_regs *regs)
Will Deaconf81ef4a2010-09-03 10:41:08 +0100676{
Will Deacon6f26aa02011-08-02 16:16:57 +0100677 int i, access;
678 u32 val, ctrl_reg, alignment_mask;
Will Deacon4a55c182010-11-29 17:06:53 +0000679 struct perf_event *wp, **slots;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100680 struct arch_hw_breakpoint *info;
Will Deacon6f26aa02011-08-02 16:16:57 +0100681 struct arch_hw_breakpoint_ctrl ctrl;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100682
Will Deacon4a55c182010-11-29 17:06:53 +0000683 slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
684
Will Deaconf81ef4a2010-09-03 10:41:08 +0100685 for (i = 0; i < core_num_wrps; ++i) {
686 rcu_read_lock();
687
Will Deacon93a04a32010-11-29 16:56:01 +0000688 wp = slots[i];
689
Will Deacon6f26aa02011-08-02 16:16:57 +0100690 if (wp == NULL)
691 goto unlock;
692
693 info = counter_arch_bp(wp);
694 /*
695 * The DFAR is an unknown value on debug architectures prior
696 * to 7.1. Since we only allow a single watchpoint on these
697 * older CPUs, we can set the trigger to the lowest possible
698 * faulting address.
699 */
700 if (debug_arch < ARM_DEBUG_ARCH_V7_1) {
701 BUG_ON(i > 0);
702 info->trigger = wp->attr.bp_addr;
703 } else {
704 if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
705 alignment_mask = 0x7;
706 else
707 alignment_mask = 0x3;
708
709 /* Check if the watchpoint value matches. */
710 val = read_wb_reg(ARM_BASE_WVR + i);
711 if (val != (addr & ~alignment_mask))
712 goto unlock;
713
714 /* Possible match, check the byte address select. */
715 ctrl_reg = read_wb_reg(ARM_BASE_WCR + i);
716 decode_ctrl_reg(ctrl_reg, &ctrl);
717 if (!((1 << (addr & alignment_mask)) & ctrl.len))
718 goto unlock;
719
720 /* Check that the access type matches. */
721 access = (fsr & ARM_FSR_ACCESS_MASK) ? HW_BREAKPOINT_W :
722 HW_BREAKPOINT_R;
723 if (!(access & hw_breakpoint_type(wp)))
724 goto unlock;
725
726 /* We have a winner. */
727 info->trigger = addr;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100728 }
729
Will Deaconf81ef4a2010-09-03 10:41:08 +0100730 pr_debug("watchpoint fired: address = 0x%x\n", info->trigger);
Will Deacon93a04a32010-11-29 16:56:01 +0000731 perf_bp_event(wp, regs);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100732
733 /*
734 * If no overflow handler is present, insert a temporary
735 * mismatch breakpoint so we can single-step over the
736 * watchpoint trigger.
737 */
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000738 if (!wp->overflow_handler)
739 enable_single_step(wp, instruction_pointer(regs));
Will Deaconf81ef4a2010-09-03 10:41:08 +0100740
Will Deacon6f26aa02011-08-02 16:16:57 +0100741unlock:
Will Deaconf81ef4a2010-09-03 10:41:08 +0100742 rcu_read_unlock();
743 }
744}
745
Will Deacon93a04a32010-11-29 16:56:01 +0000746static void watchpoint_single_step_handler(unsigned long pc)
747{
748 int i;
Will Deacon4a55c182010-11-29 17:06:53 +0000749 struct perf_event *wp, **slots;
Will Deacon93a04a32010-11-29 16:56:01 +0000750 struct arch_hw_breakpoint *info;
751
Will Deacon4a55c182010-11-29 17:06:53 +0000752 slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
753
Will Deaconc512de92011-08-02 13:01:17 +0100754 for (i = 0; i < core_num_wrps; ++i) {
Will Deacon93a04a32010-11-29 16:56:01 +0000755 rcu_read_lock();
756
757 wp = slots[i];
758
759 if (wp == NULL)
760 goto unlock;
761
762 info = counter_arch_bp(wp);
763 if (!info->step_ctrl.enabled)
764 goto unlock;
765
766 /*
767 * Restore the original watchpoint if we've completed the
768 * single-step.
769 */
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000770 if (info->trigger != pc)
771 disable_single_step(wp);
Will Deacon93a04a32010-11-29 16:56:01 +0000772
773unlock:
774 rcu_read_unlock();
775 }
776}
777
Will Deaconf81ef4a2010-09-03 10:41:08 +0100778static void breakpoint_handler(unsigned long unknown, struct pt_regs *regs)
779{
780 int i;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100781 u32 ctrl_reg, val, addr;
Will Deacon4a55c182010-11-29 17:06:53 +0000782 struct perf_event *bp, **slots;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100783 struct arch_hw_breakpoint *info;
784 struct arch_hw_breakpoint_ctrl ctrl;
785
Will Deacon4a55c182010-11-29 17:06:53 +0000786 slots = (struct perf_event **)__get_cpu_var(bp_on_reg);
787
Will Deaconf81ef4a2010-09-03 10:41:08 +0100788 /* The exception entry code places the amended lr in the PC. */
789 addr = regs->ARM_pc;
790
Will Deacon93a04a32010-11-29 16:56:01 +0000791 /* Check the currently installed breakpoints first. */
792 for (i = 0; i < core_num_brps; ++i) {
Will Deaconf81ef4a2010-09-03 10:41:08 +0100793 rcu_read_lock();
794
795 bp = slots[i];
796
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000797 if (bp == NULL)
798 goto unlock;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100799
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000800 info = counter_arch_bp(bp);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100801
802 /* Check if the breakpoint value matches. */
803 val = read_wb_reg(ARM_BASE_BVR + i);
804 if (val != (addr & ~0x3))
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000805 goto mismatch;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100806
807 /* Possible match, check the byte address select to confirm. */
808 ctrl_reg = read_wb_reg(ARM_BASE_BCR + i);
809 decode_ctrl_reg(ctrl_reg, &ctrl);
810 if ((1 << (addr & 0x3)) & ctrl.len) {
Will Deaconf81ef4a2010-09-03 10:41:08 +0100811 info->trigger = addr;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100812 pr_debug("breakpoint fired: address = 0x%x\n", addr);
813 perf_bp_event(bp, regs);
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000814 if (!bp->overflow_handler)
815 enable_single_step(bp, addr);
816 goto unlock;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100817 }
818
Will Deacon9ebb3cb2010-12-01 14:12:13 +0000819mismatch:
820 /* If we're stepping a breakpoint, it can now be restored. */
821 if (info->step_ctrl.enabled)
822 disable_single_step(bp);
823unlock:
Will Deaconf81ef4a2010-09-03 10:41:08 +0100824 rcu_read_unlock();
825 }
Will Deacon93a04a32010-11-29 16:56:01 +0000826
827 /* Handle any pending watchpoint single-step breakpoints. */
828 watchpoint_single_step_handler(addr);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100829}
830
831/*
832 * Called from either the Data Abort Handler [watchpoint] or the
Russell King02fe2842011-06-25 11:44:06 +0100833 * Prefetch Abort Handler [breakpoint] with interrupts disabled.
Will Deaconf81ef4a2010-09-03 10:41:08 +0100834 */
835static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
836 struct pt_regs *regs)
837{
Will Deacon7e202692010-11-28 14:57:24 +0000838 int ret = 0;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100839 u32 dscr;
840
Russell King02fe2842011-06-25 11:44:06 +0100841 preempt_disable();
842
843 if (interrupts_enabled(regs))
844 local_irq_enable();
Will Deacon7e202692010-11-28 14:57:24 +0000845
Will Deaconf81ef4a2010-09-03 10:41:08 +0100846 /* We only handle watchpoints and hardware breakpoints. */
847 ARM_DBG_READ(c1, 0, dscr);
848
849 /* Perform perf callbacks. */
850 switch (ARM_DSCR_MOE(dscr)) {
851 case ARM_ENTRY_BREAKPOINT:
852 breakpoint_handler(addr, regs);
853 break;
854 case ARM_ENTRY_ASYNC_WATCHPOINT:
Joe Perches235584b2010-10-30 14:21:24 -0700855 WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
Will Deaconf81ef4a2010-09-03 10:41:08 +0100856 case ARM_ENTRY_SYNC_WATCHPOINT:
Will Deacon6f26aa02011-08-02 16:16:57 +0100857 watchpoint_handler(addr, fsr, regs);
Will Deaconf81ef4a2010-09-03 10:41:08 +0100858 break;
859 default:
Will Deacon7e202692010-11-28 14:57:24 +0000860 ret = 1; /* Unhandled fault. */
Will Deaconf81ef4a2010-09-03 10:41:08 +0100861 }
862
Will Deacon7e202692010-11-28 14:57:24 +0000863 preempt_enable();
864
Will Deaconf81ef4a2010-09-03 10:41:08 +0100865 return ret;
866}
867
868/*
869 * One-time initialisation.
870 */
Will Deacon0d352e32011-08-08 14:26:53 +0100871static cpumask_t debug_err_mask;
872
873static int debug_reg_trap(struct pt_regs *regs, unsigned int instr)
874{
875 int cpu = smp_processor_id();
876
877 pr_warning("Debug register access (0x%x) caused undefined instruction on CPU %d\n",
878 instr, cpu);
879
880 /* Set the error flag for this CPU and skip the faulting instruction. */
881 cpumask_set_cpu(cpu, &debug_err_mask);
882 instruction_pointer(regs) += 4;
883 return 0;
884}
885
886static struct undef_hook debug_reg_hook = {
887 .instr_mask = 0x0fe80f10,
888 .instr_val = 0x0e000e10,
889 .fn = debug_reg_trap,
890};
891
892static void reset_ctrl_regs(void *unused)
Will Deaconf81ef4a2010-09-03 10:41:08 +0100893{
Jin Hong8ec53752012-09-10 09:37:25 -0700894 int i, raw_num_brps, err = 0, cpu = smp_processor_id();
Will Deaconc09bae72011-02-25 20:20:42 +0100895 u32 dbg_power;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100896
Will Deaconac88e072010-11-24 16:51:17 +0000897 /*
898 * v7 debug contains save and restore registers so that debug state
Will Deaconed19b732011-02-11 15:55:12 +0100899 * can be maintained across low-power modes without leaving the debug
900 * logic powered up. It is IMPLEMENTATION DEFINED whether we can access
901 * the debug registers out of reset, so we must unlock the OS Lock
902 * Access Register to avoid taking undefined instruction exceptions
903 * later on.
Will Deaconac88e072010-11-24 16:51:17 +0000904 */
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100905 switch (debug_arch) {
Will Deacona26bce12011-10-07 15:57:55 +0100906 case ARM_DEBUG_ARCH_V6:
907 case ARM_DEBUG_ARCH_V6_1:
908 /* ARMv6 cores just need to reset the registers. */
909 goto reset_regs;
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100910 case ARM_DEBUG_ARCH_V7_ECP14:
Will Deaconac88e072010-11-24 16:51:17 +0000911 /*
Will Deaconc09bae72011-02-25 20:20:42 +0100912 * Ensure sticky power-down is clear (i.e. debug logic is
913 * powered up).
914 */
915 asm volatile("mrc p14, 0, %0, c1, c5, 4" : "=r" (dbg_power));
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100916 if ((dbg_power & 0x1) == 0)
917 err = -EPERM;
918 break;
919 case ARM_DEBUG_ARCH_V7_1:
Will Deaconc09bae72011-02-25 20:20:42 +0100920 /*
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100921 * Ensure the OS double lock is clear.
Will Deaconac88e072010-11-24 16:51:17 +0000922 */
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100923 asm volatile("mrc p14, 0, %0, c1, c3, 4" : "=r" (dbg_power));
924 if ((dbg_power & 0x1) == 1)
925 err = -EPERM;
926 break;
Will Deaconac88e072010-11-24 16:51:17 +0000927 }
928
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100929 if (err) {
930 pr_warning("CPU %d debug is powered down!\n", cpu);
Will Deacon0d352e32011-08-08 14:26:53 +0100931 cpumask_or(&debug_err_mask, &debug_err_mask, cpumask_of(cpu));
Will Deaconb5d5b8f2011-07-22 18:27:37 +0100932 return;
933 }
934
935 /*
936 * Unconditionally clear the lock by writing a value
937 * other than 0xC5ACCE55 to the access register.
938 */
939 asm volatile("mcr p14, 0, %0, c1, c0, 4" : : "r" (0));
940 isb();
941
942 /*
943 * Clear any configured vector-catch events before
944 * enabling monitor mode.
945 */
946 asm volatile("mcr p14, 0, %0, c0, c7, 0" : : "r" (0));
947 isb();
948
Will Deacona26bce12011-10-07 15:57:55 +0100949reset_regs:
Stephen Boyd5607d222012-09-18 20:23:13 -0700950 if (halting_mode_enabled())
Will Deaconf81ef4a2010-09-03 10:41:08 +0100951 return;
952
Jin Hong8ec53752012-09-10 09:37:25 -0700953 /* We must also reset any reserved registers. */
954 raw_num_brps = get_num_brp_resources();
955 for (i = 0; i < raw_num_brps; ++i) {
956 write_wb_reg(ARM_BASE_BCR + i, 0UL);
957 write_wb_reg(ARM_BASE_BVR + i, 0UL);
958 }
Will Deaconf81ef4a2010-09-03 10:41:08 +0100959
960 for (i = 0; i < core_num_wrps; ++i) {
961 write_wb_reg(ARM_BASE_WCR + i, 0UL);
962 write_wb_reg(ARM_BASE_WVR + i, 0UL);
963 }
Stephen Boyd5607d222012-09-18 20:23:13 -0700964 enable_monitor_mode();
Will Deaconf81ef4a2010-09-03 10:41:08 +0100965}
966
Will Deacon7d993312010-11-24 17:45:49 +0000967static int __cpuinit dbg_reset_notify(struct notifier_block *self,
968 unsigned long action, void *cpu)
969{
970 if (action == CPU_ONLINE)
971 smp_call_function_single((int)cpu, reset_ctrl_regs, NULL, 1);
Will Deacon0d352e32011-08-08 14:26:53 +0100972
Will Deacon7d993312010-11-24 17:45:49 +0000973 return NOTIFY_OK;
974}
975
976static struct notifier_block __cpuinitdata dbg_reset_nb = {
977 .notifier_call = dbg_reset_notify,
978};
979
Will Deaconf81ef4a2010-09-03 10:41:08 +0100980static int __init arch_hw_breakpoint_init(void)
981{
Will Deaconf81ef4a2010-09-03 10:41:08 +0100982 u32 dscr;
983
984 debug_arch = get_debug_arch();
985
Will Deacon66e1cfe2011-02-11 16:01:42 +0100986 if (!debug_arch_supported()) {
Will Deaconf81ef4a2010-09-03 10:41:08 +0100987 pr_info("debug architecture 0x%x unsupported.\n", debug_arch);
Will Deacon8fbf3972010-12-01 17:37:45 +0000988 return 0;
Will Deaconf81ef4a2010-09-03 10:41:08 +0100989 }
990
991 /* Determine how many BRPs/WRPs are available. */
992 core_num_brps = get_num_brps();
993 core_num_wrps = get_num_wrps();
994
Will Deacon0d352e32011-08-08 14:26:53 +0100995 /*
996 * We need to tread carefully here because DBGSWENABLE may be
997 * driven low on this core and there isn't an architected way to
998 * determine that.
999 */
1000 register_undef_hook(&debug_reg_hook);
Will Deaconf81ef4a2010-09-03 10:41:08 +01001001
Will Deaconed19b732011-02-11 15:55:12 +01001002 /*
1003 * Reset the breakpoint resources. We assume that a halting
1004 * debugger will leave the world in a nice state for us.
1005 */
Will Deacon0d352e32011-08-08 14:26:53 +01001006 on_each_cpu(reset_ctrl_regs, NULL, 1);
1007 unregister_undef_hook(&debug_reg_hook);
1008 if (!cpumask_empty(&debug_err_mask)) {
Will Deaconc09bae72011-02-25 20:20:42 +01001009 core_num_brps = 0;
Will Deaconc09bae72011-02-25 20:20:42 +01001010 core_num_wrps = 0;
1011 return 0;
1012 }
Will Deaconed19b732011-02-11 15:55:12 +01001013
Will Deacon0d352e32011-08-08 14:26:53 +01001014 pr_info("found %d " "%s" "breakpoint and %d watchpoint registers.\n",
1015 core_num_brps, core_has_mismatch_brps() ? "(+1 reserved) " :
1016 "", core_num_wrps);
1017
Will Deaconf81ef4a2010-09-03 10:41:08 +01001018 ARM_DBG_READ(c1, 0, dscr);
1019 if (dscr & ARM_DSCR_HDBGEN) {
Will Deaconed19b732011-02-11 15:55:12 +01001020 max_watchpoint_len = 4;
Stephen Boyd7d85d612011-03-10 05:15:00 +01001021 pr_warning("halting debug mode enabled. Assuming maximum watchpoint size of %u bytes.\n",
1022 max_watchpoint_len);
Will Deaconf81ef4a2010-09-03 10:41:08 +01001023 } else {
Will Deaconac88e072010-11-24 16:51:17 +00001024 /* Work out the maximum supported watchpoint length. */
1025 max_watchpoint_len = get_max_wp_len();
1026 pr_info("maximum watchpoint size is %u bytes.\n",
1027 max_watchpoint_len);
Will Deaconf81ef4a2010-09-03 10:41:08 +01001028 }
1029
1030 /* Register debug fault handler. */
Catalin Marinasf7b81562011-11-22 17:30:31 +00001031 hook_fault_code(FAULT_CODE_DEBUG, hw_breakpoint_pending, SIGTRAP,
1032 TRAP_HWBKPT, "watchpoint debug exception");
1033 hook_ifault_code(FAULT_CODE_DEBUG, hw_breakpoint_pending, SIGTRAP,
1034 TRAP_HWBKPT, "breakpoint debug exception");
Will Deaconf81ef4a2010-09-03 10:41:08 +01001035
Will Deacon7d993312010-11-24 17:45:49 +00001036 /* Register hotplug notifier. */
1037 register_cpu_notifier(&dbg_reset_nb);
Will Deacon8fbf3972010-12-01 17:37:45 +00001038 return 0;
Will Deaconf81ef4a2010-09-03 10:41:08 +01001039}
1040arch_initcall(arch_hw_breakpoint_init);
1041
1042void hw_breakpoint_pmu_read(struct perf_event *bp)
1043{
1044}
1045
1046/*
1047 * Dummy function to register with die_notifier.
1048 */
1049int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
1050 unsigned long val, void *data)
1051{
1052 return NOTIFY_DONE;
1053}