xref: /freebsd/sys/arm64/include/pmc_mdep.h (revision c190fb35f35cc163b61e582a49115680b0d49dcc)
1412042e2SAndrew Turner /*-
2412042e2SAndrew Turner  * Copyright (c) 2009 Rui Paulo <rpaulo@FreeBSD.org>
3412042e2SAndrew Turner  * All rights reserved.
4412042e2SAndrew Turner  *
5412042e2SAndrew Turner  * Redistribution and use in source and binary forms, with or without
6412042e2SAndrew Turner  * modification, are permitted provided that the following conditions
7412042e2SAndrew Turner  * are met:
8412042e2SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
9412042e2SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
10412042e2SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright
11412042e2SAndrew Turner  *    notice, this list of conditions and the following disclaimer in the
12412042e2SAndrew Turner  *    documentation and/or other materials provided with the distribution.
13412042e2SAndrew Turner  *
14412042e2SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15412042e2SAndrew Turner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16412042e2SAndrew Turner  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17412042e2SAndrew Turner  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
18412042e2SAndrew Turner  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19412042e2SAndrew Turner  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20412042e2SAndrew Turner  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21412042e2SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22412042e2SAndrew Turner  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
23412042e2SAndrew Turner  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24412042e2SAndrew Turner  * POSSIBILITY OF SUCH DAMAGE.
25412042e2SAndrew Turner  */
26412042e2SAndrew Turner 
27412042e2SAndrew Turner #ifndef _MACHINE_PMC_MDEP_H_
28412042e2SAndrew Turner #define	_MACHINE_PMC_MDEP_H_
29412042e2SAndrew Turner 
30bc88bb2bSRuslan Bukin #define	PMC_MDEP_CLASS_INDEX_ARMV8	1
31e3572eb6SAleksandr Rybalko #define	PMC_MDEP_CLASS_INDEX_DMC620_CD2 2
32e3572eb6SAleksandr Rybalko #define	PMC_MDEP_CLASS_INDEX_DMC620_C	3
33e3572eb6SAleksandr Rybalko #define	PMC_MDEP_CLASS_INDEX_CMN600 	4
34bc88bb2bSRuslan Bukin /*
35bc88bb2bSRuslan Bukin  * On the ARMv8 platform we support the following PMCs.
36bc88bb2bSRuslan Bukin  *
37bc88bb2bSRuslan Bukin  * ARMV8	ARM Cortex-A53/57/72 processors
38bc88bb2bSRuslan Bukin  */
39bc88bb2bSRuslan Bukin #include <dev/hwpmc/hwpmc_arm64.h>
40e3572eb6SAleksandr Rybalko #include <dev/hwpmc/hwpmc_cmn600.h>
41e3572eb6SAleksandr Rybalko #include <dev/hwpmc/hwpmc_dmc620.h>
42e3572eb6SAleksandr Rybalko #include <dev/hwpmc/pmu_dmc620_reg.h>
43e3572eb6SAleksandr Rybalko #include <machine/cmn600_reg.h>
44bc88bb2bSRuslan Bukin 
45412042e2SAndrew Turner union pmc_md_op_pmcallocate {
4627ea55fcSMitchell Horne 	struct {
4727ea55fcSMitchell Horne 		uint32_t	pm_md_config;
4827ea55fcSMitchell Horne 	};
49e3572eb6SAleksandr Rybalko 	struct pmc_md_cmn600_pmu_op_pmcallocate	pm_cmn600;
50e3572eb6SAleksandr Rybalko 	struct pmc_md_dmc620_pmu_op_pmcallocate	pm_dmc620;
5127ea55fcSMitchell Horne 	uint64_t		__pad[4];
52412042e2SAndrew Turner };
53412042e2SAndrew Turner 
54412042e2SAndrew Turner /* Logging */
55412042e2SAndrew Turner #define	PMCLOG_READADDR		PMCLOG_READ64
56412042e2SAndrew Turner #define	PMCLOG_EMITADDR		PMCLOG_EMIT64
57412042e2SAndrew Turner 
58412042e2SAndrew Turner #ifdef	_KERNEL
59412042e2SAndrew Turner union pmc_md_pmc {
60bc88bb2bSRuslan Bukin 	struct pmc_md_arm64_pmc		pm_arm64;
61e3572eb6SAleksandr Rybalko 	struct pmc_md_cmn600_pmc	pm_cmn600;
62e3572eb6SAleksandr Rybalko 	struct pmc_md_dmc620_pmc	pm_dmc620;
63412042e2SAndrew Turner };
64412042e2SAndrew Turner 
65*aba91805SMitchell Horne #define	PMC_IN_KERNEL_STACK(va)	kstack_contains(curthread, (va), sizeof(va))
66bc88bb2bSRuslan Bukin #define	PMC_IN_KERNEL(va)	INKERNEL((va))
67bc88bb2bSRuslan Bukin #define	PMC_IN_USERSPACE(va)	((va) <= VM_MAXUSER_ADDRESS)
68f85aa858SOleksandr Tymoshenko #define	PMC_TRAPFRAME_TO_PC(TF)	((TF)->tf_elr)
69bc88bb2bSRuslan Bukin #define	PMC_TRAPFRAME_TO_FP(TF)	((TF)->tf_x[29])
70412042e2SAndrew Turner 
71bc88bb2bSRuslan Bukin /*
72bc88bb2bSRuslan Bukin  * Prototypes
73bc88bb2bSRuslan Bukin  */
74bc88bb2bSRuslan Bukin struct pmc_mdep *pmc_arm64_initialize(void);
75bc88bb2bSRuslan Bukin void	pmc_arm64_finalize(struct pmc_mdep *_md);
76e3572eb6SAleksandr Rybalko 
77e3572eb6SAleksandr Rybalko /* Optional class for CMN-600 controler's PMU. */
78e3572eb6SAleksandr Rybalko int pmc_cmn600_initialize(struct pmc_mdep *md);
79e3572eb6SAleksandr Rybalko void	pmc_cmn600_finalize(struct pmc_mdep *_md);
80e3572eb6SAleksandr Rybalko int pmc_cmn600_nclasses(void);
81e3572eb6SAleksandr Rybalko 
82e3572eb6SAleksandr Rybalko /* Optional class for DMC-620 controler's PMU. */
83e3572eb6SAleksandr Rybalko int pmc_dmc620_initialize_cd2(struct pmc_mdep *md);
84e3572eb6SAleksandr Rybalko void	pmc_dmc620_finalize_cd2(struct pmc_mdep *_md);
85e3572eb6SAleksandr Rybalko int pmc_dmc620_initialize_c(struct pmc_mdep *md);
86e3572eb6SAleksandr Rybalko void	pmc_dmc620_finalize_c(struct pmc_mdep *_md);
87e3572eb6SAleksandr Rybalko int pmc_dmc620_nclasses(void);
88e3572eb6SAleksandr Rybalko 
89412042e2SAndrew Turner #endif /* _KERNEL */
90412042e2SAndrew Turner 
91412042e2SAndrew Turner #endif /* !_MACHINE_PMC_MDEP_H_ */
92