Commit 88a984ba authored by Bjorn Helgaas's avatar Bjorn Helgaas

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: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarJames Bottomley <jbottomley@Parallels.com>
Acked-by: default avatarRandy Dunlap <rdunlap@infradead.org>
parent 77f2ea2f
...@@ -497,19 +497,18 @@ continuing on for size. Again, you *must* observe the cache line ...@@ -497,19 +497,18 @@ continuing on for size. Again, you *must* observe the cache line
boundaries when doing this. boundaries when doing this.
int int
dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
dma_addr_t device_addr, size_t size, int dma_addr_t device_addr, size_t size, int
flags) flags)
Declare region of memory to be handed out by dma_alloc_coherent() when Declare region of memory to be handed out by dma_alloc_coherent() when
it's asked for coherent memory for this device. it's asked for coherent memory for this device.
bus_addr is the physical address to which the memory is currently phys_addr is the cpu physical address to which the memory is currently
assigned in the bus responding region (this will be used by the assigned (this will be ioremapped so the cpu can access the region).
platform to perform the mapping).
device_addr is the bus address the device needs to be programmed device_addr is the bus address the device needs to be programmed
with actually to address this memory (this will be handed out as the with to actually address this memory (this will be handed out as the
dma_addr_t in dma_alloc_coherent()). dma_addr_t in dma_alloc_coherent()).
size is the size of the area (must be multiples of PAGE_SIZE). size is the size of the area (must be multiples of PAGE_SIZE).
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
struct dma_coherent_mem { struct dma_coherent_mem {
void *virt_base; void *virt_base;
dma_addr_t device_base; dma_addr_t device_base;
phys_addr_t pfn_base; unsigned long pfn_base;
int size; int size;
int flags; int flags;
unsigned long *bitmap; unsigned long *bitmap;
}; };
int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
dma_addr_t device_addr, size_t size, int flags) dma_addr_t device_addr, size_t size, int flags)
{ {
void __iomem *mem_base = NULL; void __iomem *mem_base = NULL;
...@@ -32,7 +32,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, ...@@ -32,7 +32,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
/* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */
mem_base = ioremap(bus_addr, size); mem_base = ioremap(phys_addr, size);
if (!mem_base) if (!mem_base)
goto out; goto out;
...@@ -45,7 +45,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, ...@@ -45,7 +45,7 @@ int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
dev->dma_mem->virt_base = mem_base; dev->dma_mem->virt_base = mem_base;
dev->dma_mem->device_base = device_addr; dev->dma_mem->device_base = device_addr;
dev->dma_mem->pfn_base = PFN_DOWN(bus_addr); dev->dma_mem->pfn_base = PFN_DOWN(phys_addr);
dev->dma_mem->size = pages; dev->dma_mem->size = pages;
dev->dma_mem->flags = flags; dev->dma_mem->flags = flags;
...@@ -208,7 +208,7 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma, ...@@ -208,7 +208,7 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
*ret = -ENXIO; *ret = -ENXIO;
if (off < count && user_count <= count - off) { if (off < count && user_count <= count - off) {
unsigned pfn = mem->pfn_base + start + off; unsigned long pfn = mem->pfn_base + start + off;
*ret = remap_pfn_range(vma, vma->vm_start, pfn, *ret = remap_pfn_range(vma, vma->vm_start, pfn,
user_count << PAGE_SHIFT, user_count << PAGE_SHIFT,
vma->vm_page_prot); vma->vm_page_prot);
......
...@@ -175,7 +175,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res) ...@@ -175,7 +175,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res)
/** /**
* dmam_declare_coherent_memory - Managed dma_declare_coherent_memory() * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory()
* @dev: Device to declare coherent memory for * @dev: Device to declare coherent memory for
* @bus_addr: Bus address of coherent memory to be declared * @phys_addr: Physical address of coherent memory to be declared
* @device_addr: Device address of coherent memory to be declared * @device_addr: Device address of coherent memory to be declared
* @size: Size of coherent memory to be declared * @size: Size of coherent memory to be declared
* @flags: Flags * @flags: Flags
...@@ -185,7 +185,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res) ...@@ -185,7 +185,7 @@ static void dmam_coherent_decl_release(struct device *dev, void *res)
* RETURNS: * RETURNS:
* 0 on success, -errno on failure. * 0 on success, -errno on failure.
*/ */
int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
dma_addr_t device_addr, size_t size, int flags) dma_addr_t device_addr, size_t size, int flags)
{ {
void *res; void *res;
...@@ -195,7 +195,7 @@ int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, ...@@ -195,7 +195,7 @@ int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
if (!res) if (!res)
return -ENOMEM; return -ENOMEM;
rc = dma_declare_coherent_memory(dev, bus_addr, device_addr, size, rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size,
flags); flags);
if (rc == 0) if (rc == 0)
devres_add(dev, res); devres_add(dev, res);
......
...@@ -16,15 +16,12 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma, ...@@ -16,15 +16,12 @@ int dma_mmap_from_coherent(struct device *dev, struct vm_area_struct *vma,
* Standard interface * Standard interface
*/ */
#define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
extern int int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
dma_addr_t device_addr, size_t size, int flags); dma_addr_t device_addr, size_t size, int flags);
extern void void dma_release_declared_memory(struct device *dev);
dma_release_declared_memory(struct device *dev);
extern void * void *dma_mark_declared_memory_occupied(struct device *dev,
dma_mark_declared_memory_occupied(struct device *dev,
dma_addr_t device_addr, size_t size); dma_addr_t device_addr, size_t size);
#else #else
#define dma_alloc_from_coherent(dev, size, handle, ret) (0) #define dma_alloc_from_coherent(dev, size, handle, ret) (0)
......
...@@ -192,7 +192,7 @@ static inline int dma_get_cache_alignment(void) ...@@ -192,7 +192,7 @@ static inline int dma_get_cache_alignment(void)
#ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY #ifndef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
static inline int static inline int
dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
dma_addr_t device_addr, size_t size, int flags) dma_addr_t device_addr, size_t size, int flags)
{ {
return 0; return 0;
...@@ -223,13 +223,14 @@ extern void *dmam_alloc_noncoherent(struct device *dev, size_t size, ...@@ -223,13 +223,14 @@ extern void *dmam_alloc_noncoherent(struct device *dev, size_t size,
extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr, extern void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle); dma_addr_t dma_handle);
#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY #ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
extern int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, extern int dmam_declare_coherent_memory(struct device *dev,
phys_addr_t phys_addr,
dma_addr_t device_addr, size_t size, dma_addr_t device_addr, size_t size,
int flags); int flags);
extern void dmam_release_declared_memory(struct device *dev); extern void dmam_release_declared_memory(struct device *dev);
#else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */ #else /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
static inline int dmam_declare_coherent_memory(struct device *dev, static inline int dmam_declare_coherent_memory(struct device *dev,
dma_addr_t bus_addr, dma_addr_t device_addr, phys_addr_t phys_addr, dma_addr_t device_addr,
size_t size, gfp_t gfp) size_t size, gfp_t gfp)
{ {
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment