blob: 02f6d937459522345882b3c85d6a57f73fff12e4 [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * drivers/gpu/ion/ion_system_heap.c
3 *
4 * Copyright (C) 2011 Google, Inc.
Mitchel Humpherysaf3b5222013-01-15 15:38:52 -08005 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07006 *
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
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -070018#include <asm/page.h>
19#include <linux/dma-mapping.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070020#include <linux/err.h>
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -070021#include <linux/highmem.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070022#include <linux/ion.h>
23#include <linux/mm.h>
24#include <linux/scatterlist.h>
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070025#include <linux/seq_file.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070026#include <linux/slab.h>
27#include <linux/vmalloc.h>
Olav Haugan3d4fe1a2012-01-13 11:42:15 -080028#include <linux/seq_file.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070029#include "ion_priv.h"
Laura Abbottabcb6f72011-10-04 16:26:49 -070030#include <mach/memory.h>
Olav Haugan85c95402012-05-30 17:32:37 -070031#include <asm/cacheflush.h>
Mitchel Humpherysaf2e5c52012-09-06 12:16:36 -070032#include <linux/msm_ion.h>
Neeti Desai3f3c2822013-03-08 17:29:53 -080033#include <linux/dma-mapping.h>
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -070034
Laura Abbott68c80642011-10-21 17:32:27 -070035static atomic_t system_heap_allocated;
36static atomic_t system_contig_heap_allocated;
37
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070038static unsigned int high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO |
39 __GFP_NOWARN | __GFP_NORETRY |
Rebecca Schultz Zavin1797e59a2012-10-18 21:51:53 -070040 __GFP_NO_KSWAPD) & ~__GFP_WAIT;
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070041static unsigned int low_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO |
42 __GFP_NOWARN);
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070043static const unsigned int orders[] = {8, 4, 0};
44static const int num_orders = ARRAY_SIZE(orders);
45static int order_to_index(unsigned int order)
46{
47 int i;
48 for (i = 0; i < num_orders; i++)
49 if (order == orders[i])
50 return i;
51 BUG();
52 return -1;
53}
54
55static unsigned int order_to_size(int order)
56{
57 return PAGE_SIZE << order;
58}
59
60struct ion_system_heap {
61 struct ion_heap heap;
62 struct ion_page_pool **pools;
63};
64
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -070065struct page_info {
66 struct page *page;
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070067 unsigned int order;
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -070068 struct list_head list;
69};
70
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070071static struct page *alloc_buffer_page(struct ion_system_heap *heap,
72 struct ion_buffer *buffer,
73 unsigned long order)
74{
75 bool cached = ion_buffer_cached(buffer);
76 bool split_pages = ion_buffer_fault_user_mappings(buffer);
77 struct ion_page_pool *pool = heap->pools[order_to_index(order)];
78 struct page *page;
Rebecca Schultz Zavin96dd58d2012-09-26 10:58:30 -070079
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070080 if (!cached) {
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070081 page = ion_page_pool_alloc(pool);
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070082 } else {
Rebecca Schultz Zavin220a6522012-10-18 21:54:01 -070083 struct scatterlist sg;
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070084 gfp_t gfp_flags = low_order_gfp_flags;
85
86 if (order > 4)
87 gfp_flags = high_order_gfp_flags;
88 page = alloc_pages(gfp_flags, order);
Rebecca Schultz Zavin220a6522012-10-18 21:54:01 -070089 if (!page)
90 return 0;
91 sg_init_table(&sg, 1);
92 sg_set_page(&sg, page, PAGE_SIZE << order, 0);
93 dma_sync_sg_for_device(NULL, &sg, 1, DMA_BIDIRECTIONAL);
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -070094 }
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070095 if (!page)
96 return 0;
Rebecca Schultz Zavin220a6522012-10-18 21:54:01 -070097
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -070098 if (split_pages)
99 split_page(page, order);
100 return page;
101}
102
103static void free_buffer_page(struct ion_system_heap *heap,
104 struct ion_buffer *buffer, struct page *page,
Rebecca Schultz Zavinca12f5d2013-01-09 11:26:37 -0800105 unsigned int order)
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700106{
107 bool cached = ion_buffer_cached(buffer);
108 bool split_pages = ion_buffer_fault_user_mappings(buffer);
109 int i;
110
111 if (!cached) {
112 struct ion_page_pool *pool = heap->pools[order_to_index(order)];
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700113 ion_page_pool_free(pool, page);
114 } else if (split_pages) {
115 for (i = 0; i < (1 << order); i++)
116 __free_page(page + i);
117 } else {
118 __free_pages(page, order);
119 }
120}
121
122
123static struct page_info *alloc_largest_available(struct ion_system_heap *heap,
124 struct ion_buffer *buffer,
125 unsigned long size,
Rebecca Schultz Zavin158316f2012-09-25 20:55:27 -0700126 unsigned int max_order)
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700127{
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700128 struct page *page;
129 struct page_info *info;
130 int i;
131
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700132 for (i = 0; i < num_orders; i++) {
133 if (size < order_to_size(orders[i]))
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700134 continue;
Rebecca Schultz Zavin158316f2012-09-25 20:55:27 -0700135 if (max_order < orders[i])
136 continue;
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700137
138 page = alloc_buffer_page(heap, buffer, orders[i]);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700139 if (!page)
140 continue;
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700141
142 info = kmalloc(sizeof(struct page_info), GFP_KERNEL);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700143 info->page = page;
144 info->order = orders[i];
145 return info;
146 }
147 return NULL;
148}
149
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700150static int ion_system_heap_allocate(struct ion_heap *heap,
151 struct ion_buffer *buffer,
152 unsigned long size, unsigned long align,
153 unsigned long flags)
154{
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700155 struct ion_system_heap *sys_heap = container_of(heap,
156 struct ion_system_heap,
157 heap);
Laura Abbottb14ed962012-01-30 14:18:08 -0800158 struct sg_table *table;
159 struct scatterlist *sg;
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700160 int ret;
161 struct list_head pages;
162 struct page_info *info, *tmp_info;
Rebecca Schultz Zavinf858ba42012-09-21 11:46:06 -0700163 int i = 0;
Olav Haugand8770692013-04-17 16:11:31 -0700164 unsigned long size_remaining = PAGE_ALIGN(size);
Rebecca Schultz Zavin158316f2012-09-25 20:55:27 -0700165 unsigned int max_order = orders[0];
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700166 bool split_pages = ion_buffer_fault_user_mappings(buffer);
Rebecca Schultz Zavin158316f2012-09-25 20:55:27 -0700167
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700168 INIT_LIST_HEAD(&pages);
169 while (size_remaining > 0) {
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700170 info = alloc_largest_available(sys_heap, buffer, size_remaining, max_order);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700171 if (!info)
172 goto err;
173 list_add_tail(&info->list, &pages);
174 size_remaining -= (1 << info->order) * PAGE_SIZE;
Rebecca Schultz Zavin158316f2012-09-25 20:55:27 -0700175 max_order = info->order;
Rebecca Schultz Zavinf858ba42012-09-21 11:46:06 -0700176 i++;
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700177 }
Laura Abbott68c80642011-10-21 17:32:27 -0700178
Laura Abbottb14ed962012-01-30 14:18:08 -0800179 table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
180 if (!table)
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700181 goto err;
182
Rebecca Schultz Zavinf858ba42012-09-21 11:46:06 -0700183 if (split_pages)
184 ret = sg_alloc_table(table, PAGE_ALIGN(size) / PAGE_SIZE,
185 GFP_KERNEL);
186 else
187 ret = sg_alloc_table(table, i, GFP_KERNEL);
188
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700189 if (ret)
190 goto err1;
191
192 sg = table->sgl;
193 list_for_each_entry_safe(info, tmp_info, &pages, list) {
194 struct page *page = info->page;
Rebecca Schultz Zavinf858ba42012-09-21 11:46:06 -0700195 if (split_pages) {
196 for (i = 0; i < (1 << info->order); i++) {
197 sg_set_page(sg, page + i, PAGE_SIZE, 0);
198 sg = sg_next(sg);
199 }
200 } else {
201 sg_set_page(sg, page, (1 << info->order) * PAGE_SIZE,
202 0);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700203 sg = sg_next(sg);
204 }
205 list_del(&info->list);
Rebecca Schultz Zavin6a93a292012-08-21 21:35:20 -0700206 kfree(info);
Laura Abbottb14ed962012-01-30 14:18:08 -0800207 }
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700208
Laura Abbottb14ed962012-01-30 14:18:08 -0800209 buffer->priv_virt = table;
Laura Abbott68c80642011-10-21 17:32:27 -0700210 atomic_add(size, &system_heap_allocated);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700211 return 0;
Laura Abbottb14ed962012-01-30 14:18:08 -0800212err1:
Laura Abbottb14ed962012-01-30 14:18:08 -0800213 kfree(table);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700214err:
215 list_for_each_entry(info, &pages, list) {
Rebecca Schultz Zavinca12f5d2013-01-09 11:26:37 -0800216 free_buffer_page(sys_heap, buffer, info->page, info->order);
Rebecca Schultz Zavin6a93a292012-08-21 21:35:20 -0700217 kfree(info);
Rebecca Schultz Zavinb831c8c2012-06-14 13:30:01 -0700218 }
Laura Abbottb14ed962012-01-30 14:18:08 -0800219 return -ENOMEM;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700220}
221
222void ion_system_heap_free(struct ion_buffer *buffer)
223{
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700224 struct ion_heap *heap = buffer->heap;
225 struct ion_system_heap *sys_heap = container_of(heap,
226 struct ion_system_heap,
227 heap);
Rebecca Schultz Zavin3df181c2012-11-15 10:43:46 -0800228 struct sg_table *table = buffer->sg_table;
Rebecca Schultz Zavinca12f5d2013-01-09 11:26:37 -0800229 bool cached = ion_buffer_cached(buffer);
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700230 struct scatterlist *sg;
231 LIST_HEAD(pages);
232 int i;
Laura Abbottb14ed962012-01-30 14:18:08 -0800233
Rebecca Schultz Zavinca12f5d2013-01-09 11:26:37 -0800234 /* uncached pages come from the page pools, zero them before returning
235 for security purposes (other allocations are zerod at alloc time */
236 if (!cached)
237 ion_heap_buffer_zero(buffer);
Rebecca Schultz Zavinf9101222012-12-18 22:46:57 -0800238
Laura Abbottb14ed962012-01-30 14:18:08 -0800239 for_each_sg(table->sgl, sg, table->nents, i)
Rebecca Schultz Zavinf9101222012-12-18 22:46:57 -0800240 free_buffer_page(sys_heap, buffer, sg_page(sg),
Rebecca Schultz Zavinca12f5d2013-01-09 11:26:37 -0800241 get_order(sg_dma_len(sg)));
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700242 sg_free_table(table);
243 kfree(table);
Laura Abbott68c80642011-10-21 17:32:27 -0700244 atomic_sub(buffer->size, &system_heap_allocated);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700245}
246
Laura Abbottb14ed962012-01-30 14:18:08 -0800247struct sg_table *ion_system_heap_map_dma(struct ion_heap *heap,
248 struct ion_buffer *buffer)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700249{
Laura Abbottb14ed962012-01-30 14:18:08 -0800250 return buffer->priv_virt;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700251}
252
253void ion_system_heap_unmap_dma(struct ion_heap *heap,
254 struct ion_buffer *buffer)
255{
Laura Abbottb14ed962012-01-30 14:18:08 -0800256 return;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700257}
258
Olav Haugan0671b9a2012-05-25 11:58:56 -0700259static int ion_system_print_debug(struct ion_heap *heap, struct seq_file *s,
260 const struct rb_root *unused)
Laura Abbott68c80642011-10-21 17:32:27 -0700261{
Olav Haugan3d4fe1a2012-01-13 11:42:15 -0800262 seq_printf(s, "total bytes currently allocated: %lx\n",
263 (unsigned long) atomic_read(&system_heap_allocated));
264
265 return 0;
Laura Abbott68c80642011-10-21 17:32:27 -0700266}
267
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700268static struct ion_heap_ops system_heap_ops = {
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700269 .allocate = ion_system_heap_allocate,
270 .free = ion_system_heap_free,
271 .map_dma = ion_system_heap_map_dma,
272 .unmap_dma = ion_system_heap_unmap_dma,
Rebecca Schultz Zavin3df181c2012-11-15 10:43:46 -0800273 .map_kernel = ion_heap_map_kernel,
274 .unmap_kernel = ion_heap_unmap_kernel,
275 .map_user = ion_heap_map_user,
Olav Haugan3d4fe1a2012-01-13 11:42:15 -0800276 .print_debug = ion_system_print_debug,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700277};
278
Olav Haugan85c95402012-05-30 17:32:37 -0700279struct ion_heap *ion_system_heap_create(struct ion_platform_heap *pheap)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700280{
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700281 struct ion_system_heap *heap;
282 int i;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700283
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700284 heap = kzalloc(sizeof(struct ion_system_heap), GFP_KERNEL);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700285 if (!heap)
286 return ERR_PTR(-ENOMEM);
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700287 heap->heap.ops = &system_heap_ops;
288 heap->heap.type = ION_HEAP_TYPE_SYSTEM;
Rebecca Schultz Zavin618d6be2013-02-13 14:48:11 -0800289 heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE;
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700290 heap->pools = kzalloc(sizeof(struct ion_page_pool *) * num_orders,
291 GFP_KERNEL);
292 if (!heap->pools)
293 goto err_alloc_pools;
294 for (i = 0; i < num_orders; i++) {
295 struct ion_page_pool *pool;
Rebecca Schultz Zavinbff299e2012-10-02 22:43:41 -0700296 gfp_t gfp_flags = low_order_gfp_flags;
297
298 if (orders[i] > 4)
299 gfp_flags = high_order_gfp_flags;
300 pool = ion_page_pool_create(gfp_flags, orders[i]);
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700301 if (!pool)
302 goto err_create_pool;
303 heap->pools[i] = pool;
304 }
305 return &heap->heap;
306err_create_pool:
307 for (i = 0; i < num_orders; i++)
308 if (heap->pools[i])
309 ion_page_pool_destroy(heap->pools[i]);
310 kfree(heap->pools);
311err_alloc_pools:
312 kfree(heap);
313 return ERR_PTR(-ENOMEM);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700314}
315
316void ion_system_heap_destroy(struct ion_heap *heap)
317{
Rebecca Schultz Zavin943facc2012-08-06 21:37:23 -0700318 struct ion_system_heap *sys_heap = container_of(heap,
319 struct ion_system_heap,
320 heap);
321 int i;
322
323 for (i = 0; i < num_orders; i++)
324 ion_page_pool_destroy(sys_heap->pools[i]);
325 kfree(sys_heap->pools);
326 kfree(sys_heap);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700327}
328
329static int ion_system_contig_heap_allocate(struct ion_heap *heap,
330 struct ion_buffer *buffer,
331 unsigned long len,
332 unsigned long align,
333 unsigned long flags)
334{
335 buffer->priv_virt = kzalloc(len, GFP_KERNEL);
336 if (!buffer->priv_virt)
337 return -ENOMEM;
Laura Abbott68c80642011-10-21 17:32:27 -0700338 atomic_add(len, &system_contig_heap_allocated);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700339 return 0;
340}
341
342void ion_system_contig_heap_free(struct ion_buffer *buffer)
343{
344 kfree(buffer->priv_virt);
Laura Abbott68c80642011-10-21 17:32:27 -0700345 atomic_sub(buffer->size, &system_contig_heap_allocated);
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700346}
347
348static int ion_system_contig_heap_phys(struct ion_heap *heap,
349 struct ion_buffer *buffer,
350 ion_phys_addr_t *addr, size_t *len)
351{
352 *addr = virt_to_phys(buffer->priv_virt);
353 *len = buffer->size;
354 return 0;
355}
356
Laura Abbottb14ed962012-01-30 14:18:08 -0800357struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap,
Rebecca Schultz Zavinb1790672012-06-14 15:08:53 -0700358 struct ion_buffer *buffer)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700359{
Laura Abbottb14ed962012-01-30 14:18:08 -0800360 struct sg_table *table;
361 int ret;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700362
Laura Abbottb14ed962012-01-30 14:18:08 -0800363 table = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
364 if (!table)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700365 return ERR_PTR(-ENOMEM);
Laura Abbottb14ed962012-01-30 14:18:08 -0800366 ret = sg_alloc_table(table, 1, GFP_KERNEL);
367 if (ret) {
368 kfree(table);
369 return ERR_PTR(ret);
370 }
371 sg_set_page(table->sgl, virt_to_page(buffer->priv_virt), buffer->size,
372 0);
373 return table;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700374}
375
Rebecca Schultz Zavinb1790672012-06-14 15:08:53 -0700376void ion_system_contig_heap_unmap_dma(struct ion_heap *heap,
377 struct ion_buffer *buffer)
378{
379 sg_free_table(buffer->sg_table);
380 kfree(buffer->sg_table);
381}
382
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700383int ion_system_contig_heap_map_user(struct ion_heap *heap,
384 struct ion_buffer *buffer,
Laura Abbottb14ed962012-01-30 14:18:08 -0800385 struct vm_area_struct *vma)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700386{
387 unsigned long pfn = __phys_to_pfn(virt_to_phys(buffer->priv_virt));
Laura Abbott894fd582011-08-19 13:33:56 -0700388
Laura Abbottb14ed962012-01-30 14:18:08 -0800389 if (ION_IS_CACHED(buffer->flags))
Laura Abbott894fd582011-08-19 13:33:56 -0700390 return remap_pfn_range(vma, vma->vm_start, pfn + vma->vm_pgoff,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700391 vma->vm_end - vma->vm_start,
392 vma->vm_page_prot);
Laura Abbott894fd582011-08-19 13:33:56 -0700393 else {
394 pr_err("%s: cannot map system heap uncached\n", __func__);
395 return -EINVAL;
396 }
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700397}
398
Olav Haugan3d4fe1a2012-01-13 11:42:15 -0800399static int ion_system_contig_print_debug(struct ion_heap *heap,
Olav Haugan0671b9a2012-05-25 11:58:56 -0700400 struct seq_file *s,
401 const struct rb_root *unused)
Laura Abbott68c80642011-10-21 17:32:27 -0700402{
Olav Haugan3d4fe1a2012-01-13 11:42:15 -0800403 seq_printf(s, "total bytes currently allocated: %lx\n",
404 (unsigned long) atomic_read(&system_contig_heap_allocated));
405
406 return 0;
Laura Abbott68c80642011-10-21 17:32:27 -0700407}
408
Rohit Vaswani35edc882012-11-20 10:20:47 -0800409void *ion_system_contig_heap_map_kernel(struct ion_heap *heap,
410 struct ion_buffer *buffer)
411{
412 return buffer->priv_virt;
413}
414
415void ion_system_contig_heap_unmap_kernel(struct ion_heap *heap,
416 struct ion_buffer *buffer)
417{
418 return;
419}
420
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700421static struct ion_heap_ops kmalloc_ops = {
422 .allocate = ion_system_contig_heap_allocate,
423 .free = ion_system_contig_heap_free,
424 .phys = ion_system_contig_heap_phys,
425 .map_dma = ion_system_contig_heap_map_dma,
Rebecca Schultz Zavinb1790672012-06-14 15:08:53 -0700426 .unmap_dma = ion_system_contig_heap_unmap_dma,
Rebecca Schultz Zavin3df181c2012-11-15 10:43:46 -0800427 .map_kernel = ion_heap_map_kernel,
428 .unmap_kernel = ion_heap_unmap_kernel,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700429 .map_user = ion_system_contig_heap_map_user,
Olav Haugan3d4fe1a2012-01-13 11:42:15 -0800430 .print_debug = ion_system_contig_print_debug,
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700431};
432
Olav Haugan85c95402012-05-30 17:32:37 -0700433struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *pheap)
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700434{
435 struct ion_heap *heap;
436
437 heap = kzalloc(sizeof(struct ion_heap), GFP_KERNEL);
438 if (!heap)
439 return ERR_PTR(-ENOMEM);
440 heap->ops = &kmalloc_ops;
441 heap->type = ION_HEAP_TYPE_SYSTEM_CONTIG;
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -0700442 return heap;
443}
444
445void ion_system_contig_heap_destroy(struct ion_heap *heap)
446{
447 kfree(heap);
448}
449