blob: 73fe20ef1d10cb7e4cae53d340eb920e486151f3 [file] [log] [blame]
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +02001/**************************************************************************
2 *
Sinclair Yehc8261a92015-06-26 01:23:42 -07003 * Copyright © 2011-2014 VMware, Inc., Palo Alto, CA., USA
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +02004 * 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 "vmwgfx_kms.h"
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010029#include <drm/drm_plane_helper.h>
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020030
31
32#define vmw_crtc_to_sou(x) \
33 container_of(x, struct vmw_screen_object_unit, base.crtc)
34#define vmw_encoder_to_sou(x) \
35 container_of(x, struct vmw_screen_object_unit, base.encoder)
36#define vmw_connector_to_sou(x) \
37 container_of(x, struct vmw_screen_object_unit, base.connector)
38
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -070039/**
40 * struct vmw_kms_sou_surface_dirty - Closure structure for
41 * blit surface to screen command.
42 * @base: The base type we derive from. Used by vmw_kms_helper_dirty().
43 * @left: Left side of bounding box.
44 * @right: Right side of bounding box.
45 * @top: Top side of bounding box.
46 * @bottom: Bottom side of bounding box.
47 * @dst_x: Difference between source clip rects and framebuffer coordinates.
48 * @dst_y: Difference between source clip rects and framebuffer coordinates.
49 * @sid: Surface id of surface to copy from.
50 */
51struct vmw_kms_sou_surface_dirty {
52 struct vmw_kms_dirty base;
53 s32 left, right, top, bottom;
54 s32 dst_x, dst_y;
55 u32 sid;
56};
57
58/*
59 * SVGA commands that are used by this code. Please see the device headers
60 * for explanation.
61 */
62struct vmw_kms_sou_readback_blit {
63 uint32 header;
64 SVGAFifoCmdBlitScreenToGMRFB body;
65};
66
67struct vmw_kms_sou_dmabuf_blit {
68 uint32 header;
69 SVGAFifoCmdBlitGMRFBToScreen body;
70};
71
72struct vmw_kms_sou_dirty_cmd {
73 SVGA3dCmdHeader header;
74 SVGA3dCmdBlitSurfaceToScreen body;
75};
76
77
78/*
79 * Other structs.
80 */
81
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020082struct vmw_screen_object_display {
Thomas Hellstrom69874272011-11-02 09:43:11 +010083 unsigned num_implicit;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020084
Thomas Hellstrom69874272011-11-02 09:43:11 +010085 struct vmw_framebuffer *implicit_fb;
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -070086 SVGAFifoCmdDefineGMRFB cur;
87 struct vmw_dma_buffer *pinned_gmrfb;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020088};
89
90/**
91 * Display unit using screen objects.
92 */
93struct vmw_screen_object_unit {
94 struct vmw_display_unit base;
95
96 unsigned long buffer_size; /**< Size of allocated buffer */
97 struct vmw_dma_buffer *buffer; /**< Backing store buffer */
98
99 bool defined;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100100 bool active_implicit;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200101};
102
103static void vmw_sou_destroy(struct vmw_screen_object_unit *sou)
104{
Sinclair Yehc8261a92015-06-26 01:23:42 -0700105 vmw_du_cleanup(&sou->base);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200106 kfree(sou);
107}
108
109
110/*
111 * Screen Object Display Unit CRTC functions
112 */
113
114static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)
115{
116 vmw_sou_destroy(vmw_crtc_to_sou(crtc));
117}
118
Thomas Hellstrom0e708bc2011-11-02 09:43:09 +0100119static void vmw_sou_del_active(struct vmw_private *vmw_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700120 struct vmw_screen_object_unit *sou)
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200121{
122 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200123
Thomas Hellstrom69874272011-11-02 09:43:11 +0100124 if (sou->active_implicit) {
125 if (--(ld->num_implicit) == 0)
126 ld->implicit_fb = NULL;
127 sou->active_implicit = false;
Thomas Hellstrom0e708bc2011-11-02 09:43:09 +0100128 }
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200129}
130
Thomas Hellstrom0e708bc2011-11-02 09:43:09 +0100131static void vmw_sou_add_active(struct vmw_private *vmw_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700132 struct vmw_screen_object_unit *sou,
133 struct vmw_framebuffer *vfb)
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200134{
135 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200136
Thomas Hellstrom69874272011-11-02 09:43:11 +0100137 BUG_ON(!ld->num_implicit && ld->implicit_fb);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200138
Thomas Hellstrom69874272011-11-02 09:43:11 +0100139 if (!sou->active_implicit && sou->base.is_implicit) {
140 ld->implicit_fb = vfb;
141 sou->active_implicit = true;
142 ld->num_implicit++;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200143 }
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200144}
145
146/**
147 * Send the fifo command to create a screen.
148 */
149static int vmw_sou_fifo_create(struct vmw_private *dev_priv,
150 struct vmw_screen_object_unit *sou,
151 uint32_t x, uint32_t y,
152 struct drm_display_mode *mode)
153{
154 size_t fifo_size;
155
156 struct {
157 struct {
158 uint32_t cmdType;
159 } header;
160 SVGAScreenObject obj;
161 } *cmd;
162
163 BUG_ON(!sou->buffer);
164
165 fifo_size = sizeof(*cmd);
166 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
167 /* The hardware has hung, nothing we can do about it here. */
168 if (unlikely(cmd == NULL)) {
169 DRM_ERROR("Fifo reserve failed.\n");
170 return -ENOMEM;
171 }
172
173 memset(cmd, 0, fifo_size);
174 cmd->header.cmdType = SVGA_CMD_DEFINE_SCREEN;
175 cmd->obj.structSize = sizeof(SVGAScreenObject);
176 cmd->obj.id = sou->base.unit;
177 cmd->obj.flags = SVGA_SCREEN_HAS_ROOT |
178 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0);
179 cmd->obj.size.width = mode->hdisplay;
180 cmd->obj.size.height = mode->vdisplay;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100181 if (sou->base.is_implicit) {
182 cmd->obj.root.x = x;
183 cmd->obj.root.y = y;
184 } else {
185 cmd->obj.root.x = sou->base.gui_x;
186 cmd->obj.root.y = sou->base.gui_y;
187 }
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200188
189 /* Ok to assume that buffer is pinned in vram */
Thomas Hellstromb37a6b92011-10-04 20:13:28 +0200190 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200191 cmd->obj.backingStore.pitch = mode->hdisplay * 4;
192
193 vmw_fifo_commit(dev_priv, fifo_size);
194
195 sou->defined = true;
196
197 return 0;
198}
199
200/**
201 * Send the fifo command to destroy a screen.
202 */
203static int vmw_sou_fifo_destroy(struct vmw_private *dev_priv,
204 struct vmw_screen_object_unit *sou)
205{
206 size_t fifo_size;
207 int ret;
208
209 struct {
210 struct {
211 uint32_t cmdType;
212 } header;
213 SVGAFifoCmdDestroyScreen body;
214 } *cmd;
215
216 /* no need to do anything */
217 if (unlikely(!sou->defined))
218 return 0;
219
220 fifo_size = sizeof(*cmd);
221 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
222 /* the hardware has hung, nothing we can do about it here */
223 if (unlikely(cmd == NULL)) {
224 DRM_ERROR("Fifo reserve failed.\n");
225 return -ENOMEM;
226 }
227
228 memset(cmd, 0, fifo_size);
229 cmd->header.cmdType = SVGA_CMD_DESTROY_SCREEN;
230 cmd->body.screenId = sou->base.unit;
231
232 vmw_fifo_commit(dev_priv, fifo_size);
233
234 /* Force sync */
235 ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
236 if (unlikely(ret != 0))
237 DRM_ERROR("Failed to sync with HW");
238 else
239 sou->defined = false;
240
241 return ret;
242}
243
244/**
245 * Free the backing store.
246 */
247static void vmw_sou_backing_free(struct vmw_private *dev_priv,
248 struct vmw_screen_object_unit *sou)
249{
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700250 vmw_dmabuf_unreference(&sou->buffer);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200251 sou->buffer_size = 0;
252}
253
254/**
255 * Allocate the backing store for the buffer.
256 */
257static int vmw_sou_backing_alloc(struct vmw_private *dev_priv,
258 struct vmw_screen_object_unit *sou,
259 unsigned long size)
260{
261 int ret;
262
263 if (sou->buffer_size == size)
264 return 0;
265
266 if (sou->buffer)
267 vmw_sou_backing_free(dev_priv, sou);
268
269 sou->buffer = kzalloc(sizeof(*sou->buffer), GFP_KERNEL);
270 if (unlikely(sou->buffer == NULL))
271 return -ENOMEM;
272
273 /* After we have alloced the backing store might not be able to
274 * resume the overlays, this is preferred to failing to alloc.
275 */
276 vmw_overlay_pause_all(dev_priv);
277 ret = vmw_dmabuf_init(dev_priv, sou->buffer, size,
278 &vmw_vram_ne_placement,
279 false, &vmw_dmabuf_bo_free);
280 vmw_overlay_resume_all(dev_priv);
281
282 if (unlikely(ret != 0))
283 sou->buffer = NULL; /* vmw_dmabuf_init frees on error */
284 else
285 sou->buffer_size = size;
286
287 return ret;
288}
289
290static int vmw_sou_crtc_set_config(struct drm_mode_set *set)
291{
292 struct vmw_private *dev_priv;
293 struct vmw_screen_object_unit *sou;
294 struct drm_connector *connector;
295 struct drm_display_mode *mode;
296 struct drm_encoder *encoder;
297 struct vmw_framebuffer *vfb;
298 struct drm_framebuffer *fb;
299 struct drm_crtc *crtc;
300 int ret = 0;
301
302 if (!set)
303 return -EINVAL;
304
305 if (!set->crtc)
306 return -EINVAL;
307
308 /* get the sou */
309 crtc = set->crtc;
310 sou = vmw_crtc_to_sou(crtc);
311 vfb = set->fb ? vmw_framebuffer_to_vfb(set->fb) : NULL;
312 dev_priv = vmw_priv(crtc->dev);
313
314 if (set->num_connectors > 1) {
Sinclair Yehc8261a92015-06-26 01:23:42 -0700315 DRM_ERROR("Too many connectors\n");
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200316 return -EINVAL;
317 }
318
319 if (set->num_connectors == 1 &&
320 set->connectors[0] != &sou->base.connector) {
Sinclair Yehc8261a92015-06-26 01:23:42 -0700321 DRM_ERROR("Connector doesn't match %p %p\n",
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200322 set->connectors[0], &sou->base.connector);
323 return -EINVAL;
324 }
325
326 /* sou only supports one fb active at the time */
Thomas Hellstrom69874272011-11-02 09:43:11 +0100327 if (sou->base.is_implicit &&
328 dev_priv->sou_priv->implicit_fb && vfb &&
329 !(dev_priv->sou_priv->num_implicit == 1 &&
330 sou->active_implicit) &&
331 dev_priv->sou_priv->implicit_fb != vfb) {
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200332 DRM_ERROR("Multiple framebuffers not supported\n");
333 return -EINVAL;
334 }
335
336 /* since they always map one to one these are safe */
337 connector = &sou->base.connector;
338 encoder = &sou->base.encoder;
339
340 /* should we turn the crtc off */
341 if (set->num_connectors == 0 || !set->mode || !set->fb) {
342 ret = vmw_sou_fifo_destroy(dev_priv, sou);
343 /* the hardware has hung don't do anything more */
344 if (unlikely(ret != 0))
345 return ret;
346
347 connector->encoder = NULL;
348 encoder->crtc = NULL;
Matt Roperf4510a22014-04-01 15:22:40 -0700349 crtc->primary->fb = NULL;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200350 crtc->x = 0;
351 crtc->y = 0;
Thomas Hellstromc6c1f322013-11-14 03:11:10 -0800352 crtc->enabled = false;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200353
354 vmw_sou_del_active(dev_priv, sou);
355
356 vmw_sou_backing_free(dev_priv, sou);
357
358 return 0;
359 }
360
361
362 /* we now know we want to set a mode */
363 mode = set->mode;
364 fb = set->fb;
365
366 if (set->x + mode->hdisplay > fb->width ||
367 set->y + mode->vdisplay > fb->height) {
368 DRM_ERROR("set outside of framebuffer\n");
369 return -EINVAL;
370 }
371
372 vmw_fb_off(dev_priv);
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700373 vmw_svga_enable(dev_priv);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200374
375 if (mode->hdisplay != crtc->mode.hdisplay ||
376 mode->vdisplay != crtc->mode.vdisplay) {
377 /* no need to check if depth is different, because backing
378 * store depth is forced to 4 by the device.
379 */
380
381 ret = vmw_sou_fifo_destroy(dev_priv, sou);
382 /* the hardware has hung don't do anything more */
383 if (unlikely(ret != 0))
384 return ret;
385
386 vmw_sou_backing_free(dev_priv, sou);
387 }
388
389 if (!sou->buffer) {
390 /* forced to depth 4 by the device */
391 size_t size = mode->hdisplay * mode->vdisplay * 4;
392 ret = vmw_sou_backing_alloc(dev_priv, sou, size);
393 if (unlikely(ret != 0))
394 return ret;
395 }
396
397 ret = vmw_sou_fifo_create(dev_priv, sou, set->x, set->y, mode);
398 if (unlikely(ret != 0)) {
399 /*
400 * We are in a bit of a situation here, the hardware has
401 * hung and we may or may not have a buffer hanging of
402 * the screen object, best thing to do is not do anything
403 * if we where defined, if not just turn the crtc of.
404 * Not what userspace wants but it needs to htfu.
405 */
406 if (sou->defined)
407 return ret;
408
409 connector->encoder = NULL;
410 encoder->crtc = NULL;
Matt Roperf4510a22014-04-01 15:22:40 -0700411 crtc->primary->fb = NULL;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200412 crtc->x = 0;
413 crtc->y = 0;
Thomas Hellstromc6c1f322013-11-14 03:11:10 -0800414 crtc->enabled = false;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200415
416 return ret;
417 }
418
419 vmw_sou_add_active(dev_priv, sou, vfb);
420
421 connector->encoder = encoder;
422 encoder->crtc = crtc;
423 crtc->mode = *mode;
Matt Roperf4510a22014-04-01 15:22:40 -0700424 crtc->primary->fb = fb;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200425 crtc->x = set->x;
426 crtc->y = set->y;
Thomas Hellstromc6c1f322013-11-14 03:11:10 -0800427 crtc->enabled = true;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200428
429 return 0;
430}
431
Sinclair Yehc8261a92015-06-26 01:23:42 -0700432/**
433 * Returns if this unit can be page flipped.
434 * Must be called with the mode_config mutex held.
435 */
436static bool vmw_sou_screen_object_flippable(struct vmw_private *dev_priv,
437 struct drm_crtc *crtc)
438{
439 struct vmw_screen_object_unit *sou = vmw_crtc_to_sou(crtc);
440
441 if (!sou->base.is_implicit)
442 return true;
443
444 if (dev_priv->sou_priv->num_implicit != 1)
445 return false;
446
447 return true;
448}
449
450/**
451 * Update the implicit fb to the current fb of this crtc.
452 * Must be called with the mode_config mutex held.
453 */
454void vmw_sou_update_implicit_fb(struct vmw_private *dev_priv,
455 struct drm_crtc *crtc)
456{
457 struct vmw_screen_object_unit *sou = vmw_crtc_to_sou(crtc);
458
459 BUG_ON(!sou->base.is_implicit);
460
461 dev_priv->sou_priv->implicit_fb =
462 vmw_framebuffer_to_vfb(sou->base.crtc.primary->fb);
463}
464
465static int vmw_sou_crtc_page_flip(struct drm_crtc *crtc,
466 struct drm_framebuffer *fb,
467 struct drm_pending_vblank_event *event,
468 uint32_t flags)
469{
470 struct vmw_private *dev_priv = vmw_priv(crtc->dev);
471 struct drm_framebuffer *old_fb = crtc->primary->fb;
472 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(fb);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700473 struct vmw_fence_obj *fence = NULL;
474 struct drm_clip_rect clips;
475 int ret;
476
477 /* require ScreenObject support for page flipping */
478 if (!dev_priv->sou_priv)
479 return -ENOSYS;
480
481 if (!vmw_sou_screen_object_flippable(dev_priv, crtc))
482 return -EINVAL;
483
484 crtc->primary->fb = fb;
485
486 /* do a full screen dirty update */
487 clips.x1 = clips.y1 = 0;
488 clips.x2 = fb->width;
489 clips.y2 = fb->height;
490
491 if (vfb->dmabuf)
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700492 ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, vfb,
493 &clips, 1, 1,
494 true, &fence);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700495 else
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700496 ret = vmw_kms_sou_do_surface_dirty(dev_priv, vfb,
497 &clips, NULL, NULL,
498 0, 0, 1, 1, &fence);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700499
500
501 if (ret != 0)
502 goto out_no_fence;
503 if (!fence) {
504 ret = -EINVAL;
505 goto out_no_fence;
506 }
507
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700508 if (event) {
509 struct drm_file *file_priv = event->base.file_priv;
510
511 ret = vmw_event_fence_action_queue(file_priv, fence,
512 &event->base,
513 &event->event.tv_sec,
514 &event->event.tv_usec,
515 true);
516 }
Sinclair Yehc8261a92015-06-26 01:23:42 -0700517
518 /*
519 * No need to hold on to this now. The only cleanup
520 * we need to do if we fail is unref the fence.
521 */
522 vmw_fence_obj_unreference(&fence);
523
524 if (vmw_crtc_to_du(crtc)->is_implicit)
525 vmw_sou_update_implicit_fb(dev_priv, crtc);
526
527 return ret;
528
529out_no_fence:
530 crtc->primary->fb = old_fb;
531 return ret;
532}
533
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200534static struct drm_crtc_funcs vmw_screen_object_crtc_funcs = {
535 .save = vmw_du_crtc_save,
536 .restore = vmw_du_crtc_restore,
537 .cursor_set = vmw_du_crtc_cursor_set,
538 .cursor_move = vmw_du_crtc_cursor_move,
539 .gamma_set = vmw_du_crtc_gamma_set,
540 .destroy = vmw_sou_crtc_destroy,
541 .set_config = vmw_sou_crtc_set_config,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700542 .page_flip = vmw_sou_crtc_page_flip,
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200543};
544
545/*
546 * Screen Object Display Unit encoder functions
547 */
548
549static void vmw_sou_encoder_destroy(struct drm_encoder *encoder)
550{
551 vmw_sou_destroy(vmw_encoder_to_sou(encoder));
552}
553
554static struct drm_encoder_funcs vmw_screen_object_encoder_funcs = {
555 .destroy = vmw_sou_encoder_destroy,
556};
557
558/*
559 * Screen Object Display Unit connector functions
560 */
561
562static void vmw_sou_connector_destroy(struct drm_connector *connector)
563{
564 vmw_sou_destroy(vmw_connector_to_sou(connector));
565}
566
Sinclair Yehc8261a92015-06-26 01:23:42 -0700567static struct drm_connector_funcs vmw_sou_connector_funcs = {
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200568 .dpms = vmw_du_connector_dpms,
569 .save = vmw_du_connector_save,
570 .restore = vmw_du_connector_restore,
571 .detect = vmw_du_connector_detect,
572 .fill_modes = vmw_du_connector_fill_modes,
573 .set_property = vmw_du_connector_set_property,
574 .destroy = vmw_sou_connector_destroy,
575};
576
577static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
578{
579 struct vmw_screen_object_unit *sou;
580 struct drm_device *dev = dev_priv->dev;
581 struct drm_connector *connector;
582 struct drm_encoder *encoder;
583 struct drm_crtc *crtc;
584
585 sou = kzalloc(sizeof(*sou), GFP_KERNEL);
586 if (!sou)
587 return -ENOMEM;
588
589 sou->base.unit = unit;
590 crtc = &sou->base.crtc;
591 encoder = &sou->base.encoder;
592 connector = &sou->base.connector;
593
Thomas Hellstrom69874272011-11-02 09:43:11 +0100594 sou->active_implicit = false;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200595
596 sou->base.pref_active = (unit == 0);
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100597 sou->base.pref_width = dev_priv->initial_width;
598 sou->base.pref_height = dev_priv->initial_height;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200599 sou->base.pref_mode = NULL;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100600 sou->base.is_implicit = true;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200601
Sinclair Yehc8261a92015-06-26 01:23:42 -0700602 drm_connector_init(dev, connector, &vmw_sou_connector_funcs,
Thomas Hellstrom305151e2011-10-22 10:36:20 +0200603 DRM_MODE_CONNECTOR_VIRTUAL);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200604 connector->status = vmw_du_connector_detect(connector, true);
605
606 drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs,
Thomas Hellstrom305151e2011-10-22 10:36:20 +0200607 DRM_MODE_ENCODER_VIRTUAL);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200608 drm_mode_connector_attach_encoder(connector, encoder);
609 encoder->possible_crtcs = (1 << unit);
610 encoder->possible_clones = 0;
611
Thomas Wood34ea3d32014-05-29 16:57:41 +0100612 (void) drm_connector_register(connector);
Thomas Hellstrom6a0a7a92013-12-02 06:04:38 -0800613
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200614 drm_crtc_init(dev, crtc, &vmw_screen_object_crtc_funcs);
615
616 drm_mode_crtc_set_gamma_size(crtc, 256);
617
Rob Clarkb8b163b2012-10-11 20:47:14 -0500618 drm_object_attach_property(&connector->base,
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200619 dev->mode_config.dirty_info_property,
620 1);
621
622 return 0;
623}
624
Sinclair Yehc8261a92015-06-26 01:23:42 -0700625int vmw_kms_sou_init_display(struct vmw_private *dev_priv)
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200626{
627 struct drm_device *dev = dev_priv->dev;
Jakob Bornecrantz74b5ea32011-10-17 11:59:44 +0200628 int i, ret;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200629
630 if (dev_priv->sou_priv) {
631 DRM_INFO("sou system already on\n");
632 return -EINVAL;
633 }
634
Thomas Hellstrom29a16e92012-11-09 12:26:13 +0000635 if (!(dev_priv->capabilities & SVGA_CAP_SCREEN_OBJECT_2)) {
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200636 DRM_INFO("Not using screen objects,"
637 " missing cap SCREEN_OBJECT_2\n");
638 return -ENOSYS;
639 }
640
641 ret = -ENOMEM;
642 dev_priv->sou_priv = kmalloc(sizeof(*dev_priv->sou_priv), GFP_KERNEL);
643 if (unlikely(!dev_priv->sou_priv))
644 goto err_no_mem;
645
Thomas Hellstrom69874272011-11-02 09:43:11 +0100646 dev_priv->sou_priv->num_implicit = 0;
647 dev_priv->sou_priv->implicit_fb = NULL;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200648
649 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
650 if (unlikely(ret != 0))
651 goto err_free;
652
Jakob Bornecrantz74b5ea32011-10-17 11:59:44 +0200653 ret = drm_mode_create_dirty_info_property(dev);
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200654 if (unlikely(ret != 0))
655 goto err_vblank_cleanup;
656
657 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
658 vmw_sou_init(dev_priv, i);
659
Sinclair Yehc8261a92015-06-26 01:23:42 -0700660 dev_priv->active_display_unit = vmw_du_screen_object;
661
662 DRM_INFO("Screen Objects Display Unit initialized\n");
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200663
664 return 0;
665
666err_vblank_cleanup:
667 drm_vblank_cleanup(dev);
668err_free:
669 kfree(dev_priv->sou_priv);
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200670 dev_priv->sou_priv = NULL;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200671err_no_mem:
672 return ret;
673}
674
Sinclair Yehc8261a92015-06-26 01:23:42 -0700675int vmw_kms_sou_close_display(struct vmw_private *dev_priv)
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200676{
677 struct drm_device *dev = dev_priv->dev;
678
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200679 if (!dev_priv->sou_priv)
680 return -ENOSYS;
681
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200682 drm_vblank_cleanup(dev);
683
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200684 kfree(dev_priv->sou_priv);
685
686 return 0;
687}
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100688
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700689static int do_dmabuf_define_gmrfb(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700690 struct vmw_framebuffer *framebuffer)
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100691{
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700692 struct vmw_dma_buffer *buf =
693 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
694 base)->buffer;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700695 int depth = framebuffer->base.depth;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700696 struct {
697 uint32_t header;
698 SVGAFifoCmdDefineGMRFB body;
699 } *cmd;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100700
Sinclair Yehc8261a92015-06-26 01:23:42 -0700701 /* Emulate RGBA support, contrary to svga_reg.h this is not
702 * supported by hosts. This is only a problem if we are reading
703 * this value later and expecting what we uploaded back.
704 */
705 if (depth == 32)
706 depth = 24;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100707
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700708 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
709 if (!cmd) {
710 DRM_ERROR("Out of fifo space for dirty framebuffer command.\n");
Sinclair Yehc8261a92015-06-26 01:23:42 -0700711 return -ENOMEM;
712 }
713
Sinclair Yehc8261a92015-06-26 01:23:42 -0700714 cmd->header = SVGA_CMD_DEFINE_GMRFB;
715 cmd->body.format.bitsPerPixel = framebuffer->base.bits_per_pixel;
716 cmd->body.format.colorDepth = depth;
717 cmd->body.format.reserved = 0;
718 cmd->body.bytesPerLine = framebuffer->base.pitches[0];
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700719 /* Buffer is reserved in vram or GMR */
720 vmw_bo_get_guest_ptr(&buf->base, &cmd->body.ptr);
721 vmw_fifo_commit(dev_priv, sizeof(*cmd));
Sinclair Yehc8261a92015-06-26 01:23:42 -0700722
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700723 return 0;
724}
Sinclair Yehc8261a92015-06-26 01:23:42 -0700725
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700726/**
727 * vmw_sou_surface_fifo_commit - Callback to fill in and submit a
728 * blit surface to screen command.
729 *
730 * @dirty: The closure structure.
731 *
732 * Fills in the missing fields in the command, and translates the cliprects
733 * to match the destination bounding box encoded.
734 */
735static void vmw_sou_surface_fifo_commit(struct vmw_kms_dirty *dirty)
736{
737 struct vmw_kms_sou_surface_dirty *sdirty =
738 container_of(dirty, typeof(*sdirty), base);
739 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
740 s32 trans_x = dirty->unit->crtc.x - sdirty->dst_x;
741 s32 trans_y = dirty->unit->crtc.y - sdirty->dst_y;
742 size_t region_size = dirty->num_hits * sizeof(SVGASignedRect);
743 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
744 int i;
745
746 cmd->header.id = SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN;
747 cmd->header.size = sizeof(cmd->body) + region_size;
748
749 /*
750 * Use the destination bounding box to specify destination - and
751 * source bounding regions.
752 */
753 cmd->body.destRect.left = sdirty->left;
754 cmd->body.destRect.right = sdirty->right;
755 cmd->body.destRect.top = sdirty->top;
756 cmd->body.destRect.bottom = sdirty->bottom;
757
758 cmd->body.srcRect.left = sdirty->left + trans_x;
759 cmd->body.srcRect.right = sdirty->right + trans_x;
760 cmd->body.srcRect.top = sdirty->top + trans_y;
761 cmd->body.srcRect.bottom = sdirty->bottom + trans_y;
762
763 cmd->body.srcImage.sid = sdirty->sid;
764 cmd->body.destScreenId = dirty->unit->unit;
765
766 /* Blits are relative to the destination rect. Translate. */
767 for (i = 0; i < dirty->num_hits; ++i, ++blit) {
768 blit->left -= sdirty->left;
769 blit->right -= sdirty->left;
770 blit->top -= sdirty->top;
771 blit->bottom -= sdirty->top;
772 }
773
774 vmw_fifo_commit(dirty->dev_priv, region_size + sizeof(*cmd));
775
776 sdirty->left = sdirty->top = S32_MAX;
777 sdirty->right = sdirty->bottom = S32_MIN;
778}
779
780/**
781 * vmw_sou_surface_clip - Callback to encode a blit surface to screen cliprect.
782 *
783 * @dirty: The closure structure
784 *
785 * Encodes a SVGASignedRect cliprect and updates the bounding box of the
786 * BLIT_SURFACE_TO_SCREEN command.
787 */
788static void vmw_sou_surface_clip(struct vmw_kms_dirty *dirty)
789{
790 struct vmw_kms_sou_surface_dirty *sdirty =
791 container_of(dirty, typeof(*sdirty), base);
792 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
793 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
794
795 /* Destination rect. */
796 blit += dirty->num_hits;
797 blit->left = dirty->unit_x1;
798 blit->top = dirty->unit_y1;
799 blit->right = dirty->unit_x2;
800 blit->bottom = dirty->unit_y2;
801
802 /* Destination bounding box */
803 sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
804 sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
805 sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
806 sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
807
808 dirty->num_hits++;
809}
810
811/**
812 * vmw_kms_sou_do_surface_dirty - Dirty part of a surface backed framebuffer
813 *
814 * @dev_priv: Pointer to the device private structure.
815 * @framebuffer: Pointer to the surface-buffer backed framebuffer.
816 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
817 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
818 * be NULL.
819 * @srf: Pointer to surface to blit from. If NULL, the surface attached
820 * to @framebuffer will be used.
821 * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
822 * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
823 * @num_clips: Number of clip rects in @clips.
824 * @inc: Increment to use when looping over @clips.
825 * @out_fence: If non-NULL, will return a ref-counted pointer to a
826 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
827 * case the device has already synchronized.
828 *
829 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
830 * interrupted.
831 */
832int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
833 struct vmw_framebuffer *framebuffer,
834 struct drm_clip_rect *clips,
835 struct drm_vmw_rect *vclips,
836 struct vmw_resource *srf,
837 s32 dest_x,
838 s32 dest_y,
839 unsigned num_clips, int inc,
840 struct vmw_fence_obj **out_fence)
841{
842 struct vmw_framebuffer_surface *vfbs =
843 container_of(framebuffer, typeof(*vfbs), base);
844 struct vmw_kms_sou_surface_dirty sdirty;
845 int ret;
846
847 if (!srf)
848 srf = &vfbs->surface->res;
849
850 ret = vmw_kms_helper_resource_prepare(srf, true);
851 if (ret)
852 return ret;
853
854 sdirty.base.fifo_commit = vmw_sou_surface_fifo_commit;
855 sdirty.base.clip = vmw_sou_surface_clip;
856 sdirty.base.dev_priv = dev_priv;
857 sdirty.base.fifo_reserve_size = sizeof(struct vmw_kms_sou_dirty_cmd) +
858 sizeof(SVGASignedRect) * num_clips;
859
860 sdirty.sid = srf->id;
861 sdirty.left = sdirty.top = S32_MAX;
862 sdirty.right = sdirty.bottom = S32_MIN;
863 sdirty.dst_x = dest_x;
864 sdirty.dst_y = dest_y;
865
866 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
867 dest_x, dest_y, num_clips, inc,
868 &sdirty.base);
869 vmw_kms_helper_resource_finish(srf, out_fence);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700870
871 return ret;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100872}
873
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700874/**
875 * vmw_sou_dmabuf_fifo_commit - Callback to submit a set of readback clips.
876 *
877 * @dirty: The closure structure.
878 *
879 * Commits a previously built command buffer of readback clips.
880 */
881static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
882{
883 vmw_fifo_commit(dirty->dev_priv,
884 sizeof(struct vmw_kms_sou_dmabuf_blit) *
885 dirty->num_hits);
886}
887
888/**
889 * vmw_sou_dmabuf_clip - Callback to encode a readback cliprect.
890 *
891 * @dirty: The closure structure
892 *
893 * Encodes a BLIT_GMRFB_TO_SCREEN cliprect.
894 */
895static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty *dirty)
896{
897 struct vmw_kms_sou_dmabuf_blit *blit = dirty->cmd;
898
899 blit += dirty->num_hits;
900 blit->header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN;
901 blit->body.destScreenId = dirty->unit->unit;
902 blit->body.srcOrigin.x = dirty->fb_x;
903 blit->body.srcOrigin.y = dirty->fb_y;
904 blit->body.destRect.left = dirty->unit_x1;
905 blit->body.destRect.top = dirty->unit_y1;
906 blit->body.destRect.right = dirty->unit_x2;
907 blit->body.destRect.bottom = dirty->unit_y2;
908 dirty->num_hits++;
909}
910
911/**
912 * vmw_kms_do_dmabuf_dirty - Dirty part of a dma-buffer backed framebuffer
913 *
914 * @dev_priv: Pointer to the device private structure.
915 * @framebuffer: Pointer to the dma-buffer backed framebuffer.
916 * @clips: Array of clip rects.
917 * @num_clips: Number of clip rects in @clips.
918 * @increment: Increment to use when looping over @clips.
919 * @interruptible: Whether to perform waits interruptible if possible.
920 * @out_fence: If non-NULL, will return a ref-counted pointer to a
921 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
922 * case the device has already synchronized.
923 *
924 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
925 * interrupted.
926 */
927int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700928 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700929 struct drm_clip_rect *clips,
930 unsigned num_clips, int increment,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700931 bool interruptible,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700932 struct vmw_fence_obj **out_fence)
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100933{
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700934 struct vmw_dma_buffer *buf =
935 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
936 base)->buffer;
937 struct vmw_kms_dirty dirty;
938 int ret;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100939
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700940 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
941 false);
942 if (ret)
943 return ret;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100944
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700945 ret = do_dmabuf_define_gmrfb(dev_priv, framebuffer);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700946 if (unlikely(ret != 0))
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700947 goto out_revert;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700948
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700949 dirty.fifo_commit = vmw_sou_dmabuf_fifo_commit;
950 dirty.clip = vmw_sou_dmabuf_clip;
951 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_dmabuf_blit) *
952 num_clips;
953 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, NULL,
954 0, 0, num_clips, increment, &dirty);
955 vmw_kms_helper_buffer_finish(dev_priv, NULL, buf, out_fence, NULL);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700956
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700957 return ret;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700958
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700959out_revert:
960 vmw_kms_helper_buffer_revert(buf);
Sinclair Yehc8261a92015-06-26 01:23:42 -0700961
962 return ret;
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100963}
Sinclair Yehc8261a92015-06-26 01:23:42 -0700964
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700965
966/**
967 * vmw_sou_readback_fifo_commit - Callback to submit a set of readback clips.
968 *
969 * @dirty: The closure structure.
970 *
971 * Commits a previously built command buffer of readback clips.
972 */
973static void vmw_sou_readback_fifo_commit(struct vmw_kms_dirty *dirty)
974{
975 vmw_fifo_commit(dirty->dev_priv,
976 sizeof(struct vmw_kms_sou_readback_blit) *
977 dirty->num_hits);
978}
979
980/**
981 * vmw_sou_readback_clip - Callback to encode a readback cliprect.
982 *
983 * @dirty: The closure structure
984 *
985 * Encodes a BLIT_SCREEN_TO_GMRFB cliprect.
986 */
987static void vmw_sou_readback_clip(struct vmw_kms_dirty *dirty)
988{
989 struct vmw_kms_sou_readback_blit *blit = dirty->cmd;
990
991 blit += dirty->num_hits;
992 blit->header = SVGA_CMD_BLIT_SCREEN_TO_GMRFB;
993 blit->body.srcScreenId = dirty->unit->unit;
994 blit->body.destOrigin.x = dirty->fb_x;
995 blit->body.destOrigin.y = dirty->fb_y;
996 blit->body.srcRect.left = dirty->unit_x1;
997 blit->body.srcRect.top = dirty->unit_y1;
998 blit->body.srcRect.right = dirty->unit_x2;
999 blit->body.srcRect.bottom = dirty->unit_y2;
1000 dirty->num_hits++;
1001}
1002
1003/**
1004 * vmw_kms_sou_readback - Perform a readback from the screen object system to
1005 * a dma-buffer backed framebuffer.
1006 *
1007 * @dev_priv: Pointer to the device private structure.
1008 * @file_priv: Pointer to a struct drm_file identifying the caller.
1009 * Must be set to NULL if @user_fence_rep is NULL.
1010 * @vfb: Pointer to the dma-buffer backed framebuffer.
1011 * @user_fence_rep: User-space provided structure for fence information.
1012 * Must be set to non-NULL if @file_priv is non-NULL.
1013 * @vclips: Array of clip rects.
1014 * @num_clips: Number of clip rects in @vclips.
1015 *
1016 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
1017 * interrupted.
1018 */
1019int vmw_kms_sou_readback(struct vmw_private *dev_priv,
1020 struct drm_file *file_priv,
1021 struct vmw_framebuffer *vfb,
1022 struct drm_vmw_fence_rep __user *user_fence_rep,
1023 struct drm_vmw_rect *vclips,
1024 uint32_t num_clips)
1025{
1026 struct vmw_dma_buffer *buf =
1027 container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
1028 struct vmw_kms_dirty dirty;
1029 int ret;
1030
1031 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, true, false);
1032 if (ret)
1033 return ret;
1034
1035 ret = do_dmabuf_define_gmrfb(dev_priv, vfb);
1036 if (unlikely(ret != 0))
1037 goto out_revert;
1038
1039 dirty.fifo_commit = vmw_sou_readback_fifo_commit;
1040 dirty.clip = vmw_sou_readback_clip;
1041 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_readback_blit) *
1042 num_clips;
1043 ret = vmw_kms_helper_dirty(dev_priv, vfb, NULL, vclips,
1044 0, 0, num_clips, 1, &dirty);
1045 vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
1046 user_fence_rep);
1047
1048 return ret;
1049
1050out_revert:
1051 vmw_kms_helper_buffer_revert(buf);
1052
1053 return ret;
1054}