blob: 805d2df88024ffcf84f4a2abcea25a2967aeb119 [file] [log] [blame]
Olivier Deprez157378f2022-04-04 15:47:50 +02001/* 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 */
30struct 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
46void init_heap_helper_buffer(struct heap_helper_buffer *buffer,
47 void (*free)(struct heap_helper_buffer *));
48
49struct dma_buf *heap_helper_export_dmabuf(struct heap_helper_buffer *buffer,
50 int fd_flags);
51
52extern const struct dma_buf_ops heap_helper_ops;
53#endif /* _HEAP_HELPERS_H */