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