xref: /minix3/sys/arch/arm/include/pmc.h (revision 0222260628fde80600502dfa2682b109215cf789)
1 /*	$NetBSD: pmc.h,v 1.3 2002/08/09 05:27:10 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2002 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Allen Briggs for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed for the NetBSD Project by
20  *      Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef _ARM_PMC_H_
39 #define	_ARM_PMC_H_
40 
41 #define	PMC_CLASS_I80200	0x10000		/* i80200-compatible */
42 #define	PMC_TYPE_I80200_CCNT	0x10001		/* cycle counter */
43 #define	PMC_TYPE_I80200_PMCx	0x10002		/* performance counter */
44 
45 #if defined(_KERNEL)
46 
47 #include <arm/cpuconf.h>
48 
49 struct arm_pmc_funcs {
50 	void	(*fork)(struct proc *p1, struct proc *p2);
51 	int	(*num_counters)(void);
52 	int	(*counter_type)(int ctr);
53 	void	(*save_context)(struct proc *p);
54 	void	(*restore_context)(struct proc *p);
55 	void	(*enable_counter)(struct proc *p, int ctr);
56 	void	(*disable_counter)(struct proc *p, int ctr);
57 	void	(*accumulate)(struct proc *parent, struct proc *child);
58 	void	(*process_exit)(struct proc *p);
59 	int	(*configure_counter)(struct proc *p, int ctr, struct pmc_counter_cfg *cfg);
60 	int	(*get_counter_val)(struct proc *p, int ctr, int flags, uint64_t *pval);
61 	int	(*counter_isconfigured)(struct proc *p, int ctr);
62 	int	(*counter_isrunning)(struct proc *p, int ctr);
63 	int	(*start_profiling)(int ctr, struct pmc_counter_cfg *cfg);
64 	int	(*stop_profiling)(int ctr);
65 	int	(*alloc_kernel_ctr)(int ctr, struct pmc_counter_cfg *cfg);
66 	int	(*free_kernel_ctr)(int ctr);
67 };
68 extern struct arm_pmc_funcs *arm_pmc;
69 
70 #define pmc_md_fork(p1,p2)		(arm_pmc->fork((p1),(p2)))
71 #define pmc_get_num_counters()		(arm_pmc->num_counters())
72 #define pmc_get_counter_type(c)		(arm_pmc->counter_type(c))
73 #define pmc_save_context(p)		(arm_pmc->save_context(p))
74 #define pmc_restore_context(p)		(arm_pmc->restore_context(p))
75 #define pmc_enable_counter(p,c)		(arm_pmc->enable_counter((p),(c)))
76 #define pmc_disable_counter(p,c)	(arm_pmc->disable_counter((p),(c)))
77 #define pmc_accumulate(p1,p2)		(arm_pmc->accumulate((p1),(p2)))
78 #define pmc_process_exit(p1)		(arm_pmc->process_exit(p))
79 #define pmc_counter_isconfigured(p,c)	(arm_pmc->counter_isconfigured((p),(c)))
80 #define pmc_counter_isrunning(p,c)	(arm_pmc->counter_isrunning((p),(c)))
81 #define pmc_start_profiling(c,f)	(arm_pmc->start_profiling((c),(f)))
82 #define pmc_stop_profiling(c)		(arm_pmc->stop_profiling((c)))
83 #define pmc_alloc_kernel_counter(c,f)	(arm_pmc->alloc_kernel_ctr((c),(f)))
84 #define pmc_free_kernel_counter(c)	(arm_pmc->free_kernel_ctr((c)))
85 #define pmc_configure_counter(p,c,f)	\
86 				(arm_pmc->configure_counter((p),(c),(f)))
87 #define pmc_get_counter_value(p,c,f,pv)	\
88 				(arm_pmc->get_counter_val((p),(c),(f),(pv)))
89 
90 #define PMC_ENABLED(p)			(p)->p_md.pmc_enabled
91 
92 #endif /* defined(_KERNEL) */
93 
94 #endif /* _ARM_PMC_H_ */
95