ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc64 / oprofile / op_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 OP_IMPL_H
13 #define OP_IMPL_H 1
14
15 #define OP_MAX_COUNTER 8
16
17 #define MSR_PMM         (1UL << (63 - 61))
18
19 /* freeze counters. set to 1 on a perfmon exception */
20 #define MMCR0_FC        (1UL << (31 - 0))
21
22 /* freeze counters while MSR mark = 1 */
23 #define MMCR0_FCM1      (1UL << (31 - 3))
24
25 /* performance monitor exception enable */
26 #define MMCR0_PMXE      (1UL << (31 - 5))
27
28 /* freeze counters on enabled condition or event */
29 #define MMCR0_FCECE     (1UL << (31 - 6))
30
31 /* performance monitor alert has occurred, set to 0 after handling exception */
32 #define MMCR0_PMAO      (1UL << (31 - 24))
33
34 /* PMC1 count enable*/
35 #define MMCR0_PMC1INTCONTROL    (1UL << (31 - 16))
36
37 /* PMCn count enable*/
38 #define MMCR0_PMCNINTCONTROL    (1UL << (31 - 17))
39
40 /* state of MSR HV when SIAR set */
41 #define MMCRA_SIHV      (1UL << (63 - 35))
42
43 /* state of MSR PR when SIAR set */
44 #define MMCRA_SIPR      (1UL << (63 - 36))
45
46 /* enable sampling */
47 #define MMCRA_SAMPLE_ENABLE     (1UL << (63 - 63))
48
49 /* Per-counter configuration as set via oprofilefs.  */
50 struct op_counter_config {
51         unsigned long valid;
52         unsigned long enabled;
53         unsigned long event;
54         unsigned long count;
55         unsigned long kernel;
56         /* We dont support per counter user/kernel selection */
57         unsigned long user;
58         unsigned long unit_mask;
59 };
60
61 /* System-wide configuration as set via oprofilefs.  */
62 struct op_system_config {
63         unsigned long enable_kernel;
64         unsigned long enable_user;
65 };
66
67 /* Per-arch configuration */
68 struct op_ppc64_model {
69         void (*reg_setup) (struct op_counter_config *,
70                            struct op_system_config *,
71                            int num_counters);
72         void (*cpu_setup) (void *);
73         void (*start) (struct op_counter_config *);
74         void (*stop) (void);
75         void (*handle_interrupt) (struct pt_regs *,
76                                   struct op_counter_config *);
77         int num_counters;
78 };
79
80 static inline unsigned int ctr_read(unsigned int i)
81 {
82         switch(i) {
83         case 0:
84                 return mfspr(SPRN_PMC1);
85         case 1:
86                 return mfspr(SPRN_PMC2);
87         case 2:
88                 return mfspr(SPRN_PMC3);
89         case 3:
90                 return mfspr(SPRN_PMC4);
91         case 4:
92                 return mfspr(SPRN_PMC5);
93         case 5:
94                 return mfspr(SPRN_PMC6);
95         case 6:
96                 return mfspr(SPRN_PMC7);
97         case 7:
98                 return mfspr(SPRN_PMC8);
99         default:
100                 return 0;
101         }
102 }
103
104 static inline void ctr_write(unsigned int i, unsigned int val)
105 {
106         switch(i) {
107         case 0:
108                 mtspr(SPRN_PMC1, val);
109                 break;
110         case 1:
111                 mtspr(SPRN_PMC2, val);
112                 break;
113         case 2:
114                 mtspr(SPRN_PMC3, val);
115                 break;
116         case 3:
117                 mtspr(SPRN_PMC4, val);
118                 break;
119         case 4:
120                 mtspr(SPRN_PMC5, val);
121                 break;
122         case 5:
123                 mtspr(SPRN_PMC6, val);
124                 break;
125         case 6:
126                 mtspr(SPRN_PMC7, val);
127                 break;
128         case 7:
129                 mtspr(SPRN_PMC8, val);
130                 break;
131         default:
132                 break;
133         }
134 }
135
136 #endif