2010-09-03 09:41:08 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, 2010 ARM Limited
|
|
|
|
*
|
|
|
|
* Author: Will Deacon <will.deacon@arm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HW_breakpoint: a unified kernel/user-space hardware breakpoint facility,
|
|
|
|
* using the CPU's debug registers.
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "hw-breakpoint: " fmt
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
2010-11-28 14:57:24 +00:00
|
|
|
#include <linux/hardirq.h>
|
2010-09-03 09:41:08 +00:00
|
|
|
#include <linux/perf_event.h>
|
|
|
|
#include <linux/hw_breakpoint.h>
|
|
|
|
#include <linux/smp.h>
|
2012-10-14 21:25:37 +00:00
|
|
|
#include <linux/cpu_pm.h>
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/cputype.h>
|
|
|
|
#include <asm/current.h>
|
|
|
|
#include <asm/hw_breakpoint.h>
|
|
|
|
#include <asm/kdebug.h>
|
|
|
|
#include <asm/traps.h>
|
2012-10-14 19:23:04 +00:00
|
|
|
#include <asm/hardware/coresight.h>
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Breakpoint currently in use for each BRP. */
|
|
|
|
static DEFINE_PER_CPU(struct perf_event *, bp_on_reg[ARM_MAX_BRP]);
|
|
|
|
|
|
|
|
/* Watchpoint currently in use for each WRP. */
|
|
|
|
static DEFINE_PER_CPU(struct perf_event *, wp_on_reg[ARM_MAX_WRP]);
|
|
|
|
|
|
|
|
/* Number of BRP/WRP registers on this CPU. */
|
|
|
|
static int core_num_brps;
|
|
|
|
static int core_num_wrps;
|
|
|
|
|
|
|
|
/* Debug architecture version. */
|
|
|
|
static u8 debug_arch;
|
|
|
|
|
2012-10-14 20:08:14 +00:00
|
|
|
/* Does debug architecture support OS Save and Restore? */
|
|
|
|
static bool has_ossr;
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Maximum supported watchpoint length. */
|
|
|
|
static u8 max_watchpoint_len;
|
|
|
|
|
2012-09-26 16:28:47 +00:00
|
|
|
#define READ_WB_REG_CASE(OP2, M, VAL) \
|
|
|
|
case ((OP2 << 4) + M): \
|
|
|
|
ARM_DBG_READ(c0, c ## M, OP2, VAL); \
|
2010-09-03 09:41:08 +00:00
|
|
|
break
|
|
|
|
|
2012-09-26 16:28:47 +00:00
|
|
|
#define WRITE_WB_REG_CASE(OP2, M, VAL) \
|
|
|
|
case ((OP2 << 4) + M): \
|
|
|
|
ARM_DBG_WRITE(c0, c ## M, OP2, VAL); \
|
2010-09-03 09:41:08 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
#define GEN_READ_WB_REG_CASES(OP2, VAL) \
|
|
|
|
READ_WB_REG_CASE(OP2, 0, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 1, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 2, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 3, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 4, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 5, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 6, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 7, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 8, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 9, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 10, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 11, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 12, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 13, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 14, VAL); \
|
|
|
|
READ_WB_REG_CASE(OP2, 15, VAL)
|
|
|
|
|
|
|
|
#define GEN_WRITE_WB_REG_CASES(OP2, VAL) \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 0, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 1, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 2, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 3, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 4, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 5, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 6, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 7, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 8, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 9, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 10, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 11, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 12, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 13, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 14, VAL); \
|
|
|
|
WRITE_WB_REG_CASE(OP2, 15, VAL)
|
|
|
|
|
|
|
|
static u32 read_wb_reg(int n)
|
|
|
|
{
|
|
|
|
u32 val = 0;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
GEN_READ_WB_REG_CASES(ARM_OP2_BVR, val);
|
|
|
|
GEN_READ_WB_REG_CASES(ARM_OP2_BCR, val);
|
|
|
|
GEN_READ_WB_REG_CASES(ARM_OP2_WVR, val);
|
|
|
|
GEN_READ_WB_REG_CASES(ARM_OP2_WCR, val);
|
|
|
|
default:
|
|
|
|
pr_warning("attempt to read from unknown breakpoint "
|
|
|
|
"register %d\n", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void write_wb_reg(int n, u32 val)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
GEN_WRITE_WB_REG_CASES(ARM_OP2_BVR, val);
|
|
|
|
GEN_WRITE_WB_REG_CASES(ARM_OP2_BCR, val);
|
|
|
|
GEN_WRITE_WB_REG_CASES(ARM_OP2_WVR, val);
|
|
|
|
GEN_WRITE_WB_REG_CASES(ARM_OP2_WCR, val);
|
|
|
|
default:
|
|
|
|
pr_warning("attempt to write to unknown breakpoint "
|
|
|
|
"register %d\n", n);
|
|
|
|
}
|
|
|
|
isb();
|
|
|
|
}
|
|
|
|
|
2010-11-28 15:09:36 +00:00
|
|
|
/* Determine debug architecture. */
|
|
|
|
static u8 get_debug_arch(void)
|
|
|
|
{
|
|
|
|
u32 didr;
|
|
|
|
|
|
|
|
/* Do we implement the extended CPUID interface? */
|
2011-08-04 13:46:23 +00:00
|
|
|
if (((read_cpuid_id() >> 16) & 0xf) != 0xf) {
|
2012-09-21 17:17:24 +00:00
|
|
|
pr_warn_once("CPUID feature registers not supported. "
|
|
|
|
"Assuming v6 debug is present.\n");
|
2010-11-28 15:09:36 +00:00
|
|
|
return ARM_DEBUG_ARCH_V6;
|
2011-08-04 13:46:23 +00:00
|
|
|
}
|
2010-11-28 15:09:36 +00:00
|
|
|
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c0, 0, didr);
|
2010-11-28 15:09:36 +00:00
|
|
|
return (didr >> 16) & 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 arch_get_debug_arch(void)
|
|
|
|
{
|
|
|
|
return debug_arch;
|
|
|
|
}
|
|
|
|
|
2011-02-11 15:01:42 +00:00
|
|
|
static int debug_arch_supported(void)
|
|
|
|
{
|
|
|
|
u8 arch = get_debug_arch();
|
2011-07-22 17:27:37 +00:00
|
|
|
|
|
|
|
/* We don't support the memory-mapped interface. */
|
|
|
|
return (arch >= ARM_DEBUG_ARCH_V6 && arch <= ARM_DEBUG_ARCH_V7_ECP14) ||
|
|
|
|
arch >= ARM_DEBUG_ARCH_V7_1;
|
2011-02-11 15:01:42 +00:00
|
|
|
}
|
|
|
|
|
2012-08-16 17:55:44 +00:00
|
|
|
/* Can we determine the watchpoint access type from the fsr? */
|
|
|
|
static int debug_exception_updates_fsr(void)
|
|
|
|
{
|
2014-01-29 21:01:31 +00:00
|
|
|
return get_debug_arch() >= ARM_DEBUG_ARCH_V8;
|
2012-08-16 17:55:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-02 12:01:17 +00:00
|
|
|
/* Determine number of WRP registers available. */
|
|
|
|
static int get_num_wrp_resources(void)
|
|
|
|
{
|
|
|
|
u32 didr;
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c0, 0, didr);
|
2011-08-02 12:01:17 +00:00
|
|
|
return ((didr >> 28) & 0xf) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine number of BRP registers available. */
|
2010-11-28 15:09:36 +00:00
|
|
|
static int get_num_brp_resources(void)
|
|
|
|
{
|
|
|
|
u32 didr;
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c0, 0, didr);
|
2010-11-28 15:09:36 +00:00
|
|
|
return ((didr >> 24) & 0xf) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Does this core support mismatch breakpoints? */
|
|
|
|
static int core_has_mismatch_brps(void)
|
|
|
|
{
|
|
|
|
return (get_debug_arch() >= ARM_DEBUG_ARCH_V7_ECP14 &&
|
|
|
|
get_num_brp_resources() > 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine number of usable WRPs available. */
|
|
|
|
static int get_num_wrps(void)
|
|
|
|
{
|
|
|
|
/*
|
2011-08-02 12:01:17 +00:00
|
|
|
* On debug architectures prior to 7.1, when a watchpoint fires, the
|
|
|
|
* only way to work out which watchpoint it was is by disassembling
|
|
|
|
* the faulting instruction and working out the address of the memory
|
|
|
|
* access.
|
2010-11-28 15:09:36 +00:00
|
|
|
*
|
|
|
|
* Furthermore, we can only do this if the watchpoint was precise
|
|
|
|
* since imprecise watchpoints prevent us from calculating register
|
|
|
|
* based addresses.
|
|
|
|
*
|
|
|
|
* Providing we have more than 1 breakpoint register, we only report
|
|
|
|
* a single watchpoint register for the time being. This way, we always
|
|
|
|
* know which watchpoint fired. In the future we can either add a
|
|
|
|
* disassembler and address generation emulator, or we can insert a
|
|
|
|
* check to see if the DFAR is set on watchpoint exception entry
|
|
|
|
* [the ARM ARM states that the DFAR is UNKNOWN, but experience shows
|
|
|
|
* that it is set on some implementations].
|
|
|
|
*/
|
2011-08-02 12:01:17 +00:00
|
|
|
if (get_debug_arch() < ARM_DEBUG_ARCH_V7_1)
|
|
|
|
return 1;
|
2010-11-28 15:09:36 +00:00
|
|
|
|
2011-08-02 12:01:17 +00:00
|
|
|
return get_num_wrp_resources();
|
2010-11-28 15:09:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine number of usable BRPs available. */
|
|
|
|
static int get_num_brps(void)
|
|
|
|
{
|
|
|
|
int brps = get_num_brp_resources();
|
2011-08-02 12:01:17 +00:00
|
|
|
return core_has_mismatch_brps() ? brps - 1 : brps;
|
2010-11-28 15:09:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/*
|
|
|
|
* In order to access the breakpoint/watchpoint control registers,
|
|
|
|
* we must be running in debug monitor mode. Unfortunately, we can
|
|
|
|
* be put into halting debug mode at any time by an external debugger
|
|
|
|
* but there is nothing we can do to prevent that.
|
|
|
|
*/
|
2012-09-24 17:01:13 +00:00
|
|
|
static int monitor_mode_enabled(void)
|
|
|
|
{
|
|
|
|
u32 dscr;
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c1, 0, dscr);
|
2012-09-24 17:01:13 +00:00
|
|
|
return !!(dscr & ARM_DSCR_MDBGEN);
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
static int enable_monitor_mode(void)
|
|
|
|
{
|
|
|
|
u32 dscr;
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c1, 0, dscr);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-12-01 17:37:45 +00:00
|
|
|
/* If monitor mode is already enabled, just return. */
|
|
|
|
if (dscr & ARM_DSCR_MDBGEN)
|
|
|
|
goto out;
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Write to the corresponding DSCR. */
|
2010-12-01 17:37:45 +00:00
|
|
|
switch (get_debug_arch()) {
|
2010-09-03 09:41:08 +00:00
|
|
|
case ARM_DEBUG_ARCH_V6:
|
|
|
|
case ARM_DEBUG_ARCH_V6_1:
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_WRITE(c0, c1, 0, (dscr | ARM_DSCR_MDBGEN));
|
2010-09-03 09:41:08 +00:00
|
|
|
break;
|
|
|
|
case ARM_DEBUG_ARCH_V7_ECP14:
|
2011-07-22 17:27:37 +00:00
|
|
|
case ARM_DEBUG_ARCH_V7_1:
|
2014-01-29 21:01:31 +00:00
|
|
|
case ARM_DEBUG_ARCH_V8:
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_WRITE(c0, c2, 2, (dscr | ARM_DSCR_MDBGEN));
|
2012-09-21 14:08:17 +00:00
|
|
|
isb();
|
2010-09-03 09:41:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-21 14:38:26 +00:00
|
|
|
return -ENODEV;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the write made it through. */
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c1, 0, dscr);
|
2012-10-25 16:18:23 +00:00
|
|
|
if (!(dscr & ARM_DSCR_MDBGEN)) {
|
|
|
|
pr_warn_once("Failed to enable monitor mode on CPU %d.\n",
|
|
|
|
smp_processor_id());
|
2012-09-21 14:38:26 +00:00
|
|
|
return -EPERM;
|
2012-10-25 16:18:23 +00:00
|
|
|
}
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
out:
|
2012-09-21 14:38:26 +00:00
|
|
|
return 0;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 17:37:45 +00:00
|
|
|
int hw_breakpoint_slots(int type)
|
|
|
|
{
|
2011-02-11 15:01:42 +00:00
|
|
|
if (!debug_arch_supported())
|
|
|
|
return 0;
|
|
|
|
|
2010-12-01 17:37:45 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/*
|
|
|
|
* Check if 8-bit byte-address select is available.
|
|
|
|
* This clobbers WRP 0.
|
|
|
|
*/
|
|
|
|
static u8 get_max_wp_len(void)
|
|
|
|
{
|
|
|
|
u32 ctrl_reg;
|
|
|
|
struct arch_hw_breakpoint_ctrl ctrl;
|
|
|
|
u8 size = 4;
|
|
|
|
|
|
|
|
if (debug_arch < ARM_DEBUG_ARCH_V7_ECP14)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memset(&ctrl, 0, sizeof(ctrl));
|
|
|
|
ctrl.len = ARM_BREAKPOINT_LEN_8;
|
|
|
|
ctrl_reg = encode_ctrl_reg(ctrl);
|
|
|
|
|
|
|
|
write_wb_reg(ARM_BASE_WVR, 0);
|
|
|
|
write_wb_reg(ARM_BASE_WCR, ctrl_reg);
|
|
|
|
if ((read_wb_reg(ARM_BASE_WCR) & ctrl_reg) == ctrl_reg)
|
|
|
|
size = 8;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 arch_get_max_wp_len(void)
|
|
|
|
{
|
|
|
|
return max_watchpoint_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install a perf counter breakpoint.
|
|
|
|
*/
|
|
|
|
int arch_install_hw_breakpoint(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
|
|
|
struct perf_event **slot, **slots;
|
2012-09-24 17:01:13 +00:00
|
|
|
int i, max_slots, ctrl_base, val_base;
|
2010-11-29 16:56:01 +00:00
|
|
|
u32 addr, ctrl;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-11-29 16:56:01 +00:00
|
|
|
addr = info->address;
|
|
|
|
ctrl = encode_ctrl_reg(info->ctrl) | 0x1;
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE) {
|
|
|
|
/* Breakpoint */
|
|
|
|
ctrl_base = ARM_BASE_BCR;
|
|
|
|
val_base = ARM_BASE_BVR;
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(bp_on_reg);
|
2010-11-28 15:09:36 +00:00
|
|
|
max_slots = core_num_brps;
|
2010-09-03 09:41:08 +00:00
|
|
|
} else {
|
|
|
|
/* Watchpoint */
|
2011-08-02 15:16:57 +00:00
|
|
|
ctrl_base = ARM_BASE_WCR;
|
|
|
|
val_base = ARM_BASE_WVR;
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(wp_on_reg);
|
2010-09-03 09:41:08 +00:00
|
|
|
max_slots = core_num_wrps;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < max_slots; ++i) {
|
|
|
|
slot = &slots[i];
|
|
|
|
|
|
|
|
if (!*slot) {
|
|
|
|
*slot = bp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 16:18:23 +00:00
|
|
|
if (i == max_slots) {
|
|
|
|
pr_warning("Can't find any breakpoint slot\n");
|
2012-09-24 17:01:13 +00:00
|
|
|
return -EBUSY;
|
2012-10-25 16:18:23 +00:00
|
|
|
}
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
/* Override the breakpoint data with the step data. */
|
|
|
|
if (info->step_ctrl.enabled) {
|
|
|
|
addr = info->trigger & ~0x3;
|
|
|
|
ctrl = encode_ctrl_reg(info->step_ctrl);
|
|
|
|
if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE) {
|
|
|
|
i = 0;
|
|
|
|
ctrl_base = ARM_BASE_BCR + core_num_brps;
|
|
|
|
val_base = ARM_BASE_BVR + core_num_brps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Setup the address register. */
|
2010-11-29 16:56:01 +00:00
|
|
|
write_wb_reg(val_base + i, addr);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Setup the control register. */
|
2010-11-29 16:56:01 +00:00
|
|
|
write_wb_reg(ctrl_base + i, ctrl);
|
2012-09-24 17:01:13 +00:00
|
|
|
return 0;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_uninstall_hw_breakpoint(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
|
|
|
struct perf_event **slot, **slots;
|
|
|
|
int i, max_slots, base;
|
|
|
|
|
|
|
|
if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE) {
|
|
|
|
/* Breakpoint */
|
|
|
|
base = ARM_BASE_BCR;
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(bp_on_reg);
|
2010-11-28 15:09:36 +00:00
|
|
|
max_slots = core_num_brps;
|
2010-09-03 09:41:08 +00:00
|
|
|
} else {
|
|
|
|
/* Watchpoint */
|
2011-08-02 15:16:57 +00:00
|
|
|
base = ARM_BASE_WCR;
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(wp_on_reg);
|
2010-09-03 09:41:08 +00:00
|
|
|
max_slots = core_num_wrps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the breakpoint. */
|
|
|
|
for (i = 0; i < max_slots; ++i) {
|
|
|
|
slot = &slots[i];
|
|
|
|
|
|
|
|
if (*slot == bp) {
|
|
|
|
*slot = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 16:18:23 +00:00
|
|
|
if (i == max_slots) {
|
|
|
|
pr_warning("Can't find any breakpoint slot\n");
|
2010-09-03 09:41:08 +00:00
|
|
|
return;
|
2012-10-25 16:18:23 +00:00
|
|
|
}
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
/* Ensure that we disable the mismatch breakpoint. */
|
|
|
|
if (info->ctrl.type != ARM_BREAKPOINT_EXECUTE &&
|
|
|
|
info->step_ctrl.enabled) {
|
|
|
|
i = 0;
|
|
|
|
base = ARM_BASE_BCR + core_num_brps;
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Reset the control register. */
|
|
|
|
write_wb_reg(base + i, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_hbp_len(u8 hbp_len)
|
|
|
|
{
|
|
|
|
unsigned int len_in_bytes = 0;
|
|
|
|
|
|
|
|
switch (hbp_len) {
|
|
|
|
case ARM_BREAKPOINT_LEN_1:
|
|
|
|
len_in_bytes = 1;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_2:
|
|
|
|
len_in_bytes = 2;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_4:
|
|
|
|
len_in_bytes = 4;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_8:
|
|
|
|
len_in_bytes = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len_in_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether bp virtual address is in kernel space.
|
|
|
|
*/
|
|
|
|
int arch_check_bp_in_kernelspace(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
unsigned long va;
|
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
|
|
|
|
|
|
|
va = info->address;
|
|
|
|
len = get_hbp_len(info->ctrl.len);
|
|
|
|
|
|
|
|
return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract generic type and length encodings from an arch_hw_breakpoint_ctrl.
|
|
|
|
* Hopefully this will disappear when ptrace can bypass the conversion
|
|
|
|
* to generic breakpoint descriptions.
|
|
|
|
*/
|
|
|
|
int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
|
|
|
|
int *gen_len, int *gen_type)
|
|
|
|
{
|
|
|
|
/* Type */
|
|
|
|
switch (ctrl.type) {
|
|
|
|
case ARM_BREAKPOINT_EXECUTE:
|
|
|
|
*gen_type = HW_BREAKPOINT_X;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LOAD:
|
|
|
|
*gen_type = HW_BREAKPOINT_R;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_STORE:
|
|
|
|
*gen_type = HW_BREAKPOINT_W;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LOAD | ARM_BREAKPOINT_STORE:
|
|
|
|
*gen_type = HW_BREAKPOINT_RW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Len */
|
|
|
|
switch (ctrl.len) {
|
|
|
|
case ARM_BREAKPOINT_LEN_1:
|
|
|
|
*gen_len = HW_BREAKPOINT_LEN_1;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_2:
|
|
|
|
*gen_len = HW_BREAKPOINT_LEN_2;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_4:
|
|
|
|
*gen_len = HW_BREAKPOINT_LEN_4;
|
|
|
|
break;
|
|
|
|
case ARM_BREAKPOINT_LEN_8:
|
|
|
|
*gen_len = HW_BREAKPOINT_LEN_8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct an arch_hw_breakpoint from a perf_event.
|
|
|
|
*/
|
|
|
|
static int arch_build_bp_info(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
|
|
|
|
|
|
|
/* Type */
|
|
|
|
switch (bp->attr.bp_type) {
|
|
|
|
case HW_BREAKPOINT_X:
|
|
|
|
info->ctrl.type = ARM_BREAKPOINT_EXECUTE;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_R:
|
|
|
|
info->ctrl.type = ARM_BREAKPOINT_LOAD;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_W:
|
|
|
|
info->ctrl.type = ARM_BREAKPOINT_STORE;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_RW:
|
|
|
|
info->ctrl.type = ARM_BREAKPOINT_LOAD | ARM_BREAKPOINT_STORE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Len */
|
|
|
|
switch (bp->attr.bp_len) {
|
|
|
|
case HW_BREAKPOINT_LEN_1:
|
|
|
|
info->ctrl.len = ARM_BREAKPOINT_LEN_1;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_LEN_2:
|
|
|
|
info->ctrl.len = ARM_BREAKPOINT_LEN_2;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_LEN_4:
|
|
|
|
info->ctrl.len = ARM_BREAKPOINT_LEN_4;
|
|
|
|
break;
|
|
|
|
case HW_BREAKPOINT_LEN_8:
|
|
|
|
info->ctrl.len = ARM_BREAKPOINT_LEN_8;
|
|
|
|
if ((info->ctrl.type != ARM_BREAKPOINT_EXECUTE)
|
|
|
|
&& max_watchpoint_len >= 8)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-11-25 12:01:54 +00:00
|
|
|
/*
|
|
|
|
* Breakpoints must be of length 2 (thumb) or 4 (ARM) bytes.
|
|
|
|
* Watchpoints can be of length 1, 2, 4 or 8 bytes if supported
|
|
|
|
* by the hardware and must be aligned to the appropriate number of
|
|
|
|
* bytes.
|
|
|
|
*/
|
|
|
|
if (info->ctrl.type == ARM_BREAKPOINT_EXECUTE &&
|
|
|
|
info->ctrl.len != ARM_BREAKPOINT_LEN_2 &&
|
|
|
|
info->ctrl.len != ARM_BREAKPOINT_LEN_4)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Address */
|
|
|
|
info->address = bp->attr.bp_addr;
|
|
|
|
|
|
|
|
/* Privilege */
|
|
|
|
info->ctrl.privilege = ARM_BREAKPOINT_USER;
|
2010-11-29 16:56:01 +00:00
|
|
|
if (arch_check_bp_in_kernelspace(bp))
|
2010-09-03 09:41:08 +00:00
|
|
|
info->ctrl.privilege |= ARM_BREAKPOINT_PRIV;
|
|
|
|
|
|
|
|
/* Enabled? */
|
|
|
|
info->ctrl.enabled = !bp->attr.disabled;
|
|
|
|
|
|
|
|
/* Mismatch */
|
|
|
|
info->ctrl.mismatch = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate the arch-specific HW Breakpoint register settings.
|
|
|
|
*/
|
|
|
|
int arch_validate_hwbkpt_settings(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
|
|
|
int ret = 0;
|
2010-11-25 12:01:54 +00:00
|
|
|
u32 offset, alignment_mask = 0x3;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2012-09-24 17:01:13 +00:00
|
|
|
/* Ensure that we are in monitor debug mode. */
|
|
|
|
if (!monitor_mode_enabled())
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Build the arch_hw_breakpoint. */
|
|
|
|
ret = arch_build_bp_info(bp);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Check address alignment. */
|
|
|
|
if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
|
|
|
|
alignment_mask = 0x7;
|
2010-11-25 12:01:54 +00:00
|
|
|
offset = info->address & alignment_mask;
|
|
|
|
switch (offset) {
|
|
|
|
case 0:
|
|
|
|
/* Aligned */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
/* Allow halfword watchpoints and breakpoints. */
|
|
|
|
if (info->ctrl.len == ARM_BREAKPOINT_LEN_2)
|
|
|
|
break;
|
2012-08-16 18:02:12 +00:00
|
|
|
case 3:
|
|
|
|
/* Allow single byte watchpoint. */
|
|
|
|
if (info->ctrl.len == ARM_BREAKPOINT_LEN_1)
|
|
|
|
break;
|
2010-11-25 12:01:54 +00:00
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 12:01:54 +00:00
|
|
|
info->address &= ~alignment_mask;
|
|
|
|
info->ctrl.len <<= offset;
|
|
|
|
|
2012-08-16 17:55:44 +00:00
|
|
|
if (!bp->overflow_handler) {
|
|
|
|
/*
|
|
|
|
* Mismatch breakpoints are required for single-stepping
|
|
|
|
* breakpoints.
|
|
|
|
*/
|
|
|
|
if (!core_has_mismatch_brps())
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* We don't allow mismatch breakpoints in kernel space. */
|
|
|
|
if (arch_check_bp_in_kernelspace(bp))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per-cpu breakpoints are not supported by our stepping
|
|
|
|
* mechanism.
|
|
|
|
*/
|
|
|
|
if (!bp->hw.bp_target)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support specific access types if the fsr
|
|
|
|
* reports them.
|
|
|
|
*/
|
|
|
|
if (!debug_exception_updates_fsr() &&
|
|
|
|
(info->ctrl.type == ARM_BREAKPOINT_LOAD ||
|
|
|
|
info->ctrl.type == ARM_BREAKPOINT_STORE))
|
|
|
|
return -EINVAL;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
2012-08-16 17:55:44 +00:00
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
/*
|
|
|
|
* Enable/disable single-stepping over the breakpoint bp at address addr.
|
|
|
|
*/
|
|
|
|
static void enable_single_step(struct perf_event *bp, u32 addr)
|
2010-09-03 09:41:08 +00:00
|
|
|
{
|
2010-12-01 14:12:13 +00:00
|
|
|
struct arch_hw_breakpoint *info = counter_arch_bp(bp);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
arch_uninstall_hw_breakpoint(bp);
|
|
|
|
info->step_ctrl.mismatch = 1;
|
|
|
|
info->step_ctrl.len = ARM_BREAKPOINT_LEN_4;
|
|
|
|
info->step_ctrl.type = ARM_BREAKPOINT_EXECUTE;
|
|
|
|
info->step_ctrl.privilege = info->ctrl.privilege;
|
|
|
|
info->step_ctrl.enabled = 1;
|
|
|
|
info->trigger = addr;
|
|
|
|
arch_install_hw_breakpoint(bp);
|
|
|
|
}
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
static void disable_single_step(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
arch_uninstall_hw_breakpoint(bp);
|
|
|
|
counter_arch_bp(bp)->step_ctrl.enabled = 0;
|
|
|
|
arch_install_hw_breakpoint(bp);
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
static void watchpoint_handler(unsigned long addr, unsigned int fsr,
|
|
|
|
struct pt_regs *regs)
|
2010-09-03 09:41:08 +00:00
|
|
|
{
|
2011-08-02 15:16:57 +00:00
|
|
|
int i, access;
|
|
|
|
u32 val, ctrl_reg, alignment_mask;
|
2010-11-29 17:06:53 +00:00
|
|
|
struct perf_event *wp, **slots;
|
2010-09-03 09:41:08 +00:00
|
|
|
struct arch_hw_breakpoint *info;
|
2011-08-02 15:16:57 +00:00
|
|
|
struct arch_hw_breakpoint_ctrl ctrl;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(wp_on_reg);
|
2010-11-29 17:06:53 +00:00
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
for (i = 0; i < core_num_wrps; ++i) {
|
|
|
|
rcu_read_lock();
|
|
|
|
|
2010-11-29 16:56:01 +00:00
|
|
|
wp = slots[i];
|
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
if (wp == NULL)
|
|
|
|
goto unlock;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
info = counter_arch_bp(wp);
|
2010-09-03 09:41:08 +00:00
|
|
|
/*
|
2011-08-02 15:16:57 +00:00
|
|
|
* The DFAR is an unknown value on debug architectures prior
|
|
|
|
* to 7.1. Since we only allow a single watchpoint on these
|
|
|
|
* older CPUs, we can set the trigger to the lowest possible
|
|
|
|
* faulting address.
|
2010-09-03 09:41:08 +00:00
|
|
|
*/
|
2011-08-02 15:16:57 +00:00
|
|
|
if (debug_arch < ARM_DEBUG_ARCH_V7_1) {
|
|
|
|
BUG_ON(i > 0);
|
|
|
|
info->trigger = wp->attr.bp_addr;
|
|
|
|
} else {
|
|
|
|
if (info->ctrl.len == ARM_BREAKPOINT_LEN_8)
|
|
|
|
alignment_mask = 0x7;
|
|
|
|
else
|
|
|
|
alignment_mask = 0x3;
|
|
|
|
|
|
|
|
/* Check if the watchpoint value matches. */
|
|
|
|
val = read_wb_reg(ARM_BASE_WVR + i);
|
|
|
|
if (val != (addr & ~alignment_mask))
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
/* Possible match, check the byte address select. */
|
|
|
|
ctrl_reg = read_wb_reg(ARM_BASE_WCR + i);
|
|
|
|
decode_ctrl_reg(ctrl_reg, &ctrl);
|
|
|
|
if (!((1 << (addr & alignment_mask)) & ctrl.len))
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
/* Check that the access type matches. */
|
2012-08-16 17:55:44 +00:00
|
|
|
if (debug_exception_updates_fsr()) {
|
|
|
|
access = (fsr & ARM_FSR_ACCESS_MASK) ?
|
|
|
|
HW_BREAKPOINT_W : HW_BREAKPOINT_R;
|
|
|
|
if (!(access & hw_breakpoint_type(wp)))
|
|
|
|
goto unlock;
|
|
|
|
}
|
2011-08-02 15:16:57 +00:00
|
|
|
|
|
|
|
/* We have a winner. */
|
|
|
|
info->trigger = addr;
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
pr_debug("watchpoint fired: address = 0x%x\n", info->trigger);
|
2010-11-29 16:56:01 +00:00
|
|
|
perf_bp_event(wp, regs);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If no overflow handler is present, insert a temporary
|
|
|
|
* mismatch breakpoint so we can single-step over the
|
|
|
|
* watchpoint trigger.
|
|
|
|
*/
|
2010-12-01 14:12:13 +00:00
|
|
|
if (!wp->overflow_handler)
|
|
|
|
enable_single_step(wp, instruction_pointer(regs));
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2011-08-02 15:16:57 +00:00
|
|
|
unlock:
|
2010-09-03 09:41:08 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-29 16:56:01 +00:00
|
|
|
static void watchpoint_single_step_handler(unsigned long pc)
|
|
|
|
{
|
|
|
|
int i;
|
2010-11-29 17:06:53 +00:00
|
|
|
struct perf_event *wp, **slots;
|
2010-11-29 16:56:01 +00:00
|
|
|
struct arch_hw_breakpoint *info;
|
|
|
|
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(wp_on_reg);
|
2010-11-29 17:06:53 +00:00
|
|
|
|
2011-08-02 12:01:17 +00:00
|
|
|
for (i = 0; i < core_num_wrps; ++i) {
|
2010-11-29 16:56:01 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
wp = slots[i];
|
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
info = counter_arch_bp(wp);
|
|
|
|
if (!info->step_ctrl.enabled)
|
|
|
|
goto unlock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the original watchpoint if we've completed the
|
|
|
|
* single-step.
|
|
|
|
*/
|
2010-12-01 14:12:13 +00:00
|
|
|
if (info->trigger != pc)
|
|
|
|
disable_single_step(wp);
|
2010-11-29 16:56:01 +00:00
|
|
|
|
|
|
|
unlock:
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
static void breakpoint_handler(unsigned long unknown, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 ctrl_reg, val, addr;
|
2010-11-29 17:06:53 +00:00
|
|
|
struct perf_event *bp, **slots;
|
2010-09-03 09:41:08 +00:00
|
|
|
struct arch_hw_breakpoint *info;
|
|
|
|
struct arch_hw_breakpoint_ctrl ctrl;
|
|
|
|
|
2013-10-21 12:17:08 +00:00
|
|
|
slots = this_cpu_ptr(bp_on_reg);
|
2010-11-29 17:06:53 +00:00
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* The exception entry code places the amended lr in the PC. */
|
|
|
|
addr = regs->ARM_pc;
|
|
|
|
|
2010-11-29 16:56:01 +00:00
|
|
|
/* Check the currently installed breakpoints first. */
|
|
|
|
for (i = 0; i < core_num_brps; ++i) {
|
2010-09-03 09:41:08 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
bp = slots[i];
|
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
if (bp == NULL)
|
|
|
|
goto unlock;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
info = counter_arch_bp(bp);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Check if the breakpoint value matches. */
|
|
|
|
val = read_wb_reg(ARM_BASE_BVR + i);
|
|
|
|
if (val != (addr & ~0x3))
|
2010-12-01 14:12:13 +00:00
|
|
|
goto mismatch;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Possible match, check the byte address select to confirm. */
|
|
|
|
ctrl_reg = read_wb_reg(ARM_BASE_BCR + i);
|
|
|
|
decode_ctrl_reg(ctrl_reg, &ctrl);
|
|
|
|
if ((1 << (addr & 0x3)) & ctrl.len) {
|
|
|
|
info->trigger = addr;
|
|
|
|
pr_debug("breakpoint fired: address = 0x%x\n", addr);
|
|
|
|
perf_bp_event(bp, regs);
|
2010-12-01 14:12:13 +00:00
|
|
|
if (!bp->overflow_handler)
|
|
|
|
enable_single_step(bp, addr);
|
|
|
|
goto unlock;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 14:12:13 +00:00
|
|
|
mismatch:
|
|
|
|
/* If we're stepping a breakpoint, it can now be restored. */
|
|
|
|
if (info->step_ctrl.enabled)
|
|
|
|
disable_single_step(bp);
|
|
|
|
unlock:
|
2010-09-03 09:41:08 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
2010-11-29 16:56:01 +00:00
|
|
|
|
|
|
|
/* Handle any pending watchpoint single-step breakpoints. */
|
|
|
|
watchpoint_single_step_handler(addr);
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from either the Data Abort Handler [watchpoint] or the
|
2011-06-25 10:44:06 +00:00
|
|
|
* Prefetch Abort Handler [breakpoint] with interrupts disabled.
|
2010-09-03 09:41:08 +00:00
|
|
|
*/
|
|
|
|
static int hw_breakpoint_pending(unsigned long addr, unsigned int fsr,
|
|
|
|
struct pt_regs *regs)
|
|
|
|
{
|
2010-11-28 14:57:24 +00:00
|
|
|
int ret = 0;
|
2010-09-03 09:41:08 +00:00
|
|
|
u32 dscr;
|
|
|
|
|
2011-06-25 10:44:06 +00:00
|
|
|
preempt_disable();
|
|
|
|
|
|
|
|
if (interrupts_enabled(regs))
|
|
|
|
local_irq_enable();
|
2010-11-28 14:57:24 +00:00
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* We only handle watchpoints and hardware breakpoints. */
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c0, c1, 0, dscr);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Perform perf callbacks. */
|
|
|
|
switch (ARM_DSCR_MOE(dscr)) {
|
|
|
|
case ARM_ENTRY_BREAKPOINT:
|
|
|
|
breakpoint_handler(addr, regs);
|
|
|
|
break;
|
|
|
|
case ARM_ENTRY_ASYNC_WATCHPOINT:
|
2010-10-30 21:21:24 +00:00
|
|
|
WARN(1, "Asynchronous watchpoint exception taken. Debugging results may be unreliable\n");
|
2010-09-03 09:41:08 +00:00
|
|
|
case ARM_ENTRY_SYNC_WATCHPOINT:
|
2011-08-02 15:16:57 +00:00
|
|
|
watchpoint_handler(addr, fsr, regs);
|
2010-09-03 09:41:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-11-28 14:57:24 +00:00
|
|
|
ret = 1; /* Unhandled fault. */
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-28 14:57:24 +00:00
|
|
|
preempt_enable();
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One-time initialisation.
|
|
|
|
*/
|
2011-08-08 13:26:53 +00:00
|
|
|
static cpumask_t debug_err_mask;
|
|
|
|
|
|
|
|
static int debug_reg_trap(struct pt_regs *regs, unsigned int instr)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
pr_warning("Debug register access (0x%x) caused undefined instruction on CPU %d\n",
|
|
|
|
instr, cpu);
|
|
|
|
|
|
|
|
/* Set the error flag for this CPU and skip the faulting instruction. */
|
|
|
|
cpumask_set_cpu(cpu, &debug_err_mask);
|
|
|
|
instruction_pointer(regs) += 4;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct undef_hook debug_reg_hook = {
|
|
|
|
.instr_mask = 0x0fe80f10,
|
|
|
|
.instr_val = 0x0e000e10,
|
|
|
|
.fn = debug_reg_trap,
|
|
|
|
};
|
|
|
|
|
2012-10-14 20:08:14 +00:00
|
|
|
/* Does this core support OS Save and Restore? */
|
|
|
|
static bool core_has_os_save_restore(void)
|
|
|
|
{
|
|
|
|
u32 oslsr;
|
|
|
|
|
|
|
|
switch (get_debug_arch()) {
|
|
|
|
case ARM_DEBUG_ARCH_V7_1:
|
|
|
|
return true;
|
|
|
|
case ARM_DEBUG_ARCH_V7_ECP14:
|
|
|
|
ARM_DBG_READ(c1, c1, 4, oslsr);
|
|
|
|
if (oslsr & ARM_OSLSR_OSLM0)
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-08 13:26:53 +00:00
|
|
|
static void reset_ctrl_regs(void *unused)
|
2010-09-03 09:41:08 +00:00
|
|
|
{
|
2011-08-02 12:01:17 +00:00
|
|
|
int i, raw_num_brps, err = 0, cpu = smp_processor_id();
|
2012-09-21 13:53:13 +00:00
|
|
|
u32 val;
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2010-11-24 16:51:17 +00:00
|
|
|
/*
|
|
|
|
* v7 debug contains save and restore registers so that debug state
|
2011-02-11 14:55:12 +00:00
|
|
|
* can be maintained across low-power modes without leaving the debug
|
|
|
|
* logic powered up. It is IMPLEMENTATION DEFINED whether we can access
|
|
|
|
* the debug registers out of reset, so we must unlock the OS Lock
|
|
|
|
* Access Register to avoid taking undefined instruction exceptions
|
|
|
|
* later on.
|
2010-11-24 16:51:17 +00:00
|
|
|
*/
|
2011-07-22 17:27:37 +00:00
|
|
|
switch (debug_arch) {
|
2011-10-07 14:57:55 +00:00
|
|
|
case ARM_DEBUG_ARCH_V6:
|
|
|
|
case ARM_DEBUG_ARCH_V6_1:
|
2012-09-21 16:53:08 +00:00
|
|
|
/* ARMv6 cores clear the registers out of reset. */
|
|
|
|
goto out_mdbgen;
|
2011-07-22 17:27:37 +00:00
|
|
|
case ARM_DEBUG_ARCH_V7_ECP14:
|
2011-02-25 19:20:42 +00:00
|
|
|
/*
|
|
|
|
* Ensure sticky power-down is clear (i.e. debug logic is
|
|
|
|
* powered up).
|
|
|
|
*/
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c1, c5, 4, val);
|
2012-09-21 13:53:13 +00:00
|
|
|
if ((val & 0x1) == 0)
|
2011-07-22 17:27:37 +00:00
|
|
|
err = -EPERM;
|
2012-09-21 13:53:13 +00:00
|
|
|
|
2012-10-14 20:08:14 +00:00
|
|
|
if (!has_ossr)
|
2012-09-21 13:53:13 +00:00
|
|
|
goto clear_vcr;
|
2011-07-22 17:27:37 +00:00
|
|
|
break;
|
|
|
|
case ARM_DEBUG_ARCH_V7_1:
|
2010-11-24 16:51:17 +00:00
|
|
|
/*
|
2011-07-22 17:27:37 +00:00
|
|
|
* Ensure the OS double lock is clear.
|
2010-11-24 16:51:17 +00:00
|
|
|
*/
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_READ(c1, c3, 4, val);
|
2012-09-21 13:53:13 +00:00
|
|
|
if ((val & 0x1) == 1)
|
2011-07-22 17:27:37 +00:00
|
|
|
err = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-05 12:57:53 +00:00
|
|
|
|
2011-07-22 17:27:37 +00:00
|
|
|
if (err) {
|
2013-03-20 16:30:30 +00:00
|
|
|
pr_warn_once("CPU %d debug is powered down!\n", cpu);
|
2011-08-08 13:26:53 +00:00
|
|
|
cpumask_or(&debug_err_mask, &debug_err_mask, cpumask_of(cpu));
|
2011-07-22 17:27:37 +00:00
|
|
|
return;
|
2010-11-24 16:51:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 17:27:37 +00:00
|
|
|
/*
|
2012-09-21 13:53:13 +00:00
|
|
|
* Unconditionally clear the OS lock by writing a value
|
2012-10-14 19:23:04 +00:00
|
|
|
* other than CS_LAR_KEY to the access register.
|
2011-07-22 17:27:37 +00:00
|
|
|
*/
|
2012-10-14 19:23:04 +00:00
|
|
|
ARM_DBG_WRITE(c1, c0, 4, ~CS_LAR_KEY);
|
2011-07-22 17:27:37 +00:00
|
|
|
isb();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any configured vector-catch events before
|
|
|
|
* enabling monitor mode.
|
|
|
|
*/
|
2012-09-21 13:53:13 +00:00
|
|
|
clear_vcr:
|
2012-09-26 16:28:47 +00:00
|
|
|
ARM_DBG_WRITE(c0, c7, 0, 0);
|
2011-07-22 17:27:37 +00:00
|
|
|
isb();
|
|
|
|
|
2012-09-21 14:38:26 +00:00
|
|
|
if (cpumask_intersects(&debug_err_mask, cpumask_of(cpu))) {
|
2013-03-20 16:30:30 +00:00
|
|
|
pr_warn_once("CPU %d failed to disable vector catch\n", cpu);
|
2010-09-03 09:41:08 +00:00
|
|
|
return;
|
2012-09-21 14:38:26 +00:00
|
|
|
}
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2012-09-21 14:38:26 +00:00
|
|
|
/*
|
|
|
|
* The control/value register pairs are UNKNOWN out of reset so
|
|
|
|
* clear them to avoid spurious debug events.
|
|
|
|
*/
|
2011-08-02 12:01:17 +00:00
|
|
|
raw_num_brps = get_num_brp_resources();
|
|
|
|
for (i = 0; i < raw_num_brps; ++i) {
|
2010-09-03 09:41:08 +00:00
|
|
|
write_wb_reg(ARM_BASE_BCR + i, 0UL);
|
|
|
|
write_wb_reg(ARM_BASE_BVR + i, 0UL);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < core_num_wrps; ++i) {
|
|
|
|
write_wb_reg(ARM_BASE_WCR + i, 0UL);
|
|
|
|
write_wb_reg(ARM_BASE_WVR + i, 0UL);
|
|
|
|
}
|
2012-09-21 14:38:26 +00:00
|
|
|
|
|
|
|
if (cpumask_intersects(&debug_err_mask, cpumask_of(cpu))) {
|
2013-03-20 16:30:30 +00:00
|
|
|
pr_warn_once("CPU %d failed to clear debug register pairs\n", cpu);
|
2012-09-21 14:38:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have a crack at enabling monitor mode. We don't actually need
|
|
|
|
* it yet, but reporting an error early is useful if it fails.
|
|
|
|
*/
|
2012-09-21 16:53:08 +00:00
|
|
|
out_mdbgen:
|
2012-09-21 14:38:26 +00:00
|
|
|
if (enable_monitor_mode())
|
|
|
|
cpumask_or(&debug_err_mask, &debug_err_mask, cpumask_of(cpu));
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 19:43:14 +00:00
|
|
|
static int dbg_reset_notify(struct notifier_block *self,
|
2010-11-24 17:45:49 +00:00
|
|
|
unsigned long action, void *cpu)
|
|
|
|
{
|
2013-02-28 16:48:57 +00:00
|
|
|
if ((action & ~CPU_TASKS_FROZEN) == CPU_ONLINE)
|
2010-11-24 17:45:49 +00:00
|
|
|
smp_call_function_single((int)cpu, reset_ctrl_regs, NULL, 1);
|
2011-08-08 13:26:53 +00:00
|
|
|
|
2010-11-24 17:45:49 +00:00
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:43:14 +00:00
|
|
|
static struct notifier_block dbg_reset_nb = {
|
2010-11-24 17:45:49 +00:00
|
|
|
.notifier_call = dbg_reset_notify,
|
|
|
|
};
|
|
|
|
|
2012-10-14 21:25:37 +00:00
|
|
|
#ifdef CONFIG_CPU_PM
|
|
|
|
static int dbg_cpu_pm_notify(struct notifier_block *self, unsigned long action,
|
|
|
|
void *v)
|
|
|
|
{
|
|
|
|
if (action == CPU_PM_EXIT)
|
|
|
|
reset_ctrl_regs(NULL);
|
|
|
|
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-12 18:03:50 +00:00
|
|
|
static struct notifier_block dbg_cpu_pm_nb = {
|
2012-10-14 21:25:37 +00:00
|
|
|
.notifier_call = dbg_cpu_pm_notify,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __init pm_init(void)
|
|
|
|
{
|
|
|
|
cpu_pm_register_notifier(&dbg_cpu_pm_nb);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void pm_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
static int __init arch_hw_breakpoint_init(void)
|
|
|
|
{
|
|
|
|
debug_arch = get_debug_arch();
|
|
|
|
|
2011-02-11 15:01:42 +00:00
|
|
|
if (!debug_arch_supported()) {
|
2010-09-03 09:41:08 +00:00
|
|
|
pr_info("debug architecture 0x%x unsupported.\n", debug_arch);
|
2010-12-01 17:37:45 +00:00
|
|
|
return 0;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 20:08:14 +00:00
|
|
|
has_ossr = core_has_os_save_restore();
|
|
|
|
|
2010-09-03 09:41:08 +00:00
|
|
|
/* Determine how many BRPs/WRPs are available. */
|
|
|
|
core_num_brps = get_num_brps();
|
|
|
|
core_num_wrps = get_num_wrps();
|
|
|
|
|
2014-03-10 20:35:21 +00:00
|
|
|
cpu_notifier_register_begin();
|
|
|
|
|
2011-08-08 13:26:53 +00:00
|
|
|
/*
|
|
|
|
* We need to tread carefully here because DBGSWENABLE may be
|
|
|
|
* driven low on this core and there isn't an architected way to
|
|
|
|
* determine that.
|
|
|
|
*/
|
|
|
|
register_undef_hook(&debug_reg_hook);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2011-02-11 14:55:12 +00:00
|
|
|
/*
|
|
|
|
* Reset the breakpoint resources. We assume that a halting
|
|
|
|
* debugger will leave the world in a nice state for us.
|
|
|
|
*/
|
2011-08-08 13:26:53 +00:00
|
|
|
on_each_cpu(reset_ctrl_regs, NULL, 1);
|
|
|
|
unregister_undef_hook(&debug_reg_hook);
|
|
|
|
if (!cpumask_empty(&debug_err_mask)) {
|
2011-02-25 19:20:42 +00:00
|
|
|
core_num_brps = 0;
|
|
|
|
core_num_wrps = 0;
|
2014-03-10 20:35:21 +00:00
|
|
|
cpu_notifier_register_done();
|
2011-02-25 19:20:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-02-11 14:55:12 +00:00
|
|
|
|
2011-08-08 13:26:53 +00:00
|
|
|
pr_info("found %d " "%s" "breakpoint and %d watchpoint registers.\n",
|
|
|
|
core_num_brps, core_has_mismatch_brps() ? "(+1 reserved) " :
|
|
|
|
"", core_num_wrps);
|
|
|
|
|
2012-09-21 14:08:17 +00:00
|
|
|
/* Work out the maximum supported watchpoint length. */
|
|
|
|
max_watchpoint_len = get_max_wp_len();
|
|
|
|
pr_info("maximum watchpoint size is %u bytes.\n",
|
|
|
|
max_watchpoint_len);
|
2010-09-03 09:41:08 +00:00
|
|
|
|
|
|
|
/* Register debug fault handler. */
|
2011-11-22 17:30:31 +00:00
|
|
|
hook_fault_code(FAULT_CODE_DEBUG, hw_breakpoint_pending, SIGTRAP,
|
|
|
|
TRAP_HWBKPT, "watchpoint debug exception");
|
|
|
|
hook_ifault_code(FAULT_CODE_DEBUG, hw_breakpoint_pending, SIGTRAP,
|
|
|
|
TRAP_HWBKPT, "breakpoint debug exception");
|
2010-09-03 09:41:08 +00:00
|
|
|
|
2012-10-14 21:25:37 +00:00
|
|
|
/* Register hotplug and PM notifiers. */
|
2014-03-10 20:35:21 +00:00
|
|
|
__register_cpu_notifier(&dbg_reset_nb);
|
|
|
|
|
|
|
|
cpu_notifier_register_done();
|
|
|
|
|
2012-10-14 21:25:37 +00:00
|
|
|
pm_init();
|
2010-12-01 17:37:45 +00:00
|
|
|
return 0;
|
2010-09-03 09:41:08 +00:00
|
|
|
}
|
|
|
|
arch_initcall(arch_hw_breakpoint_init);
|
|
|
|
|
|
|
|
void hw_breakpoint_pmu_read(struct perf_event *bp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy function to register with die_notifier.
|
|
|
|
*/
|
|
|
|
int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
|
|
|
|
unsigned long val, void *data)
|
|
|
|
{
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|