linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: 'KyongHo Cho' <pullip.cho@samsung.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	iommu@lists.linux-foundation.org,
	'Shariq Hasnain' <shariq.hasnain@linaro.org>,
	'Arnd Bergmann' <arnd@arndb.de>,
	'Benjamin Herrenschmidt' <benh@kernel.crashing.org>,
	'Krishna Reddy' <vdumpa@nvidia.com>,
	'Kyungmin Park' <kyungmin.park@samsung.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
	'Russell King - ARM Linux' <linux@arm.linux.org.uk>,
	'Chunsang Jeong' <chunsang.jeong@linaro.org>
Subject: RE: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
Date: Fri, 02 Mar 2012 12:07:59 +0100	[thread overview]
Message-ID: <015101ccf864$bacb1070$30613150$%szyprowski@samsung.com> (raw)
In-Reply-To: <CAHQjnOO5DLOj8Fw=ZriSnXg8W3k7y8Dnu--Peqe6JJX0xGMhoQ@mail.gmail.com>

Hello,

On Friday, March 02, 2012 9:06 AM KyongHo Cho wrote:

> On Thu, Mar 1, 2012 at 12:04 AM, Marek Szyprowski
> <m.szyprowski@samsung.com> wrote:
> > +/**
> > + * arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA
> > + * @dev: valid struct device pointer
> > + * @sg: list of buffers
> > + * @nents: number of buffers to map
> > + * @dir: DMA transfer direction
> > + *
> > + * Map a set of buffers described by scatterlist in streaming mode for DMA.
> > + * The scatter gather list elements are merged together (if possible) and
> > + * tagged with the appropriate dma address and length. They are obtained via
> > + * sg_dma_{address,length}.
> > + */
> > +int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
> > +                    enum dma_data_direction dir, struct dma_attrs *attrs)
> > +{
> > +       struct scatterlist *s = sg, *dma = sg, *start = sg;
> > +       int i, count = 0;
> > +       unsigned int offset = s->offset;
> > +       unsigned int size = s->offset + s->length;
> > +       unsigned int max = dma_get_max_seg_size(dev);
> > +
> > +       for (i = 1; i < nents; i++) {
> > +               s->dma_address = ARM_DMA_ERROR;
> > +               s->dma_length = 0;
> > +
> > +               s = sg_next(s);
> > +
> > +               if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) {
> > +                       if (__map_sg_chunk(dev, start, size, &dma->dma_address,
> > +                           dir) < 0)
> > +                               goto bad_mapping;
> > +
> > +                       dma->dma_address += offset;
> > +                       dma->dma_length = size - offset;
> > +
> > +                       size = offset = s->offset;
> > +                       start = s;
> > +                       dma = sg_next(dma);
> > +                       count += 1;
> > +               }
> > +               size += s->length;
> > +       }
> > +       if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir) < 0)
> > +               goto bad_mapping;
> > +
> > +       dma->dma_address += offset;
> > +       dma->dma_length = size - offset;
> > +
> > +       return count+1;
> > +
> > +bad_mapping:
> > +       for_each_sg(sg, s, count, i)
> > +               __iommu_remove_mapping(dev, sg_dma_address(s), sg_dma_len(s));
> > +       return 0;
> > +}
> > +
> This looks that the given sg list specifies the list of physical
> memory chunks and
> the list of IO virtual memory chunks at the same time after calling
> arm_dma_map_sg().
> It can happen that dma_address and dma_length of a sg entry does not
> correspond to
> physical memory information of the sg entry.

Right, that's how it is designed. If fact sg entries describes 2 independent 
lists - one for physical memory chunks and one for virtual memory chunks. 
It might happen that the whole scattered physical memory can be mapped into
contiguous virtual memory chunk, what result in only one element describing
the io dma addresses. Here is the respective paragraph from 
Documentation/DMA-API-HOWTO.txt (lines 511-517):

'The implementation is free to merge several consecutive sglist entries
into one (e.g. if DMA mapping is done with PAGE_SIZE granularity, any
consecutive sglist entries can be merged into one provided the first one
ends and the second one starts on a page boundary - in fact this is a huge
advantage for cards which either cannot do scatter-gather or have very
limited number of scatter-gather entries) and returns the actual number
of sg entries it mapped them to. On failure 0 is returned.'

> I think it is beneficial for handling IO virtual memory.
> 
> However, I worry about any other problems caused by a single sg entry contains
> information from 2 different context.

What do you mean by the 'context'. DMA mapping assumes that a single call to 
dma_map_sg maps a single memory buffer.

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>

WARNING: multiple messages have this Message-ID (diff)
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: 'KyongHo Cho' <pullip.cho@samsung.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	iommu@lists.linux-foundation.org,
	'Shariq Hasnain' <shariq.hasnain@linaro.org>,
	'Arnd Bergmann' <arnd@arndb.de>,
	'Benjamin Herrenschmidt' <benh@kernel.crashing.org>,
	'Krishna Reddy' <vdumpa@nvidia.com>,
	'Kyungmin Park' <kyungmin.park@samsung.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
	'Russell King - ARM Linux' <linux@arm.linux.org.uk>,
	'Chunsang Jeong' <chunsang.jeong@linaro.org>
