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
)
253 struct vmw_private
*dev_priv
;
254 struct vmw_screen_object_unit
*sou
;
255 struct drm_connector
*connector
;
256 struct drm_display_mode
*mode
;
257 struct drm_encoder
*encoder
;
258 struct vmw_framebuffer
*vfb
;
259 struct drm_framebuffer
*fb
;
260 struct drm_crtc
*crtc
;
271 sou
= vmw_crtc_to_sou(crtc
);
272 vfb
= set
->fb
? vmw_framebuffer_to_vfb(set
->fb
) : NULL
;
273 dev_priv
= vmw_priv(crtc
->dev
);
275 if (set
->num_connectors
> 1) {
276 DRM_ERROR("Too many connectors\n");
280 if (set
->num_connectors
== 1 &&
281 set
->connectors
[0] != &sou
->base
.connector
) {
282 DRM_ERROR("Connector doesn't match %p %p\n",
283 set
->connectors
[0], &sou
->base
.connector
);
287 /* Only one active implicit frame-buffer at a time. */
288 if (sou
->base
.is_implicit
&&
289 dev_priv
->implicit_fb
&& vfb
&&
290 !(dev_priv
->num_implicit
== 1 &&
291 sou
->base
.active_implicit
) &&
292 dev_priv
->implicit_fb
!= vfb
) {
293 DRM_ERROR("Multiple implicit framebuffers not supported.\n");
297 /* since they always map one to one these are safe */
298 connector
= &sou
->base
.connector
;
299 encoder
= &sou
->base
.encoder
;
301 /* should we turn the crtc off */
302 if (set
->num_connectors
== 0 || !set
->mode
|| !set
->fb
) {
303 ret
= vmw_sou_fifo_destroy(dev_priv
, sou
);
304 /* the hardware has hung don't do anything more */
305 if (unlikely(ret
!= 0))
308 connector
->encoder
= NULL
;
309 encoder
->crtc
= NULL
;
310 crtc
->primary
->fb
= NULL
;
313 crtc
->enabled
= false;
315 vmw_kms_del_active(dev_priv
, &sou
->base
);
317 vmw_sou_backing_free(dev_priv
, sou
);
323 /* we now know we want to set a mode */
327 if (set
->x
+ mode
->hdisplay
> fb
->width
||
328 set
->y
+ mode
->vdisplay
> fb
->height
) {
329 DRM_ERROR("set outside of framebuffer\n");
333 vmw_svga_enable(dev_priv
);
335 if (mode
->hdisplay
!= crtc
->mode
.hdisplay
||
336 mode
->vdisplay
!= crtc
->mode
.vdisplay
) {
337 /* no need to check if depth is different, because backing
338 * store depth is forced to 4 by the device.
341 ret
= vmw_sou_fifo_destroy(dev_priv
, sou
);
342 /* the hardware has hung don't do anything more */
343 if (unlikely(ret
!= 0))
346 vmw_sou_backing_free(dev_priv
, sou
);
350 /* forced to depth 4 by the device */
351 size_t size
= mode
->hdisplay
* mode
->vdisplay
* 4;
352 ret
= vmw_sou_backing_alloc(dev_priv
, sou
, size
);
353 if (unlikely(ret
!= 0))
357 ret
= vmw_sou_fifo_create(dev_priv
, sou
, set
->x
, set
->y
, mode
);
358 if (unlikely(ret
!= 0)) {
360 * We are in a bit of a situation here, the hardware has
361 * hung and we may or may not have a buffer hanging of
362 * the screen object, best thing to do is not do anything
363 * if we where defined, if not just turn the crtc of.
364 * Not what userspace wants but it needs to htfu.
369 connector
->encoder
= NULL
;
370 encoder
->crtc
= NULL
;
371 crtc
->primary
->fb
= NULL
;
374 crtc
->enabled
= false;
379 vmw_kms_add_active(dev_priv
, &sou
->base
, vfb
);
381 connector
->encoder
= encoder
;
382 encoder
->crtc
= crtc
;
384 crtc
->primary
->fb
= fb
;
387 crtc
->enabled
= true;
392 static int vmw_sou_crtc_page_flip(struct drm_crtc
*crtc
,
393 struct drm_framebuffer
*fb
,
394 struct drm_pending_vblank_event
*event
,
397 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
398 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
399 struct vmw_framebuffer
*vfb
= vmw_framebuffer_to_vfb(fb
);
400 struct vmw_fence_obj
*fence
= NULL
;
401 struct drm_vmw_rect vclips
;
404 if (!vmw_kms_crtc_flippable(dev_priv
, crtc
))
407 crtc
->primary
->fb
= fb
;
409 /* do a full screen dirty update */
412 vclips
.w
= crtc
->mode
.hdisplay
;
413 vclips
.h
= crtc
->mode
.vdisplay
;
416 ret
= vmw_kms_sou_do_dmabuf_dirty(dev_priv
, vfb
,
420 ret
= vmw_kms_sou_do_surface_dirty(dev_priv
, vfb
,
433 struct drm_file
*file_priv
= event
->base
.file_priv
;
435 ret
= vmw_event_fence_action_queue(file_priv
, fence
,
437 &event
->event
.tv_sec
,
438 &event
->event
.tv_usec
,
443 * No need to hold on to this now. The only cleanup
444 * we need to do if we fail is unref the fence.
446 vmw_fence_obj_unreference(&fence
);
448 if (vmw_crtc_to_du(crtc
)->is_implicit
)
449 vmw_kms_update_implicit_fb(dev_priv
, crtc
);
454 crtc
->primary
->fb
= old_fb
;
458 static const struct drm_crtc_funcs vmw_screen_object_crtc_funcs
= {
459 .cursor_set2
= vmw_du_crtc_cursor_set2
,
460 .cursor_move
= vmw_du_crtc_cursor_move
,
461 .gamma_set
= vmw_du_crtc_gamma_set
,
462 .destroy
= vmw_sou_crtc_destroy
,
463 .set_config
= vmw_sou_crtc_set_config
,
464 .page_flip
= vmw_sou_crtc_page_flip
,
468 * Screen Object Display Unit encoder functions
471 static void vmw_sou_encoder_destroy(struct drm_encoder
*encoder
)
473 vmw_sou_destroy(vmw_encoder_to_sou(encoder
));
476 static const struct drm_encoder_funcs vmw_screen_object_encoder_funcs
= {
477 .destroy
= vmw_sou_encoder_destroy
,
481 * Screen Object Display Unit connector functions
484 static void vmw_sou_connector_destroy(struct drm_connector
*connector
)
486 vmw_sou_destroy(vmw_connector_to_sou(connector
));
489 static const struct drm_connector_funcs vmw_sou_connector_funcs
= {
490 .dpms
= vmw_du_connector_dpms
,
491 .detect
= vmw_du_connector_detect
,
492 .fill_modes
= vmw_du_connector_fill_modes
,
493 .set_property
= vmw_du_connector_set_property
,
494 .destroy
= vmw_sou_connector_destroy
,
497 static int vmw_sou_init(struct vmw_private
*dev_priv
, unsigned unit
)
499 struct vmw_screen_object_unit
*sou
;
500 struct drm_device
*dev
= dev_priv
->dev
;
501 struct drm_connector
*connector
;
502 struct drm_encoder
*encoder
;
503 struct drm_crtc
*crtc
;
505 sou
= kzalloc(sizeof(*sou
), GFP_KERNEL
);
509 sou
->base
.unit
= unit
;
510 crtc
= &sou
->base
.crtc
;
511 encoder
= &sou
->base
.encoder
;
512 connector
= &sou
->base
.connector
;
514 sou
->base
.active_implicit
= false;
515 sou
->base
.pref_active
= (unit
== 0);
516 sou
->base
.pref_width
= dev_priv
->initial_width
;
517 sou
->base
.pref_height
= dev_priv
->initial_height
;
518 sou
->base
.pref_mode
= NULL
;
519 sou
->base
.is_implicit
= false;
521 drm_connector_init(dev
, connector
, &vmw_sou_connector_funcs
,
522 DRM_MODE_CONNECTOR_VIRTUAL
);
523 connector
->status
= vmw_du_connector_detect(connector
, true);
525 drm_encoder_init(dev
, encoder
, &vmw_screen_object_encoder_funcs
,
526 DRM_MODE_ENCODER_VIRTUAL
, NULL
);
527 drm_mode_connector_attach_encoder(connector
, encoder
);
528 encoder
->possible_crtcs
= (1 << unit
);
529 encoder
->possible_clones
= 0;
531 (void) drm_connector_register(connector
);
533 drm_crtc_init(dev
, crtc
, &vmw_screen_object_crtc_funcs
);
535 drm_mode_crtc_set_gamma_size(crtc
, 256);
537 drm_object_attach_property(&connector
->base
,
538 dev
->mode_config
.dirty_info_property
,
540 drm_object_attach_property(&connector
->base
,
541 dev_priv
->hotplug_mode_update_property
, 1);
542 drm_object_attach_property(&connector
->base
,
543 dev
->mode_config
.suggested_x_property
, 0);
544 drm_object_attach_property(&connector
->base
,
545 dev
->mode_config
.suggested_y_property
, 0);
546 if (dev_priv
->implicit_placement_property
)
547 drm_object_attach_property
549 dev_priv
->implicit_placement_property
,
550 sou
->base
.is_implicit
);
555 int vmw_kms_sou_init_display(struct vmw_private
*dev_priv
)
557 struct drm_device
*dev
= dev_priv
->dev
;
560 if (!(dev_priv
->capabilities
& SVGA_CAP_SCREEN_OBJECT_2
)) {
561 DRM_INFO("Not using screen objects,"
562 " missing cap SCREEN_OBJECT_2\n");
567 dev_priv
->num_implicit
= 0;
568 dev_priv
->implicit_fb
= NULL
;
570 ret
= drm_vblank_init(dev
, VMWGFX_NUM_DISPLAY_UNITS
);
571 if (unlikely(ret
!= 0))
574 ret
= drm_mode_create_dirty_info_property(dev
);
575 if (unlikely(ret
!= 0))
576 goto err_vblank_cleanup
;
578 vmw_kms_create_implicit_placement_property(dev_priv
, false);
580 for (i
= 0; i
< VMWGFX_NUM_DISPLAY_UNITS
; ++i
)
581 vmw_sou_init(dev_priv
, i
);
583 dev_priv
->active_display_unit
= vmw_du_screen_object
;
585 DRM_INFO("Screen Objects Display Unit initialized\n");
590 drm_vblank_cleanup(dev
);
594 int vmw_kms_sou_close_display(struct vmw_private
*dev_priv
)
596 struct drm_device
*dev
= dev_priv
->dev
;
598 drm_vblank_cleanup(dev
);
603 static int do_dmabuf_define_gmrfb(struct vmw_private
*dev_priv
,
604 struct vmw_framebuffer
*framebuffer
)
606 struct vmw_dma_buffer
*buf
=
607 container_of(framebuffer
, struct vmw_framebuffer_dmabuf
,
609 int depth
= framebuffer
->base
.depth
;
612 SVGAFifoCmdDefineGMRFB body
;
615 /* Emulate RGBA support, contrary to svga_reg.h this is not
616 * supported by hosts. This is only a problem if we are reading
617 * this value later and expecting what we uploaded back.
622 cmd
= vmw_fifo_reserve(dev_priv
, sizeof(*cmd
));
624 DRM_ERROR("Out of fifo space for dirty framebuffer command.\n");
628 cmd
->header
= SVGA_CMD_DEFINE_GMRFB
;
629 cmd
->body
.format
.bitsPerPixel
= framebuffer
->base
.bits_per_pixel
;
630 cmd
->body
.format
.colorDepth
= depth
;
631 cmd
->body
.format
.reserved
= 0;
632 cmd
->body
.bytesPerLine
= framebuffer
->base
.pitches
[0];
633 /* Buffer is reserved in vram or GMR */
634 vmw_bo_get_guest_ptr(&buf
->base
, &cmd
->body
.ptr
);
635 vmw_fifo_commit(dev_priv
, sizeof(*cmd
));
641 * vmw_sou_surface_fifo_commit - Callback to fill in and submit a
642 * blit surface to screen command.
644 * @dirty: The closure structure.
646 * Fills in the missing fields in the command, and translates the cliprects
647 * to match the destination bounding box encoded.
649 static void vmw_sou_surface_fifo_commit(struct vmw_kms_dirty
*dirty
)
651 struct vmw_kms_sou_surface_dirty
*sdirty
=
652 container_of(dirty
, typeof(*sdirty
), base
);
653 struct vmw_kms_sou_dirty_cmd
*cmd
= dirty
->cmd
;
654 s32 trans_x
= dirty
->unit
->crtc
.x
- sdirty
->dst_x
;
655 s32 trans_y
= dirty
->unit
->crtc
.y
- sdirty
->dst_y
;
656 size_t region_size
= dirty
->num_hits
* sizeof(SVGASignedRect
);
657 SVGASignedRect
*blit
= (SVGASignedRect
*) &cmd
[1];
660 if (!dirty
->num_hits
) {
661 vmw_fifo_commit(dirty
->dev_priv
, 0);
665 cmd
->header
.id
= SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN
;
666 cmd
->header
.size
= sizeof(cmd
->body
) + region_size
;
669 * Use the destination bounding box to specify destination - and
670 * source bounding regions.
672 cmd
->body
.destRect
.left
= sdirty
->left
;
673 cmd
->body
.destRect
.right
= sdirty
->right
;
674 cmd
->body
.destRect
.top
= sdirty
->top
;
675 cmd
->body
.destRect
.bottom
= sdirty
->bottom
;
677 cmd
->body
.srcRect
.left
= sdirty
->left
+ trans_x
;
678 cmd
->body
.srcRect
.right
= sdirty
->right
+ trans_x
;
679 cmd
->body
.srcRect
.top
= sdirty
->top
+ trans_y
;
680 cmd
->body
.srcRect
.bottom
= sdirty
->bottom
+ trans_y
;
682 cmd
->body
.srcImage
.sid
= sdirty
->sid
;
683 cmd
->body
.destScreenId
= dirty
->unit
->unit
;
685 /* Blits are relative to the destination rect. Translate. */
686 for (i
= 0; i
< dirty
->num_hits
; ++i
, ++blit
) {
687 blit
->left
-= sdirty
->left
;
688 blit
->right
-= sdirty
->left
;
689 blit
->top
-= sdirty
->top
;
690 blit
->bottom
-= sdirty
->top
;
693 vmw_fifo_commit(dirty
->dev_priv
, region_size
+ sizeof(*cmd
));
695 sdirty
->left
= sdirty
->top
= S32_MAX
;
696 sdirty
->right
= sdirty
->bottom
= S32_MIN
;
700 * vmw_sou_surface_clip - Callback to encode a blit surface to screen cliprect.
702 * @dirty: The closure structure
704 * Encodes a SVGASignedRect cliprect and updates the bounding box of the
705 * BLIT_SURFACE_TO_SCREEN command.
707 static void vmw_sou_surface_clip(struct vmw_kms_dirty
*dirty
)
709 struct vmw_kms_sou_surface_dirty
*sdirty
=
710 container_of(dirty
, typeof(*sdirty
), base
);
711 struct vmw_kms_sou_dirty_cmd
*cmd
= dirty
->cmd
;
712 SVGASignedRect
*blit
= (SVGASignedRect
*) &cmd
[1];
714 /* Destination rect. */
715 blit
+= dirty
->num_hits
;
716 blit
->left
= dirty
->unit_x1
;
717 blit
->top
= dirty
->unit_y1
;
718 blit
->right
= dirty
->unit_x2
;
719 blit
->bottom
= dirty
->unit_y2
;
721 /* Destination bounding box */
722 sdirty
->left
= min_t(s32
, sdirty
->left
, dirty
->unit_x1
);
723 sdirty
->top
= min_t(s32
, sdirty
->top
, dirty
->unit_y1
);
724 sdirty
->right
= max_t(s32
, sdirty
->right
, dirty
->unit_x2
);
725 sdirty
->bottom
= max_t(s32
, sdirty
->bottom
, dirty
->unit_y2
);
731 * vmw_kms_sou_do_surface_dirty - Dirty part of a surface backed framebuffer
733 * @dev_priv: Pointer to the device private structure.
734 * @framebuffer: Pointer to the surface-buffer backed framebuffer.
735 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
736 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
738 * @srf: Pointer to surface to blit from. If NULL, the surface attached
739 * to @framebuffer will be used.
740 * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
741 * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
742 * @num_clips: Number of clip rects in @clips.
743 * @inc: Increment to use when looping over @clips.
744 * @out_fence: If non-NULL, will return a ref-counted pointer to a
745 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
746 * case the device has already synchronized.
748 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
751 int vmw_kms_sou_do_surface_dirty(struct vmw_private
*dev_priv
,
752 struct vmw_framebuffer
*framebuffer
,
753 struct drm_clip_rect
*clips
,
754 struct drm_vmw_rect
*vclips
,
755 struct vmw_resource
*srf
,
758 unsigned num_clips
, int inc
,
759 struct vmw_fence_obj
**out_fence
)
761 struct vmw_framebuffer_surface
*vfbs
=
762 container_of(framebuffer
, typeof(*vfbs
), base
);
763 struct vmw_kms_sou_surface_dirty sdirty
;
767 srf
= &vfbs
->surface
->res
;
769 ret
= vmw_kms_helper_resource_prepare(srf
, true);
773 sdirty
.base
.fifo_commit
= vmw_sou_surface_fifo_commit
;
774 sdirty
.base
.clip
= vmw_sou_surface_clip
;
775 sdirty
.base
.dev_priv
= dev_priv
;
776 sdirty
.base
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_dirty_cmd
) +
777 sizeof(SVGASignedRect
) * num_clips
;
779 sdirty
.sid
= srf
->id
;
780 sdirty
.left
= sdirty
.top
= S32_MAX
;
781 sdirty
.right
= sdirty
.bottom
= S32_MIN
;
782 sdirty
.dst_x
= dest_x
;
783 sdirty
.dst_y
= dest_y
;
785 ret
= vmw_kms_helper_dirty(dev_priv
, framebuffer
, clips
, vclips
,
786 dest_x
, dest_y
, num_clips
, inc
,
788 vmw_kms_helper_resource_finish(srf
, out_fence
);
794 * vmw_sou_dmabuf_fifo_commit - Callback to submit a set of readback clips.
796 * @dirty: The closure structure.
798 * Commits a previously built command buffer of readback clips.
800 static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty
*dirty
)
802 if (!dirty
->num_hits
) {
803 vmw_fifo_commit(dirty
->dev_priv
, 0);
807 vmw_fifo_commit(dirty
->dev_priv
,
808 sizeof(struct vmw_kms_sou_dmabuf_blit
) *
813 * vmw_sou_dmabuf_clip - Callback to encode a readback cliprect.
815 * @dirty: The closure structure
817 * Encodes a BLIT_GMRFB_TO_SCREEN cliprect.
819 static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty
*dirty
)
821 struct vmw_kms_sou_dmabuf_blit
*blit
= dirty
->cmd
;
823 blit
+= dirty
->num_hits
;
824 blit
->header
= SVGA_CMD_BLIT_GMRFB_TO_SCREEN
;
825 blit
->body
.destScreenId
= dirty
->unit
->unit
;
826 blit
->body
.srcOrigin
.x
= dirty
->fb_x
;
827 blit
->body
.srcOrigin
.y
= dirty
->fb_y
;
828 blit
->body
.destRect
.left
= dirty
->unit_x1
;
829 blit
->body
.destRect
.top
= dirty
->unit_y1
;
830 blit
->body
.destRect
.right
= dirty
->unit_x2
;
831 blit
->body
.destRect
.bottom
= dirty
->unit_y2
;
836 * vmw_kms_do_dmabuf_dirty - Dirty part of a dma-buffer backed framebuffer
838 * @dev_priv: Pointer to the device private structure.
839 * @framebuffer: Pointer to the dma-buffer backed framebuffer.
840 * @clips: Array of clip rects.
841 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
843 * @num_clips: Number of clip rects in @clips.
844 * @increment: Increment to use when looping over @clips.
845 * @interruptible: Whether to perform waits interruptible if possible.
846 * @out_fence: If non-NULL, will return a ref-counted pointer to a
847 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
848 * case the device has already synchronized.
850 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
853 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private
*dev_priv
,
854 struct vmw_framebuffer
*framebuffer
,
855 struct drm_clip_rect
*clips
,
856 struct drm_vmw_rect
*vclips
,
857 unsigned num_clips
, int increment
,
859 struct vmw_fence_obj
**out_fence
)
861 struct vmw_dma_buffer
*buf
=
862 container_of(framebuffer
, struct vmw_framebuffer_dmabuf
,
864 struct vmw_kms_dirty dirty
;
867 ret
= vmw_kms_helper_buffer_prepare(dev_priv
, buf
, interruptible
,
872 ret
= do_dmabuf_define_gmrfb(dev_priv
, framebuffer
);
873 if (unlikely(ret
!= 0))
876 dirty
.fifo_commit
= vmw_sou_dmabuf_fifo_commit
;
877 dirty
.clip
= vmw_sou_dmabuf_clip
;
878 dirty
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_dmabuf_blit
) *
880 ret
= vmw_kms_helper_dirty(dev_priv
, framebuffer
, clips
, vclips
,
881 0, 0, num_clips
, increment
, &dirty
);
882 vmw_kms_helper_buffer_finish(dev_priv
, NULL
, buf
, out_fence
, NULL
);
887 vmw_kms_helper_buffer_revert(buf
);
894 * vmw_sou_readback_fifo_commit - Callback to submit a set of readback clips.
896 * @dirty: The closure structure.
898 * Commits a previously built command buffer of readback clips.
900 static void vmw_sou_readback_fifo_commit(struct vmw_kms_dirty
*dirty
)
902 if (!dirty
->num_hits
) {
903 vmw_fifo_commit(dirty
->dev_priv
, 0);
907 vmw_fifo_commit(dirty
->dev_priv
,
908 sizeof(struct vmw_kms_sou_readback_blit
) *
913 * vmw_sou_readback_clip - Callback to encode a readback cliprect.
915 * @dirty: The closure structure
917 * Encodes a BLIT_SCREEN_TO_GMRFB cliprect.
919 static void vmw_sou_readback_clip(struct vmw_kms_dirty
*dirty
)
921 struct vmw_kms_sou_readback_blit
*blit
= dirty
->cmd
;
923 blit
+= dirty
->num_hits
;
924 blit
->header
= SVGA_CMD_BLIT_SCREEN_TO_GMRFB
;
925 blit
->body
.srcScreenId
= dirty
->unit
->unit
;
926 blit
->body
.destOrigin
.x
= dirty
->fb_x
;
927 blit
->body
.destOrigin
.y
= dirty
->fb_y
;
928 blit
->body
.srcRect
.left
= dirty
->unit_x1
;
929 blit
->body
.srcRect
.top
= dirty
->unit_y1
;
930 blit
->body
.srcRect
.right
= dirty
->unit_x2
;
931 blit
->body
.srcRect
.bottom
= dirty
->unit_y2
;
936 * vmw_kms_sou_readback - Perform a readback from the screen object system to
937 * a dma-buffer backed framebuffer.
939 * @dev_priv: Pointer to the device private structure.
940 * @file_priv: Pointer to a struct drm_file identifying the caller.
941 * Must be set to NULL if @user_fence_rep is NULL.
942 * @vfb: Pointer to the dma-buffer backed framebuffer.
943 * @user_fence_rep: User-space provided structure for fence information.
944 * Must be set to non-NULL if @file_priv is non-NULL.
945 * @vclips: Array of clip rects.
946 * @num_clips: Number of clip rects in @vclips.
948 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
951 int vmw_kms_sou_readback(struct vmw_private
*dev_priv
,
952 struct drm_file
*file_priv
,
953 struct vmw_framebuffer
*vfb
,
954 struct drm_vmw_fence_rep __user
*user_fence_rep
,
955 struct drm_vmw_rect
*vclips
,
958 struct vmw_dma_buffer
*buf
=
959 container_of(vfb
, struct vmw_framebuffer_dmabuf
, base
)->buffer
;
960 struct vmw_kms_dirty dirty
;
963 ret
= vmw_kms_helper_buffer_prepare(dev_priv
, buf
, true, false);
967 ret
= do_dmabuf_define_gmrfb(dev_priv
, vfb
);
968 if (unlikely(ret
!= 0))
971 dirty
.fifo_commit
= vmw_sou_readback_fifo_commit
;
972 dirty
.clip
= vmw_sou_readback_clip
;
973 dirty
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_readback_blit
) *
975 ret
= vmw_kms_helper_dirty(dev_priv
, vfb
, NULL
, vclips
,
976 0, 0, num_clips
, 1, &dirty
);
977 vmw_kms_helper_buffer_finish(dev_priv
, file_priv
, buf
, NULL
,
983 vmw_kms_helper_buffer_revert(buf
);