Received: from milmhbs1.lsil.com (147.145.21.209) by coscas01.lsi.com
 (172.21.36.60) with Microsoft SMTP Server id 8.1.393.1; Sun, 28 Feb 2010
 08:37:03 -0700
Received: from mail2.lsil.com (mail2.lsil.com [147.145.40.22])	by
 milmhbs1.lsil.com (8.12.11/8.12.11) with ESMTP id o1SFb2lI000786	for
 <andy.sharp@lsi.com>; Sun, 28 Feb 2010 07:37:02 -0800
Received: from psmtp.com (na3sys009amx242.postini.com [74.125.149.126])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id o1SFW1Ef014490	for
 <andy.sharp@lsi.com>; Sun, 28 Feb 2010 07:32:01 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx242.postini.com
 ([74.125.148.14]) with SMTP;	Sun, 28 Feb 2010 15:37:01 GMT
Received: from localhost.localdomain ([127.0.0.1]:60829 "EHLO
        eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL)        by
 eddie.linux-mips.org with ESMTP id S1492228Ab0B1PhA (ORCPT
        <rfc822;andy.sharp@lsi.com>); Sun, 28 Feb 2010 16:37:00 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Sun, 28 Feb 2010 16:36:41
 +0100 (CET)
Received: from Chamillionaire.breakpoint.cc ([85.10.199.196]:33636 "EHLO
        Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK)        by
 eddie.linux-mips.org with ESMTP id S1492171Ab0B1Pfs (ORCPT
        <rfc822;linux-mips@linux-mips.org>); Sun, 28 Feb 2010 16:35:48 +0100
Received: id: bigeasy by Chamillionaire.breakpoint.cc authenticated by bigeasy
 with local        (easymta 1.00 BETA 1)        id 1NllBJ-0004MD-Fl; Sun, 28
 Feb 2010 16:35:45 +0100
From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
To: Ralf Baechle <ralf@linux-mips.org>
CC: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>, "David S. Miller"
	<davem@davemloft.net>, "linux-ide@vger.kernel.org"
	<linux-ide@vger.kernel.org>, Sebastian Andrzej Siewior
	<sebastian@breakpoint.cc>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Sun, 28 Feb 2010 08:35:41 -0700
Subject: [PATCH 3/3] ide: move dcache flushing to generic ide code
Thread-Topic: [PATCH 3/3] ide: move dcache flushing to generic ide code
Thread-Index: Acq4i+AzjT3IOmtLSxK+YPoHiRaxIQ==
Message-ID: <1267371341-16684-4-git-send-email-sebastian@breakpoint.cc>
References: <1267371341-16684-1-git-send-email-sebastian@breakpoint.cc>
In-Reply-To: <1267371341-16684-1-git-send-email-sebastian@breakpoint.cc>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: coscas01.lsi.com
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-scanned-by: MIMEDefang 2.39
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:83.13216/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-pstn-settings: 3 (1.0000:1.0000) s cv gt3 gt2 gt1 r p m c 
x-pstn-addresses: from <sebastian@breakpoint.cc> [22/1] 
x-pstn-neptune: 0/0/0.00/0
x-list: linux-mips
x-original-sender: sebastian@breakpoint.cc
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

the pio callbacks are called with different kind of buffers. It could be
a straight kernel addr, kernel stack or a kmaped highmem page.
Some of this break the virt_to_page() assumptions.
This patch moves the dcache flush from architecture code into generic
ide code. ide_pio_bytes() is the only place where user pages might be
written as far as I can see.
The dcache flush is avoided in two cases:
- data which is written to the device (i.e. they are comming from the
  userland)
- pages without a mapping. Those requests should be issued by
  vfs and not go to the userland.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 arch/mips/include/asm/mach-generic/ide.h |   21 ---------------------
 arch/sparc/include/asm/ide.h             |   14 --------------
 drivers/ide/ide-taskfile.c               |    7 +++++++
 3 files changed, 7 insertions(+), 35 deletions(-)

diff --git a/arch/mips/include/asm/mach-generic/ide.h b/arch/mips/include/a=
sm/mach-generic/ide.h
index 9360586..7370845 100644
--- a/arch/mips/include/asm/mach-generic/ide.h
+++ b/arch/mips/include/asm/mach-generic/ide.h
@@ -20,35 +20,16 @@
 #include <asm/processor.h>
