Home | History | Annotate | Line # | Download | only in linux
dma-buf.h revision 1.7
      1  1.7  riastrad /*	$NetBSD: dma-buf.h,v 1.7 2021/12/19 09:50:57 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.7  riastrad #include <linux/err.h>
     40  1.3  riastrad #include <linux/reservation.h>
     41  1.3  riastrad 
     42  1.3  riastrad struct device;
     43  1.3  riastrad struct dma_buf;
     44  1.3  riastrad struct dma_buf_attachment;
     45  1.3  riastrad struct dma_buf_export_info;
     46  1.3  riastrad struct dma_buf_ops;
     47  1.3  riastrad struct file;
     48  1.3  riastrad struct module;
     49  1.3  riastrad struct reservation_object;
     50  1.3  riastrad struct sg_table;
     51  1.3  riastrad struct uvm_object;
     52  1.3  riastrad 
     53  1.3  riastrad enum dma_data_direction {
     54  1.3  riastrad 	DMA_NONE		= 0,
     55  1.3  riastrad 	DMA_TO_DEVICE		= 1,
     56  1.3  riastrad 	DMA_FROM_DEVICE		= 2,
     57  1.3  riastrad 	DMA_BIDIRECTIONAL	= 3,
     58  1.3  riastrad };
     59  1.3  riastrad 
     60  1.3  riastrad struct dma_buf_ops {
     61  1.5  riastrad 	int	(*attach)(struct dma_buf *, 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.6  riastrad 	int	(*begin_cpu_access)(struct dma_buf *, enum dma_data_direction);
     70  1.6  riastrad 	int	(*end_cpu_access)(struct dma_buf *, enum dma_data_direction);
     71  1.5  riastrad 	void *	(*map)(struct dma_buf *, unsigned long);
     72  1.5  riastrad 	void	(*unmap)(struct dma_buf *, unsigned long, void *);
     73  1.3  riastrad 	int	(*mmap)(struct dma_buf *, off_t *, size_t, int, int *,
     74  1.3  riastrad 		    int *, struct uvm_object **, int *);
     75  1.3  riastrad 	void *	(*vmap)(struct dma_buf *);
     76  1.3  riastrad 	void	(*vunmap)(struct dma_buf *, void *);
     77  1.3  riastrad };
     78  1.3  riastrad 
     79  1.3  riastrad struct dma_buf {
     80  1.3  riastrad 	void				*priv;
     81  1.3  riastrad 	const struct dma_buf_ops	*ops;
     82  1.3  riastrad 	size_t				size;
     83  1.3  riastrad 	struct reservation_object	*resv;
     84  1.3  riastrad 
     85  1.3  riastrad 	kmutex_t			db_lock;
     86  1.3  riastrad 	volatile unsigned		db_refcnt;
     87  1.4  riastrad 	struct reservation_poll		db_resv_poll;
     88  1.3  riastrad 	struct reservation_object	db_resv_int[];
     89  1.3  riastrad };
     90  1.3  riastrad 
     91  1.3  riastrad struct dma_buf_attachment {
     92  1.3  riastrad 	void				*priv;
     93  1.3  riastrad 	struct dma_buf			*dmabuf;
     94  1.5  riastrad 	struct device			*dev;
     95  1.3  riastrad };
     96  1.3  riastrad 
     97  1.3  riastrad struct dma_buf_export_info {
     98  1.3  riastrad #if 0
     99  1.3  riastrad 	const char			*exp_name;
    100  1.3  riastrad 	struct module			*owner;
    101  1.3  riastrad #endif
    102  1.3  riastrad 	const struct dma_buf_ops	*ops;
    103  1.3  riastrad 	size_t				size;
    104  1.3  riastrad 	int				flags;
    105  1.3  riastrad 	struct reservation_object	*resv;
    106  1.3  riastrad 	void				*priv;
    107  1.3  riastrad };
    108  1.3  riastrad 
    109  1.3  riastrad #define	DEFINE_DMA_BUF_EXPORT_INFO(info)				      \
    110  1.3  riastrad 	struct dma_buf_export_info info = { .priv = NULL }
    111  1.3  riastrad 
    112  1.3  riastrad #define	dma_buf_attach		linux_dma_buf_attach
    113  1.3  riastrad #define	dma_buf_detach		linux_dma_buf_detach
    114  1.3  riastrad #define	dma_buf_export		linux_dma_buf_export
    115  1.3  riastrad #define	dma_buf_fd		linux_dma_buf_fd
    116  1.3  riastrad #define	dma_buf_get		linux_dma_buf_get
    117  1.3  riastrad #define	dma_buf_map_attachment	linux_dma_buf_map_attachment
    118  1.3  riastrad #define	dma_buf_put		linux_dma_buf_put
    119  1.3  riastrad #define	dma_buf_unmap_attachment linux_dma_buf_unmap_attachment
    120  1.3  riastrad #define	get_dma_buf		linux_get_dma_buf
    121  1.3  riastrad 
    122  1.3  riastrad struct dma_buf *
    123  1.3  riastrad 	dma_buf_export(struct dma_buf_export_info *);
    124  1.3  riastrad 
    125  1.3  riastrad int	dma_buf_fd(struct dma_buf *, int);
    126  1.3  riastrad struct dma_buf *
    127  1.3  riastrad 	dma_buf_get(int);
    128  1.3  riastrad void	get_dma_buf(struct dma_buf *);
    129  1.3  riastrad void	dma_buf_put(struct dma_buf *);
    130  1.3  riastrad 
    131  1.3  riastrad struct dma_buf_attachment *
    132  1.3  riastrad 	dma_buf_attach(struct dma_buf *, struct device *);
    133  1.3  riastrad void	dma_buf_detach(struct dma_buf *, struct dma_buf_attachment *);
    134  1.3  riastrad 
    135  1.3  riastrad struct sg_table *
    136  1.3  riastrad 	dma_buf_map_attachment(struct dma_buf_attachment *,
    137  1.3  riastrad 	    enum dma_data_direction);
    138  1.3  riastrad void	dma_buf_unmap_attachment(struct dma_buf_attachment *,
    139  1.3  riastrad 	    struct sg_table *, enum dma_data_direction);
    140  1.3  riastrad 
    141  1.2  riastrad #endif  /* _LINUX_DMA_BUF_H_ */
    142