Home | History | Annotate | Line # | Download | only in linux
      1  1.12  riastrad /*	$NetBSD: dma-buf.h,v 1.12 2021/12/19 12:01:40 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.11  riastrad #include <linux/dma-mapping.h>
     41   1.8  riastrad #include <linux/dma-resv.h>
     42  1.11  riastrad #include <linux/scatterlist.h>
     43   1.3  riastrad 
     44   1.3  riastrad struct device;
     45   1.3  riastrad struct dma_buf;
     46   1.3  riastrad struct dma_buf_attachment;
     47   1.3  riastrad struct dma_buf_export_info;
     48   1.3  riastrad struct dma_buf_ops;
     49   1.3  riastrad struct file;
     50   1.3  riastrad struct module;
     51   1.8  riastrad struct dma_resv;
     52   1.3  riastrad struct sg_table;
     53   1.3  riastrad struct uvm_object;
     54   1.3  riastrad 
     55   1.3  riastrad struct dma_buf_ops {
     56  1.10  riastrad 	bool	cache_sgt_mapping;
     57  1.12  riastrad 	bool	dynamic_mapping;
     58   1.5  riastrad 	int	(*attach)(struct dma_buf *, struct dma_buf_attachment *);
     59   1.3  riastrad 	void	(*detach)(struct dma_buf *, struct dma_buf_attachment *);
     60   1.3  riastrad 	struct sg_table *
     61   1.3  riastrad 		(*map_dma_buf)(struct dma_buf_attachment *,
     62   1.3  riastrad 		    enum dma_data_direction);
     63   1.3  riastrad 	void	(*unmap_dma_buf)(struct dma_buf_attachment *,
     64   1.3  riastrad 		    struct sg_table *, enum dma_data_direction);
     65   1.3  riastrad 	void	(*release)(struct dma_buf *);
     66   1.6  riastrad 	int	(*begin_cpu_access)(struct dma_buf *, enum dma_data_direction);
     67   1.6  riastrad 	int	(*end_cpu_access)(struct dma_buf *, enum dma_data_direction);
     68   1.3  riastrad 	int	(*mmap)(struct dma_buf *, off_t *, size_t, int, int *,
     69   1.3  riastrad 		    int *, struct uvm_object **, int *);
     70   1.3  riastrad 	void *	(*vmap)(struct dma_buf *);
     71   1.3  riastrad 	void	(*vunmap)(struct dma_buf *, void *);
     72   1.3  riastrad };
     73   1.3  riastrad 
     74   1.3  riastrad struct dma_buf {
     75   1.3  riastrad 	void				*priv;
     76   1.3  riastrad 	const struct dma_buf_ops	*ops;
     77   1.3  riastrad 	size_t				size;
     78   1.8  riastrad 	struct dma_resv			*resv;
     79   1.3  riastrad 
     80   1.3  riastrad 	kmutex_t			db_lock;
     81   1.3  riastrad 	volatile unsigned		db_refcnt;
     82   1.8  riastrad 	struct dma_resv_poll		db_resv_poll;
     83   1.8  riastrad 	struct dma_resv			db_resv_int[];
     84   1.3  riastrad };
     85   1.3  riastrad 
     86   1.3  riastrad struct dma_buf_attachment {
     87   1.3  riastrad 	void				*priv;
     88   1.3  riastrad 	struct dma_buf			*dmabuf;
     89  1.11  riastrad 	bus_dma_tag_t			dev; /* XXX expedient misnomer */
     90  1.12  riastrad 	bool				dynamic_mapping;
     91   1.3  riastrad };
     92   1.3  riastrad 
     93   1.3  riastrad struct dma_buf_export_info {
     94   1.3  riastrad #if 0
     95   1.3  riastrad 	const char			*exp_name;
     96   1.3  riastrad 	struct module			*owner;
     97   1.3  riastrad #endif
     98   1.3  riastrad 	const struct dma_buf_ops	*ops;
     99   1.3  riastrad 	size_t				size;
    100   1.3  riastrad 	int				flags;
    101   1.8  riastrad 	struct dma_resv			*resv;
    102   1.3  riastrad 	void				*priv;
    103   1.3  riastrad };
    104   1.3  riastrad 
    105   1.3  riastrad #define	DEFINE_DMA_BUF_EXPORT_INFO(info)				      \
    106   1.3  riastrad 	struct dma_buf_export_info info = { .priv = NULL }
    107   1.3  riastrad 
    108   1.3  riastrad #define	dma_buf_attach		linux_dma_buf_attach
    109   1.3  riastrad #define	dma_buf_detach		linux_dma_buf_detach
    110  1.12  riastrad #define	dma_buf_dynamic_attach	linux_dma_buf_dynamic_attach
    111   1.3  riastrad #define	dma_buf_export		linux_dma_buf_export
    112   1.3  riastrad #define	dma_buf_fd		linux_dma_buf_fd
    113   1.3  riastrad #define	dma_buf_get		linux_dma_buf_get
    114   1.3  riastrad #define	dma_buf_map_attachment	linux_dma_buf_map_attachment
    115   1.3  riastrad #define	dma_buf_put		linux_dma_buf_put
    116   1.3  riastrad #define	dma_buf_unmap_attachment linux_dma_buf_unmap_attachment
    117   1.3  riastrad #define	get_dma_buf		linux_get_dma_buf
    118   1.3  riastrad 
    119   1.3  riastrad struct dma_buf *
    120   1.3  riastrad 	dma_buf_export(struct dma_buf_export_info *);
    121   1.3  riastrad 
    122   1.3  riastrad int	dma_buf_fd(struct dma_buf *, int);
    123   1.3  riastrad struct dma_buf *
    124   1.3  riastrad 	dma_buf_get(int);
    125   1.3  riastrad void	get_dma_buf(struct dma_buf *);
    126   1.3  riastrad void	dma_buf_put(struct dma_buf *);
    127   1.3  riastrad 
    128   1.3  riastrad struct dma_buf_attachment *
    129  1.11  riastrad 	dma_buf_attach(struct dma_buf *, bus_dma_tag_t);
    130  1.12  riastrad struct dma_buf_attachment *
    131  1.12  riastrad 	dma_buf_dynamic_attach(struct dma_buf *, bus_dma_tag_t, bool);
    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