blob: cce5e5b02e201d236476043dd46849378447006c [file] [log] [blame]
Sinclair Yeh35c05122015-06-26 01:42:06 -07001/******************************************************************************
2 *
Sinclair Yeh54fbde82015-07-29 12:38:02 -07003 * COPYRIGHT © 2014-2015 VMware, Inc., Palo Alto, CA., USA
Sinclair Yeh35c05122015-06-26 01:42:06 -07004 * 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"
Sinclair Yeh8ce75f82015-07-08 21:20:39 -070029#include "device_include/svga3d_surfacedefs.h"
Sinclair Yeh35c05122015-06-26 01:42:06 -070030#include <drm/drm_plane_helper.h>
Sinclair Yehd7721ca2017-03-23 11:48:44 -070031#include <drm/drm_atomic.h>
32#include <drm/drm_atomic_helper.h>
33
Sinclair Yeh35c05122015-06-26 01:42:06 -070034
35#define vmw_crtc_to_stdu(x) \
36 container_of(x, struct vmw_screen_target_display_unit, base.crtc)
37#define vmw_encoder_to_stdu(x) \
38 container_of(x, struct vmw_screen_target_display_unit, base.encoder)
39#define vmw_connector_to_stdu(x) \
40 container_of(x, struct vmw_screen_target_display_unit, base.connector)
41
42
43
44enum stdu_content_type {
45 SAME_AS_DISPLAY = 0,
46 SEPARATE_SURFACE,
47 SEPARATE_DMA
48};
49
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -070050/**
51 * struct vmw_stdu_dirty - closure structure for the update functions
52 *
53 * @base: The base type we derive from. Used by vmw_kms_helper_dirty().
54 * @transfer: Transfer direction for DMA command.
55 * @left: Left side of bounding box.
56 * @right: Right side of bounding box.
57 * @top: Top side of bounding box.
58 * @bottom: Bottom side of bounding box.
59 * @buf: DMA buffer when DMA-ing between buffer and screen targets.
60 * @sid: Surface ID when copying between surface and screen targets.
61 */
62struct vmw_stdu_dirty {
63 struct vmw_kms_dirty base;
64 SVGA3dTransferType transfer;
65 s32 left, right, top, bottom;
66 u32 pitch;
67 union {
68 struct vmw_dma_buffer *buf;
69 u32 sid;
70 };
71};
72
73/*
74 * SVGA commands that are used by this code. Please see the device headers
75 * for explanation.
76 */
77struct vmw_stdu_update {
78 SVGA3dCmdHeader header;
79 SVGA3dCmdUpdateGBScreenTarget body;
80};
81
82struct vmw_stdu_dma {
83 SVGA3dCmdHeader header;
84 SVGA3dCmdSurfaceDMA body;
85};
86
87struct vmw_stdu_surface_copy {
88 SVGA3dCmdHeader header;
89 SVGA3dCmdSurfaceCopy body;
90};
Sinclair Yeh35c05122015-06-26 01:42:06 -070091
92
93/**
94 * struct vmw_screen_target_display_unit
95 *
96 * @base: VMW specific DU structure
97 * @display_srf: surface to be displayed. The dimension of this will always
98 * match the display mode. If the display mode matches
99 * content_vfbs dimensions, then this is a pointer into the
100 * corresponding field in content_vfbs. If not, then this
101 * is a separate buffer to which content_vfbs will blit to.
Sinclair Yeh35c05122015-06-26 01:42:06 -0700102 * @content_type: content_fb type
103 * @defined: true if the current display unit has been initialized
104 */
105struct vmw_screen_target_display_unit {
106 struct vmw_display_unit base;
107
108 struct vmw_surface *display_srf;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700109 enum stdu_content_type content_fb_type;
110
111 bool defined;
112};
113
114
115
116static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu);
117
118
119
120/******************************************************************************
121 * Screen Target Display Unit helper Functions
122 *****************************************************************************/
123
124/**
Sinclair Yeh35c05122015-06-26 01:42:06 -0700125 * vmw_stdu_unpin_display - unpins the resource associated with display surface
126 *
127 * @stdu: contains the display surface
128 *
129 * If the display surface was privatedly allocated by
130 * vmw_surface_gb_priv_define() and not registered as a framebuffer, then it
131 * won't be automatically cleaned up when all the framebuffers are freed. As
132 * such, we have to explicitly call vmw_resource_unreference() to get it freed.
133 */
134static void vmw_stdu_unpin_display(struct vmw_screen_target_display_unit *stdu)
135{
136 if (stdu->display_srf) {
137 struct vmw_resource *res = &stdu->display_srf->res;
138
139 vmw_resource_unpin(res);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100140 vmw_surface_unreference(&stdu->display_srf);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700141 }
142}
143
144
145
146/******************************************************************************
147 * Screen Target Display Unit CRTC Functions
148 *****************************************************************************/
149
150
151/**
152 * vmw_stdu_crtc_destroy - cleans up the STDU
153 *
154 * @crtc: used to get a reference to the containing STDU
155 */
156static void vmw_stdu_crtc_destroy(struct drm_crtc *crtc)
157{
158 vmw_stdu_destroy(vmw_crtc_to_stdu(crtc));
159}
160
Sinclair Yeh35c05122015-06-26 01:42:06 -0700161/**
162 * vmw_stdu_define_st - Defines a Screen Target
163 *
164 * @dev_priv: VMW DRM device
165 * @stdu: display unit to create a Screen Target for
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100166 * @mode: The mode to set.
167 * @crtc_x: X coordinate of screen target relative to framebuffer origin.
168 * @crtc_y: Y coordinate of screen target relative to framebuffer origin.
Sinclair Yeh35c05122015-06-26 01:42:06 -0700169 *
170 * Creates a STDU that we can used later. This function is called whenever the
171 * framebuffer size changes.
172 *
173 * RETURNs:
174 * 0 on success, error code on failure
175 */
176static int vmw_stdu_define_st(struct vmw_private *dev_priv,
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100177 struct vmw_screen_target_display_unit *stdu,
178 struct drm_display_mode *mode,
179 int crtc_x, int crtc_y)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700180{
181 struct {
182 SVGA3dCmdHeader header;
183 SVGA3dCmdDefineGBScreenTarget body;
184 } *cmd;
185
186 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
187
188 if (unlikely(cmd == NULL)) {
189 DRM_ERROR("Out of FIFO space defining Screen Target\n");
190 return -ENOMEM;
191 }
192
193 cmd->header.id = SVGA_3D_CMD_DEFINE_GB_SCREENTARGET;
194 cmd->header.size = sizeof(cmd->body);
195
196 cmd->body.stid = stdu->base.unit;
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100197 cmd->body.width = mode->hdisplay;
198 cmd->body.height = mode->vdisplay;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700199 cmd->body.flags = (0 == cmd->body.stid) ? SVGA_STFLAG_PRIMARY : 0;
200 cmd->body.dpi = 0;
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100201 if (stdu->base.is_implicit) {
202 cmd->body.xRoot = crtc_x;
203 cmd->body.yRoot = crtc_y;
204 } else {
Sinclair Yeh35c05122015-06-26 01:42:06 -0700205 cmd->body.xRoot = stdu->base.gui_x;
206 cmd->body.yRoot = stdu->base.gui_y;
207 }
Thomas Hellstrom6dd687b2016-02-12 09:57:15 +0100208 stdu->base.set_gui_x = cmd->body.xRoot;
209 stdu->base.set_gui_y = cmd->body.yRoot;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700210
211 vmw_fifo_commit(dev_priv, sizeof(*cmd));
212
213 stdu->defined = true;
214
215 return 0;
216}
217
218
219
220/**
221 * vmw_stdu_bind_st - Binds a surface to a Screen Target
222 *
223 * @dev_priv: VMW DRM device
224 * @stdu: display unit affected
225 * @res: Buffer to bind to the screen target. Set to NULL to blank screen.
226 *
227 * Binding a surface to a Screen Target the same as flipping
228 */
229static int vmw_stdu_bind_st(struct vmw_private *dev_priv,
230 struct vmw_screen_target_display_unit *stdu,
231 struct vmw_resource *res)
232{
233 SVGA3dSurfaceImageId image;
234
235 struct {
236 SVGA3dCmdHeader header;
237 SVGA3dCmdBindGBScreenTarget body;
238 } *cmd;
239
240
241 if (!stdu->defined) {
242 DRM_ERROR("No screen target defined\n");
243 return -EINVAL;
244 }
245
246 /* Set up image using information in vfb */
247 memset(&image, 0, sizeof(image));
248 image.sid = res ? res->id : SVGA3D_INVALID_ID;
249
250 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
251
252 if (unlikely(cmd == NULL)) {
253 DRM_ERROR("Out of FIFO space binding a screen target\n");
254 return -ENOMEM;
255 }
256
257 cmd->header.id = SVGA_3D_CMD_BIND_GB_SCREENTARGET;
258 cmd->header.size = sizeof(cmd->body);
259
260 cmd->body.stid = stdu->base.unit;
261 cmd->body.image = image;
262
263 vmw_fifo_commit(dev_priv, sizeof(*cmd));
264
265 return 0;
266}
267
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700268/**
269 * vmw_stdu_populate_update - populate an UPDATE_GB_SCREENTARGET command with a
270 * bounding box.
271 *
272 * @cmd: Pointer to command stream.
273 * @unit: Screen target unit.
274 * @left: Left side of bounding box.
275 * @right: Right side of bounding box.
276 * @top: Top side of bounding box.
277 * @bottom: Bottom side of bounding box.
278 */
279static void vmw_stdu_populate_update(void *cmd, int unit,
280 s32 left, s32 right, s32 top, s32 bottom)
281{
282 struct vmw_stdu_update *update = cmd;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700283
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700284 update->header.id = SVGA_3D_CMD_UPDATE_GB_SCREENTARGET;
285 update->header.size = sizeof(update->body);
286
287 update->body.stid = unit;
288 update->body.rect.x = left;
289 update->body.rect.y = top;
290 update->body.rect.w = right - left;
291 update->body.rect.h = bottom - top;
292}
Sinclair Yeh35c05122015-06-26 01:42:06 -0700293
294/**
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700295 * vmw_stdu_update_st - Full update of a Screen Target
Sinclair Yeh35c05122015-06-26 01:42:06 -0700296 *
297 * @dev_priv: VMW DRM device
Sinclair Yeh35c05122015-06-26 01:42:06 -0700298 * @stdu: display unit affected
Sinclair Yeh35c05122015-06-26 01:42:06 -0700299 *
300 * This function needs to be called whenever the content of a screen
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700301 * target has changed completely. Typically as a result of a backing
302 * surface change.
Sinclair Yeh35c05122015-06-26 01:42:06 -0700303 *
304 * RETURNS:
305 * 0 on success, error code on failure
306 */
307static int vmw_stdu_update_st(struct vmw_private *dev_priv,
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700308 struct vmw_screen_target_display_unit *stdu)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700309{
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700310 struct vmw_stdu_update *cmd;
311 struct drm_crtc *crtc = &stdu->base.crtc;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700312
313 if (!stdu->defined) {
314 DRM_ERROR("No screen target defined");
315 return -EINVAL;
316 }
317
Sinclair Yeh35c05122015-06-26 01:42:06 -0700318 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
319
320 if (unlikely(cmd == NULL)) {
321 DRM_ERROR("Out of FIFO space updating a Screen Target\n");
322 return -ENOMEM;
323 }
324
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700325 vmw_stdu_populate_update(cmd, stdu->base.unit, 0, crtc->mode.hdisplay,
326 0, crtc->mode.vdisplay);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700327
328 vmw_fifo_commit(dev_priv, sizeof(*cmd));
329
330 return 0;
331}
332
333
334
335/**
336 * vmw_stdu_destroy_st - Destroy a Screen Target
337 *
338 * @dev_priv: VMW DRM device
339 * @stdu: display unit to destroy
340 */
341static int vmw_stdu_destroy_st(struct vmw_private *dev_priv,
342 struct vmw_screen_target_display_unit *stdu)
343{
344 int ret;
345
346 struct {
347 SVGA3dCmdHeader header;
348 SVGA3dCmdDestroyGBScreenTarget body;
349 } *cmd;
350
351
352 /* Nothing to do if not successfully defined */
353 if (unlikely(!stdu->defined))
354 return 0;
355
356 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
357
358 if (unlikely(cmd == NULL)) {
359 DRM_ERROR("Out of FIFO space, screen target not destroyed\n");
360 return -ENOMEM;
361 }
362
363 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_SCREENTARGET;
364 cmd->header.size = sizeof(cmd->body);
365
366 cmd->body.stid = stdu->base.unit;
367
368 vmw_fifo_commit(dev_priv, sizeof(*cmd));
369
370 /* Force sync */
371 ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
372 if (unlikely(ret != 0))
373 DRM_ERROR("Failed to sync with HW");
374
375 stdu->defined = false;
376
377 return ret;
378}
379
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100380/**
381 * vmw_stdu_bind_fb - Bind an fb to a defined screen target
382 *
383 * @dev_priv: Pointer to a device private struct.
384 * @crtc: The crtc holding the screen target.
385 * @mode: The mode currently used by the screen target. Must be non-NULL.
386 * @new_fb: The new framebuffer to bind. Must be non-NULL.
387 *
388 * RETURNS:
389 * 0 on success, error code on failure.
390 */
391static int vmw_stdu_bind_fb(struct vmw_private *dev_priv,
392 struct drm_crtc *crtc,
393 struct drm_display_mode *mode,
394 struct drm_framebuffer *new_fb)
395{
396 struct vmw_screen_target_display_unit *stdu = vmw_crtc_to_stdu(crtc);
397 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb);
398 struct vmw_surface *new_display_srf = NULL;
399 enum stdu_content_type new_content_type;
400 struct vmw_framebuffer_surface *new_vfbs;
401 int ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700402
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100403 WARN_ON_ONCE(!stdu->defined);
404
Thomas Hellstrombeca4cf2016-06-29 13:37:35 -0700405 new_vfbs = (vfb->dmabuf) ? NULL : vmw_framebuffer_to_vfbs(new_fb);
406
407 if (new_vfbs && new_vfbs->surface->base_size.width == mode->hdisplay &&
408 new_vfbs->surface->base_size.height == mode->vdisplay)
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100409 new_content_type = SAME_AS_DISPLAY;
410 else if (vfb->dmabuf)
411 new_content_type = SEPARATE_DMA;
412 else
413 new_content_type = SEPARATE_SURFACE;
414
415 if (new_content_type != SAME_AS_DISPLAY &&
416 !stdu->display_srf) {
417 struct vmw_surface content_srf;
418 struct drm_vmw_size display_base_size = {0};
419
420 display_base_size.width = mode->hdisplay;
421 display_base_size.height = mode->vdisplay;
422 display_base_size.depth = 1;
423
424 /*
425 * If content buffer is a DMA buf, then we have to construct
426 * surface info
427 */
428 if (new_content_type == SEPARATE_DMA) {
429
Ville Syrjälä272725c2016-12-14 23:32:20 +0200430 switch (new_fb->format->cpp[0] * 8) {
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100431 case 32:
432 content_srf.format = SVGA3D_X8R8G8B8;
433 break;
434
435 case 16:
436 content_srf.format = SVGA3D_R5G6B5;
437 break;
438
439 case 8:
440 content_srf.format = SVGA3D_P8;
441 break;
442
443 default:
444 DRM_ERROR("Invalid format\n");
445 return -EINVAL;
446 }
447
448 content_srf.flags = 0;
449 content_srf.mip_levels[0] = 1;
450 content_srf.multisample_count = 0;
451 } else {
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100452 content_srf = *new_vfbs->surface;
453 }
454
455
456 ret = vmw_surface_gb_priv_define(crtc->dev,
457 0, /* because kernel visible only */
458 content_srf.flags,
459 content_srf.format,
460 true, /* a scanout buffer */
461 content_srf.mip_levels[0],
462 content_srf.multisample_count,
463 0,
464 display_base_size,
465 &new_display_srf);
466 if (unlikely(ret != 0)) {
467 DRM_ERROR("Could not allocate screen target surface.\n");
468 return ret;
469 }
470 } else if (new_content_type == SAME_AS_DISPLAY) {
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100471 new_display_srf = vmw_surface_reference(new_vfbs->surface);
472 }
473
474 if (new_display_srf) {
475 /* Pin new surface before flipping */
476 ret = vmw_resource_pin(&new_display_srf->res, false);
477 if (ret)
478 goto out_srf_unref;
479
480 ret = vmw_stdu_bind_st(dev_priv, stdu, &new_display_srf->res);
481 if (ret)
482 goto out_srf_unpin;
483
484 /* Unpin and unreference old surface */
485 vmw_stdu_unpin_display(stdu);
486
487 /* Transfer the reference */
488 stdu->display_srf = new_display_srf;
489 new_display_srf = NULL;
490 }
491
492 crtc->primary->fb = new_fb;
493 stdu->content_fb_type = new_content_type;
494 return 0;
495
496out_srf_unpin:
497 vmw_resource_unpin(&new_display_srf->res);
498out_srf_unref:
499 vmw_surface_unreference(&new_display_srf);
500 return ret;
501}
Sinclair Yeh35c05122015-06-26 01:42:06 -0700502
Sinclair Yeh06ec4192017-03-23 13:14:54 -0700503
504/**
505 * vmw_stdu_crtc_mode_set_nofb - Updates screen target size
506 *
507 * @crtc: CRTC associated with the screen target
508 *
509 * This function defines/destroys a screen target
510 *
511 */
512static void vmw_stdu_crtc_mode_set_nofb(struct drm_crtc *crtc)
513{
514 struct vmw_private *dev_priv;
515 struct vmw_screen_target_display_unit *stdu;
516 int ret;
517
518
519 stdu = vmw_crtc_to_stdu(crtc);
520 dev_priv = vmw_priv(crtc->dev);
521
522 if (stdu->defined) {
523 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
524 if (ret)
525 DRM_ERROR("Failed to blank CRTC\n");
526
527 (void) vmw_stdu_update_st(dev_priv, stdu);
528
529 ret = vmw_stdu_destroy_st(dev_priv, stdu);
530 if (ret)
531 DRM_ERROR("Failed to destroy Screen Target\n");
532
533 stdu->content_fb_type = SAME_AS_DISPLAY;
534 }
535
536 if (!crtc->state->enable)
537 return;
538
539 vmw_svga_enable(dev_priv);
540 ret = vmw_stdu_define_st(dev_priv, stdu, &crtc->mode, crtc->x, crtc->y);
541
542 if (ret)
543 DRM_ERROR("Failed to define Screen Target of size %dx%d\n",
544 crtc->x, crtc->y);
545}
546
547
548static void vmw_stdu_crtc_helper_prepare(struct drm_crtc *crtc)
549{
550}
551
552
553static void vmw_stdu_crtc_helper_commit(struct drm_crtc *crtc)
554{
555 struct vmw_private *dev_priv;
556 struct vmw_screen_target_display_unit *stdu;
557 struct vmw_framebuffer *vfb;
558 struct drm_framebuffer *fb;
559
560
561 stdu = vmw_crtc_to_stdu(crtc);
562 dev_priv = vmw_priv(crtc->dev);
563 fb = crtc->primary->fb;
564
565 vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL;
566
567 if (vfb)
568 vmw_kms_add_active(dev_priv, &stdu->base, vfb);
569 else
570 vmw_kms_del_active(dev_priv, &stdu->base);
571}
572
573static void vmw_stdu_crtc_helper_disable(struct drm_crtc *crtc)
574{
575 struct vmw_private *dev_priv;
576 struct vmw_screen_target_display_unit *stdu;
577 int ret;
578
579
580 if (!crtc) {
581 DRM_ERROR("CRTC is NULL\n");
582 return;
583 }
584
585 stdu = vmw_crtc_to_stdu(crtc);
586 dev_priv = vmw_priv(crtc->dev);
587
588 if (stdu->defined) {
589 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
590 if (ret)
591 DRM_ERROR("Failed to blank CRTC\n");
592
593 (void) vmw_stdu_update_st(dev_priv, stdu);
594
595 ret = vmw_stdu_destroy_st(dev_priv, stdu);
596 if (ret)
597 DRM_ERROR("Failed to destroy Screen Target\n");
598
599 stdu->content_fb_type = SAME_AS_DISPLAY;
600 }
601}
602
Sinclair Yeh35c05122015-06-26 01:42:06 -0700603/**
604 * vmw_stdu_crtc_set_config - Sets a mode
605 *
606 * @set: mode parameters
607 *
608 * This function is the device-specific portion of the DRM CRTC mode set.
609 * For the SVGA device, we do this by defining a Screen Target, binding a
610 * GB Surface to that target, and finally update the screen target.
611 *
612 * RETURNS:
613 * 0 on success, error code otherwise
614 */
615static int vmw_stdu_crtc_set_config(struct drm_mode_set *set)
616{
617 struct vmw_private *dev_priv;
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100618 struct vmw_framebuffer *vfb;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700619 struct vmw_screen_target_display_unit *stdu;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700620 struct drm_display_mode *mode;
621 struct drm_framebuffer *new_fb;
622 struct drm_crtc *crtc;
623 struct drm_encoder *encoder;
624 struct drm_connector *connector;
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100625 bool turning_off;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700626 int ret;
627
628
629 if (!set || !set->crtc)
630 return -EINVAL;
631
632 crtc = set->crtc;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700633 stdu = vmw_crtc_to_stdu(crtc);
634 mode = set->mode;
635 new_fb = set->fb;
636 dev_priv = vmw_priv(crtc->dev);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100637 turning_off = set->num_connectors == 0 || !mode || !new_fb;
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100638 vfb = (new_fb) ? vmw_framebuffer_to_vfb(new_fb) : NULL;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700639
640 if (set->num_connectors > 1) {
641 DRM_ERROR("Too many connectors\n");
642 return -EINVAL;
643 }
644
645 if (set->num_connectors == 1 &&
646 set->connectors[0] != &stdu->base.connector) {
647 DRM_ERROR("Connectors don't match %p %p\n",
648 set->connectors[0], &stdu->base.connector);
649 return -EINVAL;
650 }
651
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100652 if (!turning_off && (set->x + mode->hdisplay > new_fb->width ||
653 set->y + mode->vdisplay > new_fb->height)) {
654 DRM_ERROR("Set outside of framebuffer\n");
655 return -EINVAL;
656 }
Sinclair Yeh35c05122015-06-26 01:42:06 -0700657
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100658 /* Only one active implicit frame-buffer at a time. */
Thomas Hellstrom93cd1682016-05-03 11:24:35 +0200659 mutex_lock(&dev_priv->global_kms_state_mutex);
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100660 if (!turning_off && stdu->base.is_implicit && dev_priv->implicit_fb &&
661 !(dev_priv->num_implicit == 1 && stdu->base.active_implicit)
662 && dev_priv->implicit_fb != vfb) {
Thomas Hellstrom93cd1682016-05-03 11:24:35 +0200663 mutex_unlock(&dev_priv->global_kms_state_mutex);
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100664 DRM_ERROR("Multiple implicit framebuffers not supported.\n");
665 return -EINVAL;
666 }
Thomas Hellstrom93cd1682016-05-03 11:24:35 +0200667 mutex_unlock(&dev_priv->global_kms_state_mutex);
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100668
Sinclair Yeh35c05122015-06-26 01:42:06 -0700669 /* Since they always map one to one these are safe */
670 connector = &stdu->base.connector;
671 encoder = &stdu->base.encoder;
672
Sinclair Yeh35c05122015-06-26 01:42:06 -0700673 if (stdu->defined) {
Sinclair Yeh35c05122015-06-26 01:42:06 -0700674 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100675 if (ret)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700676 return ret;
677
Sinclair Yeh35c05122015-06-26 01:42:06 -0700678 vmw_stdu_unpin_display(stdu);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100679 (void) vmw_stdu_update_st(dev_priv, stdu);
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100680 vmw_kms_del_active(dev_priv, &stdu->base);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700681
682 ret = vmw_stdu_destroy_st(dev_priv, stdu);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100683 if (ret)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700684 return ret;
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100685
686 crtc->primary->fb = NULL;
687 crtc->enabled = false;
688 encoder->crtc = NULL;
689 connector->encoder = NULL;
690 stdu->content_fb_type = SAME_AS_DISPLAY;
691 crtc->x = set->x;
692 crtc->y = set->y;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700693 }
694
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100695 if (turning_off)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700696 return 0;
697
Sinclair Yeh35c05122015-06-26 01:42:06 -0700698 /*
699 * Steps to displaying a surface, assume surface is already
700 * bound:
701 * 1. define a screen target
702 * 2. bind a fb to the screen target
703 * 3. update that screen target (this is done later by
704 * vmw_kms_stdu_do_surface_dirty_or_present)
705 */
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100706 /*
707 * Note on error handling: We can't really restore the crtc to
708 * it's original state on error, but we at least update the
709 * current state to what's submitted to hardware to enable
710 * future recovery.
711 */
712 vmw_svga_enable(dev_priv);
713 ret = vmw_stdu_define_st(dev_priv, stdu, mode, set->x, set->y);
714 if (ret)
715 return ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700716
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100717 crtc->x = set->x;
718 crtc->y = set->y;
719 crtc->mode = *mode;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700720
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100721 ret = vmw_stdu_bind_fb(dev_priv, crtc, mode, new_fb);
722 if (ret)
723 return ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700724
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100725 vmw_kms_add_active(dev_priv, &stdu->base, vfb);
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100726 crtc->enabled = true;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700727 connector->encoder = encoder;
728 encoder->crtc = crtc;
729
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100730 return 0;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700731}
732
Sinclair Yeh35c05122015-06-26 01:42:06 -0700733/**
734 * vmw_stdu_crtc_page_flip - Binds a buffer to a screen target
735 *
736 * @crtc: CRTC to attach FB to
737 * @fb: FB to attach
738 * @event: Event to be posted. This event should've been alloced
739 * using k[mz]alloc, and should've been completely initialized.
740 * @page_flip_flags: Input flags.
741 *
742 * If the STDU uses the same display and content buffers, i.e. a true flip,
743 * this function will replace the existing display buffer with the new content
744 * buffer.
745 *
746 * If the STDU uses different display and content buffers, i.e. a blit, then
747 * only the content buffer will be updated.
748 *
749 * RETURNS:
750 * 0 on success, error code on failure
751 */
752static int vmw_stdu_crtc_page_flip(struct drm_crtc *crtc,
753 struct drm_framebuffer *new_fb,
754 struct drm_pending_vblank_event *event,
755 uint32_t flags)
756
757{
758 struct vmw_private *dev_priv = vmw_priv(crtc->dev);
759 struct vmw_screen_target_display_unit *stdu;
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100760 struct drm_vmw_rect vclips;
761 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700762 int ret;
763
Sinclair Yeh35c05122015-06-26 01:42:06 -0700764 dev_priv = vmw_priv(crtc->dev);
765 stdu = vmw_crtc_to_stdu(crtc);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700766
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100767 if (!stdu->defined || !vmw_kms_crtc_flippable(dev_priv, crtc))
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100768 return -EINVAL;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700769
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100770 ret = vmw_stdu_bind_fb(dev_priv, crtc, &crtc->mode, new_fb);
771 if (ret)
772 return ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700773
Thomas Hellstrom4d492a02016-02-12 09:01:29 +0100774 if (stdu->base.is_implicit)
775 vmw_kms_update_implicit_fb(dev_priv, crtc);
776
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100777 vclips.x = crtc->x;
778 vclips.y = crtc->y;
779 vclips.w = crtc->mode.hdisplay;
780 vclips.h = crtc->mode.vdisplay;
781 if (vfb->dmabuf)
782 ret = vmw_kms_stdu_dma(dev_priv, NULL, vfb, NULL, NULL, &vclips,
783 1, 1, true, false);
784 else
785 ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, &vclips,
786 NULL, 0, 0, 1, 1, NULL);
787 if (ret)
Sinclair Yeh35c05122015-06-26 01:42:06 -0700788 return ret;
789
790 if (event) {
791 struct vmw_fence_obj *fence = NULL;
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700792 struct drm_file *file_priv = event->base.file_priv;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700793
794 vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL);
795 if (!fence)
796 return -ENOMEM;
797
798 ret = vmw_event_fence_action_queue(file_priv, fence,
799 &event->base,
800 &event->event.tv_sec,
801 &event->event.tv_usec,
802 true);
803 vmw_fence_obj_unreference(&fence);
Thomas Hellstrom4e0858a2015-11-05 02:18:55 -0800804 } else {
805 vmw_fifo_flush(dev_priv, false);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700806 }
807
Thomas Hellstromb1097ae2016-02-12 08:54:07 +0100808 return 0;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700809}
810
811
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700812/**
813 * vmw_stdu_dmabuf_clip - Callback to encode a suface DMA command cliprect
814 *
815 * @dirty: The closure structure.
816 *
817 * Encodes a surface DMA command cliprect and updates the bounding box
818 * for the DMA.
819 */
820static void vmw_stdu_dmabuf_clip(struct vmw_kms_dirty *dirty)
821{
822 struct vmw_stdu_dirty *ddirty =
823 container_of(dirty, struct vmw_stdu_dirty, base);
824 struct vmw_stdu_dma *cmd = dirty->cmd;
825 struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
826
827 blit += dirty->num_hits;
828 blit->srcx = dirty->fb_x;
829 blit->srcy = dirty->fb_y;
830 blit->x = dirty->unit_x1;
831 blit->y = dirty->unit_y1;
832 blit->d = 1;
833 blit->w = dirty->unit_x2 - dirty->unit_x1;
834 blit->h = dirty->unit_y2 - dirty->unit_y1;
835 dirty->num_hits++;
836
837 if (ddirty->transfer != SVGA3D_WRITE_HOST_VRAM)
838 return;
839
840 /* Destination bounding box */
841 ddirty->left = min_t(s32, ddirty->left, dirty->unit_x1);
842 ddirty->top = min_t(s32, ddirty->top, dirty->unit_y1);
843 ddirty->right = max_t(s32, ddirty->right, dirty->unit_x2);
844 ddirty->bottom = max_t(s32, ddirty->bottom, dirty->unit_y2);
845}
846
847/**
848 * vmw_stdu_dmabuf_fifo_commit - Callback to fill in and submit a DMA command.
849 *
850 * @dirty: The closure structure.
851 *
852 * Fills in the missing fields in a DMA command, and optionally encodes
853 * a screen target update command, depending on transfer direction.
854 */
855static void vmw_stdu_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
856{
857 struct vmw_stdu_dirty *ddirty =
858 container_of(dirty, struct vmw_stdu_dirty, base);
859 struct vmw_screen_target_display_unit *stdu =
860 container_of(dirty->unit, typeof(*stdu), base);
861 struct vmw_stdu_dma *cmd = dirty->cmd;
862 struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
863 SVGA3dCmdSurfaceDMASuffix *suffix =
864 (SVGA3dCmdSurfaceDMASuffix *) &blit[dirty->num_hits];
865 size_t blit_size = sizeof(*blit) * dirty->num_hits + sizeof(*suffix);
866
867 if (!dirty->num_hits) {
868 vmw_fifo_commit(dirty->dev_priv, 0);
869 return;
870 }
871
872 cmd->header.id = SVGA_3D_CMD_SURFACE_DMA;
873 cmd->header.size = sizeof(cmd->body) + blit_size;
874 vmw_bo_get_guest_ptr(&ddirty->buf->base, &cmd->body.guest.ptr);
875 cmd->body.guest.pitch = ddirty->pitch;
876 cmd->body.host.sid = stdu->display_srf->res.id;
877 cmd->body.host.face = 0;
878 cmd->body.host.mipmap = 0;
879 cmd->body.transfer = ddirty->transfer;
880 suffix->suffixSize = sizeof(*suffix);
881 suffix->maximumOffset = ddirty->buf->base.num_pages * PAGE_SIZE;
882
883 if (ddirty->transfer == SVGA3D_WRITE_HOST_VRAM) {
884 blit_size += sizeof(struct vmw_stdu_update);
885
886 vmw_stdu_populate_update(&suffix[1], stdu->base.unit,
887 ddirty->left, ddirty->right,
888 ddirty->top, ddirty->bottom);
889 }
890
891 vmw_fifo_commit(dirty->dev_priv, sizeof(*cmd) + blit_size);
892
893 ddirty->left = ddirty->top = S32_MAX;
894 ddirty->right = ddirty->bottom = S32_MIN;
895}
896
897/**
898 * vmw_kms_stdu_dma - Perform a DMA transfer between a dma-buffer backed
899 * framebuffer and the screen target system.
900 *
901 * @dev_priv: Pointer to the device private structure.
902 * @file_priv: Pointer to a struct drm-file identifying the caller. May be
903 * set to NULL, but then @user_fence_rep must also be set to NULL.
904 * @vfb: Pointer to the dma-buffer backed framebuffer.
905 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
906 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
907 * be NULL.
908 * @num_clips: Number of clip rects in @clips or @vclips.
909 * @increment: Increment to use when looping over @clips or @vclips.
910 * @to_surface: Whether to DMA to the screen target system as opposed to
911 * from the screen target system.
912 * @interruptible: Whether to perform waits interruptible if possible.
913 *
914 * If DMA-ing till the screen target system, the function will also notify
915 * the screen target system that a bounding box of the cliprects has been
916 * updated.
917 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
918 * interrupted.
919 */
920int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
921 struct drm_file *file_priv,
922 struct vmw_framebuffer *vfb,
923 struct drm_vmw_fence_rep __user *user_fence_rep,
924 struct drm_clip_rect *clips,
925 struct drm_vmw_rect *vclips,
926 uint32_t num_clips,
927 int increment,
928 bool to_surface,
929 bool interruptible)
930{
931 struct vmw_dma_buffer *buf =
932 container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
933 struct vmw_stdu_dirty ddirty;
934 int ret;
935
936 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
937 false);
938 if (ret)
939 return ret;
940
941 ddirty.transfer = (to_surface) ? SVGA3D_WRITE_HOST_VRAM :
942 SVGA3D_READ_HOST_VRAM;
943 ddirty.left = ddirty.top = S32_MAX;
944 ddirty.right = ddirty.bottom = S32_MIN;
945 ddirty.pitch = vfb->base.pitches[0];
946 ddirty.buf = buf;
947 ddirty.base.fifo_commit = vmw_stdu_dmabuf_fifo_commit;
948 ddirty.base.clip = vmw_stdu_dmabuf_clip;
949 ddirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_dma) +
950 num_clips * sizeof(SVGA3dCopyBox) +
951 sizeof(SVGA3dCmdSurfaceDMASuffix);
952 if (to_surface)
953 ddirty.base.fifo_reserve_size += sizeof(struct vmw_stdu_update);
954
955 ret = vmw_kms_helper_dirty(dev_priv, vfb, clips, vclips,
956 0, 0, num_clips, increment, &ddirty.base);
957 vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
958 user_fence_rep);
959
960 return ret;
961}
962
963/**
964 * vmw_stdu_surface_clip - Callback to encode a surface copy command cliprect
965 *
966 * @dirty: The closure structure.
967 *
968 * Encodes a surface copy command cliprect and updates the bounding box
969 * for the copy.
970 */
971static void vmw_kms_stdu_surface_clip(struct vmw_kms_dirty *dirty)
972{
973 struct vmw_stdu_dirty *sdirty =
974 container_of(dirty, struct vmw_stdu_dirty, base);
975 struct vmw_stdu_surface_copy *cmd = dirty->cmd;
976 struct vmw_screen_target_display_unit *stdu =
977 container_of(dirty->unit, typeof(*stdu), base);
978
979 if (sdirty->sid != stdu->display_srf->res.id) {
980 struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
981
982 blit += dirty->num_hits;
983 blit->srcx = dirty->fb_x;
984 blit->srcy = dirty->fb_y;
985 blit->x = dirty->unit_x1;
986 blit->y = dirty->unit_y1;
987 blit->d = 1;
988 blit->w = dirty->unit_x2 - dirty->unit_x1;
989 blit->h = dirty->unit_y2 - dirty->unit_y1;
990 }
991
992 dirty->num_hits++;
993
994 /* Destination bounding box */
995 sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
996 sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
997 sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
998 sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
999}
1000
1001/**
1002 * vmw_stdu_surface_fifo_commit - Callback to fill in and submit a surface
1003 * copy command.
1004 *
1005 * @dirty: The closure structure.
1006 *
1007 * Fills in the missing fields in a surface copy command, and encodes a screen
1008 * target update command.
1009 */
1010static void vmw_kms_stdu_surface_fifo_commit(struct vmw_kms_dirty *dirty)
1011{
1012 struct vmw_stdu_dirty *sdirty =
1013 container_of(dirty, struct vmw_stdu_dirty, base);
1014 struct vmw_screen_target_display_unit *stdu =
1015 container_of(dirty->unit, typeof(*stdu), base);
1016 struct vmw_stdu_surface_copy *cmd = dirty->cmd;
1017 struct vmw_stdu_update *update;
1018 size_t blit_size = sizeof(SVGA3dCopyBox) * dirty->num_hits;
1019 size_t commit_size;
1020
1021 if (!dirty->num_hits) {
1022 vmw_fifo_commit(dirty->dev_priv, 0);
1023 return;
1024 }
1025
1026 if (sdirty->sid != stdu->display_srf->res.id) {
1027 struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
1028
1029 cmd->header.id = SVGA_3D_CMD_SURFACE_COPY;
1030 cmd->header.size = sizeof(cmd->body) + blit_size;
1031 cmd->body.src.sid = sdirty->sid;
1032 cmd->body.dest.sid = stdu->display_srf->res.id;
1033 update = (struct vmw_stdu_update *) &blit[dirty->num_hits];
1034 commit_size = sizeof(*cmd) + blit_size + sizeof(*update);
1035 } else {
1036 update = dirty->cmd;
1037 commit_size = sizeof(*update);
1038 }
1039
1040 vmw_stdu_populate_update(update, stdu->base.unit, sdirty->left,
1041 sdirty->right, sdirty->top, sdirty->bottom);
1042
1043 vmw_fifo_commit(dirty->dev_priv, commit_size);
1044
1045 sdirty->left = sdirty->top = S32_MAX;
1046 sdirty->right = sdirty->bottom = S32_MIN;
1047}
1048
1049/**
1050 * vmw_kms_stdu_surface_dirty - Dirty part of a surface backed framebuffer
1051 *
1052 * @dev_priv: Pointer to the device private structure.
1053 * @framebuffer: Pointer to the surface-buffer backed framebuffer.
1054 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
1055 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
1056 * be NULL.
1057 * @srf: Pointer to surface to blit from. If NULL, the surface attached
1058 * to @framebuffer will be used.
1059 * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
1060 * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
1061 * @num_clips: Number of clip rects in @clips.
1062 * @inc: Increment to use when looping over @clips.
1063 * @out_fence: If non-NULL, will return a ref-counted pointer to a
1064 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
1065 * case the device has already synchronized.
1066 *
1067 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
1068 * interrupted.
1069 */
1070int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
1071 struct vmw_framebuffer *framebuffer,
1072 struct drm_clip_rect *clips,
1073 struct drm_vmw_rect *vclips,
1074 struct vmw_resource *srf,
1075 s32 dest_x,
1076 s32 dest_y,
1077 unsigned num_clips, int inc,
1078 struct vmw_fence_obj **out_fence)
1079{
1080 struct vmw_framebuffer_surface *vfbs =
1081 container_of(framebuffer, typeof(*vfbs), base);
1082 struct vmw_stdu_dirty sdirty;
1083 int ret;
1084
1085 if (!srf)
1086 srf = &vfbs->surface->res;
1087
1088 ret = vmw_kms_helper_resource_prepare(srf, true);
1089 if (ret)
1090 return ret;
1091
1092 if (vfbs->is_dmabuf_proxy) {
1093 ret = vmw_kms_update_proxy(srf, clips, num_clips, inc);
1094 if (ret)
1095 goto out_finish;
1096 }
1097
1098 sdirty.base.fifo_commit = vmw_kms_stdu_surface_fifo_commit;
1099 sdirty.base.clip = vmw_kms_stdu_surface_clip;
1100 sdirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_surface_copy) +
1101 sizeof(SVGA3dCopyBox) * num_clips +
1102 sizeof(struct vmw_stdu_update);
1103 sdirty.sid = srf->id;
1104 sdirty.left = sdirty.top = S32_MAX;
1105 sdirty.right = sdirty.bottom = S32_MIN;
1106
1107 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
1108 dest_x, dest_y, num_clips, inc,
1109 &sdirty.base);
1110out_finish:
1111 vmw_kms_helper_resource_finish(srf, out_fence);
1112
1113 return ret;
1114}
1115
Sinclair Yeh35c05122015-06-26 01:42:06 -07001116
1117/*
1118 * Screen Target CRTC dispatch table
1119 */
Ville Syrjäläd7955fc2015-12-15 12:21:15 +01001120static const struct drm_crtc_funcs vmw_stdu_crtc_funcs = {
Sinclair Yeh35c05122015-06-26 01:42:06 -07001121 .gamma_set = vmw_du_crtc_gamma_set,
1122 .destroy = vmw_stdu_crtc_destroy,
Sinclair Yeh9c2542a2017-03-23 11:33:39 -07001123 .reset = vmw_du_crtc_reset,
1124 .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
1125 .atomic_destroy_state = vmw_du_crtc_destroy_state,
Sinclair Yeh35c05122015-06-26 01:42:06 -07001126 .set_config = vmw_stdu_crtc_set_config,
1127 .page_flip = vmw_stdu_crtc_page_flip,
1128};
1129
1130
1131
1132/******************************************************************************
1133 * Screen Target Display Unit Encoder Functions
1134 *****************************************************************************/
1135
1136/**
1137 * vmw_stdu_encoder_destroy - cleans up the STDU
1138 *
1139 * @encoder: used the get the containing STDU
1140 *
1141 * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
1142 * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
1143 * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
1144 * get called.
1145 */
1146static void vmw_stdu_encoder_destroy(struct drm_encoder *encoder)
1147{
1148 vmw_stdu_destroy(vmw_encoder_to_stdu(encoder));
1149}
1150
Ville Syrjäläd7955fc2015-12-15 12:21:15 +01001151static const struct drm_encoder_funcs vmw_stdu_encoder_funcs = {
Sinclair Yeh35c05122015-06-26 01:42:06 -07001152 .destroy = vmw_stdu_encoder_destroy,
1153};
1154
1155
1156
1157/******************************************************************************
1158 * Screen Target Display Unit Connector Functions
1159 *****************************************************************************/
1160
1161/**
1162 * vmw_stdu_connector_destroy - cleans up the STDU
1163 *
1164 * @connector: used to get the containing STDU
1165 *
1166 * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
1167 * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
1168 * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
1169 * get called.
1170 */
1171static void vmw_stdu_connector_destroy(struct drm_connector *connector)
1172{
1173 vmw_stdu_destroy(vmw_connector_to_stdu(connector));
1174}
1175
1176
1177
Ville Syrjäläd7955fc2015-12-15 12:21:15 +01001178static const struct drm_connector_funcs vmw_stdu_connector_funcs = {
Sinclair Yeh35c05122015-06-26 01:42:06 -07001179 .dpms = vmw_du_connector_dpms,
Sinclair Yeh35c05122015-06-26 01:42:06 -07001180 .detect = vmw_du_connector_detect,
1181 .fill_modes = vmw_du_connector_fill_modes,
1182 .set_property = vmw_du_connector_set_property,
1183 .destroy = vmw_stdu_connector_destroy,
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001184 .reset = vmw_du_connector_reset,
1185 .atomic_duplicate_state = vmw_du_connector_duplicate_state,
1186 .atomic_destroy_state = vmw_du_connector_destroy_state,
1187 .atomic_set_property = vmw_du_connector_atomic_set_property,
1188 .atomic_get_property = vmw_du_connector_atomic_get_property,
Sinclair Yeh35c05122015-06-26 01:42:06 -07001189};
1190
1191
1192
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001193/******************************************************************************
1194 * Screen Target Display Plane Functions
1195 *****************************************************************************/
1196
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001197
1198
1199/**
1200 * vmw_stdu_primary_plane_cleanup_fb - Unpins the display surface
1201 *
1202 * @plane: display plane
1203 * @old_state: Contains the FB to clean up
1204 *
1205 * Unpins the display surface
1206 *
1207 * Returns 0 on success
1208 */
1209static void
1210vmw_stdu_primary_plane_cleanup_fb(struct drm_plane *plane,
1211 struct drm_plane_state *old_state)
1212{
1213 struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
1214
1215 if (vps->surf)
1216 WARN_ON(!vps->pinned);
1217
1218 vmw_du_plane_cleanup_fb(plane, old_state);
1219
1220 vps->content_fb_type = SAME_AS_DISPLAY;
1221}
1222
1223
1224
1225/**
1226 * vmw_stdu_primary_plane_prepare_fb - Readies the display surface
1227 *
1228 * @plane: display plane
1229 * @new_state: info on the new plane state, including the FB
1230 *
1231 * This function allocates a new display surface if the content is
1232 * backed by a DMA. The display surface is pinned here, and it'll
1233 * be unpinned in .cleanup_fb()
1234 *
1235 * Returns 0 on success
1236 */
1237static int
1238vmw_stdu_primary_plane_prepare_fb(struct drm_plane *plane,
1239 struct drm_plane_state *new_state)
1240{
1241 struct drm_framebuffer *new_fb = new_state->fb;
1242 struct vmw_framebuffer *vfb;
1243 struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
1244 enum stdu_content_type new_content_type;
1245 struct vmw_framebuffer_surface *new_vfbs;
1246 struct drm_crtc *crtc = new_state->crtc;
1247 uint32_t hdisplay = new_state->crtc_w, vdisplay = new_state->crtc_h;
1248 int ret;
1249
1250 /* No FB to prepare */
1251 if (!new_fb) {
1252 if (vps->surf) {
1253 WARN_ON(vps->pinned != 0);
1254 vmw_surface_unreference(&vps->surf);
1255 }
1256
1257 return 0;
1258 }
1259
1260 vfb = vmw_framebuffer_to_vfb(new_fb);
1261 new_vfbs = (vfb->dmabuf) ? NULL : vmw_framebuffer_to_vfbs(new_fb);
1262
1263 if (new_vfbs && new_vfbs->surface->base_size.width == hdisplay &&
1264 new_vfbs->surface->base_size.height == vdisplay)
1265 new_content_type = SAME_AS_DISPLAY;
1266 else if (vfb->dmabuf)
1267 new_content_type = SEPARATE_DMA;
1268 else
1269 new_content_type = SEPARATE_SURFACE;
1270
1271 if (new_content_type != SAME_AS_DISPLAY) {
1272 struct vmw_surface content_srf;
1273 struct drm_vmw_size display_base_size = {0};
1274
1275 display_base_size.width = hdisplay;
1276 display_base_size.height = vdisplay;
1277 display_base_size.depth = 1;
1278
1279 /*
1280 * If content buffer is a DMA buf, then we have to construct
1281 * surface info
1282 */
1283 if (new_content_type == SEPARATE_DMA) {
1284
1285 switch (new_fb->format->cpp[0]*8) {
1286 case 32:
1287 content_srf.format = SVGA3D_X8R8G8B8;
1288 break;
1289
1290 case 16:
1291 content_srf.format = SVGA3D_R5G6B5;
1292 break;
1293
1294 case 8:
1295 content_srf.format = SVGA3D_P8;
1296 break;
1297
1298 default:
1299 DRM_ERROR("Invalid format\n");
1300 return -EINVAL;
1301 }
1302
1303 content_srf.flags = 0;
1304 content_srf.mip_levels[0] = 1;
1305 content_srf.multisample_count = 0;
1306 } else {
1307 content_srf = *new_vfbs->surface;
1308 }
1309
1310 if (vps->surf) {
1311 struct drm_vmw_size cur_base_size = vps->surf->base_size;
1312
1313 if (cur_base_size.width != display_base_size.width ||
1314 cur_base_size.height != display_base_size.height ||
1315 vps->surf->format != content_srf.format) {
1316 WARN_ON(vps->pinned != 0);
1317 vmw_surface_unreference(&vps->surf);
1318 }
1319
1320 }
1321
1322 if (!vps->surf) {
1323 ret = vmw_surface_gb_priv_define
1324 (crtc->dev,
1325 /* Kernel visible only */
1326 0,
1327 content_srf.flags,
1328 content_srf.format,
1329 true, /* a scanout buffer */
1330 content_srf.mip_levels[0],
1331 content_srf.multisample_count,
1332 0,
1333 display_base_size,
1334 &vps->surf);
1335 if (ret != 0) {
1336 DRM_ERROR("Couldn't allocate STDU surface.\n");
1337 return ret;
1338 }
1339 }
1340 } else {
1341 /*
1342 * prepare_fb and clean_fb should only take care of pinning
1343 * and unpinning. References are tracked by state objects.
1344 * The only time we add a reference in prepare_fb is if the
1345 * state object doesn't have a reference to begin with
1346 */
1347 if (vps->surf) {
1348 WARN_ON(vps->pinned != 0);
1349 vmw_surface_unreference(&vps->surf);
1350 }
1351
1352 vps->surf = vmw_surface_reference(new_vfbs->surface);
1353 }
1354
1355 if (vps->surf) {
1356
1357 /* Pin new surface before flipping */
1358 ret = vmw_resource_pin(&vps->surf->res, false);
1359 if (ret)
1360 goto out_srf_unref;
1361
1362 vps->pinned++;
1363 }
1364
1365 vps->content_fb_type = new_content_type;
1366 return 0;
1367
1368out_srf_unref:
1369 vmw_surface_unreference(&vps->surf);
1370 return ret;
1371}
1372
1373
1374
1375/**
1376 * vmw_stdu_primary_plane_atomic_update - formally switches STDU to new plane
1377 *
1378 * @plane: display plane
1379 * @old_state: Only used to get crtc info
1380 *
1381 * Formally update stdu->display_srf to the new plane, and bind the new
1382 * plane STDU. This function is called during the commit phase when
1383 * all the preparation have been done and all the configurations have
1384 * been checked.
1385 */
1386static void
1387vmw_stdu_primary_plane_atomic_update(struct drm_plane *plane,
1388 struct drm_plane_state *old_state)
1389{
1390 struct vmw_private *dev_priv;
1391 struct vmw_screen_target_display_unit *stdu;
1392 struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state);
1393 struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc;
1394 int ret;
1395
1396 stdu = vmw_crtc_to_stdu(crtc);
1397 dev_priv = vmw_priv(crtc->dev);
1398
1399 stdu->display_srf = vps->surf;
1400 stdu->content_fb_type = vps->content_fb_type;
1401
1402 if (!stdu->defined)
1403 return;
1404
1405 if (plane->state->fb)
1406 ret = vmw_stdu_bind_st(dev_priv, stdu, &stdu->display_srf->res);
1407 else
1408 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
1409
1410 /*
1411 * We cannot really fail this function, so if we do, then output an
1412 * error and quit
1413 */
1414 if (ret)
1415 DRM_ERROR("Failed to bind surface to STDU.\n");
1416 else
1417 crtc->primary->fb = plane->state->fb;
1418}
1419
1420
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001421static const struct drm_plane_funcs vmw_stdu_plane_funcs = {
1422 .update_plane = drm_primary_helper_update,
1423 .disable_plane = drm_primary_helper_disable,
1424 .destroy = vmw_du_primary_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001425 .reset = vmw_du_plane_reset,
1426 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
1427 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001428};
1429
1430static const struct drm_plane_funcs vmw_stdu_cursor_funcs = {
1431 .update_plane = vmw_du_cursor_plane_update,
1432 .disable_plane = vmw_du_cursor_plane_disable,
1433 .destroy = vmw_du_cursor_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001434 .reset = vmw_du_plane_reset,
1435 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
1436 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001437};
1438
1439
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001440/*
1441 * Atomic Helpers
1442 */
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001443static const struct
1444drm_plane_helper_funcs vmw_stdu_cursor_plane_helper_funcs = {
1445 .atomic_check = vmw_du_cursor_plane_atomic_check,
1446 .atomic_update = vmw_du_cursor_plane_atomic_update,
1447 .prepare_fb = vmw_du_cursor_plane_prepare_fb,
1448 .cleanup_fb = vmw_du_plane_cleanup_fb,
1449};
1450
1451static const struct
1452drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
1453 .atomic_check = vmw_du_primary_plane_atomic_check,
1454 .atomic_update = vmw_stdu_primary_plane_atomic_update,
1455 .prepare_fb = vmw_stdu_primary_plane_prepare_fb,
1456 .cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
1457};
1458
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001459static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
1460 .prepare = vmw_stdu_crtc_helper_prepare,
1461 .commit = vmw_stdu_crtc_helper_commit,
1462 .disable = vmw_stdu_crtc_helper_disable,
1463 .mode_set = drm_helper_crtc_mode_set,
1464 .mode_set_nofb = vmw_stdu_crtc_mode_set_nofb,
1465 .atomic_check = vmw_du_crtc_atomic_check,
1466 .atomic_begin = vmw_du_crtc_atomic_begin,
1467 .atomic_flush = vmw_du_crtc_atomic_flush,
1468};
1469
1470
Sinclair Yeh35c05122015-06-26 01:42:06 -07001471/**
1472 * vmw_stdu_init - Sets up a Screen Target Display Unit
1473 *
1474 * @dev_priv: VMW DRM device
1475 * @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS
1476 *
1477 * This function is called once per CRTC, and allocates one Screen Target
1478 * display unit to represent that CRTC. Since the SVGA device does not separate
1479 * out encoder and connector, they are represented as part of the STDU as well.
1480 */
1481static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit)
1482{
1483 struct vmw_screen_target_display_unit *stdu;
1484 struct drm_device *dev = dev_priv->dev;
1485 struct drm_connector *connector;
1486 struct drm_encoder *encoder;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001487 struct drm_plane *primary, *cursor;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001488 struct drm_crtc *crtc;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001489 int ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001490
1491
1492 stdu = kzalloc(sizeof(*stdu), GFP_KERNEL);
1493 if (!stdu)
1494 return -ENOMEM;
1495
1496 stdu->base.unit = unit;
1497 crtc = &stdu->base.crtc;
1498 encoder = &stdu->base.encoder;
1499 connector = &stdu->base.connector;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001500 primary = &stdu->base.primary;
1501 cursor = &stdu->base.cursor;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001502
1503 stdu->base.pref_active = (unit == 0);
1504 stdu->base.pref_width = dev_priv->initial_width;
1505 stdu->base.pref_height = dev_priv->initial_height;
Sinclair Yeh9c2542a2017-03-23 11:33:39 -07001506
1507 /*
1508 * Remove this after enabling atomic because property values can
1509 * only exist in a state object
1510 */
Thomas Hellstrom2e69b252016-02-12 09:59:50 +01001511 stdu->base.is_implicit = false;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001512
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001513 /* Initialize primary plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001514 vmw_du_plane_reset(primary);
1515
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001516 ret = drm_universal_plane_init(dev, primary,
1517 0, &vmw_stdu_plane_funcs,
1518 vmw_primary_plane_formats,
1519 ARRAY_SIZE(vmw_primary_plane_formats),
1520 DRM_PLANE_TYPE_PRIMARY, NULL);
1521 if (ret) {
1522 DRM_ERROR("Failed to initialize primary plane");
1523 goto err_free;
1524 }
1525
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001526 drm_plane_helper_add(primary, &vmw_stdu_primary_plane_helper_funcs);
1527
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001528 /* Initialize cursor plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001529 vmw_du_plane_reset(cursor);
1530
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001531 ret = drm_universal_plane_init(dev, cursor,
1532 0, &vmw_stdu_cursor_funcs,
1533 vmw_cursor_plane_formats,
1534 ARRAY_SIZE(vmw_cursor_plane_formats),
1535 DRM_PLANE_TYPE_CURSOR, NULL);
1536 if (ret) {
1537 DRM_ERROR("Failed to initialize cursor plane");
1538 drm_plane_cleanup(&stdu->base.primary);
1539 goto err_free;
1540 }
1541
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001542 drm_plane_helper_add(cursor, &vmw_stdu_cursor_plane_helper_funcs);
1543
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001544 vmw_du_connector_reset(connector);
1545
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001546 ret = drm_connector_init(dev, connector, &vmw_stdu_connector_funcs,
1547 DRM_MODE_CONNECTOR_VIRTUAL);
1548 if (ret) {
1549 DRM_ERROR("Failed to initialize connector\n");
1550 goto err_free;
1551 }
Sinclair Yeh35c05122015-06-26 01:42:06 -07001552 connector->status = vmw_du_connector_detect(connector, false);
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001553 vmw_connector_state_to_vcs(connector->state)->is_implicit = false;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001554
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001555 ret = drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs,
1556 DRM_MODE_ENCODER_VIRTUAL, NULL);
1557 if (ret) {
1558 DRM_ERROR("Failed to initialize encoder\n");
1559 goto err_free_connector;
1560 }
1561
1562 (void) drm_mode_connector_attach_encoder(connector, encoder);
Sinclair Yeh35c05122015-06-26 01:42:06 -07001563 encoder->possible_crtcs = (1 << unit);
1564 encoder->possible_clones = 0;
1565
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001566 ret = drm_connector_register(connector);
1567 if (ret) {
1568 DRM_ERROR("Failed to register connector\n");
1569 goto err_free_encoder;
1570 }
Sinclair Yeh35c05122015-06-26 01:42:06 -07001571
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001572 vmw_du_crtc_reset(crtc);
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001573 ret = drm_crtc_init_with_planes(dev, crtc, &stdu->base.primary,
1574 &stdu->base.cursor,
1575 &vmw_stdu_crtc_funcs, NULL);
1576 if (ret) {
1577 DRM_ERROR("Failed to initialize CRTC\n");
1578 goto err_free_unregister;
1579 }
Sinclair Yeh35c05122015-06-26 01:42:06 -07001580
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001581 drm_crtc_helper_add(crtc, &vmw_stdu_crtc_helper_funcs);
1582
Sinclair Yeh35c05122015-06-26 01:42:06 -07001583 drm_mode_crtc_set_gamma_size(crtc, 256);
1584
1585 drm_object_attach_property(&connector->base,
Thomas Hellstrom578e6092016-02-12 09:45:42 +01001586 dev_priv->hotplug_mode_update_property, 1);
1587 drm_object_attach_property(&connector->base,
1588 dev->mode_config.suggested_x_property, 0);
1589 drm_object_attach_property(&connector->base,
1590 dev->mode_config.suggested_y_property, 0);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +01001591 if (dev_priv->implicit_placement_property)
1592 drm_object_attach_property
1593 (&connector->base,
1594 dev_priv->implicit_placement_property,
1595 stdu->base.is_implicit);
Sinclair Yeh35c05122015-06-26 01:42:06 -07001596 return 0;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001597
1598err_free_unregister:
1599 drm_connector_unregister(connector);
1600err_free_encoder:
1601 drm_encoder_cleanup(encoder);
1602err_free_connector:
1603 drm_connector_cleanup(connector);
1604err_free:
1605 kfree(stdu);
1606 return ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001607}
1608
1609
1610
1611/**
1612 * vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit
1613 *
1614 * @stdu: Screen Target Display Unit to be destroyed
1615 *
1616 * Clean up after vmw_stdu_init
1617 */
1618static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu)
1619{
1620 vmw_stdu_unpin_display(stdu);
1621
1622 vmw_du_cleanup(&stdu->base);
1623 kfree(stdu);
1624}
1625
1626
1627
1628/******************************************************************************
1629 * Screen Target Display KMS Functions
1630 *
1631 * These functions are called by the common KMS code in vmwgfx_kms.c
1632 *****************************************************************************/
1633
1634/**
1635 * vmw_kms_stdu_init_display - Initializes a Screen Target based display
1636 *
1637 * @dev_priv: VMW DRM device
1638 *
1639 * This function initialize a Screen Target based display device. It checks
1640 * the capability bits to make sure the underlying hardware can support
1641 * screen targets, and then creates the maximum number of CRTCs, a.k.a Display
1642 * Units, as supported by the display hardware.
1643 *
1644 * RETURNS:
1645 * 0 on success, error code otherwise
1646 */
1647int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
1648{
1649 struct drm_device *dev = dev_priv->dev;
1650 int i, ret;
1651
1652
1653 /* Do nothing if Screen Target support is turned off */
1654 if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE)
1655 return -ENOSYS;
1656
Sinclair Yehf89c6c32015-06-26 01:54:28 -07001657 if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS))
Sinclair Yeh35c05122015-06-26 01:42:06 -07001658 return -ENOSYS;
1659
1660 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
1661 if (unlikely(ret != 0))
1662 return ret;
1663
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -07001664 dev_priv->active_display_unit = vmw_du_screen_target;
1665
Thomas Hellstrom76404ac2016-02-12 09:55:45 +01001666 vmw_kms_create_implicit_placement_property(dev_priv, false);
1667
Sinclair Yeh35c05122015-06-26 01:42:06 -07001668 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) {
1669 ret = vmw_stdu_init(dev_priv, i);
1670
1671 if (unlikely(ret != 0)) {
1672 DRM_ERROR("Failed to initialize STDU %d", i);
1673 goto err_vblank_cleanup;
1674 }
1675 }
1676
Sinclair Yeh35c05122015-06-26 01:42:06 -07001677 DRM_INFO("Screen Target Display device initialized\n");
1678
1679 return 0;
1680
1681err_vblank_cleanup:
1682 drm_vblank_cleanup(dev);
1683 return ret;
1684}
1685
1686
1687
1688/**
1689 * vmw_kms_stdu_close_display - Cleans up after vmw_kms_stdu_init_display
1690 *
1691 * @dev_priv: VMW DRM device
1692 *
1693 * Frees up any resources allocated by vmw_kms_stdu_init_display
1694 *
1695 * RETURNS:
1696 * 0 on success
1697 */
1698int vmw_kms_stdu_close_display(struct vmw_private *dev_priv)
1699{
1700 struct drm_device *dev = dev_priv->dev;
1701
1702 drm_vblank_cleanup(dev);
1703
1704 return 0;
1705}