xtensa: use DMA zone to manage coherent dma memory
PATCH 1/2 xtensa: use DMA zone to manage coherent dma memory
Previously the init code put all memory into the DMA zone as there are no peripherals with address space restrictions. On the other hand there is dma_alloc_coherent which on mmu xtensa variants makes use of fixed TLB translations that provide an uncached mirror of the first 128MB. When the old implementation by chance was given memory outside that region, it called BUG().
This patch uses the DMA zone to keep memory that can be made uncached. It calls per-variant functions (with the current behavior as weak defaults) to determine the size of that area and to get the uncached virtual address. On nommu variants the defaults are different, resulting in an empty DMA zone and failing all remapping attempts.
--- arch/xtensa/include/asm/dma-mapping.h | 21 +++--- arch/xtensa/include/asm/uncached-mapping.h | 8 ++ arch/xtensa/kernel/pci-dma.c | 108 ++++++++++++++++++++------- arch/xtensa/mm/init.c | 11 ++- 4 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 arch/xtensa/include/asm/uncached-mapping.h
arch/xtensa/include/asm/dma-mapping.h +11 -10
@@ -24,14 +24,17 @@ extern void *consistent_alloc(int, size_t, dma_addr_t, unsigned long);extern void consistent_free (void *,size_t ,dma_addr_t );extern void consistent_sync (void *,size_t ,int ); -#define dma_alloc_noncoherent (d, s, h, f) dma_alloc_coherent(d, s, h, f) -#define dma_free_noncoherent (d, s, v, h) dma_free_coherent(d, s, v, h) - -void *dma_alloc_coherent (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t flag); - -void dma_free_coherent (struct device *dev,size_t size, -void *vaddr,dma_addr_t dma_handle); +int dma_is_consistent (struct device *dev,dma_addr_t dma_handle); +void *dma_alloc_both (struct device *dev,size_t size, +dma_addr_t *dma_handle,gfp_t flag); +void dma_free_both (struct device *dev,size_t size, +void *vaddr,dma_addr_t dma_handle); +#define dma_alloc_noncoherent (d, s, h, f) \ + dma_alloc_both(d, s, h, (f) & ~__GFP_DMA) +#define dma_alloc_coherent (d, s, h, f) \ + dma_alloc_both(d, s, h, (f) | __GFP_DMA) +#define dma_free_noncoherent (d, s, v, h) dma_free_both(d, s, v, h) +#define dma_free_coherent (d, s, v, h) dma_free_both(d, s, v, h) static inline dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
@@ -167,8 +170,6 @@ dma_get_cache_alignment(void)return L1_CACHE_BYTES ; } -#define dma_is_consistent (d, h) (1) -static inline void dma_cache_sync (struct device *dev,void *vaddr,size_t size,enum dma_data_direction direction)
arch/xtensa/include/asm/uncached-mapping.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __XTENSA_UNCACHED_MAPPING_H +#define __XTENSA_UNCACHED_MAPPING_H + +unsigned long variant_uncacheable_pages (unsigned long page); +void *variant_map_uncached (void *cvaddr,unsigned long size); +void *variant_unmap_uncached (void *ucvaddr,unsigned long size); + +#endif
arch/xtensa/kernel/pci-dma.c +80 -28
141 lines not on this page · raw message
arch/xtensa/mm/init.c +7 -4
@@ -26,6 +26,7 @@#include <asm/bootparam.h> #include <asm/page.h> +#include <asm/uncached-mapping.h> /* References to section boundaries */
@@ -158,11 +159,13 @@ void __init zones_init(void)unsigned long zones_size[MAX_NR_ZONES ];int i; -/* All pages are DMA-able, so we put them all in the DMA zone. */ - - zones_size[ZONE_DMA ] = max_low_pfn -ARCH_PFN_OFFSET ; -for (i =1 ; i <MAX_NR_ZONES ; i++) +for (i =0 ; i <MAX_NR_ZONES ; i++) zones_size[i] =0 ; + zones_size[ZONE_NORMAL ] = max_low_pfn -ARCH_PFN_OFFSET ; + zones_size[ZONE_DMA ] =variant_uncacheable_pages (ARCH_PFN_OFFSET ); +if (zones_size[ZONE_DMA ] > zones_size[ZONE_NORMAL ]) + zones_size[ZONE_DMA ] = zones_size[ZONE_NORMAL ]; + zones_size[ZONE_NORMAL ] -= zones_size[ZONE_DMA ];#ifdef CONFIG_HIGHMEM zones_size[ZONE_HIGHMEM ] = max_pfn - max_low_pfn;
Signature · 1 line
1.6.2.107.ge47ee
PATCH 2/2 xtensa: support dma_alloc_coherent on s6000
The s6000 core is a nommu variant but there is additional hardware that mirrors the first 512MB of RAM at another address, which is made uncached by the boot loader.
This patch uses that RAM mirror to provide support for dma_alloc_coherent.
--- arch/xtensa/variants/s6000/Makefile | 2 +- arch/xtensa/variants/s6000/uncached-mapping.c | 46 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletions(-) create mode 100644 arch/xtensa/variants/s6000/uncached-mapping.c
arch/xtensa/variants/s6000/Makefile +1 -1
@@ -1,3 +1,3 @@ # s6000 Makefile -obj-y += irq.o gpio.o dmac.o isef.o +obj-y += irq.o gpio.o dmac.o isef.o uncached-mapping.o
arch/xtensa/variants/s6000/uncached-mapping.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
1.6.2.107.ge47ee