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