162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * arch/arm/include/asm/hardware/cache-l2x0.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2007 ARM Limited
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __ASM_ARM_HARDWARE_L2X0_H
962306a36Sopenharmony_ci#define __ASM_ARM_HARDWARE_L2X0_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/errno.h>
1262306a36Sopenharmony_ci#include <linux/init.h>
1362306a36Sopenharmony_ci#include <linux/types.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define L2X0_CACHE_ID			0x000
1662306a36Sopenharmony_ci#define L2X0_CACHE_TYPE			0x004
1762306a36Sopenharmony_ci#define L2X0_CTRL			0x100
1862306a36Sopenharmony_ci#define L2X0_AUX_CTRL			0x104
1962306a36Sopenharmony_ci#define L310_TAG_LATENCY_CTRL		0x108
2062306a36Sopenharmony_ci#define L310_DATA_LATENCY_CTRL		0x10C
2162306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CTRL		0x200
2262306a36Sopenharmony_ci#define L2X0_EVENT_CNT1_CFG		0x204
2362306a36Sopenharmony_ci#define L2X0_EVENT_CNT0_CFG		0x208
2462306a36Sopenharmony_ci#define L2X0_EVENT_CNT1_VAL		0x20C
2562306a36Sopenharmony_ci#define L2X0_EVENT_CNT0_VAL		0x210
2662306a36Sopenharmony_ci#define L2X0_INTR_MASK			0x214
2762306a36Sopenharmony_ci#define L2X0_MASKED_INTR_STAT		0x218
2862306a36Sopenharmony_ci#define L2X0_RAW_INTR_STAT		0x21C
2962306a36Sopenharmony_ci#define L2X0_INTR_CLEAR			0x220
3062306a36Sopenharmony_ci#define L2X0_CACHE_SYNC			0x730
3162306a36Sopenharmony_ci#define L2X0_DUMMY_REG			0x740
3262306a36Sopenharmony_ci#define L2X0_INV_LINE_PA		0x770
3362306a36Sopenharmony_ci#define L2X0_INV_WAY			0x77C
3462306a36Sopenharmony_ci#define L2X0_CLEAN_LINE_PA		0x7B0
3562306a36Sopenharmony_ci#define L2X0_CLEAN_LINE_IDX		0x7B8
3662306a36Sopenharmony_ci#define L2X0_CLEAN_WAY			0x7BC
3762306a36Sopenharmony_ci#define L2X0_CLEAN_INV_LINE_PA		0x7F0
3862306a36Sopenharmony_ci#define L2X0_CLEAN_INV_LINE_IDX		0x7F8
3962306a36Sopenharmony_ci#define L2X0_CLEAN_INV_WAY		0x7FC
4062306a36Sopenharmony_ci/*
4162306a36Sopenharmony_ci * The lockdown registers repeat 8 times for L310, the L210 has only one
4262306a36Sopenharmony_ci * D and one I lockdown register at 0x0900 and 0x0904.
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci#define L2X0_LOCKDOWN_WAY_D_BASE	0x900
4562306a36Sopenharmony_ci#define L2X0_LOCKDOWN_WAY_I_BASE	0x904
4662306a36Sopenharmony_ci#define L2X0_LOCKDOWN_STRIDE		0x08
4762306a36Sopenharmony_ci#define L310_ADDR_FILTER_START		0xC00
4862306a36Sopenharmony_ci#define L310_ADDR_FILTER_END		0xC04
4962306a36Sopenharmony_ci#define L2X0_TEST_OPERATION		0xF00
5062306a36Sopenharmony_ci#define L2X0_LINE_DATA			0xF10
5162306a36Sopenharmony_ci#define L2X0_LINE_TAG			0xF30
5262306a36Sopenharmony_ci#define L2X0_DEBUG_CTRL			0xF40
5362306a36Sopenharmony_ci#define L310_PREFETCH_CTRL		0xF60
5462306a36Sopenharmony_ci#define L310_POWER_CTRL			0xF80
5562306a36Sopenharmony_ci#define   L310_DYNAMIC_CLK_GATING_EN	(1 << 1)
5662306a36Sopenharmony_ci#define   L310_STNDBY_MODE_EN		(1 << 0)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* Registers shifts and masks */
5962306a36Sopenharmony_ci#define L2X0_CACHE_ID_PART_MASK		(0xf << 6)
6062306a36Sopenharmony_ci#define L2X0_CACHE_ID_PART_L210		(1 << 6)
6162306a36Sopenharmony_ci#define L2X0_CACHE_ID_PART_L220		(2 << 6)
6262306a36Sopenharmony_ci#define L2X0_CACHE_ID_PART_L310		(3 << 6)
6362306a36Sopenharmony_ci#define L2X0_CACHE_ID_RTL_MASK          0x3f
6462306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P2_02	0x00
6562306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P1		0x01
6662306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P2_01	0x02
6762306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P3		0x03
6862306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P4		0x0b
6962306a36Sopenharmony_ci#define L210_CACHE_ID_RTL_R0P5		0x0f
7062306a36Sopenharmony_ci#define L220_CACHE_ID_RTL_R1P7_01REL0	0x06
7162306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R0P0		0x00
7262306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R1P0		0x02
7362306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R2P0		0x04
7462306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R3P0		0x05
7562306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R3P1		0x06
7662306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R3P1_50REL0	0x07
7762306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R3P2		0x08
7862306a36Sopenharmony_ci#define L310_CACHE_ID_RTL_R3P3		0x09
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CTRL_ENABLE	BIT(0)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_SRC_SHIFT	2
8362306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_SRC_MASK	0xf
8462306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_SRC_DISABLED	0
8562306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_INT_DISABLED	0
8662306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_INT_INCR	1
8762306a36Sopenharmony_ci#define L2X0_EVENT_CNT_CFG_INT_OVERFLOW	2
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* L2C auxiliary control register - bits common to L2C-210/220/310 */
9062306a36Sopenharmony_ci#define L2C_AUX_CTRL_WAY_SIZE_SHIFT		17
9162306a36Sopenharmony_ci#define L2C_AUX_CTRL_WAY_SIZE_MASK		(7 << 17)
9262306a36Sopenharmony_ci#define L2C_AUX_CTRL_WAY_SIZE(n)		((n) << 17)
9362306a36Sopenharmony_ci#define L2C_AUX_CTRL_EVTMON_ENABLE		BIT(20)
9462306a36Sopenharmony_ci#define L2C_AUX_CTRL_PARITY_ENABLE		BIT(21)
9562306a36Sopenharmony_ci#define L2C_AUX_CTRL_SHARED_OVERRIDE		BIT(22)
9662306a36Sopenharmony_ci/* L2C-210/220 common bits */
9762306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT	0
9862306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK	(7 << 0)
9962306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT	3
10062306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK	(7 << 3)
10162306a36Sopenharmony_ci#define L2X0_AUX_CTRL_TAG_LATENCY_SHIFT		6
10262306a36Sopenharmony_ci#define L2X0_AUX_CTRL_TAG_LATENCY_MASK		(7 << 6)
10362306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT	9
10462306a36Sopenharmony_ci#define L2X0_AUX_CTRL_DIRTY_LATENCY_MASK	(7 << 9)
10562306a36Sopenharmony_ci#define L2X0_AUX_CTRL_ASSOC_SHIFT		13
10662306a36Sopenharmony_ci#define L2X0_AUX_CTRL_ASSOC_MASK		(15 << 13)
10762306a36Sopenharmony_ci/* L2C-210 specific bits */
10862306a36Sopenharmony_ci#define L210_AUX_CTRL_WRAP_DISABLE		BIT(12)
10962306a36Sopenharmony_ci#define L210_AUX_CTRL_WA_OVERRIDE		BIT(23)
11062306a36Sopenharmony_ci#define L210_AUX_CTRL_EXCLUSIVE_ABORT		BIT(24)
11162306a36Sopenharmony_ci/* L2C-220 specific bits */
11262306a36Sopenharmony_ci#define L220_AUX_CTRL_EXCLUSIVE_CACHE		BIT(12)
11362306a36Sopenharmony_ci#define L220_AUX_CTRL_FWA_SHIFT			23
11462306a36Sopenharmony_ci#define L220_AUX_CTRL_FWA_MASK			(3 << 23)
11562306a36Sopenharmony_ci#define L220_AUX_CTRL_NS_LOCKDOWN		BIT(26)
11662306a36Sopenharmony_ci#define L220_AUX_CTRL_NS_INT_CTRL		BIT(27)
11762306a36Sopenharmony_ci/* L2C-310 specific bits */
11862306a36Sopenharmony_ci#define L310_AUX_CTRL_FULL_LINE_ZERO		BIT(0)	/* R2P0+ */
11962306a36Sopenharmony_ci#define L310_AUX_CTRL_HIGHPRIO_SO_DEV		BIT(10)	/* R2P0+ */
12062306a36Sopenharmony_ci#define L310_AUX_CTRL_STORE_LIMITATION		BIT(11)	/* R2P0+ */
12162306a36Sopenharmony_ci#define L310_AUX_CTRL_EXCLUSIVE_CACHE		BIT(12)
12262306a36Sopenharmony_ci#define L310_AUX_CTRL_ASSOCIATIVITY_16		BIT(16)
12362306a36Sopenharmony_ci#define L310_AUX_CTRL_FWA_SHIFT			23
12462306a36Sopenharmony_ci#define L310_AUX_CTRL_FWA_MASK			(3 << 23)
12562306a36Sopenharmony_ci#define L310_AUX_CTRL_CACHE_REPLACE_RR		BIT(25)	/* R2P0+ */
12662306a36Sopenharmony_ci#define L310_AUX_CTRL_NS_LOCKDOWN		BIT(26)
12762306a36Sopenharmony_ci#define L310_AUX_CTRL_NS_INT_CTRL		BIT(27)
12862306a36Sopenharmony_ci#define L310_AUX_CTRL_DATA_PREFETCH		BIT(28)
12962306a36Sopenharmony_ci#define L310_AUX_CTRL_INSTR_PREFETCH		BIT(29)
13062306a36Sopenharmony_ci#define L310_AUX_CTRL_EARLY_BRESP		BIT(30)	/* R2P0+ */
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define L310_LATENCY_CTRL_SETUP(n)		((n) << 0)
13362306a36Sopenharmony_ci#define L310_LATENCY_CTRL_RD(n)			((n) << 4)
13462306a36Sopenharmony_ci#define L310_LATENCY_CTRL_WR(n)			((n) << 8)
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define L310_ADDR_FILTER_EN		1
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_OFFSET_MASK		0x1f
13962306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_DBL_LINEFILL_INCR	BIT(23)
14062306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_PREFETCH_DROP	BIT(24)
14162306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_DBL_LINEFILL_WRAP	BIT(27)
14262306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_DATA_PREFETCH	BIT(28)
14362306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_INSTR_PREFETCH	BIT(29)
14462306a36Sopenharmony_ci#define L310_PREFETCH_CTRL_DBL_LINEFILL		BIT(30)
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci#define L2X0_CTRL_EN			1
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define L2X0_WAY_SIZE_SHIFT		3
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci#ifndef __ASSEMBLY__
15162306a36Sopenharmony_ciextern void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask);
15262306a36Sopenharmony_ci#if defined(CONFIG_CACHE_L2X0) && defined(CONFIG_OF)
15362306a36Sopenharmony_ciextern int l2x0_of_init(u32 aux_val, u32 aux_mask);
15462306a36Sopenharmony_ci#else
15562306a36Sopenharmony_cistatic inline int l2x0_of_init(u32 aux_val, u32 aux_mask)
15662306a36Sopenharmony_ci{
15762306a36Sopenharmony_ci	return -ENODEV;
15862306a36Sopenharmony_ci}
15962306a36Sopenharmony_ci#endif
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#ifdef CONFIG_CACHE_L2X0_PMU
16262306a36Sopenharmony_civoid l2x0_pmu_register(void __iomem *base, u32 part);
16362306a36Sopenharmony_civoid l2x0_pmu_suspend(void);
16462306a36Sopenharmony_civoid l2x0_pmu_resume(void);
16562306a36Sopenharmony_ci#else
16662306a36Sopenharmony_cistatic inline void l2x0_pmu_register(void __iomem *base, u32 part) {}
16762306a36Sopenharmony_cistatic inline void l2x0_pmu_suspend(void) {}
16862306a36Sopenharmony_cistatic inline void l2x0_pmu_resume(void) {}
16962306a36Sopenharmony_ci#endif
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_cistruct l2x0_regs {
17262306a36Sopenharmony_ci	unsigned long phy_base;
17362306a36Sopenharmony_ci	unsigned long aux_ctrl;
17462306a36Sopenharmony_ci	/*
17562306a36Sopenharmony_ci	 * Whether the following registers need to be saved/restored
17662306a36Sopenharmony_ci	 * depends on platform
17762306a36Sopenharmony_ci	 */
17862306a36Sopenharmony_ci	unsigned long tag_latency;
17962306a36Sopenharmony_ci	unsigned long data_latency;
18062306a36Sopenharmony_ci	unsigned long filter_start;
18162306a36Sopenharmony_ci	unsigned long filter_end;
18262306a36Sopenharmony_ci	unsigned long prefetch_ctrl;
18362306a36Sopenharmony_ci	unsigned long pwr_ctrl;
18462306a36Sopenharmony_ci	unsigned long ctrl;
18562306a36Sopenharmony_ci	unsigned long aux2_ctrl;
18662306a36Sopenharmony_ci};
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ciextern struct l2x0_regs l2x0_saved_regs;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#endif
193