From eb0502ed1bec2cd1bb6d7f2a131d9010beddfc8a Mon Sep 17 00:00:00 2001 From: Laura Abbott Date: Tue, 1 Oct 2013 14:18:08 -0700 Subject: [PATCH] gpu: ion: Add support for specifying a default prefetch size Some heaps now support prefetching memory before allocation occurs. This currently requires a size to be given to prefetch a given size. Clients may not know what size they need to prefetch for a given heap. Since the optimal size may change with the target, add an option into devicetree to specify what size should be prefetched by default. Clients may specify a size of 0 to prefetch a the default size. Change-Id: If15e4051d53fe284129c309101c41ee423f890f9 Signed-off-by: Laura Abbott --- .../devicetree/bindings/arm/msm/msm_ion.txt | 2 ++ drivers/gpu/ion/ion_cma_secure_heap.c | 11 +++++++- drivers/gpu/ion/msm/msm_ion.c | 28 +++++++++++++++++-- include/linux/msm_ion.h | 8 ++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/msm/msm_ion.txt b/Documentation/devicetree/bindings/arm/msm/msm_ion.txt index f3cf8f384fb..d2e0916a949 100644 --- a/Documentation/devicetree/bindings/arm/msm/msm_ion.txt +++ b/Documentation/devicetree/bindings/arm/msm/msm_ion.txt @@ -37,6 +37,8 @@ Optional properties for Ion heaps - qcom,memory-reservation-size: size of reserved memory for the ION heap. - qcom,memory-reservation-type: type of memory to be reserved (see memory-reserve.txt for information about memory reservations) +- qcom,default-prefetch-size: Based value to be used for prefetching + optimizations. Ignored if the heap does not support prefetching. Example: qcom,ion { diff --git a/drivers/gpu/ion/ion_cma_secure_heap.c b/drivers/gpu/ion/ion_cma_secure_heap.c index 000c63714f5..82cd4499ed8 100644 --- a/drivers/gpu/ion/ion_cma_secure_heap.c +++ b/drivers/gpu/ion/ion_cma_secure_heap.c @@ -92,6 +92,7 @@ struct ion_cma_secure_heap { atomic_t total_allocated; atomic_t total_pool_size; unsigned long heap_size; + unsigned long default_prefetch_size; }; static void ion_secure_pool_pages(struct work_struct *work); @@ -224,6 +225,9 @@ int ion_secure_cma_prefetch(struct ion_heap *heap, void *data) if ((int) heap->type != ION_HEAP_TYPE_SECURE_DMA) return -EINVAL; + if (len == 0) + len = sheap->default_prefetch_size; + /* * Only prefetch as much space as there is left in the pool so * check against the current free size of the heap. @@ -667,14 +671,19 @@ struct ion_heap *ion_secure_cma_heap_create(struct ion_platform_heap *data) sheap->shrinker.seeks = DEFAULT_SEEKS; sheap->shrinker.batch = 0; sheap->shrinker.shrink = ion_secure_cma_shrinker; + sheap->default_prefetch_size = sheap->heap_size; register_shrinker(&sheap->shrinker); - if (!sheap->bitmap) { kfree(sheap); return ERR_PTR(-ENOMEM); } + if (data->extra_data) { + struct ion_cma_pdata *extra = data->extra_data; + sheap->default_prefetch_size = extra->default_prefetch_size; + } + /* * we initially mark everything in the allocator as being free so that * allocations can come in later diff --git a/drivers/gpu/ion/msm/msm_ion.c b/drivers/gpu/ion/msm/msm_ion.c index ebbbaf92d37..213bcb1d2b5 100644 --- a/drivers/gpu/ion/msm/msm_ion.c +++ b/drivers/gpu/ion/msm/msm_ion.c @@ -554,7 +554,8 @@ static void check_for_heap_overlap(const struct ion_platform_heap heap_list[], } #ifdef CONFIG_OF -static int msm_init_extra_data(struct ion_platform_heap *heap, +static int msm_init_extra_data(struct device_node *node, + struct ion_platform_heap *heap, const struct ion_heap_desc *heap_desc) { int ret = 0; @@ -580,6 +581,28 @@ static int msm_init_extra_data(struct ion_platform_heap *heap, ret = -ENOMEM; break; } + case ION_HEAP_TYPE_SECURE_DMA: + { + unsigned int val; + + ret = of_property_read_u32(node, + "qcom,default-prefetch-size", &val); + + if (!ret) { + heap->extra_data = kzalloc(sizeof(struct ion_cma_pdata), + GFP_KERNEL); + + if (!heap->extra_data) { + ret = -ENOMEM; + } else { + struct ion_cma_pdata *extra = heap->extra_data; + extra->default_prefetch_size = val; + } + } else { + ret = 0; + } + break; + } default: heap->extra_data = 0; break; @@ -639,7 +662,8 @@ static int msm_ion_populate_heap(struct device_node *node, if (ret) break; heap->type = heap_type; - ret = msm_init_extra_data(heap, &ion_heap_meta[i]); + ret = msm_init_extra_data(node, heap, + &ion_heap_meta[i]); break; } } diff --git a/include/linux/msm_ion.h b/include/linux/msm_ion.h index 80a0351b10e..0127edc2d97 100644 --- a/include/linux/msm_ion.h +++ b/include/linux/msm_ion.h @@ -197,6 +197,14 @@ struct ion_co_heap_pdata { enum ion_memory_types memory_type; }; +/* + * struct ion_cma_pdata - extra data for CMA regions + * @default_prefetch_size - default size to use for prefetching + */ +struct ion_cma_pdata { + unsigned long default_prefetch_size; +}; + #ifdef CONFIG_ION /** * msm_ion_client_create - allocate a client using the ion_device specified in