Path: blob/master/arch/loongarch/include/asm/hw_breakpoint.h
26488 views
/* SPDX-License-Identifier: GPL-2.0 */1/*2* Copyright (C) 2022-2023 Loongson Technology Corporation Limited3*/4#ifndef __ASM_HW_BREAKPOINT_H5#define __ASM_HW_BREAKPOINT_H67#include <asm/loongarch.h>89#ifdef __KERNEL__1011/* Breakpoint */12#define LOONGARCH_BREAKPOINT_EXECUTE (0 << 0)1314/* Watchpoints */15#define LOONGARCH_BREAKPOINT_LOAD (1 << 0)16#define LOONGARCH_BREAKPOINT_STORE (1 << 1)1718struct arch_hw_breakpoint_ctrl {19u32 __reserved : 28,20len : 2,21type : 2;22};2324struct arch_hw_breakpoint {25u64 address;26u64 mask;27struct arch_hw_breakpoint_ctrl ctrl;28};2930/* Lengths */31#define LOONGARCH_BREAKPOINT_LEN_1 0b1132#define LOONGARCH_BREAKPOINT_LEN_2 0b1033#define LOONGARCH_BREAKPOINT_LEN_4 0b0134#define LOONGARCH_BREAKPOINT_LEN_8 0b003536/*37* Limits.38* Changing these will require modifications to the register accessors.39*/40#define LOONGARCH_MAX_BRP 1441#define LOONGARCH_MAX_WRP 144243/* Virtual debug register bases. */44#define CSR_CFG_ADDR 045#define CSR_CFG_MASK (CSR_CFG_ADDR + LOONGARCH_MAX_BRP)46#define CSR_CFG_CTRL (CSR_CFG_MASK + LOONGARCH_MAX_BRP)47#define CSR_CFG_ASID (CSR_CFG_CTRL + LOONGARCH_MAX_WRP)4849/* Debug register names. */50#define LOONGARCH_CSR_NAME_ADDR ADDR51#define LOONGARCH_CSR_NAME_MASK MASK52#define LOONGARCH_CSR_NAME_CTRL CTRL53#define LOONGARCH_CSR_NAME_ASID ASID5455/* Accessor macros for the debug registers. */56#define LOONGARCH_CSR_WATCH_READ(N, REG, T, VAL) \57do { \58if (T == 0) \59VAL = csr_read64(LOONGARCH_CSR_##IB##N##REG); \60else \61VAL = csr_read64(LOONGARCH_CSR_##DB##N##REG); \62} while (0)6364#define LOONGARCH_CSR_WATCH_WRITE(N, REG, T, VAL) \65do { \66if (T == 0) \67csr_write64(VAL, LOONGARCH_CSR_##IB##N##REG); \68else \69csr_write64(VAL, LOONGARCH_CSR_##DB##N##REG); \70} while (0)7172/* Exact number */73#define CSR_FWPC_NUM 0x3f74#define CSR_MWPC_NUM 0x3f7576#define CTRL_PLV_ENABLE 0x1e77#define CTRL_PLV0_ENABLE 0x0278#define CTRL_PLV3_ENABLE 0x107980#define MWPnCFG3_LoadEn 881#define MWPnCFG3_StoreEn 98283#define MWPnCFG3_Type_mask 0x384#define MWPnCFG3_Size_mask 0x38586static inline u32 encode_ctrl_reg(struct arch_hw_breakpoint_ctrl ctrl)87{88return (ctrl.len << 10) | (ctrl.type << 8);89}9091static inline void decode_ctrl_reg(u32 reg, struct arch_hw_breakpoint_ctrl *ctrl)92{93reg >>= 8;94ctrl->type = reg & MWPnCFG3_Type_mask;95reg >>= 2;96ctrl->len = reg & MWPnCFG3_Size_mask;97}9899struct task_struct;100struct notifier_block;101struct perf_event;102struct perf_event_attr;103104extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,105int *gen_len, int *gen_type);106extern int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw);107extern int hw_breakpoint_arch_parse(struct perf_event *bp,108const struct perf_event_attr *attr,109struct arch_hw_breakpoint *hw);110extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,111unsigned long val, void *data);112113extern int arch_install_hw_breakpoint(struct perf_event *bp);114extern void arch_uninstall_hw_breakpoint(struct perf_event *bp);115extern int hw_breakpoint_slots(int type);116extern void hw_breakpoint_pmu_read(struct perf_event *bp);117118void breakpoint_handler(struct pt_regs *regs);119void watchpoint_handler(struct pt_regs *regs);120121#ifdef CONFIG_HAVE_HW_BREAKPOINT122extern void ptrace_hw_copy_thread(struct task_struct *task);123extern void hw_breakpoint_thread_switch(struct task_struct *next);124#else125static inline void ptrace_hw_copy_thread(struct task_struct *task)126{127}128static inline void hw_breakpoint_thread_switch(struct task_struct *next)129{130}131#endif132133/* Determine number of BRP registers available. */134static inline int get_num_brps(void)135{136return csr_read64(LOONGARCH_CSR_FWPC) & CSR_FWPC_NUM;137}138139/* Determine number of WRP registers available. */140static inline int get_num_wrps(void)141{142return csr_read64(LOONGARCH_CSR_MWPC) & CSR_MWPC_NUM;143}144145#endif /* __KERNEL__ */146#endif /* __ASM_BREAKPOINT_H */147148149