blob: fdbd2bef5c58bebf81087ad082a636f5578aadd4 [file] [log] [blame]
Rebecca Schultz Zavinc80005a2011-06-29 19:44:29 -07001/*
2 * drivers/gpu/ion/ion_priv.h
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
17#ifndef _ION_PRIV_H
18#define _ION_PRIV_H
19
20#include <linux/kref.h>
21#include <linux/mm_types.h>
22#include <linux/mutex.h>
23#include <linux/rbtree.h>
24#include <linux/ion.h>
25
26struct ion_mapping;
27
28struct ion_dma_mapping {
29 struct kref ref;
30 struct scatterlist *sglist;
31};
32
33struct ion_kernel_mapping {
34 struct kref ref;
35 void *vaddr;
36};
37
38struct ion_buffer *ion_handle_buffer(struct ion_handle *handle);
39
40/**
41 * struct ion_buffer - metadata for a particular buffer
42 * @ref: refernce count
43 * @node: node in the ion_device buffers tree
44 * @dev: back pointer to the ion_device
45 * @heap: back pointer to the heap the buffer came from
46 * @flags: buffer specific flags
47 * @size: size of the buffer
48*/
49struct ion_buffer {
50 struct kref ref;
51 struct rb_node node;
52 struct ion_device *dev;
53 struct ion_heap *heap;
54 unsigned long flags;
55 size_t size;
56 union {
57 void *priv_virt;
58 ion_phys_addr_t priv_phys;
59 };
60 struct mutex lock;
61 int kmap_cnt;
62 void *vaddr;
63 int dmap_cnt;
64 struct scatterlist *sglist;
65};
66
67/**
68 * struct ion_heap_ops - ops to operate on a given heap
69 * @allocate: allocate memory
70 * @free: free memory
71 * @phys get physical address of a buffer (only define on
72 * physically contiguous heaps)
73 * @map_dma map the memory for dma to a scatterlist
74 * @map_kernel map memory to the kernel
75 * @map_user map memory to userspace
76 */
77struct ion_heap_ops {
78 int (*allocate) (struct ion_heap *heap,
79 struct ion_buffer *buffer, unsigned long len,
80 unsigned long align, unsigned long flags);
81 void (*free) (struct ion_buffer *buffer);
82 int (*phys) (struct ion_heap *heap, struct ion_buffer *buffer,
83 ion_phys_addr_t *addr, size_t *len);
84 struct scatterlist *(*map_dma) (struct ion_heap *heap,
85 struct ion_buffer *buffer);
86 void (*unmap_dma) (struct ion_heap *heap, struct ion_buffer *buffer);
87 void * (*map_kernel) (struct ion_heap *heap, struct ion_buffer *buffer);
88 void (*unmap_kernel) (struct ion_heap *heap, struct ion_buffer *buffer);
89 int (*map_user) (struct ion_heap *mapper, struct ion_buffer *buffer,
90 struct vm_area_struct *vma);
91};
92
93/**
94 * struct ion_heap - represents a heap in the system
95 * @node: rb node to put the heap on the device's tree of heaps
96 * @dev: back pointer to the ion_device
97 * @type: type of heap
98 * @ops: ops struct as above
99 * @prio: priority (lower numbers first) of this heap when
100 * allocating. These are specified by platform data and
101 * MUST be unique
102 * @priv: private data used by the heap implementation
103 *
104 * Represents a pool of memory from which buffers can be made. In some
105 * systems the only heap is regular system memory allocated via vmalloc.
106 * On others, some blocks might require large physically contiguous buffers
107 * that are allocated from a specially reserved heap.
108 */
109struct ion_heap {
110 struct rb_node node;
111 struct ion_device *dev;
112 enum ion_heap_type type;
113 struct ion_heap_ops *ops;
114 int prio;
115 const char *name;
116};
117
118/**
119 * ion_device_create - allocates and returns an ion device
120 *
121 * returns a valid device or -PTR_ERR
122 */
123struct ion_device *ion_device_create(long (*custom_ioctl)
124 (struct ion_client *client,
125 unsigned int cmd,
126 unsigned long arg));
127
128/**
129 * ion_device_destroy - free and device and it's resource
130 * @dev: the device
131 */
132void ion_device_destroy(struct ion_device *dev);
133
134/**
135 * ion_device_add_heap - adds a heap to the ion device
136 * @dev: the device
137 * @heap: the heap to add
138 */
139void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap);
140
141/* CREATE HEAPS */
142struct ion_heap *ion_heap_create(struct ion_platform_heap *);
143void ion_heap_destroy(struct ion_heap *);
144
145struct ion_heap *ion_system_heap_create(struct ion_platform_heap *);
146void ion_system_heap_destroy(struct ion_heap *);
147
148struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *);
149void ion_system_contig_heap_destroy(struct ion_heap *);
150
151struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *);
152void ion_carveout_heap_destroy(struct ion_heap *);
153ion_phys_addr_t ion_carveout_allocate(struct ion_heap *heap, unsigned long size,
154 unsigned long align);
155void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr,
156 unsigned long size);
157
158#define ION_CARVEOUT_ALLOCATE_FAIL -1
159
160#endif /* _ION_PRIV_H */