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; Wed, 25 Nov 2009
 13:01:37 -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 nAPK1brJ003098	for
 <andy.sharp@lsi.com>; Wed, 25 Nov 2009 12:01:37 -0800
Received: from psmtp.com (na3sys009amx218.postini.com [74.125.149.58])	by
 mail2.lsil.com (8.12.11/8.12.11) with SMTP id nAPJvRPH006032	for
 <andy.sharp@lsi.com>; Wed, 25 Nov 2009 11:57:32 -0800 (PST)
Received: from source ([78.24.191.182]) by na3sys009amx218.postini.com
 ([74.125.148.14]) with SMTP;	Wed, 25 Nov 2009 12:01:36 PST
Received: from localhost.localdomain ([127.0.0.1]:47064 "EHLO
        eddie.linux-mips.org" rhost-flags-OK-OK-OK-FAIL)        by
 eddie.linux-mips.org with ESMTP id S1493439AbZKYUBQ (ORCPT
        <rfc822;andy.sharp@lsi.com>); Wed, 25 Nov 2009 21:01:16 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Wed, 25 Nov 2009 21:00:58
 +0100 (CET)
Received: from sj-iport-5.cisco.com ([171.68.10.87]:11617 "EHLO
        sj-iport-5.cisco.com" rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org
        with ESMTP id S1493432AbZKYUAc (ORCPT
        <rfc822;linux-mips@linux-mips.org>); Wed, 25 Nov 2009 21:00:32 +0100
Received: from sj-core-4.cisco.com ([171.68.223.138])  by sj-iport-5.cisco.com
 with ESMTP; 25 Nov 2009 20:00:27 +0000
Received: from dvomlehn-lnx2.corp.sa.net ([64.101.20.155])        by
 sj-core-4.cisco.com (8.13.8/8.14.3) with ESMTP id nAPK0RQQ023593;        Wed,
 25 Nov 2009 20:00:27 GMT
From: David VomLehn <dvomlehn@cisco.com>
To: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
CC: "ralf@linux-mips.org" <ralf@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Wed, 25 Nov 2009 13:00:28 -0700
Subject: [PATCH 2/2] Set of fixes for DMA when dma_addr_t != physical
        address
Thread-Topic: [PATCH 2/2] Set of fixes for DMA when dma_addr_t != physical
        address
Thread-Index: AcpuChinO5ZxuzYCR/C2naN3gyXyOw==
Message-ID: <20091125200027.GA13748@dvomlehn-lnx2.corp.sa.net>
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:89.22748/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 <dvomlehn@cisco.com> [22/1] 
x-pstn-neptune: 1/1/1.00/82
user-agent: Mutt/1.5.18 (2008-05-17)
authentication-results: sj-iport-5.cisco.com; dkim=neutral (message not
 signed) header.i=none
x-ironport-anti-spam-filtered: true
x-ironport-anti-spam-result: ApoEAAccDUurRN+K/2dsb2JhbAC+GZdrhDIEgXE
x-ironport-av: E=Sophos;i="4.47,288,1257120000";
    d="scan'208";a="109641201"
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Fixes for using DMA on systems where the DMA address and the physical addre=
ss
differ.

Signed-off-by: Dezhong Diao <dediao@cisco.com>
Signed-off-by: David VomLehn <dvomlehn@cisco.com>
---
 arch/mips/mm/dma-default.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 414d7ff..eaa7fb4 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -24,8 +24,11 @@ static inline unsigned long dma_addr_to_virt(struct devi=
ce *dev,
 	dma_addr_t dma_addr)
 {
 	unsigned long addr =3D plat_dma_addr_to_phys(dev, dma_addr);
+	unsigned int offset =3D (dma_addr & ~PAGE_MASK);
+	struct page *pg;
=20
-	return (unsigned long)phys_to_virt(addr);
+	pg =3D pfn_to_page(addr >> PAGE_SHIFT);
+	return (unsigned long)(page_address(pg) + offset);
 }
=20
 /*
@@ -136,7 +139,6 @@ EXPORT_SYMBOL(dma_free_coherent);
 static inline void __dma_sync(unsigned long addr, size_t size,
 	enum dma_data_direction direction)
 {
-
 	BUG_ON(addr < KSEG0);
=20
 	switch (direction) {
@@ -197,8 +199,8 @@ int dma_map_sg(struct device *dev, struct scatterlist *=
sg, int nents,
 		addr =3D (unsigned long) sg_virt(sg);
 		if (!plat_device_is_coherent(dev) && (addr >=3D KSEG0))
 			__dma_sync(addr, sg->length, direction);
-
-		sg->dma_address =3D sg_phys(sg);
+		sg->dma_address =3D plat_map_dma_mem_page(dev, sg_page(sg)) +
+			sg->offset;
 	}
=20
 	return nents;
@@ -253,7 +255,8 @@ void dma_sync_single_for_cpu(struct device *dev, dma_ad=
dr_t dma_handle,
 		unsigned long addr;
=20
 		addr =3D dma_addr_to_virt(dev, dma_handle);
-		__dma_sync(addr, size, direction);
+		if (addr >=3D KSEG0)
+			__dma_sync(addr, size, direction);
 	}
 }
=20
@@ -269,7 +272,8 @@ void dma_sync_single_for_device(struct device *dev, dma=
_addr_t dma_handle,
 		unsigned long addr;
=20
 		addr =3D dma_addr_to_virt(dev, dma_handle);
-		__dma_sync(addr, size, direction);
+		if (addr >=3D KSEG0)
+			__dma_sync(addr, size, direction);
 	}
 }
=20
@@ -284,7 +288,8 @@ void dma_sync_single_range_for_cpu(struct device *dev, =
dma_addr_t dma_handle,
 		unsigned long addr;
=20
 		addr =3D dma_addr_to_virt(dev, dma_handle);
-		__dma_sync(addr + offset, size, direction);
+		if (addr >=3D KSEG0)
+			__dma_sync(addr + offset, size, direction);
 	}
 }
=20
@@ -300,7 +305,8 @@ void dma_sync_single_range_for_device(struct device *de=
v, dma_addr_t dma_handle,
 		unsigned long addr;
=20
 		addr =3D dma_addr_to_virt(dev, dma_handle);
-		__dma_sync(addr + offset, size, direction);
+		if (addr >=3D KSEG0)
+			__dma_sync(addr + offset, size, direction);
 	}
 }
=20

