code:
/*-
 * Copyright (c) 2005, Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/hwpmc/hwpmc_piv.h 184802 2008-11-09 17:37:54Z jkoshy $
 */

/* Machine dependent interfaces */

#ifndef _DEV_HWPMC_PIV_H_
#define	_DEV_HWPMC_PIV_H_ 1

/* Intel P4 PMCs */

#define	P4_NPMCS		18
#define	P4_NESCR		45
#define	P4_INVALID_PMC_INDEX	-1
#define	P4_MAX_ESCR_PER_EVENT	2
#define	P4_MAX_PMC_PER_ESCR	3

#define	P4_CCCR_OVF			(1 << 31)
#define	P4_CCCR_CASCADE			(1 << 30)
#define	P4_CCCR_OVF_PMI_T1		(1 << 27)
#define	P4_CCCR_OVF_PMI_T0		(1 << 26)
#define	P4_CCCR_FORCE_OVF		(1 << 25)
#define	P4_CCCR_EDGE			(1 << 24)
#define	P4_CCCR_THRESHOLD_SHIFT		20
#define	P4_CCCR_THRESHOLD_MASK		0x00F00000
#define	P4_CCCR_TO_THRESHOLD(C)		(((C) << P4_CCCR_THRESHOLD_SHIFT) & \
	P4_CCCR_THRESHOLD_MASK)
#define	P4_CCCR_COMPLEMENT		(1 << 19)
#define	P4_CCCR_COMPARE			(1 << 18)
#define	P4_CCCR_ACTIVE_THREAD_SHIFT	16
#define	P4_CCCR_ACTIVE_THREAD_MASK	0x00030000
#define	P4_CCCR_TO_ACTIVE_THREAD(T)	(((T) << P4_CCCR_ACTIVE_THREAD_SHIFT) & \
	P4_CCCR_ACTIVE_THREAD_MASK)
#define	P4_CCCR_ESCR_SELECT_SHIFT	13
#define	P4_CCCR_ESCR_SELECT_MASK	0x0000E000
#define	P4_CCCR_TO_ESCR_SELECT(E)	(((E) << P4_CCCR_ESCR_SELECT_SHIFT) & \
	P4_CCCR_ESCR_SELECT_MASK)
#define	P4_CCCR_ENABLE			(1 << 12)
#define	P4_CCCR_VALID_BITS		(P4_CCCR_OVF | P4_CCCR_CASCADE | \
    P4_CCCR_OVF_PMI_T1 | P4_CCCR_OVF_PMI_T0 | P4_CCCR_FORCE_OVF | 	 \
    P4_CCCR_EDGE | P4_CCCR_THRESHOLD_MASK | P4_CCCR_COMPLEMENT |	 \
    P4_CCCR_COMPARE | P4_CCCR_ESCR_SELECT_MASK | P4_CCCR_ENABLE)

#define	P4_ESCR_EVENT_SELECT_SHIFT	25
#define	P4_ESCR_EVENT_SELECT_MASK	0x7E000000
#define	P4_ESCR_TO_EVENT_SELECT(E)	(((E) << P4_ESCR_EVENT_SELECT_SHIFT) & \
	P4_ESCR_EVENT_SELECT_MASK)
#define	P4_ESCR_EVENT_MASK_SHIFT	9
#define	P4_ESCR_EVENT_MASK_MASK		0x01FFFE00
#define	P4_ESCR_TO_EVENT_MASK(M)	(((M) << P4_ESCR_EVENT_MASK_SHIFT) & \
	P4_ESCR_EVENT_MASK_MASK)
#define	P4_ESCR_TAG_VALUE_SHIFT		5
#define	P4_ESCR_TAG_VALUE_MASK		0x000001E0
#define	P4_ESCR_TO_TAG_VALUE(T)		(((T) << P4_ESCR_TAG_VALUE_SHIFT) & \
	P4_ESCR_TAG_VALUE_MASK)
