139
138
/* Do we implement the extended CPUID interface? */
140
if (WARN_ONCE((((read_cpuid_id() >> 16) & 0xf) != 0xf),
141
"CPUID feature registers not supported. "
142
"Assuming v6 debug is present.\n"))
139
if (((read_cpuid_id() >> 16) & 0xf) != 0xf) {
140
pr_warning("CPUID feature registers not supported. "
141
"Assuming v6 debug is present.\n");
143
142
return ARM_DEBUG_ARCH_V6;
145
145
ARM_DBG_READ(c0, 0, didr);
146
146
return (didr >> 16) & 0xf;
154
154
static int debug_arch_supported(void)
156
156
u8 arch = get_debug_arch();
157
return arch >= ARM_DEBUG_ARCH_V6 && arch <= ARM_DEBUG_ARCH_V7_ECP14;
160
/* Determine number of BRP register available. */
158
/* We don't support the memory-mapped interface. */
159
return (arch >= ARM_DEBUG_ARCH_V6 && arch <= ARM_DEBUG_ARCH_V7_ECP14) ||
160
arch >= ARM_DEBUG_ARCH_V7_1;
163
/* Determine number of WRP registers available. */
164
static int get_num_wrp_resources(void)
167
ARM_DBG_READ(c0, 0, didr);
168
return ((didr >> 28) & 0xf) + 1;
171
/* Determine number of BRP registers available. */
161
172
static int get_num_brp_resources(void)
176
187
static int get_num_wrps(void)
179
* FIXME: When a watchpoint fires, the only way to work out which
180
* watchpoint it was is by disassembling the faulting instruction
181
* and working out the address of the memory access.
190
* On debug architectures prior to 7.1, when a watchpoint fires, the
191
* only way to work out which watchpoint it was is by disassembling
192
* the faulting instruction and working out the address of the memory
183
195
* Furthermore, we can only do this if the watchpoint was precise
184
196
* since imprecise watchpoints prevent us from calculating register
192
204
* [the ARM ARM states that the DFAR is UNKNOWN, but experience shows
193
205
* that it is set on some implementations].
199
ARM_DBG_READ(c0, 0, didr);
200
wrps = ((didr >> 28) & 0xf) + 1;
204
if (core_has_mismatch_brps() && wrps >= get_num_brp_resources())
205
wrps = get_num_brp_resources() - 1;
210
/* We reserve one breakpoint for each watchpoint. */
211
static int get_num_reserved_brps(void)
213
if (core_has_mismatch_brps())
214
return get_num_wrps();
207
if (get_debug_arch() < ARM_DEBUG_ARCH_V7_1)
210
return get_num_wrp_resources();
218
213
/* Determine number of usable BRPs available. */
219
214
static int get_num_brps(void)
221
216
int brps = get_num_brp_resources();
222
if (core_has_mismatch_brps())
223
brps -= get_num_reserved_brps();
217
return core_has_mismatch_brps() ? brps - 1 : brps;
346
340
val_base = ARM_BASE_BVR;
347
341
slots = (struct perf_event **)__get_cpu_var(bp_on_reg);
348
342
max_slots = core_num_brps;
349
if (info->step_ctrl.enabled) {
350
/* Override the breakpoint data with the step data. */
351
addr = info->trigger & ~0x3;
352
ctrl = encode_ctrl_reg(info->step_ctrl);
356
if (info->step_ctrl.enabled) {
357
/* Install into the reserved breakpoint region. */
358
ctrl_base = ARM_BASE_BCR + core_num_brps;
359
val_base = ARM_BASE_BVR + core_num_brps;
360
/* Override the watchpoint data with the step data. */
361
addr = info->trigger & ~0x3;
362
ctrl = encode_ctrl_reg(info->step_ctrl);
364
ctrl_base = ARM_BASE_WCR;
365
val_base = ARM_BASE_WVR;
345
ctrl_base = ARM_BASE_WCR;
346
val_base = ARM_BASE_WVR;
367
347
slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
368
348
max_slots = core_num_wrps;
365
/* Override the breakpoint data with the step data. */
366
if (info->step_ctrl.enabled) {
367
addr = info->trigger & ~0x3;
368
ctrl = encode_ctrl_reg(info->step_ctrl);
369
if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE) {
371
ctrl_base = ARM_BASE_BCR + core_num_brps;
372
val_base = ARM_BASE_BVR + core_num_brps;
385
376
/* Setup the address register. */
386
377
write_wb_reg(val_base + i, addr);
426
414
if (WARN_ONCE(i == max_slots, "Can't find any breakpoint slot\n"))
417
/* Ensure that we disable the mismatch breakpoint. */
418
if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE &&
419
info->step_ctrl.enabled) {
421
base = ARM_BASE_BCR + core_num_brps;
429
424
/* Reset the control register. */
430
425
write_wb_reg(base + i, 0);
632
627
* we can use the mismatch feature as a poor-man's hardware
633
628
* single-step, but this only works for per-task breakpoints.
635
if (WARN_ONCE(!bp->overflow_handler &&
636
(arch_check_bp_in_kernelspace(bp) || !core_has_mismatch_brps()
637
|| !bp->hw.bp_target),
638
"overflow handler required but none found\n")) {
630
if (!bp->overflow_handler && (arch_check_bp_in_kernelspace(bp) ||
631
!core_has_mismatch_brps() || !bp->hw.bp_target)) {
632
pr_warning("overflow handler required but none found\n");
666
660
arch_install_hw_breakpoint(bp);
669
static void watchpoint_handler(unsigned long unknown, struct pt_regs *regs)
663
static void watchpoint_handler(unsigned long addr, unsigned int fsr,
664
struct pt_regs *regs)
667
u32 val, ctrl_reg, alignment_mask;
672
668
struct perf_event *wp, **slots;
673
669
struct arch_hw_breakpoint *info;
670
struct arch_hw_breakpoint_ctrl ctrl;
675
672
slots = (struct perf_event **)__get_cpu_var(wp_on_reg);
677
/* Without a disassembler, we can only handle 1 watchpoint. */
678
BUG_ON(core_num_wrps > 1);
680
674
for (i = 0; i < core_num_wrps; ++i) {
682
info = counter_arch_bp(wp);
691
* The DFAR is an unknown value. Since we only allow a
692
* single watchpoint, we can set the trigger to the lowest
693
* possible faulting address.
684
* The DFAR is an unknown value on debug architectures prior
685
* to 7.1. Since we only allow a single watchpoint on these
686
* older CPUs, we can set the trigger to the lowest possible
695
info = counter_arch_bp(wp);
696
info->trigger = wp->attr.bp_addr;
689
if (debug_arch < ARM_DEBUG_ARCH_V7_1) {
691
info->trigger = wp->attr.bp_addr;
693
if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
694
alignment_mask = 0x7;
696
alignment_mask = 0x3;
698
/* Check if the watchpoint value matches. */
699
val = read_wb_reg(ARM_BASE_WVR + i);
700
if (val != (addr & ~alignment_mask))
703
/* Possible match, check the byte address select. */
704
ctrl_reg = read_wb_reg(ARM_BASE_WCR + i);
705
decode_ctrl_reg(ctrl_reg, &ctrl);
706
if (!((1 << (addr & alignment_mask)) & ctrl.len))
709
/* Check that the access type matches. */
710
access = (fsr & ARM_FSR_ACCESS_MASK) ? HW_BREAKPOINT_W :
712
if (!(access & hw_breakpoint_type(wp)))
715
/* We have a winner. */
716
info->trigger = addr;
697
719
pr_debug("watchpoint fired: address = 0x%x\n", info->trigger);
698
720
perf_bp_event(wp, regs);
818
843
case ARM_ENTRY_ASYNC_WATCHPOINT:
819
844
WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
820
845
case ARM_ENTRY_SYNC_WATCHPOINT:
821
watchpoint_handler(addr, regs);
846
watchpoint_handler(addr, fsr, regs);
824
849
ret = 1; /* Unhandled fault. */
828
* Re-enable preemption after it was disabled in the
829
* low-level exception handling code.
831
852
preempt_enable();
837
858
* One-time initialisation.
839
static void reset_ctrl_regs(void *info)
841
int i, cpu = smp_processor_id();
860
static cpumask_t debug_err_mask;
862
static int debug_reg_trap(struct pt_regs *regs, unsigned int instr)
864
int cpu = smp_processor_id();
866
pr_warning("Debug register access (0x%x) caused undefined instruction on CPU %d\n",
869
/* Set the error flag for this CPU and skip the faulting instruction. */
870
cpumask_set_cpu(cpu, &debug_err_mask);
871
instruction_pointer(regs) += 4;
875
static struct undef_hook debug_reg_hook = {
876
.instr_mask = 0x0fe80f10,
877
.instr_val = 0x0e000e10,
878
.fn = debug_reg_trap,
881
static void reset_ctrl_regs(void *unused)
883
int i, raw_num_brps, err = 0, cpu = smp_processor_id();
843
cpumask_t *cpumask = info;
846
887
* v7 debug contains save and restore registers so that debug state
850
891
* Access Register to avoid taking undefined instruction exceptions
853
if (debug_arch >= ARM_DEBUG_ARCH_V7_ECP14) {
894
switch (debug_arch) {
895
case ARM_DEBUG_ARCH_V6:
896
case ARM_DEBUG_ARCH_V6_1:
897
/* ARMv6 cores just need to reset the registers. */
899
case ARM_DEBUG_ARCH_V7_ECP14:
855
901
* Ensure sticky power-down is clear (i.e. debug logic is
858
904
asm volatile("mrc p14, 0, %0, c1, c5, 4" : "=r" (dbg_power));
859
if ((dbg_power & 0x1) == 0) {
860
pr_warning("CPU %d debug is powered down!\n", cpu);
861
cpumask_or(cpumask, cpumask, cpumask_of(cpu));
866
* Unconditionally clear the lock by writing a value
867
* other than 0xC5ACCE55 to the access register.
869
asm volatile("mcr p14, 0, %0, c1, c0, 4" : : "r" (0));
873
* Clear any configured vector-catch events before
874
* enabling monitor mode.
876
asm volatile("mcr p14, 0, %0, c0, c7, 0" : : "r" (0));
905
if ((dbg_power & 0x1) == 0)
908
case ARM_DEBUG_ARCH_V7_1:
910
* Ensure the OS double lock is clear.
912
asm volatile("mrc p14, 0, %0, c1, c3, 4" : "=r" (dbg_power));
913
if ((dbg_power & 0x1) == 1)
919
pr_warning("CPU %d debug is powered down!\n", cpu);
920
cpumask_or(&debug_err_mask, &debug_err_mask, cpumask_of(cpu));
925
* Unconditionally clear the lock by writing a value
926
* other than 0xC5ACCE55 to the access register.
928
asm volatile("mcr p14, 0, %0, c1, c0, 4" : : "r" (0));
932
* Clear any configured vector-catch events before
933
* enabling monitor mode.
935
asm volatile("mcr p14, 0, %0, c0, c7, 0" : : "r" (0));
880
939
if (enable_monitor_mode())
883
942
/* We must also reset any reserved registers. */
884
for (i = 0; i < core_num_brps + core_num_reserved_brps; ++i) {
943
raw_num_brps = get_num_brp_resources();
944
for (i = 0; i < raw_num_brps; ++i) {
885
945
write_wb_reg(ARM_BASE_BCR + i, 0UL);
886
946
write_wb_reg(ARM_BASE_BVR + i, 0UL);
919
979
/* Determine how many BRPs/WRPs are available. */
920
980
core_num_brps = get_num_brps();
921
core_num_reserved_brps = get_num_reserved_brps();
922
981
core_num_wrps = get_num_wrps();
924
pr_info("found %d breakpoint and %d watchpoint registers.\n",
925
core_num_brps + core_num_reserved_brps, core_num_wrps);
927
if (core_num_reserved_brps)
928
pr_info("%d breakpoint(s) reserved for watchpoint "
929
"single-step.\n", core_num_reserved_brps);
984
* We need to tread carefully here because DBGSWENABLE may be
985
* driven low on this core and there isn't an architected way to
988
register_undef_hook(&debug_reg_hook);
932
991
* Reset the breakpoint resources. We assume that a halting
933
992
* debugger will leave the world in a nice state for us.
935
on_each_cpu(reset_ctrl_regs, &cpumask, 1);
936
if (!cpumask_empty(&cpumask)) {
994
on_each_cpu(reset_ctrl_regs, NULL, 1);
995
unregister_undef_hook(&debug_reg_hook);
996
if (!cpumask_empty(&debug_err_mask)) {
937
997
core_num_brps = 0;
938
core_num_reserved_brps = 0;
939
998
core_num_wrps = 0;
1002
pr_info("found %d " "%s" "breakpoint and %d watchpoint registers.\n",
1003
core_num_brps, core_has_mismatch_brps() ? "(+1 reserved) " :
943
1006
ARM_DBG_READ(c1, 0, dscr);
944
1007
if (dscr & ARM_DSCR_HDBGEN) {
945
1008
max_watchpoint_len = 4;