1 /**************************************************************************
3 * Copyright © 2011-2015 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)
40 * struct vmw_kms_sou_surface_dirty - Closure structure for
41 * blit surface to screen command.
42 * @base: The base type we derive from. Used by vmw_kms_helper_dirty().
43 * @left: Left side of bounding box.
44 * @right: Right side of bounding box.
45 * @top: Top side of bounding box.
46 * @bottom: Bottom side of bounding box.
47 * @dst_x: Difference between source clip rects and framebuffer coordinates.
48 * @dst_y: Difference between source clip rects and framebuffer coordinates.
49 * @sid: Surface id of surface to copy from.
51 struct vmw_kms_sou_surface_dirty {
52 struct vmw_kms_dirty base;
53 s32 left, right, top, bottom;
59 * SVGA commands that are used by this code. Please see the device headers
62 struct vmw_kms_sou_readback_blit {
64 SVGAFifoCmdBlitScreenToGMRFB body;
67 struct vmw_kms_sou_dmabuf_blit {
69 SVGAFifoCmdBlitGMRFBToScreen body;
72 struct vmw_kms_sou_dirty_cmd {
73 SVGA3dCmdHeader header;
74 SVGA3dCmdBlitSurfaceToScreen body;
78 * Display unit using screen objects.
80 struct vmw_screen_object_unit {
81 struct vmw_display_unit base;
83 unsigned long buffer_size; /**< Size of allocated buffer */
84 struct vmw_dma_buffer *buffer; /**< Backing store buffer */
89 static void vmw_sou_destroy(struct vmw_screen_object_unit *sou)
91 vmw_du_cleanup(&sou->base);
97 * Screen Object Display Unit CRTC functions
100 static void vmw_sou_crtc_destroy(struct drm_crtc *crtc)
102 vmw_sou_destroy(vmw_crtc_to_sou(crtc));
106 * Send the fifo command to create a screen.
108 static int vmw_sou_fifo_create(struct vmw_private *dev_priv,
109 struct vmw_screen_object_unit *sou,
110 uint32_t x, uint32_t y,
111 struct drm_display_mode *mode)
119 SVGAScreenObject obj;
122 BUG_ON(!sou->buffer);
124 fifo_size = sizeof(*cmd);
125 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
126 /* The hardware has hung, nothing we can do about it here. */
127 if (unlikely(cmd == NULL)) {
128 DRM_ERROR("Fifo reserve failed.\n");
132 memset(cmd, 0, fifo_size);
133 cmd->header.cmdType = SVGA_CMD_DEFINE_SCREEN;
134 cmd->obj.structSize = sizeof(SVGAScreenObject);
135 cmd->obj.id = sou->base.unit;
136 cmd->obj.flags = SVGA_SCREEN_HAS_ROOT |
137 (sou->base.unit == 0 ? SVGA_SCREEN_IS_PRIMARY : 0);
138 cmd->obj.size.width = mode->hdisplay;
139 cmd->obj.size.height = mode->vdisplay;
140 if (sou->base.is_implicit) {
144 cmd->obj.root.x = sou->base.gui_x;
145 cmd->obj.root.y = sou->base.gui_y;
147 sou->base.set_gui_x = cmd->obj.root.x;
148 sou->base.set_gui_y = cmd->obj.root.y;
150 /* Ok to assume that buffer is pinned in vram */
151 vmw_bo_get_guest_ptr(&sou->buffer->base, &cmd->obj.backingStore.ptr);
152 cmd->obj.backingStore.pitch = mode->hdisplay * 4;
154 vmw_fifo_commit(dev_priv, fifo_size);
162 * Send the fifo command to destroy a screen.
164 static int vmw_sou_fifo_destroy(struct vmw_private *dev_priv,
165 struct vmw_screen_object_unit *sou)
174 SVGAFifoCmdDestroyScreen body;
177 /* no need to do anything */
178 if (unlikely(!sou->defined))
181 fifo_size = sizeof(*cmd);
182 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
183 /* the hardware has hung, nothing we can do about it here */
184 if (unlikely(cmd == NULL)) {
185 DRM_ERROR("Fifo reserve failed.\n");
189 memset(cmd, 0, fifo_size);
190 cmd->header.cmdType = SVGA_CMD_DESTROY_SCREEN;
191 cmd->body.screenId = sou->base.unit;
193 vmw_fifo_commit(dev_priv, fifo_size);
196 ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
197 if (unlikely(ret != 0))
198 DRM_ERROR("Failed to sync with HW");
200 sou->defined = false;
206 * Free the backing store.
208 static void vmw_sou_backing_free(struct vmw_private *dev_priv,
209 struct vmw_screen_object_unit *sou)
211 vmw_dmabuf_unreference(&sou->buffer);
212 sou->buffer_size = 0;
216 * Allocate the backing store for the buffer.
218 static int vmw_sou_backing_alloc(struct vmw_private *dev_priv,
219 struct vmw_screen_object_unit *sou,
224 if (sou->buffer_size == size)
228 vmw_sou_backing_free(dev_priv, sou);
230 sou->buffer = kzalloc(sizeof(*sou->buffer), GFP_KERNEL);
231 if (unlikely(sou->buffer == NULL))
234 /* After we have alloced the backing store might not be able to
235 * resume the overlays, this is preferred to failing to alloc.
237 vmw_overlay_pause_all(dev_priv);
238 ret = vmw_dmabuf_init(dev_priv, sou->buffer, size,
239 &vmw_vram_ne_placement,
240 false, &vmw_dmabuf_bo_free);
241 vmw_overlay_resume_all(dev_priv);
243 if (unlikely(ret != 0))
244 sou->buffer = NULL; /* vmw_dmabuf_init frees on error */
246 sou->buffer_size = size;
251 static int vmw_sou_crtc_set_config(struct drm_mode_set *set,
252 struct drm_modeset_acquire_ctx *ctx)
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 /* Only one active implicit frame-buffer at a time. */
289 mutex_lock(&dev_priv->global_kms_state_mutex);
290 if (sou->base.is_implicit &&
291 dev_priv->implicit_fb && vfb &&
292 !(dev_priv->num_implicit == 1 &&
293 sou->base.active_implicit) &&
294 dev_priv->implicit_fb != vfb) {
295 mutex_unlock(&dev_priv->global_kms_state_mutex);
296 DRM_ERROR("Multiple implicit framebuffers not supported.\n");
299 mutex_unlock(&dev_priv->global_kms_state_mutex);
301 /* since they always map one to one these are safe */
302 connector = &sou->base.connector;
303 encoder = &sou->base.encoder;
305 /* should we turn the crtc off */
306 if (set->num_connectors == 0 || !set->mode || !set->fb) {
307 ret = vmw_sou_fifo_destroy(dev_priv, sou);
308 /* the hardware has hung don't do anything more */
309 if (unlikely(ret != 0))
312 connector->encoder = NULL;
313 encoder->crtc = NULL;
314 crtc->primary->fb = NULL;
317 crtc->enabled = false;
319 vmw_kms_del_active(dev_priv, &sou->base);
321 vmw_sou_backing_free(dev_priv, sou);
327 /* we now know we want to set a mode */
331 if (set->x + mode->hdisplay > fb->width ||
332 set->y + mode->vdisplay > fb->height) {
333 DRM_ERROR("set outside of framebuffer\n");
337 vmw_svga_enable(dev_priv);
339 if (mode->hdisplay != crtc->mode.hdisplay ||
340 mode->vdisplay != crtc->mode.vdisplay) {
341 /* no need to check if depth is different, because backing
342 * store depth is forced to 4 by the device.
345 ret = vmw_sou_fifo_destroy(dev_priv, sou);
346 /* the hardware has hung don't do anything more */
347 if (unlikely(ret != 0))
350 vmw_sou_backing_free(dev_priv, sou);
354 /* forced to depth 4 by the device */
355 size_t size = mode->hdisplay * mode->vdisplay * 4;
356 ret = vmw_sou_backing_alloc(dev_priv, sou, size);
357 if (unlikely(ret != 0))
361 ret = vmw_sou_fifo_create(dev_priv, sou, set->x, set->y, mode);
362 if (unlikely(ret != 0)) {
364 * We are in a bit of a situation here, the hardware has
365 * hung and we may or may not have a buffer hanging of
366 * the screen object, best thing to do is not do anything
367 * if we where defined, if not just turn the crtc of.
368 * Not what userspace wants but it needs to htfu.
373 connector->encoder = NULL;
374 encoder->crtc = NULL;
375 crtc->primary->fb = NULL;
378 crtc->enabled = false;
383 vmw_kms_add_active(dev_priv, &sou->base, vfb);
385 connector->encoder = encoder;
386 encoder->crtc = crtc;
388 crtc->primary->fb = fb;
391 crtc->enabled = true;
396 static int vmw_sou_crtc_page_flip(struct drm_crtc *crtc,
397 struct drm_framebuffer *fb,
398 struct drm_pending_vblank_event *event,
400 struct drm_modeset_acquire_ctx *ctx)
402 struct vmw_private *dev_priv = vmw_priv(crtc->dev);
403 struct drm_framebuffer *old_fb = crtc->primary->fb;
404 struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(fb);
405 struct vmw_fence_obj *fence = NULL;
406 struct drm_vmw_rect vclips;
409 if (!vmw_kms_crtc_flippable(dev_priv, crtc))
412 crtc->primary->fb = fb;
414 /* do a full screen dirty update */
417 vclips.w = crtc->mode.hdisplay;
418 vclips.h = crtc->mode.vdisplay;
421 ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, vfb,
425 ret = vmw_kms_sou_do_surface_dirty(dev_priv, vfb,
438 struct drm_file *file_priv = event->base.file_priv;
440 ret = vmw_event_fence_action_queue(file_priv, fence,
442 &event->event.tv_sec,
443 &event->event.tv_usec,
448 * No need to hold on to this now. The only cleanup
449 * we need to do if we fail is unref the fence.
451 vmw_fence_obj_unreference(&fence);
453 if (vmw_crtc_to_du(crtc)->is_implicit)
454 vmw_kms_update_implicit_fb(dev_priv, crtc);
459 crtc->primary->fb = old_fb;
463 static const struct drm_crtc_funcs vmw_screen_object_crtc_funcs = {
464 .cursor_set2 = vmw_du_crtc_cursor_set2,
465 .cursor_move = vmw_du_crtc_cursor_move,
466 .gamma_set = vmw_du_crtc_gamma_set,
467 .destroy = vmw_sou_crtc_destroy,
468 .set_config = vmw_sou_crtc_set_config,
469 .page_flip = vmw_sou_crtc_page_flip,
473 * Screen Object Display Unit encoder functions
476 static void vmw_sou_encoder_destroy(struct drm_encoder *encoder)
478 vmw_sou_destroy(vmw_encoder_to_sou(encoder));
481 static const struct drm_encoder_funcs vmw_screen_object_encoder_funcs = {
482 .destroy = vmw_sou_encoder_destroy,
486 * Screen Object Display Unit connector functions
489 static void vmw_sou_connector_destroy(struct drm_connector *connector)
491 vmw_sou_destroy(vmw_connector_to_sou(connector));
494 static const struct drm_connector_funcs vmw_sou_connector_funcs = {
495 .dpms = vmw_du_connector_dpms,
496 .detect = vmw_du_connector_detect,
497 .fill_modes = vmw_du_connector_fill_modes,
498 .set_property = vmw_du_connector_set_property,
499 .destroy = vmw_sou_connector_destroy,
502 static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
504 struct vmw_screen_object_unit *sou;
505 struct drm_device *dev = dev_priv->dev;
506 struct drm_connector *connector;
507 struct drm_encoder *encoder;
508 struct drm_crtc *crtc;
510 sou = kzalloc(sizeof(*sou), GFP_KERNEL);
514 sou->base.unit = unit;
515 crtc = &sou->base.crtc;
516 encoder = &sou->base.encoder;
517 connector = &sou->base.connector;
519 sou->base.active_implicit = false;
520 sou->base.pref_active = (unit == 0);
521 sou->base.pref_width = dev_priv->initial_width;
522 sou->base.pref_height = dev_priv->initial_height;
523 sou->base.pref_mode = NULL;
524 sou->base.is_implicit = false;
526 drm_connector_init(dev, connector, &vmw_sou_connector_funcs,
527 DRM_MODE_CONNECTOR_VIRTUAL);
528 connector->status = vmw_du_connector_detect(connector, true);
530 drm_encoder_init(dev, encoder, &vmw_screen_object_encoder_funcs,
531 DRM_MODE_ENCODER_VIRTUAL, NULL);
532 drm_mode_connector_attach_encoder(connector, encoder);
533 encoder->possible_crtcs = (1 << unit);
534 encoder->possible_clones = 0;
536 (void) drm_connector_register(connector);
538 drm_crtc_init(dev, crtc, &vmw_screen_object_crtc_funcs);
540 drm_mode_crtc_set_gamma_size(crtc, 256);
542 drm_object_attach_property(&connector->base,
543 dev_priv->hotplug_mode_update_property, 1);
544 drm_object_attach_property(&connector->base,
545 dev->mode_config.suggested_x_property, 0);
546 drm_object_attach_property(&connector->base,
547 dev->mode_config.suggested_y_property, 0);
548 if (dev_priv->implicit_placement_property)
549 drm_object_attach_property
551 dev_priv->implicit_placement_property,
552 sou->base.is_implicit);
557 int vmw_kms_sou_init_display(struct vmw_private *dev_priv)
559 struct drm_device *dev = dev_priv->dev;
562 if (!(dev_priv->capabilities & SVGA_CAP_SCREEN_OBJECT_2)) {
563 DRM_INFO("Not using screen objects,"
564 " missing cap SCREEN_OBJECT_2\n");
569 dev_priv->num_implicit = 0;
570 dev_priv->implicit_fb = NULL;
572 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
573 if (unlikely(ret != 0))
576 vmw_kms_create_implicit_placement_property(dev_priv, false);
578 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
579 vmw_sou_init(dev_priv, i);
581 dev_priv->active_display_unit = vmw_du_screen_object;
583 DRM_INFO("Screen Objects Display Unit initialized\n");
588 int vmw_kms_sou_close_display(struct vmw_private *dev_priv)
590 struct drm_device *dev = dev_priv->dev;
592 drm_vblank_cleanup(dev);
597 static int do_dmabuf_define_gmrfb(struct vmw_private *dev_priv,
598 struct vmw_framebuffer *framebuffer)
600 struct vmw_dma_buffer *buf =
601 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
603 int depth = framebuffer->base.format->depth;
606 SVGAFifoCmdDefineGMRFB body;
609 /* Emulate RGBA support, contrary to svga_reg.h this is not
610 * supported by hosts. This is only a problem if we are reading
611 * this value later and expecting what we uploaded back.
616 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
618 DRM_ERROR("Out of fifo space for dirty framebuffer command.\n");
622 cmd->header = SVGA_CMD_DEFINE_GMRFB;
623 cmd->body.format.bitsPerPixel = framebuffer->base.format->cpp[0] * 8;
624 cmd->body.format.colorDepth = depth;
625 cmd->body.format.reserved = 0;
626 cmd->body.bytesPerLine = framebuffer->base.pitches[0];
627 /* Buffer is reserved in vram or GMR */
628 vmw_bo_get_guest_ptr(&buf->base, &cmd->body.ptr);
629 vmw_fifo_commit(dev_priv, sizeof(*cmd));
635 * vmw_sou_surface_fifo_commit - Callback to fill in and submit a
636 * blit surface to screen command.
638 * @dirty: The closure structure.
640 * Fills in the missing fields in the command, and translates the cliprects
641 * to match the destination bounding box encoded.
643 static void vmw_sou_surface_fifo_commit(struct vmw_kms_dirty *dirty)
645 struct vmw_kms_sou_surface_dirty *sdirty =
646 container_of(dirty, typeof(*sdirty), base);
647 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
648 s32 trans_x = dirty->unit->crtc.x - sdirty->dst_x;
649 s32 trans_y = dirty->unit->crtc.y - sdirty->dst_y;
650 size_t region_size = dirty->num_hits * sizeof(SVGASignedRect);
651 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
654 if (!dirty->num_hits) {
655 vmw_fifo_commit(dirty->dev_priv, 0);
659 cmd->header.id = SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN;
660 cmd->header.size = sizeof(cmd->body) + region_size;
663 * Use the destination bounding box to specify destination - and
664 * source bounding regions.
666 cmd->body.destRect.left = sdirty->left;
667 cmd->body.destRect.right = sdirty->right;
668 cmd->body.destRect.top = sdirty->top;
669 cmd->body.destRect.bottom = sdirty->bottom;
671 cmd->body.srcRect.left = sdirty->left + trans_x;
672 cmd->body.srcRect.right = sdirty->right + trans_x;
673 cmd->body.srcRect.top = sdirty->top + trans_y;
674 cmd->body.srcRect.bottom = sdirty->bottom + trans_y;
676 cmd->body.srcImage.sid = sdirty->sid;
677 cmd->body.destScreenId = dirty->unit->unit;
679 /* Blits are relative to the destination rect. Translate. */
680 for (i = 0; i < dirty->num_hits; ++i, ++blit) {
681 blit->left -= sdirty->left;
682 blit->right -= sdirty->left;
683 blit->top -= sdirty->top;
684 blit->bottom -= sdirty->top;
687 vmw_fifo_commit(dirty->dev_priv, region_size + sizeof(*cmd));
689 sdirty->left = sdirty->top = S32_MAX;
690 sdirty->right = sdirty->bottom = S32_MIN;
694 * vmw_sou_surface_clip - Callback to encode a blit surface to screen cliprect.
696 * @dirty: The closure structure
698 * Encodes a SVGASignedRect cliprect and updates the bounding box of the
699 * BLIT_SURFACE_TO_SCREEN command.
701 static void vmw_sou_surface_clip(struct vmw_kms_dirty *dirty)
703 struct vmw_kms_sou_surface_dirty *sdirty =
704 container_of(dirty, typeof(*sdirty), base);
705 struct vmw_kms_sou_dirty_cmd *cmd = dirty->cmd;
706 SVGASignedRect *blit = (SVGASignedRect *) &cmd[1];
708 /* Destination rect. */
709 blit += dirty->num_hits;
710 blit->left = dirty->unit_x1;
711 blit->top = dirty->unit_y1;
712 blit->right = dirty->unit_x2;
713 blit->bottom = dirty->unit_y2;
715 /* Destination bounding box */
716 sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
717 sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
718 sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
719 sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
725 * vmw_kms_sou_do_surface_dirty - Dirty part of a surface backed framebuffer
727 * @dev_priv: Pointer to the device private structure.
728 * @framebuffer: Pointer to the surface-buffer backed framebuffer.
729 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
730 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
732 * @srf: Pointer to surface to blit from. If NULL, the surface attached
733 * to @framebuffer will be used.
734 * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
735 * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
736 * @num_clips: Number of clip rects in @clips.
737 * @inc: Increment to use when looping over @clips.
738 * @out_fence: If non-NULL, will return a ref-counted pointer to a
739 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
740 * case the device has already synchronized.
742 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
745 int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
746 struct vmw_framebuffer *framebuffer,
747 struct drm_clip_rect *clips,
748 struct drm_vmw_rect *vclips,
749 struct vmw_resource *srf,
752 unsigned num_clips, int inc,
753 struct vmw_fence_obj **out_fence)
755 struct vmw_framebuffer_surface *vfbs =
756 container_of(framebuffer, typeof(*vfbs), base);
757 struct vmw_kms_sou_surface_dirty sdirty;
761 srf = &vfbs->surface->res;
763 ret = vmw_kms_helper_resource_prepare(srf, true);
767 sdirty.base.fifo_commit = vmw_sou_surface_fifo_commit;
768 sdirty.base.clip = vmw_sou_surface_clip;
769 sdirty.base.dev_priv = dev_priv;
770 sdirty.base.fifo_reserve_size = sizeof(struct vmw_kms_sou_dirty_cmd) +
771 sizeof(SVGASignedRect) * num_clips;
773 sdirty.sid = srf->id;
774 sdirty.left = sdirty.top = S32_MAX;
775 sdirty.right = sdirty.bottom = S32_MIN;
776 sdirty.dst_x = dest_x;
777 sdirty.dst_y = dest_y;
779 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
780 dest_x, dest_y, num_clips, inc,
782 vmw_kms_helper_resource_finish(srf, out_fence);
788 * vmw_sou_dmabuf_fifo_commit - Callback to submit a set of readback clips.
790 * @dirty: The closure structure.
792 * Commits a previously built command buffer of readback clips.
794 static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
796 if (!dirty->num_hits) {
797 vmw_fifo_commit(dirty->dev_priv, 0);
801 vmw_fifo_commit(dirty->dev_priv,
802 sizeof(struct vmw_kms_sou_dmabuf_blit) *
807 * vmw_sou_dmabuf_clip - Callback to encode a readback cliprect.
809 * @dirty: The closure structure
811 * Encodes a BLIT_GMRFB_TO_SCREEN cliprect.
813 static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty *dirty)
815 struct vmw_kms_sou_dmabuf_blit *blit = dirty->cmd;
817 blit += dirty->num_hits;
818 blit->header = SVGA_CMD_BLIT_GMRFB_TO_SCREEN;
819 blit->body.destScreenId = dirty->unit->unit;
820 blit->body.srcOrigin.x = dirty->fb_x;
821 blit->body.srcOrigin.y = dirty->fb_y;
822 blit->body.destRect.left = dirty->unit_x1;
823 blit->body.destRect.top = dirty->unit_y1;
824 blit->body.destRect.right = dirty->unit_x2;
825 blit->body.destRect.bottom = dirty->unit_y2;
830 * vmw_kms_do_dmabuf_dirty - Dirty part of a dma-buffer backed framebuffer
832 * @dev_priv: Pointer to the device private structure.
833 * @framebuffer: Pointer to the dma-buffer backed framebuffer.
834 * @clips: Array of clip rects.
835 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
837 * @num_clips: Number of clip rects in @clips.
838 * @increment: Increment to use when looping over @clips.
839 * @interruptible: Whether to perform waits interruptible if possible.
840 * @out_fence: If non-NULL, will return a ref-counted pointer to a
841 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
842 * case the device has already synchronized.
844 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
847 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
848 struct vmw_framebuffer *framebuffer,
849 struct drm_clip_rect *clips,
850 struct drm_vmw_rect *vclips,
851 unsigned num_clips, int increment,
853 struct vmw_fence_obj **out_fence)
855 struct vmw_dma_buffer *buf =
856 container_of(framebuffer, struct vmw_framebuffer_dmabuf,
858 struct vmw_kms_dirty dirty;
861 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
866 ret = do_dmabuf_define_gmrfb(dev_priv, framebuffer);
867 if (unlikely(ret != 0))
870 dirty.fifo_commit = vmw_sou_dmabuf_fifo_commit;
871 dirty.clip = vmw_sou_dmabuf_clip;
872 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_dmabuf_blit) *
874 ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
875 0, 0, num_clips, increment, &dirty);
876 vmw_kms_helper_buffer_finish(dev_priv, NULL, buf, out_fence, NULL);
881 vmw_kms_helper_buffer_revert(buf);
888 * vmw_sou_readback_fifo_commit - Callback to submit a set of readback clips.
890 * @dirty: The closure structure.
892 * Commits a previously built command buffer of readback clips.
894 static void vmw_sou_readback_fifo_commit(struct vmw_kms_dirty *dirty)
896 if (!dirty->num_hits) {
897 vmw_fifo_commit(dirty->dev_priv, 0);
901 vmw_fifo_commit(dirty->dev_priv,
902 sizeof(struct vmw_kms_sou_readback_blit) *
907 * vmw_sou_readback_clip - Callback to encode a readback cliprect.
909 * @dirty: The closure structure
911 * Encodes a BLIT_SCREEN_TO_GMRFB cliprect.
913 static void vmw_sou_readback_clip(struct vmw_kms_dirty *dirty)
915 struct vmw_kms_sou_readback_blit *blit = dirty->cmd;
917 blit += dirty->num_hits;
918 blit->header = SVGA_CMD_BLIT_SCREEN_TO_GMRFB;
919 blit->body.srcScreenId = dirty->unit->unit;
920 blit->body.destOrigin.x = dirty->fb_x;
921 blit->body.destOrigin.y = dirty->fb_y;
922 blit->body.srcRect.left = dirty->unit_x1;
923 blit->body.srcRect.top = dirty->unit_y1;
924 blit->body.srcRect.right = dirty->unit_x2;
925 blit->body.srcRect.bottom = dirty->unit_y2;
930 * vmw_kms_sou_readback - Perform a readback from the screen object system to
931 * a dma-buffer backed framebuffer.
933 * @dev_priv: Pointer to the device private structure.
934 * @file_priv: Pointer to a struct drm_file identifying the caller.
935 * Must be set to NULL if @user_fence_rep is NULL.
936 * @vfb: Pointer to the dma-buffer backed framebuffer.
937 * @user_fence_rep: User-space provided structure for fence information.
938 * Must be set to non-NULL if @file_priv is non-NULL.
939 * @vclips: Array of clip rects.
940 * @num_clips: Number of clip rects in @vclips.
942 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
945 int vmw_kms_sou_readback(struct vmw_private *dev_priv,
946 struct drm_file *file_priv,
947 struct vmw_framebuffer *vfb,
948 struct drm_vmw_fence_rep __user *user_fence_rep,
949 struct drm_vmw_rect *vclips,
952 struct vmw_dma_buffer *buf =
953 container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
954 struct vmw_kms_dirty dirty;
957 ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, true, false);
961 ret = do_dmabuf_define_gmrfb(dev_priv, vfb);
962 if (unlikely(ret != 0))
965 dirty.fifo_commit = vmw_sou_readback_fifo_commit;
966 dirty.clip = vmw_sou_readback_clip;
967 dirty.fifo_reserve_size = sizeof(struct vmw_kms_sou_readback_blit) *
969 ret = vmw_kms_helper_dirty(dev_priv, vfb, NULL, vclips,
970 0, 0, num_clips, 1, &dirty);
971 vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
977 vmw_kms_helper_buffer_revert(buf);