Received: from mail.onstor.com ([66.201.51.107]) by onstor-exch02.onstor.net with Microsoft SMTPSVC(6.0.3790.1830);
	 Thu, 10 Jul 2008 10:56:38 -0700
Received: from chiesmta2-3.messageone.com ([216.203.30.55]) by mail.onstor.com with Microsoft SMTPSVC(6.0.3790.1830);
	 Thu, 10 Jul 2008 10:56:37 -0700
Received: from ftp.linux-mips.org (ftp.linux-mips.org [213.58.128.207])
	by chiesmta2-3.messageone.com (8.13.8/8.13.8) with ESMTP id m6AHuZsd025201
	for <andy.sharp@onstor.com>; Thu, 10 Jul 2008 12:56:37 -0500
Received: from localhost.localdomain ([127.0.0.1]:62949 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP
	id S20022926AbYGJRjC (ORCPT <rfc822;andy.sharp@onstor.com>);
	Thu, 10 Jul 2008 18:39:02 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Thu, 10 Jul 2008 18:38:45 +0100 (BST)
Received: from [66.209.47.173] ([66.209.47.173]:21128 "EHLO mythtv.ewol.com")
	by ftp.linux-mips.org with ESMTP id S20022923AbYGJRin (ORCPT
	<rfc822;linux-mips@linux-mips.org>); Thu, 10 Jul 2008 18:38:43 +0100
Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1])
	by mythtv.ewol.com (8.14.2/8.14.2) with ESMTP id m6AHcP9p027626;
	Thu, 10 Jul 2008 13:38:26 -0400
Message-ID: <48764911.50409@cortland.com>
Date: 	Thu, 10 Jul 2008 13:38:25 -0400
From: Steve Brown <sbrown@cortland.com>
Reply-To: sbrown@cortland.com
User-Agent: Thunderbird 2.0.0.14 (X11/20080501)
MIME-Version: 1.0
To: linux-mips@linux-mips.org
CC: Michael Buesch <mb@bu3sch.de>
Subject: Re: Correct way to set coherent_dma_mask on a non-pci device?
References: <4873A676.8050906@cortland.com> <200807081955.47594.mb@bu3sch.de>
In-Reply-To: <200807081955.47594.mb@bu3sch.de>
Content-Type: multipart/mixed;
 boundary="------------040304090608000708050506"
X-archive-position: 19764
X-ecartis-version: Ecartis v1.0.0
Sender: linux-mips-bounce@linux-mips.org
Errors-to: linux-mips-bounce@linux-mips.org
X-original-sender: sbrown@cortland.com
Precedence: bulk
X-list: 	linux-mips
X-MessageOne-Virus-Version: vendor=fsecure engine=4.65.7161:2.4.4,1.2.40,4.0.164 definitions=2008-07-10_08:2008-07-09,2008-07-10,2008-07-10 signatures=0
X-MessageOne-Virus-Scanned: Clean
X-MessageOne-Envelope-Sender: linux-mips-bounce@linux-mips.org
X-MessageOne-Spam-Details: rule=m773emszm_notspam policy=m773emszm score=0 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=3.1.0-0805090000 definitions=main-0807100094
X-MessageOne-Spam-Score: 0
X-MessageOne-Spam-Bar: 
Return-Path: linux-mips-bounce@linux-mips.org
X-OriginalArrivalTime: 10 Jul 2008 17:56:38.0086 (UTC) FILETIME=[4CD2AE60:01C8E2B6]

This is a multi-part message in MIME format.
--------------040304090608000708050506
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Michael Buesch wrote:
> On Tuesday 08 July 2008 19:40:06 Steve Brown wrote:
>   
>> There appears to be no function like pci_set_consistent_dma_mask to set 
>> the coherent mask for a non-pci device.
>>
>> What is the "proper" way to set it?
>>
>> The context for the question is a recent change to ssb_dma_set_mask() in 
>> drivers/ssb/main.c that removed the somewhat fragile, direct 
>> manipulation of dma_mask and coherent_dma_mask in favor of a call to 
>> dma_set_mask().
>>     
>
> Note that SSB devices use the dma_*** API for doing DMA remappings.
> So it uses dma_set_mask() for setting the mask.
>
>   
I can't find any dma_*** routine that references coherent_dma_mask. It 
looks like dma_set_mask() doesn't handle the case where the device 
doesn't support coherent dma (CONFIG_DMA_NONCOHERENT=y).

Would this be the correct patch to handle that case?
 
Steve


--------------040304090608000708050506
Content-Type: text/plain;
 name="170-dma_set_mask.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="170-dma_set_mask.patch"

diff --git a/include/asm-mips/dma-mapping.h b/include/asm-mips/dma-mapping.h
index 230b3f1..8da4107 100644
--- a/include/asm-mips/dma-mapping.h
+++ b/include/asm-mips/dma-mapping.h
@@ -1,8 +1,9 @@
 #ifndef _ASM_DMA_MAPPING_H
 #define _ASM_DMA_MAPPING_H
 
-#include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include <asm/cache.h>
+#include <dma-coherence.h>
 
 void *dma_alloc_noncoherent(struct device *dev, size_t size,
 			   dma_addr_t *dma_handle, gfp_t flag);
@@ -48,7 +49,11 @@ extern int dma_supported(struct device *dev, u64 mask);
 static inline int
 dma_set_mask(struct device *dev, u64 mask)
 {
-	if(!dev->dma_mask || !dma_supported(dev, mask))
+	if(!dma_supported(dev, mask))
+		return -EIO;
+	if(!plat_device_is_coherent(dev))
+		dev->dma_mask = &dev->coherent_dma_mask;
+	if(!dev->dma_mask)
 		return -EIO;
 
 	*dev->dma_mask = mask;

--------------040304090608000708050506--

