xref: /freebsd-src/sys/dev/hwpmc/hwpmc_core.h (revision 440e7cb4aca9b6f5662ab492bd016d8ed0f85da0)
10cfab8ddSJoseph Koshy /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
40cfab8ddSJoseph Koshy  * Copyright (c) 2008 Joseph Koshy
50cfab8ddSJoseph Koshy  * All rights reserved.
60cfab8ddSJoseph Koshy  *
70cfab8ddSJoseph Koshy  * Redistribution and use in source and binary forms, with or without
80cfab8ddSJoseph Koshy  * modification, are permitted provided that the following conditions
90cfab8ddSJoseph Koshy  * are met:
100cfab8ddSJoseph Koshy  * 1. Redistributions of source code must retain the above copyright
110cfab8ddSJoseph Koshy  *    notice, this list of conditions and the following disclaimer.
120cfab8ddSJoseph Koshy  * 2. Redistributions in binary form must reproduce the above copyright
130cfab8ddSJoseph Koshy  *    notice, this list of conditions and the following disclaimer in the
140cfab8ddSJoseph Koshy  *    documentation and/or other materials provided with the distribution.
150cfab8ddSJoseph Koshy  *
160cfab8ddSJoseph Koshy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170cfab8ddSJoseph Koshy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180cfab8ddSJoseph Koshy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190cfab8ddSJoseph Koshy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200cfab8ddSJoseph Koshy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210cfab8ddSJoseph Koshy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220cfab8ddSJoseph Koshy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230cfab8ddSJoseph Koshy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240cfab8ddSJoseph Koshy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250cfab8ddSJoseph Koshy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260cfab8ddSJoseph Koshy  * SUCH DAMAGE.
270cfab8ddSJoseph Koshy  */
280cfab8ddSJoseph Koshy 
290cfab8ddSJoseph Koshy #ifndef _DEV_HWPMC_CORE_H_
300cfab8ddSJoseph Koshy #define	_DEV_HWPMC_CORE_H_ 1
310cfab8ddSJoseph Koshy 
32411c83ccSKonstantin Belousov #define	IA32_PERF_CAPABILITIES		0x345
33411c83ccSKonstantin Belousov #define	PERFCAP_LBR_FORMAT		0x003f
34411c83ccSKonstantin Belousov #define	PERFCAP_PEBS_TRAP		0x0040
35411c83ccSKonstantin Belousov #define	PERFCAP_PEBS_SAVEARCH		0x0080
36411c83ccSKonstantin Belousov #define	PERFCAP_PEBS_RECFORMAT		0x0f00
37411c83ccSKonstantin Belousov #define	PERFCAP_SMM_FREEZE		0x1000
38411c83ccSKonstantin Belousov #define	PERFCAP_FW_WRITE		0x2000	/* full width write aliases */
39411c83ccSKonstantin Belousov 
400cfab8ddSJoseph Koshy #define	IAF_OS		0x1
410cfab8ddSJoseph Koshy #define	IAF_USR		0x2
420cfab8ddSJoseph Koshy #define	IAF_ANY		0x4
430cfab8ddSJoseph Koshy #define	IAF_PMI		0x8
440cfab8ddSJoseph Koshy 
450cfab8ddSJoseph Koshy /*
460cfab8ddSJoseph Koshy  * Programmable PMCs.
470cfab8ddSJoseph Koshy  */
480cfab8ddSJoseph Koshy struct pmc_md_iap_op_pmcallocate {
491a4614a5SAlexander Motin 	uint64_t	pm_iap_config;
501e862e5aSFabien Thomas 	uint64_t	pm_iap_rsp;
510cfab8ddSJoseph Koshy };
520cfab8ddSJoseph Koshy 
530cfab8ddSJoseph Koshy #define	IAP_EVSEL(C)	((C) & 0xFF)
54959826caSMatt Macy #define	IAP_UMASK(C)	(((C) & 0xFF) << 8)
550cfab8ddSJoseph Koshy #define	IAP_USR		(1 << 16)
560cfab8ddSJoseph Koshy #define	IAP_OS		(1 << 17)
570cfab8ddSJoseph Koshy #define	IAP_EDGE	(1 << 18)
580cfab8ddSJoseph Koshy #define	IAP_INT		(1 << 20)
590cfab8ddSJoseph Koshy #define	IAP_ANY		(1 << 21)
600cfab8ddSJoseph Koshy #define	IAP_EN		(1 << 22)
610cfab8ddSJoseph Koshy #define	IAP_INV		(1 << 23)
620cfab8ddSJoseph Koshy #define	IAP_CMASK(C)	(((C) & 0xFF) << 24)
630cfab8ddSJoseph Koshy 
64959826caSMatt Macy #define	IAP_EVSEL_GET(C)	((C) & 0xFF)
65959826caSMatt Macy #define	IAP_UMASK_GET(C)	(((C) & 0xFF00) >> 8)
66959826caSMatt Macy 
671e862e5aSFabien Thomas #define	IA_OFFCORE_RSP_MASK_I7WM	0x000000F7FF
681e862e5aSFabien Thomas #define	IA_OFFCORE_RSP_MASK_SBIB	0x3F807F8FFF
691fa7f10bSFabien Thomas 
700cfab8ddSJoseph Koshy #ifdef	_KERNEL
710cfab8ddSJoseph Koshy 
720cfab8ddSJoseph Koshy /*
730cfab8ddSJoseph Koshy  * Fixed-function counters.
740cfab8ddSJoseph Koshy  */
75f4a9c304SGeorge V. Neville-Neil 
761a4614a5SAlexander Motin #define	IAF_MASK				0x000000010000000f
770cfab8ddSJoseph Koshy 
780cfab8ddSJoseph Koshy #define	IAF_CTR0				0x309
790cfab8ddSJoseph Koshy #define	IAF_CTR1				0x30A
800cfab8ddSJoseph Koshy #define	IAF_CTR2				0x30B
810cfab8ddSJoseph Koshy 
82f4a9c304SGeorge V. Neville-Neil /*
83f4a9c304SGeorge V. Neville-Neil  * The IAF_CTRL MSR is laid out in the following way.
84f4a9c304SGeorge V. Neville-Neil  *
85f4a9c304SGeorge V. Neville-Neil  * Bit Position    Use
861a4614a5SAlexander Motin  * 63 - 45         Reserved (do not touch)
871a4614a5SAlexander Motin  * 44              Ctr 3 Adaptive Record (v5)
881a4614a5SAlexander Motin  * 43 - 41         Reserved (do not touch)
891a4614a5SAlexander Motin  * 40              Ctr 2 Adaptive Record (v5)
901a4614a5SAlexander Motin  * 39 - 37         Reserved (do not touch)
911a4614a5SAlexander Motin  * 36              Ctr 1 Adaptive Record (v5)
921a4614a5SAlexander Motin  * 35 - 33         Reserved (do not touch)
931a4614a5SAlexander Motin  * 32              Ctr 0 Adaptive Record (v5)
941a4614a5SAlexander Motin  * 15              Ctr 3 PMI
951a4614a5SAlexander Motin  * 14              Ctr 3 Any Thread (v3)
961a4614a5SAlexander Motin  * 13-12           Ctr 3 Enable
97f4a9c304SGeorge V. Neville-Neil  * 11              Ctr 2 PMI
98245b0565SAlexander Motin  * 10              Ctr 2 Any Thread (v3)
99f4a9c304SGeorge V. Neville-Neil  * 9-8             Ctr 2 Enable
100f4a9c304SGeorge V. Neville-Neil  * 7               Ctr 1 PMI
101245b0565SAlexander Motin  * 6               Ctr 1 Any Thread (v3)
102f4a9c304SGeorge V. Neville-Neil  * 5-4             Ctr 1 Enable
103f4a9c304SGeorge V. Neville-Neil  * 3               Ctr 0 PMI
104245b0565SAlexander Motin  * 2               Ctr 0 Any Thread (v3)
105f4a9c304SGeorge V. Neville-Neil  * 1-0             Ctr 0 Enable (3: All Levels, 2: User, 1: OS, 0: Disable)
106f4a9c304SGeorge V. Neville-Neil  */
107f4a9c304SGeorge V. Neville-Neil 
1080cfab8ddSJoseph Koshy #define	IAF_OFFSET				32
1090cfab8ddSJoseph Koshy #define	IAF_CTRL				0x38D
1100cfab8ddSJoseph Koshy 
1110cfab8ddSJoseph Koshy /*
1120cfab8ddSJoseph Koshy  * Programmable counters.
1130cfab8ddSJoseph Koshy  */
1140cfab8ddSJoseph Koshy 
1151fa7f10bSFabien Thomas #define	IAP_PMC0				0x0C1
116411c83ccSKonstantin Belousov #define	IAP_A_PMC0				0x4C1
117f4a9c304SGeorge V. Neville-Neil 
118f4a9c304SGeorge V. Neville-Neil /*
119f4a9c304SGeorge V. Neville-Neil  * IAP_EVSEL(n) is laid out in the following way.
120f4a9c304SGeorge V. Neville-Neil  *
121f4a9c304SGeorge V. Neville-Neil  * Bit Position    Use
1221a4614a5SAlexander Motin  * 63-35           Reserved (do not touch)
1231a4614a5SAlexander Motin  * 34              Adaptive Record (v5)
1241a4614a5SAlexander Motin  * 33              IN_TX (v3)
1251a4614a5SAlexander Motin  * 32              IN_TXCP (v3)
126f4a9c304SGeorge V. Neville-Neil  * 31-24           Counter Mask
127f4a9c304SGeorge V. Neville-Neil  * 23              Invert
128f4a9c304SGeorge V. Neville-Neil  * 22              Enable
129245b0565SAlexander Motin  * 21              Any Thread (v3)
130f4a9c304SGeorge V. Neville-Neil  * 20              APIC Interrupt Enable
131f4a9c304SGeorge V. Neville-Neil  * 19              Pin Control
132f4a9c304SGeorge V. Neville-Neil  * 18              Edge Detect
133f4a9c304SGeorge V. Neville-Neil  * 17              OS
134f4a9c304SGeorge V. Neville-Neil  * 16              User
135f4a9c304SGeorge V. Neville-Neil  * 15-8            Unit Mask
136f4a9c304SGeorge V. Neville-Neil  * 7-0             Event Select
137f4a9c304SGeorge V. Neville-Neil  */
138f4a9c304SGeorge V. Neville-Neil 
1390cfab8ddSJoseph Koshy #define	IAP_EVSEL0				0x186
1400cfab8ddSJoseph Koshy 
1410cfab8ddSJoseph Koshy /*
1420cfab8ddSJoseph Koshy  * Simplified programming interface in Intel Performance Architecture
1430cfab8ddSJoseph Koshy  * v2 and later.
1440cfab8ddSJoseph Koshy  */
1451fa7f10bSFabien Thomas 
1460cfab8ddSJoseph Koshy #define	IA_GLOBAL_STATUS			0x38E
1470cfab8ddSJoseph Koshy #define	IA_GLOBAL_CTRL				0x38F
148f4a9c304SGeorge V. Neville-Neil 
149f4a9c304SGeorge V. Neville-Neil /*
150453130d9SPedro F. Giffuni  * IA_GLOBAL_CTRL is laid out in the following way.
151f4a9c304SGeorge V. Neville-Neil  *
152f4a9c304SGeorge V. Neville-Neil  * Bit Position    Use
1531a4614a5SAlexander Motin  * 63-49           Reserved (do not touch)
1541a4614a5SAlexander Motin  * 48              Perf Metrics Enable (v5)
1551a4614a5SAlexander Motin  * 47-36           Reserved (do not touch)
1561a4614a5SAlexander Motin  * 35              IAF Counter 3 Enable
157f4a9c304SGeorge V. Neville-Neil  * 34              IAF Counter 2 Enable
158f4a9c304SGeorge V. Neville-Neil  * 33              IAF Counter 1 Enable
159f4a9c304SGeorge V. Neville-Neil  * 32              IAF Counter 0 Enable
160f4a9c304SGeorge V. Neville-Neil  * 31-0            Depends on programmable counters
161f4a9c304SGeorge V. Neville-Neil  */
162f4a9c304SGeorge V. Neville-Neil 
1630cfab8ddSJoseph Koshy #define	IA_GLOBAL_OVF_CTRL			0x390
164245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_RESET			0x390
165245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_SET			0x391		/* v4 */
1660cfab8ddSJoseph Koshy 
1670cfab8ddSJoseph Koshy #define	IA_GLOBAL_STATUS_FLAG_CONDCHG		(1ULL << 63)
1680cfab8ddSJoseph Koshy #define	IA_GLOBAL_STATUS_FLAG_OVFBUF		(1ULL << 62)
169245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_FLAG_OVFUNCORE		(1ULL << 61)	/* v3 */
170245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_FLAG_ASCI		(1ULL << 60)	/* v4 */
171245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_FLAG_CTR_FRZ		(1ULL << 59)	/* v4 */
172245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_FLAG_LBP_FRZ		(1ULL << 58)	/* v4 */
173245b0565SAlexander Motin #define	IA_GLOBAL_STATUS_FLAG_TRACETOPAPMI	(1ULL << 55)	/* v4 */
174245b0565SAlexander Motin 
175245b0565SAlexander Motin #define	IA_GLOBAL_INUSE				0x392		/* v4 */
1760cfab8ddSJoseph Koshy 
1771fa7f10bSFabien Thomas /*
1781fa7f10bSFabien Thomas  * Offcore response configuration.
1791fa7f10bSFabien Thomas  */
1801fa7f10bSFabien Thomas #define	IA_OFFCORE_RSP0				0x1A6
1811fa7f10bSFabien Thomas #define	IA_OFFCORE_RSP1				0x1A7
1821fa7f10bSFabien Thomas 
1830cfab8ddSJoseph Koshy struct pmc_md_iaf_pmc {
1840cfab8ddSJoseph Koshy 	uint64_t	pm_iaf_ctrl;
1850cfab8ddSJoseph Koshy };
1860cfab8ddSJoseph Koshy 
1870cfab8ddSJoseph Koshy struct pmc_md_iap_pmc {
1881a4614a5SAlexander Motin 	uint64_t	pm_iap_evsel;
1891e862e5aSFabien Thomas 	uint64_t	pm_iap_rsp;
1900cfab8ddSJoseph Koshy };
1910cfab8ddSJoseph Koshy 
1920cfab8ddSJoseph Koshy /*
1930cfab8ddSJoseph Koshy  * Prototypes.
1940cfab8ddSJoseph Koshy  */
1950cfab8ddSJoseph Koshy 
196026346c8SAttilio Rao int	pmc_core_initialize(struct pmc_mdep *_md, int _maxcpu,
197026346c8SAttilio Rao 	    int _version_override);
1980cfab8ddSJoseph Koshy void	pmc_core_finalize(struct pmc_mdep *_md);
1990cfab8ddSJoseph Koshy 
2000cfab8ddSJoseph Koshy int	pmc_iaf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
2010cfab8ddSJoseph Koshy 
2020cfab8ddSJoseph Koshy int	pmc_iap_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
2030cfab8ddSJoseph Koshy 	    int _flags);
2040cfab8ddSJoseph Koshy 
2050cfab8ddSJoseph Koshy #endif	/* _KERNEL */
2060cfab8ddSJoseph Koshy #endif	/* _DEV_HWPMC_CORE_H */
207