From: Yoshinori Sato <ysato@users.sourceforge.jp>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/6] SH2A cache support.
Date: Tue, 11 Feb 2014 21:20:33 +0900 [thread overview]
Message-ID: <1392121237-4790-2-git-send-email-ysato@users.sourceforge.jp> (raw)
In-Reply-To: <1392121237-4790-1-git-send-email-ysato@users.sourceforge.jp>
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
arch/sh/cpu/sh2/Makefile | 6 ++
arch/sh/cpu/sh2/cache-sh2a.c | 143 ++++++++++++++++++++++++++++++++++++++++++
arch/sh/cpu/sh2/cpu.c | 31 ---------
arch/sh/cpu/sh2/nocache.c | 37 +++++++++++
arch/sh/include/asm/cpu_sh2.h | 9 ---
5 files changed, 186 insertions(+), 40 deletions(-)
create mode 100644 arch/sh/cpu/sh2/cache-sh2a.c
create mode 100644 arch/sh/cpu/sh2/nocache.c
diff --git a/arch/sh/cpu/sh2/Makefile b/arch/sh/cpu/sh2/Makefile
index a19ed5e..6a11448 100644
--- a/arch/sh/cpu/sh2/Makefile
+++ b/arch/sh/cpu/sh2/Makefile
@@ -4,9 +4,15 @@
#
# Copyright (C) 2007,2008 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
# Copyright (C) 2008 Renesas Solutions Corp.
+# Copyright (C) 2013 Yoshinori Sato <ysato@users.sourceforge.jp>
#
# SPDX-License-Identifier: GPL-2.0+
#
extra-y = start.o
obj-y = cpu.o interrupts.o watchdog.o
+ifdef CONFIG_SH2A
+obj-y += cache-sh2a.o
+else
+obj-y += nocache.o
+endif
diff --git a/arch/sh/cpu/sh2/cache-sh2a.c b/arch/sh/cpu/sh2/cache-sh2a.c
new file mode 100644
index 0000000..a7bf5bc
--- /dev/null
+++ b/arch/sh/cpu/sh2/cache-sh2a.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2013 Yoshinori Sato <ysato@users.sourceforge.jp>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/processor.h>
+#include <asm/io.h>
+
+/*
+ * Jump to cache disabled area
+ * When handling caches, we need to do it from non-cache area.
+ */
+#define jump_to_uncacheable() \
+do { \
+ unsigned long __dummy; \
+ __asm__ __volatile__( \
+ "mov.l 1f, %0\n\t" \
+ "or %1, %0\n\t" \
+ "jmp @%0\n\t" \
+ " nop\n\t" \
+ ".balign 4\n" \
+ "1: .long 2f\n" \
+ "2:" \
+ : "=&r" (__dummy) \
+ : "r" (0x20000000)); \
+} while (0)
+
+/*
+ * Back to cache area.
+ */
+#define back_to_cacheable() \
+do { \
+ unsigned long __dummy; \
+ __asm__ __volatile__( \
+ "nop;nop;nop;nop;nop;nop;nop\n\t" \
+ "mov.l 1f, %0\n\t" \
+ "jmp @%0\n\t" \
+ " nop\n\t" \
+ ".balign 4\n" \
+ "1: .long 2f\n" \
+ "2:" \
+ : "=&r" (__dummy)); \
+} while (0)
+
+#define CACHE_OC_NUM_ENTRIES 128
+#define CACHE_OC_NUM_WAYS 4
+#define CACHE_OC_ADDRESS_ARRAY 0xf0800000
+#define CACHE_OC_WAY_SHIFT 11
+#define CACHE_OC_ENTRY_SHIFT 2
+#define CACHE_UPDATED 0x02
+
+static inline void cache_wback_all(void)
+{
+ unsigned long addr, data, i, j;
+
+ for (i = 0; i < CACHE_OC_NUM_ENTRIES; i++){
+ for (j = 0; j < CACHE_OC_NUM_WAYS; j++) {
+ addr = CACHE_OC_ADDRESS_ARRAY | (j << CACHE_OC_WAY_SHIFT)
+ | (i << CACHE_OC_ENTRY_SHIFT);
+ data = inl(addr);
+ if (data & CACHE_UPDATED) {
+ data &= ~CACHE_UPDATED;
+ outl(data, addr);
+ }
+ }
+ }
+}
+void flush_cache(unsigned long addr, unsigned long size)
+{
+ unsigned long entry;
+ unsigned long tag;
+ size = (size + 3) & ~3;
+ jump_to_uncacheable();
+ while(size > 0) {
+ entry = addr & 0x000003ff0;
+ tag = addr & 0x1ffff0000;
+ /* I-Cache flush */
+ outl(tag, 0xf0000008 | entry);
+ /* D-Cache flush with wb */
+ outl(tag, 0xf0800008 | entry);
+ addr += 4;
+ size -= 4;
+ }
+ back_to_cacheable();
+}
+
+void icache_enable(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ ccr |= 0x00000900;
+ jump_to_uncacheable();
+ writel(ccr, CCR1);
+ back_to_cacheable();
+}
+
+void icache_disable(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ ccr &= ~0x00000100;
+ jump_to_uncacheable();
+ writel(ccr, CCR1);
+ back_to_cacheable();
+}
+
+int icache_status(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ return ((ccr & 0x00000100) != 0);
+}
+
+void dcache_enable(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ ccr |= 0x00000009;
+ jump_to_uncacheable();
+ writel(ccr, CCR1);
+ back_to_cacheable();
+}
+
+void dcache_disable(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ ccr &= ~0x00000001;
+ jump_to_uncacheable();
+ cache_wback_all();
+ writel(ccr, CCR1);
+ back_to_cacheable();
+}
+
+int dcache_status(void)
+{
+ unsigned long ccr;
+ ccr = readl(CCR1);
+ return ((ccr & 0x00000001) != 0);
+}
diff --git a/arch/sh/cpu/sh2/cpu.c b/arch/sh/cpu/sh2/cpu.c
index a2f856f..b401d08 100644
--- a/arch/sh/cpu/sh2/cpu.c
+++ b/arch/sh/cpu/sh2/cpu.c
@@ -52,34 +52,3 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
reset_cpu(0);
return 0;
}
-
-void flush_cache(unsigned long addr, unsigned long size)
-{
-
-}
-
-void icache_enable(void)
-{
-}
-
-void icache_disable(void)
-{
-}
-
-int icache_status(void)
-{
- return 0;
-}
-
-void dcache_enable(void)
-{
-}
-
-void dcache_disable(void)
-{
-}
-
-int dcache_status(void)
-{
- return 0;
-}
diff --git a/arch/sh/cpu/sh2/nocache.c b/arch/sh/cpu/sh2/nocache.c
new file mode 100644
index 0000000..06b7f4c
--- /dev/null
+++ b/arch/sh/cpu/sh2/nocache.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 Yoshinori Sato <ysato@users.sourceforge.jp>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/* dummy cache control functions */
+void flush_cache(unsigned long addr, unsigned long size)
+{
+
+}
+
+void icache_enable(void)
+{
+}
+
+void icache_disable(void)
+{
+}
+
+int icache_status(void)
+{
+ return 0;
+}
+
+void dcache_enable(void)
+{
+}
+
+void dcache_disable(void)
+{
+}
+
+int dcache_status(void)
+{
+ return 0;
+}
diff --git a/arch/sh/include/asm/cpu_sh2.h b/arch/sh/include/asm/cpu_sh2.h
index 18a0f0b..b67c093 100644
--- a/arch/sh/include/asm/cpu_sh2.h
+++ b/arch/sh/include/asm/cpu_sh2.h
@@ -8,15 +8,6 @@
#ifndef _ASM_CPU_SH2_H_
#define _ASM_CPU_SH2_H_
-/* cache control */
-#define CCR_CACHE_STOP 0x00000008
-#define CCR_CACHE_ENABLE 0x00000005
-#define CCR_CACHE_ICI 0x00000008
-
-#define CACHE_OC_ADDRESS_ARRAY 0xf0000000
-#define CACHE_OC_WAY_SHIFT 13
-#define CACHE_OC_NUM_ENTRIES 256
-#define CACHE_OC_ENTRY_SHIFT 4
#if defined(CONFIG_CPU_SH7203)
# include <asm/cpu_sh7203.h>
--
1.8.5.3
next prev parent reply other threads:[~2014-02-11 12:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-11 12:20 [U-Boot] [PATCH 1/6] Add MS7206SE support Yoshinori Sato
2014-02-11 12:20 ` Yoshinori Sato [this message]
2014-02-11 12:20 ` [U-Boot] [PATCH 3/6] fix typo Yoshinori Sato
2014-02-11 12:20 ` [U-Boot] [PATCH 4/6] module enabler cleanup Yoshinori Sato
2014-02-11 12:20 ` [U-Boot] [PATCH 5/6] Add SH7206 support Yoshinori Sato
2014-02-11 12:20 ` [U-Boot] [PATCH 6/6] Update build options Yoshinori Sato
-- strict thread matches above, loose matches on Subject: below --
2014-02-11 12:24 [U-Boot] [PATCH 1/6] Add MS7206SE support Yoshinori Sato
2014-02-11 12:24 ` [U-Boot] [PATCH 2/6] SH2A cache support Yoshinori Sato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392121237-4790-2-git-send-email-ysato@users.sourceforge.jp \
--to=ysato@users.sourceforge.jp \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.