2 * Blackfin CPLB initialization
4 * Copyright 2004-2007 Analog Devices Inc.
6 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
23 #include <linux/module.h>
25 #include <asm/blackfin.h>
27 #include <asm/cplbinit.h>
29 #ifdef CONFIG_MAX_MEM_SIZE
30 # define CPLB_MEM CONFIG_MAX_MEM_SIZE
32 # define CPLB_MEM CONFIG_MEM_SIZE
36 * Number of required data CPLB switchtable entries
37 * MEMSIZE / 4 (we mostly install 4M page size CPLBs
38 * approx 16 for smaller 1MB page size CPLBs for allignment purposes
39 * 1 for L1 Data Memory
40 * possibly 1 for L2 Data Memory
41 * 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
44 #define MAX_SWITCH_D_CPLBS (((CPLB_MEM / 4) + 16 + 1 + 1 + 1 \
45 + ASYNC_MEMORY_CPLB_COVERAGE) * 2)
48 * Number of required instruction CPLB switchtable entries
49 * MEMSIZE / 4 (we mostly install 4M page size CPLBs
50 * approx 12 for smaller 1MB page size CPLBs for allignment purposes
51 * 1 for L1 Instruction Memory
52 * possibly 1 for L2 Instruction Memory
53 * 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
55 #define MAX_SWITCH_I_CPLBS (((CPLB_MEM / 4) + 12 + 1 + 1 + 1) * 2)
58 u_long icplb_table
[MAX_CPLBS
+ 1];
59 u_long dcplb_table
[MAX_CPLBS
+ 1];
61 #ifdef CONFIG_CPLB_SWITCH_TAB_L1
62 # define PDT_ATTR __attribute__((l1_data))
67 u_long ipdt_table
[MAX_SWITCH_I_CPLBS
+ 1] PDT_ATTR
;
68 u_long dpdt_table
[MAX_SWITCH_D_CPLBS
+ 1] PDT_ATTR
;
70 #ifdef CONFIG_CPLB_INFO
71 u_long ipdt_swapcount_table
[MAX_SWITCH_I_CPLBS
] PDT_ATTR
;
72 u_long dpdt_swapcount_table
[MAX_SWITCH_D_CPLBS
] PDT_ATTR
;
76 struct cplb_tab init_i
;
77 struct cplb_tab init_d
;
78 struct cplb_tab switch_i
;
79 struct cplb_tab switch_d
;
82 #if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
83 static struct cplb_desc cplb_data
[] = {
88 .attr
= INITIAL_T
| SWITCH_T
| I_CPLB
| D_CPLB
,
91 #if defined(CONFIG_DEBUG_HUNT_FOR_ZERO)
96 .name
= "Zero Pointer Guard Page",
99 .start
= L1_CODE_START
,
100 .end
= L1_CODE_START
+ L1_CODE_LENGTH
,
102 .attr
= INITIAL_T
| SWITCH_T
| I_CPLB
,
103 .i_conf
= L1_IMEMORY
,
106 .name
= "L1 I-Memory",
109 .start
= L1_DATA_A_START
,
110 .end
= L1_DATA_B_START
+ L1_DATA_B_LENGTH
,
112 .attr
= INITIAL_T
| SWITCH_T
| D_CPLB
,
114 .d_conf
= L1_DMEMORY
,
115 #if ((L1_DATA_A_LENGTH > 0) || (L1_DATA_B_LENGTH > 0))
120 .name
= "L1 D-Memory",
124 .end
= 0, /* dynamic */
126 .attr
= INITIAL_T
| SWITCH_T
| I_CPLB
| D_CPLB
,
127 .i_conf
= SDRAM_IGENERIC
,
128 .d_conf
= SDRAM_DGENERIC
,
130 .name
= "Kernel Memory",
133 .start
= 0, /* dynamic */
134 .end
= 0, /* dynamic */
136 .attr
= INITIAL_T
| SWITCH_T
| D_CPLB
,
137 .i_conf
= SDRAM_IGENERIC
,
138 .d_conf
= SDRAM_DNON_CHBL
,
140 .name
= "uClinux MTD Memory",
143 .start
= 0, /* dynamic */
144 .end
= 0, /* dynamic */
146 .attr
= INITIAL_T
| SWITCH_T
| D_CPLB
,
147 .d_conf
= SDRAM_DNON_CHBL
,
149 .name
= "Uncached DMA Zone",
152 .start
= 0, /* dynamic */
153 .end
= 0, /* dynamic */
155 .attr
= SWITCH_T
| D_CPLB
,
156 .i_conf
= 0, /* dynamic */
157 .d_conf
= 0, /* dynamic */
159 .name
= "Reserved Memory",
162 .start
= ASYNC_BANK0_BASE
,
163 .end
= ASYNC_BANK3_BASE
+ ASYNC_BANK3_SIZE
,
165 .attr
= SWITCH_T
| D_CPLB
,
166 .d_conf
= SDRAM_EBIU
,
168 .name
= "Asynchronous Memory Banks",
173 .end
= L2_START
+ L2_LENGTH
,
175 .attr
= SWITCH_T
| I_CPLB
| D_CPLB
,
185 .start
= BOOT_ROM_START
,
186 .end
= BOOT_ROM_START
+ BOOT_ROM_LENGTH
,
188 .attr
= SWITCH_T
| I_CPLB
| D_CPLB
,
189 .i_conf
= SDRAM_IGENERIC
,
190 .d_conf
= SDRAM_DGENERIC
,
192 .name
= "On-Chip BootROM",
196 static u16 __init
lock_kernel_check(u32 start
, u32 end
)
198 if ((end
<= (u32
) _end
&& end
>= (u32
)_stext
) ||
199 (start
<= (u32
) _end
&& start
>= (u32
)_stext
))
204 static unsigned short __init
205 fill_cplbtab(struct cplb_tab
*table
,
206 unsigned long start
, unsigned long end
,
207 unsigned long block_size
, unsigned long cplb_data
)
211 switch (block_size
) {
227 cplb_data
= (cplb_data
& ~(3 << 16)) | (i
<< 16);
229 while ((start
< end
) && (table
->pos
< table
->size
)) {
231 table
->tab
[table
->pos
++] = start
;
233 if (lock_kernel_check(start
, start
+ block_size
) == IN_KERNEL
)
234 table
->tab
[table
->pos
++] =
235 cplb_data
| CPLB_LOCK
| CPLB_DIRTY
;
237 table
->tab
[table
->pos
++] = cplb_data
;
244 static unsigned short __init
245 close_cplbtab(struct cplb_tab
*table
)
248 while (table
->pos
< table
->size
) {
250 table
->tab
[table
->pos
++] = 0;
251 table
->tab
[table
->pos
++] = 0; /* !CPLB_VALID */
256 /* helper function */
257 static void __fill_code_cplbtab(struct cplb_tab
*t
, int i
, u32 a_start
, u32 a_end
)
259 if (cplb_data
[i
].psize
) {
264 cplb_data
[i
].i_conf
);
266 #if defined(CONFIG_BFIN_ICACHE)
267 if (ANOMALY_05000263
&& i
== SDRAM_KERN
) {
272 cplb_data
[i
].i_conf
);
280 cplb_data
[i
].i_conf
);
285 cplb_data
[i
].i_conf
);
286 fill_cplbtab(t
, a_end
,
289 cplb_data
[i
].i_conf
);
294 static void __fill_data_cplbtab(struct cplb_tab
*t
, int i
, u32 a_start
, u32 a_end
)
296 if (cplb_data
[i
].psize
) {
301 cplb_data
[i
].d_conf
);
306 cplb_data
[i
].d_conf
);
307 fill_cplbtab(t
, a_start
,
309 cplb_data
[i
].d_conf
);
310 fill_cplbtab(t
, a_end
,
313 cplb_data
[i
].d_conf
);
317 void __init
generate_cpl_tables(void)
321 u32 a_start
, a_end
, as
, ae
, as_1m
;
323 struct cplb_tab
*t_i
= NULL
;
324 struct cplb_tab
*t_d
= NULL
;
327 printk(KERN_INFO
"NOMPU: setting up cplb tables for global access\n");
329 cplb
.init_i
.size
= MAX_CPLBS
;
330 cplb
.init_d
.size
= MAX_CPLBS
;
331 cplb
.switch_i
.size
= MAX_SWITCH_I_CPLBS
;
332 cplb
.switch_d
.size
= MAX_SWITCH_D_CPLBS
;
336 cplb
.switch_i
.pos
= 0;
337 cplb
.switch_d
.pos
= 0;
339 cplb
.init_i
.tab
= icplb_table
;
340 cplb
.init_d
.tab
= dcplb_table
;
341 cplb
.switch_i
.tab
= ipdt_table
;
342 cplb
.switch_d
.tab
= dpdt_table
;
344 cplb_data
[SDRAM_KERN
].end
= memory_end
;
346 #ifdef CONFIG_MTD_UCLINUX
347 cplb_data
[SDRAM_RAM_MTD
].start
= memory_mtd_start
;
348 cplb_data
[SDRAM_RAM_MTD
].end
= memory_mtd_start
+ mtd_size
;
349 cplb_data
[SDRAM_RAM_MTD
].valid
= mtd_size
> 0;
350 # if defined(CONFIG_ROMFS_FS)
351 cplb_data
[SDRAM_RAM_MTD
].attr
|= I_CPLB
;
354 * The ROMFS_FS size is often not multiple of 1MB.
355 * This can cause multiple CPLB sets covering the same memory area.
356 * This will then cause multiple CPLB hit exceptions.
357 * Workaround: We ensure a contiguous memory area by extending the kernel
358 * memory section over the mtd section.
359 * For ROMFS_FS memory must be covered with ICPLBs anyways.
360 * So there is no difference between kernel and mtd memory setup.
363 cplb_data
[SDRAM_KERN
].end
= memory_mtd_start
+ mtd_size
;;
364 cplb_data
[SDRAM_RAM_MTD
].valid
= 0;
368 cplb_data
[SDRAM_RAM_MTD
].valid
= 0;
371 cplb_data
[SDRAM_DMAZ
].start
= _ramend
- DMA_UNCACHED_REGION
;
372 cplb_data
[SDRAM_DMAZ
].end
= _ramend
;
374 cplb_data
[RES_MEM
].start
= _ramend
;
375 cplb_data
[RES_MEM
].end
= physical_mem_end
;
377 if (reserved_mem_dcache_on
)
378 cplb_data
[RES_MEM
].d_conf
= SDRAM_DGENERIC
;
380 cplb_data
[RES_MEM
].d_conf
= SDRAM_DNON_CHBL
;
382 if (reserved_mem_icache_on
)
383 cplb_data
[RES_MEM
].i_conf
= SDRAM_IGENERIC
;
385 cplb_data
[RES_MEM
].i_conf
= SDRAM_INON_CHBL
;
387 for (i
= ZERO_P
; i
< ARRAY_SIZE(cplb_data
); ++i
) {
388 if (!cplb_data
[i
].valid
)
391 as_1m
= cplb_data
[i
].start
% SIZE_1M
;
393 /* We need to make sure all sections are properly 1M aligned
394 * However between Kernel Memory and the Kernel mtd section, depending on the
395 * rootfs size, there can be overlapping memory areas.
398 if (as_1m
&& i
!= L1I_MEM
&& i
!= L1D_MEM
) {
399 #ifdef CONFIG_MTD_UCLINUX
400 if (i
== SDRAM_RAM_MTD
) {
401 if ((cplb_data
[SDRAM_KERN
].end
+ 1) > cplb_data
[SDRAM_RAM_MTD
].start
)
402 cplb_data
[SDRAM_RAM_MTD
].start
= (cplb_data
[i
].start
& (-2*SIZE_1M
)) + SIZE_1M
;
404 cplb_data
[SDRAM_RAM_MTD
].start
= (cplb_data
[i
].start
& (-2*SIZE_1M
));
407 printk(KERN_WARNING
"Unaligned Start of %s at 0x%X\n",
408 cplb_data
[i
].name
, cplb_data
[i
].start
);
411 as
= cplb_data
[i
].start
% SIZE_4M
;
412 ae
= cplb_data
[i
].end
% SIZE_4M
;
415 a_start
= cplb_data
[i
].start
+ (SIZE_4M
- (as
));
417 a_start
= cplb_data
[i
].start
;
419 a_end
= cplb_data
[i
].end
- ae
;
421 for (j
= INITIAL_T
; j
<= SWITCH_T
; j
++) {
425 if (cplb_data
[i
].attr
& INITIAL_T
) {
433 if (cplb_data
[i
].attr
& SWITCH_T
) {
434 t_i
= &cplb
.switch_i
;
435 t_d
= &cplb
.switch_d
;
447 if (cplb_data
[i
].attr
& I_CPLB
)
448 __fill_code_cplbtab(t_i
, i
, a_start
, a_end
);
450 if (cplb_data
[i
].attr
& D_CPLB
)
451 __fill_data_cplbtab(t_d
, i
, a_start
, a_end
);
457 close_cplbtab(&cplb
.init_i
);
458 close_cplbtab(&cplb
.init_d
);
460 cplb
.init_i
.tab
[cplb
.init_i
.pos
] = -1;
461 cplb
.init_d
.tab
[cplb
.init_d
.pos
] = -1;
462 cplb
.switch_i
.tab
[cplb
.switch_i
.pos
] = -1;
463 cplb
.switch_d
.tab
[cplb
.switch_d
.pos
] = -1;