blob: ddfa02000ec3c3d63088521a5bc450dcc6ef18f6 [file] [log] [blame]
Michal Simek76316a32007-03-11 13:42:58 +01001/*
2 * (C) Copyright 2007 Michal Simek
3 *
Michal Simekdb14d772007-09-24 00:18:46 +02004 * Michal SIMEK <monstr@monstr.eu>
Michal Simek76316a32007-03-11 13:42:58 +01005 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Michal Simek76316a32007-03-11 13:42:58 +01007 */
8
9#include <common.h>
Michal Simekfb05f6d2007-05-07 23:58:31 +020010#include <asm/asm.h>
Michal Simek76316a32007-03-11 13:42:58 +010011
Michal Simek76316a32007-03-11 13:42:58 +010012int dcache_status (void)
13{
14 int i = 0;
15 int mask = 0x80;
16 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
17 /* i&=0x80 */
18 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
19 return i;
20}
21
22int icache_status (void)
23{
24 int i = 0;
25 int mask = 0x20;
26 __asm__ __volatile__ ("mfs %0,rmsr"::"r" (i):"memory");
27 /* i&=0x20 */
28 __asm__ __volatile__ ("and %0,%0,%1"::"r" (i), "r" (mask):"memory");
29 return i;
30}
Michal Simekf3f001a2007-05-07 19:25:08 +020031
32void icache_enable (void) {
Michal Simekfb05f6d2007-05-07 23:58:31 +020033 MSRSET(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020034}
35
36void icache_disable(void) {
Michal Simek8ff972c2010-04-16 12:56:33 +020037 /* we are not generate ICACHE size -> flush whole cache */
38 flush_cache(0, 32768);
Michal Simekfb05f6d2007-05-07 23:58:31 +020039 MSRCLR(0x20);
Michal Simekf3f001a2007-05-07 19:25:08 +020040}
41
42void dcache_enable (void) {
Michal Simekfb05f6d2007-05-07 23:58:31 +020043 MSRSET(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020044}
45
46void dcache_disable(void) {
Michal Simek8ff972c2010-04-16 12:56:33 +020047#ifdef XILINX_USE_DCACHE
Michal Simek8ff972c2010-04-16 12:56:33 +020048 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek8ff972c2010-04-16 12:56:33 +020049#endif
Michal Simekfb05f6d2007-05-07 23:58:31 +020050 MSRCLR(0x80);
Michal Simekf3f001a2007-05-07 19:25:08 +020051}
Michal Simek8ff972c2010-04-16 12:56:33 +020052
53void flush_cache (ulong addr, ulong size)
54{
55 int i;
56 for (i = 0; i < size; i += 4)
57 asm volatile (
58#ifdef CONFIG_ICACHE
59 "wic %0, r0;"
60#endif
61 "nop;"
62#ifdef CONFIG_DCACHE
63 "wdc.flush %0, r0;"
64#endif
65 "nop;"
66 :
67 : "r" (addr + i)
68 : "memory");
69}