Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - cache.c |
| 3 | * |
Mike Frysinger | b86b341 | 2008-02-19 00:50:58 -0500 | [diff] [blame] | 4 | * Copyright (c) 2005-2008 Analog Devices Inc. |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 5 | * |
| 6 | * (C) Copyright 2000-2004 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
Mike Frysinger | b86b341 | 2008-02-19 00:50:58 -0500 | [diff] [blame] | 9 | * Licensed under the GPL-2 or later. |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 12 | #include <common.h> |
| 13 | #include <asm/blackfin.h> |
Mike Frysinger | 50f0d21 | 2008-08-07 15:21:47 -0400 | [diff] [blame] | 14 | #include <asm/mach-common/bits/mpu.h> |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 15 | |
Mike Frysinger | b86b341 | 2008-02-19 00:50:58 -0500 | [diff] [blame] | 16 | void flush_cache(unsigned long addr, unsigned long size) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 17 | { |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 18 | void *start_addr, *end_addr; |
| 19 | int istatus, dstatus; |
| 20 | |
Mike Frysinger | b86b341 | 2008-02-19 00:50:58 -0500 | [diff] [blame] | 21 | /* no need to flush stuff in on chip memory (L1/L2/etc...) */ |
| 22 | if (addr >= 0xE0000000) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 23 | return; |
| 24 | |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 25 | start_addr = (void *)addr; |
| 26 | end_addr = (void *)(addr + size); |
| 27 | istatus = icache_status(); |
| 28 | dstatus = dcache_status(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 29 | |
Mike Frysinger | fdce83c | 2008-11-04 00:04:03 -0500 | [diff] [blame] | 30 | if (istatus) { |
| 31 | if (dstatus) |
| 32 | blackfin_icache_dcache_flush_range(start_addr, end_addr); |
| 33 | else |
| 34 | blackfin_icache_flush_range(start_addr, end_addr); |
| 35 | } else if (dstatus) |
| 36 | blackfin_dcache_flush_range(start_addr, end_addr); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 37 | } |
Mike Frysinger | 50f0d21 | 2008-08-07 15:21:47 -0400 | [diff] [blame] | 38 | |
| 39 | void icache_enable(void) |
| 40 | { |
| 41 | bfin_write_IMEM_CONTROL(IMC | ENICPLB); |
| 42 | SSYNC(); |
| 43 | } |
| 44 | |
| 45 | void icache_disable(void) |
| 46 | { |
| 47 | bfin_write_IMEM_CONTROL(0); |
| 48 | SSYNC(); |
| 49 | } |
| 50 | |
| 51 | int icache_status(void) |
| 52 | { |
Mike Frysinger | 0f9a881 | 2008-08-07 18:40:13 -0400 | [diff] [blame] | 53 | return bfin_read_IMEM_CONTROL() & IMC; |
Mike Frysinger | 50f0d21 | 2008-08-07 15:21:47 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void dcache_enable(void) |
| 57 | { |
| 58 | bfin_write_DMEM_CONTROL(ACACHE_BCACHE | ENDCPLB | PORT_PREF0); |
| 59 | SSYNC(); |
| 60 | } |
| 61 | |
| 62 | void dcache_disable(void) |
| 63 | { |
| 64 | bfin_write_DMEM_CONTROL(0); |
| 65 | SSYNC(); |
| 66 | } |
| 67 | |
| 68 | int dcache_status(void) |
| 69 | { |
Mike Frysinger | 0f9a881 | 2008-08-07 18:40:13 -0400 | [diff] [blame] | 70 | return bfin_read_DMEM_CONTROL() & ACACHE_BCACHE; |
Mike Frysinger | 50f0d21 | 2008-08-07 15:21:47 -0400 | [diff] [blame] | 71 | } |