Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2022-2023 Loongson Technology Corporation Limited
5 #define pr_fmt(fmt) "hw-breakpoint: " fmt
73 GEN_READ_WB_REG_CASES(CSR_CFG_CTRL, CTRL, t, val); in read_wb_reg()
88 GEN_WRITE_WB_REG_CASES(CSR_CFG_CTRL, CTRL, t, val); in write_wb_reg()
102 * hw_breakpoint_slot_setup - Find and setup a perf slot according to operations
111 * -ENOSPC if no slot is available/matches
112 * -EINVAL on wrong operations parameter
138 return -EINVAL; in hw_breakpoint_slot_setup()
142 return -ENOSPC; in hw_breakpoint_slot_setup()
147 memset(tsk->thread.hbp_break, 0, sizeof(tsk->thread.hbp_break)); in ptrace_hw_copy_thread()
148 memset(tsk->thread.hbp_watch, 0, sizeof(tsk->thread.hbp_watch)); in ptrace_hw_copy_thread()
157 struct thread_struct *t = &tsk->thread; in flush_ptrace_hw_breakpoint()
160 if (t->hbp_break[i]) { in flush_ptrace_hw_breakpoint()
161 unregister_hw_breakpoint(t->hbp_break[i]); in flush_ptrace_hw_breakpoint()
162 t->hbp_break[i] = NULL; in flush_ptrace_hw_breakpoint()
167 if (t->hbp_watch[i]) { in flush_ptrace_hw_breakpoint()
168 unregister_hw_breakpoint(t->hbp_watch[i]); in flush_ptrace_hw_breakpoint()
169 t->hbp_watch[i] = NULL; in flush_ptrace_hw_breakpoint()
177 u32 ctrl, privilege; in hw_breakpoint_control() local
189 if (bp->hw.target) in hw_breakpoint_control()
190 regs = task_pt_regs(bp->hw.target); in hw_breakpoint_control()
192 if (info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) { in hw_breakpoint_control()
210 if (info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) { in hw_breakpoint_control()
211 write_wb_reg(CSR_CFG_ADDR, i, 0, info->address); in hw_breakpoint_control()
212 write_wb_reg(CSR_CFG_MASK, i, 0, info->mask); in hw_breakpoint_control()
216 write_wb_reg(CSR_CFG_ADDR, i, 1, info->address); in hw_breakpoint_control()
217 write_wb_reg(CSR_CFG_MASK, i, 1, info->mask); in hw_breakpoint_control()
219 ctrl = encode_ctrl_reg(info->ctrl); in hw_breakpoint_control()
220 write_wb_reg(CSR_CFG_CTRL, i, 1, ctrl | privilege); in hw_breakpoint_control()
224 if (bp->hw.target && test_tsk_thread_flag(bp->hw.target, TIF_LOAD_WATCH)) in hw_breakpoint_control()
225 regs->csr_prmd |= CSR_PRMD_PWE; in hw_breakpoint_control()
229 if (info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) { in hw_breakpoint_control()
240 if (bp->hw.target) in hw_breakpoint_control()
241 regs->csr_prmd &= ~CSR_PRMD_PWE; in hw_breakpoint_control()
288 unsigned int len; in arch_check_bp_in_kernelspace() local
291 va = hw->address; in arch_check_bp_in_kernelspace()
292 len = get_hbp_len(hw->ctrl.len); in arch_check_bp_in_kernelspace()
294 return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE); in arch_check_bp_in_kernelspace()
302 int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl, in arch_bp_generic_fields() argument
306 switch (ctrl.type) { in arch_bp_generic_fields()
320 return -EINVAL; in arch_bp_generic_fields()
323 /* Len */ in arch_bp_generic_fields()
324 switch (ctrl.len) { in arch_bp_generic_fields()
338 return -EINVAL; in arch_bp_generic_fields()
352 switch (attr->bp_type) { in arch_build_bp_info()
354 hw->ctrl.type = LOONGARCH_BREAKPOINT_EXECUTE; in arch_build_bp_info()
357 hw->ctrl.type = LOONGARCH_BREAKPOINT_LOAD; in arch_build_bp_info()
360 hw->ctrl.type = LOONGARCH_BREAKPOINT_STORE; in arch_build_bp_info()
363 hw->ctrl.type = LOONGARCH_BREAKPOINT_LOAD | LOONGARCH_BREAKPOINT_STORE; in arch_build_bp_info()
366 return -EINVAL; in arch_build_bp_info()
369 /* Len */ in arch_build_bp_info()
370 switch (attr->bp_len) { in arch_build_bp_info()
372 hw->ctrl.len = LOONGARCH_BREAKPOINT_LEN_1; in arch_build_bp_info()
375 hw->ctrl.len = LOONGARCH_BREAKPOINT_LEN_2; in arch_build_bp_info()
378 hw->ctrl.len = LOONGARCH_BREAKPOINT_LEN_4; in arch_build_bp_info()
381 hw->ctrl.len = LOONGARCH_BREAKPOINT_LEN_8; in arch_build_bp_info()
384 return -EINVAL; in arch_build_bp_info()
388 hw->address = attr->bp_addr; in arch_build_bp_info()
394 * Validate the arch-specific HW Breakpoint register settings.
408 if (hw->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) { in hw_breakpoint_arch_parse()
410 hw->address &= ~alignment_mask; in hw_breakpoint_arch_parse()
418 u32 ctrl; in update_bp_registers() local
442 if ((info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) && (type == 0)) { in update_bp_registers()
446 ctrl = read_wb_reg(CSR_CFG_CTRL, i, 1); in update_bp_registers()
447 if (info->ctrl.type == LOONGARCH_BREAKPOINT_LOAD) in update_bp_registers()
448 ctrl |= 0x1 << MWPnCFG3_LoadEn; in update_bp_registers()
449 if (info->ctrl.type == LOONGARCH_BREAKPOINT_STORE) in update_bp_registers()
450 ctrl |= 0x1 << MWPnCFG3_StoreEn; in update_bp_registers()
451 write_wb_reg(CSR_CFG_CTRL, i, 1, ctrl); in update_bp_registers()
453 regs->csr_prmd |= CSR_PRMD_PWE; in update_bp_registers()
455 if ((info->ctrl.type == LOONGARCH_BREAKPOINT_EXECUTE) && (type == 0)) { in update_bp_registers()
458 ctrl = read_wb_reg(CSR_CFG_CTRL, i, 1); in update_bp_registers()
459 if (info->ctrl.type == LOONGARCH_BREAKPOINT_LOAD) in update_bp_registers()
460 ctrl &= ~0x1 << MWPnCFG3_LoadEn; in update_bp_registers()
461 if (info->ctrl.type == LOONGARCH_BREAKPOINT_STORE) in update_bp_registers()
462 ctrl &= ~0x1 << MWPnCFG3_StoreEn; in update_bp_registers()
463 write_wb_reg(CSR_CFG_CTRL, i, 1, ctrl); in update_bp_registers()
465 regs->csr_prmd &= ~CSR_PRMD_PWE; in update_bp_registers()
541 if (!((regs->csr_era ^ addr) & ~mask)) in hw_breakpoint_thread_switch()
543 regs->csr_prmd |= CSR_PRMD_PWE; in hw_breakpoint_thread_switch()