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 | |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 9 | #include <asm/asm.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <asm/cache.h> |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame] | 11 | #include <asm/cpuinfo.h> |
| 12 | #include <asm/global_data.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 15 | |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 16 | static void __invalidate_icache(ulong addr, ulong size) |
| 17 | { |
| 18 | if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) { |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame] | 19 | for (int i = 0; i < size; |
| 20 | i += gd_cpuinfo()->icache_line_length) { |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 21 | asm volatile ( |
| 22 | "wic %0, r0;" |
| 23 | "nop;" |
| 24 | : |
| 25 | : "r" (addr + i) |
| 26 | : "memory"); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 31 | void invalidate_icache_all(void) |
| 32 | { |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame] | 33 | __invalidate_icache(0, gd_cpuinfo()->icache_size); |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 34 | } |
| 35 | |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 36 | static void __flush_dcache(ulong addr, ulong size) |
| 37 | { |
| 38 | if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) { |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame] | 39 | for (int i = 0; i < size; |
| 40 | i += gd_cpuinfo()->dcache_line_length) { |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 41 | asm volatile ( |
| 42 | "wdc.flush %0, r0;" |
| 43 | "nop;" |
| 44 | : |
| 45 | : "r" (addr + i) |
| 46 | : "memory"); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
Ovidiu Panait | 9782f08 | 2022-05-31 21:14:32 +0300 | [diff] [blame] | 51 | void flush_dcache_range(unsigned long start, unsigned long end) |
| 52 | { |
| 53 | if (start >= end) { |
| 54 | debug("Invalid dcache range - start: 0x%08lx end: 0x%08lx\n", |
| 55 | start, end); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | __flush_dcache(start, end - start); |
| 60 | } |
| 61 | |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 62 | void flush_dcache_all(void) |
| 63 | { |
Ovidiu Panait | 87a739e | 2022-05-31 21:14:31 +0300 | [diff] [blame] | 64 | __flush_dcache(0, gd_cpuinfo()->dcache_size); |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 65 | } |
| 66 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 67 | int dcache_status(void) |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 68 | { |
| 69 | int i = 0; |
| 70 | int mask = 0x80; |
| 71 | __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory"); |
| 72 | /* i&=0x80 */ |
| 73 | __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory"); |
| 74 | return i; |
| 75 | } |
| 76 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 77 | int icache_status(void) |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 78 | { |
| 79 | int i = 0; |
| 80 | int mask = 0x20; |
| 81 | __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory"); |
| 82 | /* i&=0x20 */ |
| 83 | __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory"); |
| 84 | return i; |
| 85 | } |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 86 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 87 | void icache_enable(void) |
| 88 | { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 89 | MSRSET(0x20); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 92 | void icache_disable(void) |
| 93 | { |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 94 | invalidate_icache_all(); |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 95 | |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 96 | MSRCLR(0x20); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 99 | void dcache_enable(void) |
| 100 | { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 101 | MSRSET(0x80); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 104 | void dcache_disable(void) |
| 105 | { |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 106 | flush_dcache_all(); |
Ovidiu Panait | 3ab2bed | 2022-05-31 21:14:26 +0300 | [diff] [blame] | 107 | |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 108 | MSRCLR(0x80); |
Michal Simek | c4f5ef8 | 2007-05-07 19:25:08 +0200 | [diff] [blame] | 109 | } |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 110 | |
Simon Glass | fbf091b | 2019-11-14 12:57:36 -0700 | [diff] [blame] | 111 | void flush_cache(ulong addr, ulong size) |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 112 | { |
Ovidiu Panait | e731f15 | 2022-05-31 21:14:28 +0300 | [diff] [blame] | 113 | __invalidate_icache(addr, size); |
| 114 | __flush_dcache(addr, size); |
Michal Simek | 08a30cb | 2010-04-16 12:56:33 +0200 | [diff] [blame] | 115 | } |
Ovidiu Panait | bc159c1 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 116 | |
| 117 | void flush_cache_all(void) |
| 118 | { |
| 119 | invalidate_icache_all(); |
| 120 | flush_dcache_all(); |
| 121 | } |