CMA: Contignous Memory Allocator,连续内存分配,一般是分配给Camera,HDMI等使用,避免预留大块内存
1.声明连续内存
使用dma_contignous_reserve(phys_addr_t limit);
- limit:end of address of the reserved memory
然后call dma_declare_contiguous()声明连续内存
int __init dma_declare_contiguous(struct device *dev, unsigned long size,
phys_addr_t base, phys_addr_t limit)
- size:一般是16MB
而改函数会call __memblock_alloc_base()拿到PA.
另外,core_initcall会call cma_init_reserved_area();
cma_init_reserved_area()会call cma_create_area(),创建一块连续内存区域;
cma_create_area()会call cma_activate_area(), 对每个page调用init_cma_reserved_pageblock(pfn),通过call set_pageblock_migratetype将页设置
为MIGRATE_CMA类型;
2.申请连续内存
dma_alloc_coherent call dma_alloc_writecombine,再call 到dma_alloc_from_contignous(),该function call 到
- int alloc_contig_range(unsigned long start, unsigned long end,
unsigned migratetype)将页设置为MIGRATE_ISOLATE,不再被系统使用
- static int __alloc_contig_migrate_range(unsigned long start, unsigned long end)进行页面的分离和搬移
3.释放内存
void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, dma_addr_t handle)
- __free_from_contignous()
- dma_release_from_contignous()
- free_config_range()