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