Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 Michal Simek |
| 3 | * |
Michal Simek | 571bce1 | 2007-09-24 00:18:46 +0200 | [diff] [blame] | 4 | * Michal SIMEK <monstr@monstr.eu> |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 10 | #include <asm/asm.h> |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 11 | |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 12 | int dcache_status (void) |
| 13 | { |
| 14 | int i = 0; |
| 15 | int mask = 0x80; |
| 16 | __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory"); |
| 17 | /* i&=0x80 */ |
| 18 | __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory"); |
| 19 | return i; |
| 20 | } |
| 21 | |
| 22 | int icache_status (void) |
| 23 | { |
| 24 | int i = 0; |
| 25 | int mask = 0x20; |
| 26 | __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory"); |
| 27 | /* i&=0x20 */ |
| 28 | __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory"); |
| 29 | return i; |
| 30 | } |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 31 | |
| 32 | void icache_enable (void) { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 33 | MSRSET(0x20); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void icache_disable(void) { |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 37 | /* we are not generate ICACHE size -> flush whole cache */ |
| 38 | flush_cache(0, 32768); |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 39 | MSRCLR(0x20); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void dcache_enable (void) { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 43 | MSRSET(0x80); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void dcache_disable(void) { |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 47 | #ifdef XILINX_USE_DCACHE |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 48 | flush_cache(0, XILINX_DCACHE_BYTE_SIZE); |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 49 | #endif |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 50 | MSRCLR(0x80); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 51 | } |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 52 | |
| 53 | void flush_cache (ulong addr, ulong size) |
| 54 | { |
| 55 | int i; |
| 56 | for (i = 0; i < size; i += 4) |
| 57 | asm volatile ( |
| 58 | #ifdef CONFIG_ICACHE |
| 59 | "wic %0, r0;" |
| 60 | #endif |
| 61 | "nop;" |
| 62 | #ifdef CONFIG_DCACHE |
| 63 | "wdc.flush %0, r0;" |
| 64 | #endif |
| 65 | "nop;" |
| 66 | : |
| 67 | : "r" (addr + i) |
| 68 | : "memory"); |
| 69 | } |