From patchwork Wed Dec 17 18:02:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 5508671 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D011EBEEA8 for ; Wed, 17 Dec 2014 18:05:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E25D6209F9 for ; Wed, 17 Dec 2014 18:05:37 +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 03CB9209EA for ; Wed, 17 Dec 2014 18:05:37 +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 1Y1Iw3-0002lr-LL; Wed, 17 Dec 2014 18:02:55 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Y1Iw0-0002Ol-E6 for linux-arm-kernel@lists.infradead.org; Wed, 17 Dec 2014 18:02:53 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id sBHI2OUU019458; Wed, 17 Dec 2014 12:02:24 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id sBHI2OMl024165; Wed, 17 Dec 2014 12:02:24 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Wed, 17 Dec 2014 12:02:23 -0600 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id sBHI2Mws028069; Wed, 17 Dec 2014 12:02:23 -0600 From: Murali Karicheri To: , , , , , , , Subject: [RFC PATCH 1/2] common: dma-mapping: introduce dma_get_parent_cfg() helper Date: Wed, 17 Dec 2014 13:02:23 -0500 Message-ID: <1418839344-14393-2-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1418839344-14393-1-git-send-email-m-karicheri2@ti.com> References: <1418839344-14393-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141217_100252_594290_66EE1315 X-CRM114-Status: GOOD ( 10.43 ) X-Spam-Score: -5.0 (-----) Cc: Murali Karicheri 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Now, in Kernel, parent device's DMA parameters has to be applied to the child as is - to enable DMA support for the device. Usually this is happened in places where parent device manually instantiates child device such as in drivers/pci/probe.c (pci_device_add() for example). Now DMA configuration is represented in device data structure not only by DMA mask and DMA params, it also includes dma_pfn_offset at least. Hence introduce common dma_get_parent_cfg() helper to apply dma configuration from parent to child, and use __weak to allow arch to override it if needed. Signed-off-by: Murali Karicheri --- drivers/base/dma-mapping.c | 18 ++++++++++++++++++ include/linux/dma-mapping.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 9e8bbdd..5322426 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -339,3 +339,21 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) vunmap(cpu_addr); } #endif + +int __weak dma_get_parent_cfg(struct device *dev, struct device *parent) +{ + struct device *temp = parent; + + if (!temp) + temp = dev->parent; + + if (temp && is_device_dma_capable(temp)) { + dev->dma_mask = temp->dma_mask; + dev->coherent_dma_mask = temp->coherent_dma_mask; + dev->dma_parms = temp->dma_parms; + dev->dma_pfn_offset = temp->dma_pfn_offset; + return 0; + } + return -EINVAL; +} +EXPORT_SYMBOL(dma_get_parent_cfg); diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index d5d3881..eb080d6 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -127,6 +127,9 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) return dma_set_mask_and_coherent(dev, mask); } +extern int __weak dma_get_parent_cfg(struct device *dev, + struct device *parent); + extern u64 dma_get_required_mask(struct device *dev); #ifndef set_arch_dma_coherent_ops