1 /* $OpenBSD: dma-buf.h,v 1.4 2022/03/01 04:08:04 jsg Exp $ */
2 /*
3 * Copyright (c) 2018 Mark Kettenis
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #ifndef _LINUX_DMA_BUF_H
19 #define _LINUX_DMA_BUF_H
20
21 #include <sys/types.h>
22 #include <sys/systm.h>
23 #include <linux/dma-resv.h>
24 #include <linux/list.h>
25
26 struct dma_buf_ops;
27 struct device;
28
29 struct dma_buf {
30 const struct dma_buf_ops *ops;
31 void *priv;
32 size_t size;
33 struct file *file;
34 struct list_head attachments;
35 struct dma_resv *resv;
36 };
37
38 struct dma_buf_attachment {
39 void *importer_priv;
40 };
41
42 struct dma_buf_attach_ops {
43 void (*move_notify)(struct dma_buf_attachment *);
44 bool allow_peer2peer;
45 };
46
47 void get_dma_buf(struct dma_buf *);
48 struct dma_buf *dma_buf_get(int);
49 void dma_buf_put(struct dma_buf *);
50 int dma_buf_fd(struct dma_buf *, int);
51
52 struct dma_buf_ops {
53 void (*release)(struct dma_buf *);
54 };
55
56 struct dma_buf_export_info {
57 const struct dma_buf_ops *ops;
58 size_t size;
59 int flags;
60 void *priv;
61 struct dma_resv *resv;
62 };
63
64 #define DEFINE_DMA_BUF_EXPORT_INFO(x) struct dma_buf_export_info x
65
66 struct dma_buf *dma_buf_export(const struct dma_buf_export_info *);
67
68 static inline struct dma_buf_attachment *
dma_buf_attach(struct dma_buf * buf,struct device * dev)69 dma_buf_attach(struct dma_buf *buf, struct device *dev)
70 {
71 return NULL;
72 }
73
74 static inline void
dma_buf_detach(struct dma_buf * buf,struct dma_buf_attachment * dba)75 dma_buf_detach(struct dma_buf *buf, struct dma_buf_attachment *dba)
76 {
77 panic("dma_buf_detach");
78 }
79
80 #endif
81