[PATCH] powerpc: G4+ oprofile support
[linux-2.6] / include / asm-powerpc / oprofile_impl.h
1 /*
2  * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
3  *
4  * Based on alpha version.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #ifndef _ASM_POWERPC_OPROFILE_IMPL_H
13 #define _ASM_POWERPC_OPROFILE_IMPL_H
14
15 #define OP_MAX_COUNTER 8
16
17 /* Per-counter configuration as set via oprofilefs.  */
18 struct op_counter_config {
19 #ifdef __powerpc64__
20         unsigned long valid;
21 #endif
22         unsigned long enabled;
23         unsigned long event;
24         unsigned long count;
25         /* Classic doesn't support per-counter user/kernel selection */
26         unsigned long kernel;
27         unsigned long user;
28         unsigned long unit_mask;
29 };
30
31 /* System-wide configuration as set via oprofilefs.  */
32 struct op_system_config {
33 #ifdef CONFIG_PPC64
34         unsigned long mmcr0;
35         unsigned long mmcr1;
36         unsigned long mmcra;
37 #endif
38         unsigned long enable_kernel;
39         unsigned long enable_user;
40 #ifdef CONFIG_PPC64
41         unsigned long backtrace_spinlocks;
42 #endif
43 };
44
45 /* Per-arch configuration */
46 struct op_powerpc_model {
47         void (*reg_setup) (struct op_counter_config *,
48                            struct op_system_config *,
49                            int num_counters);
50         void (*cpu_setup) (void *);
51         void (*start) (struct op_counter_config *);
52         void (*stop) (void);
53         void (*handle_interrupt) (struct pt_regs *,
54                                   struct op_counter_config *);
55         int num_counters;
56 };
57
58 #ifdef CONFIG_FSL_BOOKE
59 extern struct op_powerpc_model op_model_fsl_booke;
60 #else /* Otherwise, it's classic */
61
62 #ifdef CONFIG_PPC64
63 extern struct op_powerpc_model op_model_rs64;
64 extern struct op_powerpc_model op_model_power4;
65
66 #else /* Otherwise, CONFIG_PPC32 */
67 extern struct op_powerpc_model op_model_7450;
68 #endif
69
70 /* All the classic PPC parts use these */
71 static inline unsigned int ctr_read(unsigned int i)
72 {
73         switch(i) {
74         case 0:
75                 return mfspr(SPRN_PMC1);
76         case 1:
77                 return mfspr(SPRN_PMC2);
78         case 2:
79                 return mfspr(SPRN_PMC3);
80         case 3:
81                 return mfspr(SPRN_PMC4);
82         case 4:
83                 return mfspr(SPRN_PMC5);
84         case 5:
85                 return mfspr(SPRN_PMC6);
86
87 /* No PPC32 chip has more than 6 so far */
88 #ifdef CONFIG_PPC64
89         case 6:
90                 return mfspr(SPRN_PMC7);
91         case 7:
92                 return mfspr(SPRN_PMC8);
93 #endif
94         default:
95                 return 0;
96         }
97 }
98
99 static inline void ctr_write(unsigned int i, unsigned int val)
100 {
101         switch(i) {
102         case 0:
103                 mtspr(SPRN_PMC1, val);
104                 break;
105         case 1:
106                 mtspr(SPRN_PMC2, val);
107                 break;
108         case 2:
109                 mtspr(SPRN_PMC3, val);
110                 break;
111         case 3:
112                 mtspr(SPRN_PMC4, val);
113                 break;
114         case 4:
115                 mtspr(SPRN_PMC5, val);
116                 break;
117         case 5:
118                 mtspr(SPRN_PMC6, val);
119                 break;
120
121 /* No PPC32 chip has more than 6, yet */
122 #ifdef CONFIG_PPC64
123         case 6:
124                 mtspr(SPRN_PMC7, val);
125                 break;
126         case 7:
127                 mtspr(SPRN_PMC8, val);
128                 break;
129 #endif
130         default:
131                 break;
132         }
133 }
134 #endif /* !CONFIG_FSL_BOOKE */
135
136 #endif /* _ASM_POWERPC_OPROFILE_IMPL_H */