blob: aa832d6be6d40e000b43e1f45b069ec8bb8c8e88 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek76316a32007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
Michal Simekdb14d772007-09-24 00:18:46 +02005 * Michal SIMEK <monstr@monstr.eu>
Michal Simek76316a32007-03-11 13:42:58 +01006 */
7
8#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07009#include <cpu_func.h>
Michal Simekfb05f6d2007-05-07 23:58:31 +020010#include <asm/asm.h>
Simon Glass90526e92020-05-10 11:39:56 -060011#include <asm/cache.h>
Michal Simek76316a32007-03-11 13:42:58 +010012
Simon Glass6cc915b2019-11-14 12:57:36 -070013int dcache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010014{
15 int i = 0;
16 int mask = 0x80;
17 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
18 /* i&=0x80 */
19 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
20 return i;
21}
22
Simon Glass6cc915b2019-11-14 12:57:36 -070023int icache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010024{
25 int i = 0;
26 int mask = 0x20;
27 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
28 /* i&=0x20 */
29 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
30 return i;
31}
Michal Simekf3f001a2007-05-07 19:25:08 +020032
Simon Glass6cc915b2019-11-14 12:57:36 -070033void icache_enable(void)
34{
Michal Simekfb05f6d2007-05-07 23:58:31 +020035 MSRSET(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020036}
37
Simon Glass6cc915b2019-11-14 12:57:36 -070038void icache_disable(void)
39{
Michal Simek8ff972c2010-04-16 12:56:33 +020040 /* we are not generate ICACHE size -> flush whole cache */
41 flush_cache(0, 32768);
Michal Simekfb05f6d2007-05-07 23:58:31 +020042 MSRCLR(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020043}
44
Simon Glass6cc915b2019-11-14 12:57:36 -070045void dcache_enable(void)
46{
Michal Simekfb05f6d2007-05-07 23:58:31 +020047 MSRSET(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020048}
49
Simon Glass6cc915b2019-11-14 12:57:36 -070050void dcache_disable(void)
51{
Michal Simek8ff972c2010-04-16 12:56:33 +020052#ifdef XILINX_USE_DCACHE
Michal Simek8ff972c2010-04-16 12:56:33 +020053 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek8ff972c2010-04-16 12:56:33 +020054#endif
Michal Simekfb05f6d2007-05-07 23:58:31 +020055 MSRCLR(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020056}
Michal Simek8ff972c2010-04-16 12:56:33 +020057
Simon Glass6cc915b2019-11-14 12:57:36 -070058void flush_cache(ulong addr, ulong size)
Michal Simek8ff972c2010-04-16 12:56:33 +020059{
60 int i;
61 for (i = 0; i < size; i += 4)
62 asm volatile (
63#ifdef CONFIG_ICACHE
64 "wic %0, r0;"
65#endif
66 "nop;"
67#ifdef CONFIG_DCACHE
68 "wdc.flush %0, r0;"
69#endif
70 "nop;"
71 :
72 : "r" (addr + i)
73 : "memory");
74}