drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / vmwgfx / vmwgfx_irq.c
blob0c7e1723292c0db7a200ff1b7fd3f3f7c580c9a4
1 /**************************************************************************
3 * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
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:
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.
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.
26 **************************************************************************/
28 #include <drm/drmP.h>
29 #include "vmwgfx_drv.h"
31 #define VMW_FENCE_WRAP (1 << 24)
33 irqreturn_t vmw_irq_handler(int irq, void *arg)
35 struct drm_device *dev = (struct drm_device *)arg;
36 struct vmw_private *dev_priv = vmw_priv(dev);
37 uint32_t status, masked_status;
39 status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
40 masked_status = status & READ_ONCE(dev_priv->irq_mask);
42 if (likely(status))
43 outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
45 if (!status)
46 return IRQ_NONE;
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);
54 if (masked_status & SVGA_IRQFLAG_FIFO_PROGRESS)
55 wake_up_all(&dev_priv->fifo_queue);
57 if (masked_status & (SVGA_IRQFLAG_COMMAND_BUFFER |
58 SVGA_IRQFLAG_ERROR))
59 vmw_cmdbuf_tasklet_schedule(dev_priv->cman);
61 return IRQ_HANDLED;
64 static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t seqno)
67 return (vmw_read(dev_priv, SVGA_REG_BUSY) == 0);
70 void vmw_update_seqno(struct vmw_private *dev_priv,
71 struct vmw_fifo_state *fifo_state)
73 u32 *fifo_mem = dev_priv->mmio_virt;
74 uint32_t seqno = vmw_mmio_read(fifo_mem + SVGA_FIFO_FENCE);
76 if (dev_priv->last_read_seqno != seqno) {
77 dev_priv->last_read_seqno = seqno;
78 vmw_marker_pull(&fifo_state->marker_queue, seqno);
79 vmw_fences_update(dev_priv->fman);
83 bool vmw_seqno_passed(struct vmw_private *dev_priv,
84 uint32_t seqno)
86 struct vmw_fifo_state *fifo_state;
87 bool ret;
89 if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
90 return true;
92 fifo_state = &dev_priv->fifo;
93 vmw_update_seqno(dev_priv, fifo_state);
94 if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
95 return true;
97 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE) &&
98 vmw_fifo_idle(dev_priv, seqno))
99 return true;
102 * Then check if the seqno is higher than what we've actually
103 * emitted. Then the fence is stale and signaled.
106 ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
107 > VMW_FENCE_WRAP);
109 return ret;
112 int vmw_fallback_wait(struct vmw_private *dev_priv,
113 bool lazy,
114 bool fifo_idle,
115 uint32_t seqno,
116 bool interruptible,
117 unsigned long timeout)
119 struct vmw_fifo_state *fifo_state = &dev_priv->fifo;
121 uint32_t count = 0;
122 uint32_t signal_seq;
123 int ret;
124 unsigned long end_jiffies = jiffies + timeout;
125 bool (*wait_condition)(struct vmw_private *, uint32_t);
126 DEFINE_WAIT(__wait);
128 wait_condition = (fifo_idle) ? &vmw_fifo_idle :
129 &vmw_seqno_passed;
132 * Block command submission while waiting for idle.
135 if (fifo_idle) {
136 down_read(&fifo_state->rwsem);
137 if (dev_priv->cman) {
138 ret = vmw_cmdbuf_idle(dev_priv->cman, interruptible,
139 10*HZ);
140 if (ret)
141 goto out_err;
145 signal_seq = atomic_read(&dev_priv->marker_seq);
146 ret = 0;
148 for (;;) {
149 prepare_to_wait(&dev_priv->fence_queue, &__wait,
150 (interruptible) ?
151 TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
152 if (wait_condition(dev_priv, seqno))
153 break;
154 if (time_after_eq(jiffies, end_jiffies)) {
155 DRM_ERROR("SVGA device lockup.\n");
156 break;
158 if (lazy)
159 schedule_timeout(1);
160 else if ((++count & 0x0F) == 0) {
162 * FIXME: Use schedule_hr_timeout here for
163 * newer kernels and lower CPU utilization.
166 __set_current_state(TASK_RUNNING);
167 schedule();
168 __set_current_state((interruptible) ?
169 TASK_INTERRUPTIBLE :
170 TASK_UNINTERRUPTIBLE);
172 if (interruptible && signal_pending(current)) {
173 ret = -ERESTARTSYS;
174 break;
177 finish_wait(&dev_priv->fence_queue, &__wait);
178 if (ret == 0 && fifo_idle) {
179 u32 *fifo_mem = dev_priv->mmio_virt;
181 vmw_mmio_write(signal_seq, fifo_mem + SVGA_FIFO_FENCE);
183 wake_up_all(&dev_priv->fence_queue);
184 out_err:
185 if (fifo_idle)
186 up_read(&fifo_state->rwsem);
188 return ret;
191 void vmw_generic_waiter_add(struct vmw_private *dev_priv,
192 u32 flag, int *waiter_count)
194 spin_lock_bh(&dev_priv->waiter_lock);
195 if ((*waiter_count)++ == 0) {
196 outl(flag, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
197 dev_priv->irq_mask |= flag;
198 vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask);
200 spin_unlock_bh(&dev_priv->waiter_lock);
203 void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
204 u32 flag, int *waiter_count)
206 spin_lock_bh(&dev_priv->waiter_lock);
207 if (--(*waiter_count) == 0) {
208 dev_priv->irq_mask &= ~flag;
209 vmw_write(dev_priv, SVGA_REG_IRQMASK, dev_priv->irq_mask);
211 spin_unlock_bh(&dev_priv->waiter_lock);
214 void vmw_seqno_waiter_add(struct vmw_private *dev_priv)
216 vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_ANY_FENCE,
217 &dev_priv->fence_queue_waiters);
220 void vmw_seqno_waiter_remove(struct vmw_private *dev_priv)
222 vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_ANY_FENCE,
223 &dev_priv->fence_queue_waiters);
226 void vmw_goal_waiter_add(struct vmw_private *dev_priv)
228 vmw_generic_waiter_add(dev_priv, SVGA_IRQFLAG_FENCE_GOAL,
229 &dev_priv->goal_queue_waiters);
232 void vmw_goal_waiter_remove(struct vmw_private *dev_priv)
234 vmw_generic_waiter_remove(dev_priv, SVGA_IRQFLAG_FENCE_GOAL,
235 &dev_priv->goal_queue_waiters);
238 int vmw_wait_seqno(struct vmw_private *dev_priv,
239 bool lazy, uint32_t seqno,
240 bool interruptible, unsigned long timeout)
242 long ret;
243 struct vmw_fifo_state *fifo = &dev_priv->fifo;
245 if (likely(dev_priv->last_read_seqno - seqno < VMW_FENCE_WRAP))
246 return 0;
248 if (likely(vmw_seqno_passed(dev_priv, seqno)))
249 return 0;
251 vmw_fifo_ping_host(dev_priv, SVGA_SYNC_GENERIC);
253 if (!(fifo->capabilities & SVGA_FIFO_CAP_FENCE))
254 return vmw_fallback_wait(dev_priv, lazy, true, seqno,
255 interruptible, timeout);
257 if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK))
258 return vmw_fallback_wait(dev_priv, lazy, false, seqno,
259 interruptible, timeout);
261 vmw_seqno_waiter_add(dev_priv);
263 if (interruptible)
264 ret = wait_event_interruptible_timeout
265 (dev_priv->fence_queue,
266 vmw_seqno_passed(dev_priv, seqno),
267 timeout);
268 else
269 ret = wait_event_timeout
270 (dev_priv->fence_queue,
271 vmw_seqno_passed(dev_priv, seqno),
272 timeout);
274 vmw_seqno_waiter_remove(dev_priv);
276 if (unlikely(ret == 0))
277 ret = -EBUSY;
278 else if (likely(ret > 0))
279 ret = 0;
281 return ret;
284 void vmw_irq_preinstall(struct drm_device *dev)
286 struct vmw_private *dev_priv = vmw_priv(dev);
287 uint32_t status;
289 if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK))
290 return;
292 status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
293 outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
296 int vmw_irq_postinstall(struct drm_device *dev)
298 return 0;
301 void vmw_irq_uninstall(struct drm_device *dev)
303 struct vmw_private *dev_priv = vmw_priv(dev);
304 uint32_t status;
306 if (!(dev_priv->capabilities & SVGA_CAP_IRQMASK))
307 return;
309 vmw_write(dev_priv, SVGA_REG_IRQMASK, 0);
311 status = inl(dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);
312 outl(status, dev_priv->io_start + VMWGFX_IRQSTATUS_PORT);