Home | History | Annotate | Line # | Download | only in linux
dma-buf.h revision 1.10
      1  1.10  riastrad /*	$NetBSD: dma-buf.h,v 1.10 2021/12/19 10:38:23 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.8  riastrad #include <linux/dma-resv.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.8  riastrad struct dma_resv;
     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.10  riastrad 	bool	cache_sgt_mapping;
     62   1.5  riastrad 	int	(*attach)(struct dma_buf *, struct dma_buf_attachment *);
     63   1.3  riastrad 	void	(*detach)(struct dma_buf *, struct dma_buf_attachment *);
     64   1.3  riastrad 	struct sg_table *
     65   1.3  riastrad 		(*map_dma_buf)(struct dma_buf_attachment *,
     66   1.3  riastrad 		    enum dma_data_direction);
     67   1.3  riastrad 	void	(*unmap_dma_buf)(struct dma_buf_attachment *,
     68   1.3  riastrad 		    struct sg_table *, enum dma_data_direction);
     69   1.3  riastrad 	void	(*release)(struct dma_buf *);
     70   1.6  riastrad 	int	(*begin_cpu_access)(struct dma_buf *, enum dma_data_direction);
     71   1.6  riastrad 	int	(*end_cpu_access)(struct dma_buf *, enum dma_data_direction);
     72   1.3  riastrad 	int	(*mmap)(struct dma_buf *, off_t *, size_t, int, int *,
     73   1.3  riastrad 		    int *, struct uvm_object **, int *);
     74   1.3  riastrad 	void *	(*vmap)(struct dma_buf *);
     75   1.3  riastrad 	void	(*vunmap)(struct dma_buf *, void *);
     76   1.3  riastrad };
     77   1.3  riastrad 
     78   1.3  riastrad struct dma_buf {
     79   1.3  riastrad 	void				*priv;
     80   1.3  riastrad 	const struct dma_buf_ops	*ops;
     81   1.3  riastrad 	size_t				size;
     82   1.8  riastrad 	struct dma_resv			*resv;
     83   1.3  riastrad 
     84   1.3  riastrad 	kmutex_t			db_lock;
     85   1.3  riastrad 	volatile unsigned		db_refcnt;
     86   1.8  riastrad 	struct dma_resv_poll		db_resv_poll;
     87   1.8  riastrad 	struct dma_resv			db_resv_int[];
     88   1.3  riastrad };
     89   1.3  riastrad 
     90   1.3  riastrad struct dma_buf_attachment {
     91   1.3  riastrad 	void				*priv;
     92   1.3  riastrad 	struct dma_buf			*dmabuf;
     93   1.5  riastrad 	struct device			*dev;
     94   1.3  riastrad };
     95   1.3  riastrad 
     96   1.3  riastrad struct dma_buf_export_info {
     97   1.3  riastrad #if 0
     98   1.3  riastrad 	const char			*exp_name;
     99   1.3  riastrad 	struct module			*owner;
    100   1.3  riastrad #endif
    101   1.3  riastrad 	const struct dma_buf_ops	*ops;
    102   1.3  riastrad 	size_t				size;
    103   1.3  riastrad 	int				flags;
    104   1.8  riastrad 	struct dma_resv			*resv;
    105   1.3  riastrad 	void				*priv;
    106   1.3  riastrad };
    107   1.3  riastrad 
    108   1.3  riastrad #define	DEFINE_DMA_BUF_EXPORT_INFO(info)				      \
    109   1.3  riastrad 	struct dma_buf_export_info info = { .priv = NULL }
    110   1.3  riastrad 
    111   1.3  riastrad #define	dma_buf_attach		linux_dma_buf_attach
    112   1.3  riastrad #define	dma_buf_detach		linux_dma_buf_detach
    113   1.3  riastrad #define	dma_buf_export		linux_dma_buf_export
    114   1.3  riastrad #define	dma_buf_fd		linux_dma_buf_fd
    115   1.3  riastrad #define	dma_buf_get		linux_dma_buf_get
    116   1.3  riastrad #define	dma_buf_map_attachment	linux_dma_buf_map_attachment
    117   1.3  riastrad #define	dma_buf_put		linux_dma_buf_put
    118   1.3  riastrad #define	dma_buf_unmap_attachment linux_dma_buf_unmap_attachment
    119   1.3  riastrad #define	get_dma_buf		linux_get_dma_buf
    120   1.3  riastrad 
    121   1.3  riastrad struct dma_buf *
    122   1.3  riastrad 	dma_buf_export(struct dma_buf_export_info *);
    123   1.3  riastrad 
    124   1.3  riastrad int	dma_buf_fd(struct dma_buf *, int);
    125   1.3  riastrad struct dma_buf *
    126   1.3  riastrad 	dma_buf_get(int);
    127   1.3  riastrad void	get_dma_buf(struct dma_buf *);
    128   1.3  riastrad void	dma_buf_put(struct dma_buf *);
    129   1.3  riastrad 
    130   1.3  riastrad struct dma_buf_attachment *
    131   1.3  riastrad 	dma_buf_attach(struct dma_buf *, struct device *);
    132   1.3  riastrad void	dma_buf_detach(struct dma_buf *, struct dma_buf_attachment *);
    133   1.3  riastrad 
    134   1.3  riastrad struct sg_table *
    135   1.3  riastrad 	dma_buf_map_attachment(struct dma_buf_attachment *,
    136   1.3  riastrad 	    enum dma_data_direction);
    137   1.3  riastrad void	dma_buf_unmap_attachment(struct dma_buf_attachment *,
    138   1.3  riastrad 	    struct sg_table *, enum dma_data_direction);
    139   1.3  riastrad 
    140   1.2  riastrad #endif  /* _LINUX_DMA_BUF_H_ */
    141