Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Framework for buffer objects that can be shared across devices/subsystems. |
| 3 | * |
| 4 | * Copyright(C) 2011 Linaro Limited. All rights reserved. |
| 5 | * Author: Sumit Semwal <sumit.semwal@ti.com> |
| 6 | * |
| 7 | * Many thanks to linaro-mm-sig list, and specially |
| 8 | * Arnd Bergmann <arnd@arndb.de>, Rob Clark <rob@ti.com> and |
| 9 | * Daniel Vetter <daniel@ffwll.ch> for their support in creation and |
| 10 | * refining of this idea. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published by |
| 14 | * the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 19 | * more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/dma-buf.h> |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 28 | #include <linux/dma-fence.h> |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 29 | #include <linux/anon_inodes.h> |
| 30 | #include <linux/export.h> |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 32 | #include <linux/module.h> |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 33 | #include <linux/seq_file.h> |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 34 | #include <linux/poll.h> |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 35 | #include <linux/reservation.h> |
Muhammad Falak R Wani | b02da6f | 2016-05-23 17:08:42 +0530 | [diff] [blame] | 36 | #include <linux/mm.h> |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 37 | |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 38 | #include <uapi/linux/dma-buf.h> |
| 39 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 40 | static inline int is_dma_buf_file(struct file *); |
| 41 | |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 42 | struct dma_buf_list { |
| 43 | struct list_head head; |
| 44 | struct mutex lock; |
| 45 | }; |
| 46 | |
| 47 | static struct dma_buf_list db_list; |
| 48 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 49 | static int dma_buf_release(struct inode *inode, struct file *file) |
| 50 | { |
| 51 | struct dma_buf *dmabuf; |
| 52 | |
| 53 | if (!is_dma_buf_file(file)) |
| 54 | return -EINVAL; |
| 55 | |
| 56 | dmabuf = file->private_data; |
| 57 | |
Daniel Vetter | f00b4da | 2012-12-20 14:14:23 +0100 | [diff] [blame] | 58 | BUG_ON(dmabuf->vmapping_counter); |
| 59 | |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 60 | /* |
| 61 | * Any fences that a dma-buf poll can wait on should be signaled |
| 62 | * before releasing dma-buf. This is the responsibility of each |
| 63 | * driver that uses the reservation objects. |
| 64 | * |
| 65 | * If you hit this BUG() it means someone dropped their ref to the |
| 66 | * dma-buf while still having pending operation to the buffer. |
| 67 | */ |
| 68 | BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active); |
| 69 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 70 | dmabuf->ops->release(dmabuf); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 71 | |
| 72 | mutex_lock(&db_list.lock); |
| 73 | list_del(&dmabuf->list_node); |
| 74 | mutex_unlock(&db_list.lock); |
| 75 | |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 76 | if (dmabuf->resv == (struct reservation_object *)&dmabuf[1]) |
| 77 | reservation_object_fini(dmabuf->resv); |
| 78 | |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 79 | module_put(dmabuf->owner); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 80 | kfree(dmabuf); |
| 81 | return 0; |
| 82 | } |
| 83 | |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 84 | static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma) |
| 85 | { |
| 86 | struct dma_buf *dmabuf; |
| 87 | |
| 88 | if (!is_dma_buf_file(file)) |
| 89 | return -EINVAL; |
| 90 | |
| 91 | dmabuf = file->private_data; |
| 92 | |
| 93 | /* check for overflowing the buffer's size */ |
Muhammad Falak R Wani | b02da6f | 2016-05-23 17:08:42 +0530 | [diff] [blame] | 94 | if (vma->vm_pgoff + vma_pages(vma) > |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 95 | dmabuf->size >> PAGE_SHIFT) |
| 96 | return -EINVAL; |
| 97 | |
| 98 | return dmabuf->ops->mmap(dmabuf, vma); |
| 99 | } |
| 100 | |
Christopher James Halse Rogers | 19e8697 | 2013-09-10 11:36:45 +0530 | [diff] [blame] | 101 | static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence) |
| 102 | { |
| 103 | struct dma_buf *dmabuf; |
| 104 | loff_t base; |
| 105 | |
| 106 | if (!is_dma_buf_file(file)) |
| 107 | return -EBADF; |
| 108 | |
| 109 | dmabuf = file->private_data; |
| 110 | |
| 111 | /* only support discovering the end of the buffer, |
| 112 | but also allow SEEK_SET to maintain the idiomatic |
| 113 | SEEK_END(0), SEEK_CUR(0) pattern */ |
| 114 | if (whence == SEEK_END) |
| 115 | base = dmabuf->size; |
| 116 | else if (whence == SEEK_SET) |
| 117 | base = 0; |
| 118 | else |
| 119 | return -EINVAL; |
| 120 | |
| 121 | if (offset != 0) |
| 122 | return -EINVAL; |
| 123 | |
| 124 | return base + offset; |
| 125 | } |
| 126 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 127 | static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 128 | { |
| 129 | struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb; |
| 130 | unsigned long flags; |
| 131 | |
| 132 | spin_lock_irqsave(&dcb->poll->lock, flags); |
| 133 | wake_up_locked_poll(dcb->poll, dcb->active); |
| 134 | dcb->active = 0; |
| 135 | spin_unlock_irqrestore(&dcb->poll->lock, flags); |
| 136 | } |
| 137 | |
| 138 | static unsigned int dma_buf_poll(struct file *file, poll_table *poll) |
| 139 | { |
| 140 | struct dma_buf *dmabuf; |
| 141 | struct reservation_object *resv; |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 142 | struct reservation_object_list *fobj; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 143 | struct dma_fence *fence_excl; |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 144 | unsigned long events; |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 145 | unsigned shared_count, seq; |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 146 | |
| 147 | dmabuf = file->private_data; |
| 148 | if (!dmabuf || !dmabuf->resv) |
| 149 | return POLLERR; |
| 150 | |
| 151 | resv = dmabuf->resv; |
| 152 | |
| 153 | poll_wait(file, &dmabuf->poll, poll); |
| 154 | |
| 155 | events = poll_requested_events(poll) & (POLLIN | POLLOUT); |
| 156 | if (!events) |
| 157 | return 0; |
| 158 | |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 159 | retry: |
| 160 | seq = read_seqcount_begin(&resv->seq); |
| 161 | rcu_read_lock(); |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 162 | |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 163 | fobj = rcu_dereference(resv->fence); |
| 164 | if (fobj) |
| 165 | shared_count = fobj->shared_count; |
| 166 | else |
| 167 | shared_count = 0; |
| 168 | fence_excl = rcu_dereference(resv->fence_excl); |
| 169 | if (read_seqcount_retry(&resv->seq, seq)) { |
| 170 | rcu_read_unlock(); |
| 171 | goto retry; |
| 172 | } |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 173 | |
| 174 | if (fence_excl && (!(events & POLLOUT) || shared_count == 0)) { |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 175 | struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_excl; |
| 176 | unsigned long pevents = POLLIN; |
| 177 | |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 178 | if (shared_count == 0) |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 179 | pevents |= POLLOUT; |
| 180 | |
| 181 | spin_lock_irq(&dmabuf->poll.lock); |
| 182 | if (dcb->active) { |
| 183 | dcb->active |= pevents; |
| 184 | events &= ~pevents; |
| 185 | } else |
| 186 | dcb->active = pevents; |
| 187 | spin_unlock_irq(&dmabuf->poll.lock); |
| 188 | |
| 189 | if (events & pevents) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 190 | if (!dma_fence_get_rcu(fence_excl)) { |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 191 | /* force a recheck */ |
| 192 | events &= ~pevents; |
| 193 | dma_buf_poll_cb(NULL, &dcb->cb); |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 194 | } else if (!dma_fence_add_callback(fence_excl, &dcb->cb, |
| 195 | dma_buf_poll_cb)) { |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 196 | events &= ~pevents; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 197 | dma_fence_put(fence_excl); |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 198 | } else { |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 199 | /* |
| 200 | * No callback queued, wake up any additional |
| 201 | * waiters. |
| 202 | */ |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 203 | dma_fence_put(fence_excl); |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 204 | dma_buf_poll_cb(NULL, &dcb->cb); |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 205 | } |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 209 | if ((events & POLLOUT) && shared_count > 0) { |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 210 | struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_shared; |
| 211 | int i; |
| 212 | |
| 213 | /* Only queue a new callback if no event has fired yet */ |
| 214 | spin_lock_irq(&dmabuf->poll.lock); |
| 215 | if (dcb->active) |
| 216 | events &= ~POLLOUT; |
| 217 | else |
| 218 | dcb->active = POLLOUT; |
| 219 | spin_unlock_irq(&dmabuf->poll.lock); |
| 220 | |
| 221 | if (!(events & POLLOUT)) |
| 222 | goto out; |
| 223 | |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 224 | for (i = 0; i < shared_count; ++i) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 225 | struct dma_fence *fence = rcu_dereference(fobj->shared[i]); |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 226 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 227 | if (!dma_fence_get_rcu(fence)) { |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 228 | /* |
| 229 | * fence refcount dropped to zero, this means |
| 230 | * that fobj has been freed |
| 231 | * |
| 232 | * call dma_buf_poll_cb and force a recheck! |
| 233 | */ |
| 234 | events &= ~POLLOUT; |
| 235 | dma_buf_poll_cb(NULL, &dcb->cb); |
| 236 | break; |
| 237 | } |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 238 | if (!dma_fence_add_callback(fence, &dcb->cb, |
| 239 | dma_buf_poll_cb)) { |
| 240 | dma_fence_put(fence); |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 241 | events &= ~POLLOUT; |
| 242 | break; |
| 243 | } |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 244 | dma_fence_put(fence); |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 245 | } |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 246 | |
| 247 | /* No callback queued, wake up any additional waiters. */ |
Maarten Lankhorst | 04a5faa | 2014-07-01 12:57:54 +0200 | [diff] [blame] | 248 | if (i == shared_count) |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 249 | dma_buf_poll_cb(NULL, &dcb->cb); |
| 250 | } |
| 251 | |
| 252 | out: |
Maarten Lankhorst | 3c3b177 | 2014-07-01 12:58:00 +0200 | [diff] [blame] | 253 | rcu_read_unlock(); |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 254 | return events; |
| 255 | } |
| 256 | |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 257 | static long dma_buf_ioctl(struct file *file, |
| 258 | unsigned int cmd, unsigned long arg) |
| 259 | { |
| 260 | struct dma_buf *dmabuf; |
| 261 | struct dma_buf_sync sync; |
| 262 | enum dma_data_direction direction; |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 263 | int ret; |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 264 | |
| 265 | dmabuf = file->private_data; |
| 266 | |
| 267 | switch (cmd) { |
| 268 | case DMA_BUF_IOCTL_SYNC: |
| 269 | if (copy_from_user(&sync, (void __user *) arg, sizeof(sync))) |
| 270 | return -EFAULT; |
| 271 | |
| 272 | if (sync.flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK) |
| 273 | return -EINVAL; |
| 274 | |
| 275 | switch (sync.flags & DMA_BUF_SYNC_RW) { |
| 276 | case DMA_BUF_SYNC_READ: |
| 277 | direction = DMA_FROM_DEVICE; |
| 278 | break; |
| 279 | case DMA_BUF_SYNC_WRITE: |
| 280 | direction = DMA_TO_DEVICE; |
| 281 | break; |
| 282 | case DMA_BUF_SYNC_RW: |
| 283 | direction = DMA_BIDIRECTIONAL; |
| 284 | break; |
| 285 | default: |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | |
| 289 | if (sync.flags & DMA_BUF_SYNC_END) |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 290 | ret = dma_buf_end_cpu_access(dmabuf, direction); |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 291 | else |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 292 | ret = dma_buf_begin_cpu_access(dmabuf, direction); |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 293 | |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 294 | return ret; |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 295 | default: |
| 296 | return -ENOTTY; |
| 297 | } |
| 298 | } |
| 299 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 300 | static const struct file_operations dma_buf_fops = { |
| 301 | .release = dma_buf_release, |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 302 | .mmap = dma_buf_mmap_internal, |
Christopher James Halse Rogers | 19e8697 | 2013-09-10 11:36:45 +0530 | [diff] [blame] | 303 | .llseek = dma_buf_llseek, |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 304 | .poll = dma_buf_poll, |
Daniel Vetter | c11e391 | 2016-02-11 20:04:51 -0200 | [diff] [blame] | 305 | .unlocked_ioctl = dma_buf_ioctl, |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | /* |
| 309 | * is_dma_buf_file - Check if struct file* is associated with dma_buf |
| 310 | */ |
| 311 | static inline int is_dma_buf_file(struct file *file) |
| 312 | { |
| 313 | return file->f_op == &dma_buf_fops; |
| 314 | } |
| 315 | |
| 316 | /** |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 317 | * DOC: dma buf device access |
| 318 | * |
| 319 | * For device DMA access to a shared DMA buffer the usual sequence of operations |
| 320 | * is fairly simple: |
| 321 | * |
| 322 | * 1. The exporter defines his exporter instance using |
| 323 | * DEFINE_DMA_BUF_EXPORT_INFO() and calls dma_buf_export() to wrap a private |
| 324 | * buffer object into a &dma_buf. It then exports that &dma_buf to userspace |
| 325 | * as a file descriptor by calling dma_buf_fd(). |
| 326 | * |
| 327 | * 2. Userspace passes this file-descriptors to all drivers it wants this buffer |
| 328 | * to share with: First the filedescriptor is converted to a &dma_buf using |
| 329 | * dma_buf_get(). The the buffer is attached to the device using |
| 330 | * dma_buf_attach(). |
| 331 | * |
| 332 | * Up to this stage the exporter is still free to migrate or reallocate the |
| 333 | * backing storage. |
| 334 | * |
| 335 | * 3. Once the buffer is attached to all devices userspace can inniate DMA |
| 336 | * access to the shared buffer. In the kernel this is done by calling |
| 337 | * dma_buf_map_attachment() and dma_buf_unmap_attachment(). |
| 338 | * |
| 339 | * 4. Once a driver is done with a shared buffer it needs to call |
| 340 | * dma_buf_detach() (after cleaning up any mappings) and then release the |
| 341 | * reference acquired with dma_buf_get by calling dma_buf_put(). |
| 342 | * |
| 343 | * For the detailed semantics exporters are expected to implement see |
| 344 | * &dma_buf_ops. |
| 345 | */ |
| 346 | |
| 347 | /** |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 348 | * dma_buf_export - Creates a new dma_buf, and associates an anon file |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 349 | * with this buffer, so it can be exported. |
| 350 | * Also connect the allocator specific data and ops to the buffer. |
Sumit Semwal | 78df969 | 2013-03-22 18:22:16 +0530 | [diff] [blame] | 351 | * Additionally, provide a name string for exporter; useful in debugging. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 352 | * |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 353 | * @exp_info: [in] holds all the export related information provided |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 354 | * by the exporter. see struct &dma_buf_export_info |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 355 | * for further details. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 356 | * |
| 357 | * Returns, on success, a newly created dma_buf object, which wraps the |
| 358 | * supplied private data and operations for dma_buf_ops. On either missing |
| 359 | * ops, or error in allocating struct dma_buf, will return negative error. |
| 360 | * |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 361 | * For most cases the easiest way to create @exp_info is through the |
| 362 | * %DEFINE_DMA_BUF_EXPORT_INFO macro. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 363 | */ |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 364 | struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 365 | { |
| 366 | struct dma_buf *dmabuf; |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 367 | struct reservation_object *resv = exp_info->resv; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 368 | struct file *file; |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 369 | size_t alloc_size = sizeof(struct dma_buf); |
Chris Wilson | a026df4 | 2016-07-18 12:16:22 +0100 | [diff] [blame] | 370 | int ret; |
Jagan Teki | 5136629 | 2015-05-21 01:09:31 +0530 | [diff] [blame] | 371 | |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 372 | if (!exp_info->resv) |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 373 | alloc_size += sizeof(struct reservation_object); |
| 374 | else |
| 375 | /* prevent &dma_buf[1] == dma_buf->resv */ |
| 376 | alloc_size += 1; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 377 | |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 378 | if (WARN_ON(!exp_info->priv |
| 379 | || !exp_info->ops |
| 380 | || !exp_info->ops->map_dma_buf |
| 381 | || !exp_info->ops->unmap_dma_buf |
| 382 | || !exp_info->ops->release |
| 383 | || !exp_info->ops->kmap_atomic |
| 384 | || !exp_info->ops->kmap |
| 385 | || !exp_info->ops->mmap)) { |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 386 | return ERR_PTR(-EINVAL); |
| 387 | } |
| 388 | |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 389 | if (!try_module_get(exp_info->owner)) |
| 390 | return ERR_PTR(-ENOENT); |
| 391 | |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 392 | dmabuf = kzalloc(alloc_size, GFP_KERNEL); |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 393 | if (!dmabuf) { |
Chris Wilson | a026df4 | 2016-07-18 12:16:22 +0100 | [diff] [blame] | 394 | ret = -ENOMEM; |
| 395 | goto err_module; |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 396 | } |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 397 | |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 398 | dmabuf->priv = exp_info->priv; |
| 399 | dmabuf->ops = exp_info->ops; |
| 400 | dmabuf->size = exp_info->size; |
| 401 | dmabuf->exp_name = exp_info->exp_name; |
Sumit Semwal | 9abdffe | 2015-05-05 14:56:15 +0530 | [diff] [blame] | 402 | dmabuf->owner = exp_info->owner; |
Maarten Lankhorst | 9b495a5 | 2014-07-01 12:57:43 +0200 | [diff] [blame] | 403 | init_waitqueue_head(&dmabuf->poll); |
| 404 | dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll; |
| 405 | dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0; |
| 406 | |
Maarten Lankhorst | 3aac450 | 2014-07-01 12:57:26 +0200 | [diff] [blame] | 407 | if (!resv) { |
| 408 | resv = (struct reservation_object *)&dmabuf[1]; |
| 409 | reservation_object_init(resv); |
| 410 | } |
| 411 | dmabuf->resv = resv; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 412 | |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 413 | file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, |
| 414 | exp_info->flags); |
Tuomas Tynkkynen | 9022e24 | 2013-08-27 16:30:38 +0300 | [diff] [blame] | 415 | if (IS_ERR(file)) { |
Chris Wilson | a026df4 | 2016-07-18 12:16:22 +0100 | [diff] [blame] | 416 | ret = PTR_ERR(file); |
| 417 | goto err_dmabuf; |
Tuomas Tynkkynen | 9022e24 | 2013-08-27 16:30:38 +0300 | [diff] [blame] | 418 | } |
Christopher James Halse Rogers | 19e8697 | 2013-09-10 11:36:45 +0530 | [diff] [blame] | 419 | |
| 420 | file->f_mode |= FMODE_LSEEK; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 421 | dmabuf->file = file; |
| 422 | |
| 423 | mutex_init(&dmabuf->lock); |
| 424 | INIT_LIST_HEAD(&dmabuf->attachments); |
| 425 | |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 426 | mutex_lock(&db_list.lock); |
| 427 | list_add(&dmabuf->list_node, &db_list.head); |
| 428 | mutex_unlock(&db_list.lock); |
| 429 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 430 | return dmabuf; |
Chris Wilson | a026df4 | 2016-07-18 12:16:22 +0100 | [diff] [blame] | 431 | |
| 432 | err_dmabuf: |
| 433 | kfree(dmabuf); |
| 434 | err_module: |
| 435 | module_put(exp_info->owner); |
| 436 | return ERR_PTR(ret); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 437 | } |
Sumit Semwal | d8fbe34 | 2015-01-23 12:53:43 +0530 | [diff] [blame] | 438 | EXPORT_SYMBOL_GPL(dma_buf_export); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 439 | |
| 440 | /** |
| 441 | * dma_buf_fd - returns a file descriptor for the given dma_buf |
| 442 | * @dmabuf: [in] pointer to dma_buf for which fd is required. |
Dave Airlie | 55c1c4c | 2012-03-16 10:34:02 +0000 | [diff] [blame] | 443 | * @flags: [in] flags to give to fd |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 444 | * |
| 445 | * On success, returns an associated 'fd'. Else, returns error. |
| 446 | */ |
Dave Airlie | 55c1c4c | 2012-03-16 10:34:02 +0000 | [diff] [blame] | 447 | int dma_buf_fd(struct dma_buf *dmabuf, int flags) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 448 | { |
Borislav Petkov | f5e097f | 2012-12-11 16:05:26 +0100 | [diff] [blame] | 449 | int fd; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 450 | |
| 451 | if (!dmabuf || !dmabuf->file) |
| 452 | return -EINVAL; |
| 453 | |
Borislav Petkov | f5e097f | 2012-12-11 16:05:26 +0100 | [diff] [blame] | 454 | fd = get_unused_fd_flags(flags); |
| 455 | if (fd < 0) |
| 456 | return fd; |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 457 | |
| 458 | fd_install(fd, dmabuf->file); |
| 459 | |
| 460 | return fd; |
| 461 | } |
| 462 | EXPORT_SYMBOL_GPL(dma_buf_fd); |
| 463 | |
| 464 | /** |
| 465 | * dma_buf_get - returns the dma_buf structure related to an fd |
| 466 | * @fd: [in] fd associated with the dma_buf to be returned |
| 467 | * |
| 468 | * On success, returns the dma_buf structure associated with an fd; uses |
| 469 | * file's refcounting done by fget to increase refcount. returns ERR_PTR |
| 470 | * otherwise. |
| 471 | */ |
| 472 | struct dma_buf *dma_buf_get(int fd) |
| 473 | { |
| 474 | struct file *file; |
| 475 | |
| 476 | file = fget(fd); |
| 477 | |
| 478 | if (!file) |
| 479 | return ERR_PTR(-EBADF); |
| 480 | |
| 481 | if (!is_dma_buf_file(file)) { |
| 482 | fput(file); |
| 483 | return ERR_PTR(-EINVAL); |
| 484 | } |
| 485 | |
| 486 | return file->private_data; |
| 487 | } |
| 488 | EXPORT_SYMBOL_GPL(dma_buf_get); |
| 489 | |
| 490 | /** |
| 491 | * dma_buf_put - decreases refcount of the buffer |
| 492 | * @dmabuf: [in] buffer to reduce refcount of |
| 493 | * |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 494 | * Uses file's refcounting done implicitly by fput(). |
| 495 | * |
| 496 | * If, as a result of this call, the refcount becomes 0, the 'release' file |
| 497 | * operation related to this fd is called. It calls the release operation of |
| 498 | * struct &dma_buf_ops in turn, and frees the memory allocated for dmabuf when |
| 499 | * exported. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 500 | */ |
| 501 | void dma_buf_put(struct dma_buf *dmabuf) |
| 502 | { |
| 503 | if (WARN_ON(!dmabuf || !dmabuf->file)) |
| 504 | return; |
| 505 | |
| 506 | fput(dmabuf->file); |
| 507 | } |
| 508 | EXPORT_SYMBOL_GPL(dma_buf_put); |
| 509 | |
| 510 | /** |
| 511 | * dma_buf_attach - Add the device to dma_buf's attachments list; optionally, |
| 512 | * calls attach() of dma_buf_ops to allow device-specific attach functionality |
| 513 | * @dmabuf: [in] buffer to attach device to. |
| 514 | * @dev: [in] device to be attached. |
| 515 | * |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 516 | * Returns struct dma_buf_attachment pointer for this attachment. Attachments |
| 517 | * must be cleaned up by calling dma_buf_detach(). |
| 518 | * |
| 519 | * Returns: |
| 520 | * |
| 521 | * A pointer to newly created &dma_buf_attachment on success, or a negative |
| 522 | * error code wrapped into a pointer on failure. |
| 523 | * |
| 524 | * Note that this can fail if the backing storage of @dmabuf is in a place not |
| 525 | * accessible to @dev, and cannot be moved to a more suitable place. This is |
| 526 | * indicated with the error code -EBUSY. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 527 | */ |
| 528 | struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, |
| 529 | struct device *dev) |
| 530 | { |
| 531 | struct dma_buf_attachment *attach; |
| 532 | int ret; |
| 533 | |
Laurent Pinchart | d1aa06a | 2012-01-26 12:27:23 +0100 | [diff] [blame] | 534 | if (WARN_ON(!dmabuf || !dev)) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 535 | return ERR_PTR(-EINVAL); |
| 536 | |
| 537 | attach = kzalloc(sizeof(struct dma_buf_attachment), GFP_KERNEL); |
| 538 | if (attach == NULL) |
Laurent Pinchart | a9fbc3b | 2012-01-26 12:27:24 +0100 | [diff] [blame] | 539 | return ERR_PTR(-ENOMEM); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 540 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 541 | attach->dev = dev; |
| 542 | attach->dmabuf = dmabuf; |
Laurent Pinchart | 2ed9201 | 2012-01-26 12:27:25 +0100 | [diff] [blame] | 543 | |
| 544 | mutex_lock(&dmabuf->lock); |
| 545 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 546 | if (dmabuf->ops->attach) { |
| 547 | ret = dmabuf->ops->attach(dmabuf, dev, attach); |
| 548 | if (ret) |
| 549 | goto err_attach; |
| 550 | } |
| 551 | list_add(&attach->node, &dmabuf->attachments); |
| 552 | |
| 553 | mutex_unlock(&dmabuf->lock); |
| 554 | return attach; |
| 555 | |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 556 | err_attach: |
| 557 | kfree(attach); |
| 558 | mutex_unlock(&dmabuf->lock); |
| 559 | return ERR_PTR(ret); |
| 560 | } |
| 561 | EXPORT_SYMBOL_GPL(dma_buf_attach); |
| 562 | |
| 563 | /** |
| 564 | * dma_buf_detach - Remove the given attachment from dmabuf's attachments list; |
| 565 | * optionally calls detach() of dma_buf_ops for device-specific detach |
| 566 | * @dmabuf: [in] buffer to detach from. |
| 567 | * @attach: [in] attachment to be detached; is free'd after this call. |
| 568 | * |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 569 | * Clean up a device attachment obtained by calling dma_buf_attach(). |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 570 | */ |
| 571 | void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) |
| 572 | { |
Laurent Pinchart | d1aa06a | 2012-01-26 12:27:23 +0100 | [diff] [blame] | 573 | if (WARN_ON(!dmabuf || !attach)) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 574 | return; |
| 575 | |
| 576 | mutex_lock(&dmabuf->lock); |
| 577 | list_del(&attach->node); |
| 578 | if (dmabuf->ops->detach) |
| 579 | dmabuf->ops->detach(dmabuf, attach); |
| 580 | |
| 581 | mutex_unlock(&dmabuf->lock); |
| 582 | kfree(attach); |
| 583 | } |
| 584 | EXPORT_SYMBOL_GPL(dma_buf_detach); |
| 585 | |
| 586 | /** |
| 587 | * dma_buf_map_attachment - Returns the scatterlist table of the attachment; |
| 588 | * mapped into _device_ address space. Is a wrapper for map_dma_buf() of the |
| 589 | * dma_buf_ops. |
| 590 | * @attach: [in] attachment whose scatterlist is to be returned |
| 591 | * @direction: [in] direction of DMA transfer |
| 592 | * |
Colin Cross | fee0c54 | 2013-12-20 16:43:50 -0800 | [diff] [blame] | 593 | * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 594 | * on error. May return -EINTR if it is interrupted by a signal. |
| 595 | * |
| 596 | * A mapping must be unmapped again using dma_buf_map_attachment(). Note that |
| 597 | * the underlying backing storage is pinned for as long as a mapping exists, |
| 598 | * therefore users/importers should not hold onto a mapping for undue amounts of |
| 599 | * time. |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 600 | */ |
| 601 | struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, |
| 602 | enum dma_data_direction direction) |
| 603 | { |
| 604 | struct sg_table *sg_table = ERR_PTR(-EINVAL); |
| 605 | |
| 606 | might_sleep(); |
| 607 | |
Laurent Pinchart | d1aa06a | 2012-01-26 12:27:23 +0100 | [diff] [blame] | 608 | if (WARN_ON(!attach || !attach->dmabuf)) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 609 | return ERR_PTR(-EINVAL); |
| 610 | |
Laurent Pinchart | d1aa06a | 2012-01-26 12:27:23 +0100 | [diff] [blame] | 611 | sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); |
Colin Cross | fee0c54 | 2013-12-20 16:43:50 -0800 | [diff] [blame] | 612 | if (!sg_table) |
| 613 | sg_table = ERR_PTR(-ENOMEM); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 614 | |
| 615 | return sg_table; |
| 616 | } |
| 617 | EXPORT_SYMBOL_GPL(dma_buf_map_attachment); |
| 618 | |
| 619 | /** |
| 620 | * dma_buf_unmap_attachment - unmaps and decreases usecount of the buffer;might |
| 621 | * deallocate the scatterlist associated. Is a wrapper for unmap_dma_buf() of |
| 622 | * dma_buf_ops. |
| 623 | * @attach: [in] attachment to unmap buffer from |
| 624 | * @sg_table: [in] scatterlist info of the buffer to unmap |
Sumit Semwal | 33ea2dc | 2012-01-27 15:09:27 +0530 | [diff] [blame] | 625 | * @direction: [in] direction of DMA transfer |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 626 | * |
Daniel Vetter | 2904a8c | 2016-12-09 19:53:07 +0100 | [diff] [blame^] | 627 | * This unmaps a DMA mapping for @attached obtained by dma_buf_map_attachment(). |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 628 | */ |
| 629 | void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, |
Sumit Semwal | 33ea2dc | 2012-01-27 15:09:27 +0530 | [diff] [blame] | 630 | struct sg_table *sg_table, |
| 631 | enum dma_data_direction direction) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 632 | { |
Rob Clark | b6fa0cd | 2012-09-28 09:29:43 +0200 | [diff] [blame] | 633 | might_sleep(); |
| 634 | |
Laurent Pinchart | d1aa06a | 2012-01-26 12:27:23 +0100 | [diff] [blame] | 635 | if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 636 | return; |
| 637 | |
Sumit Semwal | 33ea2dc | 2012-01-27 15:09:27 +0530 | [diff] [blame] | 638 | attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, |
| 639 | direction); |
Sumit Semwal | d15bd7e | 2011-12-26 14:53:15 +0530 | [diff] [blame] | 640 | } |
| 641 | EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment); |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 642 | |
Chris Wilson | ae4e46b | 2016-08-15 16:42:18 +0100 | [diff] [blame] | 643 | static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf, |
| 644 | enum dma_data_direction direction) |
| 645 | { |
| 646 | bool write = (direction == DMA_BIDIRECTIONAL || |
| 647 | direction == DMA_TO_DEVICE); |
| 648 | struct reservation_object *resv = dmabuf->resv; |
| 649 | long ret; |
| 650 | |
| 651 | /* Wait on any implicit rendering fences */ |
| 652 | ret = reservation_object_wait_timeout_rcu(resv, write, true, |
| 653 | MAX_SCHEDULE_TIMEOUT); |
| 654 | if (ret < 0) |
| 655 | return ret; |
| 656 | |
| 657 | return 0; |
| 658 | } |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 659 | |
| 660 | /** |
| 661 | * dma_buf_begin_cpu_access - Must be called before accessing a dma_buf from the |
| 662 | * cpu in the kernel context. Calls begin_cpu_access to allow exporter-specific |
| 663 | * preparations. Coherency is only guaranteed in the specified range for the |
| 664 | * specified access direction. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 665 | * @dmabuf: [in] buffer to prepare cpu access for. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 666 | * @direction: [in] length of range for cpu access. |
| 667 | * |
| 668 | * Can return negative error values, returns 0 on success. |
| 669 | */ |
Tiago Vignatti | 831e9da | 2015-12-22 19:36:45 -0200 | [diff] [blame] | 670 | int dma_buf_begin_cpu_access(struct dma_buf *dmabuf, |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 671 | enum dma_data_direction direction) |
| 672 | { |
| 673 | int ret = 0; |
| 674 | |
| 675 | if (WARN_ON(!dmabuf)) |
| 676 | return -EINVAL; |
| 677 | |
| 678 | if (dmabuf->ops->begin_cpu_access) |
Tiago Vignatti | 831e9da | 2015-12-22 19:36:45 -0200 | [diff] [blame] | 679 | ret = dmabuf->ops->begin_cpu_access(dmabuf, direction); |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 680 | |
Chris Wilson | ae4e46b | 2016-08-15 16:42:18 +0100 | [diff] [blame] | 681 | /* Ensure that all fences are waited upon - but we first allow |
| 682 | * the native handler the chance to do so more efficiently if it |
| 683 | * chooses. A double invocation here will be reasonably cheap no-op. |
| 684 | */ |
| 685 | if (ret == 0) |
| 686 | ret = __dma_buf_begin_cpu_access(dmabuf, direction); |
| 687 | |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | EXPORT_SYMBOL_GPL(dma_buf_begin_cpu_access); |
| 691 | |
| 692 | /** |
| 693 | * dma_buf_end_cpu_access - Must be called after accessing a dma_buf from the |
| 694 | * cpu in the kernel context. Calls end_cpu_access to allow exporter-specific |
| 695 | * actions. Coherency is only guaranteed in the specified range for the |
| 696 | * specified access direction. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 697 | * @dmabuf: [in] buffer to complete cpu access for. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 698 | * @direction: [in] length of range for cpu access. |
| 699 | * |
Daniel Vetter | 87e332d | 2016-03-21 08:24:22 +0100 | [diff] [blame] | 700 | * Can return negative error values, returns 0 on success. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 701 | */ |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 702 | int dma_buf_end_cpu_access(struct dma_buf *dmabuf, |
| 703 | enum dma_data_direction direction) |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 704 | { |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 705 | int ret = 0; |
| 706 | |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 707 | WARN_ON(!dmabuf); |
| 708 | |
| 709 | if (dmabuf->ops->end_cpu_access) |
Chris Wilson | 18b862d | 2016-03-18 20:02:39 +0000 | [diff] [blame] | 710 | ret = dmabuf->ops->end_cpu_access(dmabuf, direction); |
| 711 | |
| 712 | return ret; |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 713 | } |
| 714 | EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access); |
| 715 | |
| 716 | /** |
| 717 | * dma_buf_kmap_atomic - Map a page of the buffer object into kernel address |
| 718 | * space. The same restrictions as for kmap_atomic and friends apply. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 719 | * @dmabuf: [in] buffer to map page from. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 720 | * @page_num: [in] page in PAGE_SIZE units to map. |
| 721 | * |
| 722 | * This call must always succeed, any necessary preparations that might fail |
| 723 | * need to be done in begin_cpu_access. |
| 724 | */ |
| 725 | void *dma_buf_kmap_atomic(struct dma_buf *dmabuf, unsigned long page_num) |
| 726 | { |
| 727 | WARN_ON(!dmabuf); |
| 728 | |
| 729 | return dmabuf->ops->kmap_atomic(dmabuf, page_num); |
| 730 | } |
| 731 | EXPORT_SYMBOL_GPL(dma_buf_kmap_atomic); |
| 732 | |
| 733 | /** |
| 734 | * dma_buf_kunmap_atomic - Unmap a page obtained by dma_buf_kmap_atomic. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 735 | * @dmabuf: [in] buffer to unmap page from. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 736 | * @page_num: [in] page in PAGE_SIZE units to unmap. |
| 737 | * @vaddr: [in] kernel space pointer obtained from dma_buf_kmap_atomic. |
| 738 | * |
| 739 | * This call must always succeed. |
| 740 | */ |
| 741 | void dma_buf_kunmap_atomic(struct dma_buf *dmabuf, unsigned long page_num, |
| 742 | void *vaddr) |
| 743 | { |
| 744 | WARN_ON(!dmabuf); |
| 745 | |
| 746 | if (dmabuf->ops->kunmap_atomic) |
| 747 | dmabuf->ops->kunmap_atomic(dmabuf, page_num, vaddr); |
| 748 | } |
| 749 | EXPORT_SYMBOL_GPL(dma_buf_kunmap_atomic); |
| 750 | |
| 751 | /** |
| 752 | * dma_buf_kmap - Map a page of the buffer object into kernel address space. The |
| 753 | * same restrictions as for kmap and friends apply. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 754 | * @dmabuf: [in] buffer to map page from. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 755 | * @page_num: [in] page in PAGE_SIZE units to map. |
| 756 | * |
| 757 | * This call must always succeed, any necessary preparations that might fail |
| 758 | * need to be done in begin_cpu_access. |
| 759 | */ |
| 760 | void *dma_buf_kmap(struct dma_buf *dmabuf, unsigned long page_num) |
| 761 | { |
| 762 | WARN_ON(!dmabuf); |
| 763 | |
| 764 | return dmabuf->ops->kmap(dmabuf, page_num); |
| 765 | } |
| 766 | EXPORT_SYMBOL_GPL(dma_buf_kmap); |
| 767 | |
| 768 | /** |
| 769 | * dma_buf_kunmap - Unmap a page obtained by dma_buf_kmap. |
Randy Dunlap | efb4df82 | 2012-04-17 17:03:30 -0700 | [diff] [blame] | 770 | * @dmabuf: [in] buffer to unmap page from. |
Daniel Vetter | fc13020 | 2012-03-20 00:02:37 +0100 | [diff] [blame] | 771 | * @page_num: [in] page in PAGE_SIZE units to unmap. |
| 772 | * @vaddr: [in] kernel space pointer obtained from dma_buf_kmap. |
| 773 | * |
| 774 | * This call must always succeed. |
| 775 | */ |
| 776 | void dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long page_num, |
| 777 | void *vaddr) |
| 778 | { |
| 779 | WARN_ON(!dmabuf); |
| 780 | |
| 781 | if (dmabuf->ops->kunmap) |
| 782 | dmabuf->ops->kunmap(dmabuf, page_num, vaddr); |
| 783 | } |
| 784 | EXPORT_SYMBOL_GPL(dma_buf_kunmap); |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 785 | |
| 786 | |
| 787 | /** |
| 788 | * dma_buf_mmap - Setup up a userspace mmap with the given vma |
Sumit Semwal | 12c4727 | 2012-05-23 15:27:40 +0530 | [diff] [blame] | 789 | * @dmabuf: [in] buffer that should back the vma |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 790 | * @vma: [in] vma for the mmap |
| 791 | * @pgoff: [in] offset in pages where this mmap should start within the |
Jagan Teki | 5136629 | 2015-05-21 01:09:31 +0530 | [diff] [blame] | 792 | * dma-buf buffer. |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 793 | * |
| 794 | * This function adjusts the passed in vma so that it points at the file of the |
Javier Martinez Canillas | ecf1dba | 2014-04-10 01:30:05 +0200 | [diff] [blame] | 795 | * dma_buf operation. It also adjusts the starting pgoff and does bounds |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 796 | * checking on the size of the vma. Then it calls the exporters mmap function to |
| 797 | * set up the mapping. |
| 798 | * |
| 799 | * Can return negative error values, returns 0 on success. |
| 800 | */ |
| 801 | int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, |
| 802 | unsigned long pgoff) |
| 803 | { |
John Sheu | 495c10c | 2013-02-11 17:50:24 -0800 | [diff] [blame] | 804 | struct file *oldfile; |
| 805 | int ret; |
| 806 | |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 807 | if (WARN_ON(!dmabuf || !vma)) |
| 808 | return -EINVAL; |
| 809 | |
| 810 | /* check for offset overflow */ |
Muhammad Falak R Wani | b02da6f | 2016-05-23 17:08:42 +0530 | [diff] [blame] | 811 | if (pgoff + vma_pages(vma) < pgoff) |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 812 | return -EOVERFLOW; |
| 813 | |
| 814 | /* check for overflowing the buffer's size */ |
Muhammad Falak R Wani | b02da6f | 2016-05-23 17:08:42 +0530 | [diff] [blame] | 815 | if (pgoff + vma_pages(vma) > |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 816 | dmabuf->size >> PAGE_SHIFT) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | /* readjust the vma */ |
John Sheu | 495c10c | 2013-02-11 17:50:24 -0800 | [diff] [blame] | 820 | get_file(dmabuf->file); |
| 821 | oldfile = vma->vm_file; |
| 822 | vma->vm_file = dmabuf->file; |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 823 | vma->vm_pgoff = pgoff; |
| 824 | |
John Sheu | 495c10c | 2013-02-11 17:50:24 -0800 | [diff] [blame] | 825 | ret = dmabuf->ops->mmap(dmabuf, vma); |
| 826 | if (ret) { |
| 827 | /* restore old parameters on failure */ |
| 828 | vma->vm_file = oldfile; |
| 829 | fput(dmabuf->file); |
| 830 | } else { |
| 831 | if (oldfile) |
| 832 | fput(oldfile); |
| 833 | } |
| 834 | return ret; |
| 835 | |
Daniel Vetter | 4c78513 | 2012-04-24 14:38:52 +0530 | [diff] [blame] | 836 | } |
| 837 | EXPORT_SYMBOL_GPL(dma_buf_mmap); |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 838 | |
| 839 | /** |
Sumit Semwal | 12c4727 | 2012-05-23 15:27:40 +0530 | [diff] [blame] | 840 | * dma_buf_vmap - Create virtual mapping for the buffer object into kernel |
| 841 | * address space. Same restrictions as for vmap and friends apply. |
| 842 | * @dmabuf: [in] buffer to vmap |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 843 | * |
| 844 | * This call may fail due to lack of virtual mapping address space. |
| 845 | * These calls are optional in drivers. The intended use for them |
| 846 | * is for mapping objects linear in kernel space for high use objects. |
| 847 | * Please attempt to use kmap/kunmap before thinking about these interfaces. |
Colin Cross | fee0c54 | 2013-12-20 16:43:50 -0800 | [diff] [blame] | 848 | * |
| 849 | * Returns NULL on error. |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 850 | */ |
| 851 | void *dma_buf_vmap(struct dma_buf *dmabuf) |
| 852 | { |
Daniel Vetter | f00b4da | 2012-12-20 14:14:23 +0100 | [diff] [blame] | 853 | void *ptr; |
| 854 | |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 855 | if (WARN_ON(!dmabuf)) |
| 856 | return NULL; |
| 857 | |
Daniel Vetter | f00b4da | 2012-12-20 14:14:23 +0100 | [diff] [blame] | 858 | if (!dmabuf->ops->vmap) |
| 859 | return NULL; |
| 860 | |
| 861 | mutex_lock(&dmabuf->lock); |
| 862 | if (dmabuf->vmapping_counter) { |
| 863 | dmabuf->vmapping_counter++; |
| 864 | BUG_ON(!dmabuf->vmap_ptr); |
| 865 | ptr = dmabuf->vmap_ptr; |
| 866 | goto out_unlock; |
| 867 | } |
| 868 | |
| 869 | BUG_ON(dmabuf->vmap_ptr); |
| 870 | |
| 871 | ptr = dmabuf->ops->vmap(dmabuf); |
Colin Cross | fee0c54 | 2013-12-20 16:43:50 -0800 | [diff] [blame] | 872 | if (WARN_ON_ONCE(IS_ERR(ptr))) |
| 873 | ptr = NULL; |
| 874 | if (!ptr) |
Daniel Vetter | f00b4da | 2012-12-20 14:14:23 +0100 | [diff] [blame] | 875 | goto out_unlock; |
| 876 | |
| 877 | dmabuf->vmap_ptr = ptr; |
| 878 | dmabuf->vmapping_counter = 1; |
| 879 | |
| 880 | out_unlock: |
| 881 | mutex_unlock(&dmabuf->lock); |
| 882 | return ptr; |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 883 | } |
| 884 | EXPORT_SYMBOL_GPL(dma_buf_vmap); |
| 885 | |
| 886 | /** |
| 887 | * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap. |
Sumit Semwal | 12c4727 | 2012-05-23 15:27:40 +0530 | [diff] [blame] | 888 | * @dmabuf: [in] buffer to vunmap |
Randy Dunlap | 6e7b4a5 | 2012-06-09 15:02:59 -0700 | [diff] [blame] | 889 | * @vaddr: [in] vmap to vunmap |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 890 | */ |
| 891 | void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr) |
| 892 | { |
| 893 | if (WARN_ON(!dmabuf)) |
| 894 | return; |
| 895 | |
Daniel Vetter | f00b4da | 2012-12-20 14:14:23 +0100 | [diff] [blame] | 896 | BUG_ON(!dmabuf->vmap_ptr); |
| 897 | BUG_ON(dmabuf->vmapping_counter == 0); |
| 898 | BUG_ON(dmabuf->vmap_ptr != vaddr); |
| 899 | |
| 900 | mutex_lock(&dmabuf->lock); |
| 901 | if (--dmabuf->vmapping_counter == 0) { |
| 902 | if (dmabuf->ops->vunmap) |
| 903 | dmabuf->ops->vunmap(dmabuf, vaddr); |
| 904 | dmabuf->vmap_ptr = NULL; |
| 905 | } |
| 906 | mutex_unlock(&dmabuf->lock); |
Dave Airlie | 98f86c9 | 2012-05-20 12:33:56 +0530 | [diff] [blame] | 907 | } |
| 908 | EXPORT_SYMBOL_GPL(dma_buf_vunmap); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 909 | |
| 910 | #ifdef CONFIG_DEBUG_FS |
Mathias Krause | eb0b947 | 2016-06-19 14:31:29 +0200 | [diff] [blame] | 911 | static int dma_buf_debug_show(struct seq_file *s, void *unused) |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 912 | { |
| 913 | int ret; |
| 914 | struct dma_buf *buf_obj; |
| 915 | struct dma_buf_attachment *attach_obj; |
| 916 | int count = 0, attach_count; |
| 917 | size_t size = 0; |
| 918 | |
| 919 | ret = mutex_lock_interruptible(&db_list.lock); |
| 920 | |
| 921 | if (ret) |
| 922 | return ret; |
| 923 | |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 924 | seq_puts(s, "\nDma-buf Objects:\n"); |
| 925 | seq_puts(s, "size\tflags\tmode\tcount\texp_name\n"); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 926 | |
| 927 | list_for_each_entry(buf_obj, &db_list.head, list_node) { |
| 928 | ret = mutex_lock_interruptible(&buf_obj->lock); |
| 929 | |
| 930 | if (ret) { |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 931 | seq_puts(s, |
| 932 | "\tERROR locking buffer object: skipping\n"); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 933 | continue; |
| 934 | } |
| 935 | |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 936 | seq_printf(s, "%08zu\t%08x\t%08x\t%08ld\t%s\n", |
| 937 | buf_obj->size, |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 938 | buf_obj->file->f_flags, buf_obj->file->f_mode, |
Al Viro | a1f6dba | 2014-08-20 11:05:50 -0400 | [diff] [blame] | 939 | file_count(buf_obj->file), |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 940 | buf_obj->exp_name); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 941 | |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 942 | seq_puts(s, "\tAttached Devices:\n"); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 943 | attach_count = 0; |
| 944 | |
| 945 | list_for_each_entry(attach_obj, &buf_obj->attachments, node) { |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 946 | seq_puts(s, "\t"); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 947 | |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 948 | seq_printf(s, "%s\n", dev_name(attach_obj->dev)); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 949 | attach_count++; |
| 950 | } |
| 951 | |
Sumit Semwal | c0b00a5 | 2014-02-03 15:09:12 +0530 | [diff] [blame] | 952 | seq_printf(s, "Total %d devices attached\n\n", |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 953 | attach_count); |
| 954 | |
| 955 | count++; |
| 956 | size += buf_obj->size; |
| 957 | mutex_unlock(&buf_obj->lock); |
| 958 | } |
| 959 | |
| 960 | seq_printf(s, "\nTotal %d objects, %zu bytes\n", count, size); |
| 961 | |
| 962 | mutex_unlock(&db_list.lock); |
| 963 | return 0; |
| 964 | } |
| 965 | |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 966 | static int dma_buf_debug_open(struct inode *inode, struct file *file) |
| 967 | { |
Mathias Krause | eb0b947 | 2016-06-19 14:31:29 +0200 | [diff] [blame] | 968 | return single_open(file, dma_buf_debug_show, NULL); |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | static const struct file_operations dma_buf_debug_fops = { |
| 972 | .open = dma_buf_debug_open, |
| 973 | .read = seq_read, |
| 974 | .llseek = seq_lseek, |
| 975 | .release = single_release, |
| 976 | }; |
| 977 | |
| 978 | static struct dentry *dma_buf_debugfs_dir; |
| 979 | |
| 980 | static int dma_buf_init_debugfs(void) |
| 981 | { |
Mathias Krause | bd3e220 | 2016-06-19 14:31:31 +0200 | [diff] [blame] | 982 | struct dentry *d; |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 983 | int err = 0; |
Jagan Teki | 5136629 | 2015-05-21 01:09:31 +0530 | [diff] [blame] | 984 | |
Mathias Krause | bd3e220 | 2016-06-19 14:31:31 +0200 | [diff] [blame] | 985 | d = debugfs_create_dir("dma_buf", NULL); |
| 986 | if (IS_ERR(d)) |
| 987 | return PTR_ERR(d); |
Jagan Teki | 5136629 | 2015-05-21 01:09:31 +0530 | [diff] [blame] | 988 | |
Mathias Krause | bd3e220 | 2016-06-19 14:31:31 +0200 | [diff] [blame] | 989 | dma_buf_debugfs_dir = d; |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 990 | |
Mathias Krause | bd3e220 | 2016-06-19 14:31:31 +0200 | [diff] [blame] | 991 | d = debugfs_create_file("bufinfo", S_IRUGO, dma_buf_debugfs_dir, |
| 992 | NULL, &dma_buf_debug_fops); |
| 993 | if (IS_ERR(d)) { |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 994 | pr_debug("dma_buf: debugfs: failed to create node bufinfo\n"); |
Mathias Krause | b747999 | 2016-06-19 14:31:30 +0200 | [diff] [blame] | 995 | debugfs_remove_recursive(dma_buf_debugfs_dir); |
| 996 | dma_buf_debugfs_dir = NULL; |
Mathias Krause | bd3e220 | 2016-06-19 14:31:31 +0200 | [diff] [blame] | 997 | err = PTR_ERR(d); |
Mathias Krause | b747999 | 2016-06-19 14:31:30 +0200 | [diff] [blame] | 998 | } |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 999 | |
| 1000 | return err; |
| 1001 | } |
| 1002 | |
| 1003 | static void dma_buf_uninit_debugfs(void) |
| 1004 | { |
| 1005 | if (dma_buf_debugfs_dir) |
| 1006 | debugfs_remove_recursive(dma_buf_debugfs_dir); |
| 1007 | } |
Sumit Semwal | b89e356 | 2013-04-04 11:44:37 +0530 | [diff] [blame] | 1008 | #else |
| 1009 | static inline int dma_buf_init_debugfs(void) |
| 1010 | { |
| 1011 | return 0; |
| 1012 | } |
| 1013 | static inline void dma_buf_uninit_debugfs(void) |
| 1014 | { |
| 1015 | } |
| 1016 | #endif |
| 1017 | |
| 1018 | static int __init dma_buf_init(void) |
| 1019 | { |
| 1020 | mutex_init(&db_list.lock); |
| 1021 | INIT_LIST_HEAD(&db_list.head); |
| 1022 | dma_buf_init_debugfs(); |
| 1023 | return 0; |
| 1024 | } |
| 1025 | subsys_initcall(dma_buf_init); |
| 1026 | |
| 1027 | static void __exit dma_buf_deinit(void) |
| 1028 | { |
| 1029 | dma_buf_uninit_debugfs(); |
| 1030 | } |
| 1031 | __exitcall(dma_buf_deinit); |