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. |
| 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 | |
| 26 | struct ion_mapping; |
| 27 | |
| 28 | struct ion_dma_mapping { |
| 29 | struct kref ref; |
| 30 | struct scatterlist *sglist; |
| 31 | }; |
| 32 | |
| 33 | struct ion_kernel_mapping { |
| 34 | struct kref ref; |
| 35 | void *vaddr; |
| 36 | }; |
| 37 | |
| 38 | struct 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 | * @priv_virt: private data to the buffer representable as |
| 49 | * a void * |
| 50 | * @priv_phys: private data to the buffer representable as |
| 51 | * an ion_phys_addr_t (and someday a phys_addr_t) |
| 52 | * @lock: protects the buffers cnt fields |
| 53 | * @kmap_cnt: number of times the buffer is mapped to the kernel |
| 54 | * @vaddr: the kenrel mapping if kmap_cnt is not zero |
| 55 | * @dmap_cnt: number of times the buffer is mapped for dma |
| 56 | * @sglist: the scatterlist for the buffer is dmap_cnt is not zero |
| 57 | */ |
| 58 | struct ion_buffer { |
| 59 | struct kref ref; |
| 60 | struct rb_node node; |
| 61 | struct ion_device *dev; |
| 62 | struct ion_heap *heap; |
| 63 | unsigned long flags; |
| 64 | size_t size; |
| 65 | union { |
| 66 | void *priv_virt; |
| 67 | ion_phys_addr_t priv_phys; |
| 68 | }; |
| 69 | struct mutex lock; |
| 70 | int kmap_cnt; |
| 71 | void *vaddr; |
| 72 | int dmap_cnt; |
| 73 | struct scatterlist *sglist; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * struct ion_heap_ops - ops to operate on a given heap |
| 78 | * @allocate: allocate memory |
| 79 | * @free: free memory |
| 80 | * @phys get physical address of a buffer (only define on |
| 81 | * physically contiguous heaps) |
| 82 | * @map_dma map the memory for dma to a scatterlist |
| 83 | * @unmap_dma unmap the memory for dma |
| 84 | * @map_kernel map memory to the kernel |
| 85 | * @unmap_kernel unmap memory to the kernel |
| 86 | * @map_user map memory to userspace |
| 87 | */ |
| 88 | struct ion_heap_ops { |
| 89 | int (*allocate) (struct ion_heap *heap, |
| 90 | struct ion_buffer *buffer, unsigned long len, |
| 91 | unsigned long align, unsigned long flags); |
| 92 | void (*free) (struct ion_buffer *buffer); |
| 93 | int (*phys) (struct ion_heap *heap, struct ion_buffer *buffer, |
| 94 | ion_phys_addr_t *addr, size_t *len); |
| 95 | struct scatterlist *(*map_dma) (struct ion_heap *heap, |
| 96 | struct ion_buffer *buffer); |
| 97 | void (*unmap_dma) (struct ion_heap *heap, struct ion_buffer *buffer); |
| 98 | void * (*map_kernel) (struct ion_heap *heap, struct ion_buffer *buffer); |
| 99 | void (*unmap_kernel) (struct ion_heap *heap, struct ion_buffer *buffer); |
| 100 | int (*map_user) (struct ion_heap *mapper, struct ion_buffer *buffer, |
| 101 | struct vm_area_struct *vma); |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct ion_heap - represents a heap in the system |
| 106 | * @node: rb node to put the heap on the device's tree of heaps |
| 107 | * @dev: back pointer to the ion_device |
| 108 | * @type: type of heap |
| 109 | * @ops: ops struct as above |
| 110 | * @id: id of heap, also indicates priority of this heap when |
| 111 | * allocating. These are specified by platform data and |
| 112 | * MUST be unique |
| 113 | * @name: used for debugging |
| 114 | * |
| 115 | * Represents a pool of memory from which buffers can be made. In some |
| 116 | * systems the only heap is regular system memory allocated via vmalloc. |
| 117 | * On others, some blocks might require large physically contiguous buffers |
| 118 | * that are allocated from a specially reserved heap. |
| 119 | */ |
| 120 | struct ion_heap { |
| 121 | struct rb_node node; |
| 122 | struct ion_device *dev; |
| 123 | enum ion_heap_type type; |
| 124 | struct ion_heap_ops *ops; |
| 125 | int id; |
| 126 | const char *name; |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * ion_device_create - allocates and returns an ion device |
| 131 | * @custom_ioctl: arch specific ioctl function if applicable |
| 132 | * |
| 133 | * returns a valid device or -PTR_ERR |
| 134 | */ |
| 135 | struct ion_device *ion_device_create(long (*custom_ioctl) |
| 136 | (struct ion_client *client, |
| 137 | unsigned int cmd, |
| 138 | unsigned long arg)); |
| 139 | |
| 140 | /** |
| 141 | * ion_device_destroy - free and device and it's resource |
| 142 | * @dev: the device |
| 143 | */ |
| 144 | void ion_device_destroy(struct ion_device *dev); |
| 145 | |
| 146 | /** |
| 147 | * ion_device_add_heap - adds a heap to the ion device |
| 148 | * @dev: the device |
| 149 | * @heap: the heap to add |
| 150 | */ |
| 151 | void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap); |
| 152 | |
| 153 | /** |
| 154 | * functions for creating and destroying the built in ion heaps. |
| 155 | * architectures can add their own custom architecture specific |
| 156 | * heaps as appropriate. |
| 157 | */ |
| 158 | |
| 159 | struct ion_heap *ion_heap_create(struct ion_platform_heap *); |
| 160 | void ion_heap_destroy(struct ion_heap *); |
| 161 | |
| 162 | struct ion_heap *ion_system_heap_create(struct ion_platform_heap *); |
| 163 | void ion_system_heap_destroy(struct ion_heap *); |
| 164 | |
| 165 | struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *); |
| 166 | void ion_system_contig_heap_destroy(struct ion_heap *); |
| 167 | |
| 168 | struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *); |
| 169 | void ion_carveout_heap_destroy(struct ion_heap *); |
| 170 | /** |
| 171 | * kernel api to allocate/free from carveout -- used when carveout is |
| 172 | * used to back an architecture specific custom heap |
| 173 | */ |
| 174 | ion_phys_addr_t ion_carveout_allocate(struct ion_heap *heap, unsigned long size, |
| 175 | unsigned long align); |
| 176 | void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, |
| 177 | unsigned long size); |
| 178 | /** |
| 179 | * The carveout heap returns physical addresses, since 0 may be a valid |
| 180 | * physical address, this is used to indicate allocation failed |
| 181 | */ |
| 182 | #define ION_CARVEOUT_ALLOCATE_FAIL -1 |
| 183 | |
| 184 | #endif /* _ION_PRIV_H */ |