]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/hwpmc/hwpmc_piv.h
sys/dev: further adoption of SPDX licensing ID tags.
[FreeBSD/FreeBSD.git] / sys / dev / hwpmc / hwpmc_piv.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2005, Joseph Koshy
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30
31 /* Machine dependent interfaces */
32
33 #ifndef _DEV_HWPMC_PIV_H_
34 #define _DEV_HWPMC_PIV_H_ 1
35
36 /* Intel P4 PMCs */
37
38 #define P4_NPMCS                18
39 #define P4_NESCR                45
40 #define P4_INVALID_PMC_INDEX    -1
41 #define P4_MAX_ESCR_PER_EVENT   2
42 #define P4_MAX_PMC_PER_ESCR     3
43
44 #define P4_CCCR_OVF                     (1U << 31)
45 #define P4_CCCR_CASCADE                 (1 << 30)
46 #define P4_CCCR_OVF_PMI_T1              (1 << 27)
47 #define P4_CCCR_OVF_PMI_T0              (1 << 26)
48 #define P4_CCCR_FORCE_OVF               (1 << 25)
49 #define P4_CCCR_EDGE                    (1 << 24)
50 #define P4_CCCR_THRESHOLD_SHIFT         20
51 #define P4_CCCR_THRESHOLD_MASK          0x00F00000
52 #define P4_CCCR_TO_THRESHOLD(C)         (((C) << P4_CCCR_THRESHOLD_SHIFT) & \
53         P4_CCCR_THRESHOLD_MASK)
54 #define P4_CCCR_COMPLEMENT              (1 << 19)
55 #define P4_CCCR_COMPARE                 (1 << 18)
56 #define P4_CCCR_ACTIVE_THREAD_SHIFT     16
57 #define P4_CCCR_ACTIVE_THREAD_MASK      0x00030000
58 #define P4_CCCR_TO_ACTIVE_THREAD(T)     (((T) << P4_CCCR_ACTIVE_THREAD_SHIFT) & \
59         P4_CCCR_ACTIVE_THREAD_MASK)
60 #define P4_CCCR_ESCR_SELECT_SHIFT       13
61 #define P4_CCCR_ESCR_SELECT_MASK        0x0000E000
62 #define P4_CCCR_TO_ESCR_SELECT(E)       (((E) << P4_CCCR_ESCR_SELECT_SHIFT) & \
63         P4_CCCR_ESCR_SELECT_MASK)
64 #define P4_CCCR_ENABLE                  (1 << 12)
65 #define P4_CCCR_VALID_BITS              (P4_CCCR_OVF | P4_CCCR_CASCADE | \
66     P4_CCCR_OVF_PMI_T1 | P4_CCCR_OVF_PMI_T0 | P4_CCCR_FORCE_OVF |        \
67     P4_CCCR_EDGE | P4_CCCR_THRESHOLD_MASK | P4_CCCR_COMPLEMENT |         \
68     P4_CCCR_COMPARE | P4_CCCR_ESCR_SELECT_MASK | P4_CCCR_ENABLE)
69
70 #define P4_ESCR_EVENT_SELECT_SHIFT      25
71 #define P4_ESCR_EVENT_SELECT_MASK       0x7E000000
72 #define P4_ESCR_TO_EVENT_SELECT(E)      (((E) << P4_ESCR_EVENT_SELECT_SHIFT) & \
73         P4_ESCR_EVENT_SELECT_MASK)
74 #define P4_ESCR_EVENT_MASK_SHIFT        9
75 #define P4_ESCR_EVENT_MASK_MASK         0x01FFFE00
76 #define P4_ESCR_TO_EVENT_MASK(M)        (((M) << P4_ESCR_EVENT_MASK_SHIFT) & \
77         P4_ESCR_EVENT_MASK_MASK)
78 #define P4_ESCR_TAG_VALUE_SHIFT         5
79 #define P4_ESCR_TAG_VALUE_MASK          0x000001E0
80 #define P4_ESCR_TO_TAG_VALUE(T)         (((T) << P4_ESCR_TAG_VALUE_SHIFT) & \
81         P4_ESCR_TAG_VALUE_MASK)
82 #define P4_ESCR_TAG_ENABLE              0x00000010
83 #define P4_ESCR_T0_OS                   0x00000008
84 #define P4_ESCR_T0_USR                  0x00000004
85 #define P4_ESCR_T1_OS                   0x00000002
86 #define P4_ESCR_T1_USR                  0x00000001
87 #define P4_ESCR_OS                      P4_ESCR_T0_OS
88 #define P4_ESCR_USR                     P4_ESCR_T0_USR
89 #define P4_ESCR_VALID_BITS              (P4_ESCR_EVENT_SELECT_MASK |    \
90     P4_ESCR_EVENT_MASK_MASK | P4_ESCR_TAG_VALUE_MASK |                  \
91     P4_ESCR_TAG_ENABLE | P4_ESCR_T0_OS | P4_ESCR_T0_USR | P4_ESCR_T1_OS \
92     P4_ESCR_T1_USR)
93
94 #define P4_PERFCTR_MASK                 0xFFFFFFFFFFLL /* 40 bits */
95 #define P4_PERFCTR_OVERFLOWED(PMC)      ((rdpmc(PMC) & (1LL << 39)) == 0)
96
97 #define P4_CCCR_MSR_FIRST               0x360 /* MSR_BPU_CCCR0 */
98 #define P4_PERFCTR_MSR_FIRST            0x300 /* MSR_BPU_COUNTER0 */
99
100 #define P4_RELOAD_COUNT_TO_PERFCTR_VALUE(V)     (1 - (V))
101 #define P4_PERFCTR_VALUE_TO_RELOAD_COUNT(P)     (1 - (P))
102
103 struct pmc_md_p4_op_pmcallocate {
104         uint32_t        pm_p4_cccrconfig;
105         uint32_t        pm_p4_escrconfig;
106 };
107
108 #ifdef _KERNEL
109
110 /* MD extension for 'struct pmc' */
111 struct pmc_md_p4_pmc {
112         uint32_t        pm_p4_cccrvalue;
113         uint32_t        pm_p4_escrvalue;
114         uint32_t        pm_p4_escr;
115         uint32_t        pm_p4_escrmsr;
116 };
117
118
119 /*
120  * Prototypes
121  */
122
123 int     pmc_p4_initialize(struct pmc_mdep *_md, int _ncpus);
124 void    pmc_p4_finalize(struct pmc_mdep *md);
125
126 #endif /* _KERNEL */
127 #endif /* _DEV_HWPMC_PIV_H_ */