xref: /freebsd/sys/dev/hwpmc/hwpmc_uncore.h (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
1 /*-
2  * Copyright (c) 2010 Fabien Thomas
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 #ifndef _DEV_HWPMC_UNCORE_H_
30 #define	_DEV_HWPMC_UNCORE_H_ 1
31 
32 /*
33  * Fixed-function PMCs.
34  */
35 struct pmc_md_ucf_op_pmcallocate {
36 	uint16_t	pm_ucf_flags;	/* additional flags */
37 };
38 
39 #define	UCF_EN		0x1
40 #define	UCF_PMI		0x4
41 
42 /*
43  * Programmable PMCs.
44  */
45 struct pmc_md_ucp_op_pmcallocate {
46 	uint32_t	pm_ucp_config;
47 };
48 
49 #define	UCP_EVSEL(C)	((C) & 0xFF)
50 #define	UCP_UMASK(C)	((C) & 0xFF00)
51 #define	UCP_CTRR	(1 << 17)
52 #define	UCP_EDGE	(1 << 18)
53 #define	UCP_INT		(1 << 20)
54 #define	UCP_EN		(1 << 22)
55 #define	UCP_INV		(1 << 23)
56 #define	UCP_CMASK(C)	(((C) & 0xFF) << 24)
57 
58 #ifdef	_KERNEL
59 
60 #define	DCTL_FLAG_UNC_PMI	(1ULL << 13)
61 
62 /*
63  * Fixed-function counters.
64  */
65 
66 #define	UCF_MASK				0xF
67 
68 #define	UCF_CTR0				0x394
69 
70 #define	UCF_OFFSET				32
71 #define UCF_OFFSET_SB				29
72 #define	UCF_CTRL				0x395
73 
74 /*
75  * Programmable counters.
76  */
77 
78 #define	UCP_PMC0				0x3B0
79 #define	UCP_EVSEL0				0x3C0
80 #define UCP_OPCODE_MATCH			0x396
81 #define UCP_CB0_EVSEL0				0x700
82 
83 /*
84  * Simplified programming interface in Intel Performance Architecture
85  * v2 and later.
86  */
87 
88 #define	UC_GLOBAL_STATUS			0x392
89 #define	UC_GLOBAL_CTRL				0x391
90 #define	UC_GLOBAL_OVF_CTRL			0x393
91 
92 #define	UC_GLOBAL_STATUS_FLAG_CLRCHG		(1ULL << 63)
93 #define	UC_GLOBAL_STATUS_FLAG_OVFPMI		(1ULL << 61)
94 #define	UC_GLOBAL_CTRL_FLAG_FRZ			(1ULL << 63)
95 #define	UC_GLOBAL_CTRL_FLAG_ENPMICORE0		(1ULL << 48)
96 
97 /*
98  * Model specific registers.
99  */
100 
101 #define MSR_GQ_SNOOP_MESF			0x301
102 
103 struct pmc_md_ucf_pmc {
104 	uint64_t	pm_ucf_ctrl;
105 };
106 
107 struct pmc_md_ucp_pmc {
108 	uint32_t	pm_ucp_evsel;
109 };
110 
111 /*
112  * Prototypes.
113  */
114 
115 int	pmc_uncore_initialize(struct pmc_mdep *_md, int _maxcpu);
116 void	pmc_uncore_finalize(struct pmc_mdep *_md);
117 
118 void	pmc_uncore_mark_started(int _cpu, int _pmc);
119 
120 int	pmc_ucf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
121 void	pmc_ucf_finalize(struct pmc_mdep *_md);
122 
123 int	pmc_ucp_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
124 	    int _flags);
125 void	pmc_ucp_finalize(struct pmc_mdep *_md);
126 
127 #endif	/* _KERNEL */
128 #endif	/* _DEV_HWPMC_UNCORE_H */
129