From patchwork Wed Nov 28 13:48:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 13271 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AAB952425B for ; Wed, 28 Nov 2012 13:49:01 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 42826A19C3A for ; Wed, 28 Nov 2012 13:49:01 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so8156718ieb.11 for ; Wed, 28 Nov 2012 05:49:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-pgp-universal:from:to:date:thread-topic:thread-index:message-id :references:in-reply-to:accept-language:x-ms-has-attach :x-ms-tnef-correlator:x-nvconfidentiality:acceptlanguage :mime-version:cc:subject:x-beenthere:x-mailman-version:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:content-transfer-encoding:sender :errors-to:x-gm-message-state; bh=yQ1DsAyXh4nkimiBW64wuYcOlcWpDOroQatDJ1ykd+s=; b=OZsT/9wApa9xZlOk7WAFiQUaq5Qx85nbFga68/nDtqWcpxmDW/+vSoGks6wHiiBb84 3NuNcy1mcxYye17j1jV3nIW/BCLSn+K0jVKmOpQ9ZVO5w6c05+Et4l6h+0+/4p1VjsE/ S1yWJyL342plOuSdzVX4Eg4AYDTmrOK0izzfgXofVpEMskE19qvJhJ+Q/ndijmiCFQaz oKYu6PSrs3uqFjfUpQ0+pEskW2YApAP0pda8uhHlkt4lLGnWM34EBCe4LwcEGNqMKu5A A+L63V+4aNf0ENMPVULFKNTZNQisX+VOQXrkwrd78/ns7IOn/gSaDQ/Bdm9JNl8PnEJw sNMQ== Received: by 10.50.42.168 with SMTP id p8mr18959867igl.57.1354110540611; Wed, 28 Nov 2012 05:49:00 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp653157igt; Wed, 28 Nov 2012 05:48:59 -0800 (PST) Received: by 10.204.145.217 with SMTP id e25mr5869903bkv.123.1354110538598; Wed, 28 Nov 2012 05:48:58 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id jd13si29396250bkc.44.2012.11.28.05.48.56; Wed, 28 Nov 2012 05:48:58 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tdi0R-0005mL-Dl; Wed, 28 Nov 2012 13:48:51 +0000 Received: from hqemgate03.nvidia.com ([216.228.121.140]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tdi0Q-0005le-93 for linaro-mm-sig@lists.linaro.org; Wed, 28 Nov 2012 13:48:50 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Wed, 28 Nov 2012 05:51:53 -0800 Received: from hqemhub03.nvidia.com ([172.17.108.22]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 28 Nov 2012 05:48:32 -0800 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 28 Nov 2012 05:48:32 -0800 Received: from deemhub01.nvidia.com (10.21.69.137) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.279.1; Wed, 28 Nov 2012 05:48:43 -0800 Received: from DEMAIL01.nvidia.com ([10.21.69.140]) by deemhub01.nvidia.com ([10.21.69.137]) with mapi; Wed, 28 Nov 2012 14:48:39 +0100 From: Hiroshi Doyu To: "m.szyprowski@samsung.com" , "swarren@wwwdotorg.org" , "joro@8bytes.org" Date: Wed, 28 Nov 2012 14:48:32 +0100 Thread-Topic: [PATCH 1/1] ARM: tegra: bus_notifier registers IOMMU devices(was: How to specify IOMMU'able devices in DT) Thread-Index: Ac3NbxH+3Q6ZzkhrT4agOL343SIi9g== Message-ID: <20121128.154832.539666140149950229.hdoyu@nvidia.com> References: <20120924124452.41070ed2ee9944d930cffffc@nvidia.com><054901cd9a45$db1a7ea0$914f7be0$%szyprowski@samsung.com><20120924.145014.1452596970914043018.hdoyu@nvidia.com> In-Reply-To: <20120924.145014.1452596970914043018.hdoyu@nvidia.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-nvconfidentiality: public acceptlanguage: en-US MIME-Version: 1.0 Cc: "linaro-mm-sig@lists.linaro.org" , "linux@arm.linux.org.uk" , "arnd@arndb.de" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "James.Bottomley@HansenPartnership.com" , "minchan@kernel.org" , "linux-tegra@vger.kernel.org" , "kyungmin.park@samsung.com" , "pullip.cho@samsung.com" , "linux-arm-kernel@lists.infradead.org" Subject: [Linaro-mm-sig] [PATCH 1/1] ARM: tegra: bus_notifier registers IOMMU devices(was: How to specify IOMMU'able devices in DT) X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQnVd3qQfRXF41qi4eZZeoCQy2lc62umfaNugxKNTYaYtZzcQdBdkOmY3Z6AcX/ajweMagnv Hiroshi Doyu wrote @ Mon, 24 Sep 2012 14:50:14 +0300 (EEST): ... > > > > On Mon, 2012-09-24 at 12:04 +0300, Hiroshi Doyu wrote: > > > > > diff --git a/drivers/base/platform.c b/drivers/base/platform.c > > > > > index a1a7225..9eae3be 100644 > > > > > --- a/drivers/base/platform.c > > > > > +++ b/drivers/base/platform.c > > > > > @@ -21,6 +21,8 @@ > > > > > #include > > > > > #include > > > > > > > > > > +#include > > > > > + > > > > > #include "base.h" > > > > > > > > > > #define to_platform_driver(drv) (container_of((drv), struct > > > > > platform_driver, \ > > > > > @@ -305,8 +307,19 @@ int platform_device_add(struct platform_device > > > > > *pdev) > > > > > dev_name(&pdev->dev), dev_name(pdev->dev.parent)); > > > > > > > > > > ret = device_add(&pdev->dev); > > > > > - if (ret == 0) > > > > > - return ret; > > > > > + if (ret) > > > > > + goto failed; > > > > > + > > > > > +#ifdef CONFIG_PLATFORM_ENABLE_IOMMU > > > > > + if (platform_bus_type.map && !pdev->dev.archdata.mapping) { > > > > > + ret = arm_iommu_attach_device(&pdev->dev, > > > > > + platform_bus_type.map); > > > > > + if (ret) > > > > > + goto failed; > > > > > > > > This is horrible ... you're adding an architecture specific callback > > > > into our generic code; that's really a no-no. If the concept of > > > > CONFIG_PLATFORM_ENABE_IOMMU is useful to more than just arm, then this > > > > could become a generic callback. > > > > > > As mentioned in the original, this is a heck to explain what is > > > needed. I am looking for some generic solution for how to specify > > > IOMMU info for each platform devices. I'm guessing that some other SoC > > > may have the similar requirements on the above. As you mentioned, this > > > solution should be a generic, not arch specific. > > > > Please read more about bus notifiers. IMHO a good example is provided in > > the following thread: > > http://www.mail-archive.com/linux-samsung-soc@vger.kernel.org/msg12238.html > > This bus notifier seems enough flexible to afford the variation of > IOMMU map info, like Tegra ASID, which could be platform-specific, and > the other could be common too. There's already iommu_bus_notifier > too. I'll try to implement something base on this. Experimentally implemented as below. With the followig patch, each device could specify its own map in DT, and automatically the device would be attached to the map. There is a case that some devices share a map. This patch doesn't suppor such case yet. >From 8cb75bb6f3a8535a077e0e85265f87c1f1289bfd Mon Sep 17 00:00:00 2001 From: Hiroshi Doyu Date: Wed, 28 Nov 2012 14:47:04 +0200 Subject: [PATCH 1/1] ARM: tegra: bus_notifier registers IOMMU devices platform_bus notifier registers IOMMU devices if dma-window is specified. Its format is: dma-window = <"start" "size">; ex) dma-window = <0x12345000 0x8000>; Signed-off-by: Hiroshi Doyu --- arch/arm/mach-tegra/board-dt-tegra30.c | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/arm/mach-tegra/board-dt-tegra30.c b/arch/arm/mach-tegra/board-dt-tegra30.c index a2b6cf1..570d718 100644 --- a/arch/arm/mach-tegra/board-dt-tegra30.c +++ b/arch/arm/mach-tegra/board-dt-tegra30.c @@ -30,9 +30,11 @@ #include #include #include +#include #include #include +#include #include "board.h" #include "clock.h" @@ -86,10 +88,48 @@ static __initdata struct tegra_clk_init_table tegra_dt_clk_init_table[] = { { NULL, NULL, 0, 0}, }; +#ifdef CONFIG_ARM_DMA_USE_IOMMU +static int tegra_iommu_device_notifier(struct notifier_block *nb, + unsigned long event, void *_dev) +{ + struct dma_iommu_mapping *map = NULL; + struct device *dev = _dev; + dma_addr_t base; + size_t size; + int err; + + switch (event) { + case BUS_NOTIFY_ADD_DEVICE: + err = of_get_dma_window(dev->of_node, NULL, 0, NULL, &base, + &size); + if (!err) + map = arm_iommu_create_mapping(&platform_bus_type, + base, size, 0); + if (IS_ERR_OR_NULL(map)) + break; + if (arm_iommu_attach_device(dev, map)) + dev_err(dev, "Failed to attach %s\n", dev_name(dev)); + dev_dbg(dev, "Attached %s to map %p\n", dev_name(dev), map); + break; + } + return NOTIFY_DONE; +} +#else +#define tegra_iommu_device_notifier NULL +#endif + +static struct notifier_block tegra_iommu_device_nb = { + .notifier_call = tegra_iommu_device_notifier, +}; + static void __init tegra30_dt_init(void) { tegra_clk_init_from_table(tegra_dt_clk_init_table); + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) + bus_register_notifier(&platform_bus_type, + &tegra_iommu_device_nb); + of_platform_populate(NULL, of_default_bus_match_table, tegra30_auxdata_lookup, NULL); }