2 * Copyright 2008 Freescale Semiconductor, Inc.
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <asm/processor.h>
29 #ifdef CONFIG_ADDR_MAP
33 DECLARE_GLOBAL_DATA_PTR;
35 void set_tlb(u8 tlb, u32 epn, u64 rpn,
37 u8 ts, u8 esel, u8 tsize, u8 iprot)
39 u32 _mas0, _mas1, _mas2, _mas3, _mas7;
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);
51 #ifdef CONFIG_ENABLE_36BIT_PHYS
54 asm volatile("isync;msync;tlbwe;isync");
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);
62 void disable_tlb(u8 esel)
64 u32 _mas0, _mas1, _mas2, _mas3, _mas7;
66 _mas0 = FSL_BOOKE_MAS0(1, esel, 0);
76 #ifdef CONFIG_ENABLE_36BIT_PHYS
79 asm volatile("isync;msync;tlbwe;isync");
81 #ifdef CONFIG_ADDR_MAP
82 if (gd->flags & GD_FLG_RELOC)
83 addrmap_set_entry(0, 0, 0, esel);
87 void invalidate_tlb(u8 tlb)
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,
109 #ifdef CONFIG_ADDR_MAP
110 void init_addr_map(void)
114 for (i = 0; i < num_tlb_entries; i++) {
115 if (tlb_table[i].tlb == 0)
118 addrmap_set_entry(tlb_table[i].epn,
120 (1UL << ((tlb_table[i].tsize * 2) + 10)),
128 #ifndef CONFIG_SYS_DDR_TLB_START
129 #define CONFIG_SYS_DDR_TLB_START 8
132 unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
134 unsigned int tlb_size;
135 unsigned int ram_tlb_index = CONFIG_SYS_DDR_TLB_START;
136 unsigned int ram_tlb_address = (unsigned int)CONFIG_SYS_DDR_SDRAM_BASE;
137 unsigned int max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xff;
138 u64 size, memsize = (u64)memsize_in_meg << 20;
140 size = min(memsize, CONFIG_MAX_MEM_MAPPED);
142 /* Convert (4^max) kB to (2^max) bytes */
143 max_cam = max_cam * 2 + 10;
145 for (; size && ram_tlb_index < 16; ram_tlb_index++) {
146 u32 camsize = __ilog2_u64(size) & ~1U;
147 u32 align = __ilog2(ram_tlb_address) & ~1U;
149 if (align == -2) align = max_cam;
153 if (camsize > max_cam)
156 tlb_size = (camsize - 10) / 2;
158 set_tlb(1, ram_tlb_address, ram_tlb_address,
159 MAS3_SX|MAS3_SW|MAS3_SR, 0,
160 0, ram_tlb_index, tlb_size, 1);
162 size -= 1ULL << camsize;
163 memsize -= 1ULL << camsize;
164 ram_tlb_address += 1UL << camsize;
168 printf("%lldM left unmapped\n", memsize >> 20);
171 * Confirm that the requested amount of memory was mapped.
173 return memsize_in_meg;