blob: 75ec0a8fd24f440155c93af967f6af904ba16d8e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek952d5142007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
Michal Simek571bce12007-09-24 00:18:46 +02005 * Michal SIMEK <monstr@monstr.eu>
Michal Simek952d5142007-03-11 13:42:58 +01006 */
7
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Michal Simek98c19792007-05-07 23:58:31 +02009#include <asm/asm.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Ovidiu Panait87a739e2022-05-31 21:14:31 +030011#include <asm/cpuinfo.h>
12#include <asm/global_data.h>
13
14DECLARE_GLOBAL_DATA_PTR;
Michal Simek952d5142007-03-11 13:42:58 +010015
Ovidiu Panaite731f152022-05-31 21:14:28 +030016static void __invalidate_icache(ulong addr, ulong size)
17{
18 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
Ovidiu Panait87a739e2022-05-31 21:14:31 +030019 for (int i = 0; i < size;
20 i += gd_cpuinfo()->icache_line_length) {
Ovidiu Panaite731f152022-05-31 21:14:28 +030021 asm volatile (
22 "wic %0, r0;"
23 "nop;"
24 :
25 : "r" (addr + i)
26 : "memory");
27 }
28 }
29}
30
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030031void invalidate_icache_all(void)
32{
Ovidiu Panait87a739e2022-05-31 21:14:31 +030033 __invalidate_icache(0, gd_cpuinfo()->icache_size);
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030034}
35
Ovidiu Panaite731f152022-05-31 21:14:28 +030036static void __flush_dcache(ulong addr, ulong size)
37{
38 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
Ovidiu Panait87a739e2022-05-31 21:14:31 +030039 for (int i = 0; i < size;
40 i += gd_cpuinfo()->dcache_line_length) {
Ovidiu Panaite731f152022-05-31 21:14:28 +030041 asm volatile (
42 "wdc.flush %0, r0;"
43 "nop;"
44 :
45 : "r" (addr + i)
46 : "memory");
47 }
48 }
49}
50
Ovidiu Panait9782f082022-05-31 21:14:32 +030051void 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 Panaitbc159c12022-05-31 21:14:30 +030062void flush_dcache_all(void)
63{
Ovidiu Panait87a739e2022-05-31 21:14:31 +030064 __flush_dcache(0, gd_cpuinfo()->dcache_size);
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030065}
66
Simon Glassfbf091b2019-11-14 12:57:36 -070067int dcache_status(void)
Michal Simek952d5142007-03-11 13:42:58 +010068{
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 Glassfbf091b2019-11-14 12:57:36 -070077int icache_status(void)
Michal Simek952d5142007-03-11 13:42:58 +010078{
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 Simekc4f5ef82007-05-07 19:25:08 +020086
Simon Glassfbf091b2019-11-14 12:57:36 -070087void icache_enable(void)
88{
Michal Simek98c19792007-05-07 23:58:31 +020089 MSRSET(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020090}
91
Simon Glassfbf091b2019-11-14 12:57:36 -070092void icache_disable(void)
93{
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030094 invalidate_icache_all();
Ovidiu Panaite731f152022-05-31 21:14:28 +030095
Michal Simek98c19792007-05-07 23:58:31 +020096 MSRCLR(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020097}
98
Simon Glassfbf091b2019-11-14 12:57:36 -070099void dcache_enable(void)
100{
Michal Simek98c19792007-05-07 23:58:31 +0200101 MSRSET(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +0200102}
103
Simon Glassfbf091b2019-11-14 12:57:36 -0700104void dcache_disable(void)
105{
Ovidiu Panaitbc159c12022-05-31 21:14:30 +0300106 flush_dcache_all();
Ovidiu Panait3ab2bed2022-05-31 21:14:26 +0300107
Michal Simek98c19792007-05-07 23:58:31 +0200108 MSRCLR(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +0200109}
Michal Simek08a30cb2010-04-16 12:56:33 +0200110
Simon Glassfbf091b2019-11-14 12:57:36 -0700111void flush_cache(ulong addr, ulong size)
Michal Simek08a30cb2010-04-16 12:56:33 +0200112{
Ovidiu Panaite731f152022-05-31 21:14:28 +0300113 __invalidate_icache(addr, size);
114 __flush_dcache(addr, size);
Michal Simek08a30cb2010-04-16 12:56:33 +0200115}
Ovidiu Panaitbc159c12022-05-31 21:14:30 +0300116
117void flush_cache_all(void)
118{
119 invalidate_icache_all();
120 flush_dcache_all();
121}