ion: Improve support for heap walking

Clients may wish to implement custom functions on a particular
heap ID. That function assumes that the heap ID has a specific heap
type. Make that requirement explicit by only calling the custom
function if both the ID and type match.

Change-Id: Ie746362a19a22dceb6e47148d67901d483778a85
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
This commit is contained in:
Patrick Daly 2016-01-21 18:46:43 -08:00 committed by David Keitel
parent d95f304065
commit e0eb556f01
3 changed files with 22 additions and 7 deletions

View file

@ -3,7 +3,7 @@
* drivers/staging/android/ion/ion.c * drivers/staging/android/ion/ion.c
* *
* Copyright (C) 2011 Google, Inc. * Copyright (C) 2011 Google, Inc.
* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. * Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
* *
* This software is licensed under the terms of the GNU General Public * This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and * License version 2, as published by the Free Software Foundation, and
@ -1897,10 +1897,11 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
} }
EXPORT_SYMBOL(ion_device_add_heap); EXPORT_SYMBOL(ion_device_add_heap);
int ion_walk_heaps(struct ion_client *client, int heap_id, void *data, int ion_walk_heaps(struct ion_client *client, int heap_id,
enum ion_heap_type type, void *data,
int (*f)(struct ion_heap *heap, void *data)) int (*f)(struct ion_heap *heap, void *data))
{ {
int ret_val = -EINVAL; int ret_val = 0;
struct ion_heap *heap; struct ion_heap *heap;
struct ion_device *dev = client->dev; struct ion_device *dev = client->dev;
/* /*
@ -1909,7 +1910,8 @@ int ion_walk_heaps(struct ion_client *client, int heap_id, void *data,
*/ */
down_write(&dev->lock); down_write(&dev->lock);
plist_for_each_entry(heap, &dev->heaps, node) { plist_for_each_entry(heap, &dev->heaps, node) {
if (ION_HEAP(heap->id) != heap_id) if (ION_HEAP(heap->id) != heap_id ||
type != heap->type)
continue; continue;
ret_val = f(heap, data); ret_val = f(heap, data);
break; break;

View file

@ -488,7 +488,8 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
void ion_pages_sync_for_device(struct device *dev, struct page *page, void ion_pages_sync_for_device(struct device *dev, struct page *page,
size_t size, enum dma_data_direction dir); size_t size, enum dma_data_direction dir);
int ion_walk_heaps(struct ion_client *client, int heap_id, void *data, int ion_walk_heaps(struct ion_client *client, int heap_id,
enum ion_heap_type type, void *data,
int (*f)(struct ion_heap *heap, void *data)); int (*f)(struct ion_heap *heap, void *data));
struct ion_handle *ion_handle_get_by_id(struct ion_client *client, struct ion_handle *ion_handle_get_by_id(struct ion_client *client,

View file

@ -725,16 +725,28 @@ long msm_ion_custom_ioctl(struct ion_client *client,
} }
case ION_IOC_PREFETCH: case ION_IOC_PREFETCH:
{ {
ion_walk_heaps(client, data.prefetch_data.heap_id, int ret;
ret = ion_walk_heaps(client, data.prefetch_data.heap_id,
ION_HEAP_TYPE_SECURE_DMA,
(void *)data.prefetch_data.len, (void *)data.prefetch_data.len,
ion_secure_cma_prefetch); ion_secure_cma_prefetch);
if (ret)
return ret;
break; break;
} }
case ION_IOC_DRAIN: case ION_IOC_DRAIN:
{ {
ion_walk_heaps(client, data.prefetch_data.heap_id, int ret;
ret = ion_walk_heaps(client, data.prefetch_data.heap_id,
ION_HEAP_TYPE_SECURE_DMA,
(void *)data.prefetch_data.len, (void *)data.prefetch_data.len,
ion_secure_cma_drain_pool); ion_secure_cma_drain_pool);
if (ret)
return ret;
break; break;
} }