Home | History | Annotate | Line # | Download | only in linux
fence.h revision 1.9
      1  1.1  riastrad /*	$NetBSD: fence.h,v 1.9 2018/08/27 07:47:43 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.7  riastrad #include <sys/types.h>
     36  1.7  riastrad 
     37  1.7  riastrad #include <linux/mutex.h>
     38  1.4  riastrad #include <linux/rcupdate.h>
     39  1.4  riastrad 
     40  1.7  riastrad struct fence_cb;
     41  1.7  riastrad 
     42  1.7  riastrad struct fence {
     43  1.7  riastrad 	struct kref		refcount;
     44  1.7  riastrad 	spinlock_t		*lock;
     45  1.7  riastrad 	unsigned long		flags;
     46  1.7  riastrad 	unsigned		context;
     47  1.7  riastrad 	unsigned		seqno;
     48  1.7  riastrad 	const struct fence_ops	*ops;
     49  1.7  riastrad };
     50  1.7  riastrad 
     51  1.7  riastrad #define	FENCE_FLAG_SIGNALED_BIT	__BIT(0)
     52  1.7  riastrad #define	FENCE_FLAG_USER_BITS	__BIT(1)
     53  1.7  riastrad 
     54  1.2  riastrad struct fence_ops {
     55  1.7  riastrad 	const char	*(*get_driver_name)(struct fence *);
     56  1.7  riastrad 	const char	*(*get_timeline_name)(struct fence *);
     57  1.7  riastrad 	bool		(*enable_signaling)(struct fence *);
     58  1.7  riastrad 	bool		(*signaled)(struct fence *);
     59  1.7  riastrad 	long		(*wait)(struct fence *, bool, long);
     60  1.7  riastrad 	void		(*release)(struct fence *);
     61  1.2  riastrad };
     62  1.2  riastrad 
     63  1.7  riastrad typedef void (*fence_func_t)(struct fence *, struct fence_cb *);
     64  1.7  riastrad 
     65  1.7  riastrad struct fence_cb {
     66  1.7  riastrad 	fence_func_t	fcb_func;
     67  1.2  riastrad };
     68  1.2  riastrad 
     69  1.7  riastrad #define	fence_add_callback	linux_fence_add_callback
     70  1.7  riastrad #define	fence_context_alloc	linux_fence_context_alloc
     71  1.6  riastrad #define	fence_get		linux_fence_get
     72  1.7  riastrad #define	fence_init		linux_fence_init
     73  1.3  riastrad #define	fence_put		linux_fence_put
     74  1.7  riastrad #define	fence_remove_callback	linux_fence_remove_callback
     75  1.9  riastrad #define	fence_signal		linux_fence_signal
     76  1.7  riastrad #define	fence_signal_locked	linux_fence_signal_locked
     77  1.3  riastrad #define	fence_wait		linux_fence_wait
     78  1.7  riastrad #define	fence_wait_timeout	linux_fence_wait_timeout
     79  1.7  riastrad 
     80  1.7  riastrad void	fence_init(struct fence *, const struct fence_ops *, spinlock_t *,
     81  1.7  riastrad 	    unsigned, unsigned);
     82  1.7  riastrad void	fence_free(struct fence *);
     83  1.7  riastrad 
     84  1.7  riastrad unsigned
     85  1.7  riastrad 	fence_context_alloc(unsigned);
     86  1.3  riastrad 
     87  1.5  riastrad struct fence *
     88  1.5  riastrad 	fence_get(struct fence *);
     89  1.3  riastrad void	fence_put(struct fence *);
     90  1.2  riastrad 
     91  1.7  riastrad int	fence_add_callback(struct fence *, struct fence_cb *, fence_func_t);
     92  1.7  riastrad bool	fence_remove_callback(struct fence *, struct fence_cb *);
     93  1.7  riastrad 
     94  1.7  riastrad bool	fence_is_signaled(struct fence *);
     95  1.7  riastrad bool	fence_is_signaled_locked(struct fence *);
     96  1.9  riastrad int	fence_signal(struct fence *);
     97  1.7  riastrad int	fence_signal_locked(struct fence *);
     98  1.7  riastrad long	fence_default_wait(struct fence *, bool, long);
     99  1.7  riastrad long	fence_wait(struct fence *, bool);
    100  1.7  riastrad long	fence_wait_timeout(struct fence *, bool, int);
    101  1.7  riastrad 
    102  1.8  riastrad static inline void
    103  1.8  riastrad FENCE_TRACE(struct fence *f, const char *fmt, ...)
    104  1.8  riastrad {
    105  1.8  riastrad 	va_list va;
    106  1.8  riastrad 
    107  1.8  riastrad 	va_start(va, fmt);
    108  1.8  riastrad 	printf("fence %u@%u: ", f->context, f->seqno);
    109  1.8  riastrad 	vprintf(fmt, va);
    110  1.8  riastrad 	va_end(va);
    111  1.8  riastrad }
    112  1.8  riastrad 
    113  1.1  riastrad #endif	/* _LINUX_FENCE_H_ */
    114