blob: 94114555ff53ff15472d8b3533d6814e4aa01764 [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>
Michal Simekfb05f6d2007-05-07 23:58:31 +02009#include <asm/asm.h>
Michal Simek76316a32007-03-11 13:42:58 +010010
Simon Glass6cc915b2019-11-14 12:57:36 -070011int dcache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010012{
13 int i = 0;
14 int mask = 0x80;
15 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
16 /* i&=0x80 */
17 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
18 return i;
19}
20
Simon Glass6cc915b2019-11-14 12:57:36 -070021int icache_status(void)
Michal Simek76316a32007-03-11 13:42:58 +010022{
23 int i = 0;
24 int mask = 0x20;
25 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
26 /* i&=0x20 */
27 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
28 return i;
29}
Michal Simekf3f001a2007-05-07 19:25:08 +020030
Simon Glass6cc915b2019-11-14 12:57:36 -070031void icache_enable(void)
32{
Michal Simekfb05f6d2007-05-07 23:58:31 +020033 MSRSET(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020034}
35
Simon Glass6cc915b2019-11-14 12:57:36 -070036void icache_disable(void)
37{
Michal Simek8ff972c2010-04-16 12:56:33 +020038 /* we are not generate ICACHE size -> flush whole cache */
39 flush_cache(0, 32768);
Michal Simekfb05f6d2007-05-07 23:58:31 +020040 MSRCLR(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020041}
42
Simon Glass6cc915b2019-11-14 12:57:36 -070043void dcache_enable(void)
44{
Michal Simekfb05f6d2007-05-07 23:58:31 +020045 MSRSET(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020046}
47
Simon Glass6cc915b2019-11-14 12:57:36 -070048void dcache_disable(void)
49{
Michal Simek8ff972c2010-04-16 12:56:33 +020050#ifdef XILINX_USE_DCACHE
Michal Simek8ff972c2010-04-16 12:56:33 +020051 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek8ff972c2010-04-16 12:56:33 +020052#endif
Michal Simekfb05f6d2007-05-07 23:58:31 +020053 MSRCLR(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020054}
Michal Simek8ff972c2010-04-16 12:56:33 +020055
Simon Glass6cc915b2019-11-14 12:57:36 -070056void flush_cache(ulong addr, ulong size)
Michal Simek8ff972c2010-04-16 12:56:33 +020057{
58 int i;
59 for (i = 0; i < size; i += 4)
60 asm volatile (
61#ifdef CONFIG_ICACHE
62 "wic %0, r0;"
63#endif
64 "nop;"
65#ifdef CONFIG_DCACHE
66 "wdc.flush %0, r0;"
67#endif
68 "nop;"
69 :
70 : "r" (addr + i)
71 : "memory");
72}