1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include "vmwgfx_kms.h"
29#include <drm/drm_plane_helper.h>
30#include <drm/drm_atomic.h>
31#include <drm/drm_atomic_helper.h>
32
33
34#define vmw_crtc_to_sou(x) \
35 container_of(x, struct vmw_screen_object_unit, base.crtc)
36#define vmw_encoder_to_sou(x) \
37 container_of(x, struct vmw_screen_object_unit, base.encoder)
38#define vmw_connector_to_sou(x) \
39 container_of(x, struct vmw_screen_object_unit, base.connector)
40
41
42
43
44
45
46
47
48
49
50
51
52
53struct vmw_kms_sou_surface_dirty {
54 struct vmw_kms_dirty base;
55 s32 left, right, top, bottom;
56 s32 dst_x, dst_y;
57 u32 sid;
58};
59
60
61
62
63
64struct vmw_kms_sou_readback_blit {
65 uint32 header;
66 SVGAFifoCmdBlitScreenToGMRFB body;
67};
68
69struct vmw_kms_sou_dmabuf_blit {
70 uint32 header;
71 SVGAFifoCmdBlitGMRFBToScreen body;
72};
73
74struct vmw_kms_sou_dirty_cmd {
75 SVGA3dCmdHeader header;
76 SVGA3dCmdBlitSurfaceToScreen body;
77};
78
79
80
81
82struct vmw_screen_object_unit {
83 struct vmw_display_unit base;
84
85 unsigned long buffer_size;
86 struct vmw_dma_buffer *buffer;
87
88 bool defined;
89};
90
91static void vmw_sou_destroy(struct vmw_screen_object_unit *sou)
92{
93 vmw_du_cleanup(&sou->base);
94 kfree(sou);
95}
96
97
98
99
100
101
102static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)
103{
104 vmw_sou_destroy(vmw_crtc_to_sou(crtc));
105}
106
107
108
109
110static int vmw_sou_fifo_create(struct vmw_private *dev_priv,
111 struct vmw_screen_object_unit *sou,
112 uint32_t x, uint32_t y,
113 struct drm_display_mode *mode)
114{
115 size_t fifo_size;
116
117 struct {
118 struct {
119 uint32_t cmdType;
120 } header;
121 SVGAScreenObject obj;
122 } *cmd;
123
124 BUG_ON(!sou->buffer);
125
126 fifo_size = sizeof(*cmd);
127 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
128
129 if (unlikely(cmd == NULL)) {
130 DRM_ERROR("Fifo reserve failed.\n");
131 return -ENOMEM;
132 }
133
134 memset(cmd, 0, fifo_size);
135 cmd->header.cmdType = SVGA_CMD_DEFINE_SCREEN;
136 cmd->obj.structSize = sizeof(SVGAScreenObject);
137 cmd->obj.id = sou->base.unit;
138 cmd->obj.flags = SVGA_SCREEN_HAS_ROOT |
139 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0);
140 cmd->obj.size.width = mode->hdisplay;
141 cmd->obj.size.height = mode->vdisplay;
142 if (sou->base.is_implicit) {
143 cmd->obj.root.x = x;
144 cmd->obj.root.y = y;
145 } else {
146 cmd->obj.root.x = sou->base.gui_x;
147 cmd->obj.root.y = sou->base.gui_y;
148 }
149 sou->base.set_gui_x = cmd->obj.root.x;
150 sou->base.set_gui_y = cmd->obj.root.y;
151
152
153 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr);
154 cmd->obj.backingStore.pitch = mode->hdisplay * 4;
155
156 vmw_fifo_commit(dev_priv, fifo_size);
157
158 sou->defined = true;
159
160 return 0;
161}
162
163
164
165
166static int vmw_sou_fifo_destroy(struct vmw_private *dev_priv,
167 struct vmw_screen_object_unit *sou)
168{
169 size_t fifo_size;
170 int ret;
171
172 struct {
173 struct {
174 uint32_t cmdType;
175 } header;
176 SVGAFifoCmdDestroyScreen body;
177 } *cmd;
178
179
180 if (unlikely(!sou->defined))
181 return 0;
182
183 fifo_size = sizeof(*cmd);
184 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
185
186 if (unlikely(cmd == NULL)) {
187 DRM_ERROR("Fifo reserve failed.\n");
188 return -ENOMEM;
189 }
190
191 memset(cmd, 0, fifo_size);
192 cmd->header.cmdType = SVGA_CMD_DESTROY_SCREEN;
193 cmd->body.screenId = sou->base.unit;
194
195 vmw_fifo_commit(dev_priv, fifo_size);
196
197
198 ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
199 if (unlikely(ret != 0))
200 DRM_ERROR("Failed to sync with HW");
201 else
202 sou->defined = false;
203
204 return ret;
205}
206
207
208
209
210
211
212
213
214
215static void vmw_sou_crtc_mode_set_nofb(struct drm_crtc *crtc)
216{
217 struct vmw_private *dev_priv;
218 struct vmw_screen_object_unit *sou;
219 struct vmw_framebuffer *vfb;
220 struct drm_framebuffer *fb;
221 struct drm_plane_state *ps;
222 struct vmw_plane_state *vps;
223 int ret;
224
225
226 sou = vmw_crtc_to_sou(crtc);
227 dev_priv = vmw_priv(crtc->dev);
228 ps = crtc->primary->state;
229 fb = ps->fb;
230 vps = vmw_plane_state_to_vps(ps);
231
232 vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL;
233
234 if (sou->defined) {
235 ret = vmw_sou_fifo_destroy(dev_priv, sou);
236 if (ret) {
237 DRM_ERROR("Failed to destroy Screen Object\n");
238 return;
239 }
240 }
241
242 if (vfb) {
243 sou->buffer = vps->dmabuf;
244 sou->buffer_size = vps->dmabuf_size;
245
246 ret = vmw_sou_fifo_create(dev_priv, sou, crtc->x, crtc->y,
247 &crtc->mode);
248 if (ret)
249 DRM_ERROR("Failed to define Screen Object %dx%d\n",
250 crtc->x, crtc->y);
251
252 vmw_kms_add_active(dev_priv, &sou->base, vfb);
253 } else {
254 sou->buffer = NULL;
255 sou->buffer_size = 0;
256
257 vmw_kms_del_active(dev_priv, &sou->base);
258 }
259}
260
261
262
263
264
265
266
267
268static void vmw_sou_crtc_helper_prepare(struct drm_crtc *crtc)
269{
270}
271
272
273
274
275
276
277
278
279static void vmw_sou_crtc_atomic_enable(struct drm_crtc *crtc,
280 struct drm_crtc_state *old_state)
281{
282}
283
284
285
286
287
288
289static void vmw_sou_crtc_atomic_disable(struct drm_crtc *crtc,
290 struct drm_crtc_state *old_state)
291{
292 struct vmw_private *dev_priv;
293 struct vmw_screen_object_unit *sou;
294 int ret;
295
296
297 if (!crtc) {
298 DRM_ERROR("CRTC is NULL\n");
299 return;
300 }
301
302 sou = vmw_crtc_to_sou(crtc);
303 dev_priv = vmw_priv(crtc->dev);
304
305 if (sou->defined) {
306 ret = vmw_sou_fifo_destroy(dev_priv, sou);
307 if (ret)
308 DRM_ERROR("Failed to destroy Screen Object\n");
309 }
310}
311
312static int vmw_sou_crtc_page_flip(struct drm_crtc *crtc,
313 struct drm_framebuffer *new_fb,
314 struct drm_pending_vblank_event *event,
315 uint32_t flags,
316 struct drm_modeset_acquire_ctx *ctx)
317{
318 struct vmw_private *dev_priv = vmw_priv(crtc->dev);
319 struct drm_framebuffer *old_fb = crtc->primary->fb;
320 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb);
321 struct vmw_fence_obj *fence = NULL;
322 struct drm_vmw_rect vclips;
323 int ret;
324
325 if (!vmw_kms_crtc_flippable(dev_priv, crtc))
326 return -EINVAL;
327
328 flags &= ~DRM_MODE_PAGE_FLIP_ASYNC;
329 ret = drm_atomic_helper_page_flip(crtc, new_fb, NULL, flags, ctx);
330 if (ret) {
331 DRM_ERROR("Page flip error %d.\n", ret);
332 return ret;
333 }
334
335
336 vclips.x = crtc->x;
337 vclips.y = crtc->y;
338 vclips.w = crtc->mode.hdisplay;
339 vclips.h = crtc->mode.vdisplay;
340
341 if (vfb->dmabuf)
342 ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, vfb,
343 NULL, &vclips, 1, 1,
344 true, &fence);
345 else
346 ret = vmw_kms_sou_do_surface_dirty(dev_priv, vfb,
347 NULL, &vclips, NULL,
348 0, 0, 1, 1, &fence);
349
350
351 if (ret != 0)
352 goto out_no_fence;
353 if (!fence) {
354 ret = -EINVAL;
355 goto out_no_fence;
356 }
357
358 if (event) {
359 struct drm_file *file_priv = event->base.file_priv;
360
361 ret = vmw_event_fence_action_queue(file_priv, fence,
362 &event->base,
363 &event->event.vbl.tv_sec,
364 &event->event.vbl.tv_usec,
365 true);
366 }
367
368
369
370
371
372 vmw_fence_obj_unreference(&fence);
373
374 if (vmw_crtc_to_du(crtc)->is_implicit)
375 vmw_kms_update_implicit_fb(dev_priv, crtc);
376
377 return ret;
378
379out_no_fence:
380 drm_atomic_set_fb_for_plane(crtc->primary->state, old_fb);
381 return ret;
382}
383
384static const struct drm_crtc_funcs vmw_screen_object_crtc_funcs = {
385 .gamma_set = vmw_du_crtc_gamma_set,
386 .destroy = vmw_sou_crtc_destroy,
387 .reset = vmw_du_crtc_reset,
388 .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
389 .atomic_destroy_state = vmw_du_crtc_destroy_state,
390 .set_config = vmw_kms_set_config,
391 .page_flip = vmw_sou_crtc_page_flip,
392};
393
394
395
396
397
398static void vmw_sou_encoder_destroy(struct drm_encoder *encoder)
399{
400 vmw_sou_destroy(vmw_encoder_to_sou(encoder));
401}
402
403static const struct drm_encoder_funcs vmw_screen_object_encoder_funcs = {
404 .destroy = vmw_sou_encoder_destroy,
405};
406
407
408
409
410
411static void vmw_sou_connector_destroy(struct drm_connector *connector)
412{
413 vmw_sou_destroy(vmw_connector_to_sou(connector));
414}
415
416static const struct drm_connector_funcs vmw_sou_connector_funcs = {
417 .dpms = vmw_du_connector_dpms,
418 .detect = vmw_du_connector_detect,
419 .fill_modes = vmw_du_connector_fill_modes,
420 .set_property = vmw_du_connector_set_property,
421 .destroy = vmw_sou_connector_destroy,
422 .reset = vmw_du_connector_reset,
423 .atomic_duplicate_state = vmw_du_connector_duplicate_state,
424 .atomic_destroy_state = vmw_du_connector_destroy_state,
425 .atomic_set_property = vmw_du_connector_atomic_set_property,
426 .atomic_get_property = vmw_du_connector_atomic_get_property,
427};
428
429
430static const struct
431drm_connector_helper_funcs vmw_sou_connector_helper_funcs = {
432 .best_encoder = drm_atomic_helper_best_encoder,
433};
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451static void
452vmw_sou_primary_plane_cleanup_fb(struct drm_plane *plane,
453 struct drm_plane_state *old_state)
454{
455 struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state);
456
457 vmw_dmabuf_unreference(&vps->dmabuf);
458 vps->dmabuf_size = 0;
459
460 vmw_du_plane_cleanup_fb(plane, old_state);
461}
462
463
464
465
466
467
468
469
470
471
472
473
474static int
475vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane,
476 struct drm_plane_state *new_state)
477{
478 struct drm_framebuffer *new_fb = new_state->fb;
479 struct drm_crtc *crtc = plane->state->crtc ?: new_state->crtc;
480 struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
481 struct vmw_private *dev_priv;
482 size_t size;
483 int ret;
484
485
486 if (!new_fb) {
487 vmw_dmabuf_unreference(&vps->dmabuf);
488 vps->dmabuf_size = 0;
489
490 return 0;
491 }
492
493 size = new_state->crtc_w * new_state->crtc_h * 4;
494
495 if (vps->dmabuf) {
496 if (vps->dmabuf_size == size)
497 return 0;
498
499 vmw_dmabuf_unreference(&vps->dmabuf);
500 vps->dmabuf_size = 0;
501 }
502
503 vps->dmabuf = kzalloc(sizeof(*vps->dmabuf), GFP_KERNEL);
504 if (!vps->dmabuf)
505 return -ENOMEM;
506
507 dev_priv = vmw_priv(crtc->dev);
508 vmw_svga_enable(dev_priv);
509
510
511
512
513 vmw_overlay_pause_all(dev_priv);
514 ret = vmw_dmabuf_init(dev_priv, vps->dmabuf, size,
515 &vmw_vram_ne_placement,
516 false, &vmw_dmabuf_bo_free);
517 vmw_overlay_resume_all(dev_priv);
518
519 if (ret != 0)
520 vps->dmabuf = NULL;
521 else
522 vps->dmabuf_size = size;
523
524 return ret;
525}
526
527
528static void
529vmw_sou_primary_plane_atomic_update(struct drm_plane *plane,
530 struct drm_plane_state *old_state)
531{
532 struct drm_crtc *crtc = plane->state->crtc;
533
534 if (crtc)
535 crtc->primary->fb = plane->state->fb;
536}
537
538
539static const struct drm_plane_funcs vmw_sou_plane_funcs = {
540 .update_plane = drm_atomic_helper_update_plane,
541 .disable_plane = drm_atomic_helper_disable_plane,
542 .destroy = vmw_du_primary_plane_destroy,
543 .reset = vmw_du_plane_reset,
544 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
545 .atomic_destroy_state = vmw_du_plane_destroy_state,
546};
547
548static const struct drm_plane_funcs vmw_sou_cursor_funcs = {
549 .update_plane = drm_atomic_helper_update_plane,
550 .disable_plane = drm_atomic_helper_disable_plane,
551 .destroy = vmw_du_cursor_plane_destroy,
552 .reset = vmw_du_plane_reset,
553 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
554 .atomic_destroy_state = vmw_du_plane_destroy_state,
555};
556
557
558
559
560static const struct
561drm_plane_helper_funcs vmw_sou_cursor_plane_helper_funcs = {
562 .atomic_check = vmw_du_cursor_plane_atomic_check,
563 .atomic_update = vmw_du_cursor_plane_atomic_update,
564 .prepare_fb = vmw_du_cursor_plane_prepare_fb,
565 .cleanup_fb = vmw_du_plane_cleanup_fb,
566};
567
568static const struct
569drm_plane_helper_funcs vmw_sou_primary_plane_helper_funcs = {
570 .atomic_check = vmw_du_primary_plane_atomic_check,
571 .atomic_update = vmw_sou_primary_plane_atomic_update,
572 .prepare_fb = vmw_sou_primary_plane_prepare_fb,
573 .cleanup_fb = vmw_sou_primary_plane_cleanup_fb,
574};
575
576static const struct drm_crtc_helper_funcs vmw_sou_crtc_helper_funcs = {
577 .prepare = vmw_sou_crtc_helper_prepare,
578 .mode_set_nofb = vmw_sou_crtc_mode_set_nofb,
579 .atomic_check = vmw_du_crtc_atomic_check,
580 .atomic_begin = vmw_du_crtc_atomic_begin,
581 .atomic_flush = vmw_du_crtc_atomic_flush,
582 .atomic_enable = vmw_sou_crtc_atomic_enable,
583 .atomic_disable = vmw_sou_crtc_atomic_disable,
584};
585
586
587static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
588{
589 struct vmw_screen_object_unit *sou;
590 struct drm_device *dev = dev_priv->dev;
591 struct drm_connector *connector;
592 struct drm_encoder *encoder;
593 struct drm_plane *primary, *cursor;
594 struct drm_crtc *crtc;
595 int ret;
596
597 sou = kzalloc(sizeof(*sou), GFP_KERNEL);
598 if (!sou)
599 return -ENOMEM;
600
601 sou->base.unit = unit;
602 crtc = &sou->base.crtc;
603 encoder = &sou->base.encoder;
604 connector = &sou->base.connector;
605 primary = &sou->base.primary;
606 cursor = &sou->base.cursor;
607
608 sou->base.active_implicit = false;
609 sou->base.pref_active = (unit == 0);
610 sou->base.pref_width = dev_priv->initial_width;
611 sou->base.pref_height = dev_priv->initial_height;
612 sou->base.pref_mode = NULL;
613
614
615
616
617
618 sou->base.is_implicit = false;
619
620
621 vmw_du_plane_reset(primary);
622
623 ret = drm_universal_plane_init(dev, &sou->base.primary,
624 0, &vmw_sou_plane_funcs,
625 vmw_primary_plane_formats,
626 ARRAY_SIZE(vmw_primary_plane_formats),
627 NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
628 if (ret) {
629 DRM_ERROR("Failed to initialize primary plane");
630 goto err_free;
631 }
632
633 drm_plane_helper_add(primary, &vmw_sou_primary_plane_helper_funcs);
634
635
636 vmw_du_plane_reset(cursor);
637
638 ret = drm_universal_plane_init(dev, &sou->base.cursor,
639 0, &vmw_sou_cursor_funcs,
640 vmw_cursor_plane_formats,
641 ARRAY_SIZE(vmw_cursor_plane_formats),
642 NULL, DRM_PLANE_TYPE_CURSOR, NULL);
643 if (ret) {
644 DRM_ERROR("Failed to initialize cursor plane");
645 drm_plane_cleanup(&sou->base.primary);
646 goto err_free;
647 }
648
649 drm_plane_helper_add(cursor, &vmw_sou_cursor_plane_helper_funcs);
650
651 vmw_du_connector_reset(connector);
652 ret = drm_connector_init(dev, connector, &vmw_sou_connector_funcs,
653 DRM_MODE_CONNECTOR_VIRTUAL);
654 if (ret) {
655 DRM_ERROR("Failed to initialize connector\n");
656 goto err_free;
657 }
658
659 drm_connector_helper_add(connector, &vmw_sou_connector_helper_funcs);
660 connector->status = vmw_du_connector_detect(connector, true);
661 vmw_connector_state_to_vcs(connector->state)->is_implicit = false;
662
663
664 ret = drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs,
665 DRM_MODE_ENCODER_VIRTUAL, NULL);
666 if (ret) {
667 DRM_ERROR("Failed to initialize encoder\n");
668 goto err_free_connector;
669 }
670
671 (void) drm_mode_connector_attach_encoder(connector, encoder);
672 encoder->possible_crtcs = (1 << unit);
673 encoder->possible_clones = 0;
674
675 ret = drm_connector_register(connector);
676 if (ret) {
677 DRM_ERROR("Failed to register connector\n");
678 goto err_free_encoder;
679 }
680
681
682 vmw_du_crtc_reset(crtc);
683 ret = drm_crtc_init_with_planes(dev, crtc, &sou->base.primary,
684 &sou->base.cursor,
685 &vmw_screen_object_crtc_funcs, NULL);
686 if (ret) {
687 DRM_ERROR("Failed to initialize CRTC\n");
688 goto err_free_unregister;
689 }
690
691 drm_crtc_helper_add(crtc, &vmw_sou_crtc_helper_funcs);
692
693 drm_mode_crtc_set_gamma_size(crtc, 256);
694
695 drm_object_attach_property(&connector->base,
696 dev_priv->hotplug_mode_update_property, 1);
697 drm_object_attach_property(&connector->base,
698 dev->mode_config.suggested_x_property, 0);
699 drm_object_attach_property(&connector->base,
700 dev->mode_config.suggested_y_property, 0);
701 if (dev_priv->implicit_placement_property)
702 drm_object_attach_property
703 (&connector->base,
704 dev_priv->implicit_placement_property,
705 sou->base.is_implicit);
706
707 return 0;
708
709err_free_unregister:
710 drm_connector_unregister(connector);
711err_free_encoder:
712 drm_encoder_cleanup(encoder);
713err_free_connector:
714 drm_connector_cleanup(connector);
715err_free:
716 kfree(sou);
717 return ret;
718}
719
720int vmw_kms_sou_init_display(struct vmw_private *dev_priv)
721{
722 struct drm_device *dev = dev_priv->dev;
723 int i, ret;
724
725 if (!(dev_priv->capabilities & SVGA_CAP_SCREEN_OBJECT_2)) {
726 DRM_INFO("Not using screen objects,"
727 " missing cap SCREEN_OBJECT_2\n");
728 return -ENOSYS;
729 }
730
731 ret = -ENOMEM;
732 dev_priv->num_implicit = 0;
733 dev_priv->implicit_fb = NULL;
734
735 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
736 if (unlikely(ret != 0))
737 return ret;
738
739 vmw_kms_create_implicit_placement_property(dev_priv, false);
740
741 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
742 vmw_sou_init(dev_priv, i);
743
744 dev_priv->active_display_unit = vmw_du_screen_object;
745
746 DRM_INFO("Screen Objects Display Unit initialized\n");
747
748 return 0;
749}
750
751static int do_dmabuf_define_gmrfb(struct vmw_private *dev_priv,
752 struct vmw_framebuffer *framebuffer)
753{
754 struct vmw_dma_buffer *buf =
755 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
756 base)->buffer;
757 int depth = framebuffer->base.format->depth;
758 struct {
759 uint32_t header;
760 SVGAFifoCmdDefineGMRFB body;
761 } *cmd;
762
763
764
765
766
767 if (depth == 32)
768 depth = 24;
769
770 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
771 if (!cmd) {
772 DRM_ERROR("Out of fifo space for dirty framebuffer command.\n");
773 return -ENOMEM;
774 }
775
776 cmd->header = SVGA_CMD_DEFINE_GMRFB;
777 cmd->body.format.bitsPerPixel = framebuffer->base.format->cpp[0] * 8;
778 cmd->body.format.colorDepth = depth;
779 cmd->body.format.reserved = 0;
780 cmd->body.bytesPerLine = framebuffer->base.pitches[0];
781
782 vmw_bo_get_guest_ptr(&buf->base, &cmd->body.ptr);
783 vmw_fifo_commit(dev_priv, sizeof(*cmd));
784
785 return 0;
786}
787
788
789
790
791
792
793
794
795
796
797static void vmw_sou_surface_fifo_commit(struct vmw_kms_dirty *dirty)
798{
799 struct vmw_kms_sou_surface_dirty *sdirty =
800 container_of(dirty, typeof(*sdirty), base);
801 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
802 s32 trans_x = dirty->unit->crtc.x - sdirty->dst_x;
803 s32 trans_y = dirty->unit->crtc.y - sdirty->dst_y;
804 size_t region_size = dirty->num_hits * sizeof(SVGASignedRect);
805 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
806 int i;
807
808 if (!dirty->num_hits) {
809 vmw_fifo_commit(dirty->dev_priv, 0);
810 return;
811 }
812
813 cmd->header.id = SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN;
814 cmd->header.size = sizeof(cmd->body) + region_size;
815
816
817
818
819
820 cmd->body.destRect.left = sdirty->left;
821 cmd->body.destRect.right = sdirty->right;
822 cmd->body.destRect.top = sdirty->top;
823 cmd->body.destRect.bottom = sdirty->bottom;
824
825 cmd->body.srcRect.left = sdirty->left + trans_x;
826 cmd->body.srcRect.right = sdirty->right + trans_x;
827 cmd->body.srcRect.top = sdirty->top + trans_y;
828 cmd->body.srcRect.bottom = sdirty->bottom + trans_y;
829
830 cmd->body.srcImage.sid = sdirty->sid;
831 cmd->body.destScreenId = dirty->unit->unit;
832
833
834 for (i = 0; i < dirty->num_hits; ++i, ++blit) {
835 blit->left -= sdirty->left;
836 blit->right -= sdirty->left;
837 blit->top -= sdirty->top;
838 blit->bottom -= sdirty->top;
839 }
840
841 vmw_fifo_commit(dirty->dev_priv, region_size + sizeof(*cmd));
842
843 sdirty->left = sdirty->top = S32_MAX;
844 sdirty->right = sdirty->bottom = S32_MIN;
845}
846
847
848
849
850
851
852
853
854
855static void vmw_sou_surface_clip(struct vmw_kms_dirty *dirty)
856{
857 struct vmw_kms_sou_surface_dirty *sdirty =
858 container_of(dirty, typeof(*sdirty), base);
859 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
860 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
861
862
863 blit += dirty->num_hits;
864 blit->left = dirty->unit_x1;
865 blit->top = dirty->unit_y1;
866 blit->right = dirty->unit_x2;
867 blit->bottom = dirty->unit_y2;
868
869
870 sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
871 sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
872 sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
873 sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
874
875 dirty->num_hits++;
876}
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
900 struct vmw_framebuffer *framebuffer,
901 struct drm_clip_rect *clips,
902 struct drm_vmw_rect *vclips,
903 struct vmw_resource *srf,
904 s32 dest_x,
905 s32 dest_y,
906 unsigned num_clips, int inc,
907 struct vmw_fence_obj **out_fence)
908{
909 struct vmw_framebuffer_surface *vfbs =
910 container_of(framebuffer, typeof(*vfbs), base);
911 struct vmw_kms_sou_surface_dirty sdirty;
912 int ret;
913
914 if (!srf)
915 srf = &vfbs->surface->res;
916
917 ret = vmw_kms_helper_resource_prepare(srf, true);
918 if (ret)
919 return ret;
920
921 sdirty.base.fifo_commit = vmw_sou_surface_fifo_commit;
922 sdirty.base.clip = vmw_sou_surface_clip;
923 sdirty.base.dev_priv = dev_priv;
924 sdirty.base.fifo_reserve_size = sizeof(struct vmw_kms_sou_dirty_cmd) +
925 sizeof(SVGASignedRect) * num_clips;
926
927 sdirty.sid = srf->id;
928 sdirty.left = sdirty.top = S32_MAX;
929 sdirty.right = sdirty.bottom = S32_MIN;
930 sdirty.dst_x = dest_x;
931 sdirty.dst_y = dest_y;
932
933 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
934 dest_x, dest_y, num_clips, inc,
935 &sdirty.base);
936 vmw_kms_helper_resource_finish(srf, out_fence);
937
938 return ret;
939}
940
941
942
943
944
945
946
947
948static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
949{
950 if (!dirty->num_hits) {
951 vmw_fifo_commit(dirty->dev_priv, 0);
952 return;
953 }
954
955 vmw_fifo_commit(dirty->dev_priv,
956 sizeof(struct vmw_kms_sou_dmabuf_blit) *
957 dirty->num_hits);
958}
959
960
961
962
963
964
965
966
967static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty *dirty)
968{
969 struct vmw_kms_sou_dmabuf_blit *blit = dirty->cmd;
970
971 blit += dirty->num_hits;
972 blit->header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN;
973 blit->body.destScreenId = dirty->unit->unit;
974 blit->body.srcOrigin.x = dirty->fb_x;
975 blit->body.srcOrigin.y = dirty->fb_y;
976 blit->body.destRect.left = dirty->unit_x1;
977 blit->body.destRect.top = dirty->unit_y1;
978 blit->body.destRect.right = dirty->unit_x2;
979 blit->body.destRect.bottom = dirty->unit_y2;
980 dirty->num_hits++;
981}
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
1002 struct vmw_framebuffer *framebuffer,
1003 struct drm_clip_rect *clips,
1004 struct drm_vmw_rect *vclips,
1005 unsigned num_clips, int increment,
1006 bool interruptible,
1007 struct vmw_fence_obj **out_fence)
1008{
1009 struct vmw_dma_buffer *buf =
1010 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
1011 base)->buffer;
1012 struct vmw_kms_dirty dirty;
1013 int ret;
1014
1015 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
1016 false);
1017 if (ret)
1018 return ret;
1019
1020 ret = do_dmabuf_define_gmrfb(dev_priv, framebuffer);
1021 if (unlikely(ret != 0))
1022 goto out_revert;
1023
1024 dirty.fifo_commit = vmw_sou_dmabuf_fifo_commit;
1025 dirty.clip = vmw_sou_dmabuf_clip;
1026 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_dmabuf_blit) *
1027 num_clips;
1028 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
1029 0, 0, num_clips, increment, &dirty);
1030 vmw_kms_helper_buffer_finish(dev_priv, NULL, buf, out_fence, NULL);
1031
1032 return ret;
1033
1034out_revert:
1035 vmw_kms_helper_buffer_revert(buf);
1036
1037 return ret;
1038}
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048static void vmw_sou_readback_fifo_commit(struct vmw_kms_dirty *dirty)
1049{
1050 if (!dirty->num_hits) {
1051 vmw_fifo_commit(dirty->dev_priv, 0);
1052 return;
1053 }
1054
1055 vmw_fifo_commit(dirty->dev_priv,
1056 sizeof(struct vmw_kms_sou_readback_blit) *
1057 dirty->num_hits);
1058}
1059
1060
1061
1062
1063
1064
1065
1066
1067static void vmw_sou_readback_clip(struct vmw_kms_dirty *dirty)
1068{
1069 struct vmw_kms_sou_readback_blit *blit = dirty->cmd;
1070
1071 blit += dirty->num_hits;
1072 blit->header = SVGA_CMD_BLIT_SCREEN_TO_GMRFB;
1073 blit->body.srcScreenId = dirty->unit->unit;
1074 blit->body.destOrigin.x = dirty->fb_x;
1075 blit->body.destOrigin.y = dirty->fb_y;
1076 blit->body.srcRect.left = dirty->unit_x1;
1077 blit->body.srcRect.top = dirty->unit_y1;
1078 blit->body.srcRect.right = dirty->unit_x2;
1079 blit->body.srcRect.bottom = dirty->unit_y2;
1080 dirty->num_hits++;
1081}
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099int vmw_kms_sou_readback(struct vmw_private *dev_priv,
1100 struct drm_file *file_priv,
1101 struct vmw_framebuffer *vfb,
1102 struct drm_vmw_fence_rep __user *user_fence_rep,
1103 struct drm_vmw_rect *vclips,
1104 uint32_t num_clips)
1105{
1106 struct vmw_dma_buffer *buf =
1107 container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
1108 struct vmw_kms_dirty dirty;
1109 int ret;
1110
1111 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, true, false);
1112 if (ret)
1113 return ret;
1114
1115 ret = do_dmabuf_define_gmrfb(dev_priv, vfb);
1116 if (unlikely(ret != 0))
1117 goto out_revert;
1118
1119 dirty.fifo_commit = vmw_sou_readback_fifo_commit;
1120 dirty.clip = vmw_sou_readback_clip;
1121 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_readback_blit) *
1122 num_clips;
1123 ret = vmw_kms_helper_dirty(dev_priv, vfb, NULL, vclips,
1124 0, 0, num_clips, 1, &dirty);
1125 vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
1126 user_fence_rep);
1127
1128 return ret;
1129
1130out_revert:
1131 vmw_kms_helper_buffer_revert(buf);
1132
1133 return ret;
1134}
1135