From patchwork Thu Feb 13 14:13:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshinori Sato X-Patchwork-Id: 320064 X-Patchwork-Delegate: iwamatsu@nigauri.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 13E122C00B0 for ; Fri, 14 Feb 2014 01:15:57 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 119A44B685; Thu, 13 Feb 2014 15:15:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1CTPdbOFq5So; Thu, 13 Feb 2014 15:15:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AEB854B66C; Thu, 13 Feb 2014 15:15:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6892B4B5D0 for ; Thu, 13 Feb 2014 15:14:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xII25sMlNo1y for ; Thu, 13 Feb 2014 15:14:45 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail1.asahi-net.or.jp (mail1.asahi-net.or.jp [202.224.39.197]) by theia.denx.de (Postfix) with ESMTP id 3A13C4B5D2 for ; Thu, 13 Feb 2014 15:14:30 +0100 (CET) Received: from sa76r4 (y081184.ppp.asahi-net.or.jp [118.243.81.184]) by mail1.asahi-net.or.jp (Postfix) with ESMTP id 556C493F5C; Thu, 13 Feb 2014 23:14:29 +0900 (JST) Received: by sa76r4 (Postfix, from userid 1000) id 45039486A; Thu, 13 Feb 2014 23:14:29 +0900 (JST) From: Yoshinori Sato To: u-boot@lists.denx.de Date: Thu, 13 Feb 2014 23:13:43 +0900 Message-Id: <1392300825-18782-5-git-send-email-ysato@users.sourceforge.jp> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1392300825-18782-1-git-send-email-ysato@users.sourceforge.jp> References: <1392300825-18782-1-git-send-email-ysato@users.sourceforge.jp> Cc: Yoshinori Sato Subject: [U-Boot] [PATCH v2 4/6] SH2A cache support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Yoshinori Sato --- arch/sh/cpu/sh2/Makefile | 6 ++ arch/sh/cpu/sh2/cache-sh2a.c | 145 ++++++++++++++++++++++++++++++++++++++++++ arch/sh/cpu/sh2/cpu.c | 31 --------- arch/sh/cpu/sh2/nocache.c | 36 +++++++++++ arch/sh/include/asm/cpu_sh2.h | 10 --- 5 files changed, 187 insertions(+), 41 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 # Copyright (C) 2008 Renesas Solutions Corp. +# Copyright (C) 2013 Yoshinori Sato # # 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..ae59797 --- /dev/null +++ b/arch/sh/cpu/sh2/cache-sh2a.c @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 Yoshinori Sato + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +/* + * 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..29a8858 --- /dev/null +++ b/arch/sh/cpu/sh2/nocache.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2013 Yoshinori Sato + * + * 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 ca7b630..b84dad4 100644 --- a/arch/sh/include/asm/cpu_sh2.h +++ b/arch/sh/include/asm/cpu_sh2.h @@ -8,16 +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 #elif defined(CONFIG_CPU_SH7206)