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