1 /**************************************************************************
3 * Copyright © 2011-2014 VMware, Inc., Palo Alto, CA., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "vmwgfx_kms.h"
29 #include <drm/drm_plane_helper.h>
32 #define vmw_crtc_to_sou(x) \
33 container_of(x, struct vmw_screen_object_unit, base.crtc)
34 #define vmw_encoder_to_sou(x) \
35 container_of(x, struct vmw_screen_object_unit, base.encoder)
36 #define vmw_connector_to_sou(x) \
37 container_of(x, struct vmw_screen_object_unit, base.connector)
39 struct vmw_screen_object_display {
40 unsigned num_implicit;
42 struct vmw_framebuffer *implicit_fb;
46 * Display unit using screen objects.
48 struct vmw_screen_object_unit {
49 struct vmw_display_unit base;
51 unsigned long buffer_size; /**< Size of allocated buffer */
52 struct vmw_dma_buffer *buffer; /**< Backing store buffer */
58 static void vmw_sou_destroy(struct vmw_screen_object_unit *sou)
60 vmw_du_cleanup(&sou->base);
66 * Screen Object Display Unit CRTC functions
69 static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)
71 vmw_sou_destroy(vmw_crtc_to_sou(crtc));
74 static void vmw_sou_del_active(struct vmw_private *vmw_priv,
75 struct vmw_screen_object_unit *sou)
77 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
79 if (sou->active_implicit) {
80 if (--(ld->num_implicit) == 0)
81 ld->implicit_fb = NULL;
82 sou->active_implicit = false;
86 static void vmw_sou_add_active(struct vmw_private *vmw_priv,
87 struct vmw_screen_object_unit *sou,
88 struct vmw_framebuffer *vfb)
90 struct vmw_screen_object_display *ld = vmw_priv->sou_priv;
92 BUG_ON(!ld->num_implicit && ld->implicit_fb);
94 if (!sou->active_implicit && sou->base.is_implicit) {
95 ld->implicit_fb = vfb;
96 sou->active_implicit = true;
102 * Send the fifo command to create a screen.
104 static int vmw_sou_fifo_create(struct vmw_private *dev_priv,
105 struct vmw_screen_object_unit *sou,
106 uint32_t x, uint32_t y,
107 struct drm_display_mode *mode)
115 SVGAScreenObject obj;
118 BUG_ON(!sou->buffer);
120 fifo_size = sizeof(*cmd);
121 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
122 /* The hardware has hung, nothing we can do about it here. */
123 if (unlikely(cmd == NULL)) {
124 DRM_ERROR("Fifo reserve failed.\n");
128 memset(cmd, 0, fifo_size);
129 cmd->header.cmdType = SVGA_CMD_DEFINE_SCREEN;
130 cmd->obj.structSize = sizeof(SVGAScreenObject);
131 cmd->obj.id = sou->base.unit;
132 cmd->obj.flags = SVGA_SCREEN_HAS_ROOT |
133 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0);
134 cmd->obj.size.width = mode->hdisplay;
135 cmd->obj.size.height = mode->vdisplay;
136 if (sou->base.is_implicit) {
140 cmd->obj.root.x = sou->base.gui_x;
141 cmd->obj.root.y = sou->base.gui_y;
144 /* Ok to assume that buffer is pinned in vram */
145 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr);
146 cmd->obj.backingStore.pitch = mode->hdisplay * 4;
148 vmw_fifo_commit(dev_priv, fifo_size);
156 * Send the fifo command to destroy a screen.
158 static int vmw_sou_fifo_destroy(struct vmw_private *dev_priv,
159 struct vmw_screen_object_unit *sou)
168 SVGAFifoCmdDestroyScreen body;
171 /* no need to do anything */
172 if (unlikely(!sou->defined))
175 fifo_size = sizeof(*cmd);
176 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
177 /* the hardware has hung, nothing we can do about it here */
178 if (unlikely(cmd == NULL)) {
179 DRM_ERROR("Fifo reserve failed.\n");
183 memset(cmd, 0, fifo_size);
184 cmd->header.cmdType = SVGA_CMD_DESTROY_SCREEN;
185 cmd->body.screenId = sou->base.unit;
187 vmw_fifo_commit(dev_priv, fifo_size);
190 ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
191 if (unlikely(ret != 0))
192 DRM_ERROR("Failed to sync with HW");
194 sou->defined = false;
200 * Free the backing store.
202 static void vmw_sou_backing_free(struct vmw_private *dev_priv,
203 struct vmw_screen_object_unit *sou)
205 struct ttm_buffer_object *bo;
207 if (unlikely(sou->buffer == NULL))
210 bo = &sou->buffer->base;
213 sou->buffer_size = 0;
217 * Allocate the backing store for the buffer.
219 static int vmw_sou_backing_alloc(struct vmw_private *dev_priv,
220 struct vmw_screen_object_unit *sou,
225 if (sou->buffer_size == size)
229 vmw_sou_backing_free(dev_priv, sou);
231 sou->buffer = kzalloc(sizeof(*sou->buffer), GFP_KERNEL);
232 if (unlikely(sou->buffer == NULL))
235 /* After we have alloced the backing store might not be able to
236 * resume the overlays, this is preferred to failing to alloc.
238 vmw_overlay_pause_all(dev_priv);
239 ret = vmw_dmabuf_init(dev_priv, sou->buffer, size,
240 &vmw_vram_ne_placement,
241 false, &vmw_dmabuf_bo_free);
242 vmw_overlay_resume_all(dev_priv);
244 if (unlikely(ret != 0))
245 sou->buffer = NULL; /* vmw_dmabuf_init frees on error */
247 sou->buffer_size = size;
252 static int vmw_sou_crtc_set_config(struct drm_mode_set *set)
254 struct vmw_private *dev_priv;
255 struct vmw_screen_object_unit *sou;
256 struct drm_connector *connector;
257 struct drm_display_mode *mode;
258 struct drm_encoder *encoder;
259 struct vmw_framebuffer *vfb;
260 struct drm_framebuffer *fb;
261 struct drm_crtc *crtc;
272 sou = vmw_crtc_to_sou(crtc);
273 vfb = set->fb ? vmw_framebuffer_to_vfb(set->fb) : NULL;
274 dev_priv = vmw_priv(crtc->dev);
276 if (set->num_connectors > 1) {
277 DRM_ERROR("Too many connectors\n");
281 if (set->num_connectors == 1 &&
282 set->connectors[0] != &sou->base.connector) {
283 DRM_ERROR("Connector doesn't match %p %p\n",
284 set->connectors[0], &sou->base.connector);
288 /* sou only supports one fb active at the time */
289 if (sou->base.is_implicit &&
290 dev_priv->sou_priv->implicit_fb && vfb &&
291 !(dev_priv->sou_priv->num_implicit == 1 &&
292 sou->active_implicit) &&
293 dev_priv->sou_priv->implicit_fb != vfb) {
294 DRM_ERROR("Multiple framebuffers not supported\n");
298 /* since they always map one to one these are safe */
299 connector = &sou->base.connector;
300 encoder = &sou->base.encoder;
302 /* should we turn the crtc off */
303 if (set->num_connectors == 0 || !set->mode || !set->fb) {
304 ret = vmw_sou_fifo_destroy(dev_priv, sou);
305 /* the hardware has hung don't do anything more */
306 if (unlikely(ret != 0))
309 connector->encoder = NULL;
310 encoder->crtc = NULL;
311 crtc->primary->fb = NULL;
314 crtc->enabled = false;
316 vmw_sou_del_active(dev_priv, sou);
318 vmw_sou_backing_free(dev_priv, sou);
324 /* we now know we want to set a mode */
328 if (set->x + mode->hdisplay > fb->width ||
329 set->y + mode->vdisplay > fb->height) {
330 DRM_ERROR("set outside of framebuffer\n");
334 vmw_fb_off(dev_priv);
335 vmw_svga_enable(dev_priv);
337 if (mode->hdisplay != crtc->mode.hdisplay ||
338 mode->vdisplay != crtc->mode.vdisplay) {
339 /* no need to check if depth is different, because backing
340 * store depth is forced to 4 by the device.
343 ret = vmw_sou_fifo_destroy(dev_priv, sou);
344 /* the hardware has hung don't do anything more */
345 if (unlikely(ret != 0))
348 vmw_sou_backing_free(dev_priv, sou);
352 /* forced to depth 4 by the device */
353 size_t size = mode->hdisplay * mode->vdisplay * 4;
354 ret = vmw_sou_backing_alloc(dev_priv, sou, size);
355 if (unlikely(ret != 0))
359 ret = vmw_sou_fifo_create(dev_priv, sou, set->x, set->y, mode);
360 if (unlikely(ret != 0)) {
362 * We are in a bit of a situation here, the hardware has
363 * hung and we may or may not have a buffer hanging of
364 * the screen object, best thing to do is not do anything
365 * if we where defined, if not just turn the crtc of.
366 * Not what userspace wants but it needs to htfu.
371 connector->encoder = NULL;
372 encoder->crtc = NULL;
373 crtc->primary->fb = NULL;
376 crtc->enabled = false;
381 vmw_sou_add_active(dev_priv, sou, vfb);
383 connector->encoder = encoder;
384 encoder->crtc = crtc;
386 crtc->primary->fb = fb;
389 crtc->enabled = true;
395 * Returns if this unit can be page flipped.
396 * Must be called with the mode_config mutex held.
398 static bool vmw_sou_screen_object_flippable(struct vmw_private *dev_priv,
399 struct drm_crtc *crtc)
401 struct vmw_screen_object_unit *sou = vmw_crtc_to_sou(crtc);
403 if (!sou->base.is_implicit)
406 if (dev_priv->sou_priv->num_implicit != 1)
413 * Update the implicit fb to the current fb of this crtc.
414 * Must be called with the mode_config mutex held.
416 void vmw_sou_update_implicit_fb(struct vmw_private *dev_priv,
417 struct drm_crtc *crtc)
419 struct vmw_screen_object_unit *sou = vmw_crtc_to_sou(crtc);
421 BUG_ON(!sou->base.is_implicit);
423 dev_priv->sou_priv->implicit_fb =
424 vmw_framebuffer_to_vfb(sou->base.crtc.primary->fb);
427 static int vmw_sou_crtc_page_flip(struct drm_crtc *crtc,
428 struct drm_framebuffer *fb,
429 struct drm_pending_vblank_event *event,
432 struct vmw_private *dev_priv = vmw_priv(crtc->dev);
433 struct drm_framebuffer *old_fb = crtc->primary->fb;
434 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(fb);
435 struct drm_file *file_priv = event->base.file_priv;
436 struct vmw_fence_obj *fence = NULL;
437 struct drm_clip_rect clips;
440 /* require ScreenObject support for page flipping */
441 if (!dev_priv->sou_priv)
444 if (!vmw_sou_screen_object_flippable(dev_priv, crtc))
447 crtc->primary->fb = fb;
449 /* do a full screen dirty update */
450 clips.x1 = clips.y1 = 0;
451 clips.x2 = fb->width;
452 clips.y2 = fb->height;
455 ret = vmw_kms_sou_do_dmabuf_dirty(file_priv, dev_priv, vfb,
456 0, 0, &clips, 1, 1, &fence);
458 ret = vmw_kms_sou_do_surface_dirty(dev_priv, file_priv, vfb,
459 0, 0, &clips, 1, 1, &fence);
469 ret = vmw_event_fence_action_queue(file_priv, fence,
471 &event->event.tv_sec,
472 &event->event.tv_usec,
476 * No need to hold on to this now. The only cleanup
477 * we need to do if we fail is unref the fence.
479 vmw_fence_obj_unreference(&fence);
481 if (vmw_crtc_to_du(crtc)->is_implicit)
482 vmw_sou_update_implicit_fb(dev_priv, crtc);
487 crtc->primary->fb = old_fb;
491 int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
492 struct drm_file *file_priv,
493 struct vmw_framebuffer *framebuffer,
494 unsigned flags, unsigned color,
495 struct drm_clip_rect *clips,
496 unsigned num_clips, int inc,
497 struct vmw_fence_obj **out_fence)
499 struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS];
500 struct drm_clip_rect *clips_ptr;
501 struct drm_clip_rect *tmp;
502 struct drm_crtc *crtc;
505 int ret = 0; /* silence warning */
506 int left, right, top, bottom;
509 SVGA3dCmdHeader header;
510 SVGA3dCmdBlitSurfaceToScreen body;
512 SVGASignedRect *blits;
515 list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list,
517 if (crtc->primary->fb != &framebuffer->base)
519 units[num_units++] = vmw_crtc_to_du(crtc);
522 BUG_ON(!clips || !num_clips);
524 tmp = kzalloc(sizeof(*tmp) * num_clips, GFP_KERNEL);
525 if (unlikely(tmp == NULL)) {
526 DRM_ERROR("Temporary cliprect memory alloc failed.\n");
530 fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num_clips;
531 cmd = kzalloc(fifo_size, GFP_KERNEL);
532 if (unlikely(cmd == NULL)) {
533 DRM_ERROR("Temporary fifo memory alloc failed.\n");
538 /* setup blits pointer */
539 blits = (SVGASignedRect *)&cmd[1];
541 /* initial clip region */
547 /* skip the first clip rect */
548 for (i = 1, clips_ptr = clips + inc;
549 i < num_clips; i++, clips_ptr += inc) {
550 left = min_t(int, left, (int)clips_ptr->x1);
551 right = max_t(int, right, (int)clips_ptr->x2);
552 top = min_t(int, top, (int)clips_ptr->y1);
553 bottom = max_t(int, bottom, (int)clips_ptr->y2);
556 /* only need to do this once */
557 cmd->header.id = cpu_to_le32(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN);
558 cmd->header.size = cpu_to_le32(fifo_size - sizeof(cmd->header));
560 cmd->body.srcRect.left = left;
561 cmd->body.srcRect.right = right;
562 cmd->body.srcRect.top = top;
563 cmd->body.srcRect.bottom = bottom;
566 for (i = 0; i < num_clips; i++, clips_ptr += inc) {
567 tmp[i].x1 = clips_ptr->x1 - left;
568 tmp[i].x2 = clips_ptr->x2 - left;
569 tmp[i].y1 = clips_ptr->y1 - top;
570 tmp[i].y2 = clips_ptr->y2 - top;
573 /* do per unit writing, reuse fifo for each */
574 for (i = 0; i < num_units; i++) {
575 struct vmw_display_unit *unit = units[i];
576 struct vmw_clip_rect clip;
579 clip.x1 = left - unit->crtc.x;
580 clip.y1 = top - unit->crtc.y;
581 clip.x2 = right - unit->crtc.x;
582 clip.y2 = bottom - unit->crtc.y;
584 /* skip any crtcs that misses the clip region */
585 if (clip.x1 >= unit->crtc.mode.hdisplay ||
586 clip.y1 >= unit->crtc.mode.vdisplay ||
587 clip.x2 <= 0 || clip.y2 <= 0)
591 * In order for the clip rects to be correctly scaled
592 * the src and dest rects needs to be the same size.
594 cmd->body.destRect.left = clip.x1;
595 cmd->body.destRect.right = clip.x2;
596 cmd->body.destRect.top = clip.y1;
597 cmd->body.destRect.bottom = clip.y2;
599 /* create a clip rect of the crtc in dest coords */
600 clip.x2 = unit->crtc.mode.hdisplay - clip.x1;
601 clip.y2 = unit->crtc.mode.vdisplay - clip.y1;
602 clip.x1 = 0 - clip.x1;
603 clip.y1 = 0 - clip.y1;
605 /* need to reset sid as it is changed by execbuf */
606 cmd->body.srcImage.sid = cpu_to_le32(framebuffer->user_handle);
607 cmd->body.destScreenId = unit->unit;
609 /* clip and write blits to cmd stream */
610 vmw_clip_cliprects(tmp, num_clips, clip, blits, &num);
612 /* if no cliprects hit skip this */
616 /* only return the last fence */
617 if (out_fence && *out_fence)
618 vmw_fence_obj_unreference(out_fence);
620 /* recalculate package length */
621 fifo_size = sizeof(*cmd) + sizeof(SVGASignedRect) * num;
622 cmd->header.size = cpu_to_le32(fifo_size - sizeof(cmd->header));
623 ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd,
624 fifo_size, 0, 0, NULL, out_fence);
626 if (unlikely(ret != 0))
638 static struct drm_crtc_funcs vmw_screen_object_crtc_funcs = {
639 .save = vmw_du_crtc_save,
640 .restore = vmw_du_crtc_restore,
641 .cursor_set = vmw_du_crtc_cursor_set,
642 .cursor_move = vmw_du_crtc_cursor_move,
643 .gamma_set = vmw_du_crtc_gamma_set,
644 .destroy = vmw_sou_crtc_destroy,
645 .set_config = vmw_sou_crtc_set_config,
646 .page_flip = vmw_sou_crtc_page_flip,
650 * Screen Object Display Unit encoder functions
653 static void vmw_sou_encoder_destroy(struct drm_encoder *encoder)
655 vmw_sou_destroy(vmw_encoder_to_sou(encoder));
658 static struct drm_encoder_funcs vmw_screen_object_encoder_funcs = {
659 .destroy = vmw_sou_encoder_destroy,
663 * Screen Object Display Unit connector functions
666 static void vmw_sou_connector_destroy(struct drm_connector *connector)
668 vmw_sou_destroy(vmw_connector_to_sou(connector));
671 static struct drm_connector_funcs vmw_sou_connector_funcs = {
672 .dpms = vmw_du_connector_dpms,
673 .save = vmw_du_connector_save,
674 .restore = vmw_du_connector_restore,
675 .detect = vmw_du_connector_detect,
676 .fill_modes = vmw_du_connector_fill_modes,
677 .set_property = vmw_du_connector_set_property,
678 .destroy = vmw_sou_connector_destroy,
681 static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
683 struct vmw_screen_object_unit *sou;
684 struct drm_device *dev = dev_priv->dev;
685 struct drm_connector *connector;
686 struct drm_encoder *encoder;
687 struct drm_crtc *crtc;
689 sou = kzalloc(sizeof(*sou), GFP_KERNEL);
693 sou->base.unit = unit;
694 crtc = &sou->base.crtc;
695 encoder = &sou->base.encoder;
696 connector = &sou->base.connector;
698 sou->active_implicit = false;
700 sou->base.pref_active = (unit == 0);
701 sou->base.pref_width = dev_priv->initial_width;
702 sou->base.pref_height = dev_priv->initial_height;
703 sou->base.pref_mode = NULL;
704 sou->base.is_implicit = true;
706 drm_connector_init(dev, connector, &vmw_sou_connector_funcs,
707 DRM_MODE_CONNECTOR_VIRTUAL);
708 connector->status = vmw_du_connector_detect(connector, true);
710 drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs,
711 DRM_MODE_ENCODER_VIRTUAL);
712 drm_mode_connector_attach_encoder(connector, encoder);
713 encoder->possible_crtcs = (1 << unit);
714 encoder->possible_clones = 0;
716 (void) drm_connector_register(connector);
718 drm_crtc_init(dev, crtc, &vmw_screen_object_crtc_funcs);
720 drm_mode_crtc_set_gamma_size(crtc, 256);
722 drm_object_attach_property(&connector->base,
723 dev->mode_config.dirty_info_property,
729 int vmw_kms_sou_init_display(struct vmw_private *dev_priv)
731 struct drm_device *dev = dev_priv->dev;
734 if (dev_priv->sou_priv) {
735 DRM_INFO("sou system already on\n");
739 if (!(dev_priv->capabilities & SVGA_CAP_SCREEN_OBJECT_2)) {
740 DRM_INFO("Not using screen objects,"
741 " missing cap SCREEN_OBJECT_2\n");
746 dev_priv->sou_priv = kmalloc(sizeof(*dev_priv->sou_priv), GFP_KERNEL);
747 if (unlikely(!dev_priv->sou_priv))
750 dev_priv->sou_priv->num_implicit = 0;
751 dev_priv->sou_priv->implicit_fb = NULL;
753 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
754 if (unlikely(ret != 0))
757 ret = drm_mode_create_dirty_info_property(dev);
758 if (unlikely(ret != 0))
759 goto err_vblank_cleanup;
761 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
762 vmw_sou_init(dev_priv, i);
764 dev_priv->active_display_unit = vmw_du_screen_object;
766 DRM_INFO("Screen Objects Display Unit initialized\n");
771 drm_vblank_cleanup(dev);
773 kfree(dev_priv->sou_priv);
774 dev_priv->sou_priv = NULL;
779 int vmw_kms_sou_close_display(struct vmw_private *dev_priv)
781 struct drm_device *dev = dev_priv->dev;
783 if (!dev_priv->sou_priv)
786 drm_vblank_cleanup(dev);
788 kfree(dev_priv->sou_priv);
793 static int do_dmabuf_define_gmrfb(struct drm_file *file_priv,
794 struct vmw_private *dev_priv,
795 struct vmw_framebuffer *framebuffer)
797 int depth = framebuffer->base.depth;
803 SVGAFifoCmdDefineGMRFB body;
806 /* Emulate RGBA support, contrary to svga_reg.h this is not
807 * supported by hosts. This is only a problem if we are reading
808 * this value later and expecting what we uploaded back.
813 fifo_size = sizeof(*cmd);
814 cmd = kmalloc(fifo_size, GFP_KERNEL);
815 if (unlikely(cmd == NULL)) {
816 DRM_ERROR("Failed to allocate temporary cmd buffer.\n");
820 memset(cmd, 0, fifo_size);
821 cmd->header = SVGA_CMD_DEFINE_GMRFB;
822 cmd->body.format.bitsPerPixel = framebuffer->base.bits_per_pixel;
823 cmd->body.format.colorDepth = depth;
824 cmd->body.format.reserved = 0;
825 cmd->body.bytesPerLine = framebuffer->base.pitches[0];
826 cmd->body.ptr.gmrId = framebuffer->user_handle;
827 cmd->body.ptr.offset = 0;
829 ret = vmw_execbuf_process(file_priv, dev_priv, NULL, cmd,
830 fifo_size, 0, 0, NULL, NULL);
837 int vmw_kms_sou_do_dmabuf_dirty(struct drm_file *file_priv,
838 struct vmw_private *dev_priv,
839 struct vmw_framebuffer *framebuffer,
840 unsigned flags, unsigned color,
841 struct drm_clip_rect *clips,
842 unsigned num_clips, int increment,
843 struct vmw_fence_obj **out_fence)
845 struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS];
846 struct drm_clip_rect *clips_ptr;
847 int i, k, num_units, ret;
848 struct drm_crtc *crtc;
853 SVGAFifoCmdBlitGMRFBToScreen body;
856 ret = do_dmabuf_define_gmrfb(file_priv, dev_priv, framebuffer);
857 if (unlikely(ret != 0))
858 return ret; /* define_gmrfb prints warnings */
860 fifo_size = sizeof(*blits) * num_clips;
861 blits = kmalloc(fifo_size, GFP_KERNEL);
862 if (unlikely(blits == NULL)) {
863 DRM_ERROR("Failed to allocate temporary cmd buffer.\n");
868 list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) {
869 if (crtc->primary->fb != &framebuffer->base)
871 units[num_units++] = vmw_crtc_to_du(crtc);
874 for (k = 0; k < num_units; k++) {
875 struct vmw_display_unit *unit = units[k];
879 for (i = 0; i < num_clips; i++, clips_ptr += increment) {
880 int clip_x1 = clips_ptr->x1 - unit->crtc.x;
881 int clip_y1 = clips_ptr->y1 - unit->crtc.y;
882 int clip_x2 = clips_ptr->x2 - unit->crtc.x;
883 int clip_y2 = clips_ptr->y2 - unit->crtc.y;
886 /* skip any crtcs that misses the clip region */
887 if (clip_x1 >= unit->crtc.mode.hdisplay ||
888 clip_y1 >= unit->crtc.mode.vdisplay ||
889 clip_x2 <= 0 || clip_y2 <= 0)
892 /* clip size to crtc size */
893 clip_x2 = min_t(int, clip_x2, unit->crtc.mode.hdisplay);
894 clip_y2 = min_t(int, clip_y2, unit->crtc.mode.vdisplay);
896 /* translate both src and dest to bring clip into screen */
897 move_x = min_t(int, clip_x1, 0);
898 move_y = min_t(int, clip_y1, 0);
900 /* actual translate done here */
901 blits[hit_num].header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN;
902 blits[hit_num].body.destScreenId = unit->unit;
903 blits[hit_num].body.srcOrigin.x = clips_ptr->x1 - move_x;
904 blits[hit_num].body.srcOrigin.y = clips_ptr->y1 - move_y;
905 blits[hit_num].body.destRect.left = clip_x1 - move_x;
906 blits[hit_num].body.destRect.top = clip_y1 - move_y;
907 blits[hit_num].body.destRect.right = clip_x2;
908 blits[hit_num].body.destRect.bottom = clip_y2;
912 /* no clips hit the crtc */
916 /* only return the last fence */
917 if (out_fence && *out_fence)
918 vmw_fence_obj_unreference(out_fence);
920 fifo_size = sizeof(*blits) * hit_num;
921 ret = vmw_execbuf_process(file_priv, dev_priv, NULL, blits,
922 fifo_size, 0, 0, NULL, out_fence);
924 if (unlikely(ret != 0))