Skip to content

Commit 5a32c34

Browse files
committed
Merge tag 'dma-mapping-5.10' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: - rework the non-coherent DMA allocator - move private definitions out of <linux/dma-mapping.h> - lower CMA_ALIGNMENT (Paul Cercueil) - remove the omap1 dma address translation in favor of the common code - make dma-direct aware of multiple dma offset ranges (Jim Quinlan) - support per-node DMA CMA areas (Barry Song) - increase the default seg boundary limit (Nicolin Chen) - misc fixes (Robin Murphy, Thomas Tai, Xu Wang) - various cleanups * tag 'dma-mapping-5.10' of git://git.infradead.org/users/hch/dma-mapping: (63 commits) ARM/ixp4xx: add a missing include of dma-map-ops.h dma-direct: simplify the DMA_ATTR_NO_KERNEL_MAPPING handling dma-direct: factor out a dma_direct_alloc_from_pool helper dma-direct check for highmem pages in dma_direct_alloc_pages dma-mapping: merge <linux/dma-noncoherent.h> into <linux/dma-map-ops.h> dma-mapping: move large parts of <linux/dma-direct.h> to kernel/dma dma-mapping: move dma-debug.h to kernel/dma/ dma-mapping: remove <asm/dma-contiguous.h> dma-mapping: merge <linux/dma-contiguous.h> into <linux/dma-map-ops.h> dma-contiguous: remove dma_contiguous_set_default dma-contiguous: remove dev_set_cma_area dma-contiguous: remove dma_declare_contiguous dma-mapping: split <linux/dma-mapping.h> cma: decrease CMA_ALIGNMENT lower limit to 2 firewire-ohci: use dma_alloc_pages dma-iommu: implement ->alloc_noncoherent dma-mapping: add new {alloc,free}_noncoherent dma_map_ops methods dma-mapping: add a new dma_alloc_pages API dma-mapping: remove dma_cache_sync 53c700: convert to dma_alloc_noncoherent ...
2 parents f065199 + 2a410d0 commit 5a32c34

File tree

170 files changed

+1921
-1699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1921
-1699
lines changed

Documentation/admin-guide/kernel-parameters.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,18 @@
597597
placement constraint by the physical address range of
598598
memory allocations. A value of 0 disables CMA
599599
altogether. For more information, see
600-
include/linux/dma-contiguous.h
600+
kernel/dma/contiguous.c
601+
602+
cma_pernuma=nn[MG]
603+
[ARM64,KNL]
604+
Sets the size of kernel per-numa memory area for
605+
contiguous memory allocations. A value of 0 disables
606+
per-numa CMA altogether. And If this option is not
607+
specificed, the default value is 0.
608+
With per-numa CMA enabled, DMA users on node nid will
609+
first try to allocate buffer from the pernuma area
610+
which is located in node nid, if the allocation fails,
611+
they will fallback to the global default memory area.
601612

602613
cmo_free_hint= [PPC] Format: { yes | no }
603614
Specify whether pages are marked as being inactive

Documentation/core-api/dma-api.rst

+36-63
Original file line numberDiff line numberDiff line change
@@ -516,48 +516,56 @@ routines, e.g.:::
516516
}
517517

518518

519-
Part II - Advanced dma usage
520-
----------------------------
519+
Part II - Non-coherent DMA allocations
520+
--------------------------------------
521521

522-
Warning: These pieces of the DMA API should not be used in the
523-
majority of cases, since they cater for unlikely corner cases that
524-
don't belong in usual drivers.
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.
525526

526-
If you don't understand how cache line coherency works between a
527-
processor and an I/O device, you should not be using this part of the
528-
API at all.
527+
If you don't understand how cache line coherency works between a processor and
528+
an I/O device, you should not be using this part of the API.
529529

530530
::
531531

532532
void *
533-
dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
534-
gfp_t flag, unsigned long attrs)
533+
dma_alloc_noncoherent(struct device *dev, size_t size,
534+
dma_addr_t *dma_handle, enum dma_data_direction dir,
535+
gfp_t gfp)
535536

536-
Identical to dma_alloc_coherent() except that when the
537-
DMA_ATTR_NON_CONSISTENT flags is passed in the attrs argument, the
538-
platform will choose to return either consistent or non-consistent memory
539-
as it sees fit. By using this API, you are guaranteeing to the platform
540-
that you have all the correct and necessary sync points for this memory
541-
in the driver should it choose to return non-consistent memory.
537+
This routine allocates a region of <size> bytes of consistent memory. It
538+
returns a pointer to the allocated region (in the processor's virtual address
539+
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
541+
the returned memory region.
542542

543-
Note: where the platform can return consistent memory, it will
544-
guarantee that the sync points become nops.
543+
It also returns a <dma_handle> which may be cast to an unsigned integer the
544+
same width as the bus and given to the device as the DMA address base of
545+
the region.
546+
547+
The dir parameter specified if data is read and/or written by the device,
548+
see dma_map_single() for details.
549+
550+
The gfp parameter allows the caller to specify the ``GFP_`` flags (see
551+
kmalloc()) for the allocation, but rejects flags used to specify a memory
552+
zone such as GFP_DMA or GFP_HIGHMEM.
545553

546-
Warning: Handling non-consistent memory is a real pain. You should
547-
only use this API if you positively know your driver will be
548-
required to work on one of the rare (usually non-PCI) architectures
549-
that simply cannot make consistent memory.
554+
Before giving the memory to the device, dma_sync_single_for_device() needs
555+
to be called, and before reading memory written by the device,
556+
dma_sync_single_for_cpu(), just like for streaming DMA mappings that are
557+
reused.
550558

551559
::
552560

553561
void
554-
dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
555-
dma_addr_t dma_handle, unsigned long attrs)
562+
dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
563+
dma_addr_t dma_handle, enum dma_data_direction dir)
556564

557-
Free memory allocated by the dma_alloc_attrs(). All common
558-
parameters must be identical to those otherwise passed to dma_free_coherent,
559-
and the attrs argument must be identical to the attrs passed to
560-
dma_alloc_attrs().
565+
Free a region of memory previously allocated using dma_alloc_noncoherent().
566+
dev, size and dma_handle and dir must all be the same as those passed into
567+
dma_alloc_noncoherent(). cpu_addr must be the virtual address returned by
568+
the dma_alloc_noncoherent().
561569

562570
::
563571

@@ -575,41 +583,6 @@ memory or doing partial flushes.
575583
into the width returned by this call. It will also always be a power
576584
of two for easy alignment.
577585

578-
::
579-
580-
void
581-
dma_cache_sync(struct device *dev, void *vaddr, size_t size,
582-
enum dma_data_direction direction)
583-
584-
Do a partial sync of memory that was allocated by dma_alloc_attrs() with
585-
the DMA_ATTR_NON_CONSISTENT flag starting at virtual address vaddr and
586-
continuing on for size. Again, you *must* observe the cache line
587-
boundaries when doing this.
588-
589-
::
590-
591-
int
592-
dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
593-
dma_addr_t device_addr, size_t size);
594-
595-
Declare region of memory to be handed out by dma_alloc_coherent() when
596-
it's asked for coherent memory for this device.
597-
598-
phys_addr is the CPU physical address to which the memory is currently
599-
assigned (this will be ioremapped so the CPU can access the region).
600-
601-
device_addr is the DMA address the device needs to be programmed
602-
with to actually address this memory (this will be handed out as the
603-
dma_addr_t in dma_alloc_coherent()).
604-
605-
size is the size of the area (must be multiples of PAGE_SIZE).
606-
607-
As a simplification for the platforms, only *one* such region of
608-
memory may be declared per device.
609-
610-
For reasons of efficiency, most platforms choose to track the declared
611-
region only at the granularity of a page. For smaller allocations,
612-
you should use the dma_pool() API.
613586

