dma_alloc_writecombine() and MAX_ORDER
Hello,
I'm using dma_alloc_writecombine() to allocate memory in my framebuffer device driver just like many other drivers do.
Now I have a new panel with a higher resolution and more bits-per-pixel. I want to use double-buffering with DirectFB and so my framebuffer size exceeds 4Mb.
Even though my embedded system has plenty of memory, now I receive the following warning and the allocation fails:
WARNING: at /home/teemhu/mcu/has/topas/mm/page_alloc.c:2012 __alloc_pages_nodemask+0x444/0x650()
This is due to the following check in __alloc_pages_slowpath():
if (order >= MAX_ORDER) {
WARN_ON_ONCE(!(gfp_mask & __GFP_NOWARN));
return NULL;
}Because MAX_ORDER is 11, only memory chunks of size (PAGE_SIZE << MAX_ORDER_NR_PAGES) = 4Mb can be allocated.
Apparently this topic has come up when using the OMAP DSS already:
http://www.spinics.net/lists/linux-omap/msg08124.html
Another user has asked this question on the linuxfb-dev mailing list in October 2010, but did not receive an answer:
http://www.spinics.net/lists/linux-fbdev/msg01745.html
So, would increasing MAX_ORDER in order to allow bigger memory chunks to be allocated via dma_alloc_writecombine() be acceptable?
If not, can anybody give me some advice how to do the memory allocation for the framebuffer memory instead in order to circumvent the problem?
CU
Michael.
Quoted 3 lines · Michael Hunold
Now I have a new panel with a higher resolution and more bits-per-pixel. I want to use double-buffering with DirectFB and so my framebuffer size exceeds 4Mb.
You could try this patch. It steals the memory for the coherent and writecombine memory at boot time, so MAX_ORDER no longer comes into the problem. You may need to define CONSISTENT_WC_SIZE and CONSISTENT_DMA_SIZE appropriately to gain sufficient memory. Note that the sum of those two must be a multiple of 2MB, and individually must be a multiple of 1MB.
arch/arm/include/asm/dma-mapping.h +1 -2
@@ -230,8 +230,7 @@ int dma_mmap_coherent(struct device *, struct vm_area_struct *,extern void *dma_alloc_writecombine (struct device *,size_t ,dma_addr_t *,gfp_t ); -#define dma_free_writecombine (dev,size,cpu_addr,handle) \ - dma_free_coherent(dev,size,cpu_addr,handle) +extern void dma_free_writecombine (struct device *,size_t ,void *,dma_addr_t );int dma_mmap_writecombine (struct device *,struct vm_area_struct *,void *,dma_addr_t ,size_t );
arch/arm/include/asm/mach/map.h +2 -0
@@ -29,6 +29,8 @@ struct map_desc {#define MT_MEMORY_NONCACHED 11#define MT_MEMORY_DTCM 12#define MT_MEMORY_ITCM 13 +#define MT_DMA_COHERENT 14 +#define MT_WC_COHERENT 15#ifdef CONFIG_MMU extern void iotable_init (struct map_desc *,int );
arch/arm/include/asm/memory.h +7 -0
@@ -88,6 +88,13 @@#define CONSISTENT_END (0xffe00000UL)#define CONSISTENT_BASE (CONSISTENT_END - CONSISTENT_DMA_SIZE) +#ifndef CONSISTENT_WC_SIZE +#define CONSISTENT_WC_SIZE SZ_2M +#endif + +#define CONSISTENT_WC_END CONSISTENT_BASE +#define CONSISTENT_WC_BASE (CONSISTENT_WC_END - CONSISTENT_WC_SIZE) +#else /* CONFIG_MMU */ /*
arch/arm/mm/dma-mapping.c +164 -146
431 lines not on this page · raw message
arch/arm/mm/init.c +1 -0
@@ -313,6 +313,7 @@ void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)#endif arm_mm_memblock_reserve (); +dma_coherent_reserve ();/* reserve any platform specific memblock areas */ if (mdesc->reserve)
arch/arm/mm/mm.h +2 -0
@@ -30,3 +30,5 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *pagevoid __init bootmem_init (void );void arm_mm_memblock_reserve (void ); +void dma_coherent_reserve (void ); +void dma_coherent_mapping (void );
arch/arm/mm/mmu.c +24 -0
@@ -275,6 +275,16 @@ static struct mem_type mem_types[] = { .prot_l1 = PMD_TYPE_TABLE, .domain = DOMAIN_KERNEL, }, + [MT_DMA_COHERENT] = { + .prot_sect =PMD_TYPE_SECT |PMD_SECT_AP_WRITE | + PMD_SECT_S, + .domain = DOMAIN_IO, + }, + [MT_WC_COHERENT] = { + .prot_sect =PMD_TYPE_SECT |PMD_SECT_AP_WRITE | + PMD_SECT_S, + .domain = DOMAIN_IO, + }, };const struct mem_type *get_mem_type (unsigned int type)
@@ -355,6 +365,7 @@ static void __init build_mem_type_table(void) mem_types[MT_DEVICE_NONSHARED ].prot_sect |=PMD_SECT_XN ; mem_types[MT_DEVICE_CACHED ].prot_sect |=PMD_SECT_XN ; mem_types[MT_DEVICE_WC ].prot_sect |=PMD_SECT_XN ; + mem_types[MT_DMA_COHERENT ].prot_sect |=PMD_SECT_XN ; }if (cpu_arch >= CPU_ARCH_ARMv7 && (cr &CR_TRE )) {/*
@@ -459,13 +470,24 @@ static void __init build_mem_type_table(void)/* Non-cacheable Normal is XCB = 001 */ mem_types[MT_MEMORY_NONCACHED ].prot_sect |=PMD_SECT_BUFFERED ; + mem_types[MT_WC_COHERENT ].prot_sect |= +PMD_SECT_BUFFERED ; + mem_types[MT_DMA_COHERENT ].prot_sect |= +PMD_SECT_BUFFERED ; }else {/* For both ARMv6 and non-TEX-remapping ARMv7 */ mem_types[MT_MEMORY_NONCACHED ].prot_sect |=PMD_SECT_TEX (1 ); + mem_types[MT_WC_COHERENT ].prot_sect |= +PMD_SECT_TEX (1 ); +#ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE + mem_types[MT_DMA_COHERENT ].prot_sect |= +PMD_SECT_TEX (1 ); +#endif } }else { mem_types[MT_MEMORY_NONCACHED ].prot_sect |=PMD_SECT_BUFFERABLE ; + mem_types[MT_WC_COHERENT ].prot_sect |=PMD_SECT_BUFFERED ; }for (i =0 ; i <16 ; i++) {
@@ -977,6 +999,8 @@ static void __init devicemaps_init(struct machine_desc *mdesc)create_mapping (&map); } +dma_coherent_mapping (); +/* * Ask the machine support to map in the statically mapped devices. */
Hello Russell,
on 04/29/2011 04:27 PM Russell King - ARM Linux said the following:
Quoted 11 lines · Michael Hunold
Quoted 4 lines
Now I have a new panel with a higher resolution and more bits-per-pixel. I want to use double-buffering with DirectFB and so my framebuffer size exceeds 4Mb.
You could try this patch. It steals the memory for the coherent and writecombine memory at boot time, so
MAX_ORDERno longer comes into the problem. You may need to defineCONSISTENT_WC_SIZEandCONSISTENT_DMA_SIZEappropriately to gain sufficient memory. Note that the sum of those two must be a multiple of 2MB, and individually must be a multiple of 1MB.
I really want to try this patch out, but unfortunately, I don't know to which tree I can apply it to. :-(
I'm working on a tree which is based on vanilla 2.6.38 and has the additions for the platform I'm working with, but there the patch won't apply cleanly.
The tree can be found here
http://git.labs.kernelconcepts.de/?p=topas.git;a=summary
So I thought I should try "devel-stable" from
http://ftp.arm.linux.org.uk/pub/linux/arm/kernel/git-cur/linux-2.6-arm.git
but there are even more rejects there.
Can you please tell me from which tree you created this patch?
Best regards
Michael.
Quoted 9 lines · Michael Hunold
Hello Russell,
on 04/29/2011 04:27 PM Russell King - ARM Linux said the following:
Quoted 5 lines · Michael Hunold
Quoted 4 lines
Now I have a new panel with a higher resolution and more bits-per-pixel. I want to use double-buffering with DirectFB and so my framebuffer size exceeds 4Mb.
Quoted 8 lines
Quoted 5 lines
You could try this patch. It steals the memory for the coherent and writecombine memory at boot time, so
MAX_ORDERno longer comes into the problem. You may need to defineCONSISTENT_WC_SIZEandCONSISTENT_DMA_SIZEappropriately to gain sufficient memory. Note that the sum of those two must be a multiple of 2MB, and individually must be a multiple of 1MB.I really want to try this patch out, but unfortunately, I don't know to which tree I can apply it to. :-(
You may need 516295e (ARM: pgtable: add pud-level code) from a later kernel as well then.