From patchwork Thu Mar 9 19:00:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9614061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D37E660417 for ; Thu, 9 Mar 2017 19:03:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFF7B223A6 for ; Thu, 9 Mar 2017 19:03:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C28B52866F; Thu, 9 Mar 2017 19:03:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6F4BD223A6 for ; Thu, 9 Mar 2017 19:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ueM1An/CmpJndQA3en5203RdoG30Rg19+HKo2aqMNtg=; b=HdFp6EZNBRTEmaCetNEjy5TYG+ 1GCXwV1TPd7SPH0C1SVlsrOwyl1ZpfOnwfDD04KELpXeyXTOyI6KXQzgXIy+nwWvpVGfBVbzspSdh f5aNeucvIzI2BKnyy7+os18ByouJ2LY3Z7wwTmNfPL/rPwLd5Ehfm7ZGCUB67nrYfu6QwzM/EBFbZ 5nqc6EZGzyZJSq8wJgopjYEewvJ0a1J06SHDgDo1Ay93+c8IZqKbQCx640MI6d4c7G1qHgexF+nE3 nMgJNitKH6OzoTxqaP23mh26n5ALrfI300Se6E1x+xDl1nmGPn/sAPC0QMgOFYJTJBIeHVGbmusMI +66+yb6g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cm3Ld-0000GD-Sy; Thu, 09 Mar 2017 19:03:37 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cm3Jt-0007f4-ME for linux-arm-kernel@lists.infradead.org; Thu, 09 Mar 2017 19:01:52 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4DCB6609C1; Thu, 9 Mar 2017 19:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489086091; bh=RqbEwwXUzo/VpgXZFXH9MXGVbJFgH9mnnHiGD6oYQCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJBbSHWEy8tcqAkIANhauyGVEYYGc2mLyInvMCAFX+JtdvNMc1WBTEQwQVXeRAXhv x5evC6jhAaWqs7eACO1RtkwyaCJtUlSL8RXY3pkxvDmcyo1DUZ2z7VFWvsZToG+S3X BV+HvYdm2ZkVzayyFeSjB1NcOprudXMhVts6ZLzI= Received: from blr-ubuntu-32.ap.qualcomm.com (unknown [202.46.23.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 41BBC60884; Thu, 9 Mar 2017 19:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1489086090; bh=RqbEwwXUzo/VpgXZFXH9MXGVbJFgH9mnnHiGD6oYQCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o6U7wuAIEKYyHME8+ch64QpuvOub8haMxDFgfDgHK0H3aE/r/9U0MEWRIR3/byuNU RGEHxbccBNKX/67yETW9MRSmspypd3gc1yTMjNjErDWegbm/NlEwoLhdKWkwQXGRE1 fGusaaZkKW8av4039cleF4kXZxBXJiD185inq9CI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 41BBC60884 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sricharan@codeaurora.org From: Sricharan R To: robin.murphy@arm.com, will.deacon@arm.com, joro@8bytes.org, lorenzo.pieralisi@arm.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, m.szyprowski@samsung.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, tn@semihalf.com, hanjun.guo@linaro.org, okaya@codeaurora.org Subject: [PATCH V9 03/11] of: dma: Move range size workaround to of_dma_get_range() Date: Fri, 10 Mar 2017 00:30:53 +0530 Message-Id: <1489086061-9356-4-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1489086061-9356-1-git-send-email-sricharan@codeaurora.org> References: <1489086061-9356-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170309_110149_776788_0706B8CE X-CRM114-Status: GOOD ( 15.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sricharan@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Laurent Pinchart Invalid dma-ranges values should be worked around when retrieving the DMA range in of_dma_get_range(), not by all callers of the function. This isn't much of a problem now that we have a single caller, but that situation will change when moving DMA configuration to device probe time. Tested-by: Marek Szyprowski Signed-off-by: Laurent Pinchart --- drivers/of/address.c | 20 ++++++++++++++++++-- drivers/of/device.c | 15 --------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 02b2903..6aeb816 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -819,8 +819,8 @@ void __iomem *of_io_request_and_map(struct device_node *np, int index, * CPU addr (phys_addr_t) : pna cells * size : nsize cells * - * It returns -ENODEV if "dma-ranges" property was not found - * for this device in DT. + * Return 0 on success, -ENODEV if the "dma-ranges" property was not found for + * this device in DT, or -EINVAL if the CPU address or size is invalid. */ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size) { @@ -880,6 +880,22 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz *dma_addr = dmaaddr; *size = of_read_number(ranges + naddr + pna, nsize); + /* + * DT nodes sometimes incorrectly set the size as a mask. Work around + * those incorrect DT by computing the size as mask + 1. + */ + if (*size & 1) { + pr_warn("%s: size 0x%llx for dma-range in node(%s) set as mask\n", + __func__, *size, np->full_name); + *size = *size + 1; + } + + if (!*size) { + pr_err("%s: invalid size zero for dma-range in node(%s)\n", + __func__, np->full_name); + ret = -EINVAL; + goto out; + } pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", *dma_addr, *paddr, *size); diff --git a/drivers/of/device.c b/drivers/of/device.c index b1e6beb..09dedd0 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -110,21 +110,6 @@ void of_dma_configure(struct device *dev, struct device_node *np) size = dev->coherent_dma_mask + 1; } else { offset = PFN_DOWN(paddr - dma_addr); - - /* - * Add a work around to treat the size as mask + 1 in case - * it is defined in DT as a mask. - */ - if (size & 1) { - dev_warn(dev, "Invalid size 0x%llx for dma-range\n", - size); - size = size + 1; - } - - if (!size) { - dev_err(dev, "Adjusted size 0x%llx invalid\n", size); - return; - } dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); }