From patchwork Tue Aug 5 10:47:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 34917 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A39E820523 for ; Tue, 5 Aug 2014 10:49:37 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf2185633qge.0 for ; Tue, 05 Aug 2014 03:49:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Wk0il+Syvaf05KiTBuSpEiOQ00SIKgfZt2dagj2za9k=; b=FdiVNcDma/7PiO73r3Nc1GpeFRjTSKgOB+DeaGU/oxGvcF5y5aOr9rB+OlPQzdY9XT j7fq7MwJXkjBxthZBwE16ubAF6oG3JbBLHSCgzRV8dxJyKDBCAhyRR7iGm1sOwNqHtWF 6SbKhQw7psr3nsS788EUhe+ba1m3W0ST+teN4NBIAdMcwTtozzmySomlC6HaBKLEzk/r vx2/o03LFCZo703f1Le5Z2vTiX8nAS1zU9tDPAR2p9bMtgd9r8Q2vrduVbXFmwijLzpT MHXGznHXlKVOlAcYM5nLC+QNHO4F2Z4RHBlouA4hZ93bo3VE+qZ4O+Qs/u6Nx5ObXPi1 r3Cg== X-Gm-Message-State: ALoCoQnpAiFQetUi4r3T70p/zxfC6QGoZ4VPjJfgIrs3UO2dq8Q6+jWVw3x2G5p1BskQsQBqSLC9 X-Received: by 10.52.170.204 with SMTP id ao12mr1546680vdc.2.1407235777127; Tue, 05 Aug 2014 03:49:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.48.132 with SMTP id o4ls215934qga.40.gmail; Tue, 05 Aug 2014 03:49:37 -0700 (PDT) X-Received: by 10.220.137.145 with SMTP id w17mr2258639vct.47.1407235777030; Tue, 05 Aug 2014 03:49:37 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id xk9si105325vdc.48.2014.08.05.03.49.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:49:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ik5so1088494vcb.20 for ; Tue, 05 Aug 2014 03:49:36 -0700 (PDT) X-Received: by 10.220.167.9 with SMTP id o9mr2457997vcy.8.1407235776947; Tue, 05 Aug 2014 03:49:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp374579vcb; Tue, 5 Aug 2014 03:49:36 -0700 (PDT) X-Received: by 10.68.194.229 with SMTP id hz5mr3133502pbc.91.1407235775876; Tue, 05 Aug 2014 03:49:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si1542429pbw.101.2014.08.05.03.49.35 for ; Tue, 05 Aug 2014 03:49:35 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755324AbaHEKtY (ORCPT + 21 others); Tue, 5 Aug 2014 06:49:24 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:52922 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755128AbaHEKtQ (ORCPT ); Tue, 5 Aug 2014 06:49:16 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N9T00DAYY1SD200@mailout4.w1.samsung.com>; Tue, 05 Aug 2014 11:49:04 +0100 (BST) X-AuditID: cbfec7f5-b7f776d000003e54-c9-53e0b6aa4050 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id F6.EC.15956.AA6B0E35; Tue, 05 Aug 2014 11:49:14 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N9T0057MY17SE80@eusync3.samsung.com>; Tue, 05 Aug 2014 11:49:14 +0100 (BST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , linaro-mm-sig@lists.linaro.org, Arnd Bergmann , Shaik Ameer Basha , Cho KyongHo , Joerg Roedel , Thierry Reding , Olof Johansson , Laurent Pinchart , Rob Herring , Greg Kroah-Hartman , "Rafael J. Wysocki" , Inki Dae , Kukjin Kim , Sylwester Nawrocki , Tomasz Figa , Kyungmin Park Subject: [PATCH 29/29] temporary: media: s5p-mfc: add support for IOMMU Date: Tue, 05 Aug 2014 12:47:57 +0200 Message-id: <1407235677-26324-30-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> References: <1407235677-26324-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsVy+t/xq7qrtj0INti/mcPi76Rj7BbNi9ez WUy6P4HFYsF+a4vO2RvYLXoXXGWzONv0ht2ic+ISdosvVx4yWWx6fI3V4vKuOWwWM87vY7JY e+Quu8Wp65/ZLP71HmS0OHP6EqvF/z072C0Ov2lntTjycDe7xapdfxgtbv/mcxD1eHJwHpPH 71+TGD12zrrL7jG7Yyarx6ZVnWwe++euYffYvKTe4/a/x8wek28sZ/S4cqKJ1aO3+R2bx5ar 7SwefVtWMXp83iQXwBfFZZOSmpNZllqkb5fAlXGi4TRrwR7xinN7bRoYrwt3MXJySAiYSOzs XMEIYYtJXLi3nq2LkYtDSGApo8Smb6vZIZw+JokD3/6yglSxCRhKdL3tAqsSEehllOhv+sEE 4jALrGOV2N97nQWkSljAXeLBxjtMIDaLgKrE3K4LYDavgKfE3XPLoPbJSfx/uQIszgkUP3zz ANgGIQEPiZ8b1rBPYORdwMiwilE0tTS5oDgpPddIrzgxt7g0L10vOT93EyMkcr7uYFx6zOoQ owAHoxIPr8Leu8FCrIllxZW5hxglOJiVRHgl1jwIFuJNSaysSi3Kjy8qzUktPsTIxMEp1cDo fERdae3rDTbSpesEVSIvaR/0WPqt95lcnuUPCeWw32a3dhpI7kwTnL66/8K2DR/Oa//nFmH+ JXhGs/9hnc+379UhUifjLzrFJbdo7Z/9NZFD4T1HTkxrieAN3q02uiYckS7f1nx0P/pJIiek 6avrxZC+N6+XuW+pvjTvOs+O15u59CsZxXuUWIozEg21mIuKEwFLy9G1egIAAA== Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch is an example how to use more than one IOMMU controller in a device driver for hardware blocks, which have more then one dma master (memory interface with iommu controller). This patch is temporary, do not merge it yet. Signed-off-by: Marek Szyprowski --- drivers/media/platform/s5p-mfc/s5p_mfc.c | 46 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c index 77b99ae..c2e95ab 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c @@ -22,7 +22,11 @@ #include #include #include +#include #include + +#include + #include "s5p_mfc_common.h" #include "s5p_mfc_ctrl.h" #include "s5p_mfc_debug.h" @@ -996,6 +1000,39 @@ static const struct v4l2_file_operations s5p_mfc_fops = { .mmap = s5p_mfc_mmap, }; +static struct device *s5p_mfc_alloc_memdev(struct device *dev, const char *name) +{ + struct device *child; + int ret; + + child = devm_kzalloc(dev, sizeof(struct device), GFP_KERNEL); + if (!child) + return NULL; + + device_initialize(child); + dev_set_name(child, "%s:%s", dev_name(dev), name); + child->parent = dev; + child->bus = dev->bus; + child->coherent_dma_mask = dev->coherent_dma_mask; + child->dma_mask = dev->dma_mask; + + if (device_add(child) == 0) { + ret = arm_iommu_create_default_mapping(child, 0x20000000, + SZ_256M); + if (ret == 0) + return child; + } + + put_device(child); + return NULL; +} + +void s5p_mfc_free_memdev(struct device *dev) +{ + arm_iommu_release_default_mapping(dev); + put_device(dev); +} + static void *mfc_get_drv_data(struct platform_device *pdev); /* MFC probe function */ @@ -1049,8 +1086,8 @@ static int s5p_mfc_probe(struct platform_device *pdev) goto err_res; } - dev->mem_dev_l = &dev->plat_dev->dev; - dev->mem_dev_r = &dev->plat_dev->dev; + dev->mem_dev_l = s5p_mfc_alloc_memdev(&dev->plat_dev->dev, "left"); + dev->mem_dev_r = s5p_mfc_alloc_memdev(&dev->plat_dev->dev, "right"); dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l); if (IS_ERR(dev->alloc_ctx[0])) { @@ -1181,6 +1218,10 @@ static int s5p_mfc_remove(struct platform_device *pdev) s5p_mfc_release_firmware(dev); vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]); vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]); + if (dev->mem_dev_l) + s5p_mfc_free_memdev(dev->mem_dev_l); + if (dev->mem_dev_r) + s5p_mfc_free_memdev(dev->mem_dev_r); s5p_mfc_final_pm(dev); return 0; @@ -1436,6 +1477,7 @@ static struct platform_driver s5p_mfc_driver = { .owner = THIS_MODULE, .pm = &s5p_mfc_pm_ops, .of_match_table = exynos_mfc_match, + .flags = DRIVER_HAS_OWN_IOMMU_MANAGER, }, };