#define	P4_ESCR_TAG_ENABLE 		0x00000010
#define	P4_ESCR_T0_OS			0x00000008
#define	P4_ESCR_T0_USR			0x00000004
#define	P4_ESCR_T1_OS			0x00000002
#define	P4_ESCR_T1_USR			0x00000001
#define	P4_ESCR_OS			P4_ESCR_T0_OS
#define	P4_ESCR_USR			P4_ESCR_T0_USR
#define	P4_ESCR_VALID_BITS		(P4_ESCR_EVENT_SELECT_MASK |	\
    P4_ESCR_EVENT_MASK_MASK | P4_ESCR_TAG_VALUE_MASK | 			\
    P4_ESCR_TAG_ENABLE | P4_ESCR_T0_OS | P4_ESCR_T0_USR | P4_ESCR_T1_OS \
    P4_ESCR_T1_USR)

#define	P4_PERFCTR_MASK			0xFFFFFFFFFFLL /* 40 bits */
#define	P4_PERFCTR_OVERFLOWED(PMC)	((rdpmc(PMC) & (1LL << 39)) == 0)

#define	P4_CCCR_MSR_FIRST		0x360 /* MSR_BPU_CCCR0 */
#define	P4_PERFCTR_MSR_FIRST		0x300 /* MSR_BPU_COUNTER0 */

#define	P4_RELOAD_COUNT_TO_PERFCTR_VALUE(V)	(1 - (V))
#define	P4_PERFCTR_VALUE_TO_RELOAD_COUNT(P)	(1 - (P))

struct pmc_md_p4_op_pmcallocate {
	uint32_t	pm_p4_cccrconfig;
	uint32_t	pm_p4_escrconfig;
};

#ifdef _KERNEL

/* MD extension for 'struct pmc' */
struct pmc_md_p4_pmc {
	uint32_t	pm_p4_cccrvalue;
	uint32_t	pm_p4_escrvalue;
	uint32_t	pm_p4_escr;
	uint32_t	pm_p4_escrmsr;
};

/*
 * Prototypes
 */

int	pmc_p4_initialize(struct pmc_mdep *_md, int _ncpus);
void	pmc_p4_finalize(struct pmc_mdep *md);

#endif /* _KERNEL */
#endif /* _DEV_HWPMC_PIV_H_ */


code:
/*-
 * Copyright (c) 2005, Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/hwpmc/hwpmc_ppro.h 184802 2008-11-09 17:37:54Z jkoshy $
 */

/* Machine dependent interfaces */

#ifndef _DEV_HWPMC_PPRO_H_
#define	_DEV_HWPMC_PPRO_H_

/* Intel PPro, Celeron, P-II, P-III, Pentium-M PMCS */

#define	P6_NPMCS	2		/* 2 PMCs */

#define	P6_EVSEL_CMASK_MASK		0xFF000000
#define	P6_EVSEL_TO_CMASK(C)		(((C) & 0xFF) << 24)
#define	P6_EVSEL_INV			(1 << 23)
#define	P6_EVSEL_EN			(1 << 22)
#define	P6_EVSEL_INT			(1 << 20)
#define	P6_EVSEL_PC			(1 << 19)
#define	P6_EVSEL_E			(1 << 18)
#define	P6_EVSEL_OS			(1 << 17)
#define	P6_EVSEL_USR			(1 << 16)
#define	P6_EVSEL_UMASK_MASK		0x0000FF00
#define	P6_EVSEL_TO_UMASK(U)		(((U) & 0xFF) << 8)
#define	P6_EVSEL_EVENT_SELECT(ES)	((ES) & 0xFF)
#define	P6_EVSEL_RESERVED		(1 << 21)

#define	P6_MSR_EVSEL0			0x0186
#define	P6_MSR_EVSEL1			0x0187
#define	P6_MSR_PERFCTR0			0x00C1
#define	P6_MSR_PERFCTR1			0x00C2

