4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * Licensed under the GPL-2 or later.
13 #include <asm/blackfin.h>
14 #include <asm/mach-common/bits/mpu.h>
16 void flush_cache(unsigned long addr, unsigned long size)
18 void *start_addr, *end_addr;
21 /* no need to flush stuff in on chip memory (L1/L2/etc...) */
22 if (addr >= 0xE0000000)
25 start_addr = (void *)addr;
26 end_addr = (void *)(addr + size);
27 istatus = icache_status();
28 dstatus = dcache_status();
32 blackfin_icache_dcache_flush_range(start_addr, end_addr);
34 blackfin_icache_flush_range(start_addr, end_addr);
36 blackfin_dcache_flush_range(start_addr, end_addr);
39 #ifdef CONFIG_DCACHE_WB
40 static void flushinv_all_dcache(void)
42 u32 way, bank, subbank, set;
44 u32 dmem_ctl = bfin_read_DMEM_CONTROL();
46 for (bank = 0; bank < 2; ++bank) {
47 if (!(dmem_ctl & (1 << (DMC1_P - bank))))
50 for (way = 0; way < 2; ++way)
51 for (subbank = 0; subbank < 4; ++subbank)
52 for (set = 0; set < 64; ++set) {
54 bfin_write_DTEST_COMMAND(
61 status = bfin_read_DTEST_DATA0();
63 /* only worry about valid/dirty entries */
64 if ((status & 0x3) != 0x3)
67 /* construct the address using the tag */
68 addr = (status & 0xFFFFC800) | (subbank << 12) | (set << 5);
71 __asm__ __volatile__("FLUSHINV[%0];" : : "a"(addr));
77 void icache_enable(void)
79 bfin_write_IMEM_CONTROL(IMC | ENICPLB);
83 void icache_disable(void)
85 bfin_write_IMEM_CONTROL(0);
89 int icache_status(void)
91 return bfin_read_IMEM_CONTROL() & IMC;
94 void dcache_enable(void)
96 bfin_write_DMEM_CONTROL(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
100 void dcache_disable(void)
102 #ifdef CONFIG_DCACHE_WB
103 bfin_write_DMEM_CONTROL(bfin_read_DMEM_CONTROL() & ~(ENDCPLB));
104 flushinv_all_dcache();
106 bfin_write_DMEM_CONTROL(0);
110 int dcache_status(void)
112 return bfin_read_DMEM_CONTROL() & ACACHE_BCACHE;