Skip to content

Commit 1b307ac

Browse files
committed
Merge tag 'dma-mapping-5.10-1' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping fixes from Christoph Hellwig: - document the new dma_{alloc,free}_pages() API - two fixups for the dma-mapping.h split * tag 'dma-mapping-5.10-1' of git://git.infradead.org/users/hch/dma-mapping: dma-mapping: document dma_{alloc,free}_pages dma-mapping: move more functions to dma-map-ops.h ARM/sa1111: add a missing include of dma-map-ops.h
2 parents 9bf8d8b + 6857a5e commit 1b307ac

5 files changed

Lines changed: 68 additions & 32 deletions

File tree

Documentation/core-api/dma-api.rst

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,9 @@ routines, e.g.:::
519519
Part II - Non-coherent DMA allocations
520520
--------------------------------------
521521

522-
These APIs allow to allocate pages in the kernel direct mapping that are
523-
guaranteed to be DMA addressable. This means that unlike dma_alloc_coherent,
524-
virt_to_page can be called on the resulting address, and the resulting
525-
struct page can be used for everything a struct page is suitable for.
522+
These APIs allow to allocate pages that are guaranteed to be DMA addressable
523+
by the passed in device, but which need explicit management of memory ownership
524+
for the kernel vs the device.
526525

527526
If you don't understand how cache line coherency works between a processor and
528527
an I/O device, you should not be using this part of the API.
@@ -537,7 +536,7 @@ an I/O device, you should not be using this part of the API.
537536
This routine allocates a region of <size> bytes of consistent memory. It
538537
returns a pointer to the allocated region (in the processor's virtual address
539538
space) or NULL if the allocation failed. The returned memory may or may not
540-
be in the kernels direct mapping. Drivers must not call virt_to_page on
539+
be in the kernel direct mapping. Drivers must not call virt_to_page on
541540
the returned memory region.
542541

543542
It also returns a <dma_handle> which may be cast to an unsigned integer the
@@ -565,7 +564,45 @@ reused.
565564
Free a region of memory previously allocated using dma_alloc_noncoherent().
566565
dev, size and dma_handle and dir must all be the same as those passed into
567566
dma_alloc_noncoherent(). cpu_addr must be the virtual address returned by
568-
the dma_alloc_noncoherent().
567+
dma_alloc_noncoherent().
568+
569+
::
570+
571+
struct page *
572+
dma_alloc_pages(struct device *dev, size_t size, dma_addr_t *dma_handle,
573+
enum dma_data_direction dir, gfp_t gfp)
574+
575+
This routine allocates a region of <size> bytes of non-coherent memory. It
576+
returns a pointer to first struct page for the region, or NULL if the
577+
allocation failed. The resulting struct page can be used for everything a
578+
struct page is suitable for.
579+
580+
It also returns a <dma_handle> which may be cast to an unsigned integer the
581+
same width as the bus and given to the device as the DMA address base of
582+
the region.
583+
584+
The dir parameter specified if data is read and/or written by the device,
585+
see dma_map_single() for details.
586+
587+
The gfp parameter allows the caller to specify the ``GFP_`` flags (see
588+
kmalloc()) for the allocation, but rejects flags used to specify a memory
589+
zone such as GFP_DMA or GFP_HIGHMEM.
590+
591+
Before giving the memory to the device, dma_sync_single_for_device() needs
592+
to be called, and before reading memory written by the device,
593+
dma_sync_single_for_cpu(), just like for streaming DMA mappings that are
594+
reused.
595+
596+
::
597+
598+
void
599+
dma_free_pages(struct device *dev, size_t size, struct page *page,
600+
dma_addr_t dma_handle, enum dma_data_direction dir)
601+
602+
Free a region of memory previously allocated using dma_alloc_pages().
603+
dev, size and dma_handle and dir must all be the same as those passed into
604+
dma_alloc_noncoherent(). page must be the pointer returned by
605+
dma_alloc_pages().
569606

570607
::
571608

arch/arm/common/sa1111.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/platform_device.h>
2323
#include <linux/slab.h>
2424
#include <linux/spinlock.h>
25-
#include <linux/dma-mapping.h>
25+
#include <linux/dma-map-ops.h>
2626
#include <linux/clk.h>
2727
#include <linux/io.h>
2828

include/linux/dma-map-ops.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,29 @@ static inline int dma_mmap_from_global_coherent(struct vm_area_struct *vma,
203203
}
204204
#endif /* CONFIG_DMA_DECLARE_COHERENT */
205205

206+
int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
207+
void *cpu_addr, dma_addr_t dma_addr, size_t size,
208+
unsigned long attrs);
209+
int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
210+
void *cpu_addr, dma_addr_t dma_addr, size_t size,
211+
unsigned long attrs);
212+
struct page *dma_common_alloc_pages(struct device *dev, size_t size,
213+
dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp);
214+
void dma_common_free_pages(struct device *dev, size_t size, struct page *vaddr,
215+
dma_addr_t dma_handle, enum dma_data_direction dir);
216+
217+
struct page **dma_common_find_pages(void *cpu_addr);
218+
void *dma_common_contiguous_remap(struct page *page, size_t size, pgprot_t prot,
219+
const void *caller);
220+
void *dma_common_pages_remap(struct page **pages, size_t size, pgprot_t prot,
221+
const void *caller);
222+
void dma_common_free_remap(void *cpu_addr, size_t size);
223+
224+
struct page *dma_alloc_from_pool(struct device *dev, size_t size,
225+
void **cpu_addr, gfp_t flags,
226+
bool (*phys_addr_ok)(struct device *, phys_addr_t, size_t));
227+
bool dma_free_from_pool(struct device *dev, void *start, size_t size);
228+
206229
#ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H
207230
#include <asm/dma-coherence.h>
208231
#elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \

include/linux/dma-mapping.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -389,30 +389,6 @@ static inline void dma_sync_sgtable_for_device(struct device *dev,
389389
#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0)
390390
#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0)
391391

392-
extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
393-
void *cpu_addr, dma_addr_t dma_addr, size_t size,
394-
unsigned long attrs);
395-
struct page *dma_common_alloc_pages(struct device *dev, size_t size,
396-
dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp);
397-
void dma_common_free_pages(struct device *dev, size_t size, struct page *vaddr,
398-
dma_addr_t dma_handle, enum dma_data_direction dir);
399-
struct page **dma_common_find_pages(void *cpu_addr);
400-
void *dma_common_contiguous_remap(struct page *page, size_t size,
401-
pgprot_t prot, const void *caller);
402-
403-
void *dma_common_pages_remap(struct page **pages, size_t size,
404-
pgprot_t prot, const void *caller);
405-
void dma_common_free_remap(void *cpu_addr, size_t size);
406-
407-
struct page *dma_alloc_from_pool(struct device *dev, size_t size,
408-
void **cpu_addr, gfp_t flags,
409-
bool (*phys_addr_ok)(struct device *, phys_addr_t, size_t));
410-
bool dma_free_from_pool(struct device *dev, void *start, size_t size);
411-
412-
int
413-
dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr,
414-
dma_addr_t dma_addr, size_t size, unsigned long attrs);
415-
416392
static inline void *dma_alloc_coherent(struct device *dev, size_t size,
417393
dma_addr_t *dma_handle, gfp_t gfp)
418394
{

kernel/dma/remap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Copyright (c) 2014 The Linux Foundation
44
*/
5-
#include <linux/dma-mapping.h>
5+
#include <linux/dma-map-ops.h>
66
#include <linux/slab.h>
77
#include <linux/vmalloc.h>
88

0 commit comments

Comments
 (0)