614587
Part III - Debug drivers use of the DMA-API
615588
-------------------------------------------

Documentation/core-api/dma-attributes.rst

-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ Since it is optional for platforms to implement DMA_ATTR_WRITE_COMBINE,
2525
those that do not will simply ignore the attribute and exhibit default
2626
behavior.
2727

28-
DMA_ATTR_NON_CONSISTENT
29-
-----------------------
30-
31-
DMA_ATTR_NON_CONSISTENT lets the platform to choose to return either
32-
consistent or non-consistent memory as it sees fit. By using this API,
33-
you are guaranteeing to the platform that you have all the correct and
34-
necessary sync points for this memory in the driver.
35-
3628
DMA_ATTR_NO_KERNEL_MAPPING
3729
--------------------------
3830

MAINTAINERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -5216,7 +5216,7 @@ T: git git://git.infradead.org/users/hch/dma-mapping.git
52165216
F: include/asm-generic/dma-mapping.h
52175217
F: include/linux/dma-direct.h
52185218
F: include/linux/dma-mapping.h
5219-
F: include/linux/dma-noncoherent.h
5219+
F: include/linux/dma-map-ops.h
52205220
F: kernel/dma/
52215221

52225222
DMA-BUF HEAPS FRAMEWORK

arch/alpha/kernel/pci_iommu.c

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/export.h>
1212
#include <linux/scatterlist.h>
1313
#include <linux/log2.h>
14-
#include <linux/dma-mapping.h>
14+
#include <linux/dma-map-ops.h>
1515
#include <linux/iommu-helper.h>
1616

1717
#include <asm/io.h>
@@ -141,12 +141,7 @@ iommu_arena_find_pages(struct device *dev, struct pci_iommu_arena *arena,
141141
unsigned long boundary_size;
142142

143143
base = arena->dma_base >> PAGE_SHIFT;
144-
if (dev) {
145-
boundary_size = dma_get_seg_boundary(dev) + 1;
146-
boundary_size >>= PAGE_SHIFT;
147-
} else {
148-
boundary_size = 1UL << (32 - PAGE_SHIFT);
149-
}
144+
boundary_size = dma_get_seg_boundary_nr_pages(dev, PAGE_SHIFT);
150145

151146
/* Search forward for the first mask-aligned sequence of N free ptes */
152147
ptes = arena->ptes;
@@ -957,5 +952,7 @@ const struct dma_map_ops alpha_pci_ops = {
957952
.dma_supported = alpha_pci_supported,
958953
.mmap = dma_common_mmap,
959954
.get_sgtable = dma_common_get_sgtable,
955+
.alloc_pages = dma_common_alloc_pages,
956+
.free_pages = dma_common_free_pages,
960957
};
961958
EXPORT_SYMBOL(alpha_pci_ops);

arch/arc/mm/dma.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
44
*/
55

6-
#include <linux/dma-noncoherent.h>
6+
#include <linux/dma-map-ops.h>
77
#include <asm/cache.h>
88
#include <asm/cacheflush.h>
99

arch/arm/common/dmabounce.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include <linux/slab.h>
2525
#include <linux/page-flags.h>
2626
#include <linux/device.h>
27-
#include <linux/dma-mapping.h>
27+
#include <linux/dma-direct.h>
28+
#include <linux/dma-map-ops.h>
2829
#include <linux/dmapool.h>
2930
#include <linux/list.h>
3031
#include <linux/scatterlist.h>

arch/arm/include/asm/dma-contiguous.h

-15
This file was deleted.

arch/arm/include/asm/dma-direct.h

+33-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,44 @@
22
#ifndef ASM_ARM_DMA_DIRECT_H
33
#define ASM_ARM_DMA_DIRECT_H 1
44

5-
static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
5+
#include <asm/memory.h>
6+
7+
/*
8+
* dma_to_pfn/pfn_to_dma/virt_to_dma are architecture private
9+
* functions used internally by the DMA-mapping API to provide DMA
10+
* addresses. They must not be used by drivers.
11+
*/
12+
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
13+
{
14+
if (dev && dev->dma_range_map)
15+
pfn = PFN_DOWN(translate_phys_to_dma(dev, PFN_PHYS(pfn)));
16+
return (dma_addr_t)__pfn_to_bus(pfn);
17+
}
18+
19+
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
20+
{
21+
unsigned long pfn = __bus_to_pfn(addr);
22+
23+
if (dev && dev->dma_range_map)
24+
pfn = PFN_DOWN(translate_dma_to_phys(dev, PFN_PHYS(pfn)));
25+
return pfn;
26+
}
27+
28+
static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
29+
{
30+
if (dev)
31+
return pfn_to_dma(dev, virt_to_pfn(addr));
32+
33+
return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
34+
}
35+
36+
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
637
{
738
unsigned int offset = paddr & ~PAGE_MASK;
839
return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
940
}
1041

11-
static inline phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t dev_addr)
42+
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
1243
{
1344
unsigned int offset = dev_addr & ~PAGE_MASK;
1445
return __pfn_to_phys(dma_to_pfn(dev, dev_addr)) + offset;

arch/arm/include/asm/dma-iommu.h

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include <linux/mm_types.h>
88
#include <linux/scatterlist.h>
9-
#include <linux/dma-debug.h>
109
#include <linux/kref.h>
1110

1211
struct dma_iommu_mapping {

arch/arm/include/asm/dma-mapping.h

-71
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
#include <linux/mm_types.h>
88
#include <linux/scatterlist.h>
9-
#include <linux/dma-debug.h>
10-
11-
#include <asm/memory.h>
129

1310
#include <xen/xen.h>
1411
#include <asm/xen/hypervisor.h>
@@ -23,74 +20,6 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
2320
return NULL;
2421
}
2522

26-
#ifdef __arch_page_to_dma
27-
#error Please update to __arch_pfn_to_dma
28-
#endif
29-
30-
/*
31-
* dma_to_pfn/pfn_to_dma/dma_to_virt/virt_to_dma are architecture private
32-
* functions used internally by the DMA-mapping API to provide DMA
33-
* addresses. They must not be used by drivers.
34-
*/
35-
#ifndef __arch_pfn_to_dma
36-
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
37-
{
38-
if (dev)
39-
pfn -= dev->dma_pfn_offset;
40-
return (dma_addr_t)__pfn_to_bus(pfn);
41-
}
42-
43-
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
44-
{
45-
unsigned long pfn = __bus_to_pfn(addr);
46-
47-
if (dev)
48-
pfn += dev->dma_pfn_offset;
49-
50-
return pfn;
51-
}
52-
53-
static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
54-
{
55-
if (dev) {
56-
unsigned long pfn = dma_to_pfn(dev, addr);
57-
58-
return phys_to_virt(__pfn_to_phys(pfn));
59-
}
60-
61-
return (void *)__bus_to_virt((unsigned long)addr);
62-
}
63-
64-
static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
65-
{
66-
if (dev)
67-
return pfn_to_dma(dev, virt_to_pfn(addr));
68-
69-
return (dma_addr_t)__virt_to_bus((unsigned long)(addr));
70-
}
71-
72-
#else
73-
static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn)
74-
{
75-
return __arch_pfn_to_dma(dev, pfn);
76-
}
77-
78-
static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr)
79-
{
80-
return __arch_dma_to_pfn(dev, addr);
81-
}
82-
83-
static inline void *dma_to_virt(struct device *dev, dma_addr_t addr)
84-
{
85-
return __arch_dma_to_virt(dev, addr);
86-
}
87-
88-
static inline dma_addr_t virt_to_dma(struct device *dev, void *addr)
89-
{
90-
return __arch_virt_to_dma(dev, addr);
91-
}
92-
#endif
93-
9423
/**
9524
* arm_dma_alloc - allocate consistent memory for DMA
9625
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices

0 commit comments

Comments
 (0)