12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2f2699491SMichael Ellerman /*
3f2699491SMichael Ellerman * Performance counter support for POWER7 processors.
4f2699491SMichael Ellerman *
5f2699491SMichael Ellerman * Copyright 2009 Paul Mackerras, IBM Corporation.
6f2699491SMichael Ellerman */
7f2699491SMichael Ellerman #include <linux/kernel.h>
8f2699491SMichael Ellerman #include <linux/perf_event.h>
9f2699491SMichael Ellerman #include <linux/string.h>
10f2699491SMichael Ellerman #include <asm/reg.h>
11f2699491SMichael Ellerman #include <asm/cputable.h>
12f2699491SMichael Ellerman
13d10ebe79SMichael Ellerman #include "internal.h"
14d10ebe79SMichael Ellerman
15f2699491SMichael Ellerman /*
16f2699491SMichael Ellerman * Bits in event code for POWER7
17f2699491SMichael Ellerman */
18f2699491SMichael Ellerman #define PM_PMC_SH 16 /* PMC number (1-based) for direct events */
19f2699491SMichael Ellerman #define PM_PMC_MSK 0xf
20f2699491SMichael Ellerman #define PM_PMC_MSKS (PM_PMC_MSK << PM_PMC_SH)
21f2699491SMichael Ellerman #define PM_UNIT_SH 12 /* TTMMUX number and setting - unit select */
22f2699491SMichael Ellerman #define PM_UNIT_MSK 0xf
23f2699491SMichael Ellerman #define PM_COMBINE_SH 11 /* Combined event bit */
24f2699491SMichael Ellerman #define PM_COMBINE_MSK 1
25f2699491SMichael Ellerman #define PM_COMBINE_MSKS 0x800
26f2699491SMichael Ellerman #define PM_L2SEL_SH 8 /* L2 event select */
27f2699491SMichael Ellerman #define PM_L2SEL_MSK 7
28f2699491SMichael Ellerman #define PM_PMCSEL_MSK 0xff
29f2699491SMichael Ellerman
30f2699491SMichael Ellerman /*
31f2699491SMichael Ellerman * Bits in MMCR1 for POWER7
32f2699491SMichael Ellerman */
33f2699491SMichael Ellerman #define MMCR1_TTM0SEL_SH 60
34f2699491SMichael Ellerman #define MMCR1_TTM1SEL_SH 56
35f2699491SMichael Ellerman #define MMCR1_TTM2SEL_SH 52
36f2699491SMichael Ellerman #define MMCR1_TTM3SEL_SH 48
37f2699491SMichael Ellerman #define MMCR1_TTMSEL_MSK 0xf
38f2699491SMichael Ellerman #define MMCR1_L2SEL_SH 45
39f2699491SMichael Ellerman #define MMCR1_L2SEL_MSK 7
40f2699491SMichael Ellerman #define MMCR1_PMC1_COMBINE_SH 35
41f2699491SMichael Ellerman #define MMCR1_PMC2_COMBINE_SH 34
42f2699491SMichael Ellerman #define MMCR1_PMC3_COMBINE_SH 33
43f2699491SMichael Ellerman #define MMCR1_PMC4_COMBINE_SH 32
44f2699491SMichael Ellerman #define MMCR1_PMC1SEL_SH 24
45f2699491SMichael Ellerman #define MMCR1_PMC2SEL_SH 16
46f2699491SMichael Ellerman #define MMCR1_PMC3SEL_SH 8
47f2699491SMichael Ellerman #define MMCR1_PMC4SEL_SH 0
48f2699491SMichael Ellerman #define MMCR1_PMCSEL_SH(n) (MMCR1_PMC1SEL_SH - (n) * 8)
49f2699491SMichael Ellerman #define MMCR1_PMCSEL_MSK 0xff
50f2699491SMichael Ellerman
51f2699491SMichael Ellerman /*
52bbdc7aa4SSukadev Bhattiprolu * Power7 event codes.
53bbdc7aa4SSukadev Bhattiprolu */
54cfe0d8baSRunzhen Wang #define EVENT(_name, _code) \
55d4969e24SSukadev Bhattiprolu _name = _code,
56bbdc7aa4SSukadev Bhattiprolu
57cfe0d8baSRunzhen Wang enum {
58cfe0d8baSRunzhen Wang #include "power7-events-list.h"
59cfe0d8baSRunzhen Wang };
60cfe0d8baSRunzhen Wang #undef EVENT
61bd1060ebSSukadev Bhattiprolu
62bbdc7aa4SSukadev Bhattiprolu /*
63f2699491SMichael Ellerman * Layout of constraint bits:
64f2699491SMichael Ellerman * 6666555555555544444444443333333333222222222211111111110000000000
65f2699491SMichael Ellerman * 3210987654321098765432109876543210987654321098765432109876543210
66da111957SMichael Ellerman * < >< ><><><><><><>
67da111957SMichael Ellerman * L2 NC P6P5P4P3P2P1
68da111957SMichael Ellerman *
69da111957SMichael Ellerman * L2 - 16-18 - Required L2SEL value (select field)
70f2699491SMichael Ellerman *
71f2699491SMichael Ellerman * NC - number of counters
72f2699491SMichael Ellerman * 15: NC error 0x8000
73f2699491SMichael Ellerman * 12-14: number of events needing PMC1-4 0x7000
74f2699491SMichael Ellerman *
75f2699491SMichael Ellerman * P6
76f2699491SMichael Ellerman * 11: P6 error 0x800
77f2699491SMichael Ellerman * 10-11: Count of events needing PMC6
78f2699491SMichael Ellerman *
79f2699491SMichael Ellerman * P1..P5
80f2699491SMichael Ellerman * 0-9: Count of events needing PMC1..PMC5
81f2699491SMichael Ellerman */
82f2699491SMichael Ellerman
power7_get_constraint(u64 event,unsigned long * maskp,unsigned long * valp,u64 event_config1 __maybe_unused)83f2699491SMichael Ellerman static int power7_get_constraint(u64 event, unsigned long *maskp,
8482d2c16bSKajol Jain unsigned long *valp, u64 event_config1 __maybe_unused)
85f2699491SMichael Ellerman {
86da111957SMichael Ellerman int pmc, sh, unit;
87f2699491SMichael Ellerman unsigned long mask = 0, value = 0;
88f2699491SMichael Ellerman
89f2699491SMichael Ellerman pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
90f2699491SMichael Ellerman if (pmc) {
91f2699491SMichael Ellerman if (pmc > 6)
92f2699491SMichael Ellerman return -1;
93f2699491SMichael Ellerman sh = (pmc - 1) * 2;
94f2699491SMichael Ellerman mask |= 2 << sh;
95f2699491SMichael Ellerman value |= 1 << sh;
96f2699491SMichael Ellerman if (pmc >= 5 && !(event == 0x500fa || event == 0x600f4))
97f2699491SMichael Ellerman return -1;
98f2699491SMichael Ellerman }
99f2699491SMichael Ellerman if (pmc < 5) {
100f2699491SMichael Ellerman /* need a counter from PMC1-4 set */
101f2699491SMichael Ellerman mask |= 0x8000;
102f2699491SMichael Ellerman value |= 0x1000;
103f2699491SMichael Ellerman }
104da111957SMichael Ellerman
105da111957SMichael Ellerman unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
106da111957SMichael Ellerman if (unit == 6) {
107da111957SMichael Ellerman /* L2SEL must be identical across events */
108da111957SMichael Ellerman int l2sel = (event >> PM_L2SEL_SH) & PM_L2SEL_MSK;
109da111957SMichael Ellerman mask |= 0x7 << 16;
110da111957SMichael Ellerman value |= l2sel << 16;
111da111957SMichael Ellerman }
112da111957SMichael Ellerman
113f2699491SMichael Ellerman *maskp = mask;
114f2699491SMichael Ellerman *valp = value;
115f2699491SMichael Ellerman return 0;
116f2699491SMichael Ellerman }
117f2699491SMichael Ellerman
118f2699491SMichael Ellerman #define MAX_ALT 2 /* at most 2 alternatives for any event */
119f2699491SMichael Ellerman
120f2699491SMichael Ellerman static const unsigned int event_alternatives[][MAX_ALT] = {
121f2699491SMichael Ellerman { 0x200f2, 0x300f2 }, /* PM_INST_DISP */
122f2699491SMichael Ellerman { 0x200f4, 0x600f4 }, /* PM_RUN_CYC */
123f2699491SMichael Ellerman { 0x400fa, 0x500fa }, /* PM_RUN_INST_CMPL */
124f2699491SMichael Ellerman };
125f2699491SMichael Ellerman
126f2699491SMichael Ellerman /*
127f2699491SMichael Ellerman * Scan the alternatives table for a match and return the
128f2699491SMichael Ellerman * index into the alternatives table if found, else -1.
129f2699491SMichael Ellerman */
find_alternative(u64 event)130f2699491SMichael Ellerman static int find_alternative(u64 event)
131f2699491SMichael Ellerman {
132f2699491SMichael Ellerman int i, j;
133f2699491SMichael Ellerman
134f2699491SMichael Ellerman for (i = 0; i < ARRAY_SIZE(event_alternatives); ++i) {
135f2699491SMichael Ellerman if (event < event_alternatives[i][0])
136f2699491SMichael Ellerman break;
137f2699491SMichael Ellerman for (j = 0; j < MAX_ALT && event_alternatives[i][j]; ++j)
138f2699491SMichael Ellerman if (event == event_alternatives[i][j])
139f2699491SMichael Ellerman return i;
140f2699491SMichael Ellerman }
141f2699491SMichael Ellerman return -1;
142f2699491SMichael Ellerman }
143f2699491SMichael Ellerman
find_alternative_decode(u64 event)144f2699491SMichael Ellerman static s64 find_alternative_decode(u64 event)
145f2699491SMichael Ellerman {
146f2699491SMichael Ellerman int pmc, psel;
147f2699491SMichael Ellerman
148f2699491SMichael Ellerman /* this only handles the 4x decode events */
149f2699491SMichael Ellerman pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
150f2699491SMichael Ellerman psel = event & PM_PMCSEL_MSK;
151f2699491SMichael Ellerman if ((pmc == 2 || pmc == 4) && (psel & ~7) == 0x40)
152f2699491SMichael Ellerman return event - (1 << PM_PMC_SH) + 8;
153f2699491SMichael Ellerman if ((pmc == 1 || pmc == 3) && (psel & ~7) == 0x48)
154f2699491SMichael Ellerman return event + (1 << PM_PMC_SH) - 8;
155f2699491SMichael Ellerman return -1;
156f2699491SMichael Ellerman }
157f2699491SMichael Ellerman
power7_get_alternatives(u64 event,unsigned int flags,u64 alt[])158f2699491SMichael Ellerman static int power7_get_alternatives(u64 event, unsigned int flags, u64 alt[])
159f2699491SMichael Ellerman {
160f2699491SMichael Ellerman int i, j, nalt = 1;
161f2699491SMichael Ellerman s64 ae;
162f2699491SMichael Ellerman
163f2699491SMichael Ellerman alt[0] = event;
164f2699491SMichael Ellerman nalt = 1;
165f2699491SMichael Ellerman i = find_alternative(event);
166f2699491SMichael Ellerman if (i >= 0) {
167f2699491SMichael Ellerman for (j = 0; j < MAX_ALT; ++j) {
168f2699491SMichael Ellerman ae = event_alternatives[i][j];
169f2699491SMichael Ellerman if (ae && ae != event)
170f2699491SMichael Ellerman alt[nalt++] = ae;
171f2699491SMichael Ellerman }
172f2699491SMichael Ellerman } else {
173f2699491SMichael Ellerman ae = find_alternative_decode(event);
174f2699491SMichael Ellerman if (ae > 0)
175f2699491SMichael Ellerman alt[nalt++] = ae;
176f2699491SMichael Ellerman }
177f2699491SMichael Ellerman
178f2699491SMichael Ellerman if (flags & PPMU_ONLY_COUNT_RUN) {
179f2699491SMichael Ellerman /*
180f2699491SMichael Ellerman * We're only counting in RUN state,
181f2699491SMichael Ellerman * so PM_CYC is equivalent to PM_RUN_CYC
182f2699491SMichael Ellerman * and PM_INST_CMPL === PM_RUN_INST_CMPL.
183f2699491SMichael Ellerman * This doesn't include alternatives that don't provide
184f2699491SMichael Ellerman * any extra flexibility in assigning PMCs.
185f2699491SMichael Ellerman */
186f2699491SMichael Ellerman j = nalt;
187f2699491SMichael Ellerman for (i = 0; i < nalt; ++i) {
188f2699491SMichael Ellerman switch (alt[i]) {
189f2699491SMichael Ellerman case 0x1e: /* PM_CYC */
190f2699491SMichael Ellerman alt[j++] = 0x600f4; /* PM_RUN_CYC */
191f2699491SMichael Ellerman break;
192f2699491SMichael Ellerman case 0x600f4: /* PM_RUN_CYC */
193f2699491SMichael Ellerman alt[j++] = 0x1e;
194f2699491SMichael Ellerman break;
195f2699491SMichael Ellerman case 0x2: /* PM_PPC_CMPL */
196f2699491SMichael Ellerman alt[j++] = 0x500fa; /* PM_RUN_INST_CMPL */
197f2699491SMichael Ellerman break;
198f2699491SMichael Ellerman case 0x500fa: /* PM_RUN_INST_CMPL */
199f2699491SMichael Ellerman alt[j++] = 0x2; /* PM_PPC_CMPL */
200f2699491SMichael Ellerman break;
201f2699491SMichael Ellerman }
202f2699491SMichael Ellerman }
203f2699491SMichael Ellerman nalt = j;
204f2699491SMichael Ellerman }
205f2699491SMichael Ellerman
206f2699491SMichael Ellerman return nalt;
207f2699491SMichael Ellerman }
208f2699491SMichael Ellerman
209f2699491SMichael Ellerman /*
210f2699491SMichael Ellerman * Returns 1 if event counts things relating to marked instructions
211f2699491SMichael Ellerman * and thus needs the MMCRA_SAMPLE_ENABLE bit set, or 0 if not.
212f2699491SMichael Ellerman */
power7_marked_instr_event(u64 event)213f2699491SMichael Ellerman static int power7_marked_instr_event(u64 event)
214f2699491SMichael Ellerman {
215f2699491SMichael Ellerman int pmc, psel;
216f2699491SMichael Ellerman int unit;
217f2699491SMichael Ellerman
218f2699491SMichael Ellerman pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
219f2699491SMichael Ellerman unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
220f2699491SMichael Ellerman psel = event & PM_PMCSEL_MSK & ~1; /* trim off edge/level bit */
221f2699491SMichael Ellerman if (pmc >= 5)
222f2699491SMichael Ellerman return 0;
223f2699491SMichael Ellerman
224f2699491SMichael Ellerman switch (psel >> 4) {
225f2699491SMichael Ellerman case 2:
226f2699491SMichael Ellerman return pmc == 2 || pmc == 4;
227f2699491SMichael Ellerman case 3:
228f2699491SMichael Ellerman if (psel == 0x3c)
229f2699491SMichael Ellerman return pmc == 1;
230f2699491SMichael Ellerman if (psel == 0x3e)
231f2699491SMichael Ellerman return pmc != 2;
232f2699491SMichael Ellerman return 1;
233f2699491SMichael Ellerman case 4:
234f2699491SMichael Ellerman case 5:
235f2699491SMichael Ellerman return unit == 0xd;
236f2699491SMichael Ellerman case 6:
237f2699491SMichael Ellerman if (psel == 0x64)
238f2699491SMichael Ellerman return pmc >= 3;
239db6711b7SMichael Ellerman break;
240f2699491SMichael Ellerman case 8:
241f2699491SMichael Ellerman return unit == 0xd;
242f2699491SMichael Ellerman }
243f2699491SMichael Ellerman return 0;
244f2699491SMichael Ellerman }
245f2699491SMichael Ellerman
power7_compute_mmcr(u64 event[],int n_ev,unsigned int hwc[],struct mmcr_regs * mmcr,struct perf_event * pevents[],u32 flags __maybe_unused)246f2699491SMichael Ellerman static int power7_compute_mmcr(u64 event[], int n_ev,
24778d76819SAthira Rajeev unsigned int hwc[], struct mmcr_regs *mmcr,
24882d2c16bSKajol Jain struct perf_event *pevents[],
24982d2c16bSKajol Jain u32 flags __maybe_unused)
250f2699491SMichael Ellerman {
251f2699491SMichael Ellerman unsigned long mmcr1 = 0;
252f2699491SMichael Ellerman unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
253f2699491SMichael Ellerman unsigned int pmc, unit, combine, l2sel, psel;
254f2699491SMichael Ellerman unsigned int pmc_inuse = 0;
255f2699491SMichael Ellerman int i;
256f2699491SMichael Ellerman
257f2699491SMichael Ellerman /* First pass to count resource use */
258f2699491SMichael Ellerman for (i = 0; i < n_ev; ++i) {
259f2699491SMichael Ellerman pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
260f2699491SMichael Ellerman if (pmc) {
261f2699491SMichael Ellerman if (pmc > 6)
262f2699491SMichael Ellerman return -1;
263f2699491SMichael Ellerman if (pmc_inuse & (1 << (pmc - 1)))
264f2699491SMichael Ellerman return -1;
265f2699491SMichael Ellerman pmc_inuse |= 1 << (pmc - 1);
266f2699491SMichael Ellerman }
267f2699491SMichael Ellerman }
268f2699491SMichael Ellerman
269f2699491SMichael Ellerman /* Second pass: assign PMCs, set all MMCR1 fields */
270f2699491SMichael Ellerman for (i = 0; i < n_ev; ++i) {
271f2699491SMichael Ellerman pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
272f2699491SMichael Ellerman unit = (event[i] >> PM_UNIT_SH) & PM_UNIT_MSK;
273f2699491SMichael Ellerman combine = (event[i] >> PM_COMBINE_SH) & PM_COMBINE_MSK;
274f2699491SMichael Ellerman l2sel = (event[i] >> PM_L2SEL_SH) & PM_L2SEL_MSK;
275f2699491SMichael Ellerman psel = event[i] & PM_PMCSEL_MSK;
276f2699491SMichael Ellerman if (!pmc) {
277f2699491SMichael Ellerman /* Bus event or any-PMC direct event */
278f2699491SMichael Ellerman for (pmc = 0; pmc < 4; ++pmc) {
279f2699491SMichael Ellerman if (!(pmc_inuse & (1 << pmc)))
280f2699491SMichael Ellerman break;
281f2699491SMichael Ellerman }
282f2699491SMichael Ellerman if (pmc >= 4)
283f2699491SMichael Ellerman return -1;
284f2699491SMichael Ellerman pmc_inuse |= 1 << pmc;
285f2699491SMichael Ellerman } else {
286f2699491SMichael Ellerman /* Direct or decoded event */
287f2699491SMichael Ellerman --pmc;
288f2699491SMichael Ellerman }
289f2699491SMichael Ellerman if (pmc <= 3) {
290f2699491SMichael Ellerman mmcr1 |= (unsigned long) unit
291f2699491SMichael Ellerman << (MMCR1_TTM0SEL_SH - 4 * pmc);
292f2699491SMichael Ellerman mmcr1 |= (unsigned long) combine
293f2699491SMichael Ellerman << (MMCR1_PMC1_COMBINE_SH - pmc);
294f2699491SMichael Ellerman mmcr1 |= psel << MMCR1_PMCSEL_SH(pmc);
295f2699491SMichael Ellerman if (unit == 6) /* L2 events */
296f2699491SMichael Ellerman mmcr1 |= (unsigned long) l2sel
297f2699491SMichael Ellerman << MMCR1_L2SEL_SH;
298f2699491SMichael Ellerman }
299f2699491SMichael Ellerman if (power7_marked_instr_event(event[i]))
300f2699491SMichael Ellerman mmcra |= MMCRA_SAMPLE_ENABLE;
301f2699491SMichael Ellerman hwc[i] = pmc;
302f2699491SMichael Ellerman }
303f2699491SMichael Ellerman
304f2699491SMichael Ellerman /* Return MMCRx values */
30578d76819SAthira Rajeev mmcr->mmcr0 = 0;
306f2699491SMichael Ellerman if (pmc_inuse & 1)
30778d76819SAthira Rajeev mmcr->mmcr0 = MMCR0_PMC1CE;
308f2699491SMichael Ellerman if (pmc_inuse & 0x3e)
30978d76819SAthira Rajeev mmcr->mmcr0 |= MMCR0_PMCjCE;
31078d76819SAthira Rajeev mmcr->mmcr1 = mmcr1;
31178d76819SAthira Rajeev mmcr->mmcra = mmcra;
312f2699491SMichael Ellerman return 0;
313f2699491SMichael Ellerman }
314f2699491SMichael Ellerman
power7_disable_pmc(unsigned int pmc,struct mmcr_regs * mmcr)31578d76819SAthira Rajeev static void power7_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
316f2699491SMichael Ellerman {
317f2699491SMichael Ellerman if (pmc <= 3)
31878d76819SAthira Rajeev mmcr->mmcr1 &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
319f2699491SMichael Ellerman }
320f2699491SMichael Ellerman
321f2699491SMichael Ellerman static int power7_generic_events[] = {
322d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC,
323d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = PM_GCT_NOSLOT_CYC,
324d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = PM_CMPLU_STALL,
325d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
326d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1,
327d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1,
328d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BRU_FIN,
329d4969e24SSukadev Bhattiprolu [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED,
330f2699491SMichael Ellerman };
331f2699491SMichael Ellerman
332f2699491SMichael Ellerman #define C(x) PERF_COUNT_HW_CACHE_##x
333f2699491SMichael Ellerman
334f2699491SMichael Ellerman /*
335f2699491SMichael Ellerman * Table of generalized cache-related events.
336f2699491SMichael Ellerman * 0 means not supported, -1 means nonsensical, other values
337f2699491SMichael Ellerman * are event codes.
338f2699491SMichael Ellerman */
3399d4fc86dSAthira Rajeev static u64 power7_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
340f2699491SMichael Ellerman [C(L1D)] = { /* RESULT_ACCESS RESULT_MISS */
341f2699491SMichael Ellerman [C(OP_READ)] = { 0xc880, 0x400f0 },
342f2699491SMichael Ellerman [C(OP_WRITE)] = { 0, 0x300f0 },
343f2699491SMichael Ellerman [C(OP_PREFETCH)] = { 0xd8b8, 0 },
344f2699491SMichael Ellerman },
345f2699491SMichael Ellerman [C(L1I)] = { /* RESULT_ACCESS RESULT_MISS */
346f2699491SMichael Ellerman [C(OP_READ)] = { 0, 0x200fc },
347f2699491SMichael Ellerman [C(OP_WRITE)] = { -1, -1 },
348f2699491SMichael Ellerman [C(OP_PREFETCH)] = { 0x408a, 0 },
349f2699491SMichael Ellerman },
350f2699491SMichael Ellerman [C(LL)] = { /* RESULT_ACCESS RESULT_MISS */
351f2699491SMichael Ellerman [C(OP_READ)] = { 0x16080, 0x26080 },
352f2699491SMichael Ellerman [C(OP_WRITE)] = { 0x16082, 0x26082 },
353f2699491SMichael Ellerman [C(OP_PREFETCH)] = { 0, 0 },
354f2699491SMichael Ellerman },
355f2699491SMichael Ellerman [C(DTLB)] = { /* RESULT_ACCESS RESULT_MISS */
356f2699491SMichael Ellerman [C(OP_READ)] = { 0, 0x300fc },
357f2699491SMichael Ellerman [C(OP_WRITE)] = { -1, -1 },
358f2699491SMichael Ellerman [C(OP_PREFETCH)] = { -1, -1 },
359f2699491SMichael Ellerman },
360f2699491SMichael Ellerman [C(ITLB)] = { /* RESULT_ACCESS RESULT_MISS */
361f2699491SMichael Ellerman [C(OP_READ)] = { 0, 0x400fc },
362f2699491SMichael Ellerman [C(OP_WRITE)] = { -1, -1 },
363f2699491SMichael Ellerman [C(OP_PREFETCH)] = { -1, -1 },
364f2699491SMichael Ellerman },
365f2699491SMichael Ellerman [C(BPU)] = { /* RESULT_ACCESS RESULT_MISS */
366f2699491SMichael Ellerman [C(OP_READ)] = { 0x10068, 0x400f6 },
367f2699491SMichael Ellerman [C(OP_WRITE)] = { -1, -1 },
368f2699491SMichael Ellerman [C(OP_PREFETCH)] = { -1, -1 },
369f2699491SMichael Ellerman },
370f2699491SMichael Ellerman [C(NODE)] = { /* RESULT_ACCESS RESULT_MISS */
371f2699491SMichael Ellerman [C(OP_READ)] = { -1, -1 },
372f2699491SMichael Ellerman [C(OP_WRITE)] = { -1, -1 },
373f2699491SMichael Ellerman [C(OP_PREFETCH)] = { -1, -1 },
374f2699491SMichael Ellerman },
375f2699491SMichael Ellerman };
376f2699491SMichael Ellerman
3771c53a270SSukadev Bhattiprolu
378cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC);
379cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(stalled-cycles-frontend, PM_GCT_NOSLOT_CYC);
380cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(stalled-cycles-backend, PM_CMPLU_STALL);
381cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(instructions, PM_INST_CMPL);
382cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(cache-references, PM_LD_REF_L1);
383cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(cache-misses, PM_LD_MISS_L1);
384cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(branch-instructions, PM_BRU_FIN);
385cfe0d8baSRunzhen Wang GENERIC_EVENT_ATTR(branch-misses, PM_BR_MPRED);
3861c53a270SSukadev Bhattiprolu
387cfe0d8baSRunzhen Wang #define EVENT(_name, _code) POWER_EVENT_ATTR(_name, _name);
388cfe0d8baSRunzhen Wang #include "power7-events-list.h"
389cfe0d8baSRunzhen Wang #undef EVENT
390886c3b2dSSukadev Bhattiprolu
391cfe0d8baSRunzhen Wang #define EVENT(_name, _code) POWER_EVENT_PTR(_name),
392bd1060ebSSukadev Bhattiprolu
3931c53a270SSukadev Bhattiprolu static struct attribute *power7_events_attr[] = {
394cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_CYC),
395cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_GCT_NOSLOT_CYC),
396cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_CMPLU_STALL),
397cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_INST_CMPL),
398cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_LD_REF_L1),
399cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_LD_MISS_L1),
400cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_BRU_FIN),
401cfe0d8baSRunzhen Wang GENERIC_EVENT_PTR(PM_BR_MPRED),
402886c3b2dSSukadev Bhattiprolu
403cfe0d8baSRunzhen Wang #include "power7-events-list.h"
404cfe0d8baSRunzhen Wang #undef EVENT
4051c53a270SSukadev Bhattiprolu NULL
4061c53a270SSukadev Bhattiprolu };
4071c53a270SSukadev Bhattiprolu
4086b3a3e12SRohan McLure static const struct attribute_group power7_pmu_events_group = {
4091c53a270SSukadev Bhattiprolu .name = "events",
4101c53a270SSukadev Bhattiprolu .attrs = power7_events_attr,
4111c53a270SSukadev Bhattiprolu };
4121c53a270SSukadev Bhattiprolu
4133bf7b07eSSukadev Bhattiprolu PMU_FORMAT_ATTR(event, "config:0-19");
4143bf7b07eSSukadev Bhattiprolu
4153bf7b07eSSukadev Bhattiprolu static struct attribute *power7_pmu_format_attr[] = {
4163bf7b07eSSukadev Bhattiprolu &format_attr_event.attr,
4173bf7b07eSSukadev Bhattiprolu NULL,
4183bf7b07eSSukadev Bhattiprolu };
4193bf7b07eSSukadev Bhattiprolu
4206b3a3e12SRohan McLure static const struct attribute_group power7_pmu_format_group = {
4213bf7b07eSSukadev Bhattiprolu .name = "format",
4223bf7b07eSSukadev Bhattiprolu .attrs = power7_pmu_format_attr,
4233bf7b07eSSukadev Bhattiprolu };
4243bf7b07eSSukadev Bhattiprolu
4251c53a270SSukadev Bhattiprolu static const struct attribute_group *power7_pmu_attr_groups[] = {
4263bf7b07eSSukadev Bhattiprolu &power7_pmu_format_group,
4271c53a270SSukadev Bhattiprolu &power7_pmu_events_group,
4281c53a270SSukadev Bhattiprolu NULL,
4291c53a270SSukadev Bhattiprolu };
4301c53a270SSukadev Bhattiprolu
431f2699491SMichael Ellerman static struct power_pmu power7_pmu = {
432f2699491SMichael Ellerman .name = "POWER7",
433f2699491SMichael Ellerman .n_counter = 6,
434f2699491SMichael Ellerman .max_alternatives = MAX_ALT + 1,
435f2699491SMichael Ellerman .add_fields = 0x1555ul,
436f2699491SMichael Ellerman .test_adder = 0x3000ul,
437f2699491SMichael Ellerman .compute_mmcr = power7_compute_mmcr,
438f2699491SMichael Ellerman .get_constraint = power7_get_constraint,
439f2699491SMichael Ellerman .get_alternatives = power7_get_alternatives,
440f2699491SMichael Ellerman .disable_pmc = power7_disable_pmc,
441f2699491SMichael Ellerman .flags = PPMU_ALT_SIPR,
4421c53a270SSukadev Bhattiprolu .attr_groups = power7_pmu_attr_groups,
443f2699491SMichael Ellerman .n_generic = ARRAY_SIZE(power7_generic_events),
444f2699491SMichael Ellerman .generic_events = power7_generic_events,
445f2699491SMichael Ellerman .cache_events = &power7_cache_events,
446f2699491SMichael Ellerman };
447f2699491SMichael Ellerman
init_power7_pmu(void)448c49f5d88SNick Child int __init init_power7_pmu(void)
449f2699491SMichael Ellerman {
450*ec3eb9d9SRashmica Gupta unsigned int pvr = mfspr(SPRN_PVR);
451*ec3eb9d9SRashmica Gupta
452*ec3eb9d9SRashmica Gupta if (PVR_VER(pvr) != PVR_POWER7 && PVR_VER(pvr) != PVR_POWER7p)
453f2699491SMichael Ellerman return -ENODEV;
454f2699491SMichael Ellerman
455*ec3eb9d9SRashmica Gupta if (PVR_VER(pvr) == PVR_POWER7p)
456e6878835Ssukadev@linux.vnet.ibm.com power7_pmu.flags |= PPMU_SIAR_VALID;
457e6878835Ssukadev@linux.vnet.ibm.com
458f2699491SMichael Ellerman return register_power_pmu(&power7_pmu);
459f2699491SMichael Ellerman }
460