Subject: RE: [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper
Date: Fri, 02 Mar 2012 12:07:59 +0100	[thread overview]
Message-ID: <015101ccf864$bacb1070$30613150$%szyprowski@samsung.com> (raw)
Message-ID: <20120302110759.JPcOzl974K4OriY4dG6PiuWMb8tg2c3nH9dEVBCdmRs@z> (raw)
In-Reply-To: <CAHQjnOO5DLOj8Fw=ZriSnXg8W3k7y8Dnu--Peqe6JJX0xGMhoQ@mail.gmail.com>

Hello,

On Friday, March 02, 2012 9:06 AM KyongHo Cho wrote:

> On Thu, Mar 1, 2012 at 12:04 AM, Marek Szyprowski
> <m.szyprowski@samsung.com> wrote:
> > +/**
> > + * arm_iommu_map_sg - map a set of SG buffers for streaming mode DMA
> > + * @dev: valid struct device pointer
> > + * @sg: list of buffers
> > + * @nents: number of buffers to map
> > + * @dir: DMA transfer direction
> > + *
> > + * Map a set of buffers described by scatterlist in streaming mode for DMA.
> > + * The scatter gather list elements are merged together (if possible) and
> > + * tagged with the appropriate dma address and length. They are obtained via
> > + * sg_dma_{address,length}.
> > + */
> > +int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
> > +                    enum dma_data_direction dir, struct dma_attrs *attrs)
> > +{
> > +       struct scatterlist *s = sg, *dma = sg, *start = sg;
> > +       int i, count = 0;
> > +       unsigned int offset = s->offset;
> > +       unsigned int size = s->offset + s->length;
> > +       unsigned int max = dma_get_max_seg_size(dev);
> > +
> > +       for (i = 1; i < nents; i++) {
> > +               s->dma_address = ARM_DMA_ERROR;
> > +               s->dma_length = 0;
> > +
> > +               s = sg_next(s);
> > +
> > +               if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) {
> > +                       if (__map_sg_chunk(dev, start, size, &dma->dma_address,
> > +                           dir) < 0)
> > +                               goto bad_mapping;
> > +
> > +                       dma->dma_address += offset;
> > +                       dma->dma_length = size - offset;
> > +
> > +                       size = offset = s->offset;
> > +                       start = s;
> > +                       dma = sg_next(dma);
> > +                       count += 1;
> > +               }
> > +               size += s->length;
> > +       }
> > +       if (__map_sg_chunk(dev, start, size, &dma->dma_address, dir) < 0)
> > +               goto bad_mapping;
> > +
> > +       dma->dma_address += offset;
> > +       dma->dma_length = size - offset;
> > +
> > +       return count+1;
> > +
> > +bad_mapping:
> > +       for_each_sg(sg, s, count, i)
> > +               __iommu_remove_mapping(dev, sg_dma_address(s), sg_dma_len(s));
> > +       return 0;
> > +}
> > +
> This looks that the given sg list specifies the list of physical
> memory chunks and
> the list of IO virtual memory chunks at the same time after calling
> arm_dma_map_sg().
> It can happen that dma_address and dma_length of a sg entry does not
> correspond to
> physical memory information of the sg entry.

Right, that's how it is designed. If fact sg entries describes 2 independent 
lists - one for physical memory chunks and one for virtual memory chunks. 
It might happen that the whole scattered physical memory can be mapped into
contiguous virtual memory chunk, what result in only one element describing
the io dma addresses. Here is the respective paragraph from 
Documentation/DMA-API-HOWTO.txt (lines 511-517):

'The implementation is free to merge several consecutive sglist entries
into one (e.g. if DMA mapping is done with PAGE_SIZE granularity, any
consecutive sglist entries can be merged into one provided the first one
ends and the second one starts on a page boundary - in fact this is a huge
advantage for cards which either cannot do scatter-gather or have very
limited number of scatter-gather entries) and returns the actual number
of sg entries it mapped them to. On failure 0 is returned.'

> I think it is beneficial for handling IO virtual memory.
> 
> However, I worry about any other problems caused by a single sg entry contains
> information from 2 different context.

What do you mean by the 'context'. DMA mapping assumes that a single call to 
dma_map_sg maps a single memory buffer.

Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center




  parent reply	other threads:[~2012-03-02 11:07 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29 15:04 [PATCHv7 0/9] ARM: DMA-mapping framework redesign Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 1/9] ARM: dma-mapping: introduce ARM_DMA_ERROR constant Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 2/9] ARM: dma-mapping: use pr_* instread of printk Marek Szyprowski
2012-02-29 15:04   ` Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 3/9] ARM: dma-mapping: remove offset parameter to prepare for generic dma_ops Marek Szyprowski
2012-02-29 15:04   ` Marek Szyprowski
     [not found] ` <1330527862-16234-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-02-29 15:04   ` [PATCHv7 4/9] ARM: dma-mapping: use asm-generic/dma-mapping-common.h Marek Szyprowski
