Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/gpu/ion/ion_priv.h |
| 3 | * |
| 4 | * Copyright (C) 2011 Google, Inc. |
Laura Abbott | a8c373f | 2013-02-15 09:25:35 -0800 | [diff] [blame] | 5 | * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef _ION_PRIV_H |
| 19 | #define _ION_PRIV_H |
| 20 | |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 21 | #include <linux/ion.h> |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 22 | #include <linux/kref.h> |
| 23 | #include <linux/mm_types.h> |
| 24 | #include <linux/mutex.h> |
| 25 | #include <linux/rbtree.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 26 | #include <linux/seq_file.h> |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 27 | |
Laura Abbott | 61e8959 | 2013-03-21 10:55:17 -0700 | [diff] [blame] | 28 | #include "msm_ion_priv.h" |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 29 | #include <linux/sched.h> |
| 30 | #include <linux/shrinker.h> |
| 31 | #include <linux/types.h> |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 32 | |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 33 | struct ion_buffer *ion_handle_buffer(struct ion_handle *handle); |
| 34 | |
| 35 | /** |
| 36 | * struct ion_buffer - metadata for a particular buffer |
| 37 | * @ref: refernce count |
| 38 | * @node: node in the ion_device buffers tree |
| 39 | * @dev: back pointer to the ion_device |
| 40 | * @heap: back pointer to the heap the buffer came from |
| 41 | * @flags: buffer specific flags |
| 42 | * @size: size of the buffer |
| 43 | * @priv_virt: private data to the buffer representable as |
| 44 | * a void * |
| 45 | * @priv_phys: private data to the buffer representable as |
| 46 | * an ion_phys_addr_t (and someday a phys_addr_t) |
| 47 | * @lock: protects the buffers cnt fields |
| 48 | * @kmap_cnt: number of times the buffer is mapped to the kernel |
| 49 | * @vaddr: the kenrel mapping if kmap_cnt is not zero |
| 50 | * @dmap_cnt: number of times the buffer is mapped for dma |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 51 | * @sg_table: the sg table for the buffer if dmap_cnt is not zero |
Rebecca Schultz Zavin | db70ae6 | 2012-08-28 17:27:22 -0700 | [diff] [blame] | 52 | * @dirty: bitmask representing which pages of this buffer have |
| 53 | * been dirtied by the cpu and need cache maintenance |
| 54 | * before dma |
| 55 | * @vmas: list of vma's mapping this buffer |
| 56 | * @handle_count: count of handles referencing this buffer |
| 57 | * @task_comm: taskcomm of last client to reference this buffer in a |
| 58 | * handle, used for debugging |
| 59 | * @pid: pid of last client to reference this buffer in a |
| 60 | * handle, used for debugging |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 61 | */ |
| 62 | struct ion_buffer { |
| 63 | struct kref ref; |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 64 | union { |
| 65 | struct rb_node node; |
| 66 | struct list_head list; |
| 67 | }; |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 68 | struct ion_device *dev; |
| 69 | struct ion_heap *heap; |
| 70 | unsigned long flags; |
| 71 | size_t size; |
| 72 | union { |
| 73 | void *priv_virt; |
| 74 | ion_phys_addr_t priv_phys; |
| 75 | }; |
| 76 | struct mutex lock; |
| 77 | int kmap_cnt; |
| 78 | void *vaddr; |
| 79 | int dmap_cnt; |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 80 | struct sg_table *sg_table; |
Rebecca Schultz Zavin | b179067 | 2012-06-14 15:08:53 -0700 | [diff] [blame] | 81 | unsigned long *dirty; |
| 82 | struct list_head vmas; |
Rebecca Schultz Zavin | db70ae6 | 2012-08-28 17:27:22 -0700 | [diff] [blame] | 83 | /* used to track orphaned buffers */ |
| 84 | int handle_count; |
| 85 | char task_comm[TASK_COMM_LEN]; |
| 86 | pid_t pid; |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 87 | }; |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 88 | void ion_buffer_destroy(struct ion_buffer *buffer); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * struct ion_heap_ops - ops to operate on a given heap |
| 92 | * @allocate: allocate memory |
| 93 | * @free: free memory |
| 94 | * @phys get physical address of a buffer (only define on |
| 95 | * physically contiguous heaps) |
| 96 | * @map_dma map the memory for dma to a scatterlist |
| 97 | * @unmap_dma unmap the memory for dma |
| 98 | * @map_kernel map memory to the kernel |
| 99 | * @unmap_kernel unmap memory to the kernel |
| 100 | * @map_user map memory to userspace |
Alex Bird | 8a3ede3 | 2011-11-07 12:33:42 -0800 | [diff] [blame] | 101 | * @unmap_user unmap memory to userspace |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 102 | */ |
| 103 | struct ion_heap_ops { |
| 104 | int (*allocate) (struct ion_heap *heap, |
| 105 | struct ion_buffer *buffer, unsigned long len, |
| 106 | unsigned long align, unsigned long flags); |
| 107 | void (*free) (struct ion_buffer *buffer); |
| 108 | int (*phys) (struct ion_heap *heap, struct ion_buffer *buffer, |
| 109 | ion_phys_addr_t *addr, size_t *len); |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 110 | struct sg_table *(*map_dma) (struct ion_heap *heap, |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 111 | struct ion_buffer *buffer); |
| 112 | void (*unmap_dma) (struct ion_heap *heap, struct ion_buffer *buffer); |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 113 | void * (*map_kernel) (struct ion_heap *heap, struct ion_buffer *buffer); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 114 | void (*unmap_kernel) (struct ion_heap *heap, struct ion_buffer *buffer); |
| 115 | int (*map_user) (struct ion_heap *mapper, struct ion_buffer *buffer, |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 116 | struct vm_area_struct *vma); |
Alex Bird | 8a3ede3 | 2011-11-07 12:33:42 -0800 | [diff] [blame] | 117 | void (*unmap_user) (struct ion_heap *mapper, struct ion_buffer *buffer); |
Olav Haugan | 0671b9a | 2012-05-25 11:58:56 -0700 | [diff] [blame] | 118 | int (*print_debug)(struct ion_heap *heap, struct seq_file *s, |
| 119 | const struct rb_root *mem_map); |
Laura Abbott | 7e44648 | 2012-06-13 15:59:39 -0700 | [diff] [blame] | 120 | int (*secure_heap)(struct ion_heap *heap, int version, void *data); |
| 121 | int (*unsecure_heap)(struct ion_heap *heap, int version, void *data); |
Laura Abbott | 9361930 | 2012-10-11 11:51:40 -0700 | [diff] [blame] | 122 | int (*secure_buffer)(struct ion_buffer *buffer, int version, |
| 123 | void *data, int flags); |
| 124 | int (*unsecure_buffer)(struct ion_buffer *buffer, int force_unsecure); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /** |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 128 | * heap flags - flags between the heaps and core ion code |
| 129 | */ |
| 130 | #define ION_HEAP_FLAG_DEFER_FREE (1 << 0) |
| 131 | |
| 132 | /** |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 133 | * struct ion_heap - represents a heap in the system |
| 134 | * @node: rb node to put the heap on the device's tree of heaps |
| 135 | * @dev: back pointer to the ion_device |
| 136 | * @type: type of heap |
| 137 | * @ops: ops struct as above |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 138 | * @flags: flags |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 139 | * @id: id of heap, also indicates priority of this heap when |
| 140 | * allocating. These are specified by platform data and |
| 141 | * MUST be unique |
| 142 | * @name: used for debugging |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 143 | * @shrinker: a shrinker for the heap, if the heap caches system |
| 144 | * memory, it must define a shrinker to return it on low |
| 145 | * memory conditions, this includes system memory cached |
| 146 | * in the deferred free lists for heaps that support it |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 147 | * @priv: private heap data |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 148 | * @free_list: free list head if deferred free is used |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 149 | * @free_list_size size of the deferred free list in bytes |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 150 | * @lock: protects the free list |
| 151 | * @waitqueue: queue to wait on from deferred free thread |
| 152 | * @task: task struct of deferred free thread |
Rebecca Schultz Zavin | 943facc | 2012-08-06 21:37:23 -0700 | [diff] [blame] | 153 | * @debug_show: called when heap debug file is read to add any |
| 154 | * heap specific debug info to output |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 155 | * |
| 156 | * Represents a pool of memory from which buffers can be made. In some |
| 157 | * systems the only heap is regular system memory allocated via vmalloc. |
| 158 | * On others, some blocks might require large physically contiguous buffers |
| 159 | * that are allocated from a specially reserved heap. |
| 160 | */ |
| 161 | struct ion_heap { |
Rebecca Schultz Zavin | 47b9888 | 2012-11-15 10:36:10 -0800 | [diff] [blame] | 162 | struct plist_node node; |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 163 | struct ion_device *dev; |
| 164 | enum ion_heap_type type; |
| 165 | struct ion_heap_ops *ops; |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 166 | unsigned long flags; |
Rebecca Schultz Zavin | 47b9888 | 2012-11-15 10:36:10 -0800 | [diff] [blame] | 167 | unsigned int id; |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 168 | const char *name; |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 169 | struct shrinker shrinker; |
Benjamin Gaignard | 8dff0a6 | 2012-06-25 15:30:18 -0700 | [diff] [blame] | 170 | void *priv; |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 171 | struct list_head free_list; |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 172 | size_t free_list_size; |
Rebecca Schultz Zavin | 618d6be | 2013-02-13 14:48:11 -0800 | [diff] [blame] | 173 | struct rt_mutex lock; |
| 174 | wait_queue_head_t waitqueue; |
| 175 | struct task_struct *task; |
Rebecca Schultz Zavin | 943facc | 2012-08-06 21:37:23 -0700 | [diff] [blame] | 176 | int (*debug_show)(struct ion_heap *heap, struct seq_file *, void *); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | /** |
Rebecca Schultz Zavin | 943facc | 2012-08-06 21:37:23 -0700 | [diff] [blame] | 180 | * ion_buffer_cached - this ion buffer is cached |
| 181 | * @buffer: buffer |
| 182 | * |
| 183 | * indicates whether this ion buffer is cached |
| 184 | */ |
| 185 | bool ion_buffer_cached(struct ion_buffer *buffer); |
| 186 | |
| 187 | /** |
Rebecca Schultz Zavin | f858ba4 | 2012-09-21 11:46:06 -0700 | [diff] [blame] | 188 | * ion_buffer_fault_user_mappings - fault in user mappings of this buffer |
| 189 | * @buffer: buffer |
| 190 | * |
| 191 | * indicates whether userspace mappings of this buffer will be faulted |
| 192 | * in, this can affect how buffers are allocated from the heap. |
| 193 | */ |
| 194 | bool ion_buffer_fault_user_mappings(struct ion_buffer *buffer); |
| 195 | |
| 196 | /** |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 197 | * ion_device_create - allocates and returns an ion device |
| 198 | * @custom_ioctl: arch specific ioctl function if applicable |
| 199 | * |
| 200 | * returns a valid device or -PTR_ERR |
| 201 | */ |
| 202 | struct ion_device *ion_device_create(long (*custom_ioctl) |
| 203 | (struct ion_client *client, |
| 204 | unsigned int cmd, |
| 205 | unsigned long arg)); |
| 206 | |
| 207 | /** |
| 208 | * ion_device_destroy - free and device and it's resource |
| 209 | * @dev: the device |
| 210 | */ |
| 211 | void ion_device_destroy(struct ion_device *dev); |
| 212 | |
| 213 | /** |
| 214 | * ion_device_add_heap - adds a heap to the ion device |
| 215 | * @dev: the device |
| 216 | * @heap: the heap to add |
| 217 | */ |
| 218 | void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap); |
| 219 | |
| 220 | /** |
Rebecca Schultz Zavin | 3df181c | 2012-11-15 10:43:46 -0800 | [diff] [blame] | 221 | * some helpers for common operations on buffers using the sg_table |
| 222 | * and vaddr fields |
| 223 | */ |
| 224 | void *ion_heap_map_kernel(struct ion_heap *, struct ion_buffer *); |
| 225 | void ion_heap_unmap_kernel(struct ion_heap *, struct ion_buffer *); |
| 226 | int ion_heap_map_user(struct ion_heap *, struct ion_buffer *, |
| 227 | struct vm_area_struct *); |
Rebecca Schultz Zavin | ca12f5d | 2013-01-09 11:26:37 -0800 | [diff] [blame] | 228 | int ion_heap_buffer_zero(struct ion_buffer *buffer); |
Rebecca Schultz Zavin | 3df181c | 2012-11-15 10:43:46 -0800 | [diff] [blame] | 229 | |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 230 | /** |
| 231 | * ion_heap_init_deferred_free -- initialize deferred free functionality |
| 232 | * @heap: the heap |
| 233 | * |
| 234 | * If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag this function will |
| 235 | * be called to setup deferred frees. Calls to free the buffer will |
| 236 | * return immediately and the actual free will occur some time later |
| 237 | */ |
| 238 | int ion_heap_init_deferred_free(struct ion_heap *heap); |
| 239 | |
| 240 | /** |
| 241 | * ion_heap_freelist_add - add a buffer to the deferred free list |
| 242 | * @heap: the heap |
| 243 | * @buffer: the buffer |
| 244 | * |
| 245 | * Adds an item to the deferred freelist. |
| 246 | */ |
| 247 | void ion_heap_freelist_add(struct ion_heap *heap, struct ion_buffer *buffer); |
| 248 | |
| 249 | /** |
| 250 | * ion_heap_freelist_drain - drain the deferred free list |
| 251 | * @heap: the heap |
| 252 | * @size: ammount of memory to drain in bytes |
| 253 | * |
| 254 | * Drains the indicated amount of memory from the deferred freelist immediately. |
| 255 | * Returns the total amount freed. The total freed may be higher depending |
| 256 | * on the size of the items in the list, or lower if there is insufficient |
| 257 | * total memory on the freelist. |
| 258 | */ |
| 259 | size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size); |
| 260 | |
| 261 | /** |
| 262 | * ion_heap_freelist_size - returns the size of the freelist in bytes |
| 263 | * @heap: the heap |
| 264 | */ |
| 265 | size_t ion_heap_freelist_size(struct ion_heap *heap); |
| 266 | |
Rebecca Schultz Zavin | 3df181c | 2012-11-15 10:43:46 -0800 | [diff] [blame] | 267 | |
| 268 | /** |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 269 | * functions for creating and destroying the built in ion heaps. |
| 270 | * architectures can add their own custom architecture specific |
| 271 | * heaps as appropriate. |
| 272 | */ |
| 273 | |
| 274 | struct ion_heap *ion_heap_create(struct ion_platform_heap *); |
| 275 | void ion_heap_destroy(struct ion_heap *); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 276 | struct ion_heap *ion_system_heap_create(struct ion_platform_heap *); |
| 277 | void ion_system_heap_destroy(struct ion_heap *); |
| 278 | |
| 279 | struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *); |
| 280 | void ion_system_contig_heap_destroy(struct ion_heap *); |
| 281 | |
| 282 | struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *); |
| 283 | void ion_carveout_heap_destroy(struct ion_heap *); |
Laura Abbott | 8c01736 | 2011-09-22 20:59:12 -0700 | [diff] [blame] | 284 | |
Rebecca Schultz Zavin | d2ce6f8 | 2012-11-15 10:52:45 -0800 | [diff] [blame] | 285 | struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *); |
| 286 | void ion_chunk_heap_destroy(struct ion_heap *); |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 287 | /** |
| 288 | * kernel api to allocate/free from carveout -- used when carveout is |
| 289 | * used to back an architecture specific custom heap |
| 290 | */ |
| 291 | ion_phys_addr_t ion_carveout_allocate(struct ion_heap *heap, unsigned long size, |
| 292 | unsigned long align); |
| 293 | void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, |
| 294 | unsigned long size); |
| 295 | /** |
Laura Abbott | 61e8959 | 2013-03-21 10:55:17 -0700 | [diff] [blame] | 296 | * The carveout heap returns physical addresses, since 0 may be a valid |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 297 | * physical address, this is used to indicate allocation failed |
| 298 | */ |
| 299 | #define ION_CARVEOUT_ALLOCATE_FAIL -1 |
Rebecca Schultz Zavin | c80005a | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 300 | |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 301 | /** |
| 302 | * functions for creating and destroying a heap pool -- allows you |
| 303 | * to keep a pool of pre allocated memory to use from your heap. Keeping |
| 304 | * a pool of memory that is ready for dma, ie any cached mapping have been |
| 305 | * invalidated from the cache, provides a significant peformance benefit on |
| 306 | * many systems */ |
| 307 | |
| 308 | /** |
| 309 | * struct ion_page_pool - pagepool struct |
Rebecca Schultz Zavin | 9fad2fe | 2012-10-08 23:01:23 -0700 | [diff] [blame] | 310 | * @high_count: number of highmem items in the pool |
| 311 | * @low_count: number of lowmem items in the pool |
| 312 | * @high_items: list of highmem items |
| 313 | * @low_items: list of lowmem items |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 314 | * @shrinker: a shrinker for the items |
| 315 | * @mutex: lock protecting this struct and especially the count |
| 316 | * item list |
| 317 | * @alloc: function to be used to allocate pageory when the pool |
| 318 | * is empty |
| 319 | * @free: function to be used to free pageory back to the system |
| 320 | * when the shrinker fires |
| 321 | * @gfp_mask: gfp_mask to use from alloc |
| 322 | * @order: order of pages in the pool |
Rebecca Schultz Zavin | 8afce33 | 2012-10-10 14:19:17 -0700 | [diff] [blame] | 323 | * @list: plist node for list of pools |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 324 | * |
| 325 | * Allows you to keep a pool of pre allocated pages to use from your heap. |
| 326 | * Keeping a pool of pages that is ready for dma, ie any cached mapping have |
| 327 | * been invalidated from the cache, provides a significant peformance benefit |
| 328 | * on many systems |
| 329 | */ |
| 330 | struct ion_page_pool { |
Rebecca Schultz Zavin | 9fad2fe | 2012-10-08 23:01:23 -0700 | [diff] [blame] | 331 | int high_count; |
| 332 | int low_count; |
| 333 | struct list_head high_items; |
| 334 | struct list_head low_items; |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 335 | struct mutex mutex; |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 336 | gfp_t gfp_mask; |
| 337 | unsigned int order; |
Rebecca Schultz Zavin | 8afce33 | 2012-10-10 14:19:17 -0700 | [diff] [blame] | 338 | struct plist_node list; |
Rebecca Schultz Zavin | 050372e | 2012-06-07 16:36:44 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order); |
| 342 | void ion_page_pool_destroy(struct ion_page_pool *); |
| 343 | void *ion_page_pool_alloc(struct ion_page_pool *); |
| 344 | void ion_page_pool_free(struct ion_page_pool *, struct page *); |
| 345 | |
Rebecca Schultz Zavin | 83ff5da | 2013-05-23 13:37:25 -0700 | [diff] [blame^] | 346 | /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool |
| 347 | * @pool: the pool |
| 348 | * @gfp_mask: the memory type to reclaim |
| 349 | * @nr_to_scan: number of items to shrink in pages |
| 350 | * |
| 351 | * returns the number of items freed in pages |
| 352 | */ |
| 353 | int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, |
| 354 | int nr_to_scan); |
| 355 | |
Rebecca Schultz Zavin | 0c38bfd | 2011-06-29 19:44:29 -0700 | [diff] [blame] | 356 | #endif /* _ION_PRIV_H */ |