#ifndef _MACHINE_PCTR_H_
#define _MACHINE_PCTR_H_
#include <sys/ioccom.h>
typedef u_int64_t pctrval;
#define PCTR_NUM 4
struct pctrst {
u_int pctr_fn[PCTR_NUM];
pctrval pctr_tsc;
pctrval pctr_hwc[PCTR_NUM];
};
#define P5CTR_K 0x40
#define P5CTR_U 0x80
#define P5CTR_C 0x100
#define PCTR_U 0x010000
#define PCTR_K 0x020000
#define PCTR_E 0x040000
#define PCTR_EN 0x400000
#define PCTR_I 0x800000
#define PCTR_UM_M 0x0800
#define PCTR_UM_E 0x0400
#define PCTR_UM_S 0x0200
#define PCTR_UM_I 0x0100
#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I)
#define PCTR_UM_A 0x2000
#define PCTR_UM_SHIFT 8
#define PCTR_CM_SHIFT 24
#define PCIOCRD _IOR('c', 1, struct pctrst)
#define PCIOCS0 _IOW('c', 8, unsigned int)
#define PCIOCS1 _IOW('c', 9, unsigned int)
#define PCIOCS2 _IOW('c', 10, unsigned int)
#define PCIOCS3 _IOW('c', 11, unsigned int)
#define _PATH_PCTR "/dev/pctr"
#define rdtsc() \
({ \
pctrval v; \
__asm volatile ("rdtsc" : "=A" (v)); \
v; \
})
#define rdpmc(ctr) \
({ \
pctrval v; \
__asm volatile ("rdpmc\n" \
"\tandl $0xff, %%edx" \
: "=A" (v) : "c" (ctr)); \
v; \
})
#ifdef _KERNEL
#define rdmsr(msr) \
({ \
pctrval v; \
__asm volatile ("rdmsr" : "=A" (v) : "c" (msr)); \
v; \
})
#define wrmsr(msr, v) \
__asm volatile ("wrmsr" :: "A" ((u_int64_t) (v)), "c" (msr));
void pctrattach(int);
int pctropen(dev_t, int, int, struct proc *);
int pctrclose(dev_t, int, int, struct proc *);
int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *);
#endif
#endif