aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRebecca Schultz Zavin2012-12-11 13:45:59 -0600
committerArve Hjønnevåg2013-02-19 19:56:04 -0600
commit7f6e5c60f1fac1677d876925c019a5d79f890e3a (patch)
tree12e38dea5650ba96270928b0a502686d5ed71a9c
parent234f61055f4889dbff5060c4d954ead9a02c6e90 (diff)
downloadkernel-common-7f6e5c60f1fac1677d876925c019a5d79f890e3a.tar.gz
kernel-common-7f6e5c60f1fac1677d876925c019a5d79f890e3a.tar.xz
kernel-common-7f6e5c60f1fac1677d876925c019a5d79f890e3a.zip
gpu: ion: Clarify variable names and comments around heap ids v types
There is some confusion between when to use the heap type and when the id. This patch clarifies this by using clearer variable names and describing the intention in the comments. Also fixes the client debug code to print heaps by id instead of type. Change-Id: Ie8b3dadded52e18590fcb2ca94001f6ed46ef07d Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
-rw-r--r--drivers/gpu/ion/ion.c37
-rw-r--r--include/linux/ion.h51
2 files changed, 47 insertions, 41 deletions
diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index a686af33250..af304ee7285 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -1,4 +1,5 @@
1/* 1/*
2
2 * drivers/gpu/ion/ion.c 3 * drivers/gpu/ion/ion.c
3 * 4 *
4 * Copyright (C) 2011 Google, Inc. 5 * Copyright (C) 2011 Google, Inc.
@@ -62,7 +63,7 @@ struct ion_device {
62 * @dev: backpointer to ion device 63 * @dev: backpointer to ion device
63 * @handles: an rb tree of all the handles in this client 64 * @handles: an rb tree of all the handles in this client
64 * @lock: lock protecting the tree of handles 65 * @lock: lock protecting the tree of handles
65 * @heap_mask: mask of all supported heaps 66 * @heap_type_mask: mask of all supported heap types
66 * @name: used for debugging 67 * @name: used for debugging
67 * @task: used for debugging 68 * @task: used for debugging
68 * 69 *
@@ -75,7 +76,7 @@ struct ion_client {
75 struct ion_device *dev; 76 struct ion_device *dev;
76 struct rb_root handles; 77 struct rb_root handles;
77 struct mutex lock; 78 struct mutex lock;
78 unsigned int heap_mask; 79 unsigned int heap_type_mask;
79 const char *name; 80 const char *name;
80 struct task_struct *task; 81 struct task_struct *task;
81 pid_t pid; 82 pid_t pid;
@@ -386,7 +387,7 @@ static void ion_handle_add(struct ion_client *client, struct ion_handle *handle)
386} 387}
387 388
388struct ion_handle *ion_alloc(struct ion_client *client, size_t len, 389struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
389 size_t align, unsigned int heap_mask, 390 size_t align, unsigned int heap_id_mask,
390 unsigned int flags) 391 unsigned int flags)
391{ 392{
392 struct ion_handle *handle; 393 struct ion_handle *handle;
@@ -394,8 +395,8 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
394 struct ion_buffer *buffer = NULL; 395 struct ion_buffer *buffer = NULL;
395 struct ion_heap *heap; 396 struct ion_heap *heap;
396 397
397 pr_debug("%s: len %d align %d heap_mask %u flags %x\n", __func__, len, 398 pr_debug("%s: len %d align %d heap_id_mask %u flags %x\n", __func__,
398 align, heap_mask, flags); 399 len, align, heap_id_mask, flags);
399 /* 400 /*
400 * traverse the list of heaps available in this system in priority 401 * traverse the list of heaps available in this system in priority
401 * order. If the heap type is supported by the client, and matches the 402 * order. If the heap type is supported by the client, and matches the
@@ -410,10 +411,10 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
410 down_read(&dev->lock); 411 down_read(&dev->lock);
411 plist_for_each_entry(heap, &dev->heaps, node) { 412 plist_for_each_entry(heap, &dev->heaps, node) {
412 /* if the client doesn't support this heap type */ 413 /* if the client doesn't support this heap type */
413 if (!((1 << heap->type) & client->heap_mask)) 414 if (!((1 << heap->type) & client->heap_type_mask))
414 continue; 415 continue;
415 /* if the caller didn't specify this heap type */ 416 /* if the caller didn't specify this heap id */
416 if (!((1 << heap->id) & heap_mask)) 417 if (!((1 << heap->id) & heap_id_mask))
417 continue; 418 continue;
418 buffer = ion_buffer_create(heap, dev, len, align, flags); 419 buffer = ion_buffer_create(heap, dev, len, align, flags);
419 if (!IS_ERR_OR_NULL(buffer)) 420 if (!IS_ERR_OR_NULL(buffer))
@@ -588,24 +589,24 @@ static int ion_debug_client_show(struct seq_file *s, void *unused)
588{ 589{
589 struct ion_client *client = s->private; 590 struct ion_client *client = s->private;
590 struct rb_node *n; 591 struct rb_node *n;
591 size_t sizes[ION_NUM_HEAPS] = {0}; 592 size_t sizes[ION_NUM_HEAP_IDS] = {0};
592 const char *names[ION_NUM_HEAPS] = {0}; 593 const char *names[ION_NUM_HEAP_IDS] = {0};
593 int i; 594 int i;
594 595
595 mutex_lock(&client->lock); 596 mutex_lock(&client->lock);
596 for (n = rb_first(&client->handles); n; n = rb_next(n)) { 597 for (n = rb_first(&client->handles); n; n = rb_next(n)) {
597 struct ion_handle *handle = rb_entry(n, struct ion_handle, 598 struct ion_handle *handle = rb_entry(n, struct ion_handle,
598 node); 599 node);
599 enum ion_heap_type type = handle->buffer->heap->type; 600 unsigned int id = handle->buffer->heap->id;
600 601
601 if (!names[type]) 602 if (!names[id])
602 names[type] = handle->buffer->heap->name; 603 names[id] = handle->buffer->heap->name;
603 sizes[type] += handle->buffer->size; 604 sizes[id] += handle->buffer->size;
604 } 605 }
605 mutex_unlock(&client->lock); 606 mutex_unlock(&client->lock);
606 607
607 seq_printf(s, "%16.16s: %16.16s\n", "heap_name", "size_in_bytes"); 608 seq_printf(s, "%16.16s: %16.16s\n", "heap_name", "size_in_bytes");
608 for (i = 0; i < ION_NUM_HEAPS; i++) { 609 for (i = 0; i < ION_NUM_HEAP_IDS; i++) {
609 if (!names[i]) 610 if (!names[i])
610 continue; 611 continue;
611 seq_printf(s, "%16.16s: %16u\n", names[i], sizes[i]); 612 seq_printf(s, "%16.16s: %16u\n", names[i], sizes[i]);
@@ -626,7 +627,7 @@ static const struct file_operations debug_client_fops = {
626}; 627};
627 628
628struct ion_client *ion_client_create(struct ion_device *dev, 629struct ion_client *ion_client_create(struct ion_device *dev,
629 unsigned int heap_mask, 630 unsigned int heap_type_mask,
630 const char *name) 631 const char *name)
631{ 632{
632 struct ion_client *client; 633 struct ion_client *client;
@@ -661,7 +662,7 @@ struct ion_client *ion_client_create(struct ion_device *dev,
661 client->handles = RB_ROOT; 662 client->handles = RB_ROOT;
662 mutex_init(&client->lock); 663 mutex_init(&client->lock);
663 client->name = name; 664 client->name = name;
664 client->heap_mask = heap_mask; 665 client->heap_type_mask = heap_type_mask;
665 client->task = task; 666 client->task = task;
666 client->pid = pid; 667 client->pid = pid;
667 668
@@ -1057,7 +1058,7 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1057 if (copy_from_user(&data, (void __user *)arg, sizeof(data))) 1058 if (copy_from_user(&data, (void __user *)arg, sizeof(data)))
1058 return -EFAULT; 1059 return -EFAULT;
1059 data.handle = ion_alloc(client, data.len, data.align, 1060 data.handle = ion_alloc(client, data.len, data.align,
1060 data.heap_mask, data.flags); 1061 data.heap_id_mask, data.flags);
1061 1062
1062 if (IS_ERR(data.handle)) 1063 if (IS_ERR(data.handle))
1063 return PTR_ERR(data.handle); 1064 return PTR_ERR(data.handle);
diff --git a/include/linux/ion.h b/include/linux/ion.h
index 814a7f4981a..610665d2be7 100644
--- a/include/linux/ion.h
+++ b/include/linux/ion.h
@@ -45,6 +45,8 @@ enum ion_heap_type {
45#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG) 45#define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
46#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT) 46#define ION_HEAP_CARVEOUT_MASK (1 << ION_HEAP_TYPE_CARVEOUT)
47 47
48#define ION_NUM_HEAP_IDS sizeof(unsigned int) * 8
49
48/** 50/**
49 * heap flags - the lower 16 bits are used by core ion, the upper 16 51 * heap flags - the lower 16 bits are used by core ion, the upper 16
50 * bits are reserved for use by the heaps themselves. 52 * bits are reserved for use by the heaps themselves.
@@ -73,8 +75,9 @@ struct ion_buffer;
73/** 75/**
74 * struct ion_platform_heap - defines a heap in the given platform 76 * struct ion_platform_heap - defines a heap in the given platform
75 * @type: type of the heap from ion_heap_type enum 77 * @type: type of the heap from ion_heap_type enum
76 * @id: unique identifier for heap. When allocating (lower numbers 78 * @id: unique identifier for heap. When allocating higher numbers
77 * will be allocated from first) 79 * will be allocated from first. At allocation these are passed
80 * as a bit mask and therefore can not exceed ION_NUM_HEAP_IDS.
78 * @name: used for debug purposes 81 * @name: used for debug purposes
79 * @base: base address of heap in physical memory if applicable 82 * @base: base address of heap in physical memory if applicable
80 * @size: size of the heap in bytes if applicable 83 * @size: size of the heap in bytes if applicable
@@ -118,12 +121,13 @@ void ion_reserve(struct ion_platform_data *data);
118 121
119/** 122/**
120 * ion_client_create() - allocate a client and returns it 123 * ion_client_create() - allocate a client and returns it
121 * @dev: the global ion device 124 * @dev: the global ion device
122 * @heap_mask: mask of heaps this client can allocate from 125 * @heap_type_mask: mask of heaps this client can allocate from
123 * @name: used for debugging 126 * @name: used for debugging
124 */ 127 */
125struct ion_client *ion_client_create(struct ion_device *dev, 128struct ion_client *ion_client_create(struct ion_device *dev,
126 unsigned int heap_mask, const char *name); 129 unsigned int heap_type_mask,
130 const char *name);
127 131
128/** 132/**
129 * ion_client_destroy() - free's a client and all it's handles 133 * ion_client_destroy() - free's a client and all it's handles
@@ -136,21 +140,22 @@ void ion_client_destroy(struct ion_client *client);
136 140
137/** 141/**
138 * ion_alloc - allocate ion memory 142 * ion_alloc - allocate ion memory
139 * @client: the client 143 * @client: the client
140 * @len: size of the allocation 144 * @len: size of the allocation
141 * @align: requested allocation alignment, lots of hardware blocks have 145 * @align: requested allocation alignment, lots of hardware blocks
142 * alignment requirements of some kind 146 * have alignment requirements of some kind
143 * @heap_mask: mask of heaps to allocate from, if multiple bits are set 147 * @heap_id_mask: mask of heaps to allocate from, if multiple bits are set
144 * heaps will be tried in order from lowest to highest order bit 148 * heaps will be tried in order from highest to lowest
145 * @flags: heap flags, the low 16 bits are consumed by ion, the high 16 149 * id
146 * bits are passed on to the respective heap and can be heap 150 * @flags: heap flags, the low 16 bits are consumed by ion, the
147 * custom 151 * high 16 bits are passed on to the respective heap and
152 * can be heap custom
148 * 153 *
149 * Allocate memory in one of the heaps provided in heap mask and return 154 * Allocate memory in one of the heaps provided in heap mask and return
150 * an opaque handle to it. 155 * an opaque handle to it.
151 */ 156 */
152struct ion_handle *ion_alloc(struct ion_client *client, size_t len, 157struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
153 size_t align, unsigned int heap_mask, 158 size_t align, unsigned int heap_id_mask,
154 unsigned int flags); 159 unsigned int flags);
155 160
156/** 161/**
@@ -239,19 +244,19 @@ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
239 244
240/** 245/**
241 * struct ion_allocation_data - metadata passed from userspace for allocations 246 * struct ion_allocation_data - metadata passed from userspace for allocations
242 * @len: size of the allocation 247 * @len: size of the allocation
243 * @align: required alignment of the allocation 248 * @align: required alignment of the allocation
244 * @heap_mask: mask of heaps to allocate from 249 * @heap_id_mask: mask of heap ids to allocate from
245 * @flags: flags passed to heap 250 * @flags: flags passed to heap
246 * @handle: pointer that will be populated with a cookie to use to refer 251 * @handle: pointer that will be populated with a cookie to use to
247 * to this allocation 252 * refer to this allocation
248 * 253 *
249 * Provided by userspace as an argument to the ioctl 254 * Provided by userspace as an argument to the ioctl
250 */ 255 */
251struct ion_allocation_data { 256struct ion_allocation_data {
252 size_t len; 257 size_t len;
253 size_t align; 258 size_t align;
254 unsigned int heap_mask; 259 unsigned int heap_id_mask;
255 unsigned int flags; 260 unsigned int flags;
256 struct ion_handle *handle; 261 struct ion_handle *handle;
257}; 262};