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