blob: 829e6c7ae60577e48c457f96d5483727170a9e53 [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
8#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Michal Simek98c19792007-05-07 23:58:31 +020010#include <asm/asm.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <asm/cache.h>
Ovidiu Panait87a739e2022-05-31 21:14:31 +030012#include <asm/cpuinfo.h>
13#include <asm/global_data.h>
14
15DECLARE_GLOBAL_DATA_PTR;
Michal Simek952d5142007-03-11 13:42:58 +010016
Ovidiu Panaite731f152022-05-31 21:14:28 +030017static void __invalidate_icache(ulong addr, ulong size)
18{
19 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
Ovidiu Panait87a739e2022-05-31 21:14:31 +030020 for (int i = 0; i < size;
21 i += gd_cpuinfo()->icache_line_length) {
Ovidiu Panaite731f152022-05-31 21:14:28 +030022 asm volatile (
23 "wic %0, r0;"
24 "nop;"
25 :
26 : "r" (addr + i)
27 : "memory");
28 }
29 }
30}
31
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030032void invalidate_icache_all(void)
33{
Ovidiu Panait87a739e2022-05-31 21:14:31 +030034 __invalidate_icache(0, gd_cpuinfo()->icache_size);
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030035}
36
Ovidiu Panaite731f152022-05-31 21:14:28 +030037static void __flush_dcache(ulong addr, ulong size)
38{
39 if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
Ovidiu Panait87a739e2022-05-31 21:14:31 +030040 for (int i = 0; i < size;
41 i += gd_cpuinfo()->dcache_line_length) {
Ovidiu Panaite731f152022-05-31 21:14:28 +030042 asm volatile (
43 "wdc.flush %0, r0;"
44 "nop;"
45 :
46 : "r" (addr + i)
47 : "memory");
48 }
49 }
50}
51
Ovidiu Panait9782f082022-05-31 21:14:32 +030052void 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 Panaitbc159c12022-05-31 21:14:30 +030063void flush_dcache_all(void)
64{
Ovidiu Panait87a739e2022-05-31 21:14:31 +030065 __flush_dcache(0, gd_cpuinfo()->dcache_size);
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030066}
67
Simon Glassfbf091b2019-11-14 12:57:36 -070068int dcache_status(void)
Michal Simek952d5142007-03-11 13:42:58 +010069{
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 Glassfbf091b2019-11-14 12:57:36 -070078int icache_status(void)
Michal Simek952d5142007-03-11 13:42:58 +010079{
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 Simekc4f5ef82007-05-07 19:25:08 +020087
Simon Glassfbf091b2019-11-14 12:57:36 -070088void icache_enable(void)
89{
Michal Simek98c19792007-05-07 23:58:31 +020090 MSRSET(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020091}
92
Simon Glassfbf091b2019-11-14 12:57:36 -070093void icache_disable(void)
94{
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030095 invalidate_icache_all();
Ovidiu Panaite731f152022-05-31 21:14:28 +030096
Michal Simek98c19792007-05-07 23:58:31 +020097 MSRCLR(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020098}
99
Simon Glassfbf091b2019-11-14 12:57:36 -0700100void dcache_enable(void)
101{
Michal Simek98c19792007-05-07 23:58:31 +0200102 MSRSET(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +0200103}
104
Simon Glassfbf091b2019-11-14 12:57:36 -0700105void dcache_disable(void)
106{
Ovidiu Panaitbc159c12022-05-31 21:14:30 +0300107 flush_dcache_all();
Ovidiu Panait3ab2bed2022-05-31 21:14:26 +0300108
Michal Simek98c19792007-05-07 23:58:31 +0200109 MSRCLR(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +0200110}
Michal Simek08a30cb2010-04-16 12:56:33 +0200111
Simon Glassfbf091b2019-11-14 12:57:36 -0700112void flush_cache(ulong addr, ulong size)
Michal Simek08a30cb2010-04-16 12:56:33 +0200113{
Ovidiu Panaite731f152022-05-31 21:14:28 +0300114 __invalidate_icache(addr, size);
115 __flush_dcache(addr, size);
Michal Simek08a30cb2010-04-16 12:56:33 +0200116}
Ovidiu Panaitbc159c12022-05-31 21:14:30 +0300117
118void flush_cache_all(void)
119{
120 invalidate_icache_all();
121 flush_dcache_all();
122}