Home | History | Annotate | Line # | Download | only in linux
dma-fence.h revision 1.1
      1  1.1  riastrad /*	$NetBSD: dma-fence.h,v 1.1 2021/12/19 00:27:01 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*-
      4  1.1  riastrad  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5  1.1  riastrad  * All rights reserved.
      6  1.1  riastrad  *
      7  1.1  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  riastrad  * by Taylor R. Campbell.
      9  1.1  riastrad  *
     10  1.1  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.1  riastrad  * modification, are permitted provided that the following conditions
     12  1.1  riastrad  * are met:
     13  1.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.1  riastrad  *
     19  1.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  riastrad  */
     31  1.1  riastrad 
     32  1.1  riastrad #ifndef	_LINUX_FENCE_H_
     33  1.1  riastrad #define	_LINUX_FENCE_H_
     34  1.1  riastrad 
     35  1.1  riastrad #include <sys/types.h>
     36  1.1  riastrad #include <sys/condvar.h>
     37  1.1  riastrad #include <sys/kernel.h>
     38  1.1  riastrad #include <sys/queue.h>
     39  1.1  riastrad 
     40  1.1  riastrad #include <linux/kref.h>
     41  1.1  riastrad #include <linux/rcupdate.h>
     42  1.1  riastrad #include <linux/spinlock.h>
     43  1.1  riastrad 
     44  1.1  riastrad struct fence_cb;
     45  1.1  riastrad 
     46  1.1  riastrad struct fence {
     47  1.1  riastrad 	struct kref		refcount;
     48  1.1  riastrad 	spinlock_t		*lock;
     49  1.1  riastrad 	volatile unsigned long	flags;
     50  1.1  riastrad 	unsigned		context;
     51  1.1  riastrad 	unsigned		seqno;
     52  1.1  riastrad 	const struct fence_ops	*ops;
     53  1.1  riastrad 
     54  1.1  riastrad 	TAILQ_HEAD(, fence_cb)	f_callbacks;
     55  1.1  riastrad 	kcondvar_t		f_cv;
     56  1.1  riastrad 	struct rcu_head		f_rcu;
     57  1.1  riastrad };
     58  1.1  riastrad 
     59  1.1  riastrad #define	FENCE_FLAG_ENABLE_SIGNAL_BIT	0
     60  1.1  riastrad #define	FENCE_FLAG_SIGNALED_BIT		1
     61  1.1  riastrad #define	FENCE_FLAG_USER_BITS		2
     62  1.1  riastrad 
     63  1.1  riastrad struct fence_ops {
     64  1.1  riastrad 	const char	*(*get_driver_name)(struct fence *);
     65  1.1  riastrad 	const char	*(*get_timeline_name)(struct fence *);
     66  1.1  riastrad 	bool		(*enable_signaling)(struct fence *);
     67  1.1  riastrad 	bool		(*signaled)(struct fence *);
     68  1.1  riastrad 	long		(*wait)(struct fence *, bool, long);
     69  1.1  riastrad 	void		(*release)(struct fence *);
     70  1.1  riastrad };
     71  1.1  riastrad 
     72  1.1  riastrad typedef void (*fence_func_t)(struct fence *, struct fence_cb *);
     73  1.1  riastrad 
     74  1.1  riastrad struct fence_cb {
     75  1.1  riastrad 	fence_func_t		fcb_func;
     76  1.1  riastrad 	TAILQ_ENTRY(fence_cb)	fcb_entry;
     77  1.1  riastrad 	bool			fcb_onqueue;
     78  1.1  riastrad };
     79  1.1  riastrad 
     80  1.1  riastrad #define	fence_add_callback	linux_fence_add_callback
     81  1.1  riastrad #define	fence_context_alloc	linux_fence_context_alloc
     82  1.1  riastrad #define	fence_default_wait	linux_fence_default_wait
     83  1.1  riastrad #define	fence_destroy		linux_fence_destroy
     84  1.1  riastrad #define	fence_enable_sw_signaling linux_fence_enable_sw_signaling
     85  1.1  riastrad #define	fence_free		linux_fence_free
     86  1.1  riastrad #define	fence_get		linux_fence_get
     87  1.1  riastrad #define	fence_get_rcu		linux_fence_get_rcu
     88  1.1  riastrad #define	fence_init		linux_fence_init
     89  1.1  riastrad #define	fence_is_later		linux_fence_is_later
     90  1.1  riastrad #define	fence_is_signaled	linux_fence_is_signaled
     91  1.1  riastrad #define	fence_is_signaled_locked linux_fence_is_signaled_locked
     92  1.1  riastrad #define	fence_put		linux_fence_put
     93  1.1  riastrad #define	fence_remove_callback	linux_fence_remove_callback
     94  1.1  riastrad #define	fence_signal		linux_fence_signal
     95  1.1  riastrad #define	fence_signal_locked	linux_fence_signal_locked
     96  1.1  riastrad #define	fence_wait		linux_fence_wait
     97  1.1  riastrad #define	fence_wait_any_timeout	linux_fence_wait_any_timeout
     98  1.1  riastrad #define	fence_wait_timeout	linux_fence_wait_timeout
     99  1.1  riastrad 
    100  1.1  riastrad extern int	linux_fence_trace;
    101  1.1  riastrad 
    102  1.1  riastrad void	fence_init(struct fence *, const struct fence_ops *, spinlock_t *,
    103  1.1  riastrad 	    unsigned, unsigned);
    104  1.1  riastrad void	fence_destroy(struct fence *);
    105  1.1  riastrad void	fence_free(struct fence *);
    106  1.1  riastrad 
    107  1.1  riastrad unsigned
    108  1.1  riastrad 	fence_context_alloc(unsigned);
    109  1.1  riastrad bool	fence_is_later(struct fence *, struct fence *);
    110  1.1  riastrad 
    111  1.1  riastrad struct fence *
    112  1.1  riastrad 	fence_get(struct fence *);
    113  1.1  riastrad struct fence *
    114  1.1  riastrad 	fence_get_rcu(struct fence *);
    115  1.1  riastrad void	fence_put(struct fence *);
    116  1.1  riastrad 
    117  1.1  riastrad int	fence_add_callback(struct fence *, struct fence_cb *, fence_func_t);
    118  1.1  riastrad bool	fence_remove_callback(struct fence *, struct fence_cb *);
    119  1.1  riastrad void	fence_enable_sw_signaling(struct fence *);
    120  1.1  riastrad 
    121  1.1  riastrad bool	fence_is_signaled(struct fence *);
    122  1.1  riastrad bool	fence_is_signaled_locked(struct fence *);
    123  1.1  riastrad int	fence_signal(struct fence *);
    124  1.1  riastrad int	fence_signal_locked(struct fence *);
    125  1.1  riastrad long	fence_default_wait(struct fence *, bool, long);
    126  1.1  riastrad long	fence_wait(struct fence *, bool);
    127  1.1  riastrad long	fence_wait_any_timeout(struct fence **, uint32_t, bool, long);
    128  1.1  riastrad long	fence_wait_timeout(struct fence *, bool, long);
    129  1.1  riastrad 
    130  1.1  riastrad static inline void __printflike(2, 3)
    131  1.1  riastrad FENCE_TRACE(struct fence *f, const char *fmt, ...)
    132  1.1  riastrad {
    133  1.1  riastrad 	va_list va;
    134  1.1  riastrad 
    135  1.1  riastrad 	if (__predict_false(linux_fence_trace)) {
    136  1.1  riastrad 		va_start(va, fmt);
    137  1.1  riastrad 		printf("fence %u@%u: ", f->context, f->seqno);
    138  1.1  riastrad 		vprintf(fmt, va);
    139  1.1  riastrad 		va_end(va);
    140  1.1  riastrad 	}
    141  1.1  riastrad }
    142  1.1  riastrad 
    143  1.1  riastrad #endif	/* _LINUX_FENCE_H_ */
    144