aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/dma-buf.h
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2012-03-19 19:02:37 -0400
committerSumit Semwal <sumit.semwal@ti.com>2012-03-26 02:03:02 -0400
commitfc13020e086bfedf2afb95c91c026d5af1f80107 (patch)
treea06be5c3eff6865a42046b51270e4d60e30609f4 /include/linux/dma-buf.h
parent6b607e3a658fee490bdabfdeb739a3eb498b1bff (diff)
dma-buf: add support for kernel cpu access
Big differences to other contenders in the field (like ion) is that this also supports highmem, so we have to split up the cpu access from the kernel side into a prepare and a kmap step. Prepare is allowed to fail and should do everything required so that the kmap calls can succeed (like swapin/backing storage allocation, flushing, ...). More in-depth explanations will follow in the follow-up documentation patch. Changes in v2: - Clear up begin_cpu_access confusion noticed by Sumit Semwal. - Don't automatically fallback from the _atomic variants to the non-atomic variants. The _atomic callbacks are not allowed to sleep, so we want exporters to make this decision explicit. The function signatures are explicit, so simpler exporters can still use the same function for both. - Make the unmap functions optional. Simpler exporters with permanent mappings don't need to do anything at unmap time. Changes in v3: - Adjust the WARN_ON checks for the new ->ops functions as suggested by Rob Clark and Sumit Semwal. - Rebased on top of latest dma-buf-next git. Changes in v4: - Fixup a missing - in a return -EINVAL; statement. Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Rob Clark <rob@ti.com> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Diffstat (limited to 'include/linux/dma-buf.h')
-rw-r--r--include/linux/dma-buf.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index 24e0f4828711..ee7ef9990d9a 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -50,6 +50,17 @@ struct dma_buf_attachment;
50 * @unmap_dma_buf: decreases usecount of buffer, might deallocate scatter 50 * @unmap_dma_buf: decreases usecount of buffer, might deallocate scatter
51 * pages. 51 * pages.
52 * @release: release this buffer; to be called after the last dma_buf_put. 52 * @release: release this buffer; to be called after the last dma_buf_put.
53 * @begin_cpu_access: [optional] called before cpu access to invalidate cpu
54 * caches and allocate backing storage (if not yet done)
55 * respectively pin the objet into memory.
56 * @end_cpu_access: [optional] called after cpu access to flush cashes.
57 * @kmap_atomic: maps a page from the buffer into kernel address
58 * space, users may not block until the subsequent unmap call.
59 * This callback must not sleep.
60 * @kunmap_atomic: [optional] unmaps a atomically mapped page from the buffer.
61 * This Callback must not sleep.
62 * @kmap: maps a page from the buffer into kernel address space.
63 * @kunmap: [optional] unmaps a page from the buffer.
53 */ 64 */
54struct dma_buf_ops { 65struct dma_buf_ops {
55 int (*attach)(struct dma_buf *, struct device *, 66 int (*attach)(struct dma_buf *, struct device *,
@@ -73,6 +84,14 @@ struct dma_buf_ops {
73 /* after final dma_buf_put() */ 84 /* after final dma_buf_put() */
74 void (*release)(struct dma_buf *); 85 void (*release)(struct dma_buf *);
75 86
87 int (*begin_cpu_access)(struct dma_buf *, size_t, size_t,
88 enum dma_data_direction);
89 void (*end_cpu_access)(struct dma_buf *, size_t, size_t,
90 enum dma_data_direction);
91 void *(*kmap_atomic)(struct dma_buf *, unsigned long);
92 void (*kunmap_atomic)(struct dma_buf *, unsigned long, void *);
93 void *(*kmap)(struct dma_buf *, unsigned long);
94 void (*kunmap)(struct dma_buf *, unsigned long, void *);
76}; 95};
77 96
78/** 97/**
@@ -140,6 +159,14 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *,
140 enum dma_data_direction); 159 enum dma_data_direction);
141void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *, 160void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *,
142 enum dma_data_direction); 161 enum dma_data_direction);
162int dma_buf_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t len,
163 enum dma_data_direction dir);
164void dma_buf_end_cpu_access(struct dma_buf *dma_buf, size_t start, size_t len,
165 enum dma_data_direction dir);
166void *dma_buf_kmap_atomic(struct dma_buf *, unsigned long);
167void dma_buf_kunmap_atomic(struct dma_buf *, unsigned long, void *);
168void *dma_buf_kmap(struct dma_buf *, unsigned long);
169void dma_buf_kunmap(struct dma_buf *, unsigned long, void *);
143#else 170#else
144 171
145static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, 172static inline struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
@@ -188,6 +215,38 @@ static inline void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
188 return; 215 return;
189} 216}
190 217
218static inline int dma_buf_begin_cpu_access(struct dma_buf *,
219 size_t, size_t,
220 enum dma_data_direction)
221{
222 return -ENODEV;
223}
224
225static inline void dma_buf_end_cpu_access(struct dma_buf *,
226 size_t, size_t,
227 enum dma_data_direction)
228{
229}
230
231static inline void *dma_buf_kmap_atomic(struct dma_buf *, unsigned long)
232{
233 return NULL;
234}
235
236static inline void dma_buf_kunmap_atomic(struct dma_buf *, unsigned long,
237 void *)
238{
239}
240
241static inline void *dma_buf_kmap(struct dma_buf *, unsigned long)
242{
243 return NULL;
244}
245
246static inline void dma_buf_kunmap(struct dma_buf *, unsigned long,
247 void *)
248{
249}
191#endif /* CONFIG_DMA_SHARED_BUFFER */ 250#endif /* CONFIG_DMA_SHARED_BUFFER */
192 251
193#endif /* __DMA_BUF_H__ */ 252#endif /* __DMA_BUF_H__ */