18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Performance counter support for POWER5 (not POWER5++) processors.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2009 Paul Mackerras, IBM Corporation.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#include <linux/kernel.h>
88c2ecf20Sopenharmony_ci#include <linux/perf_event.h>
98c2ecf20Sopenharmony_ci#include <linux/string.h>
108c2ecf20Sopenharmony_ci#include <asm/reg.h>
118c2ecf20Sopenharmony_ci#include <asm/cputable.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "internal.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ci * Bits in event code for POWER5 (not POWER5++)
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#define PM_PMC_SH	20	/* PMC number (1-based) for direct events */
198c2ecf20Sopenharmony_ci#define PM_PMC_MSK	0xf
208c2ecf20Sopenharmony_ci#define PM_PMC_MSKS	(PM_PMC_MSK << PM_PMC_SH)
218c2ecf20Sopenharmony_ci#define PM_UNIT_SH	16	/* TTMMUX number and setting - unit select */
228c2ecf20Sopenharmony_ci#define PM_UNIT_MSK	0xf
238c2ecf20Sopenharmony_ci#define PM_BYTE_SH	12	/* Byte number of event bus to use */
248c2ecf20Sopenharmony_ci#define PM_BYTE_MSK	7
258c2ecf20Sopenharmony_ci#define PM_GRS_SH	8	/* Storage subsystem mux select */
268c2ecf20Sopenharmony_ci#define PM_GRS_MSK	7
278c2ecf20Sopenharmony_ci#define PM_BUSEVENT_MSK	0x80	/* Set if event uses event bus */
288c2ecf20Sopenharmony_ci#define PM_PMCSEL_MSK	0x7f
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Values in PM_UNIT field */
318c2ecf20Sopenharmony_ci#define PM_FPU		0
328c2ecf20Sopenharmony_ci#define PM_ISU0		1
338c2ecf20Sopenharmony_ci#define PM_IFU		2
348c2ecf20Sopenharmony_ci#define PM_ISU1		3
358c2ecf20Sopenharmony_ci#define PM_IDU		4
368c2ecf20Sopenharmony_ci#define PM_ISU0_ALT	6
378c2ecf20Sopenharmony_ci#define PM_GRS		7
388c2ecf20Sopenharmony_ci#define PM_LSU0		8
398c2ecf20Sopenharmony_ci#define PM_LSU1		0xc
408c2ecf20Sopenharmony_ci#define PM_LASTUNIT	0xc
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/*
438c2ecf20Sopenharmony_ci * Bits in MMCR1 for POWER5
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci#define MMCR1_TTM0SEL_SH	62
468c2ecf20Sopenharmony_ci#define MMCR1_TTM1SEL_SH	60
478c2ecf20Sopenharmony_ci#define MMCR1_TTM2SEL_SH	58
488c2ecf20Sopenharmony_ci#define MMCR1_TTM3SEL_SH	56
498c2ecf20Sopenharmony_ci#define MMCR1_TTMSEL_MSK	3
508c2ecf20Sopenharmony_ci#define MMCR1_TD_CP_DBG0SEL_SH	54
518c2ecf20Sopenharmony_ci#define MMCR1_TD_CP_DBG1SEL_SH	52
528c2ecf20Sopenharmony_ci#define MMCR1_TD_CP_DBG2SEL_SH	50
538c2ecf20Sopenharmony_ci#define MMCR1_TD_CP_DBG3SEL_SH	48
548c2ecf20Sopenharmony_ci#define MMCR1_GRS_L2SEL_SH	46
558c2ecf20Sopenharmony_ci#define MMCR1_GRS_L2SEL_MSK	3
568c2ecf20Sopenharmony_ci#define MMCR1_GRS_L3SEL_SH	44
578c2ecf20Sopenharmony_ci#define MMCR1_GRS_L3SEL_MSK	3
588c2ecf20Sopenharmony_ci#define MMCR1_GRS_MCSEL_SH	41
598c2ecf20Sopenharmony_ci#define MMCR1_GRS_MCSEL_MSK	7
608c2ecf20Sopenharmony_ci#define MMCR1_GRS_FABSEL_SH	39
618c2ecf20Sopenharmony_ci#define MMCR1_GRS_FABSEL_MSK	3
628c2ecf20Sopenharmony_ci#define MMCR1_PMC1_ADDER_SEL_SH	35
638c2ecf20Sopenharmony_ci#define MMCR1_PMC2_ADDER_SEL_SH	34
648c2ecf20Sopenharmony_ci#define MMCR1_PMC3_ADDER_SEL_SH	33
658c2ecf20Sopenharmony_ci#define MMCR1_PMC4_ADDER_SEL_SH	32
668c2ecf20Sopenharmony_ci#define MMCR1_PMC1SEL_SH	25
678c2ecf20Sopenharmony_ci#define MMCR1_PMC2SEL_SH	17
688c2ecf20Sopenharmony_ci#define MMCR1_PMC3SEL_SH	9
698c2ecf20Sopenharmony_ci#define MMCR1_PMC4SEL_SH	1
708c2ecf20Sopenharmony_ci#define MMCR1_PMCSEL_SH(n)	(MMCR1_PMC1SEL_SH - (n) * 8)
718c2ecf20Sopenharmony_ci#define MMCR1_PMCSEL_MSK	0x7f
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/*
748c2ecf20Sopenharmony_ci * Layout of constraint bits:
758c2ecf20Sopenharmony_ci * 6666555555555544444444443333333333222222222211111111110000000000
768c2ecf20Sopenharmony_ci * 3210987654321098765432109876543210987654321098765432109876543210
778c2ecf20Sopenharmony_ci *         <><>[  ><><>< ><> [  >[ >[ ><  ><  ><  ><  ><><><><><><>
788c2ecf20Sopenharmony_ci *         T0T1 NC G0G1G2 G3  UC PS1PS2 B0  B1  B2  B3 P6P5P4P3P2P1
798c2ecf20Sopenharmony_ci *
808c2ecf20Sopenharmony_ci * T0 - TTM0 constraint
818c2ecf20Sopenharmony_ci *     54-55: TTM0SEL value (0=FPU, 2=IFU, 3=ISU1) 0xc0_0000_0000_0000
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * T1 - TTM1 constraint
848c2ecf20Sopenharmony_ci *     52-53: TTM1SEL value (0=IDU, 3=GRS) 0x30_0000_0000_0000
858c2ecf20Sopenharmony_ci *
868c2ecf20Sopenharmony_ci * NC - number of counters
878c2ecf20Sopenharmony_ci *     51: NC error 0x0008_0000_0000_0000
888c2ecf20Sopenharmony_ci *     48-50: number of events needing PMC1-4 0x0007_0000_0000_0000
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * G0..G3 - GRS mux constraints
918c2ecf20Sopenharmony_ci *     46-47: GRS_L2SEL value
928c2ecf20Sopenharmony_ci *     44-45: GRS_L3SEL value
938c2ecf20Sopenharmony_ci *     41-44: GRS_MCSEL value
948c2ecf20Sopenharmony_ci *     39-40: GRS_FABSEL value
958c2ecf20Sopenharmony_ci *	Note that these match up with their bit positions in MMCR1
968c2ecf20Sopenharmony_ci *
978c2ecf20Sopenharmony_ci * UC - unit constraint: can't have all three of FPU|IFU|ISU1, ISU0, IDU|GRS
988c2ecf20Sopenharmony_ci *     37: UC3 error 0x20_0000_0000
998c2ecf20Sopenharmony_ci *     36: FPU|IFU|ISU1 events needed 0x10_0000_0000
1008c2ecf20Sopenharmony_ci *     35: ISU0 events needed 0x08_0000_0000
1018c2ecf20Sopenharmony_ci *     34: IDU|GRS events needed 0x04_0000_0000
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * PS1
1048c2ecf20Sopenharmony_ci *     33: PS1 error 0x2_0000_0000
1058c2ecf20Sopenharmony_ci *     31-32: count of events needing PMC1/2 0x1_8000_0000
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * PS2
1088c2ecf20Sopenharmony_ci *     30: PS2 error 0x4000_0000
1098c2ecf20Sopenharmony_ci *     28-29: count of events needing PMC3/4 0x3000_0000
1108c2ecf20Sopenharmony_ci *
1118c2ecf20Sopenharmony_ci * B0
1128c2ecf20Sopenharmony_ci *     24-27: Byte 0 event source 0x0f00_0000
1138c2ecf20Sopenharmony_ci *	      Encoding as for the event code
1148c2ecf20Sopenharmony_ci *
1158c2ecf20Sopenharmony_ci * B1, B2, B3
1168c2ecf20Sopenharmony_ci *     20-23, 16-19, 12-15: Byte 1, 2, 3 event sources
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * P1..P6
1198c2ecf20Sopenharmony_ci *     0-11: Count of events needing PMC1..PMC6
1208c2ecf20Sopenharmony_ci */
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic const int grsel_shift[8] = {
1238c2ecf20Sopenharmony_ci	MMCR1_GRS_L2SEL_SH, MMCR1_GRS_L2SEL_SH, MMCR1_GRS_L2SEL_SH,
1248c2ecf20Sopenharmony_ci	MMCR1_GRS_L3SEL_SH, MMCR1_GRS_L3SEL_SH, MMCR1_GRS_L3SEL_SH,
1258c2ecf20Sopenharmony_ci	MMCR1_GRS_MCSEL_SH, MMCR1_GRS_FABSEL_SH
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* Masks and values for using events from the various units */
1298c2ecf20Sopenharmony_cistatic unsigned long unit_cons[PM_LASTUNIT+1][2] = {
1308c2ecf20Sopenharmony_ci	[PM_FPU] =   { 0xc0002000000000ul, 0x00001000000000ul },
1318c2ecf20Sopenharmony_ci	[PM_ISU0] =  { 0x00002000000000ul, 0x00000800000000ul },
1328c2ecf20Sopenharmony_ci	[PM_ISU1] =  { 0xc0002000000000ul, 0xc0001000000000ul },
1338c2ecf20Sopenharmony_ci	[PM_IFU] =   { 0xc0002000000000ul, 0x80001000000000ul },
1348c2ecf20Sopenharmony_ci	[PM_IDU] =   { 0x30002000000000ul, 0x00000400000000ul },
1358c2ecf20Sopenharmony_ci	[PM_GRS] =   { 0x30002000000000ul, 0x30000400000000ul },
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic int power5_get_constraint(u64 event, unsigned long *maskp,
1398c2ecf20Sopenharmony_ci				 unsigned long *valp)
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci	int pmc, byte, unit, sh;
1428c2ecf20Sopenharmony_ci	int bit, fmask;
1438c2ecf20Sopenharmony_ci	unsigned long mask = 0, value = 0;
1448c2ecf20Sopenharmony_ci	int grp = -1;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
1478c2ecf20Sopenharmony_ci	if (pmc) {
1488c2ecf20Sopenharmony_ci		if (pmc > 6)
1498c2ecf20Sopenharmony_ci			return -1;
1508c2ecf20Sopenharmony_ci		sh = (pmc - 1) * 2;
1518c2ecf20Sopenharmony_ci		mask |= 2 << sh;
1528c2ecf20Sopenharmony_ci		value |= 1 << sh;
1538c2ecf20Sopenharmony_ci		if (pmc <= 4)
1548c2ecf20Sopenharmony_ci			grp = (pmc - 1) >> 1;
1558c2ecf20Sopenharmony_ci		else if (event != 0x500009 && event != 0x600005)
1568c2ecf20Sopenharmony_ci			return -1;
1578c2ecf20Sopenharmony_ci	}
1588c2ecf20Sopenharmony_ci	if (event & PM_BUSEVENT_MSK) {
1598c2ecf20Sopenharmony_ci		unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
1608c2ecf20Sopenharmony_ci		if (unit > PM_LASTUNIT)
1618c2ecf20Sopenharmony_ci			return -1;
1628c2ecf20Sopenharmony_ci		if (unit == PM_ISU0_ALT)
1638c2ecf20Sopenharmony_ci			unit = PM_ISU0;
1648c2ecf20Sopenharmony_ci		mask |= unit_cons[unit][0];
1658c2ecf20Sopenharmony_ci		value |= unit_cons[unit][1];
1668c2ecf20Sopenharmony_ci		byte = (event >> PM_BYTE_SH) & PM_BYTE_MSK;
1678c2ecf20Sopenharmony_ci		if (byte >= 4) {
1688c2ecf20Sopenharmony_ci			if (unit != PM_LSU1)
1698c2ecf20Sopenharmony_ci				return -1;
1708c2ecf20Sopenharmony_ci			/* Map LSU1 low word (bytes 4-7) to unit LSU1+1 */
1718c2ecf20Sopenharmony_ci			++unit;
1728c2ecf20Sopenharmony_ci			byte &= 3;
1738c2ecf20Sopenharmony_ci		}
1748c2ecf20Sopenharmony_ci		if (unit == PM_GRS) {
1758c2ecf20Sopenharmony_ci			bit = event & 7;
1768c2ecf20Sopenharmony_ci			fmask = (bit == 6)? 7: 3;
1778c2ecf20Sopenharmony_ci			sh = grsel_shift[bit];
1788c2ecf20Sopenharmony_ci			mask |= (unsigned long)fmask << sh;
1798c2ecf20Sopenharmony_ci			value |= (unsigned long)((event >> PM_GRS_SH) & fmask)
1808c2ecf20Sopenharmony_ci				<< sh;
1818c2ecf20Sopenharmony_ci		}
1828c2ecf20Sopenharmony_ci		/*
1838c2ecf20Sopenharmony_ci		 * Bus events on bytes 0 and 2 can be counted
1848c2ecf20Sopenharmony_ci		 * on PMC1/2; bytes 1 and 3 on PMC3/4.
1858c2ecf20Sopenharmony_ci		 */
1868c2ecf20Sopenharmony_ci		if (!pmc)
1878c2ecf20Sopenharmony_ci			grp = byte & 1;
1888c2ecf20Sopenharmony_ci		/* Set byte lane select field */
1898c2ecf20Sopenharmony_ci		mask  |= 0xfUL << (24 - 4 * byte);
1908c2ecf20Sopenharmony_ci		value |= (unsigned long)unit << (24 - 4 * byte);
1918c2ecf20Sopenharmony_ci	}
1928c2ecf20Sopenharmony_ci	if (grp == 0) {
1938c2ecf20Sopenharmony_ci		/* increment PMC1/2 field */
1948c2ecf20Sopenharmony_ci		mask  |= 0x200000000ul;
1958c2ecf20Sopenharmony_ci		value |= 0x080000000ul;
1968c2ecf20Sopenharmony_ci	} else if (grp == 1) {
1978c2ecf20Sopenharmony_ci		/* increment PMC3/4 field */
1988c2ecf20Sopenharmony_ci		mask  |= 0x40000000ul;
1998c2ecf20Sopenharmony_ci		value |= 0x10000000ul;
2008c2ecf20Sopenharmony_ci	}
2018c2ecf20Sopenharmony_ci	if (pmc < 5) {
2028c2ecf20Sopenharmony_ci		/* need a counter from PMC1-4 set */
2038c2ecf20Sopenharmony_ci		mask  |= 0x8000000000000ul;
2048c2ecf20Sopenharmony_ci		value |= 0x1000000000000ul;
2058c2ecf20Sopenharmony_ci	}
2068c2ecf20Sopenharmony_ci	*maskp = mask;
2078c2ecf20Sopenharmony_ci	*valp = value;
2088c2ecf20Sopenharmony_ci	return 0;
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#define MAX_ALT	3	/* at most 3 alternatives for any event */
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic const unsigned int event_alternatives[][MAX_ALT] = {
2148c2ecf20Sopenharmony_ci	{ 0x120e4,  0x400002 },			/* PM_GRP_DISP_REJECT */
2158c2ecf20Sopenharmony_ci	{ 0x410c7,  0x441084 },			/* PM_THRD_L2MISS_BOTH_CYC */
2168c2ecf20Sopenharmony_ci	{ 0x100005, 0x600005 },			/* PM_RUN_CYC */
2178c2ecf20Sopenharmony_ci	{ 0x100009, 0x200009, 0x500009 },	/* PM_INST_CMPL */
2188c2ecf20Sopenharmony_ci	{ 0x300009, 0x400009 },			/* PM_INST_DISP */
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/*
2228c2ecf20Sopenharmony_ci * Scan the alternatives table for a match and return the
2238c2ecf20Sopenharmony_ci * index into the alternatives table if found, else -1.
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cistatic int find_alternative(u64 event)
2268c2ecf20Sopenharmony_ci{
2278c2ecf20Sopenharmony_ci	int i, j;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(event_alternatives); ++i) {
2308c2ecf20Sopenharmony_ci		if (event < event_alternatives[i][0])
2318c2ecf20Sopenharmony_ci			break;
2328c2ecf20Sopenharmony_ci		for (j = 0; j < MAX_ALT && event_alternatives[i][j]; ++j)
2338c2ecf20Sopenharmony_ci			if (event == event_alternatives[i][j])
2348c2ecf20Sopenharmony_ci				return i;
2358c2ecf20Sopenharmony_ci	}
2368c2ecf20Sopenharmony_ci	return -1;
2378c2ecf20Sopenharmony_ci}
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistatic const unsigned char bytedecode_alternatives[4][4] = {
2408c2ecf20Sopenharmony_ci	/* PMC 1 */	{ 0x21, 0x23, 0x25, 0x27 },
2418c2ecf20Sopenharmony_ci	/* PMC 2 */	{ 0x07, 0x17, 0x0e, 0x1e },
2428c2ecf20Sopenharmony_ci	/* PMC 3 */	{ 0x20, 0x22, 0x24, 0x26 },
2438c2ecf20Sopenharmony_ci	/* PMC 4 */	{ 0x07, 0x17, 0x0e, 0x1e }
2448c2ecf20Sopenharmony_ci};
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci/*
2478c2ecf20Sopenharmony_ci * Some direct events for decodes of event bus byte 3 have alternative
2488c2ecf20Sopenharmony_ci * PMCSEL values on other counters.  This returns the alternative
2498c2ecf20Sopenharmony_ci * event code for those that do, or -1 otherwise.
2508c2ecf20Sopenharmony_ci */
2518c2ecf20Sopenharmony_cistatic s64 find_alternative_bdecode(u64 event)
2528c2ecf20Sopenharmony_ci{
2538c2ecf20Sopenharmony_ci	int pmc, altpmc, pp, j;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
2568c2ecf20Sopenharmony_ci	if (pmc == 0 || pmc > 4)
2578c2ecf20Sopenharmony_ci		return -1;
2588c2ecf20Sopenharmony_ci	altpmc = 5 - pmc;	/* 1 <-> 4, 2 <-> 3 */
2598c2ecf20Sopenharmony_ci	pp = event & PM_PMCSEL_MSK;
2608c2ecf20Sopenharmony_ci	for (j = 0; j < 4; ++j) {
2618c2ecf20Sopenharmony_ci		if (bytedecode_alternatives[pmc - 1][j] == pp) {
2628c2ecf20Sopenharmony_ci			return (event & ~(PM_PMC_MSKS | PM_PMCSEL_MSK)) |
2638c2ecf20Sopenharmony_ci				(altpmc << PM_PMC_SH) |
2648c2ecf20Sopenharmony_ci				bytedecode_alternatives[altpmc - 1][j];
2658c2ecf20Sopenharmony_ci		}
2668c2ecf20Sopenharmony_ci	}
2678c2ecf20Sopenharmony_ci	return -1;
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic int power5_get_alternatives(u64 event, unsigned int flags, u64 alt[])
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	int i, j, nalt = 1;
2738c2ecf20Sopenharmony_ci	s64 ae;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	alt[0] = event;
2768c2ecf20Sopenharmony_ci	nalt = 1;
2778c2ecf20Sopenharmony_ci	i = find_alternative(event);
2788c2ecf20Sopenharmony_ci	if (i >= 0) {
2798c2ecf20Sopenharmony_ci		for (j = 0; j < MAX_ALT; ++j) {
2808c2ecf20Sopenharmony_ci			ae = event_alternatives[i][j];
2818c2ecf20Sopenharmony_ci			if (ae && ae != event)
2828c2ecf20Sopenharmony_ci				alt[nalt++] = ae;
2838c2ecf20Sopenharmony_ci		}
2848c2ecf20Sopenharmony_ci	} else {
2858c2ecf20Sopenharmony_ci		ae = find_alternative_bdecode(event);
2868c2ecf20Sopenharmony_ci		if (ae > 0)
2878c2ecf20Sopenharmony_ci			alt[nalt++] = ae;
2888c2ecf20Sopenharmony_ci	}
2898c2ecf20Sopenharmony_ci	return nalt;
2908c2ecf20Sopenharmony_ci}
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci/*
2938c2ecf20Sopenharmony_ci * Map of which direct events on which PMCs are marked instruction events.
2948c2ecf20Sopenharmony_ci * Indexed by PMCSEL value, bit i (LE) set if PMC i is a marked event.
2958c2ecf20Sopenharmony_ci * Bit 0 is set if it is marked for all PMCs.
2968c2ecf20Sopenharmony_ci * The 0x80 bit indicates a byte decode PMCSEL value.
2978c2ecf20Sopenharmony_ci */
2988c2ecf20Sopenharmony_cistatic unsigned char direct_event_is_marked[0x28] = {
2998c2ecf20Sopenharmony_ci	0,	/* 00 */
3008c2ecf20Sopenharmony_ci	0x1f,	/* 01 PM_IOPS_CMPL */
3018c2ecf20Sopenharmony_ci	0x2,	/* 02 PM_MRK_GRP_DISP */
3028c2ecf20Sopenharmony_ci	0xe,	/* 03 PM_MRK_ST_CMPL, PM_MRK_ST_GPS, PM_MRK_ST_CMPL_INT */
3038c2ecf20Sopenharmony_ci	0,	/* 04 */
3048c2ecf20Sopenharmony_ci	0x1c,	/* 05 PM_MRK_BRU_FIN, PM_MRK_INST_FIN, PM_MRK_CRU_FIN */
3058c2ecf20Sopenharmony_ci	0x80,	/* 06 */
3068c2ecf20Sopenharmony_ci	0x80,	/* 07 */
3078c2ecf20Sopenharmony_ci	0, 0, 0,/* 08 - 0a */
3088c2ecf20Sopenharmony_ci	0x18,	/* 0b PM_THRESH_TIMEO, PM_MRK_GRP_TIMEO */
3098c2ecf20Sopenharmony_ci	0,	/* 0c */
3108c2ecf20Sopenharmony_ci	0x80,	/* 0d */
3118c2ecf20Sopenharmony_ci	0x80,	/* 0e */
3128c2ecf20Sopenharmony_ci	0,	/* 0f */
3138c2ecf20Sopenharmony_ci	0,	/* 10 */
3148c2ecf20Sopenharmony_ci	0x14,	/* 11 PM_MRK_GRP_BR_REDIR, PM_MRK_GRP_IC_MISS */
3158c2ecf20Sopenharmony_ci	0,	/* 12 */
3168c2ecf20Sopenharmony_ci	0x10,	/* 13 PM_MRK_GRP_CMPL */
3178c2ecf20Sopenharmony_ci	0x1f,	/* 14 PM_GRP_MRK, PM_MRK_{FXU,FPU,LSU}_FIN */
3188c2ecf20Sopenharmony_ci	0x2,	/* 15 PM_MRK_GRP_ISSUED */
3198c2ecf20Sopenharmony_ci	0x80,	/* 16 */
3208c2ecf20Sopenharmony_ci	0x80,	/* 17 */
3218c2ecf20Sopenharmony_ci	0, 0, 0, 0, 0,
3228c2ecf20Sopenharmony_ci	0x80,	/* 1d */
3238c2ecf20Sopenharmony_ci	0x80,	/* 1e */
3248c2ecf20Sopenharmony_ci	0,	/* 1f */
3258c2ecf20Sopenharmony_ci	0x80,	/* 20 */
3268c2ecf20Sopenharmony_ci	0x80,	/* 21 */
3278c2ecf20Sopenharmony_ci	0x80,	/* 22 */
3288c2ecf20Sopenharmony_ci	0x80,	/* 23 */
3298c2ecf20Sopenharmony_ci	0x80,	/* 24 */
3308c2ecf20Sopenharmony_ci	0x80,	/* 25 */
3318c2ecf20Sopenharmony_ci	0x80,	/* 26 */
3328c2ecf20Sopenharmony_ci	0x80,	/* 27 */
3338c2ecf20Sopenharmony_ci};
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci/*
3368c2ecf20Sopenharmony_ci * Returns 1 if event counts things relating to marked instructions
3378c2ecf20Sopenharmony_ci * and thus needs the MMCRA_SAMPLE_ENABLE bit set, or 0 if not.
3388c2ecf20Sopenharmony_ci */
3398c2ecf20Sopenharmony_cistatic int power5_marked_instr_event(u64 event)
3408c2ecf20Sopenharmony_ci{
3418c2ecf20Sopenharmony_ci	int pmc, psel;
3428c2ecf20Sopenharmony_ci	int bit, byte, unit;
3438c2ecf20Sopenharmony_ci	u32 mask;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
3468c2ecf20Sopenharmony_ci	psel = event & PM_PMCSEL_MSK;
3478c2ecf20Sopenharmony_ci	if (pmc >= 5)
3488c2ecf20Sopenharmony_ci		return 0;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	bit = -1;
3518c2ecf20Sopenharmony_ci	if (psel < sizeof(direct_event_is_marked)) {
3528c2ecf20Sopenharmony_ci		if (direct_event_is_marked[psel] & (1 << pmc))
3538c2ecf20Sopenharmony_ci			return 1;
3548c2ecf20Sopenharmony_ci		if (direct_event_is_marked[psel] & 0x80)
3558c2ecf20Sopenharmony_ci			bit = 4;
3568c2ecf20Sopenharmony_ci		else if (psel == 0x08)
3578c2ecf20Sopenharmony_ci			bit = pmc - 1;
3588c2ecf20Sopenharmony_ci		else if (psel == 0x10)
3598c2ecf20Sopenharmony_ci			bit = 4 - pmc;
3608c2ecf20Sopenharmony_ci		else if (psel == 0x1b && (pmc == 1 || pmc == 3))
3618c2ecf20Sopenharmony_ci			bit = 4;
3628c2ecf20Sopenharmony_ci	} else if ((psel & 0x58) == 0x40)
3638c2ecf20Sopenharmony_ci		bit = psel & 7;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci	if (!(event & PM_BUSEVENT_MSK))
3668c2ecf20Sopenharmony_ci		return 0;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	byte = (event >> PM_BYTE_SH) & PM_BYTE_MSK;
3698c2ecf20Sopenharmony_ci	unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
3708c2ecf20Sopenharmony_ci	if (unit == PM_LSU0) {
3718c2ecf20Sopenharmony_ci		/* byte 1 bits 0-7, byte 2 bits 0,2-4,6 */
3728c2ecf20Sopenharmony_ci		mask = 0x5dff00;
3738c2ecf20Sopenharmony_ci	} else if (unit == PM_LSU1 && byte >= 4) {
3748c2ecf20Sopenharmony_ci		byte -= 4;
3758c2ecf20Sopenharmony_ci		/* byte 4 bits 1,3,5,7, byte 5 bits 6-7, byte 7 bits 0-4,6 */
3768c2ecf20Sopenharmony_ci		mask = 0x5f00c0aa;
3778c2ecf20Sopenharmony_ci	} else
3788c2ecf20Sopenharmony_ci		return 0;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	return (mask >> (byte * 8 + bit)) & 1;
3818c2ecf20Sopenharmony_ci}
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistatic int power5_compute_mmcr(u64 event[], int n_ev,
3848c2ecf20Sopenharmony_ci			       unsigned int hwc[], struct mmcr_regs *mmcr,
3858c2ecf20Sopenharmony_ci			       struct perf_event *pevents[])
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	unsigned long mmcr1 = 0;
3888c2ecf20Sopenharmony_ci	unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
3898c2ecf20Sopenharmony_ci	unsigned int pmc, unit, byte, psel;
3908c2ecf20Sopenharmony_ci	unsigned int ttm, grp;
3918c2ecf20Sopenharmony_ci	int i, isbus, bit, grsel;
3928c2ecf20Sopenharmony_ci	unsigned int pmc_inuse = 0;
3938c2ecf20Sopenharmony_ci	unsigned int pmc_grp_use[2];
3948c2ecf20Sopenharmony_ci	unsigned char busbyte[4];
3958c2ecf20Sopenharmony_ci	unsigned char unituse[16];
3968c2ecf20Sopenharmony_ci	int ttmuse;
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci	if (n_ev > 6)
3998c2ecf20Sopenharmony_ci		return -1;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	/* First pass to count resource use */
4028c2ecf20Sopenharmony_ci	pmc_grp_use[0] = pmc_grp_use[1] = 0;
4038c2ecf20Sopenharmony_ci	memset(busbyte, 0, sizeof(busbyte));
4048c2ecf20Sopenharmony_ci	memset(unituse, 0, sizeof(unituse));
4058c2ecf20Sopenharmony_ci	for (i = 0; i < n_ev; ++i) {
4068c2ecf20Sopenharmony_ci		pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
4078c2ecf20Sopenharmony_ci		if (pmc) {
4088c2ecf20Sopenharmony_ci			if (pmc > 6)
4098c2ecf20Sopenharmony_ci				return -1;
4108c2ecf20Sopenharmony_ci			if (pmc_inuse & (1 << (pmc - 1)))
4118c2ecf20Sopenharmony_ci				return -1;
4128c2ecf20Sopenharmony_ci			pmc_inuse |= 1 << (pmc - 1);
4138c2ecf20Sopenharmony_ci			/* count 1/2 vs 3/4 use */
4148c2ecf20Sopenharmony_ci			if (pmc <= 4)
4158c2ecf20Sopenharmony_ci				++pmc_grp_use[(pmc - 1) >> 1];
4168c2ecf20Sopenharmony_ci		}
4178c2ecf20Sopenharmony_ci		if (event[i] & PM_BUSEVENT_MSK) {
4188c2ecf20Sopenharmony_ci			unit = (event[i] >> PM_UNIT_SH) & PM_UNIT_MSK;
4198c2ecf20Sopenharmony_ci			byte = (event[i] >> PM_BYTE_SH) & PM_BYTE_MSK;
4208c2ecf20Sopenharmony_ci			if (unit > PM_LASTUNIT)
4218c2ecf20Sopenharmony_ci				return -1;
4228c2ecf20Sopenharmony_ci			if (unit == PM_ISU0_ALT)
4238c2ecf20Sopenharmony_ci				unit = PM_ISU0;
4248c2ecf20Sopenharmony_ci			if (byte >= 4) {
4258c2ecf20Sopenharmony_ci				if (unit != PM_LSU1)
4268c2ecf20Sopenharmony_ci					return -1;
4278c2ecf20Sopenharmony_ci				++unit;
4288c2ecf20Sopenharmony_ci				byte &= 3;
4298c2ecf20Sopenharmony_ci			}
4308c2ecf20Sopenharmony_ci			if (!pmc)
4318c2ecf20Sopenharmony_ci				++pmc_grp_use[byte & 1];
4328c2ecf20Sopenharmony_ci			if (busbyte[byte] && busbyte[byte] != unit)
4338c2ecf20Sopenharmony_ci				return -1;
4348c2ecf20Sopenharmony_ci			busbyte[byte] = unit;
4358c2ecf20Sopenharmony_ci			unituse[unit] = 1;
4368c2ecf20Sopenharmony_ci		}
4378c2ecf20Sopenharmony_ci	}
4388c2ecf20Sopenharmony_ci	if (pmc_grp_use[0] > 2 || pmc_grp_use[1] > 2)
4398c2ecf20Sopenharmony_ci		return -1;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	/*
4428c2ecf20Sopenharmony_ci	 * Assign resources and set multiplexer selects.
4438c2ecf20Sopenharmony_ci	 *
4448c2ecf20Sopenharmony_ci	 * PM_ISU0 can go either on TTM0 or TTM1, but that's the only
4458c2ecf20Sopenharmony_ci	 * choice we have to deal with.
4468c2ecf20Sopenharmony_ci	 */
4478c2ecf20Sopenharmony_ci	if (unituse[PM_ISU0] &
4488c2ecf20Sopenharmony_ci	    (unituse[PM_FPU] | unituse[PM_IFU] | unituse[PM_ISU1])) {
4498c2ecf20Sopenharmony_ci		unituse[PM_ISU0_ALT] = 1;	/* move ISU to TTM1 */
4508c2ecf20Sopenharmony_ci		unituse[PM_ISU0] = 0;
4518c2ecf20Sopenharmony_ci	}
4528c2ecf20Sopenharmony_ci	/* Set TTM[01]SEL fields. */
4538c2ecf20Sopenharmony_ci	ttmuse = 0;
4548c2ecf20Sopenharmony_ci	for (i = PM_FPU; i <= PM_ISU1; ++i) {
4558c2ecf20Sopenharmony_ci		if (!unituse[i])
4568c2ecf20Sopenharmony_ci			continue;
4578c2ecf20Sopenharmony_ci		if (ttmuse++)
4588c2ecf20Sopenharmony_ci			return -1;
4598c2ecf20Sopenharmony_ci		mmcr1 |= (unsigned long)i << MMCR1_TTM0SEL_SH;
4608c2ecf20Sopenharmony_ci	}
4618c2ecf20Sopenharmony_ci	ttmuse = 0;
4628c2ecf20Sopenharmony_ci	for (; i <= PM_GRS; ++i) {
4638c2ecf20Sopenharmony_ci		if (!unituse[i])
4648c2ecf20Sopenharmony_ci			continue;
4658c2ecf20Sopenharmony_ci		if (ttmuse++)
4668c2ecf20Sopenharmony_ci			return -1;
4678c2ecf20Sopenharmony_ci		mmcr1 |= (unsigned long)(i & 3) << MMCR1_TTM1SEL_SH;
4688c2ecf20Sopenharmony_ci	}
4698c2ecf20Sopenharmony_ci	if (ttmuse > 1)
4708c2ecf20Sopenharmony_ci		return -1;
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci	/* Set byte lane select fields, TTM[23]SEL and GRS_*SEL. */
4738c2ecf20Sopenharmony_ci	for (byte = 0; byte < 4; ++byte) {
4748c2ecf20Sopenharmony_ci		unit = busbyte[byte];
4758c2ecf20Sopenharmony_ci		if (!unit)
4768c2ecf20Sopenharmony_ci			continue;
4778c2ecf20Sopenharmony_ci		if (unit == PM_ISU0 && unituse[PM_ISU0_ALT]) {
4788c2ecf20Sopenharmony_ci			/* get ISU0 through TTM1 rather than TTM0 */
4798c2ecf20Sopenharmony_ci			unit = PM_ISU0_ALT;
4808c2ecf20Sopenharmony_ci		} else if (unit == PM_LSU1 + 1) {
4818c2ecf20Sopenharmony_ci			/* select lower word of LSU1 for this byte */
4828c2ecf20Sopenharmony_ci			mmcr1 |= 1ul << (MMCR1_TTM3SEL_SH + 3 - byte);
4838c2ecf20Sopenharmony_ci		}
4848c2ecf20Sopenharmony_ci		ttm = unit >> 2;
4858c2ecf20Sopenharmony_ci		mmcr1 |= (unsigned long)ttm
4868c2ecf20Sopenharmony_ci			<< (MMCR1_TD_CP_DBG0SEL_SH - 2 * byte);
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	/* Second pass: assign PMCs, set PMCxSEL and PMCx_ADDER_SEL fields */
4908c2ecf20Sopenharmony_ci	for (i = 0; i < n_ev; ++i) {
4918c2ecf20Sopenharmony_ci		pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
4928c2ecf20Sopenharmony_ci		unit = (event[i] >> PM_UNIT_SH) & PM_UNIT_MSK;
4938c2ecf20Sopenharmony_ci		byte = (event[i] >> PM_BYTE_SH) & PM_BYTE_MSK;
4948c2ecf20Sopenharmony_ci		psel = event[i] & PM_PMCSEL_MSK;
4958c2ecf20Sopenharmony_ci		isbus = event[i] & PM_BUSEVENT_MSK;
4968c2ecf20Sopenharmony_ci		if (!pmc) {
4978c2ecf20Sopenharmony_ci			/* Bus event or any-PMC direct event */
4988c2ecf20Sopenharmony_ci			for (pmc = 0; pmc < 4; ++pmc) {
4998c2ecf20Sopenharmony_ci				if (pmc_inuse & (1 << pmc))
5008c2ecf20Sopenharmony_ci					continue;
5018c2ecf20Sopenharmony_ci				grp = (pmc >> 1) & 1;
5028c2ecf20Sopenharmony_ci				if (isbus) {
5038c2ecf20Sopenharmony_ci					if (grp == (byte & 1))
5048c2ecf20Sopenharmony_ci						break;
5058c2ecf20Sopenharmony_ci				} else if (pmc_grp_use[grp] < 2) {
5068c2ecf20Sopenharmony_ci					++pmc_grp_use[grp];
5078c2ecf20Sopenharmony_ci					break;
5088c2ecf20Sopenharmony_ci				}
5098c2ecf20Sopenharmony_ci			}
5108c2ecf20Sopenharmony_ci			pmc_inuse |= 1 << pmc;
5118c2ecf20Sopenharmony_ci		} else if (pmc <= 4) {
5128c2ecf20Sopenharmony_ci			/* Direct event */
5138c2ecf20Sopenharmony_ci			--pmc;
5148c2ecf20Sopenharmony_ci			if ((psel == 8 || psel == 0x10) && isbus && (byte & 2))
5158c2ecf20Sopenharmony_ci				/* add events on higher-numbered bus */
5168c2ecf20Sopenharmony_ci				mmcr1 |= 1ul << (MMCR1_PMC1_ADDER_SEL_SH - pmc);
5178c2ecf20Sopenharmony_ci		} else {
5188c2ecf20Sopenharmony_ci			/* Instructions or run cycles on PMC5/6 */
5198c2ecf20Sopenharmony_ci			--pmc;
5208c2ecf20Sopenharmony_ci		}
5218c2ecf20Sopenharmony_ci		if (isbus && unit == PM_GRS) {
5228c2ecf20Sopenharmony_ci			bit = psel & 7;
5238c2ecf20Sopenharmony_ci			grsel = (event[i] >> PM_GRS_SH) & PM_GRS_MSK;
5248c2ecf20Sopenharmony_ci			mmcr1 |= (unsigned long)grsel << grsel_shift[bit];
5258c2ecf20Sopenharmony_ci		}
5268c2ecf20Sopenharmony_ci		if (power5_marked_instr_event(event[i]))
5278c2ecf20Sopenharmony_ci			mmcra |= MMCRA_SAMPLE_ENABLE;
5288c2ecf20Sopenharmony_ci		if (pmc <= 3)
5298c2ecf20Sopenharmony_ci			mmcr1 |= psel << MMCR1_PMCSEL_SH(pmc);
5308c2ecf20Sopenharmony_ci		hwc[i] = pmc;
5318c2ecf20Sopenharmony_ci	}
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	/* Return MMCRx values */
5348c2ecf20Sopenharmony_ci	mmcr->mmcr0 = 0;
5358c2ecf20Sopenharmony_ci	if (pmc_inuse & 1)
5368c2ecf20Sopenharmony_ci		mmcr->mmcr0 = MMCR0_PMC1CE;
5378c2ecf20Sopenharmony_ci	if (pmc_inuse & 0x3e)
5388c2ecf20Sopenharmony_ci		mmcr->mmcr0 |= MMCR0_PMCjCE;
5398c2ecf20Sopenharmony_ci	mmcr->mmcr1 = mmcr1;
5408c2ecf20Sopenharmony_ci	mmcr->mmcra = mmcra;
5418c2ecf20Sopenharmony_ci	return 0;
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic void power5_disable_pmc(unsigned int pmc, struct mmcr_regs *mmcr)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	if (pmc <= 3)
5478c2ecf20Sopenharmony_ci		mmcr->mmcr1 &= ~(0x7fUL << MMCR1_PMCSEL_SH(pmc));
5488c2ecf20Sopenharmony_ci}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_cistatic int power5_generic_events[] = {
5518c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CPU_CYCLES]		= 0xf,
5528c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_INSTRUCTIONS]		= 0x100009,
5538c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_REFERENCES]	= 0x4c1090, /* LD_REF_L1 */
5548c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_MISSES]		= 0x3c1088, /* LD_MISS_L1 */
5558c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS]	= 0x230e4,  /* BR_ISSUED */
5568c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_MISSES]		= 0x230e5,  /* BR_MPRED_CR */
5578c2ecf20Sopenharmony_ci};
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci#define C(x)	PERF_COUNT_HW_CACHE_##x
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci/*
5628c2ecf20Sopenharmony_ci * Table of generalized cache-related events.
5638c2ecf20Sopenharmony_ci * 0 means not supported, -1 means nonsensical, other values
5648c2ecf20Sopenharmony_ci * are event codes.
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_cistatic u64 power5_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
5678c2ecf20Sopenharmony_ci	[C(L1D)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5688c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0x4c1090,	0x3c1088	},
5698c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	0x3c1090,	0xc10c3		},
5708c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	0xc70e7,	0		},
5718c2ecf20Sopenharmony_ci	},
5728c2ecf20Sopenharmony_ci	[C(L1I)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5738c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0,		0		},
5748c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	-1,		-1		},
5758c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	0,		0		},
5768c2ecf20Sopenharmony_ci	},
5778c2ecf20Sopenharmony_ci	[C(LL)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5788c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0,		0x3c309b	},
5798c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	0,		0		},
5808c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	0xc50c3,	0		},
5818c2ecf20Sopenharmony_ci	},
5828c2ecf20Sopenharmony_ci	[C(DTLB)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5838c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0x2c4090,	0x800c4		},
5848c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	-1,		-1		},
5858c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	-1,		-1		},
5868c2ecf20Sopenharmony_ci	},
5878c2ecf20Sopenharmony_ci	[C(ITLB)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5888c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0,		0x800c0		},
5898c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	-1,		-1		},
5908c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	-1,		-1		},
5918c2ecf20Sopenharmony_ci	},
5928c2ecf20Sopenharmony_ci	[C(BPU)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5938c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	0x230e4,	0x230e5		},
5948c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	-1,		-1		},
5958c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	-1,		-1		},
5968c2ecf20Sopenharmony_ci	},
5978c2ecf20Sopenharmony_ci	[C(NODE)] = {		/* 	RESULT_ACCESS	RESULT_MISS */
5988c2ecf20Sopenharmony_ci		[C(OP_READ)] = {	-1,		-1		},
5998c2ecf20Sopenharmony_ci		[C(OP_WRITE)] = {	-1,		-1		},
6008c2ecf20Sopenharmony_ci		[C(OP_PREFETCH)] = {	-1,		-1		},
6018c2ecf20Sopenharmony_ci	},
6028c2ecf20Sopenharmony_ci};
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_cistatic struct power_pmu power5_pmu = {
6058c2ecf20Sopenharmony_ci	.name			= "POWER5",
6068c2ecf20Sopenharmony_ci	.n_counter		= 6,
6078c2ecf20Sopenharmony_ci	.max_alternatives	= MAX_ALT,
6088c2ecf20Sopenharmony_ci	.add_fields		= 0x7000090000555ul,
6098c2ecf20Sopenharmony_ci	.test_adder		= 0x3000490000000ul,
6108c2ecf20Sopenharmony_ci	.compute_mmcr		= power5_compute_mmcr,
6118c2ecf20Sopenharmony_ci	.get_constraint		= power5_get_constraint,
6128c2ecf20Sopenharmony_ci	.get_alternatives	= power5_get_alternatives,
6138c2ecf20Sopenharmony_ci	.disable_pmc		= power5_disable_pmc,
6148c2ecf20Sopenharmony_ci	.n_generic		= ARRAY_SIZE(power5_generic_events),
6158c2ecf20Sopenharmony_ci	.generic_events		= power5_generic_events,
6168c2ecf20Sopenharmony_ci	.cache_events		= &power5_cache_events,
6178c2ecf20Sopenharmony_ci	.flags			= PPMU_HAS_SSLOT,
6188c2ecf20Sopenharmony_ci};
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ciint init_power5_pmu(void)
6218c2ecf20Sopenharmony_ci{
6228c2ecf20Sopenharmony_ci	if (!cur_cpu_spec->oprofile_cpu_type ||
6238c2ecf20Sopenharmony_ci	    strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power5"))
6248c2ecf20Sopenharmony_ci		return -ENODEV;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	return register_power_pmu(&power5_pmu);
6278c2ecf20Sopenharmony_ci}
628