dma-coherent: remove the DMA_MEMORY_MAP and DMA_MEMORY_IO flags

DMA_MEMORY_IO was never used in the tree, so remove it.  That means there is
no need for the DMA_MEMORY_MAP flag either now, so remove it as well and
change dma_declare_coherent_memory to return a normal errno value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
 Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
This commit is contained in:
Christoph Hellwig 2017-08-25 17:13:09 +02:00
parent b32dbc1e0b
commit 2436bdcda5
11 changed files with 52 additions and 111 deletions

View File

@ -592,30 +592,11 @@ size is the size of the area (must be multiples of PAGE_SIZE).
flags can be ORed together and are: flags can be ORed together and are:
- DMA_MEMORY_MAP - request that the memory returned from
dma_alloc_coherent() be directly writable.
- DMA_MEMORY_IO - request that the memory returned from
dma_alloc_coherent() be addressable using read()/write()/memcpy_toio() etc.
One or both of these flags must be present.
- DMA_MEMORY_EXCLUSIVE - only allocate memory from the declared regions. - DMA_MEMORY_EXCLUSIVE - only allocate memory from the declared regions.
Do not allow dma_alloc_coherent() to fall back to system memory when Do not allow dma_alloc_coherent() to fall back to system memory when
it's out of memory in the declared region. it's out of memory in the declared region.
The return value will be either DMA_MEMORY_MAP or DMA_MEMORY_IO and As a simplification for the platforms, only *one* such region of
must correspond to a passed in flag (i.e. no returning DMA_MEMORY_IO
if only DMA_MEMORY_MAP were passed in) for success or zero for
failure.
Note, for DMA_MEMORY_IO returns, all subsequent memory returned by
dma_alloc_coherent() may no longer be accessed directly, but instead
must be accessed using the correct bus functions. If your driver
isn't prepared to handle this contingency, it should not specify
DMA_MEMORY_IO in the input flags.
As a simplification for the platforms, only **one** such region of
memory may be declared per device. memory may be declared per device.
For reasons of efficiency, most platforms choose to track the declared For reasons of efficiency, most platforms choose to track the declared

View File

