| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Header file for dma buffer sharing framework. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 8 | 9 | * Arnd Bergmann <arnd@arndb.de>, Rob Clark <rob@ti.com> and |
|---|
| 9 | 10 | * Daniel Vetter <daniel@ffwll.ch> for their support in creation and |
|---|
| 10 | 11 | * 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 | 12 | */ |
|---|
| 24 | 13 | #ifndef __DMA_BUF_H__ |
|---|
| 25 | 14 | #define __DMA_BUF_H__ |
|---|
| .. | .. |
|---|
| 32 | 21 | #include <linux/fs.h> |
|---|
| 33 | 22 | #include <linux/dma-fence.h> |
|---|
| 34 | 23 | #include <linux/wait.h> |
|---|
| 24 | +#include <linux/android_kabi.h> |
|---|
| 35 | 25 | |
|---|
| 36 | 26 | struct device; |
|---|
| 37 | 27 | struct dma_buf; |
|---|
| .. | .. |
|---|
| 39 | 29 | |
|---|
| 40 | 30 | /** |
|---|
| 41 | 31 | * struct dma_buf_ops - operations possible on struct dma_buf |
|---|
| 42 | | - * @map_atomic: [optional] maps a page from the buffer into kernel address |
|---|
| 43 | | - * space, users may not block until the subsequent unmap call. |
|---|
| 44 | | - * This callback must not sleep. |
|---|
| 45 | | - * @unmap_atomic: [optional] unmaps a atomically mapped page from the buffer. |
|---|
| 46 | | - * This Callback must not sleep. |
|---|
| 47 | | - * @map: [optional] maps a page from the buffer into kernel address space. |
|---|
| 48 | | - * @unmap: [optional] unmaps a page from the buffer. |
|---|
| 49 | 32 | * @vmap: [optional] creates a virtual mapping for the buffer into kernel |
|---|
| 50 | 33 | * address space. Same restrictions as for vmap and friends apply. |
|---|
| 51 | 34 | * @vunmap: [optional] unmaps a vmap from the buffer |
|---|
| 52 | 35 | */ |
|---|
| 53 | 36 | struct dma_buf_ops { |
|---|
| 37 | + /** |
|---|
| 38 | + * @cache_sgt_mapping: |
|---|
| 39 | + * |
|---|
| 40 | + * If true the framework will cache the first mapping made for each |
|---|
| 41 | + * attachment. This avoids creating mappings for attachments multiple |
|---|
| 42 | + * times. |
|---|
| 43 | + */ |
|---|
| 44 | + bool cache_sgt_mapping; |
|---|
| 45 | + |
|---|
| 54 | 46 | /** |
|---|
| 55 | 47 | * @attach: |
|---|
| 56 | 48 | * |
|---|
| .. | .. |
|---|
| 91 | 83 | void (*detach)(struct dma_buf *, struct dma_buf_attachment *); |
|---|
| 92 | 84 | |
|---|
| 93 | 85 | /** |
|---|
| 86 | + * @pin: |
|---|
| 87 | + * |
|---|
| 88 | + * This is called by dma_buf_pin and lets the exporter know that the |
|---|
| 89 | + * DMA-buf can't be moved any more. |
|---|
| 90 | + * |
|---|
| 91 | + * This is called with the dmabuf->resv object locked and is mutual |
|---|
| 92 | + * exclusive with @cache_sgt_mapping. |
|---|
| 93 | + * |
|---|
| 94 | + * This callback is optional and should only be used in limited use |
|---|
| 95 | + * cases like scanout and not for temporary pin operations. |
|---|
| 96 | + * |
|---|
| 97 | + * Returns: |
|---|
| 98 | + * |
|---|
| 99 | + * 0 on success, negative error code on failure. |
|---|
| 100 | + */ |
|---|
| 101 | + int (*pin)(struct dma_buf_attachment *attach); |
|---|
| 102 | + |
|---|
| 103 | + /** |
|---|
| 104 | + * @unpin: |
|---|
| 105 | + * |
|---|
| 106 | + * This is called by dma_buf_unpin and lets the exporter know that the |
|---|
| 107 | + * DMA-buf can be moved again. |
|---|
| 108 | + * |
|---|
| 109 | + * This is called with the dmabuf->resv object locked and is mutual |
|---|
| 110 | + * exclusive with @cache_sgt_mapping. |
|---|
| 111 | + * |
|---|
| 112 | + * This callback is optional. |
|---|
| 113 | + */ |
|---|
| 114 | + void (*unpin)(struct dma_buf_attachment *attach); |
|---|
| 115 | + |
|---|
| 116 | + /** |
|---|
| 94 | 117 | * @map_dma_buf: |
|---|
| 95 | 118 | * |
|---|
| 96 | 119 | * This is called by dma_buf_map_attachment() and is used to map a |
|---|
| 97 | 120 | * shared &dma_buf into device address space, and it is mandatory. It |
|---|
| 98 | | - * can only be called if @attach has been called successfully. This |
|---|
| 99 | | - * essentially pins the DMA buffer into place, and it cannot be moved |
|---|
| 100 | | - * any more |
|---|
| 121 | + * can only be called if @attach has been called successfully. |
|---|
| 101 | 122 | * |
|---|
| 102 | 123 | * This call may sleep, e.g. when the backing storage first needs to be |
|---|
| 103 | 124 | * allocated, or moved to a location suitable for all currently attached |
|---|
| .. | .. |
|---|
| 118 | 139 | * any other kind of sharing that the exporter might wish to make |
|---|
| 119 | 140 | * available to buffer-users. |
|---|
| 120 | 141 | * |
|---|
| 142 | + * This is always called with the dmabuf->resv object locked when |
|---|
| 143 | + * the dynamic_mapping flag is true. |
|---|
| 144 | + * |
|---|
| 121 | 145 | * Returns: |
|---|
| 122 | 146 | * |
|---|
| 123 | 147 | * A &sg_table scatter list of or the backing storage of the DMA buffer, |
|---|
| .. | .. |
|---|
| 135 | 159 | * |
|---|
| 136 | 160 | * This is called by dma_buf_unmap_attachment() and should unmap and |
|---|
| 137 | 161 | * release the &sg_table allocated in @map_dma_buf, and it is mandatory. |
|---|
| 138 | | - * It should also unpin the backing storage if this is the last mapping |
|---|
| 139 | | - * of the DMA buffer, it the exporter supports backing storage |
|---|
| 140 | | - * migration. |
|---|
| 162 | + * For static dma_buf handling this might also unpins the backing |
|---|
| 163 | + * storage if this is the last mapping of the DMA buffer. |
|---|
| 141 | 164 | */ |
|---|
| 142 | 165 | void (*unmap_dma_buf)(struct dma_buf_attachment *, |
|---|
| 143 | 166 | struct sg_table *, |
|---|
| .. | .. |
|---|
| 146 | 169 | /* TODO: Add try_map_dma_buf version, to return immed with -EBUSY |
|---|
| 147 | 170 | * if the call would block. |
|---|
| 148 | 171 | */ |
|---|
| 149 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 150 | | - int (*set_release_callback)(void (*release_callback)(void *data), |
|---|
| 151 | | - void *data); |
|---|
| 152 | | - void *(*get_release_callback_data)(void *callback); |
|---|
| 153 | | - /* after final dma_buf_put() */ |
|---|
| 154 | | -#endif |
|---|
| 172 | + |
|---|
| 155 | 173 | /** |
|---|
| 156 | 174 | * @release: |
|---|
| 157 | 175 | * |
|---|
| .. | .. |
|---|
| 191 | 209 | * needs to be restarted. |
|---|
| 192 | 210 | */ |
|---|
| 193 | 211 | int (*begin_cpu_access)(struct dma_buf *, enum dma_data_direction); |
|---|
| 194 | | - |
|---|
| 195 | | - /** |
|---|
| 196 | | - * @begin_cpu_access_umapped: |
|---|
| 197 | | - * |
|---|
| 198 | | - * This is called as a result of the DMA_BUF_IOCTL_SYNC IOCTL being |
|---|
| 199 | | - * called with the DMA_BUF_SYNC_START and DMA_BUF_SYNC_USER_MAPPED flags |
|---|
| 200 | | - * set. It allows the exporter to ensure that the mmap(ed) portions of |
|---|
| 201 | | - * the buffer are available for cpu access - the exporter might need to |
|---|
| 202 | | - * allocate or swap-in and pin the backing storage. |
|---|
| 203 | | - * The exporter also needs to ensure that cpu access is |
|---|
| 204 | | - * coherent for the access direction. The direction can be used by the |
|---|
| 205 | | - * exporter to optimize the cache flushing, i.e. access with a different |
|---|
| 206 | | - * direction (read instead of write) might return stale or even bogus |
|---|
| 207 | | - * data (e.g. when the exporter needs to copy the data to temporary |
|---|
| 208 | | - * storage). |
|---|
| 209 | | - * |
|---|
| 210 | | - * This callback is optional. |
|---|
| 211 | | - * |
|---|
| 212 | | - * Returns: |
|---|
| 213 | | - * |
|---|
| 214 | | - * 0 on success or a negative error code on failure. This can for |
|---|
| 215 | | - * example fail when the backing storage can't be allocated. Can also |
|---|
| 216 | | - * return -ERESTARTSYS or -EINTR when the call has been interrupted and |
|---|
| 217 | | - * needs to be restarted. |
|---|
| 218 | | - */ |
|---|
| 219 | | - int (*begin_cpu_access_umapped)(struct dma_buf *dmabuf, |
|---|
| 220 | | - enum dma_data_direction); |
|---|
| 221 | 212 | |
|---|
| 222 | 213 | /** |
|---|
| 223 | 214 | * @begin_cpu_access_partial: |
|---|
| .. | .. |
|---|
| 274 | 265 | int (*end_cpu_access)(struct dma_buf *, enum dma_data_direction); |
|---|
| 275 | 266 | |
|---|
| 276 | 267 | /** |
|---|
| 277 | | - * @end_cpu_access_umapped: |
|---|
| 278 | | - * |
|---|
| 279 | | - * This is called as result a of the DMA_BUF_IOCTL_SYNC IOCTL being |
|---|
| 280 | | - * called with the DMA_BUF_SYNC_END and DMA_BUF_SYNC_USER_MAPPED flags |
|---|
| 281 | | - * set. The exporter can use to limit cache flushing to only those parts |
|---|
| 282 | | - * of the buffer which are mmap(ed) and to unpin any resources pinned in |
|---|
| 283 | | - * @begin_cpu_access_umapped. |
|---|
| 284 | | - * The result of any dma_buf kmap calls after end_cpu_access_umapped is |
|---|
| 285 | | - * undefined. |
|---|
| 286 | | - * |
|---|
| 287 | | - * This callback is optional. |
|---|
| 288 | | - * |
|---|
| 289 | | - * Returns: |
|---|
| 290 | | - * |
|---|
| 291 | | - * 0 on success or a negative error code on failure. Can return |
|---|
| 292 | | - * -ERESTARTSYS or -EINTR when the call has been interrupted and needs |
|---|
| 293 | | - * to be restarted. |
|---|
| 294 | | - */ |
|---|
| 295 | | - int (*end_cpu_access_umapped)(struct dma_buf *dmabuf, |
|---|
| 296 | | - enum dma_data_direction); |
|---|
| 297 | | - |
|---|
| 298 | | - /** |
|---|
| 299 | 268 | * @end_cpu_access_partial: |
|---|
| 300 | 269 | * |
|---|
| 301 | 270 | * This is called from dma_buf_end_cpu_access_partial() when the |
|---|
| .. | .. |
|---|
| 316 | 285 | int (*end_cpu_access_partial)(struct dma_buf *dmabuf, |
|---|
| 317 | 286 | enum dma_data_direction, |
|---|
| 318 | 287 | unsigned int offset, unsigned int len); |
|---|
| 319 | | - |
|---|
| 320 | | - void *(*map)(struct dma_buf *, unsigned long); |
|---|
| 321 | | - void (*unmap)(struct dma_buf *, unsigned long, void *); |
|---|
| 322 | 288 | |
|---|
| 323 | 289 | /** |
|---|
| 324 | 290 | * @mmap: |
|---|
| .. | .. |
|---|
| 388 | 354 | * will be populated with the buffer's flags. |
|---|
| 389 | 355 | */ |
|---|
| 390 | 356 | int (*get_flags)(struct dma_buf *dmabuf, unsigned long *flags); |
|---|
| 357 | + |
|---|
| 358 | + ANDROID_KABI_RESERVE(1); |
|---|
| 359 | + ANDROID_KABI_RESERVE(2); |
|---|
| 391 | 360 | }; |
|---|
| 392 | 361 | |
|---|
| 362 | +#ifdef CONFIG_DMABUF_CACHE |
|---|
| 393 | 363 | /** |
|---|
| 394 | 364 | * dma_buf_destructor - dma-buf destructor function |
|---|
| 395 | 365 | * @dmabuf: [in] pointer to dma-buf |
|---|
| .. | .. |
|---|
| 401 | 371 | * won't be called. |
|---|
| 402 | 372 | */ |
|---|
| 403 | 373 | typedef int (*dma_buf_destructor)(struct dma_buf *dmabuf, void *dtor_data); |
|---|
| 374 | +#endif |
|---|
| 404 | 375 | |
|---|
| 405 | 376 | /** |
|---|
| 406 | 377 | * struct dma_buf - shared buffer object |
|---|
| 407 | 378 | * @size: size of the buffer |
|---|
| 408 | 379 | * @file: file pointer used for sharing buffers across, and for refcounting. |
|---|
| 409 | | - * @attachments: list of dma_buf_attachment that denotes all devices attached. |
|---|
| 380 | + * @attachments: list of dma_buf_attachment that denotes all devices attached, |
|---|
| 381 | + * protected by dma_resv lock. |
|---|
| 410 | 382 | * @ops: dma_buf_ops associated with this buffer object. |
|---|
| 411 | 383 | * @lock: used internally to serialize list manipulation, attach/detach and |
|---|
| 412 | | - * vmap/unmap, and accesses to name |
|---|
| 384 | + * vmap/unmap |
|---|
| 413 | 385 | * @vmapping_counter: used internally to refcnt the vmaps |
|---|
| 414 | 386 | * @vmap_ptr: the current vmap ptr if vmapping_counter > 0 |
|---|
| 415 | 387 | * @exp_name: name of the exporter; useful for debugging. |
|---|
| 416 | | - * @name: userspace-provided name; useful for accounting and debugging. |
|---|
| 417 | | - * @name_lock: lock to protect name. |
|---|
| 418 | | - * @ktime: time (in jiffies) at which the buffer was born |
|---|
| 388 | + * @name: userspace-provided name; useful for accounting and debugging, |
|---|
| 389 | + * protected by @resv. |
|---|
| 390 | + * @name_lock: spinlock to protect name access |
|---|
| 419 | 391 | * @owner: pointer to exporter module; used for refcounting when exporter is a |
|---|
| 420 | 392 | * kernel module. |
|---|
| 421 | 393 | * @list_node: node for dma_buf accounting and debugging. |
|---|
| .. | .. |
|---|
| 424 | 396 | * @poll: for userspace poll support |
|---|
| 425 | 397 | * @cb_excl: for userspace poll support |
|---|
| 426 | 398 | * @cb_shared: for userspace poll support |
|---|
| 399 | + * @sysfs_entry: for exposing information about this buffer in sysfs. |
|---|
| 427 | 400 | * |
|---|
| 428 | 401 | * This represents a shared buffer, created by calling dma_buf_export(). The |
|---|
| 429 | 402 | * userspace representation is a normal file descriptor, which can be created by |
|---|
| .. | .. |
|---|
| 438 | 411 | size_t size; |
|---|
| 439 | 412 | struct file *file; |
|---|
| 440 | 413 | struct list_head attachments; |
|---|
| 441 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 442 | | - struct list_head release_callbacks; |
|---|
| 443 | | - struct mutex release_lock; |
|---|
| 444 | | -#endif |
|---|
| 445 | 414 | const struct dma_buf_ops *ops; |
|---|
| 446 | 415 | struct mutex lock; |
|---|
| 447 | 416 | unsigned vmapping_counter; |
|---|
| .. | .. |
|---|
| 449 | 418 | const char *exp_name; |
|---|
| 450 | 419 | const char *name; |
|---|
| 451 | 420 | spinlock_t name_lock; |
|---|
| 452 | | -#if defined(CONFIG_DEBUG_FS) |
|---|
| 453 | | - ktime_t ktime; |
|---|
| 454 | | -#endif |
|---|
| 455 | 421 | struct module *owner; |
|---|
| 456 | 422 | struct list_head list_node; |
|---|
| 457 | 423 | void *priv; |
|---|
| 458 | | - struct reservation_object *resv; |
|---|
| 424 | + struct dma_resv *resv; |
|---|
| 459 | 425 | |
|---|
| 460 | 426 | /* poll support */ |
|---|
| 461 | 427 | wait_queue_head_t poll; |
|---|
| .. | .. |
|---|
| 466 | 432 | |
|---|
| 467 | 433 | __poll_t active; |
|---|
| 468 | 434 | } cb_excl, cb_shared; |
|---|
| 435 | +#ifdef CONFIG_DMABUF_SYSFS_STATS |
|---|
| 436 | + /* for sysfs stats */ |
|---|
| 437 | + struct dma_buf_sysfs_entry { |
|---|
| 438 | + struct kobject kobj; |
|---|
| 439 | + struct dma_buf *dmabuf; |
|---|
| 440 | + } *sysfs_entry; |
|---|
| 441 | +#endif |
|---|
| 442 | +#ifdef CONFIG_DMABUF_CACHE |
|---|
| 469 | 443 | dma_buf_destructor dtor; |
|---|
| 470 | 444 | void *dtor_data; |
|---|
| 471 | | - atomic_t dent_count; |
|---|
| 445 | + struct mutex cache_lock; |
|---|
| 446 | +#endif |
|---|
| 447 | + |
|---|
| 448 | + ANDROID_KABI_RESERVE(1); |
|---|
| 449 | + ANDROID_KABI_RESERVE(2); |
|---|
| 450 | +}; |
|---|
| 451 | + |
|---|
| 452 | +/** |
|---|
| 453 | + * struct dma_buf_attach_ops - importer operations for an attachment |
|---|
| 454 | + * |
|---|
| 455 | + * Attachment operations implemented by the importer. |
|---|
| 456 | + */ |
|---|
| 457 | +struct dma_buf_attach_ops { |
|---|
| 458 | + /** |
|---|
| 459 | + * @allow_peer2peer: |
|---|
| 460 | + * |
|---|
| 461 | + * If this is set to true the importer must be able to handle peer |
|---|
| 462 | + * resources without struct pages. |
|---|
| 463 | + */ |
|---|
| 464 | + bool allow_peer2peer; |
|---|
| 465 | + |
|---|
| 466 | + /** |
|---|
| 467 | + * @move_notify: [optional] notification that the DMA-buf is moving |
|---|
| 468 | + * |
|---|
| 469 | + * If this callback is provided the framework can avoid pinning the |
|---|
| 470 | + * backing store while mappings exists. |
|---|
| 471 | + * |
|---|
| 472 | + * This callback is called with the lock of the reservation object |
|---|
| 473 | + * associated with the dma_buf held and the mapping function must be |
|---|
| 474 | + * called with this lock held as well. This makes sure that no mapping |
|---|
| 475 | + * is created concurrently with an ongoing move operation. |
|---|
| 476 | + * |
|---|
| 477 | + * Mappings stay valid and are not directly affected by this callback. |
|---|
| 478 | + * But the DMA-buf can now be in a different physical location, so all |
|---|
| 479 | + * mappings should be destroyed and re-created as soon as possible. |
|---|
| 480 | + * |
|---|
| 481 | + * New mappings can be created after this callback returns, and will |
|---|
| 482 | + * point to the new location of the DMA-buf. |
|---|
| 483 | + */ |
|---|
| 484 | + void (*move_notify)(struct dma_buf_attachment *attach); |
|---|
| 472 | 485 | }; |
|---|
| 473 | 486 | |
|---|
| 474 | 487 | /** |
|---|
| 475 | 488 | * struct dma_buf_attachment - holds device-buffer attachment data |
|---|
| 476 | 489 | * @dmabuf: buffer for this attachment. |
|---|
| 477 | 490 | * @dev: device attached to the buffer. |
|---|
| 478 | | - * @node: list of dma_buf_attachment. |
|---|
| 491 | + * @node: list of dma_buf_attachment, protected by dma_resv lock of the dmabuf. |
|---|
| 492 | + * @sgt: cached mapping. |
|---|
| 493 | + * @dir: direction of cached mapping. |
|---|
| 494 | + * @peer2peer: true if the importer can handle peer resources without pages. |
|---|
| 479 | 495 | * @priv: exporter specific attachment data. |
|---|
| 496 | + * @importer_ops: importer operations for this attachment, if provided |
|---|
| 497 | + * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held. |
|---|
| 498 | + * @importer_priv: importer specific attachment data. |
|---|
| 480 | 499 | * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer |
|---|
| 481 | 500 | * through dma_buf_map_attachment. |
|---|
| 482 | 501 | * |
|---|
| .. | .. |
|---|
| 493 | 512 | struct dma_buf *dmabuf; |
|---|
| 494 | 513 | struct device *dev; |
|---|
| 495 | 514 | struct list_head node; |
|---|
| 515 | + struct sg_table *sgt; |
|---|
| 516 | + enum dma_data_direction dir; |
|---|
| 517 | + bool peer2peer; |
|---|
| 518 | + const struct dma_buf_attach_ops *importer_ops; |
|---|
| 519 | + void *importer_priv; |
|---|
| 496 | 520 | void *priv; |
|---|
| 497 | 521 | unsigned long dma_map_attrs; |
|---|
| 522 | + |
|---|
| 523 | + ANDROID_KABI_RESERVE(1); |
|---|
| 524 | + ANDROID_KABI_RESERVE(2); |
|---|
| 498 | 525 | }; |
|---|
| 499 | 526 | |
|---|
| 500 | 527 | /** |
|---|
| .. | .. |
|---|
| 516 | 543 | const struct dma_buf_ops *ops; |
|---|
| 517 | 544 | size_t size; |
|---|
| 518 | 545 | int flags; |
|---|
| 519 | | - struct reservation_object *resv; |
|---|
| 546 | + struct dma_resv *resv; |
|---|
| 520 | 547 | void *priv; |
|---|
| 548 | + |
|---|
| 549 | + ANDROID_KABI_RESERVE(1); |
|---|
| 550 | + ANDROID_KABI_RESERVE(2); |
|---|
| 521 | 551 | }; |
|---|
| 522 | 552 | |
|---|
| 523 | 553 | /** |
|---|
| .. | .. |
|---|
| 545 | 575 | get_file(dmabuf->file); |
|---|
| 546 | 576 | } |
|---|
| 547 | 577 | |
|---|
| 548 | | -#ifdef CONFIG_ARCH_ROCKCHIP |
|---|
| 549 | | -int dma_buf_set_release_callback(struct dma_buf *dmabuf, |
|---|
| 550 | | - void (*callback)(void *), void *data); |
|---|
| 578 | +/** |
|---|
| 579 | + * dma_buf_is_dynamic - check if a DMA-buf uses dynamic mappings. |
|---|
| 580 | + * @dmabuf: the DMA-buf to check |
|---|
| 581 | + * |
|---|
| 582 | + * Returns true if a DMA-buf exporter wants to be called with the dma_resv |
|---|
| 583 | + * locked for the map/unmap callbacks, false if it doesn't wants to be called |
|---|
| 584 | + * with the lock held. |
|---|
| 585 | + */ |
|---|
| 586 | +static inline bool dma_buf_is_dynamic(struct dma_buf *dmabuf) |
|---|
| 587 | +{ |
|---|
| 588 | + return !!dmabuf->ops->pin; |
|---|
| 589 | +} |
|---|
| 551 | 590 | |
|---|
| 552 | | -void *dma_buf_get_release_callback_data(struct dma_buf *dmabuf, |
|---|
| 553 | | - void (*callback)(void *)); |
|---|
| 554 | | -#endif |
|---|
| 591 | +/** |
|---|
| 592 | + * dma_buf_attachment_is_dynamic - check if a DMA-buf attachment uses dynamic |
|---|
| 593 | + * mappinsg |
|---|
| 594 | + * @attach: the DMA-buf attachment to check |
|---|
| 595 | + * |
|---|
| 596 | + * Returns true if a DMA-buf importer wants to call the map/unmap functions with |
|---|
| 597 | + * the dma_resv lock held. |
|---|
| 598 | + */ |
|---|
| 599 | +static inline bool |
|---|
| 600 | +dma_buf_attachment_is_dynamic(struct dma_buf_attachment *attach) |
|---|
| 601 | +{ |
|---|
| 602 | + return !!attach->importer_ops; |
|---|
| 603 | +} |
|---|
| 555 | 604 | |
|---|
| 605 | +int get_each_dmabuf(int (*callback)(const struct dma_buf *dmabuf, |
|---|
| 606 | + void *private), void *private); |
|---|
| 607 | +int is_dma_buf_file(struct file *file); |
|---|
| 556 | 608 | struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, |
|---|
| 557 | | - struct device *dev); |
|---|
| 609 | + struct device *dev); |
|---|
| 610 | +struct dma_buf_attachment * |
|---|
| 611 | +dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev, |
|---|
| 612 | + const struct dma_buf_attach_ops *importer_ops, |
|---|
| 613 | + void *importer_priv); |
|---|
| 558 | 614 | void dma_buf_detach(struct dma_buf *dmabuf, |
|---|
| 559 | | - struct dma_buf_attachment *dmabuf_attach); |
|---|
| 615 | + struct dma_buf_attachment *attach); |
|---|
| 616 | +int dma_buf_pin(struct dma_buf_attachment *attach); |
|---|
| 617 | +void dma_buf_unpin(struct dma_buf_attachment *attach); |
|---|
| 560 | 618 | |
|---|
| 561 | 619 | struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info); |
|---|
| 562 | 620 | |
|---|
| .. | .. |
|---|
| 568 | 626 | enum dma_data_direction); |
|---|
| 569 | 627 | void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *, |
|---|
| 570 | 628 | enum dma_data_direction); |
|---|
| 629 | +void dma_buf_move_notify(struct dma_buf *dma_buf); |
|---|
| 571 | 630 | int dma_buf_begin_cpu_access(struct dma_buf *dma_buf, |
|---|
| 572 | 631 | enum dma_data_direction dir); |
|---|
| 573 | 632 | int dma_buf_begin_cpu_access_partial(struct dma_buf *dma_buf, |
|---|
| .. | .. |
|---|
| 578 | 637 | int dma_buf_end_cpu_access_partial(struct dma_buf *dma_buf, |
|---|
| 579 | 638 | enum dma_data_direction dir, |
|---|
| 580 | 639 | unsigned int offset, unsigned int len); |
|---|
| 581 | | -void *dma_buf_kmap(struct dma_buf *, unsigned long); |
|---|
| 582 | | -void dma_buf_kunmap(struct dma_buf *, unsigned long, void *); |
|---|
| 583 | 640 | |
|---|
| 584 | 641 | int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, |
|---|
| 585 | 642 | unsigned long); |
|---|
| 586 | 643 | void *dma_buf_vmap(struct dma_buf *); |
|---|
| 587 | 644 | void dma_buf_vunmap(struct dma_buf *, void *vaddr); |
|---|
| 645 | +long dma_buf_set_name(struct dma_buf *dmabuf, const char *name); |
|---|
| 588 | 646 | int dma_buf_get_flags(struct dma_buf *dmabuf, unsigned long *flags); |
|---|
| 589 | 647 | int dma_buf_get_uuid(struct dma_buf *dmabuf, uuid_t *uuid); |
|---|
| 590 | 648 | |
|---|
| 649 | +#ifdef CONFIG_DMABUF_CACHE |
|---|
| 591 | 650 | /** |
|---|
| 592 | 651 | * dma_buf_set_destructor - set the dma-buf's destructor |
|---|
| 593 | 652 | * @dmabuf: [in] pointer to dma-buf |
|---|
| .. | .. |
|---|
| 601 | 660 | dmabuf->dtor = dtor; |
|---|
| 602 | 661 | dmabuf->dtor_data = dtor_data; |
|---|
| 603 | 662 | } |
|---|
| 663 | +#endif |
|---|
| 664 | + |
|---|
| 665 | +#if IS_ENABLED(CONFIG_RK_DMABUF_DEBUG) |
|---|
| 666 | +void dma_buf_reset_peak_size(void); |
|---|
| 667 | +size_t dma_buf_get_peak_size(void); |
|---|
| 668 | +size_t dma_buf_get_total_size(void); |
|---|
| 669 | +#else |
|---|
| 670 | +static inline void dma_buf_reset_peak_size(void) {} |
|---|
| 671 | +static inline size_t dma_buf_get_peak_size(void) { return 0; } |
|---|
| 672 | +static inline size_t dma_buf_get_total_size(void) { return 0; } |
|---|
| 673 | +#endif |
|---|
| 604 | 674 | |
|---|
| 605 | 675 | #endif /* __DMA_BUF_H__ */ |
|---|