On Tue, Sep 4, 2012 at 3:40 PM, zhangfei gao zhangfei.gao@gmail.com wrote:
@@ -88,25 +88,36 @@ struct sg_table *ion_carveout_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { struct sg_table *table;
int ret;
struct scatterlist *sg;
int ret, i;
int nents = PAGE_ALIGN(buffer->size) / PAGE_SIZE;
struct page *page = phys_to_page(buffer->priv_phys); table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); if (!table) return ERR_PTR(-ENOMEM);
ret = sg_alloc_table(table, 1, GFP_KERNEL);
ret = sg_alloc_table(table, nents, GFP_KERNEL); if (ret) { kfree(table); return ERR_PTR(ret); }
sg_set_page(table->sgl, phys_to_page(buffer->priv_phys), buffer->size,
0);
sg = table->sgl;
for (i = 0; i < nents; i++) {
sg_set_page(sg, page + i, PAGE_SIZE, 0);
sg = sg_next(sg);
}
return table;
}
It would need page-wise sg_table only if buffer is allocated as cached.
This refers to ion_system_heap.c, personally, I think it is fine.
AFAIU the purpose of making page-wise sg_table is for dirty page tracking by ion and so is needed only if ION_FLAG_CACHED is set for the buffer. If buffer->flags does not have ION_FLAG_CACHED, sg_table with single nents should be fine. Right?