diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2014-05-20 18:54:22 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-05-20 18:55:23 -0400 |
commit | 88a984ba0795f14a3847edbd7fabe652289ea89b (patch) | |
tree | cf82c612f595bf8296892ca5bfb0672d6d6f6f0f | |
parent | 77f2ea2f8d0833f9e976368481fb9a0775acf9e7 (diff) |
DMA-API: Change dma_declare_coherent_memory() CPU address to phys_addr_t
dma_declare_coherent_memory() takes two addresses for a region of memory: a
"bus_addr" and a "device_addr". I think the intent is that "bus_addr" is
the physical address a *CPU* would use to access the region, and
"device_addr" is the bus address the *device* would use to address the
region.
Rename "bus_addr" to "phys_addr" and change its type to phys_addr_t.
Most callers already supply a phys_addr_t for this argument. The others
supply a 32-bit integer (a constant, unsigned int, or __u32) and need no
change.
Use "unsigned long", not phys_addr_t, to hold PFNs.
No functional change (this could theoretically fix a truncation in a config
with 32-bit dma_addr_t and 64-bit phys_addr_t, but I don't think there are
any such cases involving this code).
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: James Bottomley <jbottomley@Parallels.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
-rw-r--r-- | Documentation/DMA-API.txt | 9 | ||||
-rw-r--r-- | drivers/base/dma-coherent.c | 10 | ||||
-rw-r--r-- | drivers/base/dma-mapping.c | 6 | ||||
-rw-r--r-- | include/asm-generic/dma-coherent.h | 13 | ||||
-rw-r--r-- | include/linux/dma-mapping.h | 7 |
5 files changed, 21 insertions, 24 deletions
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt index 1147eba43128..4f1cdc5febd1 100644 --- a/Documentation/DMA-API.txt +++ b/Documentation/DMA-API.txt | |||
@@ -497,19 +497,18 @@ continuing on for size. Again, you *must* observe the cache line | |||
497 | boundaries when doing this. | 497 | boundaries when doing this. |
498 | 498 | ||
499 | int | 499 | int |
500 | dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 500 | dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, |
501 | dma_addr_t device_addr, size_t size, int | 501 | dma_addr_t device_addr, size_t size, int |
502 | flags) | 502 | flags) |
503 | 503 | ||
504 | Declare region of memory to be handed out by dma_alloc_coherent() when | 504 | Declare region of memory to be handed out by dma_alloc_coherent() when |
505 | it's asked for coherent memory for this device. | 505 | it's asked for coherent memory for this device. |
506 | 506 | ||
507 | bus_addr is the physical address to which the memory is currently | 507 | phys_addr is the cpu physical address to which the memory is currently |
508 | assigned in the bus responding region (this will be used by the | 508 | assigned (this will be ioremapped so the cpu can access the region). |
509 | platform to perform the mapping). | ||
510 | 509 | ||
511 | device_addr is the bus address the device needs to be programmed | 510 | device_addr is the bus address the device needs to be programmed |
512 | with actually to address this memory (this will be handed out as the | 511 | with to actually address this memory (this will be handed out as the |
513 | dma_addr_t in dma_alloc_coherent()). | 512 | dma_addr_t in dma_alloc_coherent()). |
514 | 513 | ||
515 | size is the size of the area (must be multiples of PAGE_SIZE). | 514 | size is the size of the area (must be multiples of PAGE_SIZE). |
diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index bc256b641027..7d6e84a51424 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c | |||
@@ -10,13 +10,13 @@ | |||
10 | struct dma_coherent_mem { | 10 | struct dma_coherent_mem { |
11 | void *virt_base; | 11 | void *virt_base; |
12 | dma_addr_t device_base; | 12 | dma_addr_t device_base; |
13 | phys_addr_t pfn_base; | 13 | unsigned long pfn_base; |
14 | int size; | 14 | int size; |
15 | int flags; | 15 | int flags; |
16 | unsigned long *bitmap; | 16 | unsigned long *bitmap; |
17 | }; | 17 | }; |
18 | 18 | ||
19 | int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 19 | int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, |
20 | dma_addr_t device_addr, size_t size, int flags) | 20 | dma_addr_t device_addr, size_t size, int flags) |
21 | { | 21 | { |
22 | void __iomem *mem_base = NULL; | 22 | void __iomem *mem_base = NULL; |
@@ -32,7 +32,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | |||
32 | 32 | ||
33 | /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ | 33 | /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ |
34 | 34 | ||
35 | mem_base = ioremap(bus_addr, size); | 35 | mem_base = ioremap(phys_addr, size); |
36 | if (!mem_base) | 36 | if (!mem_base) |
37 | goto out; | 37 | goto out; |
38 | 38 | ||
@@ -45,7 +45,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | |||
45 | 45 | ||
46 | dev->dma_mem->virt_base = mem_base; | 46 | dev->dma_mem->virt_base = mem_base; |
47 | dev->dma_mem->device_base = device_addr; | 47 | dev->dma_mem->device_base = device_addr; |
48 | dev->dma_mem->pfn_base = PFN_DOWN(bus_addr); | 48 | dev->dma_mem->pfn_base = PFN_DOWN(phys_addr); |
49 | dev->dma_mem->size = pages; | 49 | dev->dma_mem->size = pages; |
50 | dev->dma_mem->flags = flags; | 50 | dev->dma_mem->flags = flags; |
51 | 51 | ||
@@ -208,7 +208,7 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma, | |||
208 | 208 | ||
209 | *ret = -ENXIO; | 209 | *ret = -ENXIO; |
210 | if (off < count && user_count <= count - off) { | 210 | if (off < count && user_count <= count - off) { |
211 | unsigned pfn = mem->pfn_base + start + off; | 211 | unsigned long pfn = mem->pfn_base + start + off; |
212 | *ret = remap_pfn_range(vma, vma->vm_start, pfn, | 212 | *ret = remap_pfn_range(vma, vma->vm_start, pfn, |
213 | user_count << PAGE_SHIFT, | 213 | user_count << PAGE_SHIFT, |
214 | vma->vm_page_prot); | 214 | vma->vm_page_prot); |
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 0ce39a33b3c2..6cd08e145bfa 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c | |||
@@ -175,7 +175,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res) | |||
175 | /** | 175 | /** |
176 | * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() | 176 | * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() |
177 | * @dev: Device to declare coherent memory for | 177 | * @dev: Device to declare coherent memory for |
178 | * @bus_addr: Bus address of coherent memory to be declared | 178 | * @phys_addr: Physical address of coherent memory to be declared |
179 | * @device_addr: Device address of coherent memory to be declared | 179 | * @device_addr: Device address of coherent memory to be declared |
180 | * @size: Size of coherent memory to be declared | 180 | * @size: Size of coherent memory to be declared |
181 | * @flags: Flags | 181 | * @flags: Flags |
@@ -185,7 +185,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res) | |||
185 | * RETURNS: | 185 | * RETURNS: |
186 | * 0 on success, -errno on failure. | 186 | * 0 on success, -errno on failure. |
187 | */ | 187 | */ |
188 | int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 188 | int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, |
189 | dma_addr_t device_addr, size_t size, int flags) | 189 | dma_addr_t device_addr, size_t size, int flags) |
190 | { | 190 | { |
191 | void *res; | 191 | void *res; |
@@ -195,7 +195,7 @@ int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | |||
195 | if (!res) | 195 | if (!res) |
196 | return -ENOMEM; | 196 | return -ENOMEM; |
197 | 197 | ||
198 | rc = dma_declare_coherent_memory(dev, bus_addr, device_addr, size, | 198 | rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size, |
199 | flags); | 199 | flags); |
200 | if (rc == 0) | 200 | if (rc == 0) |
201 | devres_add(dev, res); | 201 | devres_add(dev, res); |
diff --git a/include/asm-generic/dma-coherent.h b/include/asm-generic/dma-coherent.h index 2be8a2dbc868..0297e5875798 100644 --- a/include/asm-generic/dma-coherent.h +++ b/include/asm-generic/dma-coherent.h | |||
@@ -16,16 +16,13 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma, | |||
16 | * Standard interface | 16 | * Standard interface |
17 | */ | 17 | */ |
18 | #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY | 18 | #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY |
19 | extern int | 19 | int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, |
20 | dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 20 | dma_addr_t device_addr, size_t size, int flags); |
21 | dma_addr_t device_addr, size_t size, int flags); | ||
22 | 21 | ||
23 | extern void | 22 | void dma_release_declared_memory(struct device *dev); |
24 | dma_release_declared_memory(struct device *dev); | ||
25 | 23 | ||
26 | extern void * | 24 | void *dma_mark_declared_memory_occupied(struct device *dev, |
27 | dma_mark_declared_memory_occupied(struct device *dev, | 25 | dma_addr_t device_addr, size_t size); |
28 | dma_addr_t device_addr, size_t size); | ||
29 | #else | 26 | #else |
30 | #define dma_alloc_from_coherent(dev, size, handle, ret) (0) | 27 | #define dma_alloc_from_coherent(dev, size, handle, ret) (0) |
31 | #define dma_release_from_coherent(dev, order, vaddr) (0) | 28 | #define dma_release_from_coherent(dev, order, vaddr) (0) |
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index b9aa2b97aab5..0c3eab1e39ac 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h | |||
@@ -192,7 +192,7 @@ static inline int dma_get_cache_alignment(void) | |||
192 | 192 | ||
193 | #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY | 193 | #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY |
194 | static inline int | 194 | static inline int |
195 | dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 195 | dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, |
196 | dma_addr_t device_addr, size_t size, int flags) | 196 | dma_addr_t device_addr, size_t size, int flags) |
197 | { | 197 | { |
198 | return 0; | 198 | return 0; |
@@ -223,13 +223,14 @@ extern void *dmam_alloc_noncoherent(struct device *dev, size_t size, | |||
223 | extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, | 223 | extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, |
224 | dma_addr_t dma_handle); | 224 | dma_addr_t dma_handle); |
225 | #ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY | 225 | #ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY |
226 | extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | 226 | extern int dmam_declare_coherent_memory(struct device *dev, |
227 | phys_addr_t phys_addr, | ||
227 | dma_addr_t device_addr, size_t size, | 228 | dma_addr_t device_addr, size_t size, |
228 | int flags); | 229 | int flags); |
229 | extern void dmam_release_declared_memory(struct device *dev); | 230 | extern void dmam_release_declared_memory(struct device *dev); |
230 | #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ | 231 | #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ |
231 | static inline int dmam_declare_coherent_memory(struct device *dev, | 232 | static inline int dmam_declare_coherent_memory(struct device *dev, |
232 | dma_addr_t bus_addr, dma_addr_t device_addr, | 233 | phys_addr_t phys_addr, dma_addr_t device_addr, |
233 | size_t size, gfp_t gfp) | 234 | size_t size, gfp_t gfp) |
234 | { | 235 | { |
235 | return 0; | 236 | return 0; |