Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * (C) Copyright 2000 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <asm/processor.h> |
| 28 | #include <asm/mmu.h> |
Kumar Gala | 9ac287a | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 29 | #ifdef CONFIG_ADDR_MAP |
| 30 | #include <addr_map.h> |
| 31 | #endif |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 34 | |
| 35 | void set_tlb(u8 tlb, u32 epn, u64 rpn, |
| 36 | u8 perms, u8 wimge, |
| 37 | u8 ts, u8 esel, u8 tsize, u8 iprot) |
| 38 | { |
| 39 | u32 _mas0, _mas1, _mas2, _mas3, _mas7; |
| 40 | |
| 41 | _mas0 = FSL_BOOKE_MAS0(tlb, esel, 0); |
| 42 | _mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize); |
| 43 | _mas2 = FSL_BOOKE_MAS2(epn, wimge); |
| 44 | _mas3 = FSL_BOOKE_MAS3(rpn, 0, perms); |
| 45 | _mas7 = rpn >> 32; |
| 46 | |
| 47 | mtspr(MAS0, _mas0); |
| 48 | mtspr(MAS1, _mas1); |
| 49 | mtspr(MAS2, _mas2); |
| 50 | mtspr(MAS3, _mas3); |
| 51 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
| 52 | mtspr(MAS7, _mas7); |
| 53 | #endif |
| 54 | asm volatile("isync;msync;tlbwe;isync"); |
Kumar Gala | 9ac287a | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 55 | |
| 56 | #ifdef CONFIG_ADDR_MAP |
| 57 | if ((tlb == 1) && (gd->flags & GD_FLG_RELOC)) |
| 58 | addrmap_set_entry(epn, rpn, (1UL << ((tsize * 2) + 10)), esel); |
| 59 | #endif |
Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void disable_tlb(u8 esel) |
| 63 | { |
| 64 | u32 _mas0, _mas1, _mas2, _mas3, _mas7; |
| 65 | |
| 66 | _mas0 = FSL_BOOKE_MAS0(1, esel, 0); |
| 67 | _mas1 = 0; |
| 68 | _mas2 = 0; |
| 69 | _mas3 = 0; |
| 70 | _mas7 = 0; |
| 71 | |
| 72 | mtspr(MAS0, _mas0); |
| 73 | mtspr(MAS1, _mas1); |
| 74 | mtspr(MAS2, _mas2); |
| 75 | mtspr(MAS3, _mas3); |
| 76 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
| 77 | mtspr(MAS7, _mas7); |
| 78 | #endif |
| 79 | asm volatile("isync;msync;tlbwe;isync"); |
Kumar Gala | 9ac287a | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 80 | |
| 81 | #ifdef CONFIG_ADDR_MAP |
| 82 | if (gd->flags & GD_FLG_RELOC) |
| 83 | addrmap_set_entry(0, 0, 0, esel); |
| 84 | #endif |
Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void invalidate_tlb(u8 tlb) |
| 88 | { |
| 89 | if (tlb == 0) |
| 90 | mtspr(MMUCSR0, 0x4); |
| 91 | if (tlb == 1) |
| 92 | mtspr(MMUCSR0, 0x2); |
| 93 | } |
| 94 | |
| 95 | void init_tlbs(void) |
| 96 | { |
Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 97 | int i; |
| 98 | |
| 99 | for (i = 0; i < num_tlb_entries; i++) { |
| 100 | set_tlb(tlb_table[i].tlb, tlb_table[i].epn, tlb_table[i].rpn, |
| 101 | tlb_table[i].perms, tlb_table[i].wimge, |
| 102 | tlb_table[i].ts, tlb_table[i].esel, tlb_table[i].tsize, |
| 103 | tlb_table[i].iprot); |
| 104 | } |
Kumar Gala | 95bb67f | 2008-01-16 22:33:22 -0600 | [diff] [blame] | 105 | |
| 106 | return ; |
| 107 | } |
Kumar Gala | 80f4bc7 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 108 | |
Kumar Gala | 9ac287a | 2008-12-16 14:59:20 -0600 | [diff] [blame] | 109 | #ifdef CONFIG_ADDR_MAP |
| 110 | void init_addr_map(void) |
| 111 | { |
| 112 | int i; |
| 113 | |
| 114 | for (i = 0; i < num_tlb_entries; i++) { |
| 115 | if (tlb_table[i].tlb == 0) |
| 116 | continue; |
| 117 | |
| 118 | addrmap_set_entry(tlb_table[i].epn, |
| 119 | tlb_table[i].rpn, |
| 120 | (1UL << ((tlb_table[i].tsize * 2) + 10)), |
| 121 | tlb_table[i].esel); |
| 122 | } |
| 123 | |
| 124 | return ; |
| 125 | } |
| 126 | #endif |
| 127 | |
Haiying Wang | 8a353d5 | 2009-01-13 16:29:22 -0500 | [diff] [blame] | 128 | #ifndef CONFIG_SYS_DDR_TLB_START |
| 129 | #define CONFIG_SYS_DDR_TLB_START 8 |
| 130 | #endif |
| 131 | |
Kumar Gala | 80f4bc7 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 132 | unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg) |
| 133 | { |
| 134 | unsigned int tlb_size; |
| 135 | unsigned int ram_tlb_index; |
| 136 | unsigned int ram_tlb_address; |
| 137 | |
| 138 | /* |
| 139 | * Determine size of each TLB1 entry. |
| 140 | */ |
| 141 | switch (memsize_in_meg) { |
| 142 | case 16: |
| 143 | case 32: |
| 144 | tlb_size = BOOKE_PAGESZ_16M; |
| 145 | break; |
| 146 | case 64: |
| 147 | case 128: |
| 148 | tlb_size = BOOKE_PAGESZ_64M; |
| 149 | break; |
| 150 | case 256: |
| 151 | case 512: |
| 152 | tlb_size = BOOKE_PAGESZ_256M; |
| 153 | break; |
| 154 | case 1024: |
| 155 | case 2048: |
| 156 | if (PVR_VER(get_pvr()) > PVR_VER(PVR_85xx)) |
| 157 | tlb_size = BOOKE_PAGESZ_1G; |
| 158 | else |
| 159 | tlb_size = BOOKE_PAGESZ_256M; |
| 160 | break; |
| 161 | default: |
| 162 | puts("DDR: only 16M, 32M, 64M, 128M, 256M, 512M, 1G" |
| 163 | " and 2G are supported.\n"); |
| 164 | |
| 165 | /* |
| 166 | * The memory was not able to be mapped. |
| 167 | * Default to a small size. |
| 168 | */ |
| 169 | tlb_size = BOOKE_PAGESZ_64M; |
| 170 | memsize_in_meg = 64; |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Configure DDR TLB1 entries. |
| 176 | * Starting at TLB1 8, use no more than 8 TLB1 entries. |
| 177 | */ |
Haiying Wang | 8a353d5 | 2009-01-13 16:29:22 -0500 | [diff] [blame] | 178 | ram_tlb_index = CONFIG_SYS_DDR_TLB_START; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 179 | ram_tlb_address = (unsigned int)CONFIG_SYS_DDR_SDRAM_BASE; |
Kumar Gala | 80f4bc7 | 2008-06-09 11:07:46 -0500 | [diff] [blame] | 180 | while (ram_tlb_address < (memsize_in_meg * 1024 * 1024) |
| 181 | && ram_tlb_index < 16) { |
| 182 | set_tlb(1, ram_tlb_address, ram_tlb_address, |
| 183 | MAS3_SX|MAS3_SW|MAS3_SR, 0, |
| 184 | 0, ram_tlb_index, tlb_size, 1); |
| 185 | |
| 186 | ram_tlb_address += (0x1000 << ((tlb_size - 1) * 2)); |
| 187 | ram_tlb_index++; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Confirm that the requested amount of memory was mapped. |
| 192 | */ |
| 193 | return memsize_in_meg; |
| 194 | } |