18c2ecf20Sopenharmony_ci/**
28c2ecf20Sopenharmony_ci * @file op_x86_model.h
38c2ecf20Sopenharmony_ci * interface to x86 model-specific MSR operations
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * @remark Copyright 2002 OProfile authors
68c2ecf20Sopenharmony_ci * @remark Read the file COPYING
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * @author Graydon Hoare
98c2ecf20Sopenharmony_ci * @author Robert Richter <robert.richter@amd.com>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef OP_X86_MODEL_H
138c2ecf20Sopenharmony_ci#define OP_X86_MODEL_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <asm/types.h>
168c2ecf20Sopenharmony_ci#include <asm/perf_event.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct op_msr {
198c2ecf20Sopenharmony_ci	unsigned long	addr;
208c2ecf20Sopenharmony_ci	u64		saved;
218c2ecf20Sopenharmony_ci};
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct op_msrs {
248c2ecf20Sopenharmony_ci	struct op_msr *counters;
258c2ecf20Sopenharmony_ci	struct op_msr *controls;
268c2ecf20Sopenharmony_ci	struct op_msr *multiplex;
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistruct pt_regs;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct oprofile_operations;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* The model vtable abstracts the differences between
348c2ecf20Sopenharmony_ci * various x86 CPU models' perfctr support.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_cistruct op_x86_model_spec {
378c2ecf20Sopenharmony_ci	unsigned int	num_counters;
388c2ecf20Sopenharmony_ci	unsigned int	num_controls;
398c2ecf20Sopenharmony_ci	unsigned int	num_virt_counters;
408c2ecf20Sopenharmony_ci	u64		reserved;
418c2ecf20Sopenharmony_ci	u16		event_mask;
428c2ecf20Sopenharmony_ci	int		(*init)(struct oprofile_operations *ops);
438c2ecf20Sopenharmony_ci	int		(*fill_in_addresses)(struct op_msrs * const msrs);
448c2ecf20Sopenharmony_ci	void		(*setup_ctrs)(struct op_x86_model_spec const *model,
458c2ecf20Sopenharmony_ci				      struct op_msrs const * const msrs);
468c2ecf20Sopenharmony_ci	int		(*check_ctrs)(struct pt_regs * const regs,
478c2ecf20Sopenharmony_ci				      struct op_msrs const * const msrs);
488c2ecf20Sopenharmony_ci	void		(*start)(struct op_msrs const * const msrs);
498c2ecf20Sopenharmony_ci	void		(*stop)(struct op_msrs const * const msrs);
508c2ecf20Sopenharmony_ci	void		(*shutdown)(struct op_msrs const * const msrs);
518c2ecf20Sopenharmony_ci#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
528c2ecf20Sopenharmony_ci	void		(*switch_ctrl)(struct op_x86_model_spec const *model,
538c2ecf20Sopenharmony_ci				       struct op_msrs const * const msrs);
548c2ecf20Sopenharmony_ci#endif
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct op_counter_config;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline void op_x86_warn_in_use(int counter)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	/*
628c2ecf20Sopenharmony_ci	 * The warning indicates an already running counter. If
638c2ecf20Sopenharmony_ci	 * oprofile doesn't collect data, then try using a different
648c2ecf20Sopenharmony_ci	 * performance counter on your platform to monitor the desired
658c2ecf20Sopenharmony_ci	 * event. Delete counter #%d from the desired event by editing
668c2ecf20Sopenharmony_ci	 * the /usr/share/oprofile/%s/<cpu>/events file. If the event
678c2ecf20Sopenharmony_ci	 * cannot be monitored by any other counter, contact your
688c2ecf20Sopenharmony_ci	 * hardware or BIOS vendor.
698c2ecf20Sopenharmony_ci	 */
708c2ecf20Sopenharmony_ci	pr_warn("oprofile: counter #%d on cpu #%d may already be used\n",
718c2ecf20Sopenharmony_ci		counter, smp_processor_id());
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline void op_x86_warn_reserved(int counter)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	pr_warn("oprofile: counter #%d is already reserved\n", counter);
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciextern u64 op_x86_get_ctrl(struct op_x86_model_spec const *model,
808c2ecf20Sopenharmony_ci			   struct op_counter_config *counter_config);
818c2ecf20Sopenharmony_ciextern int op_x86_phys_to_virt(int phys);
828c2ecf20Sopenharmony_ciextern int op_x86_virt_to_phys(int virt);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciextern struct op_x86_model_spec op_ppro_spec;
858c2ecf20Sopenharmony_ciextern struct op_x86_model_spec op_p4_spec;
868c2ecf20Sopenharmony_ciextern struct op_x86_model_spec op_p4_ht2_spec;
878c2ecf20Sopenharmony_ciextern struct op_x86_model_spec op_amd_spec;
888c2ecf20Sopenharmony_ciextern struct op_x86_model_spec op_arch_perfmon_spec;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#endif /* OP_X86_MODEL_H */
91