18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Kernel Probes (KProbes)
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2020 Loongson Technology Corporation Limited
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  This program is free software; you can redistribute it and/or modify
88c2ecf20Sopenharmony_ci *  it under the terms of the GNU General Public License as published by
98c2ecf20Sopenharmony_ci *  the Free Software Foundation; version 2 of the License.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *  This program is distributed in the hope that it will be useful,
128c2ecf20Sopenharmony_ci *  but WITHOUT ANY WARRANTY; without even the implied warranty of
138c2ecf20Sopenharmony_ci *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148c2ecf20Sopenharmony_ci *  GNU General Public License for more details.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci *  You should have received a copy of the GNU General Public License
178c2ecf20Sopenharmony_ci *  along with this program; if not, write to the Free Software
188c2ecf20Sopenharmony_ci *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#ifndef _ASM_KPROBES_H
228c2ecf20Sopenharmony_ci#define _ASM_KPROBES_H
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <asm-generic/kprobes.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_KPROBES
278c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
288c2ecf20Sopenharmony_ci#include <linux/types.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#include <asm/cacheflush.h>
318c2ecf20Sopenharmony_ci#include <asm/kdebug.h>
328c2ecf20Sopenharmony_ci#include <asm/inst.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define	 __ARCH_WANT_KPROBES_INSN_SLOT
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct kprobe;
378c2ecf20Sopenharmony_cistruct pt_regs;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_citypedef union loongarch_instruction kprobe_opcode_t;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define MAX_INSN_SIZE 2
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define flush_insn_slot(p)						\
448c2ecf20Sopenharmony_cido {									\
458c2ecf20Sopenharmony_ci	if (p->addr)							\
468c2ecf20Sopenharmony_ci		flush_icache_range((unsigned long)p->addr,		\
478c2ecf20Sopenharmony_ci			   (unsigned long)p->addr +			\
488c2ecf20Sopenharmony_ci			   (MAX_INSN_SIZE * sizeof(kprobe_opcode_t)));	\
498c2ecf20Sopenharmony_ci} while (0)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define kretprobe_blacklist_size 0
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_civoid arch_remove_kprobe(struct kprobe *p);
558c2ecf20Sopenharmony_ciint kprobe_fault_handler(struct pt_regs *regs, int trapnr);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Architecture specific copy of original instruction*/
588c2ecf20Sopenharmony_cistruct arch_specific_insn {
598c2ecf20Sopenharmony_ci	/* copy of the original instruction */
608c2ecf20Sopenharmony_ci	kprobe_opcode_t *insn;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct prev_kprobe {
648c2ecf20Sopenharmony_ci	struct kprobe *kp;
658c2ecf20Sopenharmony_ci	unsigned long status;
668c2ecf20Sopenharmony_ci	unsigned long old_SR;
678c2ecf20Sopenharmony_ci	unsigned long saved_SR;
688c2ecf20Sopenharmony_ci	unsigned long saved_era;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* per-cpu kprobe control block */
728c2ecf20Sopenharmony_cistruct kprobe_ctlblk {
738c2ecf20Sopenharmony_ci	unsigned long kprobe_status;
748c2ecf20Sopenharmony_ci	unsigned long kprobe_old_SR;
758c2ecf20Sopenharmony_ci	unsigned long kprobe_saved_SR;
768c2ecf20Sopenharmony_ci	unsigned long kprobe_saved_era;
778c2ecf20Sopenharmony_ci	/* Per-thread fields, used while emulating branches */
788c2ecf20Sopenharmony_ci	unsigned long flags;
798c2ecf20Sopenharmony_ci	unsigned long target_era;
808c2ecf20Sopenharmony_ci	struct prev_kprobe prev_kprobe;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciextern int kprobe_exceptions_notify(struct notifier_block *self,
848c2ecf20Sopenharmony_ci				    unsigned long val, void *data);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#endif /* CONFIG_KPROBES */
878c2ecf20Sopenharmony_ci#endif /* _ASM_KPROBES_H */
88