Rev 5078 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4075 | Serge | 1 | /************************************************************************** |
2 | * |
||
6296 | serge | 3 | * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA |
4075 | Serge | 4 | * All Rights Reserved. |
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the |
||
8 | * "Software"), to deal in the Software without restriction, including |
||
9 | * without limitation the rights to use, copy, modify, merge, publish, |
||
10 | * distribute, sub license, and/or sell copies of the Software, and to |
||
11 | * permit persons to whom the Software is furnished to do so, subject to |
||
12 | * the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
||
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | #include |
||
29 | #include "vmwgfx_drv.h" |
||
30 | |||
31 | #define VMW_FENCE_WRAP (1 << 24) |
||
32 | |||
4569 | Serge | 33 | irqreturn_t vmw_irq_handler(int irq, void *arg) |
4075 | Serge | 34 | { |
35 | struct drm_device *dev = (struct drm_device *)arg; |
||
36 | struct vmw_private *dev_priv = vmw_priv(dev); |
||
37 | uint32_t status, masked_status; |
||
38 | |||
39 | status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
6296 | serge | 40 | masked_status = status & READ_ONCE(dev_priv->irq_mask); |
4075 | Serge | 41 | |
42 | if (likely(status)) |
||
43 | outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
44 | |||
6296 | serge | 45 | if (!status) |
4075 | Serge | 46 | return IRQ_NONE; |
47 | |||
48 | if (masked_status & (SVGA_IRQFLAG_ANY_FENCE | |
||
49 | SVGA_IRQFLAG_FENCE_GOAL)) { |
||
50 | vmw_fences_update(dev_priv->fman); |
||
51 | wake_up_all(&dev_priv->fence_queue); |
||
52 | } |
||
53 | |||
54 | if (masked_status & SVGA_IRQFLAG_FIFO_PROGRESS) |
||
55 | wake_up_all(&dev_priv->fifo_queue); |
||
56 | |||
57 | |||
58 | return IRQ_HANDLED; |
||
59 | } |
||
60 | |||
61 | static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno) |
||
62 | { |
||
63 | |||
6296 | serge | 64 | return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0); |
4075 | Serge | 65 | } |
66 | |||
67 | void vmw_update_seqno(struct vmw_private *dev_priv, |
||
68 | struct vmw_fifo_state *fifo_state) |
||
69 | { |
||
6296 | serge | 70 | u32 *fifo_mem = dev_priv->mmio_virt; |
71 | uint32_t seqno = vmw_mmio_read(fifo_mem + SVGA_FIFO_FENCE); |
||
4075 | Serge | 72 | |
73 | if (dev_priv->last_read_seqno != seqno) { |
||
74 | dev_priv->last_read_seqno = seqno; |
||
75 | vmw_marker_pull(&fifo_state->marker_queue, seqno); |
||
76 | vmw_fences_update(dev_priv->fman); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | bool vmw_seqno_passed(struct vmw_private *dev_priv, |
||
81 | uint32_t seqno) |
||
82 | { |
||
83 | struct vmw_fifo_state *fifo_state; |
||
84 | bool ret; |
||
85 | |||
86 | if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP)) |
||
87 | return true; |
||
88 | |||
89 | fifo_state = &dev_priv->fifo; |
||
90 | vmw_update_seqno(dev_priv, fifo_state); |
||
91 | if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP)) |
||
92 | return true; |
||
93 | |||
94 | if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE) && |
||
95 | vmw_fifo_idle(dev_priv, seqno)) |
||
96 | return true; |
||
97 | |||
98 | /** |
||
99 | * Then check if the seqno is higher than what we've actually |
||
100 | * emitted. Then the fence is stale and signaled. |
||
101 | */ |
||
102 | |||
103 | ret = ((atomic_read(&dev_priv->marker_seq) - seqno) |
||
104 | > VMW_FENCE_WRAP); |
||
105 | |||
106 | return ret; |
||
107 | } |
||
108 | |||
109 | int vmw_fallback_wait(struct vmw_private *dev_priv, |
||
110 | bool lazy, |
||
111 | bool fifo_idle, |
||
112 | uint32_t seqno, |
||
113 | bool interruptible, |
||
114 | unsigned long timeout) |
||
115 | { |
||
116 | struct vmw_fifo_state *fifo_state = &dev_priv->fifo; |
||
117 | |||
118 | uint32_t count = 0; |
||
119 | uint32_t signal_seq; |
||
120 | int ret; |
||
5078 | serge | 121 | unsigned long end_jiffies = jiffies + timeout; |
4075 | Serge | 122 | bool (*wait_condition)(struct vmw_private *, uint32_t); |
123 | DEFINE_WAIT(__wait); |
||
124 | |||
125 | wait_condition = (fifo_idle) ? &vmw_fifo_idle : |
||
126 | &vmw_seqno_passed; |
||
127 | |||
128 | /** |
||
129 | * Block command submission while waiting for idle. |
||
130 | */ |
||
131 | |||
132 | // if (fifo_idle) |
||
133 | // down_read(&fifo_state->rwsem); |
||
134 | signal_seq = atomic_read(&dev_priv->marker_seq); |
||
135 | ret = 0; |
||
136 | |||
137 | for (;;) { |
||
138 | // prepare_to_wait(&dev_priv->fence_queue, &__wait, |
||
139 | // (interruptible) ? |
||
140 | // TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); |
||
141 | if (wait_condition(dev_priv, seqno)) |
||
142 | break; |
||
5078 | serge | 143 | if (time_after_eq(jiffies, end_jiffies)) { |
4075 | Serge | 144 | DRM_ERROR("SVGA device lockup.\n"); |
145 | break; |
||
146 | } |
||
147 | if (lazy) |
||
148 | delay(1); |
||
149 | else if ((++count & 0x0F) == 0) { |
||
150 | /** |
||
151 | * FIXME: Use schedule_hr_timeout here for |
||
152 | * newer kernels and lower CPU utilization. |
||
153 | */ |
||
154 | |||
155 | delay(1); |
||
156 | } |
||
157 | } |
||
158 | // finish_wait(&dev_priv->fence_queue, &__wait); |
||
159 | if (ret == 0 && fifo_idle) { |
||
6296 | serge | 160 | u32 *fifo_mem = dev_priv->mmio_virt; |
161 | |||
162 | vmw_mmio_write(signal_seq, fifo_mem + SVGA_FIFO_FENCE); |
||
4075 | Serge | 163 | } |
164 | wake_up_all(&dev_priv->fence_queue); |
||
165 | // if (fifo_idle) |
||
166 | // up_read(&fifo_state->rwsem); |
||
167 | |||
168 | return ret; |
||
169 | } |
||
170 | |||
6296 | serge | 171 | void vmw_generic_waiter_add(struct vmw_private *dev_priv, |
172 | u32 flag, int *waiter_count) |
||
4075 | Serge | 173 | { |
6296 | serge | 174 | spin_lock(&dev_priv->waiter_lock); |
175 | if ((*waiter_count)++ == 0) { |
||
176 | outl(flag, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
177 | dev_priv->irq_mask |= flag; |
||
4075 | Serge | 178 | vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); |
179 | } |
||
6296 | serge | 180 | spin_unlock(&dev_priv->waiter_lock); |
4075 | Serge | 181 | } |
182 | |||
6296 | serge | 183 | void vmw_generic_waiter_remove(struct vmw_private *dev_priv, |
184 | u32 flag, int *waiter_count) |
||
4075 | Serge | 185 | { |
6296 | serge | 186 | spin_lock(&dev_priv->waiter_lock); |
187 | if (--(*waiter_count) == 0) { |
||
188 | dev_priv->irq_mask &= ~flag; |
||
4075 | Serge | 189 | vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask); |
190 | } |
||
6296 | serge | 191 | spin_unlock(&dev_priv->waiter_lock); |
4075 | Serge | 192 | } |
193 | |||
6296 | serge | 194 | void vmw_seqno_waiter_add(struct vmw_private *dev_priv) |
195 | { |
||
196 | vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_ANY_FENCE, |
||
197 | &dev_priv->fence_queue_waiters); |
||
198 | } |
||
4075 | Serge | 199 | |
6296 | serge | 200 | void vmw_seqno_waiter_remove(struct vmw_private *dev_priv) |
201 | { |
||
202 | vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_ANY_FENCE, |
||
203 | &dev_priv->fence_queue_waiters); |
||
204 | } |
||
205 | |||
4075 | Serge | 206 | void vmw_goal_waiter_add(struct vmw_private *dev_priv) |
207 | { |
||
6296 | serge | 208 | vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_FENCE_GOAL, |
209 | &dev_priv->goal_queue_waiters); |
||
4075 | Serge | 210 | } |
211 | |||
212 | void vmw_goal_waiter_remove(struct vmw_private *dev_priv) |
||
213 | { |
||
6296 | serge | 214 | vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_FENCE_GOAL, |
215 | &dev_priv->goal_queue_waiters); |
||
4075 | Serge | 216 | } |
217 | |||
218 | int vmw_wait_seqno(struct vmw_private *dev_priv, |
||
219 | bool lazy, uint32_t seqno, |
||
220 | bool interruptible, unsigned long timeout) |
||
221 | { |
||
222 | long ret; |
||
223 | struct vmw_fifo_state *fifo = &dev_priv->fifo; |
||
224 | |||
225 | if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP)) |
||
226 | return 0; |
||
227 | |||
228 | if (likely(vmw_seqno_passed(dev_priv, seqno))) |
||
229 | return 0; |
||
230 | |||
231 | vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC); |
||
232 | |||
233 | if (!(fifo->capabilities & SVGA_FIFO_CAP_FENCE)) |
||
234 | return vmw_fallback_wait(dev_priv, lazy, true, seqno, |
||
235 | interruptible, timeout); |
||
236 | |||
237 | if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK)) |
||
238 | return vmw_fallback_wait(dev_priv, lazy, false, seqno, |
||
239 | interruptible, timeout); |
||
240 | |||
241 | vmw_seqno_waiter_add(dev_priv); |
||
242 | |||
243 | if (interruptible) |
||
244 | ret = wait_event_interruptible_timeout |
||
245 | (dev_priv->fence_queue, |
||
246 | vmw_seqno_passed(dev_priv, seqno), |
||
247 | timeout); |
||
248 | else |
||
249 | ret = wait_event_timeout |
||
250 | (dev_priv->fence_queue, |
||
251 | vmw_seqno_passed(dev_priv, seqno), |
||
252 | timeout); |
||
253 | |||
254 | vmw_seqno_waiter_remove(dev_priv); |
||
255 | |||
256 | if (unlikely(ret == 0)) |
||
257 | ret = -EBUSY; |
||
258 | else if (likely(ret > 0)) |
||
259 | ret = 0; |
||
260 | |||
261 | return ret; |
||
262 | } |
||
263 | |||
264 | void vmw_irq_preinstall(struct drm_device *dev) |
||
265 | { |
||
266 | struct vmw_private *dev_priv = vmw_priv(dev); |
||
267 | uint32_t status; |
||
268 | |||
269 | if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK)) |
||
270 | return; |
||
271 | |||
272 | status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
273 | outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
274 | } |
||
275 | |||
276 | int vmw_irq_postinstall(struct drm_device *dev) |
||
277 | { |
||
278 | return 0; |
||
279 | } |
||
280 | |||
281 | void vmw_irq_uninstall(struct drm_device *dev) |
||
282 | { |
||
283 | struct vmw_private *dev_priv = vmw_priv(dev); |
||
284 | uint32_t status; |
||
285 | |||
286 | if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK)) |
||
287 | return; |
||
288 | |||
289 | vmw_write(dev_priv, SVGA_REG_IRQMASK, 0); |
||
290 | |||
291 | status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
292 | outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT); |
||
293 | }>>>><> |