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