1/*-
2 * Copyright (c) 2005, Joseph Koshy
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29/* Machine dependent interfaces */
30
31#ifndef _DEV_HWPMC_PPRO_H_
32#define	_DEV_HWPMC_PPRO_H_
33
34/* Intel PPro, Celeron, P-II, P-III, Pentium-M PMCS */
35
36#define	P6_NPMCS	2		/* 2 PMCs */
37
38#define	P6_EVSEL_CMASK_MASK		0xFF000000
39#define	P6_EVSEL_TO_CMASK(C)		(((C) & 0xFF) << 24)
40#define	P6_EVSEL_INV			(1 << 23)
41#define	P6_EVSEL_EN			(1 << 22)
42#define	P6_EVSEL_INT			(1 << 20)
43#define	P6_EVSEL_PC			(1 << 19)
44#define	P6_EVSEL_E			(1 << 18)
45#define	P6_EVSEL_OS			(1 << 17)
46#define	P6_EVSEL_USR			(1 << 16)
47#define	P6_EVSEL_UMASK_MASK		0x0000FF00
48#define	P6_EVSEL_TO_UMASK(U)		(((U) & 0xFF) << 8)
49#define	P6_EVSEL_EVENT_SELECT(ES)	((ES) & 0xFF)
50#define	P6_EVSEL_RESERVED		(1 << 21)
51
52#define	P6_MSR_EVSEL0			0x0186
53#define	P6_MSR_EVSEL1			0x0187
54#define	P6_MSR_PERFCTR0			0x00C1
55#define	P6_MSR_PERFCTR1			0x00C2
56
57#define	P6_PERFCTR_READ_MASK		0xFFFFFFFFFFLL	/* 40 bits */
58#define	P6_PERFCTR_WRITE_MASK		0xFFFFFFFFU	/* 32 bits */
59
60#define	P6_RELOAD_COUNT_TO_PERFCTR_VALUE(R)	(-(R))
61#define	P6_PERFCTR_VALUE_TO_RELOAD_COUNT(P)	(-(P))
62
63#define	P6_PMC_HAS_OVERFLOWED(P)	((rdpmc(P) & (1LL << 39)) == 0)
64
65struct pmc_md_ppro_op_pmcallocate {
66	uint32_t	pm_ppro_config;
67};
68
69#ifdef _KERNEL
70
71/* MD extension for 'struct pmc' */
72struct pmc_md_ppro_pmc {
73	uint32_t	pm_ppro_evsel;
74};
75
76/*
77 * Prototypes
78 */
79
80int	pmc_p6_initialize(struct pmc_mdep *_md, int _ncpus);
81void	pmc_p6_finalize(struct pmc_mdep *_md);
82
83#endif /* _KERNEL */
84#endif /* _DEV_HWPMC_PPRO_H_ */
85