Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <config.h> |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 8 | #include <common.h> |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 9 | #include <linux/compiler.h> |
| 10 | #include <linux/kernel.h> |
Alexey Brodkin | 982f6bf | 2017-06-26 11:46:47 +0300 | [diff] [blame] | 11 | #include <linux/log2.h> |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 12 | #include <asm/arcregs.h> |
Alexey Brodkin | 6b95cca | 2015-02-03 13:58:13 +0300 | [diff] [blame] | 13 | #include <asm/cache.h> |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 14 | |
| 15 | /* Bit values in IC_CTRL */ |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 16 | #define IC_CTRL_CACHE_DISABLE BIT(0) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 17 | |
| 18 | /* Bit values in DC_CTRL */ |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 19 | #define DC_CTRL_CACHE_DISABLE BIT(0) |
| 20 | #define DC_CTRL_INV_MODE_FLUSH BIT(6) |
| 21 | #define DC_CTRL_FLUSH_STATUS BIT(8) |
Igor Guryanov | bd889f9 | 2014-12-24 16:07:07 +0300 | [diff] [blame] | 22 | #define CACHE_VER_NUM_MASK 0xF |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 23 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 24 | #define OP_INV 0x1 |
| 25 | #define OP_FLUSH 0x2 |
| 26 | #define OP_INV_IC 0x3 |
| 27 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 28 | /* Bit val in SLC_CONTROL */ |
| 29 | #define SLC_CTRL_DIS 0x001 |
| 30 | #define SLC_CTRL_IM 0x040 |
| 31 | #define SLC_CTRL_BUSY 0x100 |
| 32 | #define SLC_CTRL_RGN_OP_INV 0x200 |
| 33 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 34 | /* |
| 35 | * By default that variable will fall into .bss section. |
| 36 | * But .bss section is not relocated and so it will be initilized before |
| 37 | * relocation but will be used after being zeroed. |
| 38 | */ |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 39 | int l1_line_sz __section(".data"); |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 40 | bool dcache_exists __section(".data") = false; |
| 41 | bool icache_exists __section(".data") = false; |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 42 | |
| 43 | #define CACHE_LINE_MASK (~(l1_line_sz - 1)) |
| 44 | |
| 45 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 46 | int slc_line_sz __section(".data"); |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 47 | bool slc_exists __section(".data") = false; |
| 48 | bool ioc_exists __section(".data") = false; |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 49 | bool pae_exists __section(".data") = false; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 50 | |
Eugeniy Paltsev | 111161e | 2018-01-16 19:20:28 +0300 | [diff] [blame] | 51 | /* To force enable IOC set ioc_enable to 'true' */ |
| 52 | bool ioc_enable __section(".data") = false; |
| 53 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 54 | void read_decode_mmu_bcr(void) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 55 | { |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 56 | /* TODO: should we compare mmu version from BCR and from CONFIG? */ |
| 57 | #if (CONFIG_ARC_MMU_VER >= 4) |
| 58 | u32 tmp; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 59 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 60 | tmp = read_aux_reg(ARC_AUX_MMU_BCR); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 61 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 62 | struct bcr_mmu_4 { |
| 63 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 64 | unsigned int ver:8, sasid:1, sz1:4, sz0:4, res:2, pae:1, |
| 65 | n_ways:2, n_entry:2, n_super:2, u_itlb:3, u_dtlb:3; |
| 66 | #else |
| 67 | /* DTLB ITLB JES JE JA */ |
| 68 | unsigned int u_dtlb:3, u_itlb:3, n_super:2, n_entry:2, n_ways:2, |
| 69 | pae:1, res:2, sz0:4, sz1:4, sasid:1, ver:8; |
| 70 | #endif /* CONFIG_CPU_BIG_ENDIAN */ |
| 71 | } *mmu4; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 72 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 73 | mmu4 = (struct bcr_mmu_4 *)&tmp; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 74 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 75 | pae_exists = !!mmu4->pae; |
| 76 | #endif /* (CONFIG_ARC_MMU_VER >= 4) */ |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 77 | } |
| 78 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 79 | static void __slc_entire_op(const int op) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 80 | { |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 81 | unsigned int ctrl; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 82 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 83 | ctrl = read_aux_reg(ARC_AUX_SLC_CTRL); |
| 84 | |
| 85 | if (!(op & OP_FLUSH)) /* i.e. OP_INV */ |
| 86 | ctrl &= ~SLC_CTRL_IM; /* clear IM: Disable flush before Inv */ |
| 87 | else |
| 88 | ctrl |= SLC_CTRL_IM; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 89 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 90 | write_aux_reg(ARC_AUX_SLC_CTRL, ctrl); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 91 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 92 | if (op & OP_INV) /* Inv or flush-n-inv use same cmd reg */ |
| 93 | write_aux_reg(ARC_AUX_SLC_INVALIDATE, 0x1); |
| 94 | else |
| 95 | write_aux_reg(ARC_AUX_SLC_FLUSH, 0x1); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 96 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 97 | /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */ |
| 98 | read_aux_reg(ARC_AUX_SLC_CTRL); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 99 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 100 | /* Important to wait for flush to complete */ |
| 101 | while (read_aux_reg(ARC_AUX_SLC_CTRL) & SLC_CTRL_BUSY); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 102 | } |
| 103 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 104 | static void slc_upper_region_init(void) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 105 | { |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 106 | /* |
| 107 | * ARC_AUX_SLC_RGN_END1 and ARC_AUX_SLC_RGN_START1 are always == 0 |
| 108 | * as we don't use PAE40. |
| 109 | */ |
| 110 | write_aux_reg(ARC_AUX_SLC_RGN_END1, 0); |
| 111 | write_aux_reg(ARC_AUX_SLC_RGN_START1, 0); |
| 112 | } |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 113 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 114 | static void __slc_rgn_op(unsigned long paddr, unsigned long sz, const int op) |
| 115 | { |
| 116 | unsigned int ctrl; |
| 117 | unsigned long end; |
| 118 | |
| 119 | /* |
| 120 | * The Region Flush operation is specified by CTRL.RGN_OP[11..9] |
| 121 | * - b'000 (default) is Flush, |
| 122 | * - b'001 is Invalidate if CTRL.IM == 0 |
| 123 | * - b'001 is Flush-n-Invalidate if CTRL.IM == 1 |
| 124 | */ |
| 125 | ctrl = read_aux_reg(ARC_AUX_SLC_CTRL); |
| 126 | |
| 127 | /* Don't rely on default value of IM bit */ |
| 128 | if (!(op & OP_FLUSH)) /* i.e. OP_INV */ |
| 129 | ctrl &= ~SLC_CTRL_IM; /* clear IM: Disable flush before Inv */ |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 130 | else |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 131 | ctrl |= SLC_CTRL_IM; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 132 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 133 | if (op & OP_INV) |
| 134 | ctrl |= SLC_CTRL_RGN_OP_INV; /* Inv or flush-n-inv */ |
| 135 | else |
| 136 | ctrl &= ~SLC_CTRL_RGN_OP_INV; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 137 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 138 | write_aux_reg(ARC_AUX_SLC_CTRL, ctrl); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 139 | |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 140 | /* |
| 141 | * Lower bits are ignored, no need to clip |
| 142 | * END needs to be setup before START (latter triggers the operation) |
| 143 | * END can't be same as START, so add (l2_line_sz - 1) to sz |
| 144 | */ |
| 145 | end = paddr + sz + slc_line_sz - 1; |
| 146 | |
| 147 | /* |
| 148 | * Upper addresses (ARC_AUX_SLC_RGN_END1 and ARC_AUX_SLC_RGN_START1) |
| 149 | * are always == 0 as we don't use PAE40, so we only setup lower ones |
| 150 | * (ARC_AUX_SLC_RGN_END and ARC_AUX_SLC_RGN_START) |
| 151 | */ |
| 152 | write_aux_reg(ARC_AUX_SLC_RGN_END, end); |
| 153 | write_aux_reg(ARC_AUX_SLC_RGN_START, paddr); |
| 154 | |
| 155 | /* Make sure "busy" bit reports correct stataus, see STAR 9001165532 */ |
| 156 | read_aux_reg(ARC_AUX_SLC_CTRL); |
| 157 | |
| 158 | while (read_aux_reg(ARC_AUX_SLC_CTRL) & SLC_CTRL_BUSY); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 159 | } |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 160 | #endif /* CONFIG_ISA_ARCV2 */ |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 161 | |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 162 | #ifdef CONFIG_ISA_ARCV2 |
| 163 | static void read_decode_cache_bcr_arcv2(void) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 164 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 165 | union { |
| 166 | struct { |
| 167 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 168 | unsigned int pad:24, way:2, lsz:2, sz:4; |
| 169 | #else |
| 170 | unsigned int sz:4, lsz:2, way:2, pad:24; |
| 171 | #endif |
| 172 | } fields; |
| 173 | unsigned int word; |
| 174 | } slc_cfg; |
| 175 | |
| 176 | union { |
| 177 | struct { |
| 178 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 179 | unsigned int pad:24, ver:8; |
| 180 | #else |
| 181 | unsigned int ver:8, pad:24; |
| 182 | #endif |
| 183 | } fields; |
| 184 | unsigned int word; |
| 185 | } sbcr; |
| 186 | |
| 187 | sbcr.word = read_aux_reg(ARC_BCR_SLC); |
| 188 | if (sbcr.fields.ver) { |
| 189 | slc_cfg.word = read_aux_reg(ARC_AUX_SLC_CONFIG); |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 190 | slc_exists = true; |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 191 | slc_line_sz = (slc_cfg.fields.lsz == 0) ? 128 : 64; |
| 192 | } |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 193 | |
| 194 | union { |
| 195 | struct bcr_clust_cfg { |
| 196 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 197 | unsigned int pad:7, c:1, num_entries:8, num_cores:8, ver:8; |
| 198 | #else |
| 199 | unsigned int ver:8, num_cores:8, num_entries:8, c:1, pad:7; |
| 200 | #endif |
| 201 | } fields; |
| 202 | unsigned int word; |
| 203 | } cbcr; |
| 204 | |
| 205 | cbcr.word = read_aux_reg(ARC_BCR_CLUSTER); |
Eugeniy Paltsev | 111161e | 2018-01-16 19:20:28 +0300 | [diff] [blame] | 206 | if (cbcr.fields.c && ioc_enable) |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 207 | ioc_exists = true; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 208 | } |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 209 | #endif |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 210 | |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 211 | void read_decode_cache_bcr(void) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 212 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 213 | int dc_line_sz = 0, ic_line_sz = 0; |
| 214 | |
| 215 | union { |
| 216 | struct { |
| 217 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 218 | unsigned int pad:12, line_len:4, sz:4, config:4, ver:8; |
| 219 | #else |
| 220 | unsigned int ver:8, config:4, sz:4, line_len:4, pad:12; |
| 221 | #endif |
| 222 | } fields; |
| 223 | unsigned int word; |
| 224 | } ibcr, dbcr; |
| 225 | |
| 226 | ibcr.word = read_aux_reg(ARC_BCR_IC_BUILD); |
| 227 | if (ibcr.fields.ver) { |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 228 | icache_exists = true; |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 229 | l1_line_sz = ic_line_sz = 8 << ibcr.fields.line_len; |
| 230 | if (!ic_line_sz) |
| 231 | panic("Instruction exists but line length is 0\n"); |
| 232 | } |
| 233 | |
| 234 | dbcr.word = read_aux_reg(ARC_BCR_DC_BUILD); |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 235 | if (dbcr.fields.ver) { |
Eugeniy Paltsev | 570d551 | 2017-11-30 17:41:32 +0300 | [diff] [blame] | 236 | dcache_exists = true; |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 237 | l1_line_sz = dc_line_sz = 16 << dbcr.fields.line_len; |
| 238 | if (!dc_line_sz) |
| 239 | panic("Data cache exists but line length is 0\n"); |
| 240 | } |
| 241 | |
| 242 | if (ic_line_sz && dc_line_sz && (ic_line_sz != dc_line_sz)) |
| 243 | panic("Instruction and data cache line lengths differ\n"); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void cache_init(void) |
| 247 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 248 | read_decode_cache_bcr(); |
| 249 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 250 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 251 | read_decode_cache_bcr_arcv2(); |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 252 | |
| 253 | if (ioc_exists) { |
Alexey Brodkin | 982f6bf | 2017-06-26 11:46:47 +0300 | [diff] [blame] | 254 | /* IOC Aperture start is equal to DDR start */ |
| 255 | unsigned int ap_base = CONFIG_SYS_SDRAM_BASE; |
| 256 | /* IOC Aperture size is equal to DDR size */ |
| 257 | long ap_size = CONFIG_SYS_SDRAM_SIZE; |
| 258 | |
Alexey Brodkin | 5accfc9 | 2016-06-08 08:04:03 +0300 | [diff] [blame] | 259 | flush_dcache_all(); |
| 260 | invalidate_dcache_all(); |
| 261 | |
Alexey Brodkin | 982f6bf | 2017-06-26 11:46:47 +0300 | [diff] [blame] | 262 | if (!is_power_of_2(ap_size) || ap_size < 4096) |
| 263 | panic("IOC Aperture size must be power of 2 and bigger 4Kib"); |
| 264 | |
| 265 | /* |
| 266 | * IOC Aperture size decoded as 2 ^ (SIZE + 2) KB, |
| 267 | * so setting 0x11 implies 512M, 0x12 implies 1G... |
| 268 | */ |
| 269 | write_aux_reg(ARC_AUX_IO_COH_AP0_SIZE, |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 270 | order_base_2(ap_size / 1024) - 2); |
Alexey Brodkin | 982f6bf | 2017-06-26 11:46:47 +0300 | [diff] [blame] | 271 | |
| 272 | /* IOC Aperture start must be aligned to the size of the aperture */ |
| 273 | if (ap_base % ap_size != 0) |
| 274 | panic("IOC Aperture start must be aligned to the size of the aperture"); |
| 275 | |
| 276 | write_aux_reg(ARC_AUX_IO_COH_AP0_BASE, ap_base >> 12); |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 277 | write_aux_reg(ARC_AUX_IO_COH_PARTIAL, 1); |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 278 | write_aux_reg(ARC_AUX_IO_COH_ENABLE, 1); |
| 279 | } |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 280 | |
| 281 | read_decode_mmu_bcr(); |
| 282 | |
| 283 | /* |
| 284 | * ARC_AUX_SLC_RGN_START1 and ARC_AUX_SLC_RGN_END1 register exist |
| 285 | * only if PAE exists in current HW. So we had to check pae_exist |
| 286 | * before using them. |
| 287 | */ |
| 288 | if (slc_exists && pae_exists) |
| 289 | slc_upper_region_init(); |
| 290 | #endif /* CONFIG_ISA_ARCV2 */ |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 291 | } |
| 292 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 293 | int icache_status(void) |
| 294 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 295 | if (!icache_exists) |
Igor Guryanov | bd889f9 | 2014-12-24 16:07:07 +0300 | [diff] [blame] | 296 | return 0; |
| 297 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 298 | if (read_aux_reg(ARC_AUX_IC_CTRL) & IC_CTRL_CACHE_DISABLE) |
| 299 | return 0; |
| 300 | else |
| 301 | return 1; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void icache_enable(void) |
| 305 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 306 | if (icache_exists) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 307 | write_aux_reg(ARC_AUX_IC_CTRL, read_aux_reg(ARC_AUX_IC_CTRL) & |
| 308 | ~IC_CTRL_CACHE_DISABLE); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void icache_disable(void) |
| 312 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 313 | if (icache_exists) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 314 | write_aux_reg(ARC_AUX_IC_CTRL, read_aux_reg(ARC_AUX_IC_CTRL) | |
| 315 | IC_CTRL_CACHE_DISABLE); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | void invalidate_icache_all(void) |
| 319 | { |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 320 | /* Any write to IC_IVIC register triggers invalidation of entire I$ */ |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 321 | if (icache_status()) { |
| 322 | write_aux_reg(ARC_AUX_IC_IVIC, 1); |
Alexey Brodkin | eba1ee6 | 2017-11-17 16:02:17 +0300 | [diff] [blame] | 323 | /* |
| 324 | * As per ARC HS databook (see chapter 5.3.3.2) |
| 325 | * it is required to add 3 NOPs after each write to IC_IVIC. |
| 326 | */ |
| 327 | __builtin_arc_nop(); |
| 328 | __builtin_arc_nop(); |
| 329 | __builtin_arc_nop(); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 330 | read_aux_reg(ARC_AUX_IC_CTRL); /* blocks */ |
| 331 | } |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 332 | |
| 333 | #ifdef CONFIG_ISA_ARCV2 |
| 334 | if (slc_exists) |
| 335 | __slc_entire_op(OP_INV); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 336 | #endif |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 337 | } |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 338 | |
| 339 | int dcache_status(void) |
| 340 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 341 | if (!dcache_exists) |
Igor Guryanov | bd889f9 | 2014-12-24 16:07:07 +0300 | [diff] [blame] | 342 | return 0; |
| 343 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 344 | if (read_aux_reg(ARC_AUX_DC_CTRL) & DC_CTRL_CACHE_DISABLE) |
| 345 | return 0; |
| 346 | else |
| 347 | return 1; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void dcache_enable(void) |
| 351 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 352 | if (!dcache_exists) |
Igor Guryanov | bd889f9 | 2014-12-24 16:07:07 +0300 | [diff] [blame] | 353 | return; |
| 354 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 355 | write_aux_reg(ARC_AUX_DC_CTRL, read_aux_reg(ARC_AUX_DC_CTRL) & |
| 356 | ~(DC_CTRL_INV_MODE_FLUSH | DC_CTRL_CACHE_DISABLE)); |
| 357 | } |
| 358 | |
| 359 | void dcache_disable(void) |
| 360 | { |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 361 | if (!dcache_exists) |
Igor Guryanov | bd889f9 | 2014-12-24 16:07:07 +0300 | [diff] [blame] | 362 | return; |
| 363 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 364 | write_aux_reg(ARC_AUX_DC_CTRL, read_aux_reg(ARC_AUX_DC_CTRL) | |
| 365 | DC_CTRL_CACHE_DISABLE); |
| 366 | } |
| 367 | |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 368 | #ifndef CONFIG_SYS_DCACHE_OFF |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 369 | /* |
| 370 | * Common Helper for Line Operations on {I,D}-Cache |
| 371 | */ |
| 372 | static inline void __cache_line_loop(unsigned long paddr, unsigned long sz, |
| 373 | const int cacheop) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 374 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 375 | unsigned int aux_cmd; |
| 376 | #if (CONFIG_ARC_MMU_VER == 3) |
| 377 | unsigned int aux_tag; |
| 378 | #endif |
| 379 | int num_lines; |
| 380 | |
| 381 | if (cacheop == OP_INV_IC) { |
| 382 | aux_cmd = ARC_AUX_IC_IVIL; |
Alexey Brodkin | 6da8cfc | 2015-02-03 13:58:12 +0300 | [diff] [blame] | 383 | #if (CONFIG_ARC_MMU_VER == 3) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 384 | aux_tag = ARC_AUX_IC_PTAG; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 385 | #endif |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 386 | } else { |
| 387 | /* d$ cmd: INV (discard or wback-n-discard) OR FLUSH (wback) */ |
| 388 | aux_cmd = cacheop & OP_INV ? ARC_AUX_DC_IVDL : ARC_AUX_DC_FLDL; |
| 389 | #if (CONFIG_ARC_MMU_VER == 3) |
| 390 | aux_tag = ARC_AUX_DC_PTAG; |
| 391 | #endif |
| 392 | } |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 393 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 394 | sz += paddr & ~CACHE_LINE_MASK; |
| 395 | paddr &= CACHE_LINE_MASK; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 396 | |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 397 | num_lines = DIV_ROUND_UP(sz, l1_line_sz); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 398 | |
| 399 | while (num_lines-- > 0) { |
Alexey Brodkin | 6da8cfc | 2015-02-03 13:58:12 +0300 | [diff] [blame] | 400 | #if (CONFIG_ARC_MMU_VER == 3) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 401 | write_aux_reg(aux_tag, paddr); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 402 | #endif |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 403 | write_aux_reg(aux_cmd, paddr); |
Alexey Brodkin | dff5df2 | 2015-12-14 17:14:46 +0300 | [diff] [blame] | 404 | paddr += l1_line_sz; |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 405 | } |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 406 | } |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 407 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 408 | static unsigned int __before_dc_op(const int op) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 409 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 410 | unsigned int reg; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 411 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 412 | if (op == OP_INV) { |
| 413 | /* |
| 414 | * IM is set by default and implies Flush-n-inv |
| 415 | * Clear it here for vanilla inv |
| 416 | */ |
| 417 | reg = read_aux_reg(ARC_AUX_DC_CTRL); |
| 418 | write_aux_reg(ARC_AUX_DC_CTRL, reg & ~DC_CTRL_INV_MODE_FLUSH); |
| 419 | } |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 420 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 421 | return reg; |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 422 | } |
| 423 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 424 | static void __after_dc_op(const int op, unsigned int reg) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 425 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 426 | if (op & OP_FLUSH) /* flush / flush-n-inv both wait */ |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 427 | while (read_aux_reg(ARC_AUX_DC_CTRL) & DC_CTRL_FLUSH_STATUS); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 428 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 429 | /* Switch back to default Invalidate mode */ |
| 430 | if (op == OP_INV) |
| 431 | write_aux_reg(ARC_AUX_DC_CTRL, reg | DC_CTRL_INV_MODE_FLUSH); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 432 | } |
| 433 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 434 | static inline void __dc_entire_op(const int cacheop) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 435 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 436 | int aux; |
| 437 | unsigned int ctrl_reg = __before_dc_op(cacheop); |
| 438 | |
| 439 | if (cacheop & OP_INV) /* Inv or flush-n-inv use same cmd reg */ |
| 440 | aux = ARC_AUX_DC_IVDC; |
| 441 | else |
| 442 | aux = ARC_AUX_DC_FLSH; |
Alexey Brodkin | 35221a6 | 2015-03-27 12:47:29 +0300 | [diff] [blame] | 443 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 444 | write_aux_reg(aux, 0x1); |
| 445 | |
| 446 | __after_dc_op(cacheop, ctrl_reg); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 447 | } |
| 448 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 449 | static inline void __dc_line_op(unsigned long paddr, unsigned long sz, |
| 450 | const int cacheop) |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 451 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 452 | unsigned int ctrl_reg = __before_dc_op(cacheop); |
Eugeniy Paltsev | 6e626f0 | 2018-01-16 19:20:29 +0300 | [diff] [blame] | 453 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 454 | __cache_line_loop(paddr, sz, cacheop); |
| 455 | __after_dc_op(cacheop, ctrl_reg); |
Alexey Brodkin | 3a59d91 | 2014-02-04 12:56:14 +0400 | [diff] [blame] | 456 | } |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 457 | #else |
| 458 | #define __dc_entire_op(cacheop) |
| 459 | #define __dc_line_op(paddr, sz, cacheop) |
| 460 | #endif /* !CONFIG_SYS_DCACHE_OFF */ |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 461 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 462 | void invalidate_dcache_range(unsigned long start, unsigned long end) |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 463 | { |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 464 | if (start >= end) |
| 465 | return; |
| 466 | |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 467 | #ifdef CONFIG_ISA_ARCV2 |
| 468 | if (!ioc_exists) |
| 469 | #endif |
| 470 | __dc_line_op(start, end - start, OP_INV); |
| 471 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 472 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 473 | if (slc_exists && !ioc_exists) |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 474 | __slc_rgn_op(start, end - start, OP_INV); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 475 | #endif |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 476 | } |
| 477 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 478 | void flush_dcache_range(unsigned long start, unsigned long end) |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 479 | { |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 480 | if (start >= end) |
| 481 | return; |
| 482 | |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 483 | #ifdef CONFIG_ISA_ARCV2 |
| 484 | if (!ioc_exists) |
| 485 | #endif |
| 486 | __dc_line_op(start, end - start, OP_FLUSH); |
| 487 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 488 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 489 | if (slc_exists && !ioc_exists) |
Eugeniy Paltsev | 1d0578e | 2018-01-16 19:20:26 +0300 | [diff] [blame] | 490 | __slc_rgn_op(start, end - start, OP_FLUSH); |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 491 | #endif |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 492 | } |
| 493 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 494 | void flush_cache(unsigned long start, unsigned long size) |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 495 | { |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 496 | flush_dcache_range(start, start + size); |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 497 | } |
| 498 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 499 | void invalidate_dcache_all(void) |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 500 | { |
Alexey Brodkin | e344c1f | 2016-06-08 07:57:19 +0300 | [diff] [blame] | 501 | __dc_entire_op(OP_INV); |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 502 | |
| 503 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | e344c1f | 2016-06-08 07:57:19 +0300 | [diff] [blame] | 504 | if (slc_exists) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 505 | __slc_entire_op(OP_INV); |
| 506 | #endif |
Alexey Brodkin | 275583e | 2015-03-30 13:36:04 +0300 | [diff] [blame] | 507 | } |
| 508 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 509 | void flush_dcache_all(void) |
| 510 | { |
Alexey Brodkin | 5f54169 | 2016-04-16 15:28:30 +0300 | [diff] [blame] | 511 | __dc_entire_op(OP_FLUSH); |
Alexey Brodkin | 4764d26 | 2015-12-14 17:15:13 +0300 | [diff] [blame] | 512 | |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 513 | #ifdef CONFIG_ISA_ARCV2 |
Alexey Brodkin | 5f54169 | 2016-04-16 15:28:30 +0300 | [diff] [blame] | 514 | if (slc_exists) |
Alexey Brodkin | 9f916ee | 2015-05-18 16:56:26 +0300 | [diff] [blame] | 515 | __slc_entire_op(OP_FLUSH); |
| 516 | #endif |
| 517 | } |