Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * drivers/staging/android/ion/ion.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 _LINUX_ION_H |
| 18 | #define _LINUX_ION_H |
| 19 | |
| 20 | #include <linux/types.h> |
| 21 | |
Colin Cross | c3a2fe0 | 2013-12-13 14:24:57 -0800 | [diff] [blame] | 22 | #include "../uapi/ion.h" |
Rom Lemarchand | 22b7f24 | 2013-12-13 14:24:53 -0800 | [diff] [blame] | 23 | |
Rom Lemarchand | b88fa73 | 2013-12-13 14:24:54 -0800 | [diff] [blame] | 24 | struct ion_handle; |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 25 | struct ion_device; |
| 26 | struct ion_heap; |
| 27 | struct ion_mapper; |
| 28 | struct ion_client; |
| 29 | struct ion_buffer; |
| 30 | |
Sriram Raghunathan | 7e41617 | 2015-09-22 22:35:51 +0530 | [diff] [blame] | 31 | /* |
| 32 | * This should be removed some day when phys_addr_t's are fully |
| 33 | * plumbed in the kernel, and all instances of ion_phys_addr_t should |
| 34 | * be converted to phys_addr_t. For the time being many kernel interfaces |
| 35 | * do not accept phys_addr_t's that would have to |
| 36 | */ |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 37 | #define ion_phys_addr_t unsigned long |
| 38 | |
| 39 | /** |
| 40 | * struct ion_platform_heap - defines a heap in the given platform |
| 41 | * @type: type of the heap from ion_heap_type enum |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 42 | * @id: unique identifier for heap. When allocating higher numbers |
John Stultz | e1d855b | 2013-12-13 19:26:33 -0800 | [diff] [blame] | 43 | * will be allocated from first. At allocation these are passed |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 44 | * as a bit mask and therefore can not exceed ION_NUM_HEAP_IDS. |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 45 | * @name: used for debug purposes |
| 46 | * @base: base address of heap in physical memory if applicable |
| 47 | * @size: size of the heap in bytes if applicable |
Rebecca Schultz Zavin | e3c2eb7 | 2013-12-13 14:24:27 -0800 | [diff] [blame] | 48 | * @align: required alignment in physical memory if applicable |
| 49 | * @priv: private info passed from the board file |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 50 | * |
| 51 | * Provided by the board file. |
| 52 | */ |
| 53 | struct ion_platform_heap { |
| 54 | enum ion_heap_type type; |
| 55 | unsigned int id; |
| 56 | const char *name; |
| 57 | ion_phys_addr_t base; |
| 58 | size_t size; |
Rebecca Schultz Zavin | e3c2eb7 | 2013-12-13 14:24:27 -0800 | [diff] [blame] | 59 | ion_phys_addr_t align; |
| 60 | void *priv; |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /** |
| 64 | * struct ion_platform_data - array of platform heaps passed from board file |
| 65 | * @nr: number of structures in the array |
| 66 | * @heaps: array of platform_heap structions |
| 67 | * |
| 68 | * Provided by the board file in the form of platform data to a platform device. |
| 69 | */ |
| 70 | struct ion_platform_data { |
| 71 | int nr; |
Benjamin Gaignard | 19007b1 | 2013-12-13 14:24:43 -0800 | [diff] [blame] | 72 | struct ion_platform_heap *heaps; |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * ion_client_create() - allocate a client and returns it |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 77 | * @dev: the global ion device |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 78 | * @name: used for debugging |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 79 | */ |
| 80 | struct ion_client *ion_client_create(struct ion_device *dev, |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 81 | const char *name); |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * ion_client_destroy() - free's a client and all it's handles |
| 85 | * @client: the client |
| 86 | * |
| 87 | * Free the provided client and all it's resources including |
| 88 | * any handles it is holding. |
| 89 | */ |
| 90 | void ion_client_destroy(struct ion_client *client); |
| 91 | |
| 92 | /** |
| 93 | * ion_alloc - allocate ion memory |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 94 | * @client: the client |
| 95 | * @len: size of the allocation |
| 96 | * @align: requested allocation alignment, lots of hardware blocks |
| 97 | * have alignment requirements of some kind |
| 98 | * @heap_id_mask: mask of heaps to allocate from, if multiple bits are set |
| 99 | * heaps will be tried in order from highest to lowest |
| 100 | * id |
| 101 | * @flags: heap flags, the low 16 bits are consumed by ion, the |
| 102 | * high 16 bits are passed on to the respective heap and |
| 103 | * can be heap custom |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 104 | * |
| 105 | * Allocate memory in one of the heaps provided in heap mask and return |
| 106 | * an opaque handle to it. |
| 107 | */ |
| 108 | struct ion_handle *ion_alloc(struct ion_client *client, size_t len, |
Rebecca Schultz Zavin | 38eeeb5 | 2013-12-13 14:24:28 -0800 | [diff] [blame] | 109 | size_t align, unsigned int heap_id_mask, |
Rebecca Schultz Zavin | 56a7c18 | 2013-12-13 14:23:50 -0800 | [diff] [blame] | 110 | unsigned int flags); |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * ion_free - free a handle |
| 114 | * @client: the client |
| 115 | * @handle: the handle to free |
| 116 | * |
| 117 | * Free the provided handle. |
| 118 | */ |
| 119 | void ion_free(struct ion_client *client, struct ion_handle *handle); |
| 120 | |
| 121 | /** |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 122 | * ion_map_kernel - create mapping for the given handle |
| 123 | * @client: the client |
| 124 | * @handle: handle to map |
| 125 | * |
| 126 | * Map the given handle into the kernel and return a kernel address that |
| 127 | * can be used to access this address. |
| 128 | */ |
| 129 | void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle); |
| 130 | |
| 131 | /** |
| 132 | * ion_unmap_kernel() - destroy a kernel mapping for a handle |
| 133 | * @client: the client |
| 134 | * @handle: handle to unmap |
| 135 | */ |
| 136 | void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); |
| 137 | |
| 138 | /** |
Johan Mossberg | 22ba432 | 2013-12-13 14:24:34 -0800 | [diff] [blame] | 139 | * ion_share_dma_buf() - share buffer as dma-buf |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 140 | * @client: the client |
Rebecca Schultz Zavin | b892bf7 | 2013-12-13 14:23:40 -0800 | [diff] [blame] | 141 | * @handle: the handle |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 142 | */ |
Johan Mossberg | 22ba432 | 2013-12-13 14:24:34 -0800 | [diff] [blame] | 143 | struct dma_buf *ion_share_dma_buf(struct ion_client *client, |
| 144 | struct ion_handle *handle); |
| 145 | |
| 146 | /** |
| 147 | * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd |
| 148 | * @client: the client |
| 149 | * @handle: the handle |
| 150 | */ |
| 151 | int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle); |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
Rohit kumar | 9f90381 | 2016-01-12 09:31:46 +0530 | [diff] [blame] | 154 | * ion_import_dma_buf() - get ion_handle from dma-buf |
| 155 | * @client: the client |
| 156 | * @dmabuf: the dma-buf |
| 157 | * |
| 158 | * Get the ion_buffer associated with the dma-buf and return the ion_handle. |
| 159 | * If no ion_handle exists for this buffer, return newly created ion_handle. |
| 160 | * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL) |
| 161 | */ |
| 162 | struct ion_handle *ion_import_dma_buf(struct ion_client *client, |
| 163 | struct dma_buf *dmabuf); |
| 164 | |
| 165 | /** |
| 166 | * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get handle |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 167 | * @client: the client |
Rebecca Schultz Zavin | b892bf7 | 2013-12-13 14:23:40 -0800 | [diff] [blame] | 168 | * @fd: the dma-buf fd |
| 169 | * |
Rohit kumar | 9f90381 | 2016-01-12 09:31:46 +0530 | [diff] [blame] | 170 | * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd, |
| 171 | * import that fd and return a handle representing it. If a dma-buf from |
Rebecca Schultz Zavin | b892bf7 | 2013-12-13 14:23:40 -0800 | [diff] [blame] | 172 | * another exporter is passed in this function will return ERR_PTR(-EINVAL) |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 173 | */ |
Rohit kumar | 9f90381 | 2016-01-12 09:31:46 +0530 | [diff] [blame] | 174 | struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd); |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 175 | |
Rebecca Schultz Zavin | c30707b | 2013-12-13 19:38:38 -0800 | [diff] [blame] | 176 | #endif /* _LINUX_ION_H */ |