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