From: Christoph Hellwig <hch@lst.de>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Christoph Hellwig <hch@lst.de>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Tomasz Figa <tfiga@chromium.org>,
Ricardo Ribalda <ribalda@chromium.org>,
Sergey Senozhatsky <senozhatsky@google.com>,
iommu@lists.linux-foundation.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Subject: Re: [PATCH 4/7] dma-mapping: add a dma_alloc_noncontiguous API
Date: Mon, 1 Mar 2021 09:09:42 +0100 [thread overview]
Message-ID: <20210301080942.GA27723@lst.de> (raw)
In-Reply-To: <53a6c581-4d9f-c69a-80f5-2e95e810c4d1@arm.com>
On Tue, Feb 16, 2021 at 06:55:39PM +0000, Robin Murphy wrote:
> On 2021-02-02 09:51, Christoph Hellwig wrote:
>> Add a new API that returns a potentiall virtually non-contigous sg_table
>> and a DMA address. This API is only properly implemented for dma-iommu
>> and will simply return a contigious chunk as a fallback.
>>
>> The intent is that media drivers can use this API if either:
>>
>> - no kernel mapping or only temporary kernel mappings are required.
>> That is as a better replacement for DMA_ATTR_NO_KERNEL_MAPPING
>> - a kernel mapping is required for cached and DMA mapped pages, but
>> the driver also needs the pages to e.g. map them to userspace.
>> In that sense it is a replacement for some aspects of the recently
>> removed and never fully implemented DMA_ATTR_NON_CONSISTENT
>>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>> Documentation/core-api/dma-api.rst | 74 +++++++++++++++++++++
>> include/linux/dma-map-ops.h | 18 +++++
>> include/linux/dma-mapping.h | 31 +++++++++
>> kernel/dma/mapping.c | 103 +++++++++++++++++++++++++++++
>> 4 files changed, 226 insertions(+)
>>
>> diff --git a/Documentation/core-api/dma-api.rst b/Documentation/core-api/dma-api.rst
>> index 157a474ae54416..e24b2447f4bfe6 100644
>> --- a/Documentation/core-api/dma-api.rst
>> +++ b/Documentation/core-api/dma-api.rst
>> @@ -594,6 +594,80 @@ dev, size, dma_handle and dir must all be the same as those passed into
>> dma_alloc_noncoherent(). cpu_addr must be the virtual address returned by
>> dma_alloc_noncoherent().
>> +::
>> +
>> + struct sg_table *
>> + dma_alloc_noncontiguous(struct device *dev, size_t size,
>> + enum dma_data_direction dir, gfp_t gfp)
>> +
>> +This routine allocates <size> bytes of non-coherent and possibly non-contiguous
>> +memory. It returns a pointer to struct sg_table that describes the allocated
>> +and DMA mapped memory, or NULL if the allocation failed. The resulting memory
>> +can be used for struct page mapped into a scatterlist are suitable for.
>> +
>> +The return sg_table is guaranteed to have 1 single DMA mapped segment as
>> +indicated by sgt->nents, but it might have multiple CPU side segments as
>> +indicated by sgt->orig_nents.
>> +
>> +The dir parameter specified if data is read and/or written by the device,
>> +see dma_map_single() for details.
>> +
>> +The gfp parameter allows the caller to specify the ``GFP_`` flags (see
>> +kmalloc()) for the allocation, but rejects flags used to specify a memory
>> +zone such as GFP_DMA or GFP_HIGHMEM.
>> +
>> +Before giving the memory to the device, dma_sync_sgtable_for_device() needs
>> +to be called, and before reading memory written by the device,
>> +dma_sync_sgtable_for_cpu(), just like for streaming DMA mappings that are
>> +reused.
>> +
>> +::
>> +
>> + void
>> + dma_free_noncontiguous(struct device *dev, size_t size,
>> + struct sg_table *sgt,
>> + enum dma_data_direction dir)
>> +
>> +Free memory previously allocated using dma_alloc_noncontiguous(). dev, size,
>> +and dir must all be the same as those passed into dma_alloc_noncontiguous().
>> +sgt must be the pointer returned by dma_alloc_noncontiguous().
>> +
>> +::
>> +
>> + void *
>> + dma_vmap_noncontiguous(struct device *dev, size_t size,
>> + struct sg_table *sgt)
>> +
>> +Return a contiguous kernel mapping for an allocation returned from
>> +dma_alloc_noncontiguous(). dev and size must be the same as those passed into
>> +dma_alloc_noncontiguous(). sgt must be the pointer returned by
>> +dma_alloc_noncontiguous().
>> +
>> +Once a non-contiguous allocation is mapped using this function, the
>> +flush_kernel_vmap_range() and invalidate_kernel_vmap_range() APIs must be used
>> +to manage the coherency of the kernel mapping.
>
> Maybe say something like "coherency between the kernel mapping and any
> userspace mappings"? Otherwise people like me may be easily confused and
> think it's referring to coherency between the kernel mapping and the
> device, where in most cases those APIs won't help at all :)
Well, it is all of the above for a VIVT cache setup. I've ammended
it to:
Once a non-contiguous allocation is mapped using this function, the
flush_kernel_vmap_range() and invalidate_kernel_vmap_range() APIs must be used
to manage the coherency between the kernel mapping, the device and user space
mappings (if any).
next prev parent reply other threads:[~2021-03-01 8:10 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 9:51 add a new dma_alloc_noncontiguous API v2 Christoph Hellwig
2021-02-02 9:51 ` [PATCH 1/7] dma-mapping: remove the {alloc,free}_noncoherent methods Christoph Hellwig
2021-02-02 9:51 ` [PATCH 2/7] dma-mapping: add a dma_mmap_pages helper Christoph Hellwig
2021-02-02 9:51 ` [PATCH 3/7] dma-mapping: refactor dma_{alloc,free}_pages Christoph Hellwig
2021-02-02 9:51 ` [PATCH 4/7] dma-mapping: add a dma_alloc_noncontiguous API Christoph Hellwig
2021-02-16 18:55 ` Robin Murphy
2021-03-01 8:09 ` Christoph Hellwig [this message]
2021-02-02 9:51 ` [PATCH 5/7] dma-iommu: refactor iommu_dma_alloc_remap Christoph Hellwig
2021-02-02 9:51 ` [PATCH 6/7] dma-iommu: implement ->alloc_noncontiguous Christoph Hellwig
2021-02-16 8:14 ` Tomasz Figa
2021-02-16 8:49 ` Christoph Hellwig
2021-03-01 7:17 ` Sergey Senozhatsky
2021-03-01 7:21 ` Christoph Hellwig
2021-03-01 8:02 ` Sergey Senozhatsky
2021-03-01 8:11 ` Christoph Hellwig
2021-02-02 9:51 ` [PATCH 7/7] media: uvcvideo: Use dma_alloc_noncontiguos API Christoph Hellwig
2021-02-07 18:48 ` add a new dma_alloc_noncontiguous API v2 Christoph Hellwig
2021-02-08 11:33 ` Tomasz Figa
2021-02-09 8:22 ` Christoph Hellwig
2021-02-09 8:29 ` Ricardo Ribalda
2021-02-09 14:46 ` Ricardo Ribalda
2021-02-09 17:02 ` Christoph Hellwig
2021-02-11 9:08 ` Ricardo Ribalda
2021-02-11 13:06 ` Christoph Hellwig
2021-02-11 13:20 ` Ricardo Ribalda
2021-02-11 13:55 ` Laurent Pinchart
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=20210301080942.GA27723@lst.de \
--to=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
--cc=robin.murphy@arm.com \
--cc=senozhatsky@google.com \
--cc=tfiga@chromium.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).