1/*
2 * Copyright (C) 2001-2002 Hewlett-Packard Co
3 *               Stephane Eranian <eranian@hpl.hp.com>
4 */
5
6#ifndef _ASM_IA64_PERFMON_H
7#define _ASM_IA64_PERFMON_H
8
9/*
10 * perfmon comamnds supported on all CPU models
11 */
12#define PFM_WRITE_PMCS		0x01
13#define PFM_WRITE_PMDS		0x02
14#define PFM_READ_PMDS		0x03
15#define PFM_STOP		0x04
16#define PFM_START		0x05
17#define PFM_ENABLE		0x06
18#define PFM_DISABLE		0x07
19#define PFM_CREATE_CONTEXT	0x08
20#define PFM_DESTROY_CONTEXT	0x09
21#define PFM_RESTART		0x0a
22#define PFM_PROTECT_CONTEXT	0x0b
23#define PFM_GET_FEATURES	0x0c
24#define PFM_DEBUG		0x0d
25#define PFM_UNPROTECT_CONTEXT	0x0e
26#define PFM_GET_PMC_RESET_VAL	0x0f
27
28
29/*
30 * CPU model specific commands (may not be supported on all models)
31 */
32#define PFM_WRITE_IBRS		0x20
33#define PFM_WRITE_DBRS		0x21
34
35/*
36 * context flags
37 */
38#define PFM_FL_INHERIT_NONE	 0x00	/* never inherit a context across fork (default) */
39#define PFM_FL_INHERIT_ONCE	 0x01	/* clone pfm_context only once across fork() */
40#define PFM_FL_INHERIT_ALL	 0x02	/* always clone pfm_context across fork() */
41#define PFM_FL_NOTIFY_BLOCK    	 0x04	/* block task on user level notifications */
42#define PFM_FL_SYSTEM_WIDE	 0x08	/* create a system wide context */
43
44/*
45 * PMC flags
46 */
47#define PFM_REGFL_OVFL_NOTIFY	0x1	/* send notification on overflow */
48
49/*
50 * PMD/PMC/IBR/DBR return flags (ignored on input)
51 *
52 * Those flags are used on output and must be checked in case EAGAIN is returned
53 * by any of the calls using a pfarg_reg_t or pfarg_dbreg_t structure.
54 */
55#define PFM_REG_RETFL_NOTAVAIL	(1U<<31) /* set if register is implemented but not available */
56#define PFM_REG_RETFL_EINVAL	(1U<<30) /* set if register entry is invalid */
57#define PFM_REG_RETFL_MASK	(PFM_REG_RETFL_NOTAVAIL|PFM_REG_RETFL_EINVAL)
58
59#define PFM_REG_HAS_ERROR(flag)	(((flag) & PFM_REG_RETFL_MASK) != 0)
60
61/*
62 * Request structure used to define a context
63 */
64typedef struct {
65	unsigned long ctx_smpl_entries;	/* how many entries in sampling buffer */
66	unsigned long ctx_smpl_regs[4];	/* which pmds to record on overflow */
67
68	pid_t	      ctx_notify_pid;	/* which process to notify on overflow */
69	int	      ctx_flags;	/* noblock/block, inherit flags */
70	void	      *ctx_smpl_vaddr;	/* returns address of BTB buffer */
71
72	unsigned long ctx_cpu_mask;	/* on which CPU to enable perfmon (systemwide) */
73
74	unsigned long reserved[8];	/* for future use */
75} pfarg_context_t;
76
77/*
78 * Request structure used to write/read a PMC or PMD
79 */
80typedef struct {
81	unsigned int	reg_num;	/* which register */
82	unsigned int	reg_flags;	/* PMC: notify/don't notify. PMD/PMC: return flags */
83	unsigned long	reg_value;	/* configuration (PMC) or initial value (PMD) */
84
85	unsigned long	reg_long_reset;	/* reset after sampling buffer overflow (large) */
86	unsigned long	reg_short_reset;/* reset after counter overflow (small) */
87
88	unsigned long	reg_reset_pmds[4]; /* which other counters to reset on overflow */
89
90	unsigned long   reserved[16];	/* for future use */
91} pfarg_reg_t;
92
93typedef struct {
94	unsigned int	dbreg_num;	/* which register */
95	unsigned int	dbreg_flags;	/* dbregs return flags */
96	unsigned long	dbreg_value;	/* configuration (PMC) or initial value (PMD) */
97	unsigned long	reserved[6];
98} pfarg_dbreg_t;
99
100typedef struct {
101	unsigned int	ft_version;	/* perfmon: major [16-31], minor [0-15] */
102	unsigned int	ft_smpl_version;/* sampling format: major [16-31], minor [0-15] */
103	unsigned long	reserved[4];	/* for future use */
104} pfarg_features_t;
105
106/*
107 * This header is at the beginning of the sampling buffer returned to the user.
108 * It is exported as Read-Only at this point. It is directly followed by the
109 * first record.
110 */
111typedef struct {
112	unsigned int	hdr_version;		/* contains perfmon version (smpl format diffs) */
113	unsigned int	reserved;
114	unsigned long	hdr_entry_size;		/* size of one entry in bytes */
115	unsigned long	hdr_count;		/* how many valid entries */
116	unsigned long	hdr_pmds[4];		/* which pmds are recorded */
117} perfmon_smpl_hdr_t;
118
119/*
120 * Define the version numbers for both perfmon as a whole and the sampling buffer format.
121 */
122#define PFM_VERSION_MAJ		1U
123#define PFM_VERSION_MIN		0U
124#define PFM_VERSION		(((PFM_VERSION_MAJ&0xffff)<<16)|(PFM_VERSION_MIN & 0xffff))
125
126#define PFM_SMPL_VERSION_MAJ	1U
127#define PFM_SMPL_VERSION_MIN	0U
128#define PFM_SMPL_VERSION	(((PFM_SMPL_VERSION_MAJ&0xffff)<<16)|(PFM_SMPL_VERSION_MIN & 0xffff))
129
130
131#define PFM_VERSION_MAJOR(x)	(((x)>>16) & 0xffff)
132#define PFM_VERSION_MINOR(x)	((x) & 0xffff)
133
134typedef struct {
135	int		pid;		/* identification of process */
136	int		cpu;		/* which cpu was used */
137	unsigned long	rate;		/* initial value of overflowed counter */
138	unsigned long	stamp;		/* timestamp */
139	unsigned long	ip;		/* where did the overflow interrupt happened */
140	unsigned long	regs;		/* bitmask of which registers overflowed */
141	unsigned long   period;		/* sampling period used by overflowed counter (smallest pmd index) */
142} perfmon_smpl_entry_t;
143
144extern int perfmonctl(pid_t pid, int cmd, void *arg, int narg);
145
146#ifdef __KERNEL__
147
148extern void pfm_save_regs (struct task_struct *);
149extern void pfm_load_regs (struct task_struct *);
150
151extern int  pfm_inherit (struct task_struct *, struct pt_regs *);
152extern void pfm_context_exit (struct task_struct *);
153extern void pfm_flush_regs (struct task_struct *);
154extern void pfm_cleanup_notifiers (struct task_struct *);
155extern void pfm_cleanup_owners (struct task_struct *);
156extern int  pfm_use_debug_registers(struct task_struct *);
157extern int  pfm_release_debug_registers(struct task_struct *);
158extern int  pfm_cleanup_smpl_buf(struct task_struct *);
159extern void pfm_syst_wide_update_task(struct task_struct *, int);
160extern void perfmon_init_percpu(void);
161
162#endif /* __KERNEL__ */
163
164#endif /* _ASM_IA64_PERFMON_H */
165