2012-02-29 15:04     ` Marek Szyprowski
2012-02-29 15:04   ` [PATCHv7 8/9] ARM: dma-mapping: use alloc, mmap, free from dma_ops Marek Szyprowski
2012-02-29 15:04     ` Marek Szyprowski
2012-03-22 13:45     ` Subash Patel
2012-03-23 12:12       ` Marek Szyprowski
2012-03-23 12:26         ` [PATCH 0/2] ARM: dma-mapping: Fix mmap support for coherent buffers Marek Szyprowski
2012-03-23 12:26           ` Marek Szyprowski
2012-03-23 12:26           ` [PATCH 1/2] common: add dma_mmap_from_coherent() function Marek Szyprowski
2012-03-23 12:26             ` Marek Szyprowski
2012-03-23 12:26           ` [PATCH 2/2] arm: dma-mapping: use dma_mmap_from_coherent() Marek Szyprowski
2012-03-23 12:26             ` Marek Szyprowski
     [not found]           ` <1332505563-17646-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-03-26 11:04             ` [PATCH 0/2] ARM: dma-mapping: Fix mmap support for coherent buffers Subash Patel
2012-03-26 11:04               ` Subash Patel
2012-02-29 15:04 ` [PATCHv7 5/9] ARM: dma-mapping: implement dma sg methods on top of any generic dma ops Marek Szyprowski
2012-02-29 15:04   ` Marek Szyprowski
2012-03-26 11:38   ` Subash Patel
2012-03-26 11:38     ` Subash Patel
2012-02-29 15:04 ` [PATCHv7 6/9] ARM: dma-mapping: move all dma bounce code to separate dma ops structure Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 7/9] ARM: dma-mapping: remove redundant code and cleanup Marek Szyprowski
2012-02-29 15:04 ` [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper Marek Szyprowski
2012-03-02  8:05   ` KyongHo Cho
2012-03-02  8:05     ` KyongHo Cho
2012-03-02 11:07     ` Marek Szyprowski [this message]
2012-03-02 11:07       ` Marek Szyprowski
2012-03-20 13:50     ` Subash Patel
2012-03-20 13:50       ` Subash Patel
2012-03-20 23:56       ` KyongHo Cho
2012-03-20 23:56         ` KyongHo Cho
2012-03-22 13:59         ` Subash Patel
2012-03-22 13:59           ` Subash Patel
2012-03-30  7:14           ` Subash Patel
2012-03-30  7:14             ` Subash Patel
2012-03-05 11:47   ` Hiroshi Doyu
2012-03-05 11:47     ` Hiroshi Doyu
     [not found]     ` <20120305134721.0ab0d0e6de56fa30250059b1-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-03-05 16:07       ` Marek Szyprowski
2012-03-05 16:07         ` Marek Szyprowski
2012-03-06 22:48         ` Krishna Reddy
2012-03-06 22:48           ` Krishna Reddy
2012-03-07  6:09           ` Hiroshi Doyu
2012-03-07  6:09             ` Hiroshi Doyu
     [not found]             ` <20120307.080952.2152478004740487196.hdoyu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-03-07  6:37               ` Hiroshi Doyu
2012-03-07  6:37                 ` Hiroshi Doyu
2012-03-07  7:06                 ` Krishna Reddy
2012-03-07  7:06                   ` Krishna Reddy
2012-03-07  7:16                 ` Hiroshi Doyu
2012-03-07  7:16                   ` Hiroshi Doyu
2012-03-07 16:58                   ` Marek Szyprowski
2012-03-07 16:58                     ` Marek Szyprowski
     [not found]                     ` <011701ccfc83$78030180$68090480$%szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-03-09 14:53                       ` [PATCH] ARM: dma-mapping: fix calculation of iova bitmap size Marek Szyprowski
2012-03-09 14:53                         ` Marek Szyprowski
2012-03-06 23:21   ` [PATCHv7 9/9] ARM: dma-mapping: add support for IOMMU mapper Russell King - ARM Linux
2012-03-06 23:21     ` Russell King - ARM Linux
2012-03-06 23:36     ` Krishna Reddy
2012-03-06 23:36       ` Krishna Reddy
2012-03-07 16:17     ` Marek Szyprowski
2012-03-29  7:19   ` Hiroshi Doyu
2012-03-29  7:19     ` Hiroshi Doyu
2012-03-29  8:00     ` Marek Szyprowski
2012-03-29  8:00       ` Marek Szyprowski
2012-03-30  2:24       ` Krishna Reddy
2012-03-30  2:24         ` Krishna Reddy
2012-03-30  6:30         ` Marek Szyprowski
2012-03-30  6:30           ` Marek Szyprowski

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='015101ccf864$bacb1070$30613150$%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=iommu@lists.linux-foundation.org \
    --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-samsung-soc@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=pullip.cho@samsung.com \
    --cc=shariq.hasnain@linaro.org \
    --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).