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