#define	P6_PERFCTR_READ_MASK		0xFFFFFFFFFFLL	/* 40 bits */
#define	P6_PERFCTR_WRITE_MASK		0xFFFFFFFFU	/* 32 bits */

#define	P6_RELOAD_COUNT_TO_PERFCTR_VALUE(R)	(-(R))
#define	P6_PERFCTR_VALUE_TO_RELOAD_COUNT(P)	(-(P))

#define	P6_PMC_HAS_OVERFLOWED(P)	((rdpmc(P) & (1LL << 39)) == 0)

struct pmc_md_ppro_op_pmcallocate {
	uint32_t	pm_ppro_config;
};

#ifdef _KERNEL

/* MD extension for 'struct pmc' */
struct pmc_md_ppro_pmc {
	uint32_t	pm_ppro_evsel;
};

/*
 * Prototypes
 */

int	pmc_p6_initialize(struct pmc_mdep *_md, int _ncpus);
void	pmc_p6_finalize(struct pmc_mdep *_md);

#endif /* _KERNEL */
#endif /* _DEV_HWPMC_PPRO_H_ */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (c) 2008 Joseph Koshy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/hwpmc/hwpmc_tsc.h 184802 2008-11-09 17:37:54Z jkoshy $
 */

#ifndef _DEV_HWPMC_TSC_H_
#define	_DEV_HWPMC_TSC_H_ 1

#ifdef	_KERNEL

#define	TSC_NPMCS	1

/*
 * Prototypes.
 */

int	pmc_tsc_initialize(struct pmc_mdep *_md, int _maxcpu);
void	pmc_tsc_finalize(struct pmc_mdep *_md);
#endif	/* _KERNEL */
#endif	/* _DEV_HWPMC_TSC_H */


code:
/*-
 * Copyright (c) 2010 Fabien Thomas
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/hwpmc/hwpmc_uncore.h 206089 2010-04-02 13:23:49Z fabient $
 */

#ifndef _DEV_HWPMC_UNCORE_H_
#define	_DEV_HWPMC_UNCORE_H_ 1

/*
 * Fixed-function PMCs.
 */
struct pmc_md_ucf_op_pmcallocate {
	uint16_t	pm_ucf_flags;	/* additional flags */
};

#define	UCF_EN		0x1
#define	UCF_PMI		0x4

/*
 * Programmable PMCs.
 */
struct pmc_md_ucp_op_pmcallocate {
	uint32_t	pm_ucp_config;
};

#define	UCP_EVSEL(C)	((C) & 0xFF)
#define	UCP_UMASK(C)	((C) & 0xFF00)
#define	UCP_CTRR	(1 << 17)
#define	UCP_EDGE	(1 << 18)
#define	UCP_INT		(1 << 20)
#define	UCP_EN		(1 << 22)
#define	UCP_INV		(1 << 23)
#define	UCP_CMASK(C)	(((C) & 0xFF) << 24)

#ifdef	_KERNEL

#define	DCTL_FLAG_UNC_PMI	(1ULL << 13)

/*
 * Fixed-function counters.
 */

#define	UCF_MASK				0xF

#define	UCF_CTR0				0x394

#define	UCF_OFFSET				32
#define	UCF_CTRL				0x395

/*
 * Programmable counters.
 */

#define	UCP_PMC0				0x3B0
#define	UCP_EVSEL0				0x3C0
#define UCP_OPCODE_MATCH			0x396

/*
 * Simplified programming interface in Intel Performance Architecture
 * v2 and later.
 */

#define	UC_GLOBAL_STATUS			0x392
#define	UC_GLOBAL_CTRL				0x391
#define	UC_GLOBAL_OVF_CTRL			0x393

#define	UC_GLOBAL_STATUS_FLAG_CLRCHG		(1ULL << 63)
#define	UC_GLOBAL_STATUS_FLAG_OVFPMI		(1ULL << 61)
#define	UC_GLOBAL_CTRL_FLAG_FRZ			(1ULL << 63)
#define	UC_GLOBAL_CTRL_FLAG_ENPMICORE0		(1ULL << 48)

