|
@@ -39,9 +39,15 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
|
|
|
struct ion_cma_heap *cma_heap = to_cma_heap(heap);
|
|
|
struct sg_table *table;
|
|
|
struct page *pages;
|
|
|
+ unsigned long size = PAGE_ALIGN(len);
|
|
|
+ unsigned long nr_pages = size >> PAGE_SHIFT;
|
|
|
+ unsigned long align = get_order(size);
|
|
|
int ret;
|
|
|
|
|
|
- pages = cma_alloc(cma_heap->cma, len, 0, GFP_KERNEL);
|
|
|
+ if (align > CONFIG_CMA_ALIGNMENT)
|
|
|
+ align = CONFIG_CMA_ALIGNMENT;
|
|
|
+
|
|
|
+ pages = cma_alloc(cma_heap->cma, nr_pages, align, GFP_KERNEL);
|
|
|
if (!pages)
|
|
|
return -ENOMEM;
|
|
|
|
|
@@ -53,7 +59,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
|
|
|
if (ret)
|
|
|
goto free_mem;
|
|
|
|
|
|
- sg_set_page(table->sgl, pages, len, 0);
|
|
|
+ sg_set_page(table->sgl, pages, size, 0);
|
|
|
|
|
|
buffer->priv_virt = pages;
|
|
|
buffer->sg_table = table;
|
|
@@ -62,7 +68,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
|
|
|
free_mem:
|
|
|
kfree(table);
|
|
|
err:
|
|
|
- cma_release(cma_heap->cma, pages, buffer->size);
|
|
|
+ cma_release(cma_heap->cma, pages, nr_pages);
|
|
|
return -ENOMEM;
|
|
|
}
|
|
|
|
|
@@ -70,9 +76,10 @@ static void ion_cma_free(struct ion_buffer *buffer)
|
|
|
{
|
|
|
struct ion_cma_heap *cma_heap = to_cma_heap(buffer->heap);
|
|
|
struct page *pages = buffer->priv_virt;
|
|
|
+ unsigned long nr_pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT;
|
|
|
|
|
|
/* release memory */
|
|
|
- cma_release(cma_heap->cma, pages, buffer->size);
|
|
|
+ cma_release(cma_heap->cma, pages, nr_pages);
|
|
|
/* release sg table */
|
|
|
sg_free_table(buffer->sg_table);
|
|
|
kfree(buffer->sg_table);
|