=20
 /* MIPS port and memory-mapped I/O string operations.  */
-static inline void __ide_set_pages_dirty(const void *addr, unsigned long s=
ize)
-{
-	unsigned long end =3D (unsigned long)addr + size;
-
-	if (!(cpu_has_dc_aliases || !cpu_has_ic_fills_f_dc))
-		return;
-
-	while ((unsigned long)addr < end) {
-		struct page *p =3D virt_to_page(addr);
-		struct address_space *mapping =3D page_mapping(p);
-
-		if (mapping && mapping_mapped(mapping))
-			SetPageDcacheDirty(p);
-		addr +=3D PAGE_SIZE;
-	}
-}
-
 static inline void __ide_insw(unsigned long port, void *addr,
 	unsigned int count)
 {
 	insw(port, addr, count);
-	__ide_set_pages_dirty(addr, count * 2);
 }
=20
 static inline void __ide_insl(unsigned long port, void *addr,
 	unsigned int count)
 {
 	insl(port, addr, count);
-	__ide_set_pages_dirty(addr, count * 4);
 }
=20
 static inline void __ide_outsw(unsigned long port, const void *addr,
@@ -66,13 +47,11 @@ static inline void __ide_outsl(unsigned long port, cons=
t void *addr,
 static inline void __ide_mm_insw(void __iomem *port, void *addr, u32 count=
)
 {
 	readsw(port, addr, count);
-	__ide_set_pages_dirty(addr, count * 2);
 }
=20
 static inline void __ide_mm_insl(void __iomem *port, void *addr, u32 count=
)
 {
 	readsl(port, addr, count);
-	__ide_set_pages_dirty(addr, count * 4);
 }
=20
 static inline void __ide_mm_outsw(void __iomem *port, void *addr, u32 coun=
t)
diff --git a/arch/sparc/include/asm/ide.h b/arch/sparc/include/asm/ide.h
index b7af3d6..c1037ca 100644
--- a/arch/sparc/include/asm/ide.h
+++ b/arch/sparc/include/asm/ide.h
@@ -34,9 +34,6 @@
=20
 static inline void __ide_insw(void __iomem *port, void *dst, u32 count)
 {
-#if defined(CONFIG_SPARC64) && defined(DCACHE_ALIASING_POSSIBLE)
-	unsigned long end =3D (unsigned long)dst + (count << 1);
-#endif
 	u16 *ps =3D dst;
 	u32 *pi;
=20
@@ -56,17 +53,10 @@ static inline void __ide_insw(void __iomem *port, void =
*dst, u32 count)
 	ps =3D (u16 *)pi;
 	if(count)
 		*ps++ =3D __raw_readw(port);
-
-#if defined(CONFIG_SPARC64) && defined(DCACHE_ALIASING_POSSIBLE)
-	__flush_dcache_range((unsigned long)dst, end);
-#endif
 }
=20
 static inline void __ide_outsw(void __iomem *port, const void *src, u32 co=
unt)
 {
-#if defined(CONFIG_SPARC64) && defined(DCACHE_ALIASING_POSSIBLE)
-	unsigned long end =3D (unsigned long)src + (count << 1);
-#endif
 	const u16 *ps =3D src;
 	const u32 *pi;
=20
@@ -86,10 +76,6 @@ static inline void __ide_outsw(void __iomem *port, const=
 void *src, u32 count)
 	ps =3D (const u16 *)pi;
 	if(count)
 		__raw_writew(*ps, port);
-
-#if defined(CONFIG_SPARC64) && defined(DCACHE_ALIASING_POSSIBLE)
-	__flush_dcache_range((unsigned long)src, end);
-#endif
 }
=20
 #endif /* __KERNEL__ */
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index cc8633c..95a9922 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -273,6 +273,13 @@ void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd =
*cmd,
 		if (page_is_high)
 			local_irq_restore(flags);
=20
+		if (!write) {
+			struct address_space *mapping =3D page_mapping(page);
+
+			if (mapping && mapping_mapped(mapping))
+				flush_dcache_page(page);
+		}
+
 		len -=3D nr_bytes;
 	}
 }
--=20
1.6.6