struct pmc_md_ucf_pmc {
	uint64_t	pm_ucf_ctrl;
};

struct pmc_md_ucp_pmc {
	uint32_t	pm_ucp_evsel;
};

/*
 * Prototypes.
 */

int	pmc_uncore_initialize(struct pmc_mdep *_md, int _maxcpu);
void	pmc_uncore_finalize(struct pmc_mdep *_md);

void	pmc_uncore_mark_started(int _cpu, int _pmc);

int	pmc_ucf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
void	pmc_ucf_finalize(struct pmc_mdep *_md);

int	pmc_ucp_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
	    int _flags);
void	pmc_ucp_finalize(struct pmc_mdep *_md);

#endif	/* _KERNEL */
#endif	/* _DEV_HWPMC_UNCORE_H */


code:
/*-
 * Copyright (c) 2009 Rui Paulo <rpaulo@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD: release/9.0.0/sys/dev/hwpmc/hwpmc_xscale.h 200928 2009-12-23 23:16:54Z rpaulo $
 */

#ifndef _DEV_HWPMC_XSCALE_H_
#define _DEV_HWPMC_XSCALE_H_

#define	XSCALE_PMC_CAPS		(PMC_CAP_INTERRUPT | PMC_CAP_USER |     \
				 PMC_CAP_SYSTEM | PMC_CAP_EDGE |	\
				 PMC_CAP_THRESHOLD | PMC_CAP_READ |	\
				 PMC_CAP_WRITE | PMC_CAP_INVERT |	\
				 PMC_CAP_QUALIFIER)

#define	XSCALE_PMNC_ENABLE		0x01	/* Enable all Counters */
#define	XSCALE_PMNC_PMNRESET		0x02	/* Performance Counter Reset */
#define	XSCALE_PMNC_CCNTRESET		0x04	/* Clock Counter Reset */
#define	XSCALE_PMNC_CCNTDIV		0x08	/* Clock Counter Divider */
/* IXP425 only -- first generation */
#define	XSCALE_PMNC_EVT0_MASK		0x00ff000
#define	XSCALE_PMNC_EVT1_MASK		0xff00000

#define	XSCALE_INTEN_CCNT		0x01	/* Enable Clock Counter Int. */
#define	XSCALE_INTEN_PMN0		0x02	/* Enable PMN0 Interrupts */
#define	XSCALE_INTEN_PMN1		0x04	/* Enable PMN1 Interrupts */
#define	XSCALE_INTEN_PMN2		0x08	/* Enable PMN2 Interrupts */
#define	XSCALE_INTEN_PMN3		0x10	/* Enable PMN3 Interrupts */

#define	XSCALE_EVTSEL_EVT0_MASK		0x000000ff
#define	XSCALE_EVTSEL_EVT1_MASK		0x0000ff00
#define	XSCALE_EVTSEL_EVT2_MASK		0x00ff0000
#define	XSCALE_EVTSEL_EVT3_MASK		0xff000000

#define	XSCALE_FLAG_CCNT_OVERFLOW	0x01
#define	XSCALE_FLAG_PMN0_OVERFLOW	0x02
#define	XSCALE_FLAG_PMN1_OVERFLOW	0x04
#define	XSCALE_FLAG_PMN2_OVERFLOW	0x08
#define	XSCALE_FLAG_PMN3_OVERFLOW	0x10

#define	XSCALE_RELOAD_COUNT_TO_PERFCTR_VALUE(R)	(-(R))
#define	XSCALE_PERFCTR_VALUE_TO_RELOAD_COUNT(P)	(-(P))

#ifdef _KERNEL
/* MD extension for 'struct pmc' */
struct pmc_md_xscale_pmc {
	uint32_t	pm_xscale_evsel;
};
#endif /* _KERNEL */
#endif /* _DEV_HWPMC_XSCALE_H_ */