18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Performance counter support for POWER8 processors.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2009 Paul Mackerras, IBM Corporation.
68c2ecf20Sopenharmony_ci * Copyright 2013 Michael Ellerman, IBM Corporation.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define pr_fmt(fmt)	"power8-pmu: " fmt
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "isa207-common.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * Some power8 event codes.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#define EVENT(_name, _code)	_name = _code,
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cienum {
198c2ecf20Sopenharmony_ci#include "power8-events-list.h"
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#undef EVENT
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* MMCRA IFM bits - POWER8 */
258c2ecf20Sopenharmony_ci#define	POWER8_MMCRA_IFM1		0x0000000040000000UL
268c2ecf20Sopenharmony_ci#define	POWER8_MMCRA_IFM2		0x0000000080000000UL
278c2ecf20Sopenharmony_ci#define	POWER8_MMCRA_IFM3		0x00000000C0000000UL
288c2ecf20Sopenharmony_ci#define	POWER8_MMCRA_BHRB_MASK		0x00000000C0000000UL
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * Raw event encoding for PowerISA v2.07 (Power8):
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci *        60        56        52        48        44        40        36        32
348c2ecf20Sopenharmony_ci * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
358c2ecf20Sopenharmony_ci *   | | [ ]                           [      thresh_cmp     ]   [  thresh_ctl   ]
368c2ecf20Sopenharmony_ci *   | |  |                                                              |
378c2ecf20Sopenharmony_ci *   | |  *- IFM (Linux)                 thresh start/stop OR FAB match -*
388c2ecf20Sopenharmony_ci *   | *- BHRB (Linux)
398c2ecf20Sopenharmony_ci *   *- EBB (Linux)
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci *        28        24        20        16        12         8         4         0
428c2ecf20Sopenharmony_ci * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
438c2ecf20Sopenharmony_ci *   [   ] [  sample ]   [cache]   [ pmc ]   [unit ]   c     m   [    pmcxsel    ]
448c2ecf20Sopenharmony_ci *     |        |           |                          |     |
458c2ecf20Sopenharmony_ci *     |        |           |                          |     *- mark
468c2ecf20Sopenharmony_ci *     |        |           *- L1/L2/L3 cache_sel      |
478c2ecf20Sopenharmony_ci *     |        |                                      |
488c2ecf20Sopenharmony_ci *     |        *- sampling mode for marked events     *- combine
498c2ecf20Sopenharmony_ci *     |
508c2ecf20Sopenharmony_ci *     *- thresh_sel
518c2ecf20Sopenharmony_ci *
528c2ecf20Sopenharmony_ci * Below uses IBM bit numbering.
538c2ecf20Sopenharmony_ci *
548c2ecf20Sopenharmony_ci * MMCR1[x:y] = unit    (PMCxUNIT)
558c2ecf20Sopenharmony_ci * MMCR1[x]   = combine (PMCxCOMB)
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * if pmc == 3 and unit == 0 and pmcxsel[0:6] == 0b0101011
588c2ecf20Sopenharmony_ci *	# PM_MRK_FAB_RSP_MATCH
598c2ecf20Sopenharmony_ci *	MMCR1[20:27] = thresh_ctl   (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
608c2ecf20Sopenharmony_ci * else if pmc == 4 and unit == 0xf and pmcxsel[0:6] == 0b0101001
618c2ecf20Sopenharmony_ci *	# PM_MRK_FAB_RSP_MATCH_CYC
628c2ecf20Sopenharmony_ci *	MMCR1[20:27] = thresh_ctl   (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
638c2ecf20Sopenharmony_ci * else
648c2ecf20Sopenharmony_ci *	MMCRA[48:55] = thresh_ctl   (THRESH START/END)
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci * if thresh_sel:
678c2ecf20Sopenharmony_ci *	MMCRA[45:47] = thresh_sel
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci * if thresh_cmp:
708c2ecf20Sopenharmony_ci *	MMCRA[22:24] = thresh_cmp[0:2]
718c2ecf20Sopenharmony_ci *	MMCRA[25:31] = thresh_cmp[3:9]
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * if unit == 6 or unit == 7
748c2ecf20Sopenharmony_ci *	MMCRC[53:55] = cache_sel[1:3]      (L2EVENT_SEL)
758c2ecf20Sopenharmony_ci * else if unit == 8 or unit == 9:
768c2ecf20Sopenharmony_ci *	if cache_sel[0] == 0: # L3 bank
778c2ecf20Sopenharmony_ci *		MMCRC[47:49] = cache_sel[1:3]  (L3EVENT_SEL0)
788c2ecf20Sopenharmony_ci *	else if cache_sel[0] == 1:
798c2ecf20Sopenharmony_ci *		MMCRC[50:51] = cache_sel[2:3]  (L3EVENT_SEL1)
808c2ecf20Sopenharmony_ci * else if cache_sel[1]: # L1 event
818c2ecf20Sopenharmony_ci *	MMCR1[16] = cache_sel[2]
828c2ecf20Sopenharmony_ci *	MMCR1[17] = cache_sel[3]
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * if mark:
858c2ecf20Sopenharmony_ci *	MMCRA[63]    = 1		(SAMPLE_ENABLE)
868c2ecf20Sopenharmony_ci *	MMCRA[57:59] = sample[0:2]	(RAND_SAMP_ELIG)
878c2ecf20Sopenharmony_ci *	MMCRA[61:62] = sample[3:4]	(RAND_SAMP_MODE)
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * if EBB and BHRB:
908c2ecf20Sopenharmony_ci *	MMCRA[32:33] = IFM
918c2ecf20Sopenharmony_ci *
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* PowerISA v2.07 format attribute structure*/
958c2ecf20Sopenharmony_ciextern struct attribute_group isa207_pmu_format_group;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* Table of alternatives, sorted by column 0 */
988c2ecf20Sopenharmony_cistatic const unsigned int event_alternatives[][MAX_ALT] = {
998c2ecf20Sopenharmony_ci	{ PM_MRK_ST_CMPL,		PM_MRK_ST_CMPL_ALT },
1008c2ecf20Sopenharmony_ci	{ PM_BR_MRK_2PATH,		PM_BR_MRK_2PATH_ALT },
1018c2ecf20Sopenharmony_ci	{ PM_L3_CO_MEPF,		PM_L3_CO_MEPF_ALT },
1028c2ecf20Sopenharmony_ci	{ PM_MRK_DATA_FROM_L2MISS,	PM_MRK_DATA_FROM_L2MISS_ALT },
1038c2ecf20Sopenharmony_ci	{ PM_CMPLU_STALL_ALT,		PM_CMPLU_STALL },
1048c2ecf20Sopenharmony_ci	{ PM_BR_2PATH,			PM_BR_2PATH_ALT },
1058c2ecf20Sopenharmony_ci	{ PM_INST_DISP,			PM_INST_DISP_ALT },
1068c2ecf20Sopenharmony_ci	{ PM_RUN_CYC_ALT,		PM_RUN_CYC },
1078c2ecf20Sopenharmony_ci	{ PM_MRK_FILT_MATCH,		PM_MRK_FILT_MATCH_ALT },
1088c2ecf20Sopenharmony_ci	{ PM_LD_MISS_L1,		PM_LD_MISS_L1_ALT },
1098c2ecf20Sopenharmony_ci	{ PM_RUN_INST_CMPL_ALT,		PM_RUN_INST_CMPL },
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic int power8_get_alternatives(u64 event, unsigned int flags, u64 alt[])
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	int num_alt = 0;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	num_alt = isa207_get_alternatives(event, alt,
1178c2ecf20Sopenharmony_ci					  ARRAY_SIZE(event_alternatives), flags,
1188c2ecf20Sopenharmony_ci					  event_alternatives);
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	return num_alt;
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(cpu-cycles,			PM_CYC);
1248c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(stalled-cycles-frontend,	PM_GCT_NOSLOT_CYC);
1258c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(stalled-cycles-backend,	PM_CMPLU_STALL);
1268c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(instructions,		PM_INST_CMPL);
1278c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(branch-instructions,		PM_BRU_FIN);
1288c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(branch-misses,		PM_BR_MPRED_CMPL);
1298c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(cache-references,		PM_LD_REF_L1);
1308c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(cache-misses,		PM_LD_MISS_L1);
1318c2ecf20Sopenharmony_ciGENERIC_EVENT_ATTR(mem_access,			MEM_ACCESS);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-dcache-load-misses,		PM_LD_MISS_L1);
1348c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-dcache-loads,		PM_LD_REF_L1);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-dcache-prefetches,		PM_L1_PREF);
1378c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-dcache-store-misses,	PM_ST_MISS_L1);
1388c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-icache-load-misses,		PM_L1_ICACHE_MISS);
1398c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-icache-loads,		PM_INST_FROM_L1);
1408c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(L1-icache-prefetches,		PM_IC_PREF_WRITE);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(LLC-load-misses,		PM_DATA_FROM_L3MISS);
1438c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(LLC-loads,			PM_DATA_FROM_L3);
1448c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(LLC-prefetches,		PM_L3_PREF_ALL);
1458c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(LLC-store-misses,		PM_L2_ST_MISS);
1468c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(LLC-stores,			PM_L2_ST);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(branch-load-misses,		PM_BR_MPRED_CMPL);
1498c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(branch-loads,			PM_BRU_FIN);
1508c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(dTLB-load-misses,		PM_DTLB_MISS);
1518c2ecf20Sopenharmony_ciCACHE_EVENT_ATTR(iTLB-load-misses,		PM_ITLB_MISS);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistatic struct attribute *power8_events_attr[] = {
1548c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_CYC),
1558c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_GCT_NOSLOT_CYC),
1568c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_CMPLU_STALL),
1578c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_INST_CMPL),
1588c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_BRU_FIN),
1598c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL),
1608c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_LD_REF_L1),
1618c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(PM_LD_MISS_L1),
1628c2ecf20Sopenharmony_ci	GENERIC_EVENT_PTR(MEM_ACCESS),
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_LD_MISS_L1),
1658c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_LD_REF_L1),
1668c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_L1_PREF),
1678c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_ST_MISS_L1),
1688c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_L1_ICACHE_MISS),
1698c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_INST_FROM_L1),
1708c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_IC_PREF_WRITE),
1718c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS),
1728c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_DATA_FROM_L3),
1738c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_L3_PREF_ALL),
1748c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_L2_ST_MISS),
1758c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_L2_ST),
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_BR_MPRED_CMPL),
1788c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_BRU_FIN),
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_DTLB_MISS),
1818c2ecf20Sopenharmony_ci	CACHE_EVENT_PTR(PM_ITLB_MISS),
1828c2ecf20Sopenharmony_ci	NULL
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistatic struct attribute_group power8_pmu_events_group = {
1868c2ecf20Sopenharmony_ci	.name = "events",
1878c2ecf20Sopenharmony_ci	.attrs = power8_events_attr,
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic const struct attribute_group *power8_pmu_attr_groups[] = {
1918c2ecf20Sopenharmony_ci	&isa207_pmu_format_group,
1928c2ecf20Sopenharmony_ci	&power8_pmu_events_group,
1938c2ecf20Sopenharmony_ci	NULL,
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic int power8_generic_events[] = {
1978c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CPU_CYCLES] =			PM_CYC,
1988c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =	PM_GCT_NOSLOT_CYC,
1998c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =	PM_CMPLU_STALL,
2008c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_INSTRUCTIONS] =			PM_INST_CMPL,
2018c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] =		PM_BRU_FIN,
2028c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_MISSES] =			PM_BR_MPRED_CMPL,
2038c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_REFERENCES] =		PM_LD_REF_L1,
2048c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_MISSES] =			PM_LD_MISS_L1,
2058c2ecf20Sopenharmony_ci};
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic u64 power8_bhrb_filter_map(u64 branch_sample_type)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	u64 pmu_bhrb_filter = 0;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	/* BHRB and regular PMU events share the same privilege state
2128c2ecf20Sopenharmony_ci	 * filter configuration. BHRB is always recorded along with a
2138c2ecf20Sopenharmony_ci	 * regular PMU event. As the privilege state filter is handled
2148c2ecf20Sopenharmony_ci	 * in the basic PMC configuration of the accompanying regular
2158c2ecf20Sopenharmony_ci	 * PMU event, we ignore any separate BHRB specific request.
2168c2ecf20Sopenharmony_ci	 */
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	/* No branch filter requested */
2198c2ecf20Sopenharmony_ci	if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY)
2208c2ecf20Sopenharmony_ci		return pmu_bhrb_filter;
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	/* Invalid branch filter options - HW does not support */
2238c2ecf20Sopenharmony_ci	if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
2248c2ecf20Sopenharmony_ci		return -1;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
2278c2ecf20Sopenharmony_ci		return -1;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
2308c2ecf20Sopenharmony_ci		return -1;
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
2338c2ecf20Sopenharmony_ci		pmu_bhrb_filter |= POWER8_MMCRA_IFM1;
2348c2ecf20Sopenharmony_ci		return pmu_bhrb_filter;
2358c2ecf20Sopenharmony_ci	}
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	/* Every thing else is unsupported */
2388c2ecf20Sopenharmony_ci	return -1;
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic void power8_config_bhrb(u64 pmu_bhrb_filter)
2428c2ecf20Sopenharmony_ci{
2438c2ecf20Sopenharmony_ci	pmu_bhrb_filter &= POWER8_MMCRA_BHRB_MASK;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	/* Enable BHRB filter in PMU */
2468c2ecf20Sopenharmony_ci	mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci#define C(x)	PERF_COUNT_HW_CACHE_##x
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/*
2528c2ecf20Sopenharmony_ci * Table of generalized cache-related events.
2538c2ecf20Sopenharmony_ci * 0 means not supported, -1 means nonsensical, other values
2548c2ecf20Sopenharmony_ci * are event codes.
2558c2ecf20Sopenharmony_ci */
2568c2ecf20Sopenharmony_cistatic u64 power8_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
2578c2ecf20Sopenharmony_ci	[ C(L1D) ] = {
2588c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
2598c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_LD_REF_L1,
2608c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_LD_MISS_L1,
2618c2ecf20Sopenharmony_ci		},
2628c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
2638c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = 0,
2648c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_ST_MISS_L1,
2658c2ecf20Sopenharmony_ci		},
2668c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
2678c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_L1_PREF,
2688c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = 0,
2698c2ecf20Sopenharmony_ci		},
2708c2ecf20Sopenharmony_ci	},
2718c2ecf20Sopenharmony_ci	[ C(L1I) ] = {
2728c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
2738c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_INST_FROM_L1,
2748c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_L1_ICACHE_MISS,
2758c2ecf20Sopenharmony_ci		},
2768c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
2778c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_L1_DEMAND_WRITE,
2788c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
2798c2ecf20Sopenharmony_ci		},
2808c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
2818c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_IC_PREF_WRITE,
2828c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = 0,
2838c2ecf20Sopenharmony_ci		},
2848c2ecf20Sopenharmony_ci	},
2858c2ecf20Sopenharmony_ci	[ C(LL) ] = {
2868c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
2878c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_DATA_FROM_L3,
2888c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_DATA_FROM_L3MISS,
2898c2ecf20Sopenharmony_ci		},
2908c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
2918c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_L2_ST,
2928c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_L2_ST_MISS,
2938c2ecf20Sopenharmony_ci		},
2948c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
2958c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_L3_PREF_ALL,
2968c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = 0,
2978c2ecf20Sopenharmony_ci		},
2988c2ecf20Sopenharmony_ci	},
2998c2ecf20Sopenharmony_ci	[ C(DTLB) ] = {
3008c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
3018c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = 0,
3028c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_DTLB_MISS,
3038c2ecf20Sopenharmony_ci		},
3048c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
3058c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3068c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3078c2ecf20Sopenharmony_ci		},
3088c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
3098c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3108c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3118c2ecf20Sopenharmony_ci		},
3128c2ecf20Sopenharmony_ci	},
3138c2ecf20Sopenharmony_ci	[ C(ITLB) ] = {
3148c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
3158c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = 0,
3168c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_ITLB_MISS,
3178c2ecf20Sopenharmony_ci		},
3188c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
3198c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3208c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3218c2ecf20Sopenharmony_ci		},
3228c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
3238c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3248c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3258c2ecf20Sopenharmony_ci		},
3268c2ecf20Sopenharmony_ci	},
3278c2ecf20Sopenharmony_ci	[ C(BPU) ] = {
3288c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
3298c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = PM_BRU_FIN,
3308c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = PM_BR_MPRED_CMPL,
3318c2ecf20Sopenharmony_ci		},
3328c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
3338c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3348c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3358c2ecf20Sopenharmony_ci		},
3368c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
3378c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3388c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3398c2ecf20Sopenharmony_ci		},
3408c2ecf20Sopenharmony_ci	},
3418c2ecf20Sopenharmony_ci	[ C(NODE) ] = {
3428c2ecf20Sopenharmony_ci		[ C(OP_READ) ] = {
3438c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3448c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3458c2ecf20Sopenharmony_ci		},
3468c2ecf20Sopenharmony_ci		[ C(OP_WRITE) ] = {
3478c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3488c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3498c2ecf20Sopenharmony_ci		},
3508c2ecf20Sopenharmony_ci		[ C(OP_PREFETCH) ] = {
3518c2ecf20Sopenharmony_ci			[ C(RESULT_ACCESS) ] = -1,
3528c2ecf20Sopenharmony_ci			[ C(RESULT_MISS)   ] = -1,
3538c2ecf20Sopenharmony_ci		},
3548c2ecf20Sopenharmony_ci	},
3558c2ecf20Sopenharmony_ci};
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci#undef C
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_cistatic struct power_pmu power8_pmu = {
3608c2ecf20Sopenharmony_ci	.name			= "POWER8",
3618c2ecf20Sopenharmony_ci	.n_counter		= MAX_PMU_COUNTERS,
3628c2ecf20Sopenharmony_ci	.max_alternatives	= MAX_ALT + 1,
3638c2ecf20Sopenharmony_ci	.add_fields		= ISA207_ADD_FIELDS,
3648c2ecf20Sopenharmony_ci	.test_adder		= ISA207_TEST_ADDER,
3658c2ecf20Sopenharmony_ci	.compute_mmcr		= isa207_compute_mmcr,
3668c2ecf20Sopenharmony_ci	.config_bhrb		= power8_config_bhrb,
3678c2ecf20Sopenharmony_ci	.bhrb_filter_map	= power8_bhrb_filter_map,
3688c2ecf20Sopenharmony_ci	.get_constraint		= isa207_get_constraint,
3698c2ecf20Sopenharmony_ci	.get_alternatives	= power8_get_alternatives,
3708c2ecf20Sopenharmony_ci	.get_mem_data_src	= isa207_get_mem_data_src,
3718c2ecf20Sopenharmony_ci	.get_mem_weight		= isa207_get_mem_weight,
3728c2ecf20Sopenharmony_ci	.disable_pmc		= isa207_disable_pmc,
3738c2ecf20Sopenharmony_ci	.flags			= PPMU_HAS_SIER | PPMU_ARCH_207S,
3748c2ecf20Sopenharmony_ci	.n_generic		= ARRAY_SIZE(power8_generic_events),
3758c2ecf20Sopenharmony_ci	.generic_events		= power8_generic_events,
3768c2ecf20Sopenharmony_ci	.cache_events		= &power8_cache_events,
3778c2ecf20Sopenharmony_ci	.attr_groups		= power8_pmu_attr_groups,
3788c2ecf20Sopenharmony_ci	.bhrb_nr		= 32,
3798c2ecf20Sopenharmony_ci};
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ciint init_power8_pmu(void)
3828c2ecf20Sopenharmony_ci{
3838c2ecf20Sopenharmony_ci	int rc;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	if (!cur_cpu_spec->oprofile_cpu_type ||
3868c2ecf20Sopenharmony_ci	    strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
3878c2ecf20Sopenharmony_ci		return -ENODEV;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	rc = register_power_pmu(&power8_pmu);
3908c2ecf20Sopenharmony_ci	if (rc)
3918c2ecf20Sopenharmony_ci		return rc;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	/* Tell userspace that EBB is supported */
3948c2ecf20Sopenharmony_ci	cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_EBB;
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	if (cpu_has_feature(CPU_FTR_PMAO_BUG))
3978c2ecf20Sopenharmony_ci		pr_info("PMAO restore workaround active.\n");
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	return 0;
4008c2ecf20Sopenharmony_ci}
401