Tue May 14 14:11:43 2013 UTC ()
Don't call sh4_icache_sync_all() before sh_cache_ops is initialized.
Instead, use SH4_EMODE_CACHE_FLUSH() or SH4_CACHE_FLUSH() macro to
invalidate cache before initializing CCR.
This seems to suppress random file system corruption on wd(4) at acardide(4)
(which uses bus-master DMA and calls many cache flush ops) during pkgsrc
packages builds on landisk.


(tsutsui)
diff -r1.23 -r1.24 src/sys/arch/sh3/sh3/cache_sh4.c

cvs diff -r1.23 -r1.24 src/sys/arch/sh3/sh3/cache_sh4.c (expand / switch to unified diff)

--- src/sys/arch/sh3/sh3/cache_sh4.c 2012/12/12 16:24:49 1.23
+++ src/sys/arch/sh3/sh3/cache_sh4.c 2013/05/14 14:11:43 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cache_sh4.c,v 1.23 2012/12/12 16:24:49 tsutsui Exp $ */ 1/* $NetBSD: cache_sh4.c,v 1.24 2013/05/14 14:11:43 tsutsui Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi. 8 * by UCHIYAMA Yasushi.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: cache_sh4.c,v 1.23 2012/12/12 16:24:49 tsutsui Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: cache_sh4.c,v 1.24 2013/05/14 14:11:43 tsutsui Exp $");
34 34
35#include "opt_cache.h" 35#include "opt_cache.h"
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39 39
40#include <sh3/cache.h> 40#include <sh3/cache.h>
41#include <sh3/cache_sh4.h> 41#include <sh3/cache_sh4.h>
42#include <sh3/vmparam.h> 42#include <sh3/vmparam.h>
43 43
44#define round_line(x) (((x) + 31) & ~31) 44#define round_line(x) (((x) + 31) & ~31)
45#define trunc_line(x) ((x) & ~31) 45#define trunc_line(x) ((x) & ~31)
46 46
@@ -108,28 +108,31 @@ sh4_cache_config(void) @@ -108,28 +108,31 @@ sh4_cache_config(void)
108#if defined(SH4_CACHE_DISABLE_ICACHE) 108#if defined(SH4_CACHE_DISABLE_ICACHE)
109 r &= ~SH4_CCR_ICE; 109 r &= ~SH4_CCR_ICE;
110#endif 110#endif
111#if defined(SH4_CACHE_DISABLE_DCACHE) 111#if defined(SH4_CACHE_DISABLE_DCACHE)
112 r &= ~SH4_CCR_OCE; 112 r &= ~SH4_CCR_OCE;
113#endif 113#endif
114#if defined(SH4_CACHE_WB_U0_P0_P3) 114#if defined(SH4_CACHE_WB_U0_P0_P3)
115 r &= ~SH4_CCR_WT; 115 r &= ~SH4_CCR_WT;
116#endif 116#endif
117#if defined(SH4_CACHE_WB_P1) 117#if defined(SH4_CACHE_WB_P1)
118 r |= SH4_CCR_CB; 118 r |= SH4_CCR_CB;
119#endif 119#endif
120 120
121 sh4_icache_sync_all(); 
122 RUN_P2; 121 RUN_P2;
 122 if (r & SH4_CCR_EMODE)
 123 SH4_EMODE_CACHE_FLUSH();
 124 else
 125 SH4_CACHE_FLUSH();
123 _reg_write_4(SH4_CCR, SH4_CCR_ICI|SH4_CCR_OCI); 126 _reg_write_4(SH4_CCR, SH4_CCR_ICI|SH4_CCR_OCI);
124 _reg_write_4(SH4_CCR, r); 127 _reg_write_4(SH4_CCR, r);
125 RUN_P1; 128 RUN_P1;
126 129
127 r = _reg_read_4(SH4_CCR); 130 r = _reg_read_4(SH4_CCR);
128 131
129 sh_cache_unified = 0; 132 sh_cache_unified = 0;
130 sh_cache_enable_icache = (r & SH4_CCR_ICE); 133 sh_cache_enable_icache = (r & SH4_CCR_ICE);
131 sh_cache_enable_dcache = (r & SH4_CCR_OCE); 134 sh_cache_enable_dcache = (r & SH4_CCR_OCE);
132 sh_cache_ways = ways; 135 sh_cache_ways = ways;
133 sh_cache_line_size = SH4_CACHE_LINESZ; 136 sh_cache_line_size = SH4_CACHE_LINESZ;
134 sh_cache_alias_mask = (dcache_size / ways - 1) & ~PAGE_MASK; 137 sh_cache_alias_mask = (dcache_size / ways - 1) & ~PAGE_MASK;
135 sh_cache_prefer_mask = (dcache_size / ways - 1); 138 sh_cache_prefer_mask = (dcache_size / ways - 1);