aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/acpi.h2
-rw-r--r--include/linux/device.h7
-rw-r--r--include/linux/dma-debug.h8
-rw-r--r--include/linux/dma-direct.h8
-rw-r--r--include/linux/dma-mapping.h42
-rw-r--r--include/linux/dma-noncoherent.h27
-rw-r--r--include/linux/of_device.h3
7 files changed, 62 insertions, 35 deletions
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index de8d3d3fa651..af4628979d13 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -831,8 +831,6 @@ static inline int acpi_dma_configure(struct device *dev,
831 return 0; 831 return 0;
832} 832}
833 833
834static inline void acpi_dma_deconfigure(struct device *dev) { }
835
836#define ACPI_PTR(_ptr) (NULL) 834#define ACPI_PTR(_ptr) (NULL)
837 835
838static inline void acpi_device_set_enumerated(struct acpi_device *adev) 836static inline void acpi_device_set_enumerated(struct acpi_device *adev)
diff --git a/include/linux/device.h b/include/linux/device.h
index 8f882549edee..983506789402 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -927,6 +927,8 @@ struct dev_links_info {
927 * @offline: Set after successful invocation of bus type's .offline(). 927 * @offline: Set after successful invocation of bus type's .offline().
928 * @of_node_reused: Set if the device-tree node is shared with an ancestor 928 * @of_node_reused: Set if the device-tree node is shared with an ancestor
929 * device. 929 * device.
930 * @dma_coherent: this particular device is dma coherent, even if the
931 * architecture supports non-coherent devices.
930 * 932 *
931 * At the lowest level, every device in a Linux system is represented by an 933 * At the lowest level, every device in a Linux system is represented by an
932 * instance of struct device. The device structure contains the information 934 * instance of struct device. The device structure contains the information
@@ -1016,6 +1018,11 @@ struct device {
1016 bool offline_disabled:1; 1018 bool offline_disabled:1;
1017 bool offline:1; 1019 bool offline:1;
1018 bool of_node_reused:1; 1020 bool of_node_reused:1;
1021#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
1022 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
1023 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
1024 bool dma_coherent:1;
1025#endif
1019}; 1026};
1020 1027
1021static inline struct device *kobj_to_dev(struct kobject *kobj) 1028static inline struct device *kobj_to_dev(struct kobject *kobj)
diff --git a/include/linux/dma-debug.h b/include/linux/dma-debug.h
index a785f2507159..30213adbb6b9 100644
--- a/include/linux/dma-debug.h
+++ b/include/linux/dma-debug.h
@@ -32,6 +32,9 @@ extern void dma_debug_add_bus(struct bus_type *bus);
32 32
33extern int dma_debug_resize_entries(u32 num_entries); 33extern int dma_debug_resize_entries(u32 num_entries);
34 34
35extern void debug_dma_map_single(struct device *dev, const void *addr,
36 unsigned long len);
37
35extern void debug_dma_map_page(struct device *dev, struct page *page, 38extern void debug_dma_map_page(struct device *dev, struct page *page,
36 size_t offset, size_t size, 39 size_t offset, size_t size,
37 int direction, dma_addr_t dma_addr, 40 int direction, dma_addr_t dma_addr,
@@ -103,6 +106,11 @@ static inline int dma_debug_resize_entries(u32 num_entries)
103 return 0; 106 return 0;
104} 107}
105 108
109static inline void debug_dma_map_single(struct device *dev, const void *addr,
110 unsigned long len)
111{
112}
113
106static inline void debug_dma_map_page(struct device *dev, struct page *page, 114static inline void debug_dma_map_page(struct device *dev, struct page *page,
107 size_t offset, size_t size, 115 size_t offset, size_t size,
108 int direction, dma_addr_t dma_addr, 116 int direction, dma_addr_t dma_addr,
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index 8d9f33febde5..fbca184ff5a0 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -27,7 +27,8 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
27 if (!dev->dma_mask) 27 if (!dev->dma_mask)
28 return false; 28 return false;
29 29
30 return addr + size - 1 <= *dev->dma_mask; 30 return addr + size - 1 <=
31 min_not_zero(*dev->dma_mask, dev->bus_dma_mask);
31} 32}
32#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */ 33#endif /* !CONFIG_ARCH_HAS_PHYS_TO_DMA */
33 34
@@ -55,10 +56,15 @@ static inline void dma_mark_clean(void *addr, size_t size)
55} 56}
56#endif /* CONFIG_ARCH_HAS_DMA_MARK_CLEAN */ 57#endif /* CONFIG_ARCH_HAS_DMA_MARK_CLEAN */
57 58
59u64 dma_direct_get_required_mask(struct device *dev);
58void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, 60void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
59 gfp_t gfp, unsigned long attrs); 61 gfp_t gfp, unsigned long attrs);
60void dma_direct_free(struct device *dev, size_t size, void *cpu_addr, 62void dma_direct_free(struct device *dev, size_t size, void *cpu_addr,
61 dma_addr_t dma_addr, unsigned long attrs); 63 dma_addr_t dma_addr, unsigned long attrs);
64void *dma_direct_alloc_pages(struct device *dev, size_t size,
65 dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs);
66void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
67 dma_addr_t dma_addr, unsigned long attrs);
62dma_addr_t dma_direct_map_page(struct device *dev, struct page *page, 68dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
63 unsigned long offset, size_t size, enum dma_data_direction dir, 69 unsigned long offset, size_t size, enum dma_data_direction dir,
64 unsigned long attrs); 70 unsigned long attrs);
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 1db6a6b46d0d..15bd41447025 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -130,13 +130,10 @@ struct dma_map_ops {
130 enum dma_data_direction direction); 130 enum dma_data_direction direction);
131 int (*mapping_error)(struct device *dev, dma_addr_t dma_addr); 131 int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
132 int (*dma_supported)(struct device *dev, u64 mask); 132 int (*dma_supported)(struct device *dev, u64 mask);
133#ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK
134 u64 (*get_required_mask)(struct device *dev); 133 u64 (*get_required_mask)(struct device *dev);
135#endif
136}; 134};
137 135
138extern const struct dma_map_ops dma_direct_ops; 136extern const struct dma_map_ops dma_direct_ops;
139extern const struct dma_map_ops dma_noncoherent_ops;
140extern const struct dma_map_ops dma_virt_ops; 137extern const struct dma_map_ops dma_virt_ops;
141 138
142#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1)) 139#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
@@ -232,6 +229,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
232 dma_addr_t addr; 229 dma_addr_t addr;
233 230
234 BUG_ON(!valid_dma_direction(dir)); 231 BUG_ON(!valid_dma_direction(dir));
232 debug_dma_map_single(dev, ptr, size);
235 addr = ops->map_page(dev, virt_to_page(ptr), 233 addr = ops->map_page(dev, virt_to_page(ptr),
236 offset_in_page(ptr), size, 234 offset_in_page(ptr), size,
237 dir, attrs); 235 dir, attrs);
@@ -445,7 +443,8 @@ dma_cache_sync(struct device *dev, void *vaddr, size_t size,
445} 443}
446 444
447extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, 445extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
448 void *cpu_addr, dma_addr_t dma_addr, size_t size); 446 void *cpu_addr, dma_addr_t dma_addr, size_t size,
447 unsigned long attrs);
449 448
450void *dma_common_contiguous_remap(struct page *page, size_t size, 449void *dma_common_contiguous_remap(struct page *page, size_t size,
451 unsigned long vm_flags, 450 unsigned long vm_flags,
@@ -477,14 +476,14 @@ dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, void *cpu_addr,
477 BUG_ON(!ops); 476 BUG_ON(!ops);
478 if (ops->mmap) 477 if (ops->mmap)
479 return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs); 478 return ops->mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
480 return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); 479 return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size, attrs);
481} 480}
482 481
483#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0) 482#define dma_mmap_coherent(d, v, c, h, s) dma_mmap_attrs(d, v, c, h, s, 0)
484 483
485int 484int
486dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, 485dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr,
487 void *cpu_addr, dma_addr_t dma_addr, size_t size); 486 dma_addr_t dma_addr, size_t size, unsigned long attrs);
488 487
489static inline int 488static inline int
490dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr, 489dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
@@ -496,7 +495,8 @@ dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr,
496 if (ops->get_sgtable) 495 if (ops->get_sgtable)
497 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size, 496 return ops->get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
498 attrs); 497 attrs);
499 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size); 498 return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size,
499 attrs);
500} 500}
501 501
502#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0) 502#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, 0)
@@ -558,9 +558,11 @@ static inline void dma_free_attrs(struct device *dev, size_t size,
558} 558}
559 559
560static inline void *dma_alloc_coherent(struct device *dev, size_t size, 560static inline void *dma_alloc_coherent(struct device *dev, size_t size,
561 dma_addr_t *dma_handle, gfp_t flag) 561 dma_addr_t *dma_handle, gfp_t gfp)
562{ 562{
563 return dma_alloc_attrs(dev, size, dma_handle, flag, 0); 563
564 return dma_alloc_attrs(dev, size, dma_handle, gfp,
565 (gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0);
564} 566}
565 567
566static inline void dma_free_coherent(struct device *dev, size_t size, 568static inline void dma_free_coherent(struct device *dev, size_t size,
@@ -753,18 +755,6 @@ dma_mark_declared_memory_occupied(struct device *dev,
753} 755}
754#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ 756#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
755 757
756#ifdef CONFIG_HAS_DMA
757int dma_configure(struct device *dev);
758void dma_deconfigure(struct device *dev);
759#else
760static inline int dma_configure(struct device *dev)
761{
762 return 0;
763}
764
765static inline void dma_deconfigure(struct device *dev) {}
766#endif
767
768/* 758/*
769 * Managed DMA API 759 * Managed DMA API
770 */ 760 */
@@ -806,8 +796,12 @@ static inline void dmam_release_declared_memory(struct device *dev)
806static inline void *dma_alloc_wc(struct device *dev, size_t size, 796static inline void *dma_alloc_wc(struct device *dev, size_t size,
807 dma_addr_t *dma_addr, gfp_t gfp) 797 dma_addr_t *dma_addr, gfp_t gfp)
808{ 798{
809 return dma_alloc_attrs(dev, size, dma_addr, gfp, 799 unsigned long attrs = DMA_ATTR_NO_WARN;
810 DMA_ATTR_WRITE_COMBINE); 800
801 if (gfp & __GFP_NOWARN)
802 attrs |= DMA_ATTR_NO_WARN;
803
804 return dma_alloc_attrs(dev, size, dma_addr, gfp, attrs);
811} 805}
812#ifndef dma_alloc_writecombine 806#ifndef dma_alloc_writecombine
813#define dma_alloc_writecombine dma_alloc_wc 807#define dma_alloc_writecombine dma_alloc_wc
diff --git a/include/linux/dma-noncoherent.h b/include/linux/dma-noncoherent.h
index a0aa00cc909d..9051b055beec 100644
--- a/include/linux/dma-noncoherent.h
+++ b/include/linux/dma-noncoherent.h
@@ -4,18 +4,35 @@
4 4
5#include <linux/dma-mapping.h> 5#include <linux/dma-mapping.h>
6 6
7#ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H
8#include <asm/dma-coherence.h>
9#elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
10 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
11 defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
12static inline bool dev_is_dma_coherent(struct device *dev)
13{
14 return dev->dma_coherent;
15}
16#else
17static inline bool dev_is_dma_coherent(struct device *dev)
18{
19 return true;
20}
21#endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
22
7void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, 23void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
8 gfp_t gfp, unsigned long attrs); 24 gfp_t gfp, unsigned long attrs);
9void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, 25void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
10 dma_addr_t dma_addr, unsigned long attrs); 26 dma_addr_t dma_addr, unsigned long attrs);
27long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
28 dma_addr_t dma_addr);
11 29
12#ifdef CONFIG_DMA_NONCOHERENT_MMAP 30#ifdef CONFIG_ARCH_HAS_DMA_MMAP_PGPROT
13int arch_dma_mmap(struct device *dev, struct vm_area_struct *vma, 31pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
14 void *cpu_addr, dma_addr_t dma_addr, size_t size,
15 unsigned long attrs); 32 unsigned long attrs);
16#else 33#else
17#define arch_dma_mmap NULL 34# define arch_dma_mmap_pgprot(dev, prot, attrs) pgprot_noncached(prot)
18#endif /* CONFIG_DMA_NONCOHERENT_MMAP */ 35#endif
19 36
20#ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC 37#ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC
21void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size, 38void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 165fd302b442..8d31e39dd564 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -58,7 +58,6 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
58int of_dma_configure(struct device *dev, 58int of_dma_configure(struct device *dev,
59 struct device_node *np, 59 struct device_node *np,
60 bool force_dma); 60 bool force_dma);
61void of_dma_deconfigure(struct device *dev);
62#else /* CONFIG_OF */ 61#else /* CONFIG_OF */
63 62
64static inline int of_driver_match_device(struct device *dev, 63static inline int of_driver_match_device(struct device *dev,
@@ -113,8 +112,6 @@ static inline int of_dma_configure(struct device *dev,
113{ 112{
114 return 0; 113 return 0;
115} 114}
116static inline void of_dma_deconfigure(struct device *dev)
117{}
118#endif /* CONFIG_OF */ 115#endif /* CONFIG_OF */
119 116
120#endif /* _LINUX_OF_DEVICE_H */ 117#endif /* _LINUX_OF_DEVICE_H */