Update ia64 patch to 2.5.72-030619
[linux-flexiantxendom0-3.2.10.git] / include / asm-ia64 / perfmon.h
1 /*
2  * Copyright (C) 2001-2003 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 /* obsolete */
18 #define PFM_DISABLE             0x07 /* obsolete */
19 #define PFM_CREATE_CONTEXT      0x08
20 #define PFM_DESTROY_CONTEXT     0x09 /* obsolete use close() */
21 #define PFM_RESTART             0x0a
22 #define PFM_PROTECT_CONTEXT     0x0b /* obsolete */
23 #define PFM_GET_FEATURES        0x0c
24 #define PFM_DEBUG               0x0d
25 #define PFM_UNPROTECT_CONTEXT   0x0e /* obsolete */
26 #define PFM_GET_PMC_RESET_VAL   0x0f
27 #define PFM_LOAD_CONTEXT        0x10
28 #define PFM_UNLOAD_CONTEXT      0x11
29
30 /*
31  * PMU model specific commands (may not be supported on all PMU models)
32  */
33 #define PFM_WRITE_IBRS          0x20
34 #define PFM_WRITE_DBRS          0x21
35
36 /*
37  * context flags
38  */
39 #define PFM_FL_NOTIFY_BLOCK      0x01   /* block task on user level notifications */
40 #define PFM_FL_SYSTEM_WIDE       0x02   /* create a system wide context */
41 #define PFM_FL_UNSECURE          0x04   /* allow unsecure monitoring for non self-monitoring task */
42 #define PFM_FL_OVFL_NO_MSG       0x80   /* do not post overflow/end messages for notification */
43
44 /*
45  * event set flags
46  */
47 #define PFM_SETFL_EXCL_IDLE      0x01   /* exclude idle task (syswide only) XXX: DO NOT USE YET */
48
49 /*
50  * PMC flags
51  */
52 #define PFM_REGFL_OVFL_NOTIFY   0x1     /* send notification on overflow */
53 #define PFM_REGFL_RANDOM        0x2     /* randomize sampling interval   */
54
55 /*
56  * PMD/PMC/IBR/DBR return flags (ignored on input)
57  *
58  * Those flags are used on output and must be checked in case EAGAIN is returned
59  * by any of the calls using a pfarg_reg_t or pfarg_dbreg_t structure.
60  */
61 #define PFM_REG_RETFL_NOTAVAIL  (1UL<<31) /* set if register is implemented but not available */
62 #define PFM_REG_RETFL_EINVAL    (1UL<<30) /* set if register entry is invalid */
63 #define PFM_REG_RETFL_MASK      (PFM_REG_RETFL_NOTAVAIL|PFM_REG_RETFL_EINVAL)
64
65 #define PFM_REG_HAS_ERROR(flag) (((flag) & PFM_REG_RETFL_MASK) != 0)
66
67 typedef unsigned char pfm_uuid_t[16];   /* custom sampling buffer identifier type */
68
69 /*
70  * Request structure used to define a context
71  */
72 typedef struct {
73         pfm_uuid_t    ctx_smpl_buf_id;  /* which buffer format to use (if needed) */
74         unsigned long ctx_flags;        /* noblock/block */
75         unsigned int  ctx_nextra_sets;  /* number of extra event sets (you always get 1) */
76         int           ctx_fd;           /* return arg: unique identification for context */
77         void          *ctx_smpl_vaddr;  /* return arg: virtual address of sampling buffer, is used */
78         unsigned long ctx_reserved[11]; /* for future use */
79 } pfarg_context_t;
80
81 /*
82  * Request structure used to write/read a PMC or PMD
83  */
84 typedef struct {
85         unsigned int    reg_num;           /* which register                             */
86         unsigned int    reg_set;           /* event set for this register                */
87
88         unsigned long   reg_value;         /* initial pmc/pmd value                      */
89         unsigned long   reg_flags;         /* input: pmc/pmd flags, return: reg error    */
90
91         unsigned long   reg_long_reset;    /* reset after buffer overflow notification   */
92         unsigned long   reg_short_reset;   /* reset after counter overflow               */
93
94         unsigned long   reg_reset_pmds[4]; /* which other counters to reset on overflow  */
95         unsigned long   reg_random_seed;   /* seed value when randomization is used      */
96         unsigned long   reg_random_mask;   /* bitmask used to limit random value         */
97         unsigned long   reg_last_reset_val;/* return: PMD last reset value               */
98
99         unsigned long   reg_smpl_pmds[4];  /* which pmds are accessed when PMC overflows */
100         unsigned long   reg_smpl_eventid;  /* opaque sampling event identifier           */
101
102         unsigned long   reserved[3];       /* for future use                             */
103 } pfarg_reg_t;
104
105 typedef struct {
106         unsigned int    dbreg_num;              /* which debug register        */
107         unsigned int    dbreg_set;              /* event set for this register */
108         unsigned long   dbreg_value;            /* value for debug register    */
109         unsigned long   dbreg_flags;            /* return: dbreg error         */
110         unsigned long   dbreg_reserved[1];      /* for future use              */
111 } pfarg_dbreg_t;
112
113 typedef struct {
114         unsigned int    ft_version;     /* perfmon: major [16-31], minor [0-15] */
115         unsigned int    ft_reserved;    /* reserved for future use              */
116         unsigned long   reserved[4];    /* for future use                       */
117 } pfarg_features_t;
118
119 typedef struct {
120         pid_t           load_pid;         /* process to load the context into */
121         unsigned int    load_set;         /* first event set to load          */
122         unsigned long   load_reserved[2]; /* for future use                   */
123 } pfarg_load_t;
124
125 typedef struct {
126         int             msg_type;               /* generic message header */
127         int             msg_ctx_fd;             /* generic message header */
128         unsigned long   msg_tstamp;             /* for perf tuning */
129         unsigned int    msg_active_set;         /* active set at the time of overflow */
130         unsigned long   msg_ovfl_pmds[4];       /* which PMDs overflowed */
131 } pfm_ovfl_msg_t;
132
133 typedef struct {
134         int             msg_type;               /* generic message header */
135         int             msg_ctx_fd;             /* generic message header */
136         unsigned long   msg_tstamp;             /* for perf tuning */
137 } pfm_end_msg_t;
138
139 typedef struct {
140         int             msg_type;               /* type of the message */
141         int             msg_ctx_fd;             /* unique identifier for the context */
142         unsigned long   msg_tstamp;             /* for perf tuning */
143 } pfm_gen_msg_t;
144
145 #define PFM_MSG_OVFL    1       /* an overflow happened */
146 #define PFM_MSG_END     2       /* task to which context was attached ended */
147
148 typedef union {
149         pfm_ovfl_msg_t  pfm_ovfl_msg;
150         pfm_end_msg_t   pfm_end_msg;
151         pfm_gen_msg_t   pfm_gen_msg;
152 } pfm_msg_t;
153
154 /*
155  * Define the version numbers for both perfmon as a whole and the sampling buffer format.
156  */
157 #define PFM_VERSION_MAJ          2U
158 #define PFM_VERSION_MIN          0U
159 #define PFM_SMPL_HDR_VERSION_MAJ 2U
160 #define PFM_SMPL_HDR_VERSION_MIN 0U
161 #define PFM_VERSION              (((PFM_VERSION_MAJ&0xffff)<<16)|(PFM_VERSION_MIN & 0xffff))
162 #define PFM_VERSION_MAJOR(x)     (((x)>>16) & 0xffff)
163 #define PFM_VERSION_MINOR(x)     ((x) & 0xffff)
164
165
166 /*
167  * miscellaneous architected definitions
168  */
169 #define PMU_FIRST_COUNTER       4       /* first counting monitor (PMC/PMD) */
170 #define PMU_MAX_PMCS            256     /* maximum architected number of PMC registers */
171 #define PMU_MAX_PMDS            256     /* maximum architected number of PMD registers */
172
173 #ifdef __KERNEL__
174
175 extern long perfmonctl(int fd, int cmd, void *arg, int narg);
176
177 extern void pfm_save_regs (struct task_struct *);
178 extern void pfm_load_regs (struct task_struct *);
179
180 extern void pfm_exit_thread(struct task_struct *);
181 extern int  pfm_use_debug_registers(struct task_struct *);
182 extern int  pfm_release_debug_registers(struct task_struct *);
183 extern void pfm_syst_wide_update_task(struct task_struct *, unsigned long info, int is_ctxswin);
184 extern void pfm_inherit(struct task_struct *task, struct pt_regs *regs);
185 extern void pfm_init_percpu(void);
186 extern void pfm_handle_work(void);
187
188 /*
189  * Reset PMD register flags
190  */
191 #define PFM_PMD_NO_RESET        0
192 #define PFM_PMD_LONG_RESET      1
193 #define PFM_PMD_SHORT_RESET     2
194
195 typedef struct {
196         unsigned int notify_user:1;     /* notify user program of overflow                           */
197         unsigned int reset_pmds :2;     /* PFM_PMD_NO_RESET, PFM_PMD_LONG_RESET, PFM_PMD_SHORT_RESET */
198         unsigned int block:1;           /* block monitored task on kernel exit                       */
199         unsigned int stop_monitoring:1; /* will mask monitoring via PMCx.plm                         */
200         unsigned int reserved:26;       /* for future use                                            */
201 } pfm_ovfl_ctrl_t;
202
203 typedef struct {
204         unsigned long   ovfl_pmds[4];   /* bitmask of overflowed pmds                            */
205         unsigned long   ovfl_notify[4]; /* bitmask of overflow pmds which asked for notification */
206         unsigned long   pmd_value;      /* current 64-bit value of 1st pmd which overflowed      */
207         unsigned long   pmd_last_reset; /* last reset value of 1st pmd which overflowed          */
208         unsigned long   pmd_eventid;    /* eventid associated with 1st pmd which overflowed      */
209         unsigned int    active_set;     /* event set active at the time of the overflow          */
210         unsigned int    reserved1;
211         unsigned long   smpl_pmds[4];
212         unsigned long   smpl_pmds_values[PMU_MAX_PMDS];
213         pfm_ovfl_ctrl_t ovfl_ctrl;      /* return: perfmon controls to set by handler            */
214 } pfm_ovfl_arg_t;
215
216
217 typedef struct _pfm_buffer_fmt_t {
218         char            *fmt_name;
219         pfm_uuid_t      fmt_uuid;
220         size_t          fmt_arg_size;
221         unsigned long   fmt_flags;
222
223         int             (*fmt_validate)(struct task_struct *task, unsigned int flags, int cpu, void *arg);
224         int             (*fmt_getsize)(struct task_struct *task, unsigned int flags, int cpu, void *arg, unsigned long *size);
225         int             (*fmt_init)(struct task_struct *task, void *buf, unsigned int flags, int cpu, void *arg);
226         int             (*fmt_handler)(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, struct pt_regs *regs);
227         int             (*fmt_restart)(struct task_struct *task, pfm_ovfl_ctrl_t *ctrl, void *buf, struct pt_regs *regs);
228         int             (*fmt_restart_active)(struct task_struct *task, pfm_ovfl_ctrl_t *ctrl, void *buf, struct pt_regs *regs);
229         int             (*fmt_exit)(struct task_struct *task, void *buf, struct pt_regs *regs);
230
231         struct _pfm_buffer_fmt_t *fmt_next;
232         struct _pfm_buffer_fmt_t *fmt_prev;
233 } pfm_buffer_fmt_t;
234
235 extern int pfm_register_buffer_fmt(pfm_buffer_fmt_t *fmt);
236 extern int pfm_unregister_buffer_fmt(pfm_uuid_t uuid);
237
238 /*
239  * perfmon interface exported to modules
240  */
241 extern long pfm_mod_fast_read_pmds(struct task_struct *, unsigned long mask[4], unsigned long *addr, struct pt_regs *regs);
242 extern long pfm_mod_read_pmds(struct task_struct *, pfarg_reg_t *req, unsigned int nreq, struct pt_regs *regs);
243 extern long pfm_mod_write_pmcs(struct task_struct *, pfarg_reg_t *req, unsigned int nreq, struct pt_regs *regs);
244
245 /*
246  * describe the content of the local_cpu_date->pfm_syst_info field
247  */
248 #define PFM_CPUINFO_SYST_WIDE   0x1     /* if set a system wide session exists */
249 #define PFM_CPUINFO_DCR_PP      0x2     /* if set the system wide session has started */
250 #define PFM_CPUINFO_EXCL_IDLE   0x4     /* the system wide session excludes the idle task */
251
252 #endif /* __KERNEL__ */
253
254 #endif /* _ASM_IA64_PERFMON_H */