Linux IOMMU Development
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Robin Murphy <robin.murphy@arm.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"linux-samsung-soc@vger.kernel.org"
	<linux-samsung-soc@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Cc: Rob Herring <robh@kernel.org>,
	Thierry Reding <treding@nvidia.com>,
	Shaik Ameer Basha <shaik.ameer@samsung.com>,
	Joonyoung Shim <jy0922.shim@samsung.com>,
	Arnd Bergmann <arnd@arndb.de>, Inki Dae <inki.dae@samsung.com>,
	Seung-Woo Kim <sw0312.kim@samsung.com>,
	Will Deacon <Will.Deacon@arm.com>,
	Tomasz Figa <tomasz.figa@gmail.com>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Kukjin Kim <kgene@kernel.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Javier Martinez Canillas <javier@dowhile0.org>,
	Cho KyongHo <pullip.cho@samsung.com>,
	David Wodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH v6 01/25] arm: dma-mapping: add support for creating reserved mappings in iova space
Date: Tue, 19 May 2015 12:49:36 +0200	[thread overview]
Message-ID: <555B1540.4040104@samsung.com> (raw)
In-Reply-To: <554A1E9C.7060101@arm.com>

Hello,

On 2015-05-06 16:01, Robin Murphy wrote:
> Hi Marek,
>
> On 04/05/15 09:15, Marek Szyprowski wrote:
>> Some devices (like frame buffers) are enabled by bootloader and 
>> configured
>> to perform DMA operations automatically (like displaying boot logo or 
>> splash
>> screen). Such devices operate and perform DMA operation usually until 
>> the
>> proper driver for them is loaded and probed. However before that 
>> happens,
>> system usually loads IOMMU drivers and configures dma parameters for 
>> each
>> device. When such initial configuration is created and enabled, it 
>> usually
>> contains empty translation rules betweem IO address space and physical
>> memory, because no buffers nor memory regions have been requested by the
>> respective driver.
>>
>> This patch adds support for "iommu-reserved-mapping", which can be used
>> to provide definitions for mappings that need to be created on system
>> boot to let such devices (enabled by bootloader) to operate properly
>> until respective driver is probed.
>
> This appears to only work if you assume the driver is going to tear 
> down the existing domain entirely; what about drivers that don't 
> manage IOMMUs explicitly, or if there are multiple active devices 
> behind the same IOMMU which (in future) start out in the same default 
> domain? If any device is happy to remain in the default domain then it 
> would be nice to clear the reservations once they are no longer needed.

Right, this need to be somehow worked out, but frankly right now I don't 
have
good idea which code should do it. The only idea that comes to my mind 
is using
a BUS_NOTIFY_BOUND_DRIVER notifier, but I don't like this approach.

> Could we not address the issue in a more robust way, like fleshing out 
> an implementation of the nascent IOMMU_DOMAIN_IDENTITY type, then just 
> flagging such devices to stipulate that their boot-time default domain 
> must be an identity-mapped one?

I'm open for any solution that will cover this case. Maybe my idea of iommu
reserved regions is a bit over-engineered? Maybe instead of defining 
reserved
ranges it will be enough to add something like 
'iommu-on-boot-identity-mapping'
property? This way one can later use it for IOMMU_DOMAIN_IDENTITY 
approach or
something else what will be agreed?

>
>> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> ---
>>   Documentation/devicetree/bindings/iommu/iommu.txt |  44 +++++++++
>>   arch/arm/mm/dma-mapping.c                         | 112 
>> ++++++++++++++++++++++
>>   2 files changed, 156 insertions(+)
>>
> [...]
>> @@ -2048,6 +2092,66 @@ void arm_iommu_detach_device(struct device *dev)
>>   }
>>   EXPORT_SYMBOL_GPL(arm_iommu_detach_device);
>>
>> +static int arm_iommu_add_reserved(struct device *dev,
>> +                       struct dma_iommu_mapping *domain, phys_addr_t 
>> phys,
>> +                       dma_addr_t dma, size_t size)
>> +{
>> +       int ret;
>> +
>> +       ret = __reserve_iova(domain, dma, size);
>> +       if (ret) {
>> +               dev_err(dev, "failed to reserve mapping\n");
>> +               return -EINVAL;
>> +       }
>> +
>> +       ret = iommu_map(domain->domain, dma, phys, size, IOMMU_READ);
>> +       if (ret != 0) {
>> +               dev_err(dev, "create IOMMU mapping\n");
>> +               return ret;
>> +       }
>> +
>> +       dev_info(dev, "created reserved DMA mapping (%pa -> %pad, %zu 
>> bytes)\n",
>> +                &phys, &dma, size);
>> +
>> +       return 0;
>> +}
>> +
>> +static int arm_iommu_init_reserved(struct device *dev,
>> +                                  struct dma_iommu_mapping *domain)
>> +{
>> +       const char *name = "iommu-reserved-mapping";
>> +       const __be32 *prop = NULL;
>> +       int len, naddr, nsize;
>> +       struct device_node *node = dev->of_node;
>> +       phys_addr_t phys;
>> +       dma_addr_t dma;
>> +       size_t size;
>> +
>> +       if (!node)
>> +               return 0;
>> +
>> +       naddr = of_n_addr_cells(node);
>> +       nsize = of_n_size_cells(node);
>> +
>> +       prop = of_get_property(node, name, &len);
>> +       if (!prop)
>> +               return 0;
>> +
>> +       len /= sizeof(u32);
>> +
>> +       if (len < 2 * naddr + nsize) {
>> +               dev_err(dev, "invalid length (%d cells) of %s 
>> property\n",
>> +                       len, name);
>> +               return -EINVAL;
>> +       }
>> +
>> +       phys = of_read_number(prop, naddr);
>> +       dma = of_read_number(prop + naddr, naddr);
>> +       size = of_read_number(prop + 2*naddr, nsize);
>> +
>> +       return arm_iommu_add_reserved(dev, domain, phys, dma, size);
> > +}
>
> I may be missing something, but I don't see how this can handle 
> multiple ranges for the same device as the binding says.
>

Right, loop is missing in the above calls.

>>   static struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent)
>>   {
>>          return coherent ? &iommu_coherent_ops : &iommu_ops;
>> @@ -2068,6 +2172,14 @@ static bool arm_setup_iommu_dma_ops(struct 
>> device *dev, u64 dma_base, u64 size,
>>                  return false;
>>          }
>>
>> +       if (arm_iommu_init_reserved(dev, mapping) != 0) {
>> +               pr_warn("Failed to initialize reserved mapping for 
>> device %s\n",
>> +                       dev_name(dev));
>> +               __arm_iommu_detach_device(dev);
>> +               arm_iommu_release_mapping(mapping);
>> +               return false;
>> +       }
>> +
>>          if (__arm_iommu_attach_device(dev, mapping)) {
>>                  pr_warn("Failed to attached device %s to 
>> IOMMU_mapping\n",
>>                                  dev_name(dev));
>
> I'm hoping Joerg is still working on his default domain series, 
> because the domain creation in arch_setup_dma_ops turns out to be 
> horrible on a number of levels (like everything happening in the wrong 
> order for platform devices). If that doesn't negate this issue 
> entirely, it's going to significantly break this way of hooking up the 
> solution (depending on what the drivers do) - worth some 
> consideration, at least.

I would really like to have something working soon, it's been a lot of 
discussion but still
very little of code that actually implements anything...

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

  reply	other threads:[~2015-05-19 10:49 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04  8:15 [PATCH v6 00/25] Exynos SYSMMU (IOMMU) integration with DT and DMA-mapping subsystem Marek Szyprowski
2015-05-04  8:15 ` [PATCH v6 02/25] arm: exynos: pm_domains: register power domain driver from core_initcall Marek Szyprowski
2015-05-04  8:15 ` [PATCH v6 03/25] drm/exynos: iommu: detach from default dma-mapping domain on init Marek Szyprowski
2015-05-04  8:15 ` [PATCH v6 04/25] drm/exynos: fimd: ensure proper hw state in fimd_clear_channel() Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 05/25] iommu: exynos: don't read version register on every tlb operation Marek Szyprowski
2015-05-10 12:59   ` Cho KyongHo
     [not found] ` <1430727380-10912-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-04  8:15   ` [PATCH v6 01/25] arm: dma-mapping: add support for creating reserved mappings in iova space Marek Szyprowski
2015-05-04 22:12     ` Rob Herring
     [not found]       ` <CAL_JsqKB4F8tspydBFrL-PH3gXcyu-pwQwBETMizJzTpAF3yzg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-05-18 12:09         ` Marek Szyprowski
2015-05-06 14:01     ` Robin Murphy
2015-05-19 10:49       ` Marek Szyprowski [this message]
2015-05-04  8:16   ` [PATCH v6 06/25] iommu: exynos: remove unused functions Marek Szyprowski
2015-05-10 13:01     ` Cho KyongHo
2015-05-04 10:30   ` [PATCH v6 27/26] iommu: exynos: add system suspend/resume support Marek Szyprowski
2015-05-05 15:05   ` [PATCH v6 00/25] Exynos SYSMMU (IOMMU) integration with DT and DMA-mapping subsystem Joerg Roedel
2015-05-18 12:16     ` Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 07/25] iommu: exynos: remove useless spinlock Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 08/25] iommu: exynos: refactor function parameters to simplify code Marek Szyprowski
     [not found]   ` <1430727380-10912-9-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-05 14:52     ` Joerg Roedel
2015-05-10 13:27     ` Cho KyongHo
     [not found]       ` <20150510222712.a955a6d326698ba5a09c6fe7-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-18 12:58         ` Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 09/25] iommu: exynos: remove unused functions, part 2 Marek Szyprowski
     [not found]   ` <1430727380-10912-10-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-05 14:53     ` Joerg Roedel
2015-05-04  8:16 ` [PATCH v6 10/25] iommu: exynos: remove useless device_add/remove callbacks Marek Szyprowski
     [not found]   ` <1430727380-10912-11-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-05 14:55     ` Joerg Roedel
     [not found]       ` <20150505145538.GL15736-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-05-18 12:09         ` Marek Szyprowski
2015-05-18 17:04           ` Joerg Roedel
     [not found]             ` <20150518170430.GK20611-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2015-05-18 19:37               ` Laurent Pinchart
2015-05-04  8:16 ` [PATCH v6 11/25] iommu: exynos: add support for binding more than one sysmmu to master device Marek Szyprowski
2015-05-10 13:34   ` Cho KyongHo
     [not found]     ` <20150510223437.b651f6d2f3f0ead49eb72488-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-18 13:03       ` Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 12/25] iommu: exynos: add support for runtime_pm Marek Szyprowski
2015-05-10 13:38   ` Cho KyongHo
2015-05-18 12:25     ` Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 13/25] iommu: exynos: rename variables to reflect their purpose Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 14/25] iommu: exynos: use struct exynos_iommu_domain in internal structures Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 15/25] iommu: exynos: document " Marek Szyprowski
     [not found]   ` <1430727380-10912-16-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-05 15:00     ` Joerg Roedel
2015-05-04  8:16 ` [PATCH v6 16/25] iommu: exynos: remove excessive includes and sort others alphabetically Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 17/25] iommu: exynos: init from dt-specific callback instead of initcall Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 18/25] iommu: exynos: add callback for initializing devices from device tree Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 19/25] iommu: exynos: remove unneeded code Marek Szyprowski
2015-05-04  8:16 ` [PATCH v6 20/25] ARM: dts: exynos4: add sysmmu nodes Marek Szyprowski
2015-05-05  4:08   ` Krzysztof Kozłowski
2015-05-04  8:16 ` [PATCH v6 21/25] ARM: dts: exynos3250: " Marek Szyprowski
2015-05-05  4:10   ` Krzysztof Kozłowski
2015-05-04  8:16 ` [PATCH v6 22/25] ARM: dts: exynos4415: " Marek Szyprowski
2015-05-05  4:09   ` Krzysztof Kozłowski
2015-05-04  8:16 ` [PATCH v6 23/25] ARM: dts: exynos5250: " Marek Szyprowski
2015-05-05  4:04   ` Krzysztof Kozłowski
2015-05-04  8:16 ` [PATCH v6 24/25] ARM: dts: exynos5420: " Marek Szyprowski
2015-05-05  4:10   ` Krzysztof Kozłowski
2015-05-04  8:16 ` [PATCH v6 25/25] ARM: dts: exynos: add iommu reserved regions for bootloader's splash screen Marek Szyprowski
     [not found]   ` <1430727380-10912-26-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-05  5:50     ` Krzysztof Kozłowski
2015-05-11 16:00 ` [PATCH v6 00/25] Exynos SYSMMU (IOMMU) integration with DT and DMA-mapping subsystem Javier Martinez Canillas
2015-05-12 15:35   ` Javier Martinez Canillas
2015-05-18 13:26   ` Marek Szyprowski
     [not found]     ` <5559E88E.9050108-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-18 13:32       ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=555B1540.4040104@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=Will.Deacon@arm.com \
    --cc=arnd@arndb.de \
    --cc=dwmw2@infradead.org \
    --cc=inki.dae@samsung.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=javier@dowhile0.org \
    --cc=jy0922.shim@samsung.com \
    --cc=kgene@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=pullip.cho@samsung.com \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=shaik.ameer@samsung.com \
    --cc=sw0312.kim@samsung.com \
    --cc=tomasz.figa@gmail.com \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox