From patchwork Tue Aug 5 10:47:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 34935 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 42C092397D for ; Tue, 5 Aug 2014 10:51:05 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf3235750oag.0 for ; Tue, 05 Aug 2014 03:51:04 -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=o/zg79aeV5mJrnFqsgGleAtoYhSXI8FtvD1tXYpiY4E=; b=C0e53/QZBTLwpGooCvKAP7Mg+joZCGIcbISwn3YVDVhlIymo4XUkUzdI79Dlp/ZEx1 /BH2xwv2Jps7dIQcNXsK96wc0L7tkMpfmgsGxoBHbRokbuYd/zCMXRReJNGXNKNKMXyJ vy3rbmVj7JOz5zYltgu4MF6HKisag386FOyzcF2WgSiMQrbu9oaJAZ16zJkxOvzuk5tI WqqalXWbptB7TK8tnyxijhHDqppWIcZZPoZJNeMl4mMtlkbrdtUpkwNSaiPSOby9ZS/A yVl2dNTsFwlZob/SylRl2bvVeM5mFnBILQhiu1XnLYdvwMNcCgF6+bD/XA/bH6VdTw8/ YCGQ== X-Gm-Message-State: ALoCoQn9L4rOs+maxkXhIXWIDnX7I/M+Er61WU2yxyx7LgxAO4xnnv46W6v7eVeCdZlGKiGvMvyb X-Received: by 10.182.45.162 with SMTP id o2mr1605257obm.20.1407235863272; Tue, 05 Aug 2014 03:51:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.226 with SMTP id r89ls212576qgd.44.gmail; Tue, 05 Aug 2014 03:51:03 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr1936938vdb.27.1407235863182; Tue, 05 Aug 2014 03:51:03 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id qp20si791335vdb.6.2014.08.05.03.51.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 03:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id hy4so1116477vcb.13 for ; Tue, 05 Aug 2014 03:51:03 -0700 (PDT) X-Received: by 10.220.167.9 with SMTP id o9mr2463278vcy.8.1407235863106; Tue, 05 Aug 2014 03:51:03 -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 tc5csp374698vcb; Tue, 5 Aug 2014 03:51:02 -0700 (PDT) X-Received: by 10.66.141.76 with SMTP id rm12mr3310965pab.138.1407235862065; Tue, 05 Aug 2014 03:51:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xc3si1513378pab.114.2014.08.05.03.51.01 for ; Tue, 05 Aug 2014 03:51:02 -0700 (PDT) Received-SPF: none (google.com: linux-samsung-soc-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 S1755628AbaHEKu7 (ORCPT + 6 others); Tue, 5 Aug 2014 06:50:59 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:52908 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755077AbaHEKtL (ORCPT ); Tue, 5 Aug 2014 06:49:11 -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 <0N9T00DA4Y1NLQ00@mailout4.w1.samsung.com>; Tue, 05 Aug 2014 11:49:00 +0100 (BST) X-AuditID: cbfec7f5-b7f776d000003e54-ba-53e0b6a57051 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 72.EC.15956.5A6B0E35; Tue, 05 Aug 2014 11:49:09 +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:09 +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 24/29] iommu: exynos: create default iommu-based dma-mapping for master devices Date: Tue, 05 Aug 2014 12:47:52 +0200 Message-id: <1407235677-26324-25-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+NgFnrBLMWRmVeSWpSXmKPExsVy+t/xq7pLtz0INvhx1Mji76Rj7BbNi9ez WUy6P4HFYsF+a4vO2RvYLXoXXGWzONv0ht2ic+ISdosvVx4yWWx6fI3V4vKuOWwWM87vY7JY e+Quu8Wp65/ZLP71HmS0OHP6EqvF/z072C0Ov2lntTjycDe7xapdfxgtbv/mcxD1eHJwHpPH 71+TGD12zrrL7jG7Yyarx6ZVnWwe++euYffYvKTe4/a/x8wek28sZ/S4cqKJ1aO3+R2bx5ar 7SwefVtWMXp83iQXwBfFZZOSmpNZllqkb5fAlXH49w3GgvOiFb/2dDA2MP4S7GLk5JAQMJFY dnAXM4QtJnHh3nq2LkYuDiGBpYwSr4/tYoJw+pgkWibvZQWpYhMwlOh62wVWJSLQyyjR3/QD rIpZYB2rxP7e6ywgVcICiRIbJrYygtgsAqoSP3ZuYQOxeQU8Jd53P2OC2Ccn8f/lCjCbEyh+ +OYBsA1CAh4SPzesYZ/AyLuAkWEVo2hqaXJBcVJ6rpFecWJucWleul5yfu4mRkjsfN3BuPSY 1SFGAQ5GJR5ehb13g4VYE8uKK3MPMUpwMCuJ8EqseRAsxJuSWFmVWpQfX1Sak1p8iJGJg1Oq gVH26gGumhvi1Zs3lq/9dv7dW82aGdsn5O6MeebW9su6s+lTZOn6pp/Prm24dr9cx4NVum3Z ZLGHuRtt/U5OXux34Nmb2QEHHLb4Wj7ZfHC5DldvnoMOq1HRLCaJcxlf5WJvbeSoDgnf+k2S nVfBwVfk4tQ47h97gjT2LVgWzzR19sM+phnviz4psRRnJBpqMRcVJwIAZXTVTHsCAAA= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-samsung-soc@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.182 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 adds code to create default per-device iommu-based dma-mapping instance for all master devices, whose driver didn't set DRIVER_HAS_OWN_IOMMU_MANAGER flag. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 49 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 845f547..336b2f8 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -12,6 +12,7 @@ #define DEBUG #endif +#include #include #include #include @@ -29,6 +30,7 @@ #include #include +#include #include typedef u32 sysmmu_iova_t; @@ -1064,6 +1066,43 @@ static phys_addr_t exynos_iommu_iova_to_phys(struct iommu_domain *domain, return phys; } +static int sysmmu_master_device_event(struct notifier_block *nb, + unsigned long val, void *p) +{ + struct device *dev = p; + struct exynos_iommu_owner *owner = dev->archdata.iommu; + struct sysmmu_drvdata *data; + + if (!owner) + return 0; + + data = list_first_entry(&owner->clients, struct sysmmu_drvdata, + owner_node); + if (!data) + return 0; + + switch (val) { + + case IOMMU_GROUP_NOTIFY_BIND_DRIVER: + if (!(dev->driver->flags & DRIVER_HAS_OWN_IOMMU_MANAGER)) + arm_iommu_create_default_mapping(dev, data->base, + data->size); + break; + + case IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER: + case IOMMU_GROUP_NOTIFY_DRVBIND_FAILED: + if (!(dev->driver->flags & DRIVER_HAS_OWN_IOMMU_MANAGER)) + arm_iommu_release_default_mapping(dev); + break; + } + + return 0; +} + +static struct notifier_block sysmmu_master_device_notifier = { + .notifier_call = sysmmu_master_device_event, +}; + static void __free_owner_struct(struct exynos_iommu_owner *owner, struct device *dev) { @@ -1202,6 +1241,7 @@ static int exynos_iommu_add_device(struct device *dev) if (ret != 0) goto err; + iommu_group_register_notifier(group, &sysmmu_master_device_notifier); iommu_group_put(group); return 0; @@ -1213,8 +1253,15 @@ err: static void exynos_iommu_remove_device(struct device *dev) { struct exynos_iommu_owner *owner = dev->archdata.iommu; + struct iommu_group *group = iommu_group_get(dev); + + if (group) { + iommu_group_unregister_notifier(group, + &sysmmu_master_device_notifier); + iommu_group_remove_device(dev); + iommu_group_put(group); + } - iommu_group_remove_device(dev); if (owner) __free_owner_struct(owner, dev); }