From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Zach Pfeffer <zpfeffer@codeaurora.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
ebiederm@xmission.com, linux-arch@vger.kernel.org,
dwalker@codeaurora.org, mel@csn.ul.ie,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, andi@firstfloor.org,
linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC 1/3 v3] mm: iommu: An API to unify IOMMU, CPU and device memory management
Date: Mon, 19 Jul 2010 09:22:13 +0100 [thread overview]
Message-ID: <20100719082213.GA7421@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20100715014148.GC2239@codeaurora.org>
On Wed, Jul 14, 2010 at 06:41:48PM -0700, Zach Pfeffer wrote:
> On Thu, Jul 15, 2010 at 08:07:28AM +0900, FUJITA Tomonori wrote:
> > Why we we need a new abstraction layer to solve the problem that the
> > current API can handle?
>
> The current API can't really handle it because the DMA API doesn't
> separate buffer allocation from buffer mapping.
That's not entirely correct. The DMA API provides two things:
1. An API for allocating DMA coherent buffers
2. An API for mapping streaming buffers
Some implementations of (2) end up using (1) to work around broken
hardware - but that's a separate problem (and causes its own set of
problems.)
> For instance: I need 10, 1 MB physical buffers and a 64 KB physical
> buffer. With the DMA API I need to allocate 10*1MB/PAGE_SIZE + 64
> KB/PAGE_SIZE scatterlist elements, fix them all up to follow the
> chaining specification and then go through all of them again to fix up
> their virtual mappings for the mapper that's mapping the physical
> buffer.
You're making it sound like extremely hard work.
struct scatterlist *sg;
int i, nents = 11;
sg = kmalloc(sizeof(*sg) * nents, GFP_KERNEL);
if (!sg)
return -ENOMEM;
sg_init_table(sg, nents);
for (i = 0; i < nents; i++) {
if (i != nents - 1)
len = 1048576;
else
len = 64*1024;
buf = alloc_buffer(len);
sg_set_buf(&sg[i], buf, len);
}
There's no need to split the scatterlist elements up into individual
pages - the block layer doesn't do that when it passes scatterlists
down to block device drivers.
I'm not saying that it's reasonable to pass (or even allocate) a 1MB
buffer via the DMA API.
> If I want to share the buffer with another device I have to
> make a copy of the entire thing then fix up the virtual mappings for
> the other device I'm sharing with.
This is something the DMA API doesn't do - probably because there hasn't
been a requirement for it.
One of the issues for drivers is that by separating the mapped scatterlist
from the input buffer scatterlist, it creates something else for them to
allocate, which causes an additional failure point - and as all users sit
well with the current API, there's little reason to change especially
given the number of drivers which would need to be updated.
What you can do is:
struct map {
dma_addr_t addr;
size_t len;
};
int map_sg(struct device *dev, struct scatterlist *list,
unsigned int nents, struct map *map, enum dma_data_direction dir)
{
struct scatterlist *sg;
unsigned int i, j = 0;
for_each_sg(list, sg, nents, i) {
map[j]->addr = dma_map_page(dev, sg_page(sg), sg->offset,
sg->length, dir);
map[j]->len = length;
if (dma_mapping_error(map[j]->addr))
break;
j++;
}
return j;
}
void unmap(struct device *dev, struct map *map, unsigned int nents,
enum dma_data_direction dir)
{
while (nents) {
dma_unmap_page(dev, map->addr, map->len, dir);
map++;
nents--;
}
}
Note: this may not be portable to all architectures. It may also break
if there's something like the dmabounce or swiotlb code remapping buffers
which don't fit the DMA mask for the device - that's a different problem.
You can then map the same scatterlist into multiple different 'map'
arrays for several devices simultaneously. What you can't do is access
the buffers from the CPU while they're mapped to any device.
I'm not saying that you should do the above - I'm just proving that it's
not as hard as you seem to be making out.
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-07-19 8:23 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-03 5:38 [RFC 1/3 v3] mm: iommu: An API to unify IOMMU, CPU and device memory management Zach Pfeffer
2010-07-03 19:06 ` Eric W. Biederman
2010-07-07 22:44 ` Zach Pfeffer
2010-07-07 23:07 ` Russell King - ARM Linux
2010-07-08 23:59 ` Zach Pfeffer
2010-07-12 1:25 ` FUJITA Tomonori
2010-07-13 5:57 ` Zach Pfeffer
2010-07-13 6:03 ` FUJITA Tomonori
2010-07-13 12:14 ` Zach Pfeffer
2010-07-14 1:59 ` FUJITA Tomonori
2010-07-14 20:11 ` Zach Pfeffer
2010-07-14 22:05 ` Russell King - ARM Linux
2010-07-15 1:29 ` Zach Pfeffer
2010-07-15 1:47 ` Eric W. Biederman
2010-07-15 5:40 ` Zach Pfeffer
2010-07-15 5:35 ` Zach Pfeffer
2010-07-15 8:55 ` Russell King - ARM Linux
2010-07-16 0:48 ` Tim HRM
2010-07-16 7:58 ` Russell King - ARM Linux
2010-07-17 0:01 ` Larry Bassel
2010-07-19 9:21 ` Tim HRM
2010-07-21 0:44 ` Zach Pfeffer
2010-07-21 1:44 ` Timothy Meade
2010-07-22 4:06 ` Zach Pfeffer
2010-07-19 17:55 ` Michael Bohan
2010-07-19 18:40 ` Russell King - ARM Linux
2010-07-20 22:02 ` stepanm
2010-07-20 22:29 ` Russell King - ARM Linux
2010-07-21 5:49 ` Shilimkar, Santosh
2010-07-21 7:28 ` Russell King - ARM Linux
2010-07-21 7:45 ` Shilimkar, Santosh
2010-07-21 18:04 ` stepanm
2010-07-20 20:45 ` Zach Pfeffer
2010-07-20 20:54 ` Russell King - ARM Linux
2010-07-20 21:56 ` Zach Pfeffer
2010-07-19 6:52 ` Zach Pfeffer
2010-07-19 7:44 ` Eric W. Biederman
2010-07-22 4:25 ` Zach Pfeffer
2010-07-22 7:34 ` Russell King - ARM Linux
2010-07-22 16:25 ` Zach Pfeffer
2010-07-14 23:07 ` FUJITA Tomonori
2010-07-15 1:41 ` Zach Pfeffer
2010-07-19 8:22 ` Russell King - ARM Linux [this message]
2010-07-20 10:09 ` FUJITA Tomonori
2010-07-20 22:20 ` Zach Pfeffer
2010-07-21 1:44 ` FUJITA Tomonori
2010-07-22 4:30 ` Zach Pfeffer
2010-07-22 4:43 ` FUJITA Tomonori
2010-07-22 16:44 ` Zach Pfeffer
2010-07-22 7:39 ` Russell King - ARM Linux
2010-07-22 16:28 ` Zach Pfeffer
-- strict thread matches above, loose matches on Subject: below --
2010-07-06 15:42 Zach Pfeffer
2010-07-21 5:18 stepanm
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=20100719082213.GA7421@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=andi@firstfloor.org \
--cc=dwalker@codeaurora.org \
--cc=ebiederm@xmission.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-omap@vger.kernel.org \
--cc=mel@csn.ul.ie \
--cc=zpfeffer@codeaurora.org \
/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).