blob: aa832d6be6d40e000b43e1f45b069ec8bb8c8e88 [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>
Michal Simek952d5142007-03-11 13:42:58 +010012
Simon Glassfbf091b2019-11-14 12:57:36 -070013int dcache_status(void)
Michal Simek952d5142007-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 Glassfbf091b2019-11-14 12:57:36 -070023int icache_status(void)
Michal Simek952d5142007-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 Simekc4f5ef82007-05-07 19:25:08 +020032
Simon Glassfbf091b2019-11-14 12:57:36 -070033void icache_enable(void)
34{
Michal Simek98c19792007-05-07 23:58:31 +020035 MSRSET(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020036}
37
Simon Glassfbf091b2019-11-14 12:57:36 -070038void icache_disable(void)
39{
Michal Simek08a30cb2010-04-16 12:56:33 +020040 /* we are not generate ICACHE size -> flush whole cache */
41 flush_cache(0, 32768);
Michal Simek98c19792007-05-07 23:58:31 +020042 MSRCLR(0x20);
Michal Simekc4f5ef82007-05-07 19:25:08 +020043}
44
Simon Glassfbf091b2019-11-14 12:57:36 -070045void dcache_enable(void)
46{
Michal Simek98c19792007-05-07 23:58:31 +020047 MSRSET(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020048}
49
Simon Glassfbf091b2019-11-14 12:57:36 -070050void dcache_disable(void)
51{
Michal Simek08a30cb2010-04-16 12:56:33 +020052#ifdef XILINX_USE_DCACHE
Michal Simek08a30cb2010-04-16 12:56:33 +020053 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek08a30cb2010-04-16 12:56:33 +020054#endif
Michal Simek98c19792007-05-07 23:58:31 +020055 MSRCLR(0x80);
Michal Simekc4f5ef82007-05-07 19:25:08 +020056}
Michal Simek08a30cb2010-04-16 12:56:33 +020057
Simon Glassfbf091b2019-11-14 12:57:36 -070058void flush_cache(ulong addr, ulong size)
Michal Simek08a30cb2010-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}