drm_wait_netbsd.h revision 1.1.2.5 1 /* $NetBSD: drm_wait_netbsd.h,v 1.1.2.5 2013/07/24 02:36:31 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2013 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 _DRM_DRM_WAIT_NETBSD_H_
33 #define _DRM_DRM_WAIT_NETBSD_H_
34
35 #include <sys/param.h>
36 #include <sys/condvar.h>
37 #include <sys/kernel.h>
38 #include <sys/mutex.h>
39 #include <sys/systm.h>
40
41 #include <linux/mutex.h>
42 #include <linux/spinlock.h>
43
44 typedef kcondvar_t drm_waitqueue_t;
45
46 #define DRM_HZ hz /* XXX Hurk... */
47
48 static inline void
49 DRM_INIT_WAITQUEUE(drm_waitqueue_t *q, const char *name)
50 {
51 cv_init(q, name);
52 }
53
54 static inline void
55 DRM_DESTROY_WAITQUEUE(drm_waitqueue_t *q)
56 {
57 cv_destroy(q);
58 }
59
60 static inline void
61 DRM_WAKEUP_ONE(drm_waitqueue_t *q, struct mutex *interlock)
62 {
63 KASSERT(mutex_is_locked(interlock));
64 cv_signal(q);
65 }
66
67 static inline void
68 DRM_WAKEUP_ALL(drm_waitqueue_t *q, struct mutex *interlock)
69 {
70 KASSERT(mutex_is_locked(interlock));
71 cv_broadcast(q);
72 }
73
74 static inline void
75 DRM_SPIN_WAKEUP_ONE(drm_waitqueue_t *q, spinlock_t *interlock)
76 {
77 KASSERT(spin_is_locked(interlock));
78 cv_signal(q);
79 }
80
81 static inline void
82 DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, spinlock_t *interlock)
83 {
84 KASSERT(spin_is_locked(interlock));
85 cv_broadcast(q);
86 }
87
88 #define DRM_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \
89 { \
90 KASSERT(mutex_is_locked((INTERLOCK))); \
91 while (!(CONDITION)) { \
92 /* XXX errno NetBSD->Linux */ \
93 (RET) = -cv_wait_sig((Q), &(INTERLOCK)->mtx_lock); \
94 if (RET) \
95 break; \
96 } \
97 } while (0)
98
99 #define DRM_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) do \
100 { \
101 KASSERT(mutex_is_locked((INTERLOCK))); \
102 while (!(CONDITION)) { \
103 /* XXX errno NetBSD->Linux */ \
104 (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->mtx_lock, \
105 (TICKS)); \
106 if (RET) \
107 break; \
108 } \
109 } while (0)
110
111 #define DRM_SPIN_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \
112 { \
113 KASSERT(spin_is_locked((INTERLOCK))); \
114 while (!(CONDITION)) { \
115 /* XXX errno NetBSD->Linux */ \
116 (RET) = -cv_wait_sig((Q), &(INTERLOCK)->sl_lock); \
117 if (RET) \
118 break; \
119 } \
120 } while (0)
121
122 #define DRM_SPIN_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) \
123 do \
124 { \
125 KASSERT(spin_is_locked((INTERLOCK))); \
126 while (!(CONDITION)) { \
127 /* XXX errno NetBSD->Linux */ \
128 (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->sl_lock, \
129 (TICKS)); \
130 if (RET) \
131 break; \
132 } \
133 } while (0)
134
135 #endif /* _DRM_DRM_WAIT_NETBSD_H_ */
136