]> Git Repo - J-u-boot.git/blame - cpu/mpc85xx/tlb.c
ppc/85xx: Move code around to prep for NAND_SPL
[J-u-boot.git] / cpu / mpc85xx / tlb.c
CommitLineData
44a23cfd 1/*
d30f9043 2 * Copyright 2008-2009 Freescale Semiconductor, Inc.
44a23cfd
KG
3 *
4 * (C) Copyright 2000
5 * Wolfgang Denk, DENX Software Engineering, [email protected].
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>
ecf5b98c
KG
29#ifdef CONFIG_ADDR_MAP
30#include <addr_map.h>
31#endif
32
33DECLARE_GLOBAL_DATA_PTR;
44a23cfd 34
b2eec281
KG
35void invalidate_tlb(u8 tlb)
36{
37 if (tlb == 0)
38 mtspr(MMUCSR0, 0x4);
39 if (tlb == 1)
40 mtspr(MMUCSR0, 0x2);
41}
42
43void init_tlbs(void)
44{
45 int i;
46
47 for (i = 0; i < num_tlb_entries; i++) {
48 write_tlb(tlb_table[i].mas0,
49 tlb_table[i].mas1,
50 tlb_table[i].mas2,
51 tlb_table[i].mas3,
52 tlb_table[i].mas7);
53 }
54
55 return ;
56}
57
44a23cfd
KG
58void set_tlb(u8 tlb, u32 epn, u64 rpn,
59 u8 perms, u8 wimge,
60 u8 ts, u8 esel, u8 tsize, u8 iprot)
61{
62 u32 _mas0, _mas1, _mas2, _mas3, _mas7;
63
64 _mas0 = FSL_BOOKE_MAS0(tlb, esel, 0);
65 _mas1 = FSL_BOOKE_MAS1(1, iprot, 0, ts, tsize);
66 _mas2 = FSL_BOOKE_MAS2(epn, wimge);
67 _mas3 = FSL_BOOKE_MAS3(rpn, 0, perms);
d30f9043 68 _mas7 = FSL_BOOKE_MAS7(rpn);
44a23cfd 69
d30f9043 70 write_tlb(_mas0, _mas1, _mas2, _mas3, _mas7);
ecf5b98c
KG
71
72#ifdef CONFIG_ADDR_MAP
73 if ((tlb == 1) && (gd->flags & GD_FLG_RELOC))
74 addrmap_set_entry(epn, rpn, (1UL << ((tsize * 2) + 10)), esel);
75#endif
44a23cfd
KG
76}
77
78void disable_tlb(u8 esel)
79{
80 u32 _mas0, _mas1, _mas2, _mas3, _mas7;
81
82 _mas0 = FSL_BOOKE_MAS0(1, esel, 0);
83 _mas1 = 0;
84 _mas2 = 0;
85 _mas3 = 0;
86 _mas7 = 0;
87
88 mtspr(MAS0, _mas0);
89 mtspr(MAS1, _mas1);
90 mtspr(MAS2, _mas2);
91 mtspr(MAS3, _mas3);
92#ifdef CONFIG_ENABLE_36BIT_PHYS
93 mtspr(MAS7, _mas7);
94#endif
95 asm volatile("isync;msync;tlbwe;isync");
ecf5b98c
KG
96
97#ifdef CONFIG_ADDR_MAP
98 if (gd->flags & GD_FLG_RELOC)
99 addrmap_set_entry(0, 0, 0, esel);
100#endif
44a23cfd
KG
101}
102
c2287af1
KG
103static void tlbsx (const volatile unsigned *addr)
104{
105 __asm__ __volatile__ ("tlbsx 0,%0" : : "r" (addr), "m" (*addr));
106}
107
108/* return -1 if we didn't find anything */
109int find_tlb_idx(void *addr, u8 tlbsel)
110{
111 u32 _mas0, _mas1;
112
113 /* zero out Search PID, AS */
114 mtspr(MAS6, 0);
115
116 tlbsx(addr);
117
118 _mas0 = mfspr(MAS0);
119 _mas1 = mfspr(MAS1);
120
121 /* we found something, and its in the TLB we expect */
122 if ((MAS1_VALID & _mas1) &&
123 (MAS0_TLBSEL(tlbsel) == (_mas0 & MAS0_TLBSEL_MSK))) {
124 return ((_mas0 & MAS0_ESEL_MSK) >> 16);
125 }
126
127 return -1;
128}
129
ecf5b98c
KG
130#ifdef CONFIG_ADDR_MAP
131void init_addr_map(void)
132{
133 int i;
e393e2e9 134 unsigned int max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xff;
ecf5b98c 135
e393e2e9
KG
136 /* walk all the entries */
137 for (i = 0; i < max_cam; i++) {
138 unsigned long epn;
963f2f61 139 u32 tsize, _mas1;
e393e2e9
KG
140 phys_addr_t rpn;
141
142 mtspr(MAS0, FSL_BOOKE_MAS0(1, i, 0));
143
144 asm volatile("tlbre;isync");
145 _mas1 = mfspr(MAS1);
146
147 /* if the entry isn't valid skip it */
148 if (!(_mas1 & MAS1_VALID))
ecf5b98c
KG
149 continue;
150
e393e2e9
KG
151 tsize = (_mas1 >> 8) & 0xf;
152 epn = mfspr(MAS2) & MAS2_EPN;
153 rpn = mfspr(MAS3) & MAS3_RPN;
154#ifdef CONFIG_ENABLE_36BIT_PHYS
155 rpn |= ((phys_addr_t)mfspr(MAS7)) << 32;
156#endif
157
158 addrmap_set_entry(epn, rpn, (1UL << ((tsize * 2) + 10)), i);
ecf5b98c
KG
159 }
160
161 return ;
162}
163#endif
164
95026431
HW
165#ifndef CONFIG_SYS_DDR_TLB_START
166#define CONFIG_SYS_DDR_TLB_START 8
167#endif
168
6fb1b734
KG
169unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg)
170{
171 unsigned int tlb_size;
f8523cb0
KG
172 unsigned int ram_tlb_index = CONFIG_SYS_DDR_TLB_START;
173 unsigned int ram_tlb_address = (unsigned int)CONFIG_SYS_DDR_SDRAM_BASE;
90d13b8a 174 unsigned int max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xf;
f8523cb0 175 u64 size, memsize = (u64)memsize_in_meg << 20;
6fb1b734 176
f8523cb0
KG
177 size = min(memsize, CONFIG_MAX_MEM_MAPPED);
178
179 /* Convert (4^max) kB to (2^max) bytes */
180 max_cam = max_cam * 2 + 10;
181
182 for (; size && ram_tlb_index < 16; ram_tlb_index++) {
183 u32 camsize = __ilog2_u64(size) & ~1U;
184 u32 align = __ilog2(ram_tlb_address) & ~1U;
185
186 if (align == -2) align = max_cam;
187 if (camsize > align)
188 camsize = align;
189
190 if (camsize > max_cam)
191 camsize = max_cam;
192
193 tlb_size = (camsize - 10) / 2;
6fb1b734 194
6fb1b734
KG
195 set_tlb(1, ram_tlb_address, ram_tlb_address,
196 MAS3_SX|MAS3_SW|MAS3_SR, 0,
197 0, ram_tlb_index, tlb_size, 1);
198
f8523cb0
KG
199 size -= 1ULL << camsize;
200 memsize -= 1ULL << camsize;
201 ram_tlb_address += 1UL << camsize;
6fb1b734
KG
202 }
203
f8523cb0 204 if (memsize)
d4b130dc 205 print_size(memsize, " left unmapped\n");
f8523cb0 206
6fb1b734
KG
207 /*
208 * Confirm that the requested amount of memory was mapped.
209 */
210 return memsize_in_meg;
211}
This page took 0.142444 seconds and 4 git commands to generate.