18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef	_I386_HW_BREAKPOINT_H
38c2ecf20Sopenharmony_ci#define	_I386_HW_BREAKPOINT_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <uapi/asm/hw_breakpoint.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#define	__ARCH_HW_BREAKPOINT_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * The name should probably be something dealt in
118c2ecf20Sopenharmony_ci * a higher level. While dealing with the user
128c2ecf20Sopenharmony_ci * (display/resolving)
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_cistruct arch_hw_breakpoint {
158c2ecf20Sopenharmony_ci	unsigned long	address;
168c2ecf20Sopenharmony_ci	unsigned long	mask;
178c2ecf20Sopenharmony_ci	u8		len;
188c2ecf20Sopenharmony_ci	u8		type;
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <linux/kdebug.h>
228c2ecf20Sopenharmony_ci#include <linux/percpu.h>
238c2ecf20Sopenharmony_ci#include <linux/list.h>
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Available HW breakpoint length encodings */
268c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_LEN_X		0x40
278c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_LEN_1		0x40
288c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_LEN_2		0x44
298c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_LEN_4		0x4c
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
328c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_LEN_8		0x48
338c2ecf20Sopenharmony_ci#endif
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Available HW breakpoint type encodings */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* trigger on instruction execute */
388c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_EXECUTE	0x80
398c2ecf20Sopenharmony_ci/* trigger on memory write */
408c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_WRITE	0x81
418c2ecf20Sopenharmony_ci/* trigger on memory read or write */
428c2ecf20Sopenharmony_ci#define X86_BREAKPOINT_RW	0x83
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* Total number of available HW breakpoint registers */
458c2ecf20Sopenharmony_ci#define HBP_NUM 4
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic inline int hw_breakpoint_slots(int type)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	return HBP_NUM;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistruct perf_event_attr;
538c2ecf20Sopenharmony_cistruct perf_event;
548c2ecf20Sopenharmony_cistruct pmu;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciextern int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw);
578c2ecf20Sopenharmony_ciextern int hw_breakpoint_arch_parse(struct perf_event *bp,
588c2ecf20Sopenharmony_ci				    const struct perf_event_attr *attr,
598c2ecf20Sopenharmony_ci				    struct arch_hw_breakpoint *hw);
608c2ecf20Sopenharmony_ciextern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
618c2ecf20Sopenharmony_ci					   unsigned long val, void *data);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciint arch_install_hw_breakpoint(struct perf_event *bp);
658c2ecf20Sopenharmony_civoid arch_uninstall_hw_breakpoint(struct perf_event *bp);
668c2ecf20Sopenharmony_civoid hw_breakpoint_pmu_read(struct perf_event *bp);
678c2ecf20Sopenharmony_civoid hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciextern void
708c2ecf20Sopenharmony_ciarch_fill_perf_breakpoint(struct perf_event *bp);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciunsigned long encode_dr7(int drnum, unsigned int len, unsigned int type);
738c2ecf20Sopenharmony_ciint decode_dr7(unsigned long dr7, int bpnum, unsigned *len, unsigned *type);
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciextern int arch_bp_generic_fields(int x86_len, int x86_type,
768c2ecf20Sopenharmony_ci				  int *gen_len, int *gen_type);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciextern struct pmu perf_ops_bp;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#endif	/* _I386_HW_BREAKPOINT_H */
81