GNU Linux-libre 5.10.153-gnu1
[releases.git] / drivers / dma-buf / heaps / heap-helpers.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * DMABUF Heaps helper code
4  *
5  * Copyright (C) 2011 Google, Inc.
6  * Copyright (C) 2019 Linaro Ltd.
7  */
8
9 #ifndef _HEAP_HELPERS_H
10 #define _HEAP_HELPERS_H
11
12 #include <linux/dma-heap.h>
13 #include <linux/list.h>
14
15 /**
16  * struct heap_helper_buffer - helper buffer metadata
17  * @heap:               back pointer to the heap the buffer came from
18  * @dmabuf:             backing dma-buf for this buffer
19  * @size:               size of the buffer
20  * @priv_virt           pointer to heap specific private value
21  * @lock                mutext to protect the data in this structure
22  * @vmap_cnt            count of vmap references on the buffer
23  * @vaddr               vmap'ed virtual address
24  * @pagecount           number of pages in the buffer
25  * @pages               list of page pointers
26  * @attachments         list of device attachments
27  *
28  * @free                heap callback to free the buffer
29  */
30 struct heap_helper_buffer {
31         struct dma_heap *heap;
32         struct dma_buf *dmabuf;
33         size_t size;
34
35         void *priv_virt;
36         struct mutex lock;
37         int vmap_cnt;
38         void *vaddr;
39         pgoff_t pagecount;
40         struct page **pages;
41         struct list_head attachments;
42
43         void (*free)(struct heap_helper_buffer *buffer);
44 };
45
46 void init_heap_helper_buffer(struct heap_helper_buffer *buffer,
47                              void (*free)(struct heap_helper_buffer *));
48
49 struct dma_buf *heap_helper_export_dmabuf(struct heap_helper_buffer *buffer,
50                                           int fd_flags);
51
52 extern const struct dma_buf_ops heap_helper_ops;
53 #endif /* _HEAP_HELPERS_H */