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