Commit 8fbf397c authored by Will Deacon's avatar Will Deacon

ARM: hw_breakpoint: do not fail initcall if monitor mode is disabled

The debug registers can only be manipulated from software if monitor
debug mode is enabled. On some cores, this can never be enabled (i.e.
the corresponding bit in the DSCR is RAZ/WI).

This patch ensures we can handle this hardware configuration and fail
gracefully, rather than blow up the kernel during boot.
Reported-by: default avatarCyril Chemparathy <cyril@ti.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 4a55c18e
...@@ -219,23 +219,6 @@ static int get_num_brps(void) ...@@ -219,23 +219,6 @@ static int get_num_brps(void)
return brps; return brps;
} }
int hw_breakpoint_slots(int type)
{
/*
* We can be called early, so don't rely on
* our static variables being initialised.
*/
switch (type) {
case TYPE_INST:
return get_num_brps();
case TYPE_DATA:
return get_num_wrps();
default:
pr_warning("unknown slot type: %d\n", type);
return 0;
}
}
/* /*
* In order to access the breakpoint/watchpoint control registers, * In order to access the breakpoint/watchpoint control registers,
* we must be running in debug monitor mode. Unfortunately, we can * we must be running in debug monitor mode. Unfortunately, we can
...@@ -256,8 +239,12 @@ static int enable_monitor_mode(void) ...@@ -256,8 +239,12 @@ static int enable_monitor_mode(void)
goto out; goto out;
} }
/* If monitor mode is already enabled, just return. */
if (dscr & ARM_DSCR_MDBGEN)
goto out;
/* Write to the corresponding DSCR. */ /* Write to the corresponding DSCR. */
switch (debug_arch) { switch (get_debug_arch()) {
case ARM_DEBUG_ARCH_V6: case ARM_DEBUG_ARCH_V6:
case ARM_DEBUG_ARCH_V6_1: case ARM_DEBUG_ARCH_V6_1:
ARM_DBG_WRITE(c1, 0, (dscr | ARM_DSCR_MDBGEN)); ARM_DBG_WRITE(c1, 0, (dscr | ARM_DSCR_MDBGEN));
...@@ -272,15 +259,30 @@ static int enable_monitor_mode(void) ...@@ -272,15 +259,30 @@ static int enable_monitor_mode(void)
/* Check that the write made it through. */ /* Check that the write made it through. */
ARM_DBG_READ(c1, 0, dscr); ARM_DBG_READ(c1, 0, dscr);
if (WARN_ONCE(!(dscr & ARM_DSCR_MDBGEN), if (!(dscr & ARM_DSCR_MDBGEN))
"failed to enable monitor mode.")) {
ret = -EPERM; ret = -EPERM;
}
out: out:
return ret; return ret;
} }
int hw_breakpoint_slots(int type)
{
/*
* We can be called early, so don't rely on
* our static variables being initialised.
*/
switch (type) {
case TYPE_INST:
return get_num_brps();
case TYPE_DATA:
return get_num_wrps();
default:
pr_warning("unknown slot type: %d\n", type);
return 0;
}
}
/* /*
* Check if 8-bit byte-address select is available. * Check if 8-bit byte-address select is available.
* This clobbers WRP 0. * This clobbers WRP 0.
...@@ -294,9 +296,6 @@ static u8 get_max_wp_len(void) ...@@ -294,9 +296,6 @@ static u8 get_max_wp_len(void)
if (debug_arch < ARM_DEBUG_ARCH_V7_ECP14) if (debug_arch < ARM_DEBUG_ARCH_V7_ECP14)
goto out; goto out;
if (enable_monitor_mode())
goto out;
memset(&ctrl, 0, sizeof(ctrl)); memset(&ctrl, 0, sizeof(ctrl));
ctrl.len = ARM_BREAKPOINT_LEN_8; ctrl.len = ARM_BREAKPOINT_LEN_8;
ctrl_reg = encode_ctrl_reg(ctrl); ctrl_reg = encode_ctrl_reg(ctrl);
...@@ -879,15 +878,13 @@ static struct notifier_block __cpuinitdata dbg_reset_nb = { ...@@ -879,15 +878,13 @@ static struct notifier_block __cpuinitdata dbg_reset_nb = {
static int __init arch_hw_breakpoint_init(void) static int __init arch_hw_breakpoint_init(void)
{ {
int ret = 0;
u32 dscr; u32 dscr;
debug_arch = get_debug_arch(); debug_arch = get_debug_arch();
if (debug_arch > ARM_DEBUG_ARCH_V7_ECP14) { if (debug_arch > ARM_DEBUG_ARCH_V7_ECP14) {
pr_info("debug architecture 0x%x unsupported.\n", debug_arch); pr_info("debug architecture 0x%x unsupported.\n", debug_arch);
ret = -ENODEV; return 0;
goto out;
} }
/* Determine how many BRPs/WRPs are available. */ /* Determine how many BRPs/WRPs are available. */
...@@ -928,8 +925,7 @@ static int __init arch_hw_breakpoint_init(void) ...@@ -928,8 +925,7 @@ static int __init arch_hw_breakpoint_init(void)
/* Register hotplug notifier. */ /* Register hotplug notifier. */
register_cpu_notifier(&dbg_reset_nb); register_cpu_notifier(&dbg_reset_nb);
out: return 0;
return ret;
} }
arch_initcall(arch_hw_breakpoint_init); arch_initcall(arch_hw_breakpoint_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment