linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: 'Arnd Bergmann' <arnd@arndb.de>
Cc: linux-arm-kernel@lists.infradead.org,
	linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, iommu@lists.linux-foundation.org,
	'Kyungmin Park' <kyungmin.park@samsung.com>,
	'Joerg Roedel' <joro@8bytes.org>,
	'Russell King - ARM Linux' <linux@arm.linux.org.uk>,
	'Chunsang Jeong' <chunsang.jeong@linaro.org>,
	'Krishna Reddy' <vdumpa@nvidia.com>,
	'KyongHo Cho' <pullip.cho@samsung.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
	'Benjamin Herrenschmidt' <benh@kernel.crashing.org>,
	'Konrad Rzeszutek Wilk' <konrad.wilk@oracle.com>,
	'Hiroshi Doyu' <hdoyu@nvidia.com>,
	'Subash Patel' <subashrp@gmail.com>
Subject: RE: [PATCHv8 10/10] ARM: dma-mapping: add support for IOMMU mapper
Date: Thu, 12 Apr 2012 11:49:23 +0200	[thread overview]
Message-ID: <026f01cd1891$8a2f1b80$9e8d5280$%szyprowski@samsung.com> (raw)
In-Reply-To: <201204101158.29590.arnd@arndb.de>

Hi Arnd,

On Tuesday, April 10, 2012 1:58 PM Arnd Bergmann wrote:

> On Tuesday 10 April 2012, Marek Szyprowski wrote:
> > +/**
> > + * arm_iommu_create_mapping
> > + * @bus: pointer to the bus holding the client device (for IOMMU calls)
> > + * @base: start address of the valid IO address space
> > + * @size: size of the valid IO address space
> > + * @order: accuracy of the IO addresses allocations
> > + *
> > + * Creates a mapping structure which holds information about used/unused
> > + * IO address ranges, which is required to perform memory allocation and
> > + * mapping with IOMMU aware functions.
> > + *
> > + * The client device need to be attached to the mapping with
> > + * arm_iommu_attach_device function.
> > + */
> > +struct dma_iommu_mapping *
> > +arm_iommu_create_mapping(struct bus_type *bus, dma_addr_t base, size_t size,
> > +                        int order)
> > +{
> > +       unsigned int count = size >> (PAGE_SHIFT + order);
> > +       unsigned int bitmap_size = BITS_TO_LONGS(count) * sizeof(long);
> > +       struct dma_iommu_mapping *mapping;
> > +       int err = -ENOMEM;
> > +
> > +       if (!count)
> > +               return ERR_PTR(-EINVAL);
> > +
> > +       mapping = kzalloc(sizeof(struct dma_iommu_mapping), GFP_KERNEL);
> > +       if (!mapping)
> > +               goto err;
> > +
> > +       mapping->bitmap = kzalloc(bitmap_size, GFP_KERNEL);
> > +       if (!mapping->bitmap)
> > +               goto err2;
> > +
> > +       mapping->base = base;
> > +       mapping->bits = BITS_PER_BYTE * bitmap_size;
> > +       mapping->order = order;
> > +       spin_lock_init(&mapping->lock);
> > +
> > +       mapping->domain = iommu_domain_alloc(bus);
> > +       if (!mapping->domain)
> > +               goto err3;
> > +
> > +       kref_init(&mapping->kref);
> > +       return mapping;
> > +err3:
> > +       kfree(mapping->bitmap);
> > +err2:
> > +       kfree(mapping);
> > +err:
> > +       return ERR_PTR(err);
> > +}
> > +EXPORT_SYMBOL(arm_iommu_create_mapping);
> 
> I don't understand this function, mostly I guess because you have not
> provided any users. A few questions here:
> 
> * What is ARM specific about it that it is named arm_iommu_create_mapping?
>   Isn't this completely generic, at least on the interface side?

This function is quite generic. It creates 'struct dma_iommu_mapping' object,
which is stored in the client's device arch data. This object mainly stores
information about io/dma address space: base address, allocation bitmap and
respective iommu domain. Please note that more than one device can be assigned
to the given dma_iommu_mapping to match different hardware topologies.

This function is called by the board/(sub-)platform startup code to initialize
iommu based dma-mapping. For the example usage please refer to 
s5p_create_iommu_mapping() function in arch/arm/mach-exynos/dev-sysmmu.c on 
3.4-rc2-arm-dma-v8-samsung branch in 
git://git.linaro.org/people/mszyprowski/linux-dma-mapping.git

GITWeb shortcut: 
http://git.linaro.org/gitweb?p=people/mszyprowski/linux-dma-mapping.git;a=blob;f=arch/arm/mach-exyno
s/dev-sysmmu.c;h=31f2d6caf0e9949def18abd18af3f9d16737ae19;hb=6025093750d41f88406042e6486e331b806dc87
5#l283

> * Why is this exported to modules? Which device drivers do you expect
>   to call it?

I thought it might be useful to use modules for registering devices, but 
now I see that no platform use such approach. I will drop these exports 
unless someone finds a real use case for them.

> * Why do you pass the bus_type in here? That seems like the completely
>   wrong thing to do when all devices are on the same bus type (e.g.
>   amba or platform) but are connected to different instances that each
>   have their own iommu. I guess this is a question for Jörg, because the
>   base iommu interface provides iommu_domain_alloc().

That's only a consequence of the iommu api. I would also prefer to use client 
device pointer here instead of the bus id, but maybe I don't have enough 
knowledge about desktop IOMMUs. I suspect that there is also a need to assign
one IOMMU driver to the whole bus (like pci bus) and it originates from such
systems. In embedded world we usually have only one iommu driver which 
operates on the platform bus devices. On Samsung Exynos4 we have over a dozen
SYSMMU controllers for various multimedia blocks, but they are all exactly 
the same. We use one iommu ops structure and store a pointer to the real 
iommu controller instance inside arch data of the client struct device.
 
Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2012-04-12  9:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10 11:04 [PATCHv8 00/10] ARM: DMA-mapping framework redesign Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 01/10] common: add dma_mmap_from_coherent() function Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 02/10] ARM: dma-mapping: use pr_* instread of printk Marek Szyprowski
2012-04-10 11:41   ` Arnd Bergmann
2012-04-10 11:04 ` [PATCHv8 03/10] ARM: dma-mapping: introduce ARM_DMA_ERROR constant Marek Szyprowski
2012-04-10 11:31   ` Arnd Bergmann
2012-04-10 12:53     ` Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 04/10] ARM: dma-mapping: remove offset parameter to prepare for generic dma_ops Marek Szyprowski
2012-04-10 11:43   ` Arnd Bergmann
2012-04-11 12:05     ` Marek Szyprowski
2012-04-11 12:18       ` Arnd Bergmann
2012-04-11 13:05         ` Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 05/10] ARM: dma-mapping: use asm-generic/dma-mapping-common.h Marek Szyprowski
2012-04-10 11:47   ` Arnd Bergmann
2012-04-11 12:07     ` Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 06/10] ARM: dma-mapping: implement dma sg methods on top of any generic dma ops Marek Szyprowski
2012-04-10 11:04 ` [PATCHv8 07/10] ARM: dma-mapping: move all dma bounce code to separate dma ops structure Marek Szyprowski
2012-04-10 12:24   ` Arnd Bergmann
2012-04-10 12:51     ` Marek Szyprowski
2012-04-10 13:17       ` Arnd Bergmann
2012-04-10 11:04 ` [PATCHv8 08/10] ARM: dma-mapping: remove redundant code and cleanup Marek Szyprowski
2012-04-10 12:22   ` Arnd Bergmann
2012-04-10 11:04 ` [PATCHv8 09/10] ARM: dma-mapping: use alloc, mmap, free from dma_ops Marek Szyprowski
2012-04-10 12:21   ` Arnd Bergmann
2012-04-10 11:04 ` [PATCHv8 10/10] ARM: dma-mapping: add support for IOMMU mapper Marek Szyprowski
2012-04-10 11:58   ` Arnd Bergmann
2012-04-10 12:57     ` Marek Szyprowski
2012-04-12  9:49     ` Marek Szyprowski [this message]
2012-04-18  7:14 ` [PATCHv8 00/10] ARM: DMA-mapping framework redesign Subash Patel

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='026f01cd1891$8a2f1b80$9e8d5280$%szyprowski@samsung.com' \
    --to=m.szyprowski@samsung.com \
    --cc=andrzej.p@samsung.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=chunsang.jeong@linaro.org \
    --cc=hdoyu@nvidia.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=konrad.wilk@oracle.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@arm.linux.org.uk \
    --cc=pullip.cho@samsung.com \
    --cc=subashrp@gmail.com \
    --cc=vdumpa@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;
as well as URLs for NNTP newsgroup(s).