hwpmc_core.h revision 206089
1185363Sjkoshy/*-
2185363Sjkoshy * Copyright (c) 2008 Joseph Koshy
3185363Sjkoshy * All rights reserved.
4185363Sjkoshy *
5185363Sjkoshy * Redistribution and use in source and binary forms, with or without
6185363Sjkoshy * modification, are permitted provided that the following conditions
7185363Sjkoshy * are met:
8185363Sjkoshy * 1. Redistributions of source code must retain the above copyright
9185363Sjkoshy *    notice, this list of conditions and the following disclaimer.
10185363Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11185363Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12185363Sjkoshy *    documentation and/or other materials provided with the distribution.
13185363Sjkoshy *
14185363Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15185363Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16185363Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17185363Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18185363Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19185363Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20185363Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21185363Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22185363Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23185363Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24185363Sjkoshy * SUCH DAMAGE.
25185363Sjkoshy *
26185363Sjkoshy * $FreeBSD: head/sys/dev/hwpmc/hwpmc_core.h 206089 2010-04-02 13:23:49Z fabient $
27185363Sjkoshy */
28185363Sjkoshy
29185363Sjkoshy#ifndef _DEV_HWPMC_CORE_H_
30185363Sjkoshy#define	_DEV_HWPMC_CORE_H_ 1
31185363Sjkoshy
32185363Sjkoshy/*
33185363Sjkoshy * Fixed-function PMCs.
34185363Sjkoshy */
35185363Sjkoshystruct pmc_md_iaf_op_pmcallocate {
36185363Sjkoshy	uint16_t	pm_iaf_flags;	/* additional flags */
37185363Sjkoshy};
38185363Sjkoshy
39185363Sjkoshy#define	IAF_OS		0x1
40185363Sjkoshy#define	IAF_USR		0x2
41185363Sjkoshy#define	IAF_ANY		0x4
42185363Sjkoshy#define	IAF_PMI		0x8
43185363Sjkoshy
44185363Sjkoshy/*
45185363Sjkoshy * Programmable PMCs.
46185363Sjkoshy */
47185363Sjkoshystruct pmc_md_iap_op_pmcallocate {
48185363Sjkoshy	uint32_t	pm_iap_config;
49206089Sfabient	uint32_t	pm_iap_rsp;
50185363Sjkoshy};
51185363Sjkoshy
52185363Sjkoshy#define	IAP_EVSEL(C)	((C) & 0xFF)
53185363Sjkoshy#define	IAP_UMASK(C)	((C) & 0xFF00)
54185363Sjkoshy#define	IAP_USR		(1 << 16)
55185363Sjkoshy#define	IAP_OS		(1 << 17)
56185363Sjkoshy#define	IAP_EDGE	(1 << 18)
57185363Sjkoshy#define	IAP_INT		(1 << 20)
58185363Sjkoshy#define	IAP_ANY		(1 << 21)
59185363Sjkoshy#define	IAP_EN		(1 << 22)
60185363Sjkoshy#define	IAP_INV		(1 << 23)
61185363Sjkoshy#define	IAP_CMASK(C)	(((C) & 0xFF) << 24)
62185363Sjkoshy
63206089Sfabient#define	IA_OFFCORE_RSP_MASK	0xF7FF
64206089Sfabient
65185363Sjkoshy#ifdef	_KERNEL
66185363Sjkoshy
67185363Sjkoshy/*
68185363Sjkoshy * Fixed-function counters.
69185363Sjkoshy */
70185363Sjkoshy#define	IAF_MASK				0xF
71185363Sjkoshy
72185363Sjkoshy#define	IAF_CTR0				0x309
73185363Sjkoshy#define	IAF_CTR1				0x30A
74185363Sjkoshy#define	IAF_CTR2				0x30B
75185363Sjkoshy
76185363Sjkoshy#define	IAF_OFFSET				32
77185363Sjkoshy#define	IAF_CTRL				0x38D
78185363Sjkoshy
79185363Sjkoshy/*
80185363Sjkoshy * Programmable counters.
81185363Sjkoshy */
82206089Sfabient
83185363Sjkoshy#define	IAP_PMC0				0x0C1
84185363Sjkoshy#define	IAP_EVSEL0				0x186
85185363Sjkoshy
86185363Sjkoshy/*
87185363Sjkoshy * Simplified programming interface in Intel Performance Architecture
88185363Sjkoshy * v2 and later.
89185363Sjkoshy */
90206089Sfabient
91185363Sjkoshy#define	IA_GLOBAL_STATUS			0x38E
92185363Sjkoshy#define	IA_GLOBAL_CTRL				0x38F
93185363Sjkoshy#define	IA_GLOBAL_OVF_CTRL			0x390
94185363Sjkoshy
95185363Sjkoshy#define	IA_GLOBAL_STATUS_FLAG_CONDCHG		(1ULL << 63)
96185363Sjkoshy#define	IA_GLOBAL_STATUS_FLAG_OVFBUF		(1ULL << 62)
97185363Sjkoshy
98206089Sfabient/*
99206089Sfabient * Offcore response configuration.
100206089Sfabient */
101206089Sfabient#define	IA_OFFCORE_RSP0				0x1A6
102206089Sfabient#define	IA_OFFCORE_RSP1				0x1A7
103206089Sfabient
104185363Sjkoshystruct pmc_md_iaf_pmc {
105185363Sjkoshy	uint64_t	pm_iaf_ctrl;
106185363Sjkoshy};
107185363Sjkoshy
108185363Sjkoshystruct pmc_md_iap_pmc {
109185363Sjkoshy	uint32_t	pm_iap_evsel;
110206089Sfabient	uint32_t	pm_iap_rsp;
111185363Sjkoshy};
112185363Sjkoshy
113185363Sjkoshy/*
114185363Sjkoshy * Prototypes.
115185363Sjkoshy */
116185363Sjkoshy
117185363Sjkoshyint	pmc_core_initialize(struct pmc_mdep *_md, int _maxcpu);
118185363Sjkoshyvoid	pmc_core_finalize(struct pmc_mdep *_md);
119185363Sjkoshy
120185363Sjkoshyvoid	pmc_core_mark_started(int _cpu, int _pmc);
121185363Sjkoshy
122185363Sjkoshyint	pmc_iaf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
123185363Sjkoshyvoid	pmc_iaf_finalize(struct pmc_mdep *_md);
124185363Sjkoshy
125185363Sjkoshyint	pmc_iap_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
126185363Sjkoshy	    int _flags);
127185363Sjkoshyvoid	pmc_iap_finalize(struct pmc_mdep *_md);
128185363Sjkoshy
129185363Sjkoshy#endif	/* _KERNEL */
130185363Sjkoshy#endif	/* _DEV_HWPMC_CORE_H */
131