18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (C) 2008-2018 Andes Technology Corporation */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __ASM_PMU_H
58c2ecf20Sopenharmony_ci#define __ASM_PMU_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
88c2ecf20Sopenharmony_ci#include <linux/perf_event.h>
98c2ecf20Sopenharmony_ci#include <asm/unistd.h>
108c2ecf20Sopenharmony_ci#include <asm/bitfield.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* Has special meaning for perf core implementation */
138c2ecf20Sopenharmony_ci#define HW_OP_UNSUPPORTED		0x0
148c2ecf20Sopenharmony_ci#define C(_x)				PERF_COUNT_HW_CACHE_##_x
158c2ecf20Sopenharmony_ci#define CACHE_OP_UNSUPPORTED		0x0
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* Enough for both software and hardware defined events */
188c2ecf20Sopenharmony_ci#define SOFTWARE_EVENT_MASK		0xFF
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define PFM_OFFSET_MAGIC_0		2	/* DO NOT START FROM 0 */
218c2ecf20Sopenharmony_ci#define PFM_OFFSET_MAGIC_1		(PFM_OFFSET_MAGIC_0 + 36)
228c2ecf20Sopenharmony_ci#define PFM_OFFSET_MAGIC_2		(PFM_OFFSET_MAGIC_1 + 36)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cienum { PFMC0, PFMC1, PFMC2, MAX_COUNTERS };
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciu32 PFM_CTL_OVF[3] = { PFM_CTL_mskOVF0, PFM_CTL_mskOVF1,
278c2ecf20Sopenharmony_ci		       PFM_CTL_mskOVF2 };
288c2ecf20Sopenharmony_ciu32 PFM_CTL_EN[3] = { PFM_CTL_mskEN0, PFM_CTL_mskEN1,
298c2ecf20Sopenharmony_ci		      PFM_CTL_mskEN2 };
308c2ecf20Sopenharmony_ciu32 PFM_CTL_OFFSEL[3] = { PFM_CTL_offSEL0, PFM_CTL_offSEL1,
318c2ecf20Sopenharmony_ci			  PFM_CTL_offSEL2 };
328c2ecf20Sopenharmony_ciu32 PFM_CTL_IE[3] = { PFM_CTL_mskIE0, PFM_CTL_mskIE1, PFM_CTL_mskIE2 };
338c2ecf20Sopenharmony_ciu32 PFM_CTL_KS[3] = { PFM_CTL_mskKS0, PFM_CTL_mskKS1, PFM_CTL_mskKS2 };
348c2ecf20Sopenharmony_ciu32 PFM_CTL_KU[3] = { PFM_CTL_mskKU0, PFM_CTL_mskKU1, PFM_CTL_mskKU2 };
358c2ecf20Sopenharmony_ciu32 PFM_CTL_SEL[3] = { PFM_CTL_mskSEL0, PFM_CTL_mskSEL1, PFM_CTL_mskSEL2 };
368c2ecf20Sopenharmony_ci/*
378c2ecf20Sopenharmony_ci * Perf Events' indices
388c2ecf20Sopenharmony_ci */
398c2ecf20Sopenharmony_ci#define NDS32_IDX_CYCLE_COUNTER			0
408c2ecf20Sopenharmony_ci#define NDS32_IDX_COUNTER0			1
418c2ecf20Sopenharmony_ci#define NDS32_IDX_COUNTER1			2
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* The events for a given PMU register set. */
448c2ecf20Sopenharmony_cistruct pmu_hw_events {
458c2ecf20Sopenharmony_ci	/*
468c2ecf20Sopenharmony_ci	 * The events that are active on the PMU for the given index.
478c2ecf20Sopenharmony_ci	 */
488c2ecf20Sopenharmony_ci	struct perf_event *events[MAX_COUNTERS];
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	/*
518c2ecf20Sopenharmony_ci	 * A 1 bit for an index indicates that the counter is being used for
528c2ecf20Sopenharmony_ci	 * an event. A 0 means that the counter can be used.
538c2ecf20Sopenharmony_ci	 */
548c2ecf20Sopenharmony_ci	unsigned long used_mask[BITS_TO_LONGS(MAX_COUNTERS)];
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/*
578c2ecf20Sopenharmony_ci	 * Hardware lock to serialize accesses to PMU registers. Needed for the
588c2ecf20Sopenharmony_ci	 * read/modify/write sequences.
598c2ecf20Sopenharmony_ci	 */
608c2ecf20Sopenharmony_ci	raw_spinlock_t pmu_lock;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct nds32_pmu {
648c2ecf20Sopenharmony_ci	struct pmu pmu;
658c2ecf20Sopenharmony_ci	cpumask_t active_irqs;
668c2ecf20Sopenharmony_ci	char *name;
678c2ecf20Sopenharmony_ci	 irqreturn_t (*handle_irq)(int irq_num, void *dev);
688c2ecf20Sopenharmony_ci	void (*enable)(struct perf_event *event);
698c2ecf20Sopenharmony_ci	void (*disable)(struct perf_event *event);
708c2ecf20Sopenharmony_ci	int (*get_event_idx)(struct pmu_hw_events *hw_events,
718c2ecf20Sopenharmony_ci			     struct perf_event *event);
728c2ecf20Sopenharmony_ci	int (*set_event_filter)(struct hw_perf_event *evt,
738c2ecf20Sopenharmony_ci				struct perf_event_attr *attr);
748c2ecf20Sopenharmony_ci	u32 (*read_counter)(struct perf_event *event);
758c2ecf20Sopenharmony_ci	void (*write_counter)(struct perf_event *event, u32 val);
768c2ecf20Sopenharmony_ci	void (*start)(struct nds32_pmu *nds32_pmu);
778c2ecf20Sopenharmony_ci	void (*stop)(struct nds32_pmu *nds32_pmu);
788c2ecf20Sopenharmony_ci	void (*reset)(void *data);
798c2ecf20Sopenharmony_ci	int (*request_irq)(struct nds32_pmu *nds32_pmu, irq_handler_t handler);
808c2ecf20Sopenharmony_ci	void (*free_irq)(struct nds32_pmu *nds32_pmu);
818c2ecf20Sopenharmony_ci	int (*map_event)(struct perf_event *event);
828c2ecf20Sopenharmony_ci	int num_events;
838c2ecf20Sopenharmony_ci	atomic_t active_events;
848c2ecf20Sopenharmony_ci	u64 max_period;
858c2ecf20Sopenharmony_ci	struct platform_device *plat_device;
868c2ecf20Sopenharmony_ci	struct pmu_hw_events *(*get_hw_events)(void);
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define to_nds32_pmu(p)			(container_of(p, struct nds32_pmu, pmu))
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciint nds32_pmu_register(struct nds32_pmu *nds32_pmu, int type);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciu64 nds32_pmu_event_update(struct perf_event *event);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciint nds32_pmu_event_set_period(struct perf_event *event);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * Common NDS32 SPAv3 event types
998c2ecf20Sopenharmony_ci *
1008c2ecf20Sopenharmony_ci * Note: An implementation may not be able to count all of these events
1018c2ecf20Sopenharmony_ci * but the encodings are considered to be `reserved' in the case that
1028c2ecf20Sopenharmony_ci * they are not available.
1038c2ecf20Sopenharmony_ci *
1048c2ecf20Sopenharmony_ci * SEL_TOTAL_CYCLES will add an offset is due to ZERO is defined as
1058c2ecf20Sopenharmony_ci * NOT_SUPPORTED EVENT mapping in generic perf code.
1068c2ecf20Sopenharmony_ci * You will need to deal it in the event writing implementation.
1078c2ecf20Sopenharmony_ci */
1088c2ecf20Sopenharmony_cienum spav3_counter_0_perf_types {
1098c2ecf20Sopenharmony_ci	SPAV3_0_SEL_BASE = -1 + PFM_OFFSET_MAGIC_0,	/* counting symbol */
1108c2ecf20Sopenharmony_ci	SPAV3_0_SEL_TOTAL_CYCLES = 0 + PFM_OFFSET_MAGIC_0,
1118c2ecf20Sopenharmony_ci	SPAV3_0_SEL_COMPLETED_INSTRUCTION = 1 + PFM_OFFSET_MAGIC_0,
1128c2ecf20Sopenharmony_ci	SPAV3_0_SEL_LAST	/* counting symbol */
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cienum spav3_counter_1_perf_types {
1168c2ecf20Sopenharmony_ci	SPAV3_1_SEL_BASE = -1 + PFM_OFFSET_MAGIC_1,	/* counting symbol */
1178c2ecf20Sopenharmony_ci	SPAV3_1_SEL_TOTAL_CYCLES = 0 + PFM_OFFSET_MAGIC_1,
1188c2ecf20Sopenharmony_ci	SPAV3_1_SEL_COMPLETED_INSTRUCTION = 1 + PFM_OFFSET_MAGIC_1,
1198c2ecf20Sopenharmony_ci	SPAV3_1_SEL_CONDITIONAL_BRANCH = 2 + PFM_OFFSET_MAGIC_1,
1208c2ecf20Sopenharmony_ci	SPAV3_1_SEL_TAKEN_CONDITIONAL_BRANCH = 3 + PFM_OFFSET_MAGIC_1,
1218c2ecf20Sopenharmony_ci	SPAV3_1_SEL_PREFETCH_INSTRUCTION = 4 + PFM_OFFSET_MAGIC_1,
1228c2ecf20Sopenharmony_ci	SPAV3_1_SEL_RET_INST = 5 + PFM_OFFSET_MAGIC_1,
1238c2ecf20Sopenharmony_ci	SPAV3_1_SEL_JR_INST = 6 + PFM_OFFSET_MAGIC_1,
1248c2ecf20Sopenharmony_ci	SPAV3_1_SEL_JAL_JRAL_INST = 7 + PFM_OFFSET_MAGIC_1,
1258c2ecf20Sopenharmony_ci	SPAV3_1_SEL_NOP_INST = 8 + PFM_OFFSET_MAGIC_1,
1268c2ecf20Sopenharmony_ci	SPAV3_1_SEL_SCW_INST = 9 + PFM_OFFSET_MAGIC_1,
1278c2ecf20Sopenharmony_ci	SPAV3_1_SEL_ISB_DSB_INST = 10 + PFM_OFFSET_MAGIC_1,
1288c2ecf20Sopenharmony_ci	SPAV3_1_SEL_CCTL_INST = 11 + PFM_OFFSET_MAGIC_1,
1298c2ecf20Sopenharmony_ci	SPAV3_1_SEL_TAKEN_INTERRUPTS = 12 + PFM_OFFSET_MAGIC_1,
1308c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LOADS_COMPLETED = 13 + PFM_OFFSET_MAGIC_1,
1318c2ecf20Sopenharmony_ci	SPAV3_1_SEL_UITLB_ACCESS = 14 + PFM_OFFSET_MAGIC_1,
1328c2ecf20Sopenharmony_ci	SPAV3_1_SEL_UDTLB_ACCESS = 15 + PFM_OFFSET_MAGIC_1,
1338c2ecf20Sopenharmony_ci	SPAV3_1_SEL_MTLB_ACCESS = 16 + PFM_OFFSET_MAGIC_1,
1348c2ecf20Sopenharmony_ci	SPAV3_1_SEL_CODE_CACHE_ACCESS = 17 + PFM_OFFSET_MAGIC_1,
1358c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DATA_DEPENDENCY_STALL_CYCLES = 18 + PFM_OFFSET_MAGIC_1,
1368c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DATA_CACHE_MISS_STALL_CYCLES = 19 + PFM_OFFSET_MAGIC_1,
1378c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DATA_CACHE_ACCESS = 20 + PFM_OFFSET_MAGIC_1,
1388c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DATA_CACHE_MISS = 21 + PFM_OFFSET_MAGIC_1,
1398c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LOAD_DATA_CACHE_ACCESS = 22 + PFM_OFFSET_MAGIC_1,
1408c2ecf20Sopenharmony_ci	SPAV3_1_SEL_STORE_DATA_CACHE_ACCESS = 23 + PFM_OFFSET_MAGIC_1,
1418c2ecf20Sopenharmony_ci	SPAV3_1_SEL_ILM_ACCESS = 24 + PFM_OFFSET_MAGIC_1,
1428c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LSU_BIU_CYCLES = 25 + PFM_OFFSET_MAGIC_1,
1438c2ecf20Sopenharmony_ci	SPAV3_1_SEL_HPTWK_BIU_CYCLES = 26 + PFM_OFFSET_MAGIC_1,
1448c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DMA_BIU_CYCLES = 27 + PFM_OFFSET_MAGIC_1,
1458c2ecf20Sopenharmony_ci	SPAV3_1_SEL_CODE_CACHE_FILL_BIU_CYCLES = 28 + PFM_OFFSET_MAGIC_1,
1468c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LEGAL_UNALIGN_DCACHE_ACCESS = 29 + PFM_OFFSET_MAGIC_1,
1478c2ecf20Sopenharmony_ci	SPAV3_1_SEL_PUSH25 = 30 + PFM_OFFSET_MAGIC_1,
1488c2ecf20Sopenharmony_ci	SPAV3_1_SEL_SYSCALLS_INST = 31 + PFM_OFFSET_MAGIC_1,
1498c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LAST	/* counting symbol */
1508c2ecf20Sopenharmony_ci};
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cienum spav3_counter_2_perf_types {
1538c2ecf20Sopenharmony_ci	SPAV3_2_SEL_BASE = -1 + PFM_OFFSET_MAGIC_2,	/* counting symbol */
1548c2ecf20Sopenharmony_ci	SPAV3_2_SEL_TOTAL_CYCLES = 0 + PFM_OFFSET_MAGIC_2,
1558c2ecf20Sopenharmony_ci	SPAV3_2_SEL_COMPLETED_INSTRUCTION = 1 + PFM_OFFSET_MAGIC_2,
1568c2ecf20Sopenharmony_ci	SPAV3_2_SEL_CONDITIONAL_BRANCH_MISPREDICT = 2 + PFM_OFFSET_MAGIC_2,
1578c2ecf20Sopenharmony_ci	SPAV3_2_SEL_TAKEN_CONDITIONAL_BRANCH_MISPREDICT =
1588c2ecf20Sopenharmony_ci	    3 + PFM_OFFSET_MAGIC_2,
1598c2ecf20Sopenharmony_ci	SPAV3_2_SEL_PREFETCH_INSTRUCTION_CACHE_HIT = 4 + PFM_OFFSET_MAGIC_2,
1608c2ecf20Sopenharmony_ci	SPAV3_1_SEL_RET_MISPREDICT = 5 + PFM_OFFSET_MAGIC_2,
1618c2ecf20Sopenharmony_ci	SPAV3_1_SEL_IMMEDIATE_J_INST = 6 + PFM_OFFSET_MAGIC_2,
1628c2ecf20Sopenharmony_ci	SPAV3_1_SEL_MULTIPLY_INST = 7 + PFM_OFFSET_MAGIC_2,
1638c2ecf20Sopenharmony_ci	SPAV3_1_SEL_16_BIT_INST = 8 + PFM_OFFSET_MAGIC_2,
1648c2ecf20Sopenharmony_ci	SPAV3_1_SEL_FAILED_SCW_INST = 9 + PFM_OFFSET_MAGIC_2,
1658c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LD_AFTER_ST_CONFLICT_REPLAYS = 10 + PFM_OFFSET_MAGIC_2,
1668c2ecf20Sopenharmony_ci	SPAV3_1_SEL_TAKEN_EXCEPTIONS = 12 + PFM_OFFSET_MAGIC_2,
1678c2ecf20Sopenharmony_ci	SPAV3_1_SEL_STORES_COMPLETED = 13 + PFM_OFFSET_MAGIC_2,
1688c2ecf20Sopenharmony_ci	SPAV3_2_SEL_UITLB_MISS = 14 + PFM_OFFSET_MAGIC_2,
1698c2ecf20Sopenharmony_ci	SPAV3_2_SEL_UDTLB_MISS = 15 + PFM_OFFSET_MAGIC_2,
1708c2ecf20Sopenharmony_ci	SPAV3_2_SEL_MTLB_MISS = 16 + PFM_OFFSET_MAGIC_2,
1718c2ecf20Sopenharmony_ci	SPAV3_2_SEL_CODE_CACHE_MISS = 17 + PFM_OFFSET_MAGIC_2,
1728c2ecf20Sopenharmony_ci	SPAV3_1_SEL_EMPTY_INST_QUEUE_STALL_CYCLES = 18 + PFM_OFFSET_MAGIC_2,
1738c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DATA_WRITE_BACK = 19 + PFM_OFFSET_MAGIC_2,
1748c2ecf20Sopenharmony_ci	SPAV3_2_SEL_DATA_CACHE_MISS = 21 + PFM_OFFSET_MAGIC_2,
1758c2ecf20Sopenharmony_ci	SPAV3_2_SEL_LOAD_DATA_CACHE_MISS = 22 + PFM_OFFSET_MAGIC_2,
1768c2ecf20Sopenharmony_ci	SPAV3_2_SEL_STORE_DATA_CACHE_MISS = 23 + PFM_OFFSET_MAGIC_2,
1778c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DLM_ACCESS = 24 + PFM_OFFSET_MAGIC_2,
1788c2ecf20Sopenharmony_ci	SPAV3_1_SEL_LSU_BIU_REQUEST = 25 + PFM_OFFSET_MAGIC_2,
1798c2ecf20Sopenharmony_ci	SPAV3_1_SEL_HPTWK_BIU_REQUEST = 26 + PFM_OFFSET_MAGIC_2,
1808c2ecf20Sopenharmony_ci	SPAV3_1_SEL_DMA_BIU_REQUEST = 27 + PFM_OFFSET_MAGIC_2,
1818c2ecf20Sopenharmony_ci	SPAV3_1_SEL_CODE_CACHE_FILL_BIU_REQUEST = 28 + PFM_OFFSET_MAGIC_2,
1828c2ecf20Sopenharmony_ci	SPAV3_1_SEL_EXTERNAL_EVENTS = 29 + PFM_OFFSET_MAGIC_2,
1838c2ecf20Sopenharmony_ci	SPAV3_1_SEL_POP25 = 30 + PFM_OFFSET_MAGIC_2,
1848c2ecf20Sopenharmony_ci	SPAV3_2_SEL_LAST	/* counting symbol */
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci/* Get converted event counter index */
1888c2ecf20Sopenharmony_cistatic inline int get_converted_event_idx(unsigned long event)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	int idx;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	if ((event) > SPAV3_0_SEL_BASE && event < SPAV3_0_SEL_LAST) {
1938c2ecf20Sopenharmony_ci		idx = 0;
1948c2ecf20Sopenharmony_ci	} else if ((event) > SPAV3_1_SEL_BASE && event < SPAV3_1_SEL_LAST) {
1958c2ecf20Sopenharmony_ci		idx = 1;
1968c2ecf20Sopenharmony_ci	} else if ((event) > SPAV3_2_SEL_BASE && event < SPAV3_2_SEL_LAST) {
1978c2ecf20Sopenharmony_ci		idx = 2;
1988c2ecf20Sopenharmony_ci	} else {
1998c2ecf20Sopenharmony_ci		pr_err("GET_CONVERTED_EVENT_IDX PFM counter range error\n");
2008c2ecf20Sopenharmony_ci		return -EPERM;
2018c2ecf20Sopenharmony_ci	}
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	return idx;
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/* Get converted hardware event number */
2078c2ecf20Sopenharmony_cistatic inline u32 get_converted_evet_hw_num(u32 event)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	if (event > SPAV3_0_SEL_BASE && event < SPAV3_0_SEL_LAST)
2108c2ecf20Sopenharmony_ci		event -= PFM_OFFSET_MAGIC_0;
2118c2ecf20Sopenharmony_ci	else if (event > SPAV3_1_SEL_BASE && event < SPAV3_1_SEL_LAST)
2128c2ecf20Sopenharmony_ci		event -= PFM_OFFSET_MAGIC_1;
2138c2ecf20Sopenharmony_ci	else if (event > SPAV3_2_SEL_BASE && event < SPAV3_2_SEL_LAST)
2148c2ecf20Sopenharmony_ci		event -= PFM_OFFSET_MAGIC_2;
2158c2ecf20Sopenharmony_ci	else if (event != 0)
2168c2ecf20Sopenharmony_ci		pr_err("GET_CONVERTED_EVENT_HW_NUM PFM counter range error\n");
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	return event;
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci/*
2228c2ecf20Sopenharmony_ci * NDS32 HW events mapping
2238c2ecf20Sopenharmony_ci *
2248c2ecf20Sopenharmony_ci * The hardware events that we support. We do support cache operations but
2258c2ecf20Sopenharmony_ci * we have harvard caches and no way to combine instruction and data
2268c2ecf20Sopenharmony_ci * accesses/misses in hardware.
2278c2ecf20Sopenharmony_ci */
2288c2ecf20Sopenharmony_cistatic const unsigned int nds32_pfm_perf_map[PERF_COUNT_HW_MAX] = {
2298c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CPU_CYCLES] = SPAV3_0_SEL_TOTAL_CYCLES,
2308c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_INSTRUCTIONS] = SPAV3_1_SEL_COMPLETED_INSTRUCTION,
2318c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_REFERENCES] = SPAV3_1_SEL_DATA_CACHE_ACCESS,
2328c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_MISSES] = SPAV3_2_SEL_DATA_CACHE_MISS,
2338c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = HW_OP_UNSUPPORTED,
2348c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BRANCH_MISSES] = HW_OP_UNSUPPORTED,
2358c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_BUS_CYCLES] = HW_OP_UNSUPPORTED,
2368c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = HW_OP_UNSUPPORTED,
2378c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = HW_OP_UNSUPPORTED,
2388c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_REF_CPU_CYCLES] = HW_OP_UNSUPPORTED
2398c2ecf20Sopenharmony_ci};
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic const unsigned int nds32_pfm_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
2428c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_OP_MAX]
2438c2ecf20Sopenharmony_ci	[PERF_COUNT_HW_CACHE_RESULT_MAX] = {
2448c2ecf20Sopenharmony_ci	[C(L1D)] = {
2458c2ecf20Sopenharmony_ci		    [C(OP_READ)] = {
2468c2ecf20Sopenharmony_ci				    [C(RESULT_ACCESS)] =
2478c2ecf20Sopenharmony_ci				    SPAV3_1_SEL_LOAD_DATA_CACHE_ACCESS,
2488c2ecf20Sopenharmony_ci				    [C(RESULT_MISS)] =
2498c2ecf20Sopenharmony_ci				    SPAV3_2_SEL_LOAD_DATA_CACHE_MISS,
2508c2ecf20Sopenharmony_ci				    },
2518c2ecf20Sopenharmony_ci		    [C(OP_WRITE)] = {
2528c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] =
2538c2ecf20Sopenharmony_ci				     SPAV3_1_SEL_STORE_DATA_CACHE_ACCESS,
2548c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] =
2558c2ecf20Sopenharmony_ci				     SPAV3_2_SEL_STORE_DATA_CACHE_MISS,
2568c2ecf20Sopenharmony_ci				     },
2578c2ecf20Sopenharmony_ci		    [C(OP_PREFETCH)] = {
2588c2ecf20Sopenharmony_ci					[C(RESULT_ACCESS)] =
2598c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
2608c2ecf20Sopenharmony_ci					[C(RESULT_MISS)] =
2618c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
2628c2ecf20Sopenharmony_ci					},
2638c2ecf20Sopenharmony_ci		    },
2648c2ecf20Sopenharmony_ci	[C(L1I)] = {
2658c2ecf20Sopenharmony_ci		    [C(OP_READ)] = {
2668c2ecf20Sopenharmony_ci				    [C(RESULT_ACCESS)] =
2678c2ecf20Sopenharmony_ci				    SPAV3_1_SEL_CODE_CACHE_ACCESS,
2688c2ecf20Sopenharmony_ci				    [C(RESULT_MISS)] =
2698c2ecf20Sopenharmony_ci				    SPAV3_2_SEL_CODE_CACHE_MISS,
2708c2ecf20Sopenharmony_ci				    },
2718c2ecf20Sopenharmony_ci		    [C(OP_WRITE)] = {
2728c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] =
2738c2ecf20Sopenharmony_ci				     SPAV3_1_SEL_CODE_CACHE_ACCESS,
2748c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] =
2758c2ecf20Sopenharmony_ci				     SPAV3_2_SEL_CODE_CACHE_MISS,
2768c2ecf20Sopenharmony_ci				     },
2778c2ecf20Sopenharmony_ci		    [C(OP_PREFETCH)] = {
2788c2ecf20Sopenharmony_ci					[C(RESULT_ACCESS)] =
2798c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
2808c2ecf20Sopenharmony_ci					[C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
2818c2ecf20Sopenharmony_ci					},
2828c2ecf20Sopenharmony_ci		    },
2838c2ecf20Sopenharmony_ci	/* TODO: L2CC */
2848c2ecf20Sopenharmony_ci	[C(LL)] = {
2858c2ecf20Sopenharmony_ci		   [C(OP_READ)] = {
2868c2ecf20Sopenharmony_ci				   [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
2878c2ecf20Sopenharmony_ci				   [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
2888c2ecf20Sopenharmony_ci				   },
2898c2ecf20Sopenharmony_ci		   [C(OP_WRITE)] = {
2908c2ecf20Sopenharmony_ci				    [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
2918c2ecf20Sopenharmony_ci				    [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
2928c2ecf20Sopenharmony_ci				    },
2938c2ecf20Sopenharmony_ci		   [C(OP_PREFETCH)] = {
2948c2ecf20Sopenharmony_ci				       [C(RESULT_ACCESS)] =
2958c2ecf20Sopenharmony_ci				       CACHE_OP_UNSUPPORTED,
2968c2ecf20Sopenharmony_ci				       [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
2978c2ecf20Sopenharmony_ci				       },
2988c2ecf20Sopenharmony_ci		   },
2998c2ecf20Sopenharmony_ci	/* NDS32 PMU does not support TLB read/write hit/miss,
3008c2ecf20Sopenharmony_ci	 * However, it can count access/miss, which mixed with read and write.
3018c2ecf20Sopenharmony_ci	 * Therefore, only READ counter will use it.
3028c2ecf20Sopenharmony_ci	 * We do as possible as we can.
3038c2ecf20Sopenharmony_ci	 */
3048c2ecf20Sopenharmony_ci	[C(DTLB)] = {
3058c2ecf20Sopenharmony_ci		     [C(OP_READ)] = {
3068c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] =
3078c2ecf20Sopenharmony_ci					SPAV3_1_SEL_UDTLB_ACCESS,
3088c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] =
3098c2ecf20Sopenharmony_ci					SPAV3_2_SEL_UDTLB_MISS,
3108c2ecf20Sopenharmony_ci				     },
3118c2ecf20Sopenharmony_ci		     [C(OP_WRITE)] = {
3128c2ecf20Sopenharmony_ci				      [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
3138c2ecf20Sopenharmony_ci				      [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
3148c2ecf20Sopenharmony_ci				      },
3158c2ecf20Sopenharmony_ci		     [C(OP_PREFETCH)] = {
3168c2ecf20Sopenharmony_ci					 [C(RESULT_ACCESS)] =
3178c2ecf20Sopenharmony_ci					 CACHE_OP_UNSUPPORTED,
3188c2ecf20Sopenharmony_ci					 [C(RESULT_MISS)] =
3198c2ecf20Sopenharmony_ci					 CACHE_OP_UNSUPPORTED,
3208c2ecf20Sopenharmony_ci					 },
3218c2ecf20Sopenharmony_ci		     },
3228c2ecf20Sopenharmony_ci	[C(ITLB)] = {
3238c2ecf20Sopenharmony_ci		     [C(OP_READ)] = {
3248c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] =
3258c2ecf20Sopenharmony_ci					SPAV3_1_SEL_UITLB_ACCESS,
3268c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] =
3278c2ecf20Sopenharmony_ci					SPAV3_2_SEL_UITLB_MISS,
3288c2ecf20Sopenharmony_ci				     },
3298c2ecf20Sopenharmony_ci		     [C(OP_WRITE)] = {
3308c2ecf20Sopenharmony_ci				      [C(RESULT_ACCESS)] =
3318c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3328c2ecf20Sopenharmony_ci				      [C(RESULT_MISS)] =
3338c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3348c2ecf20Sopenharmony_ci				      },
3358c2ecf20Sopenharmony_ci		     [C(OP_PREFETCH)] = {
3368c2ecf20Sopenharmony_ci					 [C(RESULT_ACCESS)] =
3378c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3388c2ecf20Sopenharmony_ci					 [C(RESULT_MISS)] =
3398c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3408c2ecf20Sopenharmony_ci					 },
3418c2ecf20Sopenharmony_ci		     },
3428c2ecf20Sopenharmony_ci	[C(BPU)] = {		/* What is BPU? */
3438c2ecf20Sopenharmony_ci		    [C(OP_READ)] = {
3448c2ecf20Sopenharmony_ci				    [C(RESULT_ACCESS)] =
3458c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3468c2ecf20Sopenharmony_ci				    [C(RESULT_MISS)] =
3478c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3488c2ecf20Sopenharmony_ci				    },
3498c2ecf20Sopenharmony_ci		    [C(OP_WRITE)] = {
3508c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] =
3518c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3528c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] =
3538c2ecf20Sopenharmony_ci					CACHE_OP_UNSUPPORTED,
3548c2ecf20Sopenharmony_ci				     },
3558c2ecf20Sopenharmony_ci		    [C(OP_PREFETCH)] = {
3568c2ecf20Sopenharmony_ci					[C(RESULT_ACCESS)] =
3578c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3588c2ecf20Sopenharmony_ci					[C(RESULT_MISS)] =
3598c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3608c2ecf20Sopenharmony_ci					},
3618c2ecf20Sopenharmony_ci		    },
3628c2ecf20Sopenharmony_ci	[C(NODE)] = {		/* What is NODE? */
3638c2ecf20Sopenharmony_ci		     [C(OP_READ)] = {
3648c2ecf20Sopenharmony_ci				     [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
3658c2ecf20Sopenharmony_ci				     [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
3668c2ecf20Sopenharmony_ci				     },
3678c2ecf20Sopenharmony_ci		     [C(OP_WRITE)] = {
3688c2ecf20Sopenharmony_ci				      [C(RESULT_ACCESS)] = CACHE_OP_UNSUPPORTED,
3698c2ecf20Sopenharmony_ci				      [C(RESULT_MISS)] = CACHE_OP_UNSUPPORTED,
3708c2ecf20Sopenharmony_ci				      },
3718c2ecf20Sopenharmony_ci		     [C(OP_PREFETCH)] = {
3728c2ecf20Sopenharmony_ci					 [C(RESULT_ACCESS)] =
3738c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3748c2ecf20Sopenharmony_ci					 [C(RESULT_MISS)] =
3758c2ecf20Sopenharmony_ci						CACHE_OP_UNSUPPORTED,
3768c2ecf20Sopenharmony_ci					 },
3778c2ecf20Sopenharmony_ci		     },
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ciint nds32_pmu_map_event(struct perf_event *event,
3818c2ecf20Sopenharmony_ci			const unsigned int (*event_map)[PERF_COUNT_HW_MAX],
3828c2ecf20Sopenharmony_ci			const unsigned int (*cache_map)[PERF_COUNT_HW_CACHE_MAX]
3838c2ecf20Sopenharmony_ci			[PERF_COUNT_HW_CACHE_OP_MAX]
3848c2ecf20Sopenharmony_ci			[PERF_COUNT_HW_CACHE_RESULT_MAX], u32 raw_event_mask);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci#endif /* __ASM_PMU_H */
387