Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753792AbbFJCjQ (ORCPT ); Tue, 9 Jun 2015 22:39:16 -0400 Received: from mail-bn1on0132.outbound.protection.outlook.com ([157.56.110.132]:48424 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752616AbbFJCjG (ORCPT ); Tue, 9 Jun 2015 22:39:06 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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 v4] powerpc/cache: add cache flush operation for various e500 Date: Wed, 10 Jun 2015 10:20:22 +0800 Message-ID: <1433902822-17784-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;BY2FFO11FD045;1:+lPLqfX7lyENaoncOqlBAHjHf1TJ0bwq1uzJJHxljIT3xfTXF8yZnatuLpmoeWmKyHuR8uWF7dhmp7O8YEDri0owNTPj4rCmdARrcxvkj5wVZD/918iSwzHouc1JxGCGsdwmB6za1Lmd3hSzzticfmWtpnM6UWrRuiafCh5D2td5SIkEjH1aHL0t9eSSE+dsEScf4HSm0Ow68cY06wS2x3HT/4D+xTwAbUU+cvnUQ++jLQaCl/djNYGMZplqEdOaEHgQ4SWJOfGHtFJys760edjFI2cysLU0Xlrx6Tt8BshpPIFP7Zj3O2NH9Uw0uUv4ODHMmre6xzWIysaQeBWgEg== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(199003)(189002)(106466001)(86362001)(189998001)(92566002)(19580395003)(50986999)(6806004)(19580405001)(48376002)(105606002)(50466002)(50226001)(110136002)(36756003)(87936001)(77156002)(5001920100001)(2351001)(77096005)(5001960100002)(229853001)(46102003)(85426001)(2371004)(86152002)(47776003)(104016003)(4001450100001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR03MB386;H:tx30smr01.am.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;BL2PR03MB386;2:URcHdPIsce2oCpm0q+iHl1RXOLYO5dfDQ6gN/Yhr4kENb1JI7hEXUN2hxSz6fHzK;2:YNWhpp4YLFfWO9IqHpOiyTMe1xr+mLhQ3zYTdPO6UEro5T3nO9yWJF6J4L3fFn2luZaWoLCRSd2DiQFjgcKvNjrO2ZnfIiEF6CvzyfO/Ct3thJ4EAqlGyz4xnU+fWb8t6uuf7wvMsCybyVfZBUfyh4QRlicge4jH6e4+GtcLVzyrMZbetWt9MumpDBDMGuVllRJ7DdzlgVdT/bJidhc9lAiyTT3TXQfMLcfIySIs9vI=;6:KwJR0IeLTppTjNmrgCi1/Eu50mV526iMwds6j/CxV0AC++BiP4b7bQB1TzPCT1FHctfK9n/IoqFl9VFxJ9+pMM/A23qKtweeoIbRxFxzfb59jmsxkclxAjti58MMHcsfqhBtxX+mpa5bkcwiXup8SdbLTtYUA4W17b22HtP0R3Z58W3Xy+r5l/zDSlHCNdwI9epNK0jEoPZ1zY7rrBb8a0nD4uFia4wiVrEKp8NWO1vlNgaQ/T9oBz98VZXTNoosyJw+epwlB3iSvxr4Tp7hoAac2JhM3aepLq5eKFSpi80AQ7XKKEABbVXZBwNokKvCjjfjy6IzzDa9b6ctqazWUw==;3:aAJ3ubBjmihGXbSTLkwi/XP0v7Ap7xLZ/JbqNXtB++NUYPXfXRTkAaC93GdciBjjh0ShT2xZEtojpS3eoi3MCZgZDivSdd7rsSOaBFDqK59bw0cK+CyaAQMG6FRxCaAdkpMjr7VRGub3GuQmqBB5HxiKDec82Ou6L2GqFKd3Df+ii387MNqArWEck5W1bMBbLGxmce+Afv+5UgnmeATX1XpZiDHZ63URclneIcyJ9pL7pzXNhiP0C6BQBU8W3GD3TLuotLTs6GtC6e9R3SsTgPriF8ouOzoTJ9vc33AqedqaR5xOABP8bPOHFA/I4ehs X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB386;UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB177; 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:BL2PR03MB386;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB386; X-Forefront-PRVS: 06036BD506 X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB386;9:5kb7ANElCK/A2Fhv79KCl19yscBODpqXvjG2KSEcu8LccVJUshPHTEJ8B3HTox8f5crvtN/7K3mIj3venXUxV0vWC6VOTtpUOc+Blv0iCZf3EzNLPc881DV9ZgNjVIfsglTuZWlnZTc7eSX9C3stwyRzCos75sok9LIMvj73ixeJVwoIHy0hN5+UG9ll+6NoY4qOYfVwpJyiWusyuOU8zV/Db52R0f90D3UgGSKy3rTUX8RAGWowDA4iUwWS7C8DEJUntaGZPkVcd7RIdgH36PXfejpXJLUvlUpzqa7lEi4mJa5W8I6OGFqz5Rv3BqainUGTKm6UmubuJwTtf8VleT8yjTFSjx1zMllHew2GOQa+u0OmDGijGyIn0CfRrq/TKnjV/v8bNlCPMdLI1Ld28/0gngldRCoYNLOLOdA/7RYcym5/fHjuzZ6uGmmTPi4BtiHpEgrDT70saIAIjMdCMRCj6+ZQUrXZDEHAgWR+mMkguDLvEKNekK3dJA5Hnggr83XA303CUDaqpfdo313zEpZHfiUL0RZb0z2u41XwI//BQbV8gdU1mMNY1HPoA99jnMgU0NkPugcNd2LgePANC9Rht2mItGnWk9ybHkrMLYINobUyHOzZ2gsDUgxonTgSri7HmnzCCli+mmtRxjbEmX7rg+QzKKrfNodwBhxXjQHdxTCOafkXrvuR+Xu/0KqS9wHlBVSe24Hd2qy9goupzuuc+tZepgGwty+BGXIsRJMW3GKK0/0fTkc3y2k9jxAqXotq+rec8pVNn6z4xXZsuzbaK7y2Lfw+5jnwcOVwu1DOEUwxlc30DE7J4/8EDEZ+Bgd/RSbenRcJQIsW0Aq3TgpjGHWR+uPzcs6oy5JJJc8= X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB386;3:f/Dp+eueF0uER5jmwgeD5UiWQUW4iDvAsdWdwJ/ykeFqj6h4wLKsyg46VN7xSEfizZR5rZu1SAZgtXO3fgkCpGSkhWWm/MDk0JAgwVUQF3T9uz/7CNrk3SlXwn4YvDpxWWeAWw08sTvIVov2eWMSpg==;10:VtOoCwI5b6WHyYDybEPZxVIpNN7K9iv0Kkx0DqtvPKb8RRlJO9nnIuGzrgtrMTMLJuAmR2Aqq0cGBWBB4DW6XfXRkazU82czsF6ZrfQUgfI=;6:ZXN4cYQU8uf+HuNmT2sV6JD3z9AfhDMcEx++iHWs5cbCvNXKtZ30m4OMsjjInS2I X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2015 02:24:35.8844 (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.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB386 X-Microsoft-Exchange-Diagnostics: 1;BL2PR03MB177;2:oQTpPiFFOpttPGokrr4xD/z7MMaHQ8TtwRFQ8lMgfenRDwNKAmR8LPBtFcFkKyJc;2:2bpAJfKvRBAVXOWXje3WbKOyp4eFNSLiEXaN7jt1a0Qx+iuaV/TMd2mZNYWL5Z6HZU6F0/kW+maFyRWd6Ivl87uqXHILeamd20HXCpHgRFpxO/yNdRJ73ncZvhnbFgq/2sWu5K1cvqr4eB7sd8xeicNcLBWwPD/lyFASpByjhkxtU9ETRynBZ4GBPnEFjN+pOYPzswcXm13swKcwtqIgFrh9KGla5cuv/rgMOrP77y4=;9:x7t413tl7cDOaNuoDwnlScSXf7BAzS4sL8Jd36VVSsPXLuFfGYoPHUcmEp0oaVpYHoO6GFGqmsHXlbyPwrRtknHVUspWdvMcBC/0zoZv51jIM2NuCb5Za/JkepnzpsuoEDWPSE0oQ4yZ1XXLnepRBg== X-OriginatorOrg: freescale.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9787 Lines: 360 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 --- v4: - line up cpu_down_flush* 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..00fccd7 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/