blob: c92363356ae142292fdcc29f0e1ebd758ff49e8c [file] [log] [blame]
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -08001/*
2 * drivers/staging/android/ion/ion_system_heap.c
3 *
4 * Copyright (C) 2011 Google, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -080017#include <asm/page.h>
18#include <linux/dma-mapping.h>
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -080019#include <linux/err.h>
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -080020#include <linux/highmem.h>
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -080021#include <linux/mm.h>
22#include <linux/scatterlist.h>
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080023#include <linux/seq_file.h>
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -080024#include <linux/slab.h>
25#include <linux/vmalloc.h>
26#include "ion.h"
27#include "ion_priv.h"
28
Colin Crossf63958d2013-12-13 19:26:28 -080029static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN |
30 __GFP_NORETRY) & ~__GFP_WAIT;
31static gfp_t low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080032static const unsigned int orders[] = {8, 4, 0};
33static const int num_orders = ARRAY_SIZE(orders);
34static int order_to_index(unsigned int order)
35{
36 int i;
37 for (i = 0; i < num_orders; i++)
38 if (order == orders[i])
39 return i;
40 BUG();
41 return -1;
42}
43
44static unsigned int order_to_size(int order)
45{
46 return PAGE_SIZE << order;
47}
48
49struct ion_system_heap {
50 struct ion_heap heap;
51 struct ion_page_pool **pools;
52};
53
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -080054struct page_info {
55 struct page *page;
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080056 unsigned int order;
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -080057 struct list_head list;
58};
59
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080060static struct page *alloc_buffer_page(struct ion_system_heap *heap,
61 struct ion_buffer *buffer,
62 unsigned long order)
63{
64 bool cached = ion_buffer_cached(buffer);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080065 struct ion_page_pool *pool = heap->pools[order_to_index(order)];
66 struct page *page;
Rebecca Schultz Zavinb0599c02013-12-13 14:24:08 -080067
Rebecca Schultz Zavinee4a4982013-12-13 14:24:12 -080068 if (!cached) {
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080069 page = ion_page_pool_alloc(pool);
Rebecca Schultz Zavinee4a4982013-12-13 14:24:12 -080070 } else {
71 gfp_t gfp_flags = low_order_gfp_flags;
72
73 if (order > 4)
74 gfp_flags = high_order_gfp_flags;
Colin Crossa3056902013-12-13 19:26:25 -080075 page = alloc_pages(gfp_flags, order);
Rebecca Schultz Zavin8fae8312013-12-13 14:24:18 -080076 if (!page)
Colin Crossf63958d2013-12-13 19:26:28 -080077 return NULL;
Colin Crosse946b202013-12-13 14:25:01 -080078 ion_pages_sync_for_device(NULL, page, PAGE_SIZE << order,
79 DMA_BIDIRECTIONAL);
Rebecca Schultz Zavinee4a4982013-12-13 14:24:12 -080080 }
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080081 if (!page)
Colin Crossf63958d2013-12-13 19:26:28 -080082 return NULL;
Rebecca Schultz Zavin8fae8312013-12-13 14:24:18 -080083
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080084 return page;
85}
86
87static void free_buffer_page(struct ion_system_heap *heap,
88 struct ion_buffer *buffer, struct page *page,
Rebecca Schultz Zavin0b6b2cd2013-12-13 14:24:32 -080089 unsigned int order)
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080090{
91 bool cached = ion_buffer_cached(buffer);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080092
Mitchel Humpherys53a91c62014-02-17 13:58:39 -080093 if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE)) {
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080094 struct ion_page_pool *pool = heap->pools[order_to_index(order)];
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080095 ion_page_pool_free(pool, page);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -080096 } else {
97 __free_pages(page, order);
98 }
99}
100
101
102static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
103 struct ion_buffer *buffer,
104 unsigned long size,
Rebecca Schultz Zavinba96a2e2013-12-13 14:24:07 -0800105 unsigned int max_order)
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800106{
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800107 struct page *page;
108 struct page_info *info;
109 int i;
110
John Stultzf4ea8232013-12-16 21:07:52 -0800111 info = kmalloc(sizeof(struct page_info), GFP_KERNEL);
112 if (!info)
113 return NULL;
114
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800115 for (i = 0; i < num_orders; i++) {
116 if (size < order_to_size(orders[i]))
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800117 continue;
Rebecca Schultz Zavinba96a2e2013-12-13 14:24:07 -0800118 if (max_order < orders[i])
119 continue;
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800120
121 page = alloc_buffer_page(heap, buffer, orders[i]);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800122 if (!page)
123 continue;
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800124
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800125 info->page = page;
126 info->order = orders[i];
Colin Crossc9e84402014-02-04 16:08:38 -0800127 INIT_LIST_HEAD(&info->list);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800128 return info;
129 }
John Stultzf4ea8232013-12-16 21:07:52 -0800130 kfree(info);
131
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800132 return NULL;
133}
134
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800135static int ion_system_heap_allocate(struct ion_heap *heap,
136 struct ion_buffer *buffer,
137 unsigned long size, unsigned long align,
138 unsigned long flags)
139{
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800140 struct ion_system_heap *sys_heap = container_of(heap,
141 struct ion_system_heap,
142 heap);
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800143 struct sg_table *table;
144 struct scatterlist *sg;
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800145 int ret;
146 struct list_head pages;
147 struct page_info *info, *tmp_info;
Rebecca Schultz Zavin13ba7802013-12-13 14:24:06 -0800148 int i = 0;
Colin Crossc9e84402014-02-04 16:08:38 -0800149 unsigned long size_remaining = PAGE_ALIGN(size);
Rebecca Schultz Zavinba96a2e2013-12-13 14:24:07 -0800150 unsigned int max_order = orders[0];
151
Colin Crossc13d1df2013-12-13 14:25:03 -0800152 if (align > PAGE_SIZE)
153 return -EINVAL;
154
Colin Crossc9e84402014-02-04 16:08:38 -0800155 if (size / PAGE_SIZE > totalram_pages / 2)
156 return -ENOMEM;
157
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800158 INIT_LIST_HEAD(&pages);
159 while (size_remaining > 0) {
John Stultze1d855b2013-12-13 19:26:33 -0800160 info = alloc_largest_available(sys_heap, buffer, size_remaining,
161 max_order);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800162 if (!info)
163 goto err;
164 list_add_tail(&info->list, &pages);
165 size_remaining -= (1 << info->order) * PAGE_SIZE;
Rebecca Schultz Zavinba96a2e2013-12-13 14:24:07 -0800166 max_order = info->order;
Rebecca Schultz Zavin13ba7802013-12-13 14:24:06 -0800167 i++;
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800168 }
John Stultzea725ec2013-12-13 19:26:18 -0800169 table = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800170 if (!table)
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800171 goto err;
172
Rebecca Schultz Zavinc13bd1c2013-12-13 14:24:45 -0800173 ret = sg_alloc_table(table, i, GFP_KERNEL);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800174 if (ret)
175 goto err1;
176
177 sg = table->sgl;
178 list_for_each_entry_safe(info, tmp_info, &pages, list) {
179 struct page *page = info->page;
Rebecca Schultz Zavinc13bd1c2013-12-13 14:24:45 -0800180 sg_set_page(sg, page, (1 << info->order) * PAGE_SIZE, 0);
181 sg = sg_next(sg);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800182 list_del(&info->list);
Rebecca Schultz Zavin708f0ca2013-12-13 14:23:59 -0800183 kfree(info);
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800184 }
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800185
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800186 buffer->priv_virt = table;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800187 return 0;
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800188err1:
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800189 kfree(table);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800190err:
John Stultzea725ec2013-12-13 19:26:18 -0800191 list_for_each_entry_safe(info, tmp_info, &pages, list) {
Rebecca Schultz Zavin0b6b2cd2013-12-13 14:24:32 -0800192 free_buffer_page(sys_heap, buffer, info->page, info->order);
Rebecca Schultz Zavin708f0ca2013-12-13 14:23:59 -0800193 kfree(info);
Rebecca Schultz Zavinbd5d6bd2013-12-13 14:23:51 -0800194 }
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800195 return -ENOMEM;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800196}
197
Colin Crossf63958d2013-12-13 19:26:28 -0800198static void ion_system_heap_free(struct ion_buffer *buffer)
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800199{
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800200 struct ion_heap *heap = buffer->heap;
201 struct ion_system_heap *sys_heap = container_of(heap,
202 struct ion_system_heap,
203 heap);
Rebecca Schultz Zavin88982272013-12-13 14:24:26 -0800204 struct sg_table *table = buffer->sg_table;
Rebecca Schultz Zavin0b6b2cd2013-12-13 14:24:32 -0800205 bool cached = ion_buffer_cached(buffer);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800206 struct scatterlist *sg;
207 LIST_HEAD(pages);
208 int i;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800209
Rebecca Schultz Zavin0b6b2cd2013-12-13 14:24:32 -0800210 /* uncached pages come from the page pools, zero them before returning
211 for security purposes (other allocations are zerod at alloc time */
Mitchel Humpherys53a91c62014-02-17 13:58:39 -0800212 if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE))
Rebecca Schultz Zavin0b6b2cd2013-12-13 14:24:32 -0800213 ion_heap_buffer_zero(buffer);
Rebecca Schultz Zavin77cbe822013-12-13 14:24:31 -0800214
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800215 for_each_sg(table->sgl, sg, table->nents, i)
Rebecca Schultz Zavin77cbe822013-12-13 14:24:31 -0800216 free_buffer_page(sys_heap, buffer, sg_page(sg),
Colin Cross06e0dca2013-12-13 14:25:02 -0800217 get_order(sg->length));
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800218 sg_free_table(table);
219 kfree(table);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800220}
221
Colin Crossf63958d2013-12-13 19:26:28 -0800222static struct sg_table *ion_system_heap_map_dma(struct ion_heap *heap,
223 struct ion_buffer *buffer)
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800224{
225 return buffer->priv_virt;
226}
227
Colin Crossf63958d2013-12-13 19:26:28 -0800228static void ion_system_heap_unmap_dma(struct ion_heap *heap,
229 struct ion_buffer *buffer)
Rebecca Schultz Zavinb15934b2013-12-13 14:23:41 -0800230{
231 return;
232}
233
Colin Crossb9daf0b2014-02-17 13:58:38 -0800234static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask,
235 int nr_to_scan)
236{
237 struct ion_system_heap *sys_heap;
238 int nr_total = 0;
239 int i;
240
241 sys_heap = container_of(heap, struct ion_system_heap, heap);
242
243 for (i = 0; i < num_orders; i++) {
244 struct ion_page_pool *pool = sys_heap->pools[i];
245 nr_total += ion_page_pool_shrink(pool, gfp_mask, nr_to_scan);
246 }
247
248 return nr_total;
249}
250
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800251static struct ion_heap_ops system_heap_ops = {
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800252 .allocate = ion_system_heap_allocate,
253 .free = ion_system_heap_free,
254 .map_dma = ion_system_heap_map_dma,
255 .unmap_dma = ion_system_heap_unmap_dma,
Rebecca Schultz Zavin88982272013-12-13 14:24:26 -0800256 .map_kernel = ion_heap_map_kernel,
257 .unmap_kernel = ion_heap_unmap_kernel,
258 .map_user = ion_heap_map_user,
Colin Crossb9daf0b2014-02-17 13:58:38 -0800259 .shrink = ion_system_heap_shrink,
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800260};
261
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800262static int ion_system_heap_debug_show(struct ion_heap *heap, struct seq_file *s,
263 void *unused)
264{
265
266 struct ion_system_heap *sys_heap = container_of(heap,
267 struct ion_system_heap,
268 heap);
269 int i;
270 for (i = 0; i < num_orders; i++) {
271 struct ion_page_pool *pool = sys_heap->pools[i];
Rebecca Schultz Zavin0fb9b812013-12-13 14:24:13 -0800272 seq_printf(s, "%d order %u highmem pages in pool = %lu total\n",
273 pool->high_count, pool->order,
274 (1 << pool->order) * PAGE_SIZE * pool->high_count);
275 seq_printf(s, "%d order %u lowmem pages in pool = %lu total\n",
276 pool->low_count, pool->order,
277 (1 << pool->order) * PAGE_SIZE * pool->low_count);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800278 }
279 return 0;
280}
281
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800282struct ion_heap *ion_system_heap_create(struct ion_platform_heap *unused)
283{
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800284 struct ion_system_heap *heap;
285 int i;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800286
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800287 heap = kzalloc(sizeof(struct ion_system_heap), GFP_KERNEL);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800288 if (!heap)
289 return ERR_PTR(-ENOMEM);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800290 heap->heap.ops = &system_heap_ops;
291 heap->heap.type = ION_HEAP_TYPE_SYSTEM;
Rebecca Schultz Zavinfe2faea2013-12-13 14:24:35 -0800292 heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE;
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800293 heap->pools = kzalloc(sizeof(struct ion_page_pool *) * num_orders,
294 GFP_KERNEL);
295 if (!heap->pools)
296 goto err_alloc_pools;
297 for (i = 0; i < num_orders; i++) {
298 struct ion_page_pool *pool;
Rebecca Schultz Zavinee4a4982013-12-13 14:24:12 -0800299 gfp_t gfp_flags = low_order_gfp_flags;
300
301 if (orders[i] > 4)
302 gfp_flags = high_order_gfp_flags;
303 pool = ion_page_pool_create(gfp_flags, orders[i]);
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800304 if (!pool)
305 goto err_create_pool;
306 heap->pools[i] = pool;
307 }
Rebecca Schultz Zavinea313b52013-12-13 14:24:39 -0800308
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800309 heap->heap.debug_show = ion_system_heap_debug_show;
310 return &heap->heap;
311err_create_pool:
312 for (i = 0; i < num_orders; i++)
313 if (heap->pools[i])
314 ion_page_pool_destroy(heap->pools[i]);
315 kfree(heap->pools);
316err_alloc_pools:
317 kfree(heap);
318 return ERR_PTR(-ENOMEM);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800319}
320
321void ion_system_heap_destroy(struct ion_heap *heap)
322{
Rebecca Schultz Zavin45b17a82013-12-13 14:24:11 -0800323 struct ion_system_heap *sys_heap = container_of(heap,
324 struct ion_system_heap,
325 heap);
326 int i;
327
328 for (i = 0; i < num_orders; i++)
329 ion_page_pool_destroy(sys_heap->pools[i]);
330 kfree(sys_heap->pools);
331 kfree(sys_heap);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800332}
333
334static int ion_system_contig_heap_allocate(struct ion_heap *heap,
335 struct ion_buffer *buffer,
336 unsigned long len,
337 unsigned long align,
338 unsigned long flags)
339{
Colin Crossc13d1df2013-12-13 14:25:03 -0800340 int order = get_order(len);
Colin Cross5c6a4702013-12-13 19:26:27 -0800341 struct page *page;
342 struct sg_table *table;
343 unsigned long i;
344 int ret;
Colin Crossc13d1df2013-12-13 14:25:03 -0800345
346 if (align > (PAGE_SIZE << order))
347 return -EINVAL;
348
Colin Cross5c6a4702013-12-13 19:26:27 -0800349 page = alloc_pages(low_order_gfp_flags, order);
350 if (!page)
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800351 return -ENOMEM;
Colin Cross5c6a4702013-12-13 19:26:27 -0800352
353 split_page(page, order);
354
355 len = PAGE_ALIGN(len);
356 for (i = len >> PAGE_SHIFT; i < (1 << order); i++)
357 __free_page(page + i);
358
359 table = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
360 if (!table) {
361 ret = -ENOMEM;
362 goto out;
363 }
364
365 ret = sg_alloc_table(table, 1, GFP_KERNEL);
366 if (ret)
367 goto out;
368
369 sg_set_page(table->sgl, page, len, 0);
370
371 buffer->priv_virt = table;
372
373 ion_pages_sync_for_device(NULL, page, len, DMA_BIDIRECTIONAL);
374
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800375 return 0;
Colin Cross5c6a4702013-12-13 19:26:27 -0800376
377out:
378 for (i = 0; i < len >> PAGE_SHIFT; i++)
379 __free_page(page + i);
380 kfree(table);
381 return ret;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800382}
383
Colin Crossf63958d2013-12-13 19:26:28 -0800384static void ion_system_contig_heap_free(struct ion_buffer *buffer)
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800385{
Colin Cross5c6a4702013-12-13 19:26:27 -0800386 struct sg_table *table = buffer->priv_virt;
387 struct page *page = sg_page(table->sgl);
388 unsigned long pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT;
389 unsigned long i;
390
391 for (i = 0; i < pages; i++)
392 __free_page(page + i);
393 sg_free_table(table);
394 kfree(table);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800395}
396
397static int ion_system_contig_heap_phys(struct ion_heap *heap,
398 struct ion_buffer *buffer,
399 ion_phys_addr_t *addr, size_t *len)
400{
Colin Cross5c6a4702013-12-13 19:26:27 -0800401 struct sg_table *table = buffer->priv_virt;
402 struct page *page = sg_page(table->sgl);
403 *addr = page_to_phys(page);
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800404 *len = buffer->size;
405 return 0;
406}
407
Colin Crossf63958d2013-12-13 19:26:28 -0800408static struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap,
Rebecca Schultz Zavin56a7c182013-12-13 14:23:50 -0800409 struct ion_buffer *buffer)
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800410{
Colin Cross5c6a4702013-12-13 19:26:27 -0800411 return buffer->priv_virt;
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800412}
413
Colin Crossf63958d2013-12-13 19:26:28 -0800414static void ion_system_contig_heap_unmap_dma(struct ion_heap *heap,
415 struct ion_buffer *buffer)
Rebecca Schultz Zavin56a7c182013-12-13 14:23:50 -0800416{
Rebecca Schultz Zavin56a7c182013-12-13 14:23:50 -0800417}
418
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800419static struct ion_heap_ops kmalloc_ops = {
420 .allocate = ion_system_contig_heap_allocate,
421 .free = ion_system_contig_heap_free,
422 .phys = ion_system_contig_heap_phys,
423 .map_dma = ion_system_contig_heap_map_dma,
Rebecca Schultz Zavin56a7c182013-12-13 14:23:50 -0800424 .unmap_dma = ion_system_contig_heap_unmap_dma,
Rebecca Schultz Zavin88982272013-12-13 14:24:26 -0800425 .map_kernel = ion_heap_map_kernel,
426 .unmap_kernel = ion_heap_unmap_kernel,
Colin Crossa82130f2013-12-13 19:26:15 -0800427 .map_user = ion_heap_map_user,
Rebecca Schultz Zavinc30707b2013-12-13 19:38:38 -0800428};
429
430struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *unused)
431{
432 struct ion_heap *heap;
433
434 heap = kzalloc(sizeof(struct ion_heap), GFP_KERNEL);
435 if (!heap)
436 return ERR_PTR(-ENOMEM);
437 heap->ops = &kmalloc_ops;
438 heap->type = ION_HEAP_TYPE_SYSTEM_CONTIG;
439 return heap;
440}
441
442void ion_system_contig_heap_destroy(struct ion_heap *heap)
443{
444 kfree(heap);
445}
446