dma-buf.h revision 1.3 1 1.3 riastrad /* $NetBSD: dma-buf.h,v 1.3 2018/08/27 15:22:54 riastradh Exp $ */
2 1.2 riastrad
3 1.2 riastrad /*-
4 1.3 riastrad * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 1.2 riastrad * All rights reserved.
6 1.2 riastrad *
7 1.2 riastrad * This code is derived from software contributed to The NetBSD Foundation
8 1.2 riastrad * by Taylor R. Campbell.
9 1.2 riastrad *
10 1.2 riastrad * Redistribution and use in source and binary forms, with or without
11 1.2 riastrad * modification, are permitted provided that the following conditions
12 1.2 riastrad * are met:
13 1.2 riastrad * 1. Redistributions of source code must retain the above copyright
14 1.2 riastrad * notice, this list of conditions and the following disclaimer.
15 1.2 riastrad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 riastrad * notice, this list of conditions and the following disclaimer in the
17 1.2 riastrad * documentation and/or other materials provided with the distribution.
18 1.2 riastrad *
19 1.2 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 riastrad * POSSIBILITY OF SUCH DAMAGE.
30 1.2 riastrad */
31 1.2 riastrad
32 1.2 riastrad #ifndef _LINUX_DMA_BUF_H_
33 1.2 riastrad #define _LINUX_DMA_BUF_H_
34 1.2 riastrad
35 1.3 riastrad #include <sys/types.h>
36 1.3 riastrad #include <sys/bus.h>
37 1.3 riastrad #include <sys/mutex.h>
38 1.3 riastrad
39 1.3 riastrad #include <linux/reservation.h>
40 1.3 riastrad
41 1.3 riastrad struct device;
42 1.3 riastrad struct dma_buf;
43 1.3 riastrad struct dma_buf_attachment;
44 1.3 riastrad struct dma_buf_export_info;
45 1.3 riastrad struct dma_buf_ops;
46 1.3 riastrad struct file;
47 1.3 riastrad struct module;
48 1.3 riastrad struct reservation_object;
49 1.3 riastrad struct sg_table;
50 1.3 riastrad struct uvm_object;
51 1.3 riastrad
52 1.3 riastrad enum dma_data_direction {
53 1.3 riastrad DMA_NONE = 0,
54 1.3 riastrad DMA_TO_DEVICE = 1,
55 1.3 riastrad DMA_FROM_DEVICE = 2,
56 1.3 riastrad DMA_BIDIRECTIONAL = 3,
57 1.3 riastrad };
58 1.3 riastrad
59 1.3 riastrad struct dma_buf_ops {
60 1.3 riastrad int (*attach)(struct dma_buf *, struct device *,
61 1.3 riastrad struct dma_buf_attachment *);
62 1.3 riastrad void (*detach)(struct dma_buf *, struct dma_buf_attachment *);
63 1.3 riastrad struct sg_table *
64 1.3 riastrad (*map_dma_buf)(struct dma_buf_attachment *,
65 1.3 riastrad enum dma_data_direction);
66 1.3 riastrad void (*unmap_dma_buf)(struct dma_buf_attachment *,
67 1.3 riastrad struct sg_table *, enum dma_data_direction);
68 1.3 riastrad void (*release)(struct dma_buf *);
69 1.3 riastrad int (*begin_cpu_access)(struct dma_buf *, size_t, size_t,
70 1.3 riastrad enum dma_data_direction);
71 1.3 riastrad int (*end_cpu_access)(struct dma_buf *, size_t, size_t,
72 1.3 riastrad enum dma_data_direction);
73 1.3 riastrad void * (*kmap_atomic)(struct dma_buf *, unsigned long);
74 1.3 riastrad void (*kunmap_atomic)(struct dma_buf *, unsigned long, void *);
75 1.3 riastrad void * (*kmap)(struct dma_buf *, unsigned long);
76 1.3 riastrad void (*kunmap)(struct dma_buf *, unsigned long, void *);
77 1.3 riastrad int (*mmap)(struct dma_buf *, off_t *, size_t, int, int *,
78 1.3 riastrad int *, struct uvm_object **, int *);
79 1.3 riastrad void * (*vmap)(struct dma_buf *);
80 1.3 riastrad void (*vunmap)(struct dma_buf *, void *);
81 1.3 riastrad };
82 1.3 riastrad
83 1.3 riastrad struct dma_buf {
84 1.3 riastrad void *priv;
85 1.3 riastrad const struct dma_buf_ops *ops;
86 1.3 riastrad size_t size;
87 1.3 riastrad struct reservation_object *resv;
88 1.3 riastrad
89 1.3 riastrad kmutex_t db_lock;
90 1.3 riastrad volatile unsigned db_refcnt;
91 1.3 riastrad struct selinfo db_selq;
92 1.3 riastrad struct reservation_object db_resv_int[];
93 1.3 riastrad };
94 1.3 riastrad
95 1.3 riastrad struct dma_buf_attachment {
96 1.3 riastrad void *priv;
97 1.3 riastrad struct dma_buf *dmabuf;
98 1.3 riastrad };
99 1.3 riastrad
100 1.3 riastrad struct dma_buf_export_info {
101 1.3 riastrad #if 0
102 1.3 riastrad const char *exp_name;
103 1.3 riastrad struct module *owner;
104 1.3 riastrad #endif
105 1.3 riastrad const struct dma_buf_ops *ops;
106 1.3 riastrad size_t size;
107 1.3 riastrad int flags;
108 1.3 riastrad struct reservation_object *resv;
109 1.3 riastrad void *priv;
110 1.3 riastrad };
111 1.3 riastrad
112 1.3 riastrad #define DEFINE_DMA_BUF_EXPORT_INFO(info) \
113 1.3 riastrad struct dma_buf_export_info info = { .priv = NULL }
114 1.3 riastrad
115 1.3 riastrad #define dma_buf_attach linux_dma_buf_attach
116 1.3 riastrad #define dma_buf_detach linux_dma_buf_detach
117 1.3 riastrad #define dma_buf_export linux_dma_buf_export
118 1.3 riastrad #define dma_buf_fd linux_dma_buf_fd
119 1.3 riastrad #define dma_buf_get linux_dma_buf_get
120 1.3 riastrad #define dma_buf_map_attachment linux_dma_buf_map_attachment
121 1.3 riastrad #define dma_buf_put linux_dma_buf_put
122 1.3 riastrad #define dma_buf_unmap_attachment linux_dma_buf_unmap_attachment
123 1.3 riastrad #define get_dma_buf linux_get_dma_buf
124 1.3 riastrad
125 1.3 riastrad struct dma_buf *
126 1.3 riastrad dma_buf_export(struct dma_buf_export_info *);
127 1.3 riastrad
128 1.3 riastrad int dma_buf_fd(struct dma_buf *, int);
129 1.3 riastrad struct dma_buf *
130 1.3 riastrad dma_buf_get(int);
131 1.3 riastrad void get_dma_buf(struct dma_buf *);
132 1.3 riastrad void dma_buf_put(struct dma_buf *);
133 1.3 riastrad
134 1.3 riastrad struct dma_buf_attachment *
135 1.3 riastrad dma_buf_attach(struct dma_buf *, struct device *);
136 1.3 riastrad void dma_buf_detach(struct dma_buf *, struct dma_buf_attachment *);
137 1.3 riastrad
138 1.3 riastrad struct sg_table *
139 1.3 riastrad dma_buf_map_attachment(struct dma_buf_attachment *,
140 1.3 riastrad enum dma_data_direction);
141 1.3 riastrad void dma_buf_unmap_attachment(struct dma_buf_attachment *,
142 1.3 riastrad struct sg_table *, enum dma_data_direction);
143 1.3 riastrad
144 1.2 riastrad #endif /* _LINUX_DMA_BUF_H_ */
145