hwpmc_core.h revision 185363
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 185363 2008-11-27 09:00:47Z jkoshy $
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;
49185363Sjkoshy};
50185363Sjkoshy
51185363Sjkoshy#define	IAP_EVSEL(C)	((C) & 0xFF)
52185363Sjkoshy#define	IAP_UMASK(C)	((C) & 0xFF00)
53185363Sjkoshy#define	IAP_USR		(1 << 16)
54185363Sjkoshy#define	IAP_OS		(1 << 17)
55185363Sjkoshy#define	IAP_EDGE	(1 << 18)
56185363Sjkoshy#define	IAP_INT		(1 << 20)
57185363Sjkoshy#define	IAP_ANY		(1 << 21)
58185363Sjkoshy#define	IAP_EN		(1 << 22)
59185363Sjkoshy#define	IAP_INV		(1 << 23)
60185363Sjkoshy#define	IAP_CMASK(C)	(((C) & 0xFF) << 24)
61185363Sjkoshy
62185363Sjkoshy#ifdef	_KERNEL
63185363Sjkoshy
64185363Sjkoshy/*
65185363Sjkoshy * Fixed-function counters.
66185363Sjkoshy */
67185363Sjkoshy#define	IAF_MASK				0xF
68185363Sjkoshy
69185363Sjkoshy#define	IAF_CTR0				0x309
70185363Sjkoshy#define	IAF_CTR1				0x30A
71185363Sjkoshy#define	IAF_CTR2				0x30B
72185363Sjkoshy
73185363Sjkoshy#define	IAF_OFFSET				32
74185363Sjkoshy#define	IAF_CTRL				0x38D
75185363Sjkoshy
76185363Sjkoshy/*
77185363Sjkoshy * Programmable counters.
78185363Sjkoshy */
79185363Sjkoshy#define	IAP_PMC0				0x0C1
80185363Sjkoshy#define	IAP_PMC1				0x0C2
81185363Sjkoshy
82185363Sjkoshy#define	IAP_EVSEL0				0x186
83185363Sjkoshy#define	IAP_EVSEL1				0x187
84185363Sjkoshy
85185363Sjkoshy/*
86185363Sjkoshy * Simplified programming interface in Intel Performance Architecture
87185363Sjkoshy * v2 and later.
88185363Sjkoshy */
89185363Sjkoshy#define	IA_GLOBAL_STATUS			0x38E
90185363Sjkoshy#define	IA_GLOBAL_CTRL				0x38F
91185363Sjkoshy#define	IA_GLOBAL_OVF_CTRL			0x390
92185363Sjkoshy
93185363Sjkoshy#define	IA_GLOBAL_STATUS_FLAG_CONDCHG		(1ULL << 63)
94185363Sjkoshy#define	IA_GLOBAL_STATUS_FLAG_OVFBUF		(1ULL << 62)
95185363Sjkoshy
96185363Sjkoshystruct pmc_md_iaf_pmc {
97185363Sjkoshy	uint64_t	pm_iaf_ctrl;
98185363Sjkoshy};
99185363Sjkoshy
100185363Sjkoshystruct pmc_md_iap_pmc {
101185363Sjkoshy	uint32_t	pm_iap_evsel;
102185363Sjkoshy};
103185363Sjkoshy
104185363Sjkoshy/*
105185363Sjkoshy * Prototypes.
106185363Sjkoshy */
107185363Sjkoshy
108185363Sjkoshyint	pmc_core_initialize(struct pmc_mdep *_md, int _maxcpu);
109185363Sjkoshyvoid	pmc_core_finalize(struct pmc_mdep *_md);
110185363Sjkoshy
111185363Sjkoshyvoid	pmc_core_mark_started(int _cpu, int _pmc);
112185363Sjkoshy
113185363Sjkoshyint	pmc_iaf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
114185363Sjkoshyvoid	pmc_iaf_finalize(struct pmc_mdep *_md);
115185363Sjkoshy
116185363Sjkoshyint	pmc_iap_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
117185363Sjkoshy	    int _flags);
118185363Sjkoshyvoid	pmc_iap_finalize(struct pmc_mdep *_md);
119185363Sjkoshy
120185363Sjkoshy#endif	/* _KERNEL */
121185363Sjkoshy#endif	/* _DEV_HWPMC_CORE_H */
122