From patchwork Thu Feb 26 00:20:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 5885961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 40D1DBF440 for ; Thu, 26 Feb 2015 00:23:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40A2C2037F for ; Thu, 26 Feb 2015 00:23:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B07F20304 for ; Thu, 26 Feb 2015 00:23:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQmCO-0007qS-Gp; Thu, 26 Feb 2015 00:21:04 +0000 Received: from mail-ie0-x22e.google.com ([2607:f8b0:4001:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YQmCH-0007jB-WB for linux-arm-kernel@lists.infradead.org; Thu, 26 Feb 2015 00:20:59 +0000 Received: by iecar1 with SMTP id ar1so9764624iec.11 for ; Wed, 25 Feb 2015 16:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=TKI/Qy3EPv26qdoNkkB7yGZK/FNP+serTMvq0vwqXVE=; b=JjE4pKmetQP/co237TdCKf95mIZvVeIqwoHtwZ0qXUqCKWDpQlSDPjdKlslaWcgJpb k403sfHG5vzQ7aIYXqFBCICvEnTyHzCqFPT/Fvecubrq31YOHh/QwOzF6H/hurQGgQ0+ 4M7hd7x9OP5vE35BmXyPDiqXaN21DQ2B6WQyOE8eM+SeSv++qnn2rweeeWS6fkO7zIze spHvh8AILVv/yL9f/hhDRyDrtVAGzz8Xhkr848tMJaQru5zq4KvS3+jFD+EmNZfrUwTf b3pfvoTBZQiaLoMBjWw6NzSK6k7UDdojk2o7RhmLtpvluy/CMTQfV7Os5/I5X7nphIzT hvYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=TKI/Qy3EPv26qdoNkkB7yGZK/FNP+serTMvq0vwqXVE=; b=gp80UYHyxuzHQxJUviFdmHv8LLbvcVAxfN2IelSSxWfHO8Ou8Rjqk6cFRnbfHPDDwD 1+B4KUGjOTSVRsHbNmi/d1oz5rU7QYwmX1v1H94dByedhE5R2tAW2lTWYkZ2sazV3oLu qP3U90SySdVcBRQJakRIQ45VtSPH9h1RcByfzkJU6bOCcrgKqeevF5IaE511tzH+XGjY g1uRm3FDYQpnJndZls0f4repyYLh0ao0cFekuj4wqtzC95txSnHMS6WcGxWXLAifuWUX 2oVaMXPfIqy+wSqGd2i2t1PdVd3H8Fajw+NOwaf5ccPd59F1b+pkVmpf8zpV2lAAVuhX 5x0A== X-Gm-Message-State: ALoCoQnARpqozOA9LxJKtoGUIbSe61+ACTqT7jbeF2App1k31Yggn/Xmfaa4rO+698EijwxQzZ17 X-Received: by 10.50.225.72 with SMTP id ri8mr8445265igc.48.1424910036447; Wed, 25 Feb 2015 16:20:36 -0800 (PST) Received: from google.com ([2620:0:1000:3204:9b9:b8dc:b10:7718]) by mx.google.com with ESMTPSA id f142sm11716176ioe.3.2015.02.25.16.20.35 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 16:20:35 -0800 (PST) Date: Wed, 25 Feb 2015 18:20:33 -0600 From: Bjorn Helgaas To: Murali Karicheri Subject: Re: [PATCH v1] of: calculate masks of the device based on dma-range size Message-ID: <20150226002033.GR6220@google.com> References: <1423677215-28968-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1423677215-28968-1-git-send-email-m-karicheri2@ti.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150225_162058_112132_D9CFD160 X-CRM114-Status: GOOD ( 18.63 ) X-Spam-Score: 2.3 (++) Cc: devicetree@vger.kernel.org, Russell King , Arnd Bergmann , linux-pci@vger.kernel.org, Joerg Roedel , Will Deacon , linux-kernel@vger.kernel.org, Rob Herring , Suravee Suthikulpanit , Catalin Marinas , Grant Likely , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FSL_HELO_FAKE, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP [+cc Catalin] On Wed, Feb 11, 2015 at 12:53:35PM -0500, Murali Karicheri wrote: > This patch update of_dma_configure() API to calculate the > masks (dma_mask and coherent_dma_mask) based on the dma-range > values set in DT for the device. Also limit the mask to lower > of the default mask and mask calculated. > > Cc: Joerg Roedel > Cc: Grant Likely > Cc: Rob Herring > Cc: Bjorn Helgaas > Cc: Will Deacon > Cc: Russell King > Cc: Arnd Bergmann > Cc: Suravee Suthikulpanit > > Signed-off-by: Murali Karicheri Applied with Catalin's reviewed-by to pci/iommu for v4.1, thanks! I agree with Catalin's comment about the "size = 1ULL << 32" line. I don't see how that will make a difference, so I dropped it. The patch I merged is below. Let me know if you think we do need that line or any other tweaks. Bjorn commit a5a1dd69080dfcf53bfd6e179f3db68e824aeaae Author: Murali Karicheri Date: Wed Feb 25 17:21:04 2015 -0600 of: Calculate device DMA masks based on DT dma-range size Calculate the dma_mask and coherent_dma_mask based on the dma-range values set in DT for the device. Limit the mask to lower of the default mask and mask calculated. Signed-off-by: Murali Karicheri Signed-off-by: Bjorn Helgaas Reviewed-by: Catalin Marinas CC: Joerg Roedel CC: Grant Likely CC: Rob Herring CC: Will Deacon CC: Russell King CC: Arnd Bergmann CC: Suravee Suthikulpanit diff --git a/drivers/of/device.c b/drivers/of/device.c index 28e743888402..20c1332a0018 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -90,10 +90,11 @@ void of_dma_configure(struct device *dev, struct device_node *np) struct iommu_ops *iommu; /* - * Set default dma-mask to 32 bit. Drivers are expected to setup - * the correct supported dma_mask. + * Set default coherent_dma_mask to 32 bit. Drivers are expected to + * setup the correct supported mask. */ - dev->coherent_dma_mask = DMA_BIT_MASK(32); + if (!dev->coherent_dma_mask) + dev->coherent_dma_mask = DMA_BIT_MASK(32); /* * Set it to coherent_dma_mask by default if the architecture @@ -128,6 +129,15 @@ void of_dma_configure(struct device *dev, struct device_node *np) dev->dma_pfn_offset = offset; + /* + * Limit coherent and dma mask based on size and default mask + * set by the driver. + */ + dev->coherent_dma_mask = min(dev->coherent_dma_mask, + DMA_BIT_MASK(ilog2(dma_addr + size))); + *dev->dma_mask = min((*dev->dma_mask), + DMA_BIT_MASK(ilog2(dma_addr + size))); + coherent = of_dma_is_coherent(np); dev_dbg(dev, "device is%sdma coherent\n", coherent ? " " : " not ");