blob: 76ca5fa1e3bfb9069bca219352939d7e041208fc [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
Sinclair Yehd947d1b2017-03-23 14:23:20 -07001192static const struct
1193drm_connector_helper_funcs vmw_stdu_connector_helper_funcs = {
1194 .best_encoder = drm_atomic_helper_best_encoder,
1195};
1196
1197
Sinclair Yeh35c05122015-06-26 01:42:06 -07001198
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001199/******************************************************************************
1200 * Screen Target Display Plane Functions
1201 *****************************************************************************/
1202
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001203
1204
1205/**
1206 * vmw_stdu_primary_plane_cleanup_fb - Unpins the display surface
1207 *
1208 * @plane: display plane
1209 * @old_state: Contains the FB to clean up
1210 *
1211 * Unpins the display surface
1212 *
1213 * Returns 0 on success
1214 */
1215static void
1216vmw_stdu_primary_plane_cleanup_fb(struct drm_plane *plane,
1217 struct drm_plane_state *old_state)
1218{
1219 struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
1220
1221 if (vps->surf)
1222 WARN_ON(!vps->pinned);
1223
1224 vmw_du_plane_cleanup_fb(plane, old_state);
1225
1226 vps->content_fb_type = SAME_AS_DISPLAY;
1227}
1228
1229
1230
1231/**
1232 * vmw_stdu_primary_plane_prepare_fb - Readies the display surface
1233 *
1234 * @plane: display plane
1235 * @new_state: info on the new plane state, including the FB
1236 *
1237 * This function allocates a new display surface if the content is
1238 * backed by a DMA. The display surface is pinned here, and it'll
1239 * be unpinned in .cleanup_fb()
1240 *
1241 * Returns 0 on success
1242 */
1243static int
1244vmw_stdu_primary_plane_prepare_fb(struct drm_plane *plane,
1245 struct drm_plane_state *new_state)
1246{
1247 struct drm_framebuffer *new_fb = new_state->fb;
1248 struct vmw_framebuffer *vfb;
1249 struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
1250 enum stdu_content_type new_content_type;
1251 struct vmw_framebuffer_surface *new_vfbs;
1252 struct drm_crtc *crtc = new_state->crtc;
1253 uint32_t hdisplay = new_state->crtc_w, vdisplay = new_state->crtc_h;
1254 int ret;
1255
1256 /* No FB to prepare */
1257 if (!new_fb) {
1258 if (vps->surf) {
1259 WARN_ON(vps->pinned != 0);
1260 vmw_surface_unreference(&vps->surf);
1261 }
1262
1263 return 0;
1264 }
1265
1266 vfb = vmw_framebuffer_to_vfb(new_fb);
1267 new_vfbs = (vfb->dmabuf) ? NULL : vmw_framebuffer_to_vfbs(new_fb);
1268
1269 if (new_vfbs && new_vfbs->surface->base_size.width == hdisplay &&
1270 new_vfbs->surface->base_size.height == vdisplay)
1271 new_content_type = SAME_AS_DISPLAY;
1272 else if (vfb->dmabuf)
1273 new_content_type = SEPARATE_DMA;
1274 else
1275 new_content_type = SEPARATE_SURFACE;
1276
1277 if (new_content_type != SAME_AS_DISPLAY) {
1278 struct vmw_surface content_srf;
1279 struct drm_vmw_size display_base_size = {0};
1280
1281 display_base_size.width = hdisplay;
1282 display_base_size.height = vdisplay;
1283 display_base_size.depth = 1;
1284
1285 /*
1286 * If content buffer is a DMA buf, then we have to construct
1287 * surface info
1288 */
1289 if (new_content_type == SEPARATE_DMA) {
1290
1291 switch (new_fb->format->cpp[0]*8) {
1292 case 32:
1293 content_srf.format = SVGA3D_X8R8G8B8;
1294 break;
1295
1296 case 16:
1297 content_srf.format = SVGA3D_R5G6B5;
1298 break;
1299
1300 case 8:
1301 content_srf.format = SVGA3D_P8;
1302 break;
1303
1304 default:
1305 DRM_ERROR("Invalid format\n");
1306 return -EINVAL;
1307 }
1308
1309 content_srf.flags = 0;
1310 content_srf.mip_levels[0] = 1;
1311 content_srf.multisample_count = 0;
1312 } else {
1313 content_srf = *new_vfbs->surface;
1314 }
1315
1316 if (vps->surf) {
1317 struct drm_vmw_size cur_base_size = vps->surf->base_size;
1318
1319 if (cur_base_size.width != display_base_size.width ||
1320 cur_base_size.height != display_base_size.height ||
1321 vps->surf->format != content_srf.format) {
1322 WARN_ON(vps->pinned != 0);
1323 vmw_surface_unreference(&vps->surf);
1324 }
1325
1326 }
1327
1328 if (!vps->surf) {
1329 ret = vmw_surface_gb_priv_define
1330 (crtc->dev,
1331 /* Kernel visible only */
1332 0,
1333 content_srf.flags,
1334 content_srf.format,
1335 true, /* a scanout buffer */
1336 content_srf.mip_levels[0],
1337 content_srf.multisample_count,
1338 0,
1339 display_base_size,
1340 &vps->surf);
1341 if (ret != 0) {
1342 DRM_ERROR("Couldn't allocate STDU surface.\n");
1343 return ret;
1344 }
1345 }
1346 } else {
1347 /*
1348 * prepare_fb and clean_fb should only take care of pinning
1349 * and unpinning. References are tracked by state objects.
1350 * The only time we add a reference in prepare_fb is if the
1351 * state object doesn't have a reference to begin with
1352 */
1353 if (vps->surf) {
1354 WARN_ON(vps->pinned != 0);
1355 vmw_surface_unreference(&vps->surf);
1356 }
1357
1358 vps->surf = vmw_surface_reference(new_vfbs->surface);
1359 }
1360
1361 if (vps->surf) {
1362
1363 /* Pin new surface before flipping */
1364 ret = vmw_resource_pin(&vps->surf->res, false);
1365 if (ret)
1366 goto out_srf_unref;
1367
1368 vps->pinned++;
1369 }
1370
1371 vps->content_fb_type = new_content_type;
1372 return 0;
1373
1374out_srf_unref:
1375 vmw_surface_unreference(&vps->surf);
1376 return ret;
1377}
1378
1379
1380
1381/**
1382 * vmw_stdu_primary_plane_atomic_update - formally switches STDU to new plane
1383 *
1384 * @plane: display plane
1385 * @old_state: Only used to get crtc info
1386 *
1387 * Formally update stdu->display_srf to the new plane, and bind the new
1388 * plane STDU. This function is called during the commit phase when
1389 * all the preparation have been done and all the configurations have
1390 * been checked.
1391 */
1392static void
1393vmw_stdu_primary_plane_atomic_update(struct drm_plane *plane,
1394 struct drm_plane_state *old_state)
1395{
1396 struct vmw_private *dev_priv;
1397 struct vmw_screen_target_display_unit *stdu;
1398 struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state);
1399 struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc;
1400 int ret;
1401
1402 stdu = vmw_crtc_to_stdu(crtc);
1403 dev_priv = vmw_priv(crtc->dev);
1404
1405 stdu->display_srf = vps->surf;
1406 stdu->content_fb_type = vps->content_fb_type;
1407
1408 if (!stdu->defined)
1409 return;
1410
1411 if (plane->state->fb)
1412 ret = vmw_stdu_bind_st(dev_priv, stdu, &stdu->display_srf->res);
1413 else
1414 ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
1415
1416 /*
1417 * We cannot really fail this function, so if we do, then output an
1418 * error and quit
1419 */
1420 if (ret)
1421 DRM_ERROR("Failed to bind surface to STDU.\n");
1422 else
1423 crtc->primary->fb = plane->state->fb;
1424}
1425
1426
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001427static const struct drm_plane_funcs vmw_stdu_plane_funcs = {
1428 .update_plane = drm_primary_helper_update,
1429 .disable_plane = drm_primary_helper_disable,
1430 .destroy = vmw_du_primary_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001431 .reset = vmw_du_plane_reset,
1432 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
1433 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001434};
1435
1436static const struct drm_plane_funcs vmw_stdu_cursor_funcs = {
1437 .update_plane = vmw_du_cursor_plane_update,
1438 .disable_plane = vmw_du_cursor_plane_disable,
1439 .destroy = vmw_du_cursor_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001440 .reset = vmw_du_plane_reset,
1441 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
1442 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001443};
1444
1445
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001446/*
1447 * Atomic Helpers
1448 */
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001449static const struct
1450drm_plane_helper_funcs vmw_stdu_cursor_plane_helper_funcs = {
1451 .atomic_check = vmw_du_cursor_plane_atomic_check,
1452 .atomic_update = vmw_du_cursor_plane_atomic_update,
1453 .prepare_fb = vmw_du_cursor_plane_prepare_fb,
1454 .cleanup_fb = vmw_du_plane_cleanup_fb,
1455};
1456
1457static const struct
1458drm_plane_helper_funcs vmw_stdu_primary_plane_helper_funcs = {
1459 .atomic_check = vmw_du_primary_plane_atomic_check,
1460 .atomic_update = vmw_stdu_primary_plane_atomic_update,
1461 .prepare_fb = vmw_stdu_primary_plane_prepare_fb,
1462 .cleanup_fb = vmw_stdu_primary_plane_cleanup_fb,
1463};
1464
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001465static const struct drm_crtc_helper_funcs vmw_stdu_crtc_helper_funcs = {
1466 .prepare = vmw_stdu_crtc_helper_prepare,
1467 .commit = vmw_stdu_crtc_helper_commit,
1468 .disable = vmw_stdu_crtc_helper_disable,
1469 .mode_set = drm_helper_crtc_mode_set,
1470 .mode_set_nofb = vmw_stdu_crtc_mode_set_nofb,
1471 .atomic_check = vmw_du_crtc_atomic_check,
1472 .atomic_begin = vmw_du_crtc_atomic_begin,
1473 .atomic_flush = vmw_du_crtc_atomic_flush,
1474};
1475
1476
Sinclair Yeh35c05122015-06-26 01:42:06 -07001477/**
1478 * vmw_stdu_init - Sets up a Screen Target Display Unit
1479 *
1480 * @dev_priv: VMW DRM device
1481 * @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS
1482 *
1483 * This function is called once per CRTC, and allocates one Screen Target
1484 * display unit to represent that CRTC. Since the SVGA device does not separate
1485 * out encoder and connector, they are represented as part of the STDU as well.
1486 */
1487static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit)
1488{
1489 struct vmw_screen_target_display_unit *stdu;
1490 struct drm_device *dev = dev_priv->dev;
1491 struct drm_connector *connector;
1492 struct drm_encoder *encoder;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001493 struct drm_plane *primary, *cursor;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001494 struct drm_crtc *crtc;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001495 int ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001496
1497
1498 stdu = kzalloc(sizeof(*stdu), GFP_KERNEL);
1499 if (!stdu)
1500 return -ENOMEM;
1501
1502 stdu->base.unit = unit;
1503 crtc = &stdu->base.crtc;
1504 encoder = &stdu->base.encoder;
1505 connector = &stdu->base.connector;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001506 primary = &stdu->base.primary;
1507 cursor = &stdu->base.cursor;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001508
1509 stdu->base.pref_active = (unit == 0);
1510 stdu->base.pref_width = dev_priv->initial_width;
1511 stdu->base.pref_height = dev_priv->initial_height;
Sinclair Yeh9c2542a2017-03-23 11:33:39 -07001512
1513 /*
1514 * Remove this after enabling atomic because property values can
1515 * only exist in a state object
1516 */
Thomas Hellstrom2e69b252016-02-12 09:59:50 +01001517 stdu->base.is_implicit = false;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001518
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001519 /* Initialize primary plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001520 vmw_du_plane_reset(primary);
1521
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001522 ret = drm_universal_plane_init(dev, primary,
1523 0, &vmw_stdu_plane_funcs,
1524 vmw_primary_plane_formats,
1525 ARRAY_SIZE(vmw_primary_plane_formats),
1526 DRM_PLANE_TYPE_PRIMARY, NULL);
1527 if (ret) {
1528 DRM_ERROR("Failed to initialize primary plane");
1529 goto err_free;
1530 }
1531
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001532 drm_plane_helper_add(primary, &vmw_stdu_primary_plane_helper_funcs);
1533
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001534 /* Initialize cursor plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -07001535 vmw_du_plane_reset(cursor);
1536
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001537 ret = drm_universal_plane_init(dev, cursor,
1538 0, &vmw_stdu_cursor_funcs,
1539 vmw_cursor_plane_formats,
1540 ARRAY_SIZE(vmw_cursor_plane_formats),
1541 DRM_PLANE_TYPE_CURSOR, NULL);
1542 if (ret) {
1543 DRM_ERROR("Failed to initialize cursor plane");
1544 drm_plane_cleanup(&stdu->base.primary);
1545 goto err_free;
1546 }
1547
Sinclair Yeh060e2ad2017-03-23 14:18:32 -07001548 drm_plane_helper_add(cursor, &vmw_stdu_cursor_plane_helper_funcs);
1549
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001550 vmw_du_connector_reset(connector);
1551
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001552 ret = drm_connector_init(dev, connector, &vmw_stdu_connector_funcs,
1553 DRM_MODE_CONNECTOR_VIRTUAL);
1554 if (ret) {
1555 DRM_ERROR("Failed to initialize connector\n");
1556 goto err_free;
1557 }
Sinclair Yehd947d1b2017-03-23 14:23:20 -07001558
1559 drm_connector_helper_add(connector, &vmw_stdu_connector_helper_funcs);
Sinclair Yeh35c05122015-06-26 01:42:06 -07001560 connector->status = vmw_du_connector_detect(connector, false);
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001561 vmw_connector_state_to_vcs(connector->state)->is_implicit = false;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001562
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001563 ret = drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs,
1564 DRM_MODE_ENCODER_VIRTUAL, NULL);
1565 if (ret) {
1566 DRM_ERROR("Failed to initialize encoder\n");
1567 goto err_free_connector;
1568 }
1569
1570 (void) drm_mode_connector_attach_encoder(connector, encoder);
Sinclair Yeh35c05122015-06-26 01:42:06 -07001571 encoder->possible_crtcs = (1 << unit);
1572 encoder->possible_clones = 0;
1573
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001574 ret = drm_connector_register(connector);
1575 if (ret) {
1576 DRM_ERROR("Failed to register connector\n");
1577 goto err_free_encoder;
1578 }
Sinclair Yeh35c05122015-06-26 01:42:06 -07001579
Sinclair Yehd7721ca2017-03-23 11:48:44 -07001580 vmw_du_crtc_reset(crtc);
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001581 ret = drm_crtc_init_with_planes(dev, crtc, &stdu->base.primary,
1582 &stdu->base.cursor,
1583 &vmw_stdu_crtc_funcs, NULL);
1584 if (ret) {
1585 DRM_ERROR("Failed to initialize CRTC\n");
1586 goto err_free_unregister;
1587 }
Sinclair Yeh35c05122015-06-26 01:42:06 -07001588
Sinclair Yeh06ec4192017-03-23 13:14:54 -07001589 drm_crtc_helper_add(crtc, &vmw_stdu_crtc_helper_funcs);
1590
Sinclair Yeh35c05122015-06-26 01:42:06 -07001591 drm_mode_crtc_set_gamma_size(crtc, 256);
1592
1593 drm_object_attach_property(&connector->base,
Thomas Hellstrom578e6092016-02-12 09:45:42 +01001594 dev_priv->hotplug_mode_update_property, 1);
1595 drm_object_attach_property(&connector->base,
1596 dev->mode_config.suggested_x_property, 0);
1597 drm_object_attach_property(&connector->base,
1598 dev->mode_config.suggested_y_property, 0);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +01001599 if (dev_priv->implicit_placement_property)
1600 drm_object_attach_property
1601 (&connector->base,
1602 dev_priv->implicit_placement_property,
1603 stdu->base.is_implicit);
Sinclair Yeh35c05122015-06-26 01:42:06 -07001604 return 0;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -07001605
1606err_free_unregister:
1607 drm_connector_unregister(connector);
1608err_free_encoder:
1609 drm_encoder_cleanup(encoder);
1610err_free_connector:
1611 drm_connector_cleanup(connector);
1612err_free:
1613 kfree(stdu);
1614 return ret;
Sinclair Yeh35c05122015-06-26 01:42:06 -07001615}
1616
1617
1618
1619/**
1620 * vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit
1621 *
1622 * @stdu: Screen Target Display Unit to be destroyed
1623 *
1624 * Clean up after vmw_stdu_init
1625 */
1626static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu)
1627{
1628 vmw_stdu_unpin_display(stdu);
1629
1630 vmw_du_cleanup(&stdu->base);
1631 kfree(stdu);
1632}
1633
1634
1635
1636/******************************************************************************
1637 * Screen Target Display KMS Functions
1638 *
1639 * These functions are called by the common KMS code in vmwgfx_kms.c
1640 *****************************************************************************/
1641
1642/**
1643 * vmw_kms_stdu_init_display - Initializes a Screen Target based display
1644 *
1645 * @dev_priv: VMW DRM device
1646 *
1647 * This function initialize a Screen Target based display device. It checks
1648 * the capability bits to make sure the underlying hardware can support
1649 * screen targets, and then creates the maximum number of CRTCs, a.k.a Display
1650 * Units, as supported by the display hardware.
1651 *
1652 * RETURNS:
1653 * 0 on success, error code otherwise
1654 */
1655int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
1656{
1657 struct drm_device *dev = dev_priv->dev;
1658 int i, ret;
1659
1660
1661 /* Do nothing if Screen Target support is turned off */
1662 if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE)
1663 return -ENOSYS;
1664
Sinclair Yehf89c6c32015-06-26 01:54:28 -07001665 if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS))
Sinclair Yeh35c05122015-06-26 01:42:06 -07001666 return -ENOSYS;
1667
1668 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
1669 if (unlikely(ret != 0))
1670 return ret;
1671
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -07001672 dev_priv->active_display_unit = vmw_du_screen_target;
1673
Thomas Hellstrom76404ac2016-02-12 09:55:45 +01001674 vmw_kms_create_implicit_placement_property(dev_priv, false);
1675
Sinclair Yeh35c05122015-06-26 01:42:06 -07001676 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) {
1677 ret = vmw_stdu_init(dev_priv, i);
1678
1679 if (unlikely(ret != 0)) {
1680 DRM_ERROR("Failed to initialize STDU %d", i);
1681 goto err_vblank_cleanup;
1682 }
1683 }
1684
Sinclair Yeh35c05122015-06-26 01:42:06 -07001685 DRM_INFO("Screen Target Display device initialized\n");
1686
1687 return 0;
1688
1689err_vblank_cleanup:
1690 drm_vblank_cleanup(dev);
1691 return ret;
1692}
1693
1694
1695
1696/**
1697 * vmw_kms_stdu_close_display - Cleans up after vmw_kms_stdu_init_display
1698 *
1699 * @dev_priv: VMW DRM device
1700 *
1701 * Frees up any resources allocated by vmw_kms_stdu_init_display
1702 *
1703 * RETURNS:
1704 * 0 on success
1705 */
1706int vmw_kms_stdu_close_display(struct vmw_private *dev_priv)
1707{
1708 struct drm_device *dev = dev_priv->dev;
1709
1710 drm_vblank_cleanup(dev);
1711
1712 return 0;
1713}