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> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 10 | #include <asm/asm.h> |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 11 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 12 | int dcache_status(void) |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 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 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 22 | int icache_status(void) |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 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 | f3f001a | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 31 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 32 | void icache_enable(void) |
| 33 | { |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 34 | MSRSET(0x20); |
Michal Simek | f3f001a | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 37 | void icache_disable(void) |
| 38 | { |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 39 | /* we are not generate ICACHE size -> flush whole cache */ |
| 40 | flush_cache(0, 32768); |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 41 | MSRCLR(0x20); |
Michal Simek | f3f001a | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 44 | void dcache_enable(void) |
| 45 | { |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 46 | MSRSET(0x80); |
Michal Simek | f3f001a | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 47 | } |
| 48 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 49 | void dcache_disable(void) |
| 50 | { |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 51 | #ifdef XILINX_USE_DCACHE |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 52 | flush_cache(0, XILINX_DCACHE_BYTE_SIZE); |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 53 | #endif |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 54 | MSRCLR(0x80); |
Michal Simek | f3f001a | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 55 | } |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 56 | |
Simon Glass | 6cc915b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 57 | void flush_cache(ulong addr, ulong size) |
Michal Simek | 8ff972c | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 58 | { |
| 59 | int i; |
| 60 | for (i = 0; i < size; i += 4) |
| 61 | asm volatile ( |
| 62 | #ifdef CONFIG_ICACHE |
| 63 | "wic %0, r0;" |
| 64 | #endif |
| 65 | "nop;" |
| 66 | #ifdef CONFIG_DCACHE |
| 67 | "wdc.flush %0, r0;" |
| 68 | #endif |
| 69 | "nop;" |
| 70 | : |
| 71 | : "r" (addr + i) |
| 72 | : "memory"); |
| 73 | } |