From patchwork Fri Oct 12 10:53:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 10638463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07AA85CAF for ; Fri, 12 Oct 2018 10:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBBAB2BB2F for ; Fri, 12 Oct 2018 10:53:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E070B2BB51; Fri, 12 Oct 2018 10:53:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1DCC2BB4D for ; Fri, 12 Oct 2018 10:53:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727758AbeJLSZr (ORCPT ); Fri, 12 Oct 2018 14:25:47 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:52648 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728191AbeJLSZr (ORCPT ); Fri, 12 Oct 2018 14:25:47 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181012105354euoutp021ddd759291ba4a5ca9bfb4518e8db0ac~c1w94Dsx00711907119euoutp02u; Fri, 12 Oct 2018 10:53:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181012105354euoutp021ddd759291ba4a5ca9bfb4518e8db0ac~c1w94Dsx00711907119euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539341634; bh=3n7Yjvyk85U9Lz8IlG6Nmrx19LBd4aNBOGELsOJt9K0=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=YO6/JHZX7PcqZhiV/KnIICLRlL01j85F8rWr54epu+TlY6AWHFVe7kNNfsrYebWm9 lYK8H6VU4JjVRU+qCe0/PcThTVP+Dp8QkfJaLjmDMq1WWOo98RO3QgwxFEhXDQES7E 1ABy1Z/iCYq7BfxZd6AOQGVBjZVPAzNQ4JJWxz7k= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181012105353eucas1p1530cb9c8c4475b3ded9bddf41a6159af~c1w9YwXKZ1270512705eucas1p1M; Fri, 12 Oct 2018 10:53:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.74.04441.14D70CB5; Fri, 12 Oct 2018 11:53:53 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181012105352eucas1p1632502a2266a59a5db820ed43b4954a8~c1w8qOYYE1270512705eucas1p1J; Fri, 12 Oct 2018 10:53:52 +0000 (GMT) X-AuditID: cbfec7f2-a1ae89c000001159-b9-5bc07d41d485 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 58.0B.04128.04D70CB5; Fri, 12 Oct 2018 11:53:52 +0100 (BST) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0PGH00F8SFLQDI70@eusync3.samsung.com>; Fri, 12 Oct 2018 11:53:52 +0100 (BST) From: Andrzej Hajda To: Inki Dae Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski , dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH 5/6] drm/exynos/iommu: replace preprocessor conditionals with C conditionals Date: Fri, 12 Oct 2018 12:53:45 +0200 Message-id: <20181012105346.3754-6-a.hajda@samsung.com> X-Mailer: git-send-email 2.18.0 In-reply-to: <20181012105346.3754-1-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOIsWRmVeSWpSXmKPExsWy7djPc7qOtQeiDT6vFLa4te4cq8XGGetZ La58fc9mMen+BBaLGef3MVmsPXKX3YHN4373cSaPvi2rGD0+b5ILYI7isklJzcksSy3St0vg yjhxN7Dgh1rF9QMH2BsY+xW7GDk5JARMJJpn3mUBsYUEVjBKPL7u1cXIBWR/ZpSYd/EyO0zR vumHWSGKljFK7HrGB1H0n1Hi+7tDYN1sApoSfzffZAOxRQSUJVbta2cHKWIWuMQo8fpkNyNI QlggTqLt7xywqSwCqhJvViwHi/MKmEscnruBDWKbvMTD4+1gcU4BC4ll9w6ygAySEPjIKrFu +gwWiCIXia71H6AahCVeHd8CdaqMxOXJ3VA19RJNM68wQzR3MEqcWLwcqsFa4vDxi2D/MAvw SUzaNh2oiAMozivR0SYEYXpIrN9jBvFxN6PEyrfmExglFzAyrGIUTy0tzk1PLTbMSy3XK07M LS7NS9dLzs/dxAiMrtP/jn/awfj1UtIhRgEORiUe3gX9+6OFWBPLiitzDzFKcDArifAuyDoQ LcSbklhZlVqUH19UmpNafIhRmoNFSZx32byN0UIC6YklqdmpqQWpRTBZJg5OqQbGgNetktcX hnKqrXtosOHpAV7eHUWlX0Tbpk7d4nnGvkNxCaOdbO6BdImU7JxYmYaf8i9Fotz3Xipd6/vb mnnR4i8GzdLOKeIr5l+y+e3+7m8oy9EFbHucykUMLAu+mBTa6J9xWLzH7u63D7d5LjQtcmU5 +DXn/Mrl+4TOelyW1JknM9FPPOqjEktxRqKhFnNRcSIAJQBOH6oCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOJMWRmVeSWpSXmKPExsVy+t/xq7oOtQeiDXbN1La4te4cq8XGGetZ La58fc9mMen+BBaLGef3MVmsPXKX3YHN4373cSaPvi2rGD0+b5ILYI7isklJzcksSy3St0vg yjhxN7Dgh1rF9QMH2BsY+xW7GDk5JARMJPZNP8zaxcjFISSwhFFiV89fRpCEkEAjk8TVVWYg NpuApsTfzTfZQGwRAWWJVfva2UEamAWuMEq0f+tiB0kIC8RJfFn2B8xmEVCVeLNiOdggXgFz icNzN7BBbJOXeHi8HSzOKWAhsezeQRaIZeYSB+ddZpnAyLOAkWEVo0hqaXFuem6xkV5xYm5x aV66XnJ+7iZGYHBsO/Zzyw7GrnfBhxgFOBiVeHh/TNwfLcSaWFZcmXuIUYKDWUmEd0HWgWgh 3pTEyqrUovz4otKc1OJDjNIcLErivOcNKqOEBNITS1KzU1MLUotgskwcnFINjDEWZb9ZDrN/ 6VuSYxry72rh5OLTWyuuJ53t5a6/WqB7ocec88CRQ4pzrYqmPntrEZx2eFqF+sI+ff/iHb/W tM3/WLGD4RfjAQWTKUmq8w47rm7VfMZpc/3flGD3mEn2U79XRH+1s5jvb6/jterrYU+NE8r7 Gk6+Fn89u1Tg+tTTnOsj/HRu1yqxFGckGmoxFxUnAgAmUbZWCgIAAA== X-CMS-MailID: 20181012105352eucas1p1632502a2266a59a5db820ed43b4954a8 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181012105352eucas1p1632502a2266a59a5db820ed43b4954a8 References: <20181012105346.3754-1-a.hajda@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using C conditionals is preferred solution - it provides better code coverage, makes code more clear. Signed-off-by: Andrzej Hajda --- drivers/gpu/drm/exynos/exynos_drm_iommu.c | 108 ++++++++-------------- 1 file changed, 36 insertions(+), 72 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c index 564f1529d77e..14558dedc043 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_iommu.c +++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.c @@ -12,84 +12,30 @@ #include #include +#include #include #include #include "exynos_drm_drv.h" #include "exynos_drm_iommu.h" -#define EXYNOS_DEV_ADDR_START 0x20000000 -#define EXYNOS_DEV_ADDR_SIZE 0x40000000 - #if defined(CONFIG_ARM_DMA_USE_IOMMU) #include - -static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv, - unsigned long start, unsigned long size) -{ - priv->mapping = arm_iommu_create_mapping(&platform_bus_type, start, - size); - return IS_ERR(priv->mapping); -} - -static inline void -__exynos_iommu_release_mapping(struct exynos_drm_private *priv) -{ - arm_iommu_release_mapping(priv->mapping); -} - -static inline int __exynos_iommu_attach(struct exynos_drm_private *priv, - struct device *dev) -{ - if (dev->archdata.mapping) - arm_iommu_detach_device(dev); - - return arm_iommu_attach_device(dev, priv->mapping); -} - -static inline void __exynos_iommu_detach(struct exynos_drm_private *priv, - struct device *dev) -{ - arm_iommu_detach_device(dev); -} - -#elif defined(CONFIG_IOMMU_DMA) -#include - -static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv, - unsigned long start, unsigned long size) -{ - priv->mapping = iommu_get_domain_for_dev(priv->dma_dev); - return 0; -} - -static inline void __exynos_iommu_release_mapping(struct exynos_drm_private *priv) -{ - priv->mapping = NULL; -} - -static inline int __exynos_iommu_attach(struct exynos_drm_private *priv, - struct device *dev) -{ - struct iommu_domain *domain = priv->mapping; - - if (dev != priv->dma_dev) - return iommu_attach_device(domain, dev); - return 0; -} - -static inline void __exynos_iommu_detach(struct exynos_drm_private *priv, - struct device *dev) -{ - struct iommu_domain *domain = priv->mapping; - - if (dev != priv->dma_dev) - iommu_detach_device(domain, dev); -} #else -#error Unsupported architecture and IOMMU/DMA-mapping glue code +#define arm_iommu_create_mapping(...) ({ NULL; }) +#define arm_iommu_attach_device(...) ({ -ENODEV; }) +#define arm_iommu_release_mapping(...) ({ }) +#define arm_iommu_detach_device(...) ({ }) +#define to_dma_iommu_mapping(dev) NULL #endif +#if !defined(CONFIG_IOMMU_DMA) +#define iommu_dma_init_domain(...) ({ -EINVAL; }) +#endif + +#define EXYNOS_DEV_ADDR_START 0x20000000 +#define EXYNOS_DEV_ADDR_SIZE 0x40000000 + static inline int configure_dma_max_seg_size(struct device *dev) { if (!dev->dma_parms) @@ -116,8 +62,13 @@ int drm_create_iommu_mapping(struct drm_device *drm_dev) { struct exynos_drm_private *priv = drm_dev->dev_private; - return __exynos_iommu_create_mapping(priv, EXYNOS_DEV_ADDR_START, - EXYNOS_DEV_ADDR_SIZE); + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) + priv->mapping = arm_iommu_create_mapping(&platform_bus_type, + EXYNOS_DEV_ADDR_START, EXYNOS_DEV_ADDR_SIZE); + else if (IS_ENABLED(CONFIG_IOMMU_DMA)) + priv->mapping = iommu_get_domain_for_dev(priv->dma_dev); + + return IS_ERR(priv->mapping); } /* @@ -129,7 +80,8 @@ void drm_release_iommu_mapping(struct drm_device *drm_dev) { struct exynos_drm_private *priv = drm_dev->dev_private; - __exynos_iommu_release_mapping(priv); + arm_iommu_release_mapping(priv->mapping); + priv->mapping = NULL; } /* @@ -157,7 +109,15 @@ int drm_iommu_attach_device(struct drm_device *drm_dev, if (ret) return ret; - ret = __exynos_iommu_attach(priv, subdrv_dev); + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) { + if (to_dma_iommu_mapping(subdrv_dev)) + arm_iommu_detach_device(subdrv_dev); + + ret = arm_iommu_attach_device(subdrv_dev, priv->mapping); + } else if (IS_ENABLED(CONFIG_IOMMU_DMA)) { + ret = iommu_attach_device(priv->mapping, subdrv_dev); + } + if (ret) clear_dma_max_seg_size(subdrv_dev); @@ -178,6 +138,10 @@ void drm_iommu_detach_device(struct drm_device *drm_dev, { struct exynos_drm_private *priv = drm_dev->dev_private; - __exynos_iommu_detach(priv, subdrv_dev); + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) + arm_iommu_detach_device(subdrv_dev); + else if (IS_ENABLED(CONFIG_IOMMU_DMA)) + iommu_detach_device(priv->mapping, subdrv_dev); + clear_dma_max_seg_size(subdrv_dev); }