blob: f271f39d5655fc1bf619a71f09904cd6817780a6 [file] [log] [blame]
Bernd Schmidt29440a22007-07-12 16:25:29 +08001/*
2 * Blackfin CPLB initialization
3 *
4 * Copyright 2004-2007 Analog Devices Inc.
5 *
6 * Bugs: Enter bugs at http://blackfin.uclinux.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see the file COPYING, or write
20 * to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23#include <linux/module.h>
24
25#include <asm/blackfin.h>
Robin Getz3bebca22007-10-10 23:55:26 +080026#include <asm/cplb.h>
Bernd Schmidt29440a22007-07-12 16:25:29 +080027#include <asm/cplbinit.h>
28
Mike Frysinger0e184c62008-04-23 08:23:51 +080029/*
30* Number of required data CPLB switchtable entries
31* MEMSIZE / 4 (we mostly install 4M page size CPLBs
32* approx 16 for smaller 1MB page size CPLBs for allignment purposes
33* 1 for L1 Data Memory
34* possibly 1 for L2 Data Memory
35* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
36* 1 for ASYNC Memory
37*/
38#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1 \
39 + ASYNC_MEMORY_CPLB_COVERAGE) * 2)
40
41/*
42* Number of required instruction CPLB switchtable entries
43* MEMSIZE / 4 (we mostly install 4M page size CPLBs
44* approx 12 for smaller 1MB page size CPLBs for allignment purposes
45* 1 for L1 Instruction Memory
46* possibly 1 for L2 Instruction Memory
47* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
48*/
49#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1 + 1) * 2)
50
51
Mike Frysinger81a487a2007-11-21 15:55:45 +080052u_long icplb_table[MAX_CPLBS + 1];
53u_long dcplb_table[MAX_CPLBS + 1];
Bernd Schmidt29440a22007-07-12 16:25:29 +080054
55#ifdef CONFIG_CPLB_SWITCH_TAB_L1
Mike Frysinger81a487a2007-11-21 15:55:45 +080056# define PDT_ATTR __attribute__((l1_data))
Bernd Schmidt29440a22007-07-12 16:25:29 +080057#else
Mike Frysinger81a487a2007-11-21 15:55:45 +080058# define PDT_ATTR
59#endif
Bernd Schmidt29440a22007-07-12 16:25:29 +080060
Mike Frysinger81a487a2007-11-21 15:55:45 +080061u_long ipdt_table[MAX_SWITCH_I_CPLBS + 1] PDT_ATTR;
62u_long dpdt_table[MAX_SWITCH_D_CPLBS + 1] PDT_ATTR;
Bernd Schmidt29440a22007-07-12 16:25:29 +080063
64#ifdef CONFIG_CPLB_INFO
Mike Frysinger81a487a2007-11-21 15:55:45 +080065u_long ipdt_swapcount_table[MAX_SWITCH_I_CPLBS] PDT_ATTR;
66u_long dpdt_swapcount_table[MAX_SWITCH_D_CPLBS] PDT_ATTR;
67#endif
Bernd Schmidt29440a22007-07-12 16:25:29 +080068
69struct s_cplb {
70 struct cplb_tab init_i;
71 struct cplb_tab init_d;
72 struct cplb_tab switch_i;
73 struct cplb_tab switch_d;
74};
75
Robin Getz3bebca22007-10-10 23:55:26 +080076#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
Bernd Schmidt29440a22007-07-12 16:25:29 +080077static struct cplb_desc cplb_data[] = {
78 {
79 .start = 0,
80 .end = SIZE_1K,
81 .psize = SIZE_1K,
82 .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
83 .i_conf = SDRAM_OOPS,
84 .d_conf = SDRAM_OOPS,
85#if defined(CONFIG_DEBUG_HUNT_FOR_ZERO)
86 .valid = 1,
87#else
88 .valid = 0,
89#endif
Mike Frysingerc3a9f432007-11-21 16:12:12 +080090 .name = "Zero Pointer Guard Page",
Bernd Schmidt29440a22007-07-12 16:25:29 +080091 },
92 {
93 .start = L1_CODE_START,
94 .end = L1_CODE_START + L1_CODE_LENGTH,
95 .psize = SIZE_4M,
96 .attr = INITIAL_T | SWITCH_T | I_CPLB,
97 .i_conf = L1_IMEMORY,
98 .d_conf = 0,
99 .valid = 1,
100 .name = "L1 I-Memory",
101 },
102 {
103 .start = L1_DATA_A_START,
104 .end = L1_DATA_B_START + L1_DATA_B_LENGTH,
105 .psize = SIZE_4M,
106 .attr = INITIAL_T | SWITCH_T | D_CPLB,
107 .i_conf = 0,
108 .d_conf = L1_DMEMORY,
109#if ((L1_DATA_A_LENGTH > 0) || (L1_DATA_B_LENGTH > 0))
110 .valid = 1,
111#else
112 .valid = 0,
113#endif
114 .name = "L1 D-Memory",
115 },
116 {
117 .start = 0,
118 .end = 0, /* dynamic */
119 .psize = 0,
120 .attr = INITIAL_T | SWITCH_T | I_CPLB | D_CPLB,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800121 .i_conf = SDRAM_IGENERIC,
122 .d_conf = SDRAM_DGENERIC,
Bernd Schmidt29440a22007-07-12 16:25:29 +0800123 .valid = 1,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800124 .name = "Kernel Memory",
Bernd Schmidt29440a22007-07-12 16:25:29 +0800125 },
126 {
127 .start = 0, /* dynamic */
128 .end = 0, /* dynamic */
129 .psize = 0,
130 .attr = INITIAL_T | SWITCH_T | D_CPLB,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800131 .i_conf = SDRAM_IGENERIC,
132 .d_conf = SDRAM_DNON_CHBL,
Bernd Schmidt29440a22007-07-12 16:25:29 +0800133 .valid = 1,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800134 .name = "uClinux MTD Memory",
Bernd Schmidt29440a22007-07-12 16:25:29 +0800135 },
136 {
137 .start = 0, /* dynamic */
138 .end = 0, /* dynamic */
139 .psize = SIZE_1M,
140 .attr = INITIAL_T | SWITCH_T | D_CPLB,
141 .d_conf = SDRAM_DNON_CHBL,
142 .valid = 1,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800143 .name = "Uncached DMA Zone",
Bernd Schmidt29440a22007-07-12 16:25:29 +0800144 },
145 {
146 .start = 0, /* dynamic */
147 .end = 0, /* dynamic */
148 .psize = 0,
149 .attr = SWITCH_T | D_CPLB,
150 .i_conf = 0, /* dynamic */
151 .d_conf = 0, /* dynamic */
152 .valid = 1,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800153 .name = "Reserved Memory",
Bernd Schmidt29440a22007-07-12 16:25:29 +0800154 },
155 {
156 .start = ASYNC_BANK0_BASE,
157 .end = ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE,
158 .psize = 0,
159 .attr = SWITCH_T | D_CPLB,
160 .d_conf = SDRAM_EBIU,
161 .valid = 1,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800162 .name = "Asynchronous Memory Banks",
Bernd Schmidt29440a22007-07-12 16:25:29 +0800163 },
164 {
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800165#ifdef L2_START
166 .start = L2_START,
167 .end = L2_START + L2_LENGTH,
Bernd Schmidt29440a22007-07-12 16:25:29 +0800168 .psize = SIZE_1M,
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800169 .attr = SWITCH_T | I_CPLB | D_CPLB,
Bernd Schmidt29440a22007-07-12 16:25:29 +0800170 .i_conf = L2_MEMORY,
171 .d_conf = L2_MEMORY,
172 .valid = 1,
173#else
174 .valid = 0,
175#endif
176 .name = "L2 Memory",
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800177 },
178 {
179 .start = BOOT_ROM_START,
180 .end = BOOT_ROM_START + BOOT_ROM_LENGTH,
181 .psize = SIZE_1M,
182 .attr = SWITCH_T | I_CPLB | D_CPLB,
183 .i_conf = SDRAM_IGENERIC,
184 .d_conf = SDRAM_DGENERIC,
185 .valid = 1,
186 .name = "On-Chip BootROM",
187 },
Bernd Schmidt29440a22007-07-12 16:25:29 +0800188};
189
190static u16 __init lock_kernel_check(u32 start, u32 end)
191{
Robin Getz6a3f0b42007-11-15 15:10:48 +0800192 if ((end <= (u32) _end && end >= (u32)_stext) ||
193 (start <= (u32) _end && start >= (u32)_stext))
Bernd Schmidt29440a22007-07-12 16:25:29 +0800194 return IN_KERNEL;
195 return 0;
196}
197
198static unsigned short __init
199fill_cplbtab(struct cplb_tab *table,
200 unsigned long start, unsigned long end,
201 unsigned long block_size, unsigned long cplb_data)
202{
203 int i;
204
205 switch (block_size) {
206 case SIZE_4M:
207 i = 3;
208 break;
209 case SIZE_1M:
210 i = 2;
211 break;
212 case SIZE_4K:
213 i = 1;
214 break;
215 case SIZE_1K:
216 default:
217 i = 0;
218 break;
219 }
220
221 cplb_data = (cplb_data & ~(3 << 16)) | (i << 16);
222
223 while ((start < end) && (table->pos < table->size)) {
224
225 table->tab[table->pos++] = start;
226
227 if (lock_kernel_check(start, start + block_size) == IN_KERNEL)
228 table->tab[table->pos++] =
229 cplb_data | CPLB_LOCK | CPLB_DIRTY;
230 else
231 table->tab[table->pos++] = cplb_data;
232
233 start += block_size;
234 }
235 return 0;
236}
237
238static unsigned short __init
239close_cplbtab(struct cplb_tab *table)
240{
241
242 while (table->pos < table->size) {
243
244 table->tab[table->pos++] = 0;
245 table->tab[table->pos++] = 0; /* !CPLB_VALID */
246 }
247 return 0;
248}
249
250/* helper function */
251static void __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
252{
253 if (cplb_data[i].psize) {
254 fill_cplbtab(t,
255 cplb_data[i].start,
256 cplb_data[i].end,
257 cplb_data[i].psize,
258 cplb_data[i].i_conf);
259 } else {
Robin Getz3bebca22007-10-10 23:55:26 +0800260#if defined(CONFIG_BFIN_ICACHE)
Mike Frysinger1aafd902007-07-25 11:19:14 +0800261 if (ANOMALY_05000263 && i == SDRAM_KERN) {
Bernd Schmidt29440a22007-07-12 16:25:29 +0800262 fill_cplbtab(t,
263 cplb_data[i].start,
264 cplb_data[i].end,
265 SIZE_4M,
266 cplb_data[i].i_conf);
267 } else
268#endif
269 {
270 fill_cplbtab(t,
271 cplb_data[i].start,
272 a_start,
273 SIZE_1M,
274 cplb_data[i].i_conf);
275 fill_cplbtab(t,
276 a_start,
277 a_end,
278 SIZE_4M,
279 cplb_data[i].i_conf);
280 fill_cplbtab(t, a_end,
281 cplb_data[i].end,
282 SIZE_1M,
283 cplb_data[i].i_conf);
284 }
285 }
286}
287
288static void __fill_data_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_end)
289{
290 if (cplb_data[i].psize) {
291 fill_cplbtab(t,
292 cplb_data[i].start,
293 cplb_data[i].end,
294 cplb_data[i].psize,
295 cplb_data[i].d_conf);
296 } else {
297 fill_cplbtab(t,
298 cplb_data[i].start,
299 a_start, SIZE_1M,
300 cplb_data[i].d_conf);
301 fill_cplbtab(t, a_start,
302 a_end, SIZE_4M,
303 cplb_data[i].d_conf);
304 fill_cplbtab(t, a_end,
305 cplb_data[i].end,
306 SIZE_1M,
307 cplb_data[i].d_conf);
308 }
309}
310
311void __init generate_cpl_tables(void)
312{
313
314 u16 i, j, process;
315 u32 a_start, a_end, as, ae, as_1m;
316
317 struct cplb_tab *t_i = NULL;
318 struct cplb_tab *t_d = NULL;
319 struct s_cplb cplb;
320
Mike Frysinger8cab0282008-04-24 05:13:10 +0800321 printk(KERN_INFO "NOMPU: setting up cplb tables for global access\n");
322
Bernd Schmidt29440a22007-07-12 16:25:29 +0800323 cplb.init_i.size = MAX_CPLBS;
324 cplb.init_d.size = MAX_CPLBS;
325 cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
326 cplb.switch_d.size = MAX_SWITCH_D_CPLBS;
327
328 cplb.init_i.pos = 0;
329 cplb.init_d.pos = 0;
330 cplb.switch_i.pos = 0;
331 cplb.switch_d.pos = 0;
332
333 cplb.init_i.tab = icplb_table;
334 cplb.init_d.tab = dcplb_table;
335 cplb.switch_i.tab = ipdt_table;
336 cplb.switch_d.tab = dpdt_table;
337
338 cplb_data[SDRAM_KERN].end = memory_end;
339
340#ifdef CONFIG_MTD_UCLINUX
341 cplb_data[SDRAM_RAM_MTD].start = memory_mtd_start;
342 cplb_data[SDRAM_RAM_MTD].end = memory_mtd_start + mtd_size;
343 cplb_data[SDRAM_RAM_MTD].valid = mtd_size > 0;
344# if defined(CONFIG_ROMFS_FS)
345 cplb_data[SDRAM_RAM_MTD].attr |= I_CPLB;
346
347 /*
348 * The ROMFS_FS size is often not multiple of 1MB.
349 * This can cause multiple CPLB sets covering the same memory area.
350 * This will then cause multiple CPLB hit exceptions.
351 * Workaround: We ensure a contiguous memory area by extending the kernel
352 * memory section over the mtd section.
353 * For ROMFS_FS memory must be covered with ICPLBs anyways.
354 * So there is no difference between kernel and mtd memory setup.
355 */
356
357 cplb_data[SDRAM_KERN].end = memory_mtd_start + mtd_size;;
358 cplb_data[SDRAM_RAM_MTD].valid = 0;
359
360# endif
361#else
362 cplb_data[SDRAM_RAM_MTD].valid = 0;
363#endif
364
365 cplb_data[SDRAM_DMAZ].start = _ramend - DMA_UNCACHED_REGION;
366 cplb_data[SDRAM_DMAZ].end = _ramend;
367
368 cplb_data[RES_MEM].start = _ramend;
369 cplb_data[RES_MEM].end = physical_mem_end;
370
371 if (reserved_mem_dcache_on)
372 cplb_data[RES_MEM].d_conf = SDRAM_DGENERIC;
373 else
374 cplb_data[RES_MEM].d_conf = SDRAM_DNON_CHBL;
375
376 if (reserved_mem_icache_on)
377 cplb_data[RES_MEM].i_conf = SDRAM_IGENERIC;
378 else
379 cplb_data[RES_MEM].i_conf = SDRAM_INON_CHBL;
380
Mike Frysingerc3a9f432007-11-21 16:12:12 +0800381 for (i = ZERO_P; i < ARRAY_SIZE(cplb_data); ++i) {
Bernd Schmidt29440a22007-07-12 16:25:29 +0800382 if (!cplb_data[i].valid)
383 continue;
384
385 as_1m = cplb_data[i].start % SIZE_1M;
386
387 /* We need to make sure all sections are properly 1M aligned
388 * However between Kernel Memory and the Kernel mtd section, depending on the
389 * rootfs size, there can be overlapping memory areas.
390 */
391
392 if (as_1m && i != L1I_MEM && i != L1D_MEM) {
393#ifdef CONFIG_MTD_UCLINUX
394 if (i == SDRAM_RAM_MTD) {
395 if ((cplb_data[SDRAM_KERN].end + 1) > cplb_data[SDRAM_RAM_MTD].start)
396 cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M)) + SIZE_1M;
397 else
398 cplb_data[SDRAM_RAM_MTD].start = (cplb_data[i].start & (-2*SIZE_1M));
399 } else
400#endif
401 printk(KERN_WARNING "Unaligned Start of %s at 0x%X\n",
402 cplb_data[i].name, cplb_data[i].start);
403 }
404
405 as = cplb_data[i].start % SIZE_4M;
406 ae = cplb_data[i].end % SIZE_4M;
407
408 if (as)
409 a_start = cplb_data[i].start + (SIZE_4M - (as));
410 else
411 a_start = cplb_data[i].start;
412
413 a_end = cplb_data[i].end - ae;
414
415 for (j = INITIAL_T; j <= SWITCH_T; j++) {
416
417 switch (j) {
418 case INITIAL_T:
419 if (cplb_data[i].attr & INITIAL_T) {
420 t_i = &cplb.init_i;
421 t_d = &cplb.init_d;
422 process = 1;
423 } else
424 process = 0;
425 break;
426 case SWITCH_T:
427 if (cplb_data[i].attr & SWITCH_T) {
428 t_i = &cplb.switch_i;
429 t_d = &cplb.switch_d;
430 process = 1;
431 } else
432 process = 0;
433 break;
434 default:
435 process = 0;
436 break;
437 }
438
439 if (!process)
440 continue;
441 if (cplb_data[i].attr & I_CPLB)
442 __fill_code_cplbtab(t_i, i, a_start, a_end);
443
444 if (cplb_data[i].attr & D_CPLB)
445 __fill_data_cplbtab(t_d, i, a_start, a_end);
446 }
447 }
448
449/* close tables */
450
451 close_cplbtab(&cplb.init_i);
452 close_cplbtab(&cplb.init_d);
453
454 cplb.init_i.tab[cplb.init_i.pos] = -1;
455 cplb.init_d.tab[cplb.init_d.pos] = -1;
456 cplb.switch_i.tab[cplb.switch_i.pos] = -1;
457 cplb.switch_d.tab[cplb.switch_d.pos] = -1;
458
459}
460
461#endif
462