ARM: IOMMU: Tegra30: iommu_ops for SMMU driver
Subsystems (5)
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH v2 1/2 ARM: IOMMU: Tegra20: iommu_ops for GART driver
Tegra 20 IOMMU H/W, GART (Graphics Address Relocation Table). This patch implements struct iommu_ops for GART for the upper IOMMU API.
This H/W module supports only single virtual address space(domain), and manages a single level 1-to-1 mapping H/W translation page table.
--- drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/tegra-gart.c | 451 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 463 insertions(+), 0 deletions(-) create mode 100644 drivers/iommu/tegra-gart.c
drivers/iommu/Kconfig +11 -0
@@ -131,4 +131,15 @@ config OMAP_IOMMU_DEBUG Say N unless you know you need this. +config TEGRA_IOMMU_GART + bool "Tegra GART IOMMU Support" + depends on ARCH_TEGRA_2x_SOC + default y + select IOMMU_API + help + Enables support for remapping discontiguous physical memory + shared with the operating system into contiguous I/O virtual + space through the GART (Graphics Address Relocation Table) + hardware included on Tegra SoCs. + endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_IRQ_REMAP) += intr_remapping.o obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o +obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o
drivers/iommu/tegra-gart.c new file +451 -0
451 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [PATCH v2 1/2] [RFC] ARM: IOMMU: Tegra20: iommu_ops for GART driver
Quoted 11 lines · Hiroshi DOYU
Tegra 20 IOMMU H/W, GART (Graphics Address Relocation Table). This patch implements struct
iommu_opsfor GART for the upper IOMMU API.This H/W module supports only single virtual address space(domain), and manages a single level 1-to-1 mapping H/W translation page table.
Signed-off-by Hiroshi DOYU <[email protected]>--- drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/tegra-gart.c | 451 ++++++++++++++++++++++++++++++++++++++++++++
The code looks good in general. I think we need to extend the IOMMU-API a little bit to better support GART IOMMUs. A user of the IOMMU-API should be able to get the information about the iova-base and size of the aperture for example. These extensions will be beneficial for porting other GART-like driver to the IOMMU-API too.
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Re: [PATCH v2 1/2] [RFC] ARM: IOMMU: Tegra20: iommu_ops for GART driver
Hi Joerg, Thank you for your quick review.
From: Joerg Roedel <[email protected]>
Subject: Re: [PATCH v2 1/2] [RFC] ARM: IOMMU: Tegra20: iommu_ops for GART driver
Date: Fri, 16 Dec 2011 16:43:31 +0100
Message-ID: <[email protected]>
Quoted 7 lines · Hiroshi DOYU
Quoted 6 lines
Tegra 20 IOMMU H/W, GART (Graphics Address Relocation Table). This patch implements struct
iommu_opsfor GART for the upper IOMMU API.This H/W module supports only single virtual address space(domain), and manages a single level 1-to-1 mapping H/W translation page table.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Hiroshi DOYU <[email protected]>--- drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/tegra-gart.c | 451 ++++++++++++++++++++++++++++++++++++++++++++The code looks good in general.
Thanks.
Quoted 5 lines
I think we need to extend the IOMMU-API
a little bit to better support GART IOMMUs. A user of the IOMMU-API should be able to get the information about the iova-base and size of the aperture for example. These extensions will be beneficial for porting other GART-like driver to the IOMMU-API too.
is it similar to how ".pgsize_bitmap" is passed?
Quoted 11 lines
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Re: [PATCH v2 1/2] [RFC] ARM: IOMMU: Tegra20: iommu_ops for GART driver
In reply to Hiroshi DOYUHi,
One question is inlined below:
From: Hiroshi Doyu <[email protected]>
Subject: [PATCH v2 1/2] [RFC] ARM: IOMMU: Tegra20: iommu_ops for GART driver
Date: Thu, 15 Dec 2011 14:11:29 +0100
Message-ID: <[email protected]>
Quoted 14 lines
Tegra 20 IOMMU H/W, GART (Graphics Address Relocation Table). This patch implements struct
iommu_opsfor GART for the upper IOMMU API.This H/W module supports only single virtual address space(domain), and manages a single level 1-to-1 mapping H/W translation page table.
Signed-off-by Hiroshi DOYU <[email protected]>--- drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/tegra-gart.c | 451 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 463 insertions(+), 0 deletions(-) create mode 100644 drivers/iommu/tegra-gart.c
....
drivers/iommu/tegra-gart.c line 60
Quoted 13 lines
drivers/iommu/tegra-gart.c new file +13
-0+ +struct gart_device { +void __iomem *regs; +u32 *savedata; +u32 page_count;/* total remappable size */ +dma_addr_t iovmm_base;/* offset to apply to vmm_area */ +spinlock_t pte_lock;/* for pagetable */ +struct list_head client; +spinlock_t client_lock;/* for client list */ +struct device *dev; +}; + +static struct gart_device *gart_handle;/* unique for a system */
^^^^^^^^^^^
.....
drivers/iommu/tegra-gart.c line 145
Quoted 4 lines
drivers/iommu/tegra-gart.c new file +4
-0+ +static int gart_iommu_domain_init (struct iommu_domain *domain) +{ + domain->priv = gart_handle;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
drivers/iommu/tegra-gart.c line 148
Quoted 3 lines
drivers/iommu/tegra-gart.c new file +3
-0+pr_debug ("gart@%p\n" , gart_handle); +return 0 ; +}
In the above, the global pointer is used to pass gart_device to set it in dmain->priv. It works with a single gart_device, but not with multiple gart_devices. This is too bad, I know;). I guess that this can be solved with device tree info where a client device is set as a child of gart_device at device registration. Is this the right way from IOMMU API POV?
for (i = 0; i < ARRAY_SIZE(dmaapi_dummy_device); i++) {
int err;
struct platform_device *pdev = &dmaapi_dummy_device[i];
pdev->dev.platform_data = (void *)dummy_hwgrp_map[i];
pdev->dev.parent = &tegra_gart_device;
^^^^^^^^^^^^^^^^^^^
err = platform_device_register(pdev);RFC PATCH v2 2/2 ARM: IOMMU: Tegra30: iommu_ops for SMMU driver
In reply to a message not in the archiveTegra 30 IOMMU H/W, SMMU (System Memory Management Unit). This patch implements struct iommu_ops for SMMU for the upper IOMMU API.
This H/W module supports multiple virtual address spaces(domain x4), and manages 2 level H/W translation pagetable.
--- arch/arm/mach-tegra/include/mach/smmu.h | 63 ++ drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/tegra-smmu.c | 1027 +++++++++++++++++++++++++++++++ 4 files changed, 1102 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-tegra/include/mach/smmu.h create mode 100644 drivers/iommu/tegra-smmu.c
arch/arm/mach-tegra/include/mach/smmu.h new file +63 -0
@@ -0,0 +1,63 @@ +/* +* IOMMU API for SMMU in Tegra30 +* +* Copyright (c) 2010-2011, NVIDIA CORPORATION. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef MACH_SMMU_H +#define MACH_SMMU_H + +enum smmu_hwgrp { +HWGRP_AFI , +HWGRP_AVPC , +HWGRP_DC , +HWGRP_DCB , +HWGRP_EPP , +HWGRP_G2 , +HWGRP_HC , +HWGRP_HDA , +HWGRP_ISP , +HWGRP_MPE , +HWGRP_NV , +HWGRP_NV2 , +HWGRP_PPCS , +HWGRP_SATA , +HWGRP_VDE , +HWGRP_VI , + +HWGRP_COUNT , + +HWGRP_END = ~0 , +}; + +#define HWG_AFI (1 << HWGRP_AFI) +#define HWG_AVPC (1 << HWGRP_AVPC) +#define HWG_DC (1 << HWGRP_DC) +#define HWG_DCB (1 << HWGRP_DCB) +#define HWG_EPP (1 << HWGRP_EPP) +#define HWG_G2 (1 << HWGRP_G2) +#define HWG_HC (1 << HWGRP_HC) +#define HWG_HDA (1 << HWGRP_HDA) +#define HWG_ISP (1 << HWGRP_ISP) +#define HWG_MPE (1 << HWGRP_MPE) +#define HWG_NV (1 << HWGRP_NV) +#define HWG_NV2 (1 << HWGRP_NV2) +#define HWG_PPCS (1 << HWGRP_PPCS) +#define HWG_SATA (1 << HWGRP_SATA) +#define HWG_VDE (1 << HWGRP_VDE) +#define HWG_VI (1 << HWGRP_VI) + +#endif /* MACH_SMMU_H */
drivers/iommu/Kconfig +11 -0
@@ -142,4 +142,15 @@ config TEGRA_IOMMU_GART space through the GART (Graphics Address Relocation Table) hardware included on Tegra SoCs. +config TEGRA_IOMMU_SMMU + bool "Tegra SMMU IOMMU Support" + depends on ARCH_TEGRA_3x_SOC + default y + select IOMMU_API + help + Enables support for remapping discontiguous physical memory + shared with the operating system into contiguous I/O virtual + space through the SMMU (System Memory Management Unit) + hardware included on Tegra SoCs. + endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o obj-$(CONFIG_TEGRA_IOMMU_GART) += tegra-gart.o +obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o
drivers/iommu/tegra-smmu.c new file +1027 -0
1,027 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 44 lines · Hiroshi DOYU
drivers/iommu/tegra-smmu.c new file +44
-0+static int smmu_iommu_attach_dev (struct iommu_domain *domain, +struct device *dev) +{ +struct smmu_as *as = domain->priv; +struct smmu_client *client, *c; +u32 map; +int err; + + client =kmalloc (sizeof (*c),GFP_KERNEL ); +if (!client) +return -ENOMEM ; + client->dev = dev; + client->as = as; + map = (unsigned long )dev->platform_data; +if (!map) +return -EINVAL ; + + err =smmu_client_enable_hwgrp (client, map); +if (err) + goto err_hwgrp; + +spin_lock (&as->client_lock); +list_for_each_entry (c, &as->client, list) { +if (c->dev == dev) { +pr_err ("%s is already attached\n" ,dev_name (dev)); + err = -EINVAL ; + goto err_client; + } + } +list_add (&client->list, &as->client); +spin_unlock (&as->client_lock); + +/* +* Reserve "page zero" for AVP vectors using a common dummy +* page. +*/ +if (map &HWG_AVPC ) { +struct page *page; + + page = as->smmu->avp_vector_page; +__smmu_iommu_map_pfn (as,0 ,page_to_pfn (page)); + +pr_info ("Reserve \"page zero\" for AVP vectors using a common dummy\n" ); + }
drivers/iommu/tegra-smmu.c line 834
Quoted 10 lines
drivers/iommu/tegra-smmu.c new file +10
-0+ +pr_debug ("Attached %s\n" ,dev_name (dev)); +return 0 ; +err_client: +smmu_client_disable_hwgrp (client); +spin_unlock (&as->client_lock); +err_hwgrp: +kfree (client); +return err; +}
Hmm, I have a question about that. Reading the code it looks like your SMMU exists per pheripheral device and the SMMU hardware supports multiple address spaces per device, right? The domains are implemented for one address-space. So is it right that a device can have multiple address-spaces? If so, what kind of devices do you bind to the domains then. I doesn't make sense to bind whole peripheral devices in this case.
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Hi Joerg, Thank you for your quick review.
From: Joerg Roedel <[email protected]>
Subject: Re: [PATCH v2 2/2] [RFC] ARM: IOMMU: Tegra30: iommu_ops for SMMU driver
Date: Fri, 16 Dec 2011 16:39:04 +0100
Message-ID: <[email protected]>
Quoted 50 lines · Hiroshi DOYU
Quoted 49 lines
drivers/iommu/tegra-smmu.c new file +49
-0+static int smmu_iommu_attach_dev (struct iommu_domain *domain, +struct device *dev) +{ +struct smmu_as *as = domain->priv; +struct smmu_client *client, *c; +u32 map; +int err; + + client =kmalloc (sizeof (*c),GFP_KERNEL ); +if (!client) +return -ENOMEM ; + client->dev = dev; + client->as = as; + map = (unsigned long )dev->platform_data; +if (!map) +return -EINVAL ; + + err =smmu_client_enable_hwgrp (client, map); +if (err) + goto err_hwgrp; + +spin_lock (&as->client_lock); +list_for_each_entry (c, &as->client, list) { +if (c->dev == dev) { +pr_err ("%s is already attached\n" ,dev_name (dev)); + err = -EINVAL ; + goto err_client; + } + } +list_add (&client->list, &as->client); +spin_unlock (&as->client_lock); + +/* +* Reserve "page zero" for AVP vectors using a common dummy +* page. +*/ +if (map &HWG_AVPC ) { +struct page *page; + + page = as->smmu->avp_vector_page; +__smmu_iommu_map_pfn (as,0 ,page_to_pfn (page)); + +pr_info ("Reserve \"page zero\" for AVP vectors using a common dummy\n" ); + } + +pr_debug ("Attached %s\n" ,dev_name (dev)); +return 0 ; +err_client: +smmu_client_disable_hwgrp (client);
Quoted 8 lines
drivers/iommu/tegra-smmu.c line 834
Quoted 5 lines
drivers/iommu/tegra-smmu.c new file +5
-0+spin_unlock (&as->client_lock); +err_hwgrp: +kfree (client); +return err; +}Hmm, I have a question about that. Reading the code it looks like your SMMU exists per pheripheral device
A single SMMU is shared with multiple peripheral devices, a single SMMU has multiple ASIDs. ASID is used per group of peripheral devices. These peripheral groups can be configured by the above "hwgrp"/"map" passed via platform_data. The above "struct device" represents a groupd of peripheral devices, a kind of virtual device.
The above "struct device" ~= a group of peripheral devices.
Quoted 2 lines
and the SMMU hardware supports multiple address spaces per device, right?
Yes, where "device" is a gropud of peripheral devices.
Quoted 1 line
The domains are implemented for one address-space.
Yes.
Quoted 2 lines
So is it right that a device can have multiple
address-spaces?
No, at least, the following code prevents if a peripheral is already assigned ASID.
smmu_client_enable_hwgrp():
....
+ for_each_set_bit(i, &map, BITS_PER_LONG) {
+ offs = HWGRP_ASID_REG(i);
+ val = smmu_read(smmu, offs);
+ if (on) {
+ if (WARN_ON(val & mask))
+ goto err_hw_busy;
Quoted 3 lines
If so, what kind of devices do you bind to the domains then. I doesn't make sense to bind whole peripheral devices in this case.
Here, the above "struct device" ~= a group of any peripheral devices. Those groups are configurable.
In my simple DMA API test(not posted), the above hwgrp/map is configured as below:
146 static int __init dmaapi_test_init(void)
147 {
148 int i;
149 struct dma_iommu_mapping *map;
150
151 map = arm_iommu_create_mapping(IOVA_START, IOVA_SIZE, 0);
152 BUG_ON(!map);
153 pr_debug("Allocate IOVA: %08x-%08x\n", map->base, map->base + IOVA_SIZE);
154
155 for (i = 0; i < ARRAY_SIZE(dmaapi_dummy_device); i++) {
156 int err;
157 struct platform_device *pdev = &dmaapi_dummy_device[i];
158
159 pdev->dev.platform_data = (void *)dummy_hwgrp_map[i];
160 err = platform_device_register(pdev);
161 BUG_ON(err);
162
163 err = arm_iommu_attach_device(&pdev->dev, map);
164 BUG_ON(err);
165 pr_debug("IOMMU API: Attached to %s\n", dev_name(&pdev->dev));
166 }So peripheral devices can be divided into multiple groups, and each each group represents struct device with hwgrp/map info in platform_data.
From: Hiroshi Doyu <[email protected]>
Subject: Re: [PATCH v2 2/2] [RFC] ARM: IOMMU: Tegra30: iommu_ops for SMMU driver
Date: Sat, 17 Dec 2011 03:03:15 +0200 (EET)
Message-ID: <[email protected]>
Quoted 83 lines
Hi Joerg, Thank you for your quick review.
From: Joerg Roedel <[email protected]>
Subject: Re: [PATCH v2 2/2] [RFC] ARM: IOMMU: Tegra30:iommu_opsfor SMMU driver
Date: Fri, 16 Dec 2011 16:39:04 +0100
Message-ID: <[email protected]>Quoted 50 lines · Hiroshi DOYU
Quoted 49 lines
drivers/iommu/tegra-smmu.c new file +49
-0+static int smmu_iommu_attach_dev (struct iommu_domain *domain, +struct device *dev) +{ +struct smmu_as *as = domain->priv; +struct smmu_client *client, *c; +u32 map; +int err; + + client =kmalloc (sizeof (*c),GFP_KERNEL ); +if (!client) +return -ENOMEM ; + client->dev = dev; + client->as = as; + map = (unsigned long )dev->platform_data; +if (!map) +return -EINVAL ; + + err =smmu_client_enable_hwgrp (client, map); +if (err) + goto err_hwgrp; + +spin_lock (&as->client_lock); +list_for_each_entry (c, &as->client, list) { +if (c->dev == dev) { +pr_err ("%s is already attached\n" ,dev_name (dev)); + err = -EINVAL ; + goto err_client; + } + } +list_add (&client->list, &as->client); +spin_unlock (&as->client_lock); + +/* +* Reserve "page zero" for AVP vectors using a common dummy +* page. +*/ +if (map &HWG_AVPC ) { +struct page *page; + + page = as->smmu->avp_vector_page; +__smmu_iommu_map_pfn (as,0 ,page_to_pfn (page)); + +pr_info ("Reserve \"page zero\" for AVP vectors using a common dummy\n" ); + } + +pr_debug ("Attached %s\n" ,dev_name (dev)); +return 0 ; +err_client: +smmu_client_disable_hwgrp (client);Quoted 8 lines
drivers/iommu/tegra-smmu.c line 834
Quoted 5 lines
drivers/iommu/tegra-smmu.c new file +5
-0+spin_unlock (&as->client_lock); +err_hwgrp: +kfree (client); +return err; +}Hmm, I have a question about that. Reading the code it looks like your SMMU exists per pheripheral device
A single SMMU is shared with multiple peripheral devices, a single SMMU has multiple ASIDs. ASID is used per group of peripheral devices. These peripheral groups can be configured by the above "hwgrp"/"map" passed via
platform_data. The above "struct device" represents a groupd of peripheral devices, a kind of virtual device.The above "struct device" ~= a group of peripheral devices.
Quoted 2 lines
and the SMMU hardware supports multiple address spaces per device, right?
Yes, where "device" is a gropud of peripheral devices.
Quoted 1 line
The domains are implemented for one address-space.
Yes.
Quoted 7 lines
Quoted 2 lines
So is it right that a device can have multiple
address-spaces?No, at least, the following code prevents if a peripheral is already assigned ASID.
smmu_client_enable_hwgrp():
Here, smmu_client_enable_hwgrp() == __smmu_client_set_hwgrp(),
+static int __smmu_client_set_hwgrp(struct smmu_client *c,
+ unsigned long map, int on)
+{
+ int i;
+ struct smmu_as *as = c->as;
+ u32 val, offs, mask = SMMU_ASID_ENABLE(as->asid);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^+ struct smmu_device *smmu = as->smmu;
+
+ WARN_ON(!on && map);
+ if (on && !map)
+ return -EINVAL;
+ if (!on)
+ map = smmu_client_hwgrp(c);
+
+ for_each_set_bit(i, &map, BITS_PER_LONG) {
drivers/iommu/tegra-smmu.c line 316
Quoted 6 lines
drivers/iommu/tegra-smmu.c new file +6
-0+for_each_set_bit (i, &map,BITS_PER_LONG ) { + offs =HWGRP_ASID_REG (i); + val =smmu_read (smmu, offs); +if (on) { +if (WARN_ON (val & mask)) + goto err_hw_busy;
^^^^^^^^^^^^^^^^^^^^^^^^^
This checks if peripheral device is already enable(and ASID assigned). If so, it returns error. A group of peripheral devices are configured into struct device in advance.
Quoted 37 lines
Quoted 5 lines
If so, what kind of devices do you bind to the domains then. I doesn't make sense to bind whole peripheral devices in this case.
Here, the above "struct device" ~= a group of any peripheral devices. Those groups are configurable.
In my simple DMA API test(not posted), the above hwgrp/map is configured as below:
146 static int __init dmaapi_test_init(void) 147 { 148 int i; 149 struct dma_iommu_mapping *map; 150 151 map = arm_iommu_create_mapping(IOVA_START, IOVA_SIZE, 0); 152 BUG_ON(!map); 153 pr_debug("Allocate IOVA: %08x-%08x\n", map->base, map->base + IOVA_SIZE); 154 155 for (i = 0; i < ARRAY_SIZE(dmaapi_dummy_device); i++) { 156 int err; 157 struct platform_device *pdev = &dmaapi_dummy_device[i]; 158 159 pdev->dev.platform_data = (void *)dummy_hwgrp_map[i]; 160 err = platform_device_register(pdev); 161 BUG_ON(err); 162 163 err = arm_iommu_attach_device(&pdev->dev, map); 164 BUG_ON(err); 165 pr_debug("IOMMU API: Attached to %s\n", dev_name(&pdev->dev)); 166 }So peripheral devices can be divided into multiple groups, and each each group represents struct device with hwgrp/map info in
platform_data.