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