diff options
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/Makefile | 2 | ||||
| -rw-r--r-- | drivers/base/dma-contiguous.c | 52 | ||||
| -rw-r--r-- | drivers/base/dma-removed.c | 153 |
3 files changed, 187 insertions, 20 deletions
diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 4e22ce3ed73..c75d762258a 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -6,7 +6,7 @@ obj-y := core.o bus.o dd.o syscore.o \ attribute_container.o transport_class.o \ topology.o obj-$(CONFIG_DEVTMPFS) += devtmpfs.o -obj-$(CONFIG_CMA) += dma-contiguous.o +obj-$(CONFIG_CMA) += dma-contiguous.o dma-removed.o obj-y += power/ obj-$(CONFIG_HAS_DMA) += dma-mapping.o obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 46e93e5d477..3b51cc4ebc7 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -38,6 +38,7 @@ #include <linux/swap.h> #include <linux/mm_types.h> #include <linux/dma-contiguous.h> +#include <linux/dma-removed.h> #include <trace/events/kmem.h> struct cma { @@ -220,11 +221,12 @@ int __init cma_fdt_scan(unsigned long node, const char *uname, __be32 *prop; char *name; bool in_system; + bool remove; unsigned long size_cells = dt_root_size_cells; unsigned long addr_cells = dt_root_addr_cells; phys_addr_t limit = MEMBLOCK_ALLOC_ANYWHERE; - if (!of_get_flat_dt_prop(node, "linux,contiguous-region", NULL)) + if (!of_get_flat_dt_prop(node, "linux,reserve-contiguous-region", NULL)) return 0; prop = of_get_flat_dt_prop(node, "#size-cells", NULL); @@ -250,10 +252,13 @@ int __init cma_fdt_scan(unsigned long node, const char *uname, if (prop) limit = be32_to_cpu(prop[0]); + remove = + of_get_flat_dt_prop(node, "linux,remove-completely", NULL) ? 1 : 0; + pr_info("Found %s, memory base %pa, size %ld MiB, limit %pa\n", uname, &base, (unsigned long)size / SZ_1M, &limit); dma_contiguous_reserve_area(size, &base, limit, name, - in_system); + in_system, remove); return 0; } @@ -295,7 +300,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit) (unsigned long)sel_size / SZ_1M); if (dma_contiguous_reserve_area(sel_size, &base, limit, NULL, - CMA_RESERVE_AREA) == 0) + CMA_RESERVE_AREA, false) == 0) dma_contiguous_def_base = base; } #ifdef CONFIG_OF @@ -319,7 +324,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit) */ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t *res_base, phys_addr_t limit, const char *name, - bool to_system) + bool to_system, bool remove) { phys_addr_t base = *res_base; phys_addr_t alignment; @@ -365,6 +370,15 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t *res_base, } } + if (remove) { + if (!to_system) { + memblock_free(base, size); + memblock_remove(base, size); + } else { + WARN(1, "Removing is incompatible with staying in the system\n"); + } + } + /* * Each reserved area must be initialised later, when more kernel * subsystems (like slab allocator) are available. @@ -380,7 +394,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t *res_base, &base); /* Architecture specific contiguous memory fixup. */ - dma_contiguous_early_fixup(base, size); + if (!remove) + dma_contiguous_early_fixup(base, size); return 0; err: pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M); @@ -430,6 +445,10 @@ static void cma_assign_device_from_dt(struct device *dev) return; dev_set_cma_area(dev, cma); + + if (of_property_read_bool(node, "linux,remove-completely")) + set_dma_ops(dev, &removed_dma_ops); + pr_info("Assigned CMA region at %lx to %s device\n", (unsigned long)value, dev_name(dev)); } @@ -494,17 +513,16 @@ phys_addr_t cma_get_base(struct device *dev) * global one. Requires architecture specific get_dev_cma_area() helper * function. */ -struct page *dma_alloc_from_contiguous(struct device *dev, int count, +unsigned long dma_alloc_from_contiguous(struct device *dev, int count, unsigned int align) { - unsigned long mask, pfn, pageno, start = 0; + unsigned long mask, pfn = 0, pageno, start = 0; struct cma *cma = dev_get_cma_area(dev); - struct page *page = NULL; int ret = 0; int tries = 0; if (!cma || !cma->count) - return NULL; + return 0; if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; @@ -513,7 +531,7 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count, count, align); if (!count) - return NULL; + return 0; mask = (1 << align) - 1; @@ -530,7 +548,6 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count, ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA); if (ret == 0) { bitmap_set(cma->bitmap, pageno, count); - page = pfn_to_page(pfn); break; } else if (ret != -EBUSY) { break; @@ -545,8 +562,8 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count, } mutex_unlock(&cma_mutex); - pr_debug("%s(): returned %p\n", __func__, page); - return page; + pr_debug("%s(): returned %lx\n", __func__, pfn); + return pfn; } /** @@ -559,18 +576,15 @@ struct page *dma_alloc_from_contiguous(struct device *dev, int count, * It returns false when provided pages do not belong to contiguous area and * true otherwise. */ -bool dma_release_from_contiguous(struct device *dev, struct page *pages, +bool dma_release_from_contiguous(struct device *dev, unsigned long pfn, int count) { struct cma *cma = dev_get_cma_area(dev); - unsigned long pfn; - if (!cma || !pages) + if (!cma || !pfn) return false; - pr_debug("%s(page %p)\n", __func__, (void *)pages); - - pfn = page_to_pfn(pages); + pr_debug("%s(pfn %lx)\n", __func__, pfn); if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) return false; diff --git a/drivers/base/dma-removed.c b/drivers/base/dma-removed.c new file mode 100644 index 00000000000..004827a65e4 --- /dev/null +++ b/drivers/base/dma-removed.c @@ -0,0 +1,153 @@ +/* + * + * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. + * Copyright (C) 2000-2004 Russell King + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include <linux/module.h> +#include <linux/mm.h> +#include <linux/gfp.h> +#include <linux/errno.h> +#include <linux/list.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/dma-contiguous.h> +#include <linux/highmem.h> +#include <linux/memblock.h> +#include <linux/slab.h> +#include <linux/iommu.h> +#include <linux/io.h> +#include <linux/vmalloc.h> +#include <linux/sizes.h> + +#define NO_KERNEL_MAPPING_DUMMY 0x2222 + +void *removed_alloc(struct device *dev, size_t size, dma_addr_t *handle, + gfp_t gfp, struct dma_attrs *attrs) +{ + bool no_kernel_mapping = dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, + attrs); + unsigned long pfn; + unsigned long order = get_order(size); + void *addr = NULL; + + size = PAGE_ALIGN(size); + + if (!(gfp & __GFP_WAIT)) + return NULL; + + pfn = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT, order); + + if (pfn) { + addr = ioremap(__pfn_to_phys(pfn), size); + memset(addr, 0, size); + if (no_kernel_mapping) { + iounmap(addr); + addr = (void *)NO_KERNEL_MAPPING_DUMMY; + } + if (addr) + *handle = __pfn_to_phys(pfn); + + } + + return addr; +} + + +int removed_mmap(struct device *dev, struct vm_area_struct *vma, + void *cpu_addr, dma_addr_t dma_addr, size_t size, + struct dma_attrs *attrs) +{ + return -ENXIO; +} + +void removed_free(struct device *dev, size_t size, void *cpu_addr, + dma_addr_t handle, struct dma_attrs *attrs) +{ + bool no_kernel_mapping = dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING, + attrs); + + if (!no_kernel_mapping) + iounmap(cpu_addr); + dma_release_from_contiguous(dev, __phys_to_pfn(handle), + size >> PAGE_SHIFT); +} + +static dma_addr_t removed_map_page(struct device *dev, struct page *page, + unsigned long offset, size_t size, + enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + return ~(dma_addr_t)0; +} + +static void removed_unmap_page(struct device *dev, dma_addr_t dma_handle, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + return; +} + +static int removed_map_sg(struct device *dev, struct scatterlist *sg, + int nents, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + return 0; +} + +static void removed_unmap_sg(struct device *dev, + struct scatterlist *sg, int nents, + enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + return; +} + +static void removed_sync_single_for_cpu(struct device *dev, + dma_addr_t dma_handle, size_t size, + enum dma_data_direction dir) +{ + return; +} + +void removed_sync_single_for_device(struct device *dev, + dma_addr_t dma_handle, size_t size, + enum dma_data_direction dir) +{ + return; +} + +void removed_sync_sg_for_cpu(struct device *dev, + struct scatterlist *sg, int nents, + enum dma_data_direction dir) +{ + return; +} + +void removed_sync_sg_for_device(struct device *dev, + struct scatterlist *sg, int nents, + enum dma_data_direction dir) +{ + return; +} + +struct dma_map_ops removed_dma_ops = { + .alloc = removed_alloc, + .free = removed_free, + .mmap = removed_mmap, + .map_page = removed_map_page, + .unmap_page = removed_unmap_page, + .map_sg = removed_map_sg, + .unmap_sg = removed_unmap_sg, + .sync_single_for_cpu = removed_sync_single_for_cpu, + .sync_single_for_device = removed_sync_single_for_device, + .sync_sg_for_cpu = removed_sync_sg_for_cpu, + .sync_sg_for_device = removed_sync_sg_for_device, +}; +EXPORT_SYMBOL(removed_dma_ops); + + |
