1206089Sfabient/*-
2206089Sfabient * Copyright (c) 2010 Fabien Thomas
3206089Sfabient * All rights reserved.
4206089Sfabient *
5206089Sfabient * Redistribution and use in source and binary forms, with or without
6206089Sfabient * modification, are permitted provided that the following conditions
7206089Sfabient * are met:
8206089Sfabient * 1. Redistributions of source code must retain the above copyright
9206089Sfabient *    notice, this list of conditions and the following disclaimer.
10206089Sfabient * 2. Redistributions in binary form must reproduce the above copyright
11206089Sfabient *    notice, this list of conditions and the following disclaimer in the
12206089Sfabient *    documentation and/or other materials provided with the distribution.
13206089Sfabient *
14206089Sfabient * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15206089Sfabient * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16206089Sfabient * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17206089Sfabient * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18206089Sfabient * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19206089Sfabient * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20206089Sfabient * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21206089Sfabient * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22206089Sfabient * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23206089Sfabient * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24206089Sfabient * SUCH DAMAGE.
25206089Sfabient *
26206089Sfabient * $FreeBSD$
27206089Sfabient */
28206089Sfabient
29206089Sfabient#ifndef _DEV_HWPMC_UNCORE_H_
30206089Sfabient#define	_DEV_HWPMC_UNCORE_H_ 1
31206089Sfabient
32206089Sfabient/*
33206089Sfabient * Fixed-function PMCs.
34206089Sfabient */
35206089Sfabientstruct pmc_md_ucf_op_pmcallocate {
36206089Sfabient	uint16_t	pm_ucf_flags;	/* additional flags */
37206089Sfabient};
38206089Sfabient
39206089Sfabient#define	UCF_EN		0x1
40206089Sfabient#define	UCF_PMI		0x4
41206089Sfabient
42206089Sfabient/*
43206089Sfabient * Programmable PMCs.
44206089Sfabient */
45206089Sfabientstruct pmc_md_ucp_op_pmcallocate {
46206089Sfabient	uint32_t	pm_ucp_config;
47206089Sfabient};
48206089Sfabient
49206089Sfabient#define	UCP_EVSEL(C)	((C) & 0xFF)
50206089Sfabient#define	UCP_UMASK(C)	((C) & 0xFF00)
51206089Sfabient#define	UCP_CTRR	(1 << 17)
52206089Sfabient#define	UCP_EDGE	(1 << 18)
53206089Sfabient#define	UCP_INT		(1 << 20)
54206089Sfabient#define	UCP_EN		(1 << 22)
55206089Sfabient#define	UCP_INV		(1 << 23)
56206089Sfabient#define	UCP_CMASK(C)	(((C) & 0xFF) << 24)
57206089Sfabient
58206089Sfabient#ifdef	_KERNEL
59206089Sfabient
60206089Sfabient#define	DCTL_FLAG_UNC_PMI	(1ULL << 13)
61206089Sfabient
62206089Sfabient/*
63206089Sfabient * Fixed-function counters.
64206089Sfabient */
65206089Sfabient
66206089Sfabient#define	UCF_MASK				0xF
67206089Sfabient
68206089Sfabient#define	UCF_CTR0				0x394
69206089Sfabient
70206089Sfabient#define	UCF_OFFSET				32
71232366Sdavide#define UCF_OFFSET_SB				29
72206089Sfabient#define	UCF_CTRL				0x395
73206089Sfabient
74206089Sfabient/*
75206089Sfabient * Programmable counters.
76206089Sfabient */
77206089Sfabient
78206089Sfabient#define	UCP_PMC0				0x3B0
79206089Sfabient#define	UCP_EVSEL0				0x3C0
80206089Sfabient#define UCP_OPCODE_MATCH			0x396
81232366Sdavide#define UCP_CB0_EVSEL0				0x700
82206089Sfabient
83206089Sfabient/*
84206089Sfabient * Simplified programming interface in Intel Performance Architecture
85206089Sfabient * v2 and later.
86206089Sfabient */
87206089Sfabient
88206089Sfabient#define	UC_GLOBAL_STATUS			0x392
89206089Sfabient#define	UC_GLOBAL_CTRL				0x391
90206089Sfabient#define	UC_GLOBAL_OVF_CTRL			0x393
91206089Sfabient
92206089Sfabient#define	UC_GLOBAL_STATUS_FLAG_CLRCHG		(1ULL << 63)
93206089Sfabient#define	UC_GLOBAL_STATUS_FLAG_OVFPMI		(1ULL << 61)
94206089Sfabient#define	UC_GLOBAL_CTRL_FLAG_FRZ			(1ULL << 63)
95206089Sfabient#define	UC_GLOBAL_CTRL_FLAG_ENPMICORE0		(1ULL << 48)
96206089Sfabient
97229469Sfabient/*
98229469Sfabient * Model specific registers.
99229469Sfabient */
100229469Sfabient
101229469Sfabient#define MSR_GQ_SNOOP_MESF			0x301
102229469Sfabient
103206089Sfabientstruct pmc_md_ucf_pmc {
104206089Sfabient	uint64_t	pm_ucf_ctrl;
105206089Sfabient};
106206089Sfabient
107206089Sfabientstruct pmc_md_ucp_pmc {
108206089Sfabient	uint32_t	pm_ucp_evsel;
109206089Sfabient};
110206089Sfabient
111206089Sfabient/*
112206089Sfabient * Prototypes.
113206089Sfabient */
114206089Sfabient
115206089Sfabientint	pmc_uncore_initialize(struct pmc_mdep *_md, int _maxcpu);
116206089Sfabientvoid	pmc_uncore_finalize(struct pmc_mdep *_md);
117206089Sfabient
118206089Sfabientint	pmc_ucf_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width);
119206089Sfabientvoid	pmc_ucf_finalize(struct pmc_mdep *_md);
120206089Sfabient
121206089Sfabientint	pmc_ucp_initialize(struct pmc_mdep *_md, int _maxcpu, int _npmc, int _width,
122206089Sfabient	    int _flags);
123206089Sfabientvoid	pmc_ucp_finalize(struct pmc_mdep *_md);
124206089Sfabient
125206089Sfabient#endif	/* _KERNEL */
126206089Sfabient#endif	/* _DEV_HWPMC_UNCORE_H */
127