Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752154AbbFIB6K (ORCPT ); Mon, 8 Jun 2015 21:58:10 -0400 Received: from mail-bn1on0119.outbound.protection.outlook.com ([157.56.110.119]:2011 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752984AbbFIB6D (ORCPT ); Mon, 8 Jun 2015 21:58:03 -0400 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; feescale.com; dkim=none (message not signed) header.d=none; From: To: CC: , , "Tang Yuantian" , Chenhui Zhao , Tang Yuantian Subject: [PATCH v3] powerpc/cache: add cache flush operation for various e500 Date: Tue, 9 Jun 2015 09:53:47 +0800 Message-ID: <1433814827-10431-1-git-send-email-Yuantian.Tang@freescale.com> X-Mailer: git-send-email 2.1.0.27.g96db324 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD051;1:CUr+xeYlMRNiYnnCKSeZW7L3mc1q4IDzRfnJ44/3+SRbv4DtKvevawWnNkjL98QeY9fgieVF3//SrFmXCSFRiisuaL9OIjWnsyDE8hObqHzirA4nIEPcmu9u4jxO3+Fo0tszfbvzOsFFW40AAogkkiGgdqrJ8aWSceB01PL4cf8yAuWIiodh2JTBmuH9p3I6zagE7bKTZ/3yJsSe1MLMqlKKKFA2scRxEsqpy9D7rcgAorGySaChmE+KFE14fCOygMXyzcMqX2dugzVFlRVIzzB7QNEX7dcLuRMBcFUXQxE6kL74hN9e8ABGDBiQCb3I/9/IS4KOG+bxIaCq7LTLog== X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(199003)(189002)(229853001)(86152002)(36756003)(50986999)(92566002)(77096005)(86362001)(106466001)(19580405001)(46102003)(48376002)(50466002)(104016003)(6806004)(85426001)(87936001)(50226001)(189998001)(105606002)(47776003)(5001960100002)(77156002)(19580395003)(62966003)(110136002)(2351001)(4001450100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR03MB387;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB387;2:Oz491kWouF27293g6C75va9ETzmfBt8G0NuLeKdNMeflhlBqm0x1ikRsv49kKGCl;2:OWiBuoPcbrEXuyStwL0bX6JKg6UaTti9mpOrw47KrHawFUMbrjOWYsqzNEZpENrTFYzBwPa6kpt7ybPWLQhvCvOzBZgH2NdyHZCF7hNpR9WUp7pLCK26tDDc+cbUeGo6TBHtqnQYYMj0bhYJd9U8/PDZiKIUeteXQsQdoHF+JBrpLFRcn9Q+W9xRRS8dXe6V+4hn83kPhNdYeLck2fO8LEXZ+V+hcqBNcDzDIEtVXU0=;6:o1OGrE//8V8gzANHZ6tY+6bgDFxiJKvuH7rbzdNi/D2WRiauGv92/RV3VWo+jtxQGndy5aKrxnUeDnc8SsBqTbitYXtCKBIzRshTdeemO3a5gTkeaCFK2EPiW3LZ/4+R7xjAQ/RfqSMdyxDyZurk+5t4ulyLzBaqD+07sQVmxVJuh9Frp4yDzWMff/jTrd1H2d0NcIVqypKaG9vete7kkscjeJgHqLLImc8TbECImjEKwoIkyKtp5BEwR1Ssynn5eQsechhqfoq/PsJUNwIE3YsP8Azq2XI+HpYGJ42BuS7OPqZ6QwH65Jxf5cxFmnPpapRk6S+/BlWFlzyWTf/qjQ==;3:vvRSZf6/utPODoc9ZHf/DQi/o7qQS+MkYuHnurlOdkOTUgYbkvypUG6cQ93hhYnQWg9FgSL+WRfjN7HhM3rRUby3rBzFEU4EZUS2hXUtRQHxA/3hCLAafz6oej/vGOb3rELF8QmN+2nZVnZgTK23pompkoHn4HeGHfO42DD3McWUg992DYXanP3bykETcDGj5OThJMsZr76T6hewm2DqVA8P2S9zbn1EYnXy27DVYJkk7fogq7fPqJsBkF2Ti4UNctYPj5oF3aISZznrZymJjH9RRvl9eiIkSs1P9EQhF5f+1VooU+45XBoIDHfc6Hec X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB387; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(520003)(5005006)(3002001);SRVR:BL2PR03MB387;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB387; X-Forefront-PRVS: 06022AA85F X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB387;9:wsBIp9Eti5PoWqGH04uujv/y5WOwpDsMfAH7qLhiRaqj1IIHvYuJ6KxjqnF2ATIaPYwk+FWw0W73AyNUa7ygqpc/niQHT/LcwxpNM10L0D+w+oINx+OJcEk46Wr9AbaQvtnT3pbo9931GGE+R0TWNvjuBtQV3I/Qi4A1wN+Iar1WDD/gKOEHkGQAjYjO91YTorpqN65Ol/i1zFpWReiNfQ6kB36WZFBPtI0K80/KmWkl4U39ysAVfLpIB5IRH0H4Y03AmikvKn4qbicBp4rV/5PoY8gU0MT6bL6gvw6T6Sa9Sc89fu94sEvgNpZtjaRAU9rBHJgr34qCUrgaaqBDYRe6S6BB2i8R+XJOfoDQlfphqGqoulsHaRHy6yr2X4zEyhVO70JImSiplGjvGf7rR95spqoU4gUDs3X40+P9vuaQPJOCRSDPAw+tFddU0fuprfX+fqsWdrwiLUohWDbN9Cf4/3WXE0aCAWNn3J4fizlMzVIxNuLfqhixHifeYcCgRrx7w4OH3yH0cKRVx3IR7MAvln2ctxM4798FkGO984VkY8i5EPE7rl6Z+LirEzh7i1/k2hsx0k1G3/GwVIreTga1v6Hn+YeUs5as6DbNaafdwCUtH0Ox2/44+2foXHTzLX+u8W+1hV8acALIe7RFapo5274to5jmAMWRqnuUYvlX5MIDX5VeFEohpPsoEQmGOS3waafXnLw/XXEUqei7BD15JpsGSJ/M355rAaXEo8MX+efeX2AEXuMo7r4VNdRwlHU5neQ5yA6y7+OIIT6em0Z8ypHeh9+qgxrYQXbMYLF4rTTV8pLMiEZ5sz4fDwt+X69OR32jl50E+xlaFi9opg== X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB387;3:KVw5fEahk5RiUFiKGT9gb7q8q09JWptyNm84UmZRkQ6m0AgluW8mAP5rgxlKVxFmJRwFhHjiIb5sW6NtsnQvLolYJEe+HawpfjTuE5VX7vS5w5HKAyQHHY1EN7VMD2bnVX1YQCEVTO8spynZeeWY5Q==;10:M8WGH+Qz1BkcWdUTc86DJUzQjT+0Ggi02WP1IARERqrUd5/JvtHId9UJYsdFfuk4Urc1Re/UAPd/AMsCwXmp8mU3n+i9ERZbFFZ9Y1NI46I=;6:HWDe9neu0CD+0lfESDdadMHhEE7IgfILNC85seXRKAJAtOnXQ39+2kPaQyevwzaN X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2015 01:58:00.0208 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB387 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9752 Lines: 358 From: Tang Yuantian Various e500 core have different cache architecture, so they need different cache flush operations. Therefore, add a callback function cpu_flush_caches to the struct cpu_spec. The cache flush operation for the specific kind of e500 is selected at init time. The callback function will flush all caches inside the current cpu. Signed-off-by: Chenhui Zhao Signed-off-by: Tang Yuantian --- v3: - change all flush_caches to cpu_down_flush - replace whitespace with tab v2: - remove some function's prefix "__" - remove redundent CONFIG_PPC_E500MC micro arch/powerpc/include/asm/cacheflush.h | 2 - arch/powerpc/include/asm/cputable.h | 11 +++ arch/powerpc/kernel/asm-offsets.c | 3 + arch/powerpc/kernel/cpu_setup_fsl_booke.S | 112 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/cputable.c | 4 ++ arch/powerpc/kernel/head_fsl_booke.S | 74 -------------------- arch/powerpc/platforms/85xx/smp.c | 3 +- 7 files changed, 132 insertions(+), 77 deletions(-) diff --git a/arch/powerpc/include/asm/cacheflush.h b/arch/powerpc/include/asm/cacheflush.h index 30b35ff..729fde4 100644 --- a/arch/powerpc/include/asm/cacheflush.h +++ b/arch/powerpc/include/asm/cacheflush.h @@ -30,8 +30,6 @@ extern void flush_dcache_page(struct page *page); #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) -extern void __flush_disable_L1(void); - extern void flush_icache_range(unsigned long, unsigned long); extern void flush_icache_user_range(struct vm_area_struct *vma, struct page *page, unsigned long addr, diff --git a/arch/powerpc/include/asm/cputable.h b/arch/powerpc/include/asm/cputable.h index 6367b83..0444469 100644 --- a/arch/powerpc/include/asm/cputable.h +++ b/arch/powerpc/include/asm/cputable.h @@ -43,6 +43,13 @@ extern int machine_check_e500(struct pt_regs *regs); extern int machine_check_e200(struct pt_regs *regs); extern int machine_check_47x(struct pt_regs *regs); +#if defined(CONFIG_E500) +extern void cpu_down_flush_e500v2(void); +extern void cpu_down_flush_e500mc(void); +extern void cpu_down_flush_e5500(void); +extern void cpu_down_flush_e6500(void); +#endif + /* NOTE WELL: Update identify_cpu() if fields are added or removed! */ struct cpu_spec { /* CPU is matched via (PVR & pvr_mask) == pvr_value */ @@ -59,6 +66,10 @@ struct cpu_spec { unsigned int icache_bsize; unsigned int dcache_bsize; +#if defined(CONFIG_E500) + /* flush caches inside the current cpu */ + void (*cpu_down_flush)(void); +#endif /* number of performance monitor counters */ unsigned int num_pmcs; enum powerpc_pmc_type pmc_type; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 0034b6b..52efca9 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -373,6 +373,9 @@ int main(void) DEFINE(CPU_SPEC_FEATURES, offsetof(struct cpu_spec, cpu_features)); DEFINE(CPU_SPEC_SETUP, offsetof(struct cpu_spec, cpu_setup)); DEFINE(CPU_SPEC_RESTORE, offsetof(struct cpu_spec, cpu_restore)); +#if defined(CONFIG_E500) + DEFINE(CPU_DOWN_FLUSH, offsetof(struct cpu_spec, cpu_down_flush)); +#endif DEFINE(pbe_address, offsetof(struct pbe, address)); DEFINE(pbe_orig_address, offsetof(struct pbe, orig_address)); diff --git a/arch/powerpc/kernel/cpu_setup_fsl_booke.S b/arch/powerpc/kernel/cpu_setup_fsl_booke.S index dddba3e..462aed9 100644 --- a/arch/powerpc/kernel/cpu_setup_fsl_booke.S +++ b/arch/powerpc/kernel/cpu_setup_fsl_booke.S @@ -13,11 +13,13 @@ * */ +#include #include #include #include #include #include +#include _GLOBAL(__e500_icache_setup) mfspr r0, SPRN_L1CSR1 @@ -233,3 +235,113 @@ _GLOBAL(__setup_cpu_e5500) mtlr r5 blr #endif + +/* flush L1 date cache, it can apply to e500v2, e500mc and e5500 */ +_GLOBAL(flush_dcache_L1) + mfmsr r10 + wrteei 0 + + mfspr r3,SPRN_L1CFG0 + rlwinm r5,r3,9,3 /* Extract cache block size */ + twlgti r5,1 /* Only 32 and 64 byte cache blocks + * are currently defined. + */ + li r4,32 + subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) - + * log2(number of ways) + */ + slw r5,r4,r5 /* r5 = cache block size */ + + rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */ + mulli r7,r7,13 /* An 8-way cache will require 13 + * loads per set. + */ + slw r7,r7,r6 + + /* save off HID0 and set DCFA */ + mfspr r8,SPRN_HID0 + ori r9,r8,HID0_DCFA@l + mtspr SPRN_HID0,r9 + isync + + LOAD_REG_IMMEDIATE(r6, KERNELBASE) + mr r4, r6 + mtctr r7 + +1: lwz r3,0(r4) /* Load... */ + add r4,r4,r5 + bdnz 1b + + msync + mr r4, r6 + mtctr r7 + +1: dcbf 0,r4 /* ...and flush. */ + add r4,r4,r5 + bdnz 1b + + /* restore HID0 */ + mtspr SPRN_HID0,r8 + isync + + wrtee r10 + + blr + +has_L2_cache: + /* skip L2 cache on P2040/P2040E as they have no L2 cache */ + mfspr r3, SPRN_SVR + /* shift right by 8 bits and clear E bit of SVR */ + rlwinm r4, r3, 24, ~0x800 + + lis r3, SVR_P2040@h + ori r3, r3, SVR_P2040@l + cmpw r4, r3 + beq 1f + + li r3, 1 + blr +1: + li r3, 0 + blr + +/* flush backside L2 cache */ +flush_backside_L2_cache: + mflr r10 + bl has_L2_cache + mtlr r10 + cmpwi r3, 0 + beq 2f + + /* Flush the L2 cache */ + mfspr r3, SPRN_L2CSR0 + ori r3, r3, L2CSR0_L2FL@l + msync + isync + mtspr SPRN_L2CSR0,r3 + isync + + /* check if it is complete */ +1: mfspr r3,SPRN_L2CSR0 + andi. r3, r3, L2CSR0_L2FL@l + bne 1b +2: + blr + +_GLOBAL(cpu_down_flush_e500v2) + mflr r0 + bl flush_dcache_L1 + mtlr r0 + blr + +_GLOBAL(cpu_down_flush_e500mc) +_GLOBAL(cpu_down_flush_e5500) + mflr r0 + bl flush_dcache_L1 + bl flush_backside_L2_cache + mtlr r0 + blr + +/* L1 Data Cache of e6500 contains no modified data, no flush is required */ +_GLOBAL(cpu_down_flush_e6500) + blr diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c index 60262fd..8d78e8e 100644 --- a/arch/powerpc/kernel/cputable.c +++ b/arch/powerpc/kernel/cputable.c @@ -2021,6 +2021,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_e500v2, .machine_check = machine_check_e500, .platform = "ppc8548", + .cpu_down_flush = cpu_down_flush_e500v2, }, #else { /* e500mc */ @@ -2040,6 +2041,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .cpu_setup = __setup_cpu_e500mc, .machine_check = machine_check_e500mc, .platform = "ppce500mc", + .cpu_down_flush = cpu_down_flush_e500mc, }, #endif /* CONFIG_PPC_E500MC */ #endif /* CONFIG_PPC32 */ @@ -2064,6 +2066,7 @@ static struct cpu_spec __initdata cpu_specs[] = { #endif .machine_check = machine_check_e500mc, .platform = "ppce5500", + .cpu_down_flush = cpu_down_flush_e5500, }, { /* e6500 */ .pvr_mask = 0xffff0000, @@ -2086,6 +2089,7 @@ static struct cpu_spec __initdata cpu_specs[] = { #endif .machine_check = machine_check_e500mc, .platform = "ppce6500", + .cpu_down_flush = cpu_down_flush_e6500, }, #endif /* CONFIG_PPC_E500MC */ #ifdef CONFIG_PPC32 diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index fffd1f9..709bc50 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -1075,80 +1075,6 @@ _GLOBAL(set_context) isync /* Force context change */ blr -_GLOBAL(flush_dcache_L1) - mfspr r3,SPRN_L1CFG0 - - rlwinm r5,r3,9,3 /* Extract cache block size */ - twlgti r5,1 /* Only 32 and 64 byte cache blocks - * are currently defined. - */ - li r4,32 - subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) - - * log2(number of ways) - */ - slw r5,r4,r5 /* r5 = cache block size */ - - rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */ - mulli r7,r7,13 /* An 8-way cache will require 13 - * loads per set. - */ - slw r7,r7,r6 - - /* save off HID0 and set DCFA */ - mfspr r8,SPRN_HID0 - ori r9,r8,HID0_DCFA@l - mtspr SPRN_HID0,r9 - isync - - lis r4,KERNELBASE@h - mtctr r7 - -1: lwz r3,0(r4) /* Load... */ - add r4,r4,r5 - bdnz 1b - - msync - lis r4,KERNELBASE@h - mtctr r7 - -1: dcbf 0,r4 /* ...and flush. */ - add r4,r4,r5 - bdnz 1b - - /* restore HID0 */ - mtspr SPRN_HID0,r8 - isync - - blr - -/* Flush L1 d-cache, invalidate and disable d-cache and i-cache */ -_GLOBAL(__flush_disable_L1) - mflr r10 - bl flush_dcache_L1 /* Flush L1 d-cache */ - mtlr r10 - - mfspr r4, SPRN_L1CSR0 /* Invalidate and disable d-cache */ - li r5, 2 - rlwimi r4, r5, 0, 3 - - msync - isync - mtspr SPRN_L1CSR0, r4 - isync - -1: mfspr r4, SPRN_L1CSR0 /* Wait for the invalidate to finish */ - andi. r4, r4, 2 - bne 1b - - mfspr r4, SPRN_L1CSR1 /* Invalidate and disable i-cache */ - li r5, 2 - rlwimi r4, r5, 0, 3 - - mtspr SPRN_L1CSR1, r4 - isync - - blr - #ifdef CONFIG_SMP /* When we get here, r24 needs to hold the CPU # */ .globl __secondary_start diff --git a/arch/powerpc/platforms/85xx/smp.c b/arch/powerpc/platforms/85xx/smp.c index 8631ac5..16b366f 100644 --- a/arch/powerpc/platforms/85xx/smp.c +++ b/arch/powerpc/platforms/85xx/smp.c @@ -139,7 +139,8 @@ static void smp_85xx_mach_cpu_die(void) mtspr(SPRN_TCR, 0); - __flush_disable_L1(); + cur_cpu_spec->cpu_down_flush(); + tmp = (mfspr(SPRN_HID0) & ~(HID0_DOZE|HID0_SLEEP)) | HID0_NAP; mtspr(SPRN_HID0, tmp); isync(); -- 2.1.0.27.g96db324 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/