Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 2 | /* |
Kumar Gala | ebc7394 | 2011-02-03 20:21:42 -0600 | [diff] [blame] | 3 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 4 | * |
| 5 | * (C) Copyright 2000 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Ovidiu Panait | 2fd81be | 2022-01-01 19:13:29 +0200 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 11 | #include <asm/bitops.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 13 | #include <asm/processor.h> |
| 14 | #include <asm/mmu.h> |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 15 | #ifdef CONFIG_ADDR_MAP |
| 16 | #include <addr_map.h> |
| 17 | #endif |
| 18 | |
Fabio Estevam | 2d2f490 | 2015-11-05 12:43:40 -0200 | [diff] [blame] | 19 | #include <linux/log2.h> |
| 20 | |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 22 | |
Kumar Gala | b2eec28 | 2009-09-11 12:32:01 -0500 | [diff] [blame] | 23 | void invalidate_tlb(u8 tlb) |
| 24 | { |
| 25 | if (tlb == 0) |
| 26 | mtspr(MMUCSR0, 0x4); |
| 27 | if (tlb == 1) |
| 28 | mtspr(MMUCSR0, 0x2); |
| 29 | } |
| 30 | |
Alexander Graf | fa08d39 | 2014-04-11 17:09:45 +0200 | [diff] [blame] | 31 | __weak void init_tlbs(void) |
Kumar Gala | b2eec28 | 2009-09-11 12:32:01 -0500 | [diff] [blame] | 32 | { |
| 33 | int i; |
| 34 | |
| 35 | for (i = 0; i < num_tlb_entries; i++) { |
| 36 | write_tlb(tlb_table[i].mas0, |
| 37 | tlb_table[i].mas1, |
| 38 | tlb_table[i].mas2, |
| 39 | tlb_table[i].mas3, |
| 40 | tlb_table[i].mas7); |
| 41 | } |
| 42 | |
| 43 | return ; |
| 44 | } |
| 45 | |
Ying Zhang | 0151d99 | 2013-08-16 15:16:10 +0800 | [diff] [blame] | 46 | #if !defined(CONFIG_NAND_SPL) && \ |
Tom Rini | b35316f | 2022-05-13 12:26:35 -0400 | [diff] [blame] | 47 | (!defined(CONFIG_SPL_BUILD) || !CONFIG_IS_ENABLED(INIT_MINIMAL)) |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 48 | void read_tlbcam_entry(int idx, u32 *valid, u32 *tsize, unsigned long *epn, |
| 49 | phys_addr_t *rpn) |
| 50 | { |
| 51 | u32 _mas1; |
| 52 | |
| 53 | mtspr(MAS0, FSL_BOOKE_MAS0(1, idx, 0)); |
| 54 | asm volatile("tlbre;isync"); |
| 55 | _mas1 = mfspr(MAS1); |
| 56 | |
| 57 | *valid = (_mas1 & MAS1_VALID); |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 58 | *tsize = (_mas1 >> 7) & 0x1f; |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 59 | *epn = mfspr(MAS2) & MAS2_EPN; |
| 60 | *rpn = mfspr(MAS3) & MAS3_RPN; |
| 61 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
| 62 | *rpn |= ((u64)mfspr(MAS7)) << 32; |
| 63 | #endif |
| 64 | } |
| 65 | |
Becky Bruce | 70e02bc | 2010-06-17 11:37:22 -0500 | [diff] [blame] | 66 | void print_tlbcam(void) |
| 67 | { |
| 68 | int i; |
| 69 | unsigned int num_cam = mfspr(SPRN_TLB1CFG) & 0xfff; |
| 70 | |
| 71 | /* walk all the entries */ |
| 72 | printf("TLBCAM entries\n"); |
| 73 | for (i = 0; i < num_cam; i++) { |
| 74 | unsigned long epn; |
| 75 | u32 tsize, valid; |
| 76 | phys_addr_t rpn; |
| 77 | |
| 78 | read_tlbcam_entry(i, &valid, &tsize, &epn, &rpn); |
| 79 | printf("entry %02d: V: %d EPN 0x%08x RPN 0x%08llx size:", |
| 80 | i, (valid == 0) ? 0 : 1, (unsigned int)epn, |
| 81 | (unsigned long long)rpn); |
| 82 | print_size(TSIZE_TO_BYTES(tsize), "\n"); |
| 83 | } |
| 84 | } |
| 85 | |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 86 | static inline void use_tlb_cam(u8 idx) |
| 87 | { |
| 88 | int i = idx / 32; |
| 89 | int bit = idx % 32; |
| 90 | |
Simon Glass | 7c80c6c | 2012-12-13 20:48:52 +0000 | [diff] [blame] | 91 | gd->arch.used_tlb_cams[i] |= (1 << bit); |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static inline void free_tlb_cam(u8 idx) |
| 95 | { |
| 96 | int i = idx / 32; |
| 97 | int bit = idx % 32; |
| 98 | |
Simon Glass | 7c80c6c | 2012-12-13 20:48:52 +0000 | [diff] [blame] | 99 | gd->arch.used_tlb_cams[i] &= ~(1 << bit); |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void init_used_tlb_cams(void) |
| 103 | { |
| 104 | int i; |
| 105 | unsigned int num_cam = mfspr(SPRN_TLB1CFG) & 0xfff; |
| 106 | |
| 107 | for (i = 0; i < ((CONFIG_SYS_NUM_TLBCAMS+31)/32); i++) |
Simon Glass | 7c80c6c | 2012-12-13 20:48:52 +0000 | [diff] [blame] | 108 | gd->arch.used_tlb_cams[i] = 0; |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 109 | |
| 110 | /* walk all the entries */ |
| 111 | for (i = 0; i < num_cam; i++) { |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 112 | mtspr(MAS0, FSL_BOOKE_MAS0(1, i, 0)); |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 113 | asm volatile("tlbre;isync"); |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 114 | if (mfspr(MAS1) & MAS1_VALID) |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 115 | use_tlb_cam(i); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | int find_free_tlbcam(void) |
| 120 | { |
| 121 | int i; |
| 122 | u32 idx; |
| 123 | |
| 124 | for (i = 0; i < ((CONFIG_SYS_NUM_TLBCAMS+31)/32); i++) { |
Simon Glass | 7c80c6c | 2012-12-13 20:48:52 +0000 | [diff] [blame] | 125 | idx = ffz(gd->arch.used_tlb_cams[i]); |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 126 | |
| 127 | if (idx != 32) |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | idx += i * 32; |
| 132 | |
| 133 | if (idx >= CONFIG_SYS_NUM_TLBCAMS) |
| 134 | return -1; |
| 135 | |
| 136 | return idx; |
| 137 | } |
| 138 | |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 139 | void set_tlb(u8 tlb, u32 epn, u64 rpn, |
| 140 | u8 perms, u8 wimge, |
| 141 | u8 ts, u8 esel, u8 tsize, u8 iprot) |
| 142 | { |
| 143 | u32 _mas0, _mas1, _mas2, _mas3, _mas7; |
| 144 | |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 145 | if (tlb == 1) |
| 146 | use_tlb_cam(esel); |
| 147 | |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 148 | if ((mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1 && |
| 149 | tsize & 1) { |
| 150 | printf("%s: bad tsize %d on entry %d at 0x%08x\n", |
| 151 | __func__, tsize, tlb, epn); |
| 152 | return; |
| 153 | } |
| 154 | |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 155 | _mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); |
| 156 | _mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); |
| 157 | _mas2 = FSL_BOOKE_MAS2(epn, wimge); |
| 158 | _mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); |
Kumar Gala | d30f904 | 2009-09-11 11:27:00 -0500 | [diff] [blame] | 159 | _mas7 = FSL_BOOKE_MAS7(rpn); |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 160 | |
Kumar Gala | d30f904 | 2009-09-11 11:27:00 -0500 | [diff] [blame] | 161 | write_tlb(_mas0, _mas1, _mas2, _mas3, _mas7); |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 162 | |
| 163 | #ifdef CONFIG_ADDR_MAP |
| 164 | if ((tlb == 1) && (gd->flags & GD_FLG_RELOC)) |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 165 | addrmap_set_entry(epn, rpn, TSIZE_TO_BYTES(tsize), esel); |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 166 | #endif |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void disable_tlb(u8 esel) |
| 170 | { |
Kumar Gala | 3d6d9c3 | 2011-11-09 09:59:32 -0600 | [diff] [blame] | 171 | u32 _mas0, _mas1, _mas2, _mas3; |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 172 | |
Kumar Gala | 94e9411 | 2009-11-12 10:26:16 -0600 | [diff] [blame] | 173 | free_tlb_cam(esel); |
| 174 | |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 175 | _mas0 = FSL_BOOKE_MAS0(1, esel, 0); |
| 176 | _mas1 = 0; |
| 177 | _mas2 = 0; |
| 178 | _mas3 = 0; |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 179 | |
| 180 | mtspr(MAS0, _mas0); |
| 181 | mtspr(MAS1, _mas1); |
| 182 | mtspr(MAS2, _mas2); |
| 183 | mtspr(MAS3, _mas3); |
| 184 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
Kumar Gala | 3d6d9c3 | 2011-11-09 09:59:32 -0600 | [diff] [blame] | 185 | mtspr(MAS7, 0); |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 186 | #endif |
| 187 | asm volatile("isync;msync;tlbwe;isync"); |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 188 | |
| 189 | #ifdef CONFIG_ADDR_MAP |
| 190 | if (gd->flags & GD_FLG_RELOC) |
| 191 | addrmap_set_entry(0, 0, 0, esel); |
| 192 | #endif |
Kumar Gala | 44a23cf | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 193 | } |
| 194 | |
Kumar Gala | c2287af | 2009-09-03 08:20:24 -0500 | [diff] [blame] | 195 | static void tlbsx (const volatile unsigned *addr) |
| 196 | { |
| 197 | __asm__ __volatile__ ("tlbsx 0,%0" : : "r" (addr), "m" (*addr)); |
| 198 | } |
| 199 | |
| 200 | /* return -1 if we didn't find anything */ |
| 201 | int find_tlb_idx(void *addr, u8 tlbsel) |
| 202 | { |
| 203 | u32 _mas0, _mas1; |
| 204 | |
| 205 | /* zero out Search PID, AS */ |
| 206 | mtspr(MAS6, 0); |
| 207 | |
| 208 | tlbsx(addr); |
| 209 | |
| 210 | _mas0 = mfspr(MAS0); |
| 211 | _mas1 = mfspr(MAS1); |
| 212 | |
| 213 | /* we found something, and its in the TLB we expect */ |
| 214 | if ((MAS1_VALID & _mas1) && |
| 215 | (MAS0_TLBSEL(tlbsel) == (_mas0 & MAS0_TLBSEL_MSK))) { |
| 216 | return ((_mas0 & MAS0_ESEL_MSK) >> 16); |
| 217 | } |
| 218 | |
| 219 | return -1; |
| 220 | } |
| 221 | |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 222 | #ifdef CONFIG_ADDR_MAP |
Ovidiu Panait | 1b212bb | 2022-01-01 19:13:28 +0200 | [diff] [blame] | 223 | int init_addr_map(void) |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 224 | { |
| 225 | int i; |
Kumar Gala | cdbdbe6 | 2009-11-13 08:52:21 -0600 | [diff] [blame] | 226 | unsigned int num_cam = mfspr(SPRN_TLB1CFG) & 0xfff; |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 227 | |
Kumar Gala | e393e2e | 2009-08-14 16:43:22 -0500 | [diff] [blame] | 228 | /* walk all the entries */ |
Kumar Gala | cdbdbe6 | 2009-11-13 08:52:21 -0600 | [diff] [blame] | 229 | for (i = 0; i < num_cam; i++) { |
Kumar Gala | e393e2e | 2009-08-14 16:43:22 -0500 | [diff] [blame] | 230 | unsigned long epn; |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 231 | u32 tsize, valid; |
Kumar Gala | e393e2e | 2009-08-14 16:43:22 -0500 | [diff] [blame] | 232 | phys_addr_t rpn; |
| 233 | |
Becky Bruce | 4e63df3 | 2010-06-17 11:37:21 -0500 | [diff] [blame] | 234 | read_tlbcam_entry(i, &valid, &tsize, &epn, &rpn); |
| 235 | if (valid & MAS1_VALID) |
| 236 | addrmap_set_entry(epn, rpn, TSIZE_TO_BYTES(tsize), i); |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 237 | } |
| 238 | |
Ovidiu Panait | 1b212bb | 2022-01-01 19:13:28 +0200 | [diff] [blame] | 239 | return 0; |
Kumar Gala | ecf5b98 | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 240 | } |
| 241 | #endif |
| 242 | |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 243 | uint64_t tlb_map_range(ulong v_addr, phys_addr_t p_addr, uint64_t size, |
| 244 | enum tlb_map_type map_type) |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 245 | { |
Kumar Gala | 355f4f8 | 2009-11-13 09:04:19 -0600 | [diff] [blame] | 246 | int i; |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 247 | unsigned int tlb_size; |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 248 | unsigned int wimge; |
| 249 | unsigned int perm; |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 250 | unsigned int max_cam, tsize_mask; |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 251 | |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 252 | if (map_type == TLB_MAP_RAM) { |
| 253 | perm = MAS3_SX|MAS3_SW|MAS3_SR; |
| 254 | wimge = MAS2_M; |
Becky Bruce | 6b1ef2a | 2010-12-17 17:17:55 -0600 | [diff] [blame] | 255 | #ifdef CONFIG_SYS_PPC_DDR_WIMGE |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 256 | wimge = CONFIG_SYS_PPC_DDR_WIMGE; |
Becky Bruce | 6b1ef2a | 2010-12-17 17:17:55 -0600 | [diff] [blame] | 257 | #endif |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 258 | } else { |
| 259 | perm = MAS3_SW|MAS3_SR; |
| 260 | wimge = MAS2_I|MAS2_G; |
| 261 | } |
| 262 | |
Kumar Gala | 50cf3d1 | 2011-10-31 22:13:26 -0500 | [diff] [blame] | 263 | if ((mfspr(SPRN_MMUCFG) & MMUCFG_MAVN) == MMUCFG_MAVN_V1) { |
| 264 | /* Convert (4^max) kB to (2^max) bytes */ |
| 265 | max_cam = ((mfspr(SPRN_TLB1CFG) >> 16) & 0xf) * 2 + 10; |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 266 | tsize_mask = ~1U; |
Kumar Gala | 50cf3d1 | 2011-10-31 22:13:26 -0500 | [diff] [blame] | 267 | } else { |
| 268 | /* Convert (2^max) kB to (2^max) bytes */ |
| 269 | max_cam = __ilog2(mfspr(SPRN_TLB1PS)) + 10; |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 270 | tsize_mask = ~0U; |
Kumar Gala | 50cf3d1 | 2011-10-31 22:13:26 -0500 | [diff] [blame] | 271 | } |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 272 | |
Kumar Gala | 355f4f8 | 2009-11-13 09:04:19 -0600 | [diff] [blame] | 273 | for (i = 0; size && i < 8; i++) { |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 274 | int tlb_index = find_free_tlbcam(); |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 275 | u32 camsize = __ilog2_u64(size) & tsize_mask; |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 276 | u32 align = __ilog2(v_addr) & tsize_mask; |
Kumar Gala | f8523cb | 2009-02-06 09:56:35 -0600 | [diff] [blame] | 277 | |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 278 | if (tlb_index == -1) |
Kumar Gala | 355f4f8 | 2009-11-13 09:04:19 -0600 | [diff] [blame] | 279 | break; |
| 280 | |
Kumar Gala | f8523cb | 2009-02-06 09:56:35 -0600 | [diff] [blame] | 281 | if (align == -2) align = max_cam; |
| 282 | if (camsize > align) |
| 283 | camsize = align; |
| 284 | |
| 285 | if (camsize > max_cam) |
| 286 | camsize = max_cam; |
| 287 | |
Scott Wood | 31d084d | 2013-01-18 15:45:58 +0000 | [diff] [blame] | 288 | tlb_size = camsize - 10; |
Kumar Gala | f8523cb | 2009-02-06 09:56:35 -0600 | [diff] [blame] | 289 | |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 290 | set_tlb(1, v_addr, p_addr, perm, wimge, |
| 291 | 0, tlb_index, tlb_size, 1); |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 292 | |
Kumar Gala | f8523cb | 2009-02-06 09:56:35 -0600 | [diff] [blame] | 293 | size -= 1ULL << camsize; |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 294 | v_addr += 1UL << camsize; |
York Sun | c02ce6e | 2010-09-28 15:20:32 -0700 | [diff] [blame] | 295 | p_addr += 1UL << camsize; |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 296 | } |
| 297 | |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 298 | return size; |
| 299 | } |
| 300 | |
| 301 | unsigned int setup_ddr_tlbs_phys(phys_addr_t p_addr, |
| 302 | unsigned int memsize_in_meg) |
| 303 | { |
| 304 | unsigned int ram_tlb_address = (unsigned int)CONFIG_SYS_DDR_SDRAM_BASE; |
| 305 | u64 memsize = (u64)memsize_in_meg << 20; |
York Sun | 0ccee4e | 2014-12-02 11:21:09 -0800 | [diff] [blame] | 306 | u64 size; |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 307 | |
York Sun | 0ccee4e | 2014-12-02 11:21:09 -0800 | [diff] [blame] | 308 | size = min(memsize, (u64)CONFIG_MAX_MEM_MAPPED); |
| 309 | size = tlb_map_range(ram_tlb_address, p_addr, size, TLB_MAP_RAM); |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 310 | |
York Sun | 0ccee4e | 2014-12-02 11:21:09 -0800 | [diff] [blame] | 311 | if (size || memsize > CONFIG_MAX_MEM_MAPPED) { |
| 312 | print_size(memsize > CONFIG_MAX_MEM_MAPPED ? |
| 313 | memsize - CONFIG_MAX_MEM_MAPPED + size : size, |
| 314 | " left unmapped\n"); |
| 315 | } |
Alexander Graf | f29f804 | 2014-04-11 17:09:43 +0200 | [diff] [blame] | 316 | |
Kumar Gala | 6fb1b73 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 317 | return memsize_in_meg; |
| 318 | } |
York Sun | c02ce6e | 2010-09-28 15:20:32 -0700 | [diff] [blame] | 319 | |
| 320 | unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg) |
| 321 | { |
| 322 | return |
| 323 | setup_ddr_tlbs_phys(CONFIG_SYS_DDR_SDRAM_BASE, memsize_in_meg); |
| 324 | } |
Becky Bruce | 9cdfe28 | 2011-07-18 18:49:15 -0500 | [diff] [blame] | 325 | |
| 326 | /* Invalidate the DDR TLBs for the requested size */ |
| 327 | void clear_ddr_tlbs_phys(phys_addr_t p_addr, unsigned int memsize_in_meg) |
| 328 | { |
| 329 | u32 vstart = CONFIG_SYS_DDR_SDRAM_BASE; |
| 330 | unsigned long epn; |
| 331 | u32 tsize, valid, ptr; |
| 332 | phys_addr_t rpn = 0; |
| 333 | int ddr_esel; |
| 334 | u64 memsize = (u64)memsize_in_meg << 20; |
| 335 | |
| 336 | ptr = vstart; |
| 337 | |
| 338 | while (ptr < (vstart + memsize)) { |
| 339 | ddr_esel = find_tlb_idx((void *)ptr, 1); |
| 340 | if (ddr_esel != -1) { |
| 341 | read_tlbcam_entry(ddr_esel, &valid, &tsize, &epn, &rpn); |
| 342 | disable_tlb(ddr_esel); |
| 343 | } |
| 344 | ptr += TSIZE_TO_BYTES(tsize); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void clear_ddr_tlbs(unsigned int memsize_in_meg) |
| 349 | { |
| 350 | clear_ddr_tlbs_phys(CONFIG_SYS_DDR_SDRAM_BASE, memsize_in_meg); |
| 351 | } |
| 352 | |
| 353 | |
Scott Wood | c97cd1b | 2012-09-20 19:02:18 -0500 | [diff] [blame] | 354 | #endif /* not SPL */ |