xref: /freebsd/sys/dev/hwpmc/hwpmc_powerpc.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2013 Justin Hibbits
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 #ifndef _DEV_HWPMC_POWERPC_H_
32 #define	_DEV_HWPMC_POWERPC_H_ 1
33 
34 #ifdef _KERNEL
35 
36 #define	POWERPC_PMC_CAPS	(PMC_CAP_INTERRUPT | PMC_CAP_USER |     \
37 				 PMC_CAP_SYSTEM | PMC_CAP_EDGE |	\
38 				 PMC_CAP_THRESHOLD | PMC_CAP_READ |	\
39 				 PMC_CAP_WRITE | PMC_CAP_INVERT |	\
40 				 PMC_CAP_QUALIFIER)
41 
42 #define POWERPC_PMC_KERNEL_ENABLE	(0x1 << 30)
43 #define POWERPC_PMC_USER_ENABLE		(0x1 << 31)
44 
45 #define POWERPC_PMC_ENABLE	(POWERPC_PMC_KERNEL_ENABLE | POWERPC_PMC_USER_ENABLE)
46 #define	POWERPC_RELOAD_COUNT_TO_PERFCTR_VALUE(V)	(0x80000000-(V))
47 #define	POWERPC_PERFCTR_VALUE_TO_RELOAD_COUNT(P)	(0x80000000-(P))
48 
49 #define	POWERPC_MAX_PMC_VALUE	0x7fffffffUL
50 
51 #define	POWERPC_PMC_HAS_OVERFLOWED(n) (powerpc_pmcn_read(n) & (0x1 << 31))
52 
53 /*
54  * PMC value is used with OVERFLOWCNT to simulate a 64-bit counter to the
55  * machine independent part of hwpmc.
56  */
57 #define	PPC_OVERFLOWCNT(pm)	(pm)->pm_md.pm_powerpc.pm_powerpc_overflowcnt
58 #define	PPC_OVERFLOWCNT_MAX	0x200000000UL
59 
60 struct powerpc_cpu {
61 	enum pmc_class	pc_class;
62 	struct pmc_hw	pc_ppcpmcs[];
63 };
64 
65 struct pmc_ppc_event {
66 	enum pmc_event pe_event;
67 	uint32_t pe_flags;
68 #define  PMC_FLAG_PMC1	0x01
69 #define  PMC_FLAG_PMC2	0x02
70 #define  PMC_FLAG_PMC3	0x04
71 #define  PMC_FLAG_PMC4	0x08
72 #define  PMC_FLAG_PMC5	0x10
73 #define  PMC_FLAG_PMC6	0x20
74 #define  PMC_FLAG_PMC7	0x40
75 #define  PMC_FLAG_PMC8	0x80
76 	uint32_t pe_code;
77 };
78 
79 extern struct powerpc_cpu **powerpc_pcpu;
80 extern struct pmc_ppc_event *ppc_event_codes;
81 extern size_t ppc_event_codes_size;
82 extern int ppc_event_first;
83 extern int ppc_event_last;
84 extern int ppc_max_pmcs;
85 extern enum pmc_class ppc_class;
86 
87 extern void (*powerpc_set_pmc)(int cpu, int ri, int config);
88 extern pmc_value_t (*powerpc_pmcn_read)(unsigned int pmc);
89 extern void (*powerpc_pmcn_write)(unsigned int pmc, uint32_t val);
90 extern void (*powerpc_resume_pmc)(bool ie);
91 
92 int pmc_e500_initialize(struct pmc_mdep *pmc_mdep);
93 int pmc_mpc7xxx_initialize(struct pmc_mdep *pmc_mdep);
94 int pmc_ppc970_initialize(struct pmc_mdep *pmc_mdep);
95 int pmc_power8_initialize(struct pmc_mdep *pmc_mdep);
96 
97 int powerpc_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc);
98 int powerpc_get_config(int cpu, int ri, struct pmc **ppm);
99 int powerpc_pcpu_init(struct pmc_mdep *md, int cpu);
100 int powerpc_pcpu_fini(struct pmc_mdep *md, int cpu);
101 int powerpc_allocate_pmc(int cpu, int ri, struct pmc *pm,
102     const struct pmc_op_pmcallocate *a);
103 int powerpc_release_pmc(int cpu, int ri, struct pmc *pmc);
104 int powerpc_start_pmc(int cpu, int ri);
105 int powerpc_stop_pmc(int cpu, int ri);
106 int powerpc_config_pmc(int cpu, int ri, struct pmc *pm);
107 pmc_value_t powerpc_pmcn_read_default(unsigned int pmc);
108 void powerpc_pmcn_write_default(unsigned int pmc, uint32_t val);
109 int powerpc_read_pmc(int cpu, int ri, pmc_value_t *v);
110 int powerpc_write_pmc(int cpu, int ri, pmc_value_t v);
111 int powerpc_pmc_intr(struct trapframe *tf);
112 
113 #endif /* _KERNEL */
114 
115 #endif	/* _DEV_HWPMC_POWERPC_H_ */
116