@ -245,7 +245,6 @@ static phys_addr_t mx2_camera_base __initdata;
static void __init visstrim_analog_camera_init(void) static void __init visstrim_analog_camera_init(void)
{ {
struct platform_device *pdev; struct platform_device *pdev;
int dma;
gpio_set_value(TVP5150_PWDN, 1); gpio_set_value(TVP5150_PWDN, 1);
ndelay(1); ndelay(1);
@ -258,12 +257,9 @@ static void __init visstrim_analog_camera_init(void)
if (IS_ERR(pdev)) if (IS_ERR(pdev))
return; return;
dma = dma_declare_coherent_memory(&pdev->dev, dma_declare_coherent_memory(&pdev->dev, mx2_camera_base,
mx2_camera_base, mx2_camera_base, mx2_camera_base, MX2_CAMERA_BUF_SIZE,
MX2_CAMERA_BUF_SIZE, DMA_MEMORY_EXCLUSIVE);
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
if (!(dma & DMA_MEMORY_MAP))
return;
} }
static void __init visstrim_reserve(void) static void __init visstrim_reserve(void)
@ -444,16 +440,13 @@ static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
static void __init visstrim_coda_init(void) static void __init visstrim_coda_init(void)
{ {
struct platform_device *pdev; struct platform_device *pdev;
int dma;
pdev = imx27_add_coda(); pdev = imx27_add_coda();
dma = dma_declare_coherent_memory(&pdev->dev, dma_declare_coherent_memory(&pdev->dev,
mx2_camera_base + MX2_CAMERA_BUF_SIZE, mx2_camera_base + MX2_CAMERA_BUF_SIZE,
mx2_camera_base + MX2_CAMERA_BUF_SIZE, mx2_camera_base + MX2_CAMERA_BUF_SIZE,
MX2_CAMERA_BUF_SIZE, MX2_CAMERA_BUF_SIZE,
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); DMA_MEMORY_EXCLUSIVE);
if (!(dma & DMA_MEMORY_MAP))
return;
} }
/* DMA deinterlace */ /* DMA deinterlace */
@ -466,24 +459,21 @@ static void __init visstrim_deinterlace_init(void)
{ {
int ret = -ENOMEM; int ret = -ENOMEM;
struct platform_device *pdev = &visstrim_deinterlace; struct platform_device *pdev = &visstrim_deinterlace;
int dma;
ret = platform_device_register(pdev); ret = platform_device_register(pdev);
dma = dma_declare_coherent_memory(&pdev->dev, dma_declare_coherent_memory(&pdev->dev,
mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE,
mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE, mx2_camera_base + 2 * MX2_CAMERA_BUF_SIZE,
MX2_CAMERA_BUF_SIZE, MX2_CAMERA_BUF_SIZE,
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); DMA_MEMORY_EXCLUSIVE);
if (!(dma & DMA_MEMORY_MAP))
return;
} }
/* Emma-PrP for format conversion */ /* Emma-PrP for format conversion */
static void __init visstrim_emmaprp_init(void) static void __init visstrim_emmaprp_init(void)
{ {
struct platform_device *pdev; struct platform_device *pdev;
int dma; int ret;
pdev = imx27_add_mx2_emmaprp(); pdev = imx27_add_mx2_emmaprp();
if (IS_ERR(pdev)) if (IS_ERR(pdev))
@ -493,11 +483,11 @@ static void __init visstrim_emmaprp_init(void)
* Use the same memory area as the analog camera since both * Use the same memory area as the analog camera since both
* devices are, by nature, exclusive. * devices are, by nature, exclusive.
*/ */
dma = dma_declare_coherent_memory(&pdev->dev, ret = dma_declare_coherent_memory(&pdev->dev,
mx2_camera_base, mx2_camera_base, mx2_camera_base, mx2_camera_base,
MX2_CAMERA_BUF_SIZE, MX2_CAMERA_BUF_SIZE,
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); DMA_MEMORY_EXCLUSIVE);
if (!(dma & DMA_MEMORY_MAP)) if (ret)
pr_err("Failed to declare memory for emmaprp\n"); pr_err("Failed to declare memory for emmaprp\n");
} }

View File

@ -475,7 +475,7 @@ static phys_addr_t mx3_camera_base __initdata;
static int __init mx31moboard_init_cam(void) static int __init mx31moboard_init_cam(void)
{ {
int dma, ret = -ENOMEM; int dma, ret;
struct platform_device *pdev; struct platform_device *pdev;
imx31_add_ipu_core(); imx31_add_ipu_core();
@ -484,11 +484,11 @@ static int __init mx31moboard_init_cam(void)
if (IS_ERR(pdev)) if (IS_ERR(pdev))
return PTR_ERR(pdev); return PTR_ERR(pdev);
dma = dma_declare_coherent_memory(&pdev->dev, ret = dma_declare_coherent_memory(&pdev->dev,
mx3_camera_base, mx3_camera_base, mx3_camera_base, mx3_camera_base,
MX3_CAMERA_BUF_SIZE, MX3_CAMERA_BUF_SIZE,
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); DMA_MEMORY_EXCLUSIVE);
if (!(dma & DMA_MEMORY_MAP)) if (ret)
goto err; goto err;
ret = platform_device_add(pdev); ret = platform_device_add(pdev);

View File

@ -63,11 +63,10 @@ static void gapspci_fixup_resources(struct pci_dev *dev)
res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1; res.end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1;
res.flags = IORESOURCE_MEM; res.flags = IORESOURCE_MEM;
pcibios_resource_to_bus(dev->bus, &region, &res); pcibios_resource_to_bus(dev->bus, &region, &res);
BUG_ON(!dma_declare_coherent_memory(&dev->dev, BUG_ON(dma_declare_coherent_memory(&dev->dev,
res.start, res.start,
region.start, region.start,
resource_size(&res), resource_size(&res),
DMA_MEMORY_MAP |
DMA_MEMORY_EXCLUSIVE)); DMA_MEMORY_EXCLUSIVE));
break; break;
default: default:

View File

@ -46,15 +46,10 @@ static bool dma_init_coherent_memory(
int pages = size >> PAGE_SHIFT; int pages = size >> PAGE_SHIFT;
int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long);
if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0)
goto out;
if (!size) if (!size)
goto out; goto out;
if (flags & DMA_MEMORY_MAP) mem_base = memremap(phys_addr, size, MEMREMAP_WC);
mem_base = memremap(phys_addr, size, MEMREMAP_WC);
else
mem_base = ioremap(phys_addr, size);
if (!mem_base) if (!mem_base)
goto out; goto out;
@ -77,12 +72,8 @@ static bool dma_init_coherent_memory(
out: out:
kfree(dma_mem); kfree(dma_mem);
if (mem_base) { if (mem_base)
if (flags & DMA_MEMORY_MAP) memunmap(mem_base);
memunmap(mem_base);
else
iounmap(mem_base);
}
return false; return false;
} }
@ -91,10 +82,7 @@ static void dma_release_coherent_memory(struct dma_coherent_mem *mem)
if (!mem) if (!mem)
return; return;
if (mem->flags & DMA_MEMORY_MAP) memunmap(mem->virt_base);
memunmap(mem->virt_base);
else
iounmap(mem->virt_base);
kfree(mem->bitmap); kfree(mem->bitmap);
kfree(mem); kfree(mem);
} }
@ -116,16 +104,16 @@ 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)
{ {
struct dma_coherent_mem *mem; struct dma_coherent_mem *mem;
int ret;
if (!dma_init_coherent_memory(phys_addr, device_addr, size, flags, ret = dma_init_coherent_memory(phys_addr, device_addr, size, flags, &mem);
&mem)) if (ret)
return 0; return ret;
if (dma_assign_coherent_memory(dev, mem) == 0) ret = dma_assign_coherent_memory(dev, mem);
return flags & DMA_MEMORY_MAP ? DMA_MEMORY_MAP : DMA_MEMORY_IO; if (ret)
dma_release_coherent_memory(mem);
dma_release_coherent_memory(mem); return ret;
return 0;
} }
EXPORT_SYMBOL(dma_declare_coherent_memory); EXPORT_SYMBOL(dma_declare_coherent_memory);
@ -186,15 +174,9 @@ static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem,
*/ */
*dma_handle = mem->device_base + (pageno << PAGE_SHIFT); *dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
ret = mem->virt_base + (pageno << PAGE_SHIFT); ret = mem->virt_base + (pageno << PAGE_SHIFT);
dma_memory_map = (mem->flags & DMA_MEMORY_MAP);
spin_unlock_irqrestore(&mem->spinlock, flags); spin_unlock_irqrestore(&mem->spinlock, flags);
if (dma_memory_map) memset(ret, 0, size);
memset(ret, 0, size);
else
memset_io(ret, 0, size);
return ret; return ret;
err: err:
spin_unlock_irqrestore(&mem->spinlock, flags); spin_unlock_irqrestore(&mem->spinlock, flags);
return NULL; return NULL;
@ -360,7 +342,7 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
if (!mem && if (!mem &&
!dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, !dma_init_coherent_memory(rmem->base, rmem->base, rmem->size,
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, DMA_MEMORY_EXCLUSIVE,
&mem)) { &mem)) {
pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n",
&rmem->base, (unsigned long)rmem->size / SZ_1M); &rmem->base, (unsigned long)rmem->size / SZ_1M);

