Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+21 -24
+4 -5
Documentation/DMA-API.txt
··· 497 497 boundaries when doing this. 498 498 499 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 501 dma_addr_t device_addr, size_t size, int 502 502 flags) 503 503 504 504 Declare region of memory to be handed out by dma_alloc_coherent() when 505 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 508 - assigned in the bus responding region (this will be used by the 509 - platform to perform the mapping). 507 + phys_addr is the cpu physical address to which the memory is currently 508 + assigned (this will be ioremapped so the cpu can access the region). 510 509 511 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 512 dma_addr_t in dma_alloc_coherent()). 514 513 515 514 size is the size of the area (must be multiples of PAGE_SIZE).
+5 -5
drivers/base/dma-coherent.c
··· 10 10 struct dma_coherent_mem { 11 11 void *virt_base; 12 12 dma_addr_t device_base; 13 - phys_addr_t pfn_base; 13 + unsigned long pfn_base; 14 14 int size; 15 15 int flags; 16 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 20 dma_addr_t device_addr, size_t size, int flags) 21 21 { 22 22 void __iomem *mem_base = NULL; ··· 32 32 33 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 36 if (!mem_base) 37 37 goto out; 38 38 ··· 45 45 46 46 dev->dma_mem->virt_base = mem_base; 47 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 49 dev->dma_mem->size = pages; 50 50 dev->dma_mem->flags = flags; 51 51 ··· 208 208 209 209 *ret = -ENXIO; 210 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 212 *ret = remap_pfn_range(vma, vma->vm_start, pfn, 213 213 user_count << PAGE_SHIFT, 214 214 vma->vm_page_prot);
+3 -3
drivers/base/dma-mapping.c
··· 175 175 /** 176 176 * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() 177 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 179 * @device_addr: Device address of coherent memory to be declared 180 180 * @size: Size of coherent memory to be declared 181 181 * @flags: Flags ··· 185 185 * RETURNS: 186 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 189 dma_addr_t device_addr, size_t size, int flags) 190 190 { 191 191 void *res; ··· 195 195 if (!res) 196 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 199 flags); 200 200 if (rc == 0) 201 201 devres_add(dev, res);
+5 -8
include/asm-generic/dma-coherent.h
··· 16 16 * Standard interface 17 17 */ 18 18 #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 19 - extern int 20 - dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, 21 - dma_addr_t device_addr, size_t size, int flags); 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); 22 21 23 - extern void 24 - dma_release_declared_memory(struct device *dev); 22 + void dma_release_declared_memory(struct device *dev); 25 23 26 - extern void * 27 - dma_mark_declared_memory_occupied(struct device *dev, 28 - dma_addr_t device_addr, size_t size); 24 + void *dma_mark_declared_memory_occupied(struct device *dev, 25 + dma_addr_t device_addr, size_t size); 29 26 #else 30 27 #define dma_alloc_from_coherent(dev, size, handle, ret) (0) 31 28 #define dma_release_from_coherent(dev, order, vaddr) (0)
+4 -3
include/linux/dma-mapping.h
··· 192 192 193 193 #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY 194 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 196 dma_addr_t device_addr, size_t size, int flags) 197 197 { 198 198 return 0; ··· 223 223 extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, 224 224 dma_addr_t dma_handle); 225 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 228 dma_addr_t device_addr, size_t size, 228 229 int flags); 229 230 extern void dmam_release_declared_memory(struct device *dev); 230 231 #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ 231 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 234 size_t size, gfp_t gfp) 234 235 { 235 236 return 0;