| @@ -1,135 +1,149 @@ | | | @@ -1,135 +1,149 @@ |
1 | /* $NetBSD: drm_wait_netbsd.h,v 1.1.2.5 2013/07/24 02:36:31 riastradh Exp $ */ | | 1 | /* $NetBSD: drm_wait_netbsd.h,v 1.1.2.6 2013/07/24 03:08:03 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 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 | | 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 | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #ifndef _DRM_DRM_WAIT_NETBSD_H_ | | 32 | #ifndef _DRM_DRM_WAIT_NETBSD_H_ |
33 | #define _DRM_DRM_WAIT_NETBSD_H_ | | 33 | #define _DRM_DRM_WAIT_NETBSD_H_ |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/condvar.h> | | 36 | #include <sys/condvar.h> |
37 | #include <sys/kernel.h> | | 37 | #include <sys/kernel.h> |
38 | #include <sys/mutex.h> | | 38 | #include <sys/mutex.h> |
39 | #include <sys/systm.h> | | 39 | #include <sys/systm.h> |
40 | | | 40 | |
41 | #include <linux/mutex.h> | | 41 | #include <linux/mutex.h> |
42 | #include <linux/spinlock.h> | | 42 | #include <linux/spinlock.h> |
43 | | | 43 | |
44 | typedef kcondvar_t drm_waitqueue_t; | | 44 | typedef kcondvar_t drm_waitqueue_t; |
45 | | | 45 | |
46 | #define DRM_HZ hz /* XXX Hurk... */ | | 46 | #define DRM_HZ hz /* XXX Hurk... */ |
47 | | | 47 | |
48 | static inline void | | 48 | static inline void |
49 | DRM_INIT_WAITQUEUE(drm_waitqueue_t *q, const char *name) | | 49 | DRM_INIT_WAITQUEUE(drm_waitqueue_t *q, const char *name) |
50 | { | | 50 | { |
51 | cv_init(q, name); | | 51 | cv_init(q, name); |
52 | } | | 52 | } |
53 | | | 53 | |
54 | static inline void | | 54 | static inline void |
55 | DRM_DESTROY_WAITQUEUE(drm_waitqueue_t *q) | | 55 | DRM_DESTROY_WAITQUEUE(drm_waitqueue_t *q) |
56 | { | | 56 | { |
57 | cv_destroy(q); | | 57 | cv_destroy(q); |
58 | } | | 58 | } |
59 | | | 59 | |
| | | 60 | static inline bool |
| | | 61 | DRM_WAITERS_P(drm_waitqueue_t *q, struct mutex *interlock) |
| | | 62 | { |
| | | 63 | KASSERT(mutex_is_locked(interlock)); |
| | | 64 | return cv_has_waiters(q); |
| | | 65 | } |
| | | 66 | |
60 | static inline void | | 67 | static inline void |
61 | DRM_WAKEUP_ONE(drm_waitqueue_t *q, struct mutex *interlock) | | 68 | DRM_WAKEUP_ONE(drm_waitqueue_t *q, struct mutex *interlock) |
62 | { | | 69 | { |
63 | KASSERT(mutex_is_locked(interlock)); | | 70 | KASSERT(mutex_is_locked(interlock)); |
64 | cv_signal(q); | | 71 | cv_signal(q); |
65 | } | | 72 | } |
66 | | | 73 | |
67 | static inline void | | 74 | static inline void |
68 | DRM_WAKEUP_ALL(drm_waitqueue_t *q, struct mutex *interlock) | | 75 | DRM_WAKEUP_ALL(drm_waitqueue_t *q, struct mutex *interlock) |
69 | { | | 76 | { |
70 | KASSERT(mutex_is_locked(interlock)); | | 77 | KASSERT(mutex_is_locked(interlock)); |
71 | cv_broadcast(q); | | 78 | cv_broadcast(q); |
72 | } | | 79 | } |
73 | | | 80 | |
| | | 81 | static inline bool |
| | | 82 | DRM_SPIN_WAITERS_P(drm_waitqueue_t *q, spinlock_t *interlock) |
| | | 83 | { |
| | | 84 | KASSERT(spin_is_locked(interlock)); |
| | | 85 | return cv_has_waiters(q); |
| | | 86 | } |
| | | 87 | |
74 | static inline void | | 88 | static inline void |
75 | DRM_SPIN_WAKEUP_ONE(drm_waitqueue_t *q, spinlock_t *interlock) | | 89 | DRM_SPIN_WAKEUP_ONE(drm_waitqueue_t *q, spinlock_t *interlock) |
76 | { | | 90 | { |
77 | KASSERT(spin_is_locked(interlock)); | | 91 | KASSERT(spin_is_locked(interlock)); |
78 | cv_signal(q); | | 92 | cv_signal(q); |
79 | } | | 93 | } |
80 | | | 94 | |
81 | static inline void | | 95 | static inline void |
82 | DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, spinlock_t *interlock) | | 96 | DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, spinlock_t *interlock) |
83 | { | | 97 | { |
84 | KASSERT(spin_is_locked(interlock)); | | 98 | KASSERT(spin_is_locked(interlock)); |
85 | cv_broadcast(q); | | 99 | cv_broadcast(q); |
86 | } | | 100 | } |
87 | | | 101 | |
88 | #define DRM_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \ | | 102 | #define DRM_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \ |
89 | { \ | | 103 | { \ |
90 | KASSERT(mutex_is_locked((INTERLOCK))); \ | | 104 | KASSERT(mutex_is_locked((INTERLOCK))); \ |
91 | while (!(CONDITION)) { \ | | 105 | while (!(CONDITION)) { \ |
92 | /* XXX errno NetBSD->Linux */ \ | | 106 | /* XXX errno NetBSD->Linux */ \ |
93 | (RET) = -cv_wait_sig((Q), &(INTERLOCK)->mtx_lock); \ | | 107 | (RET) = -cv_wait_sig((Q), &(INTERLOCK)->mtx_lock); \ |
94 | if (RET) \ | | 108 | if (RET) \ |
95 | break; \ | | 109 | break; \ |
96 | } \ | | 110 | } \ |
97 | } while (0) | | 111 | } while (0) |
98 | | | 112 | |
99 | #define DRM_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) do \ | | 113 | #define DRM_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) do \ |
100 | { \ | | 114 | { \ |
101 | KASSERT(mutex_is_locked((INTERLOCK))); \ | | 115 | KASSERT(mutex_is_locked((INTERLOCK))); \ |
102 | while (!(CONDITION)) { \ | | 116 | while (!(CONDITION)) { \ |
103 | /* XXX errno NetBSD->Linux */ \ | | 117 | /* XXX errno NetBSD->Linux */ \ |
104 | (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->mtx_lock, \ | | 118 | (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->mtx_lock, \ |
105 | (TICKS)); \ | | 119 | (TICKS)); \ |
106 | if (RET) \ | | 120 | if (RET) \ |
107 | break; \ | | 121 | break; \ |
108 | } \ | | 122 | } \ |
109 | } while (0) | | 123 | } while (0) |
110 | | | 124 | |
111 | #define DRM_SPIN_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \ | | 125 | #define DRM_SPIN_WAIT_UNTIL(RET, Q, INTERLOCK, CONDITION) do \ |
112 | { \ | | 126 | { \ |
113 | KASSERT(spin_is_locked((INTERLOCK))); \ | | 127 | KASSERT(spin_is_locked((INTERLOCK))); \ |
114 | while (!(CONDITION)) { \ | | 128 | while (!(CONDITION)) { \ |
115 | /* XXX errno NetBSD->Linux */ \ | | 129 | /* XXX errno NetBSD->Linux */ \ |
116 | (RET) = -cv_wait_sig((Q), &(INTERLOCK)->sl_lock); \ | | 130 | (RET) = -cv_wait_sig((Q), &(INTERLOCK)->sl_lock); \ |
117 | if (RET) \ | | 131 | if (RET) \ |
118 | break; \ | | 132 | break; \ |
119 | } \ | | 133 | } \ |
120 | } while (0) | | 134 | } while (0) |
121 | | | 135 | |
122 | #define DRM_SPIN_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) \ | | 136 | #define DRM_SPIN_TIMED_WAIT_UNTIL(RET, Q, INTERLOCK, TICKS, CONDITION) \ |
123 | do \ | | 137 | do \ |
124 | { \ | | 138 | { \ |
125 | KASSERT(spin_is_locked((INTERLOCK))); \ | | 139 | KASSERT(spin_is_locked((INTERLOCK))); \ |
126 | while (!(CONDITION)) { \ | | 140 | while (!(CONDITION)) { \ |
127 | /* XXX errno NetBSD->Linux */ \ | | 141 | /* XXX errno NetBSD->Linux */ \ |
128 | (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->sl_lock, \ | | 142 | (RET) = -cv_timedwait_sig((Q), &(INTERLOCK)->sl_lock, \ |
129 | (TICKS)); \ | | 143 | (TICKS)); \ |
130 | if (RET) \ | | 144 | if (RET) \ |
131 | break; \ | | 145 | break; \ |
132 | } \ | | 146 | } \ |
133 | } while (0) | | 147 | } while (0) |
134 | | | 148 | |
135 | #endif /* _DRM_DRM_WAIT_NETBSD_H_ */ | | 149 | #endif /* _DRM_DRM_WAIT_NETBSD_H_ */ |