View File

@ -176,13 +176,10 @@ int dmam_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size, rc = dma_declare_coherent_memory(dev, phys_addr, device_addr, size,
flags); flags);
if (rc) { if (!rc)
devres_add(dev, res); devres_add(dev, res);
rc = 0; else
} else {
devres_free(res); devres_free(res);
rc = -ENOMEM;
}
return rc; return rc;
} }

View File

@ -1708,11 +1708,10 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
err = dma_declare_coherent_memory(&pdev->dev, res->start, err = dma_declare_coherent_memory(&pdev->dev, res->start,
res->start, res->start,
resource_size(res), resource_size(res),
DMA_MEMORY_MAP |
DMA_MEMORY_EXCLUSIVE); DMA_MEMORY_EXCLUSIVE);
if (!err) { if (err) {
dev_err(&pdev->dev, "Unable to declare CEU memory.\n"); dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
return -ENXIO; return err;
} }
pcdev->video_limit = resource_size(res); pcdev->video_limit = resource_size(res);

View File

@ -217,8 +217,7 @@ NCR_Q720_probe(struct device *dev)
} }
if (dma_declare_coherent_memory(dev, base_addr, base_addr, if (dma_declare_coherent_memory(dev, base_addr, base_addr,
mem_size, DMA_MEMORY_MAP) mem_size, 0)) {
!= DMA_MEMORY_MAP) {
printk(KERN_ERR "NCR_Q720: DMA declare memory failed\n"); printk(KERN_ERR "NCR_Q720: DMA declare memory failed\n");
goto out_release_region; goto out_release_region;
} }

View File

@ -123,13 +123,12 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
* regular memory. The HCD_LOCAL_MEM flag does just that. * regular memory. The HCD_LOCAL_MEM flag does just that.
*/ */
if (!dma_declare_coherent_memory(dev, mem->start, retval = dma_declare_coherent_memory(dev, mem->start,
mem->start - mem->parent->start, mem->start - mem->parent->start,
resource_size(mem), resource_size(mem),
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
DMA_MEMORY_EXCLUSIVE)) { if (retval) {
dev_err(dev, "cannot declare coherent memory\n"); dev_err(dev, "cannot declare coherent memory\n");
retval = -ENXIO;
goto err1; goto err1;
} }

View File

@ -227,13 +227,10 @@ static int ohci_hcd_tmio_drv_probe(struct platform_device *dev)
goto err_ioremap_regs; goto err_ioremap_regs;
} }
if (!dma_declare_coherent_memory(&dev->dev, sram->start, ret = dma_declare_coherent_memory(&dev->dev, sram->start, sram->start,
sram->start, resource_size(sram), DMA_MEMORY_EXCLUSIVE);
resource_size(sram), if (ret)
DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE)) {
ret = -EBUSY;
goto err_dma_declare; goto err_dma_declare;
}
if (cell->enable) { if (cell->enable) {
ret = cell->enable(dev); ret = cell->enable(dev);

View File

@ -694,9 +694,7 @@ static inline int dma_get_cache_alignment(void)
#endif #endif
/* flags for the coherent memory api */ /* flags for the coherent memory api */
#define DMA_MEMORY_MAP 0x01 #define DMA_MEMORY_EXCLUSIVE 0x01
#define DMA_MEMORY_IO 0x02
#define DMA_MEMORY_EXCLUSIVE 0x04
#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
@ -709,7 +707,7 @@ static inline int
dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_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 -ENOSYS;
} }
static inline void static inline void