Home | History | Annotate | Line # | Download | only in linux
fence.h revision 1.10
      1   1.1  riastrad /*	$NetBSD: fence.h,v 1.10 2018/08/27 07:53:05 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.10  riastrad #define	fence_enable_sw_signaling linux_fence_enable_sw_signaling
     72   1.6  riastrad #define	fence_get		linux_fence_get
     73   1.7  riastrad #define	fence_init		linux_fence_init
     74   1.3  riastrad #define	fence_put		linux_fence_put
     75   1.7  riastrad #define	fence_remove_callback	linux_fence_remove_callback
     76   1.9  riastrad #define	fence_signal		linux_fence_signal
     77   1.7  riastrad #define	fence_signal_locked	linux_fence_signal_locked
     78   1.3  riastrad #define	fence_wait		linux_fence_wait
     79   1.7  riastrad #define	fence_wait_timeout	linux_fence_wait_timeout
     80   1.7  riastrad 
     81   1.7  riastrad void	fence_init(struct fence *, const struct fence_ops *, spinlock_t *,
     82   1.7  riastrad 	    unsigned, unsigned);
     83   1.7  riastrad void	fence_free(struct fence *);
     84   1.7  riastrad 
     85   1.7  riastrad unsigned
     86   1.7  riastrad 	fence_context_alloc(unsigned);
     87   1.3  riastrad 
     88   1.5  riastrad struct fence *
     89   1.5  riastrad 	fence_get(struct fence *);
     90   1.3  riastrad void	fence_put(struct fence *);
     91   1.2  riastrad 
     92   1.7  riastrad int	fence_add_callback(struct fence *, struct fence_cb *, fence_func_t);
     93   1.7  riastrad bool	fence_remove_callback(struct fence *, struct fence_cb *);
     94  1.10  riastrad void	fence_enable_sw_signaling(struct fence *);
     95   1.7  riastrad 
     96   1.7  riastrad bool	fence_is_signaled(struct fence *);
     97   1.7  riastrad bool	fence_is_signaled_locked(struct fence *);
     98   1.9  riastrad int	fence_signal(struct fence *);
     99   1.7  riastrad int	fence_signal_locked(struct fence *);
    100   1.7  riastrad long	fence_default_wait(struct fence *, bool, long);
    101   1.7  riastrad long	fence_wait(struct fence *, bool);
    102   1.7  riastrad long	fence_wait_timeout(struct fence *, bool, int);
    103   1.7  riastrad 
    104   1.8  riastrad static inline void
    105   1.8  riastrad FENCE_TRACE(struct fence *f, const char *fmt, ...)
    106   1.8  riastrad {
    107   1.8  riastrad 	va_list va;
    108   1.8  riastrad 
    109   1.8  riastrad 	va_start(va, fmt);
    110   1.8  riastrad 	printf("fence %u@%u: ", f->context, f->seqno);
    111   1.8  riastrad 	vprintf(fmt, va);
    112   1.8  riastrad 	va_end(va);
    113   1.8  riastrad }
    114   1.8  riastrad 
    115   1.1  riastrad #endif	/* _LINUX_FENCE_H_ */
    116