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
;
82 struct vmw_screen_object_display
{
83 unsigned num_implicit
;
85 struct vmw_framebuffer
*implicit_fb
;
86 SVGAFifoCmdDefineGMRFB cur
;
87 struct vmw_dma_buffer
*pinned_gmrfb
;
91 * Display unit using screen objects.
93 struct vmw_screen_object_unit
{
94 struct vmw_display_unit base
;
96 unsigned long buffer_size
; /**< Size of allocated buffer */
97 struct vmw_dma_buffer
*buffer
; /**< Backing store buffer */
100 bool active_implicit
;
103 static void vmw_sou_destroy(struct vmw_screen_object_unit
*sou
)
105 vmw_du_cleanup(&sou
->base
);
111 * Screen Object Display Unit CRTC functions
114 static void vmw_sou_crtc_destroy(struct drm_crtc
*crtc
)
116 vmw_sou_destroy(vmw_crtc_to_sou(crtc
));
119 static void vmw_sou_del_active(struct vmw_private
*vmw_priv
,
120 struct vmw_screen_object_unit
*sou
)
122 struct vmw_screen_object_display
*ld
= vmw_priv
->sou_priv
;
124 if (sou
->active_implicit
) {
125 if (--(ld
->num_implicit
) == 0)
126 ld
->implicit_fb
= NULL
;
127 sou
->active_implicit
= false;
131 static void vmw_sou_add_active(struct vmw_private
*vmw_priv
,
132 struct vmw_screen_object_unit
*sou
,
133 struct vmw_framebuffer
*vfb
)
135 struct vmw_screen_object_display
*ld
= vmw_priv
->sou_priv
;
137 BUG_ON(!ld
->num_implicit
&& ld
->implicit_fb
);
139 if (!sou
->active_implicit
&& sou
->base
.is_implicit
) {
140 ld
->implicit_fb
= vfb
;
141 sou
->active_implicit
= true;
147 * Send the fifo command to create a screen.
149 static int vmw_sou_fifo_create(struct vmw_private
*dev_priv
,
150 struct vmw_screen_object_unit
*sou
,
151 uint32_t x
, uint32_t y
,
152 struct drm_display_mode
*mode
)
160 SVGAScreenObject obj
;
163 BUG_ON(!sou
->buffer
);
165 fifo_size
= sizeof(*cmd
);
166 cmd
= vmw_fifo_reserve(dev_priv
, fifo_size
);
167 /* The hardware has hung, nothing we can do about it here. */
168 if (unlikely(cmd
== NULL
)) {
169 DRM_ERROR("Fifo reserve failed.\n");
173 memset(cmd
, 0, fifo_size
);
174 cmd
->header
.cmdType
= SVGA_CMD_DEFINE_SCREEN
;
175 cmd
->obj
.structSize
= sizeof(SVGAScreenObject
);
176 cmd
->obj
.id
= sou
->base
.unit
;
177 cmd
->obj
.flags
= SVGA_SCREEN_HAS_ROOT
|
178 (sou
->base
.unit
== 0 ? SVGA_SCREEN_IS_PRIMARY
: 0);
179 cmd
->obj
.size
.width
= mode
->hdisplay
;
180 cmd
->obj
.size
.height
= mode
->vdisplay
;
181 if (sou
->base
.is_implicit
) {
185 cmd
->obj
.root
.x
= sou
->base
.gui_x
;
186 cmd
->obj
.root
.y
= sou
->base
.gui_y
;
189 /* Ok to assume that buffer is pinned in vram */
190 vmw_bo_get_guest_ptr(&sou
->buffer
->base
, &cmd
->obj
.backingStore
.ptr
);
191 cmd
->obj
.backingStore
.pitch
= mode
->hdisplay
* 4;
193 vmw_fifo_commit(dev_priv
, fifo_size
);
201 * Send the fifo command to destroy a screen.
203 static int vmw_sou_fifo_destroy(struct vmw_private
*dev_priv
,
204 struct vmw_screen_object_unit
*sou
)
213 SVGAFifoCmdDestroyScreen body
;
216 /* no need to do anything */
217 if (unlikely(!sou
->defined
))
220 fifo_size
= sizeof(*cmd
);
221 cmd
= vmw_fifo_reserve(dev_priv
, fifo_size
);
222 /* the hardware has hung, nothing we can do about it here */
223 if (unlikely(cmd
== NULL
)) {
224 DRM_ERROR("Fifo reserve failed.\n");
228 memset(cmd
, 0, fifo_size
);
229 cmd
->header
.cmdType
= SVGA_CMD_DESTROY_SCREEN
;
230 cmd
->body
.screenId
= sou
->base
.unit
;
232 vmw_fifo_commit(dev_priv
, fifo_size
);
235 ret
= vmw_fallback_wait(dev_priv
, false, true, 0, false, 3*HZ
);
236 if (unlikely(ret
!= 0))
237 DRM_ERROR("Failed to sync with HW");
239 sou
->defined
= false;
245 * Free the backing store.
247 static void vmw_sou_backing_free(struct vmw_private
*dev_priv
,
248 struct vmw_screen_object_unit
*sou
)
250 vmw_dmabuf_unreference(&sou
->buffer
);
251 sou
->buffer_size
= 0;
255 * Allocate the backing store for the buffer.
257 static int vmw_sou_backing_alloc(struct vmw_private
*dev_priv
,
258 struct vmw_screen_object_unit
*sou
,
263 if (sou
->buffer_size
== size
)
267 vmw_sou_backing_free(dev_priv
, sou
);
269 sou
->buffer
= kzalloc(sizeof(*sou
->buffer
), GFP_KERNEL
);
270 if (unlikely(sou
->buffer
== NULL
))
273 /* After we have alloced the backing store might not be able to
274 * resume the overlays, this is preferred to failing to alloc.
276 vmw_overlay_pause_all(dev_priv
);
277 ret
= vmw_dmabuf_init(dev_priv
, sou
->buffer
, size
,
278 &vmw_vram_ne_placement
,
279 false, &vmw_dmabuf_bo_free
);
280 vmw_overlay_resume_all(dev_priv
);
282 if (unlikely(ret
!= 0))
283 sou
->buffer
= NULL
; /* vmw_dmabuf_init frees on error */
285 sou
->buffer_size
= size
;
290 static int vmw_sou_crtc_set_config(struct drm_mode_set
*set
)
292 struct vmw_private
*dev_priv
;
293 struct vmw_screen_object_unit
*sou
;
294 struct drm_connector
*connector
;
295 struct drm_display_mode
*mode
;
296 struct drm_encoder
*encoder
;
297 struct vmw_framebuffer
*vfb
;
298 struct drm_framebuffer
*fb
;
299 struct drm_crtc
*crtc
;
310 sou
= vmw_crtc_to_sou(crtc
);
311 vfb
= set
->fb
? vmw_framebuffer_to_vfb(set
->fb
) : NULL
;
312 dev_priv
= vmw_priv(crtc
->dev
);
314 if (set
->num_connectors
> 1) {
315 DRM_ERROR("Too many connectors\n");
319 if (set
->num_connectors
== 1 &&
320 set
->connectors
[0] != &sou
->base
.connector
) {
321 DRM_ERROR("Connector doesn't match %p %p\n",
322 set
->connectors
[0], &sou
->base
.connector
);
326 /* sou only supports one fb active at the time */
327 if (sou
->base
.is_implicit
&&
328 dev_priv
->sou_priv
->implicit_fb
&& vfb
&&
329 !(dev_priv
->sou_priv
->num_implicit
== 1 &&
330 sou
->active_implicit
) &&
331 dev_priv
->sou_priv
->implicit_fb
!= vfb
) {
332 DRM_ERROR("Multiple framebuffers not supported\n");
336 /* since they always map one to one these are safe */
337 connector
= &sou
->base
.connector
;
338 encoder
= &sou
->base
.encoder
;
340 /* should we turn the crtc off */
341 if (set
->num_connectors
== 0 || !set
->mode
|| !set
->fb
) {
342 ret
= vmw_sou_fifo_destroy(dev_priv
, sou
);
343 /* the hardware has hung don't do anything more */
344 if (unlikely(ret
!= 0))
347 connector
->encoder
= NULL
;
348 encoder
->crtc
= NULL
;
349 crtc
->primary
->fb
= NULL
;
352 crtc
->enabled
= false;
354 vmw_sou_del_active(dev_priv
, sou
);
356 vmw_sou_backing_free(dev_priv
, sou
);
362 /* we now know we want to set a mode */
366 if (set
->x
+ mode
->hdisplay
> fb
->width
||
367 set
->y
+ mode
->vdisplay
> fb
->height
) {
368 DRM_ERROR("set outside of framebuffer\n");
372 vmw_svga_enable(dev_priv
);
374 if (mode
->hdisplay
!= crtc
->mode
.hdisplay
||
375 mode
->vdisplay
!= crtc
->mode
.vdisplay
) {
376 /* no need to check if depth is different, because backing
377 * store depth is forced to 4 by the device.
380 ret
= vmw_sou_fifo_destroy(dev_priv
, sou
);
381 /* the hardware has hung don't do anything more */
382 if (unlikely(ret
!= 0))
385 vmw_sou_backing_free(dev_priv
, sou
);
389 /* forced to depth 4 by the device */
390 size_t size
= mode
->hdisplay
* mode
->vdisplay
* 4;
391 ret
= vmw_sou_backing_alloc(dev_priv
, sou
, size
);
392 if (unlikely(ret
!= 0))
396 ret
= vmw_sou_fifo_create(dev_priv
, sou
, set
->x
, set
->y
, mode
);
397 if (unlikely(ret
!= 0)) {
399 * We are in a bit of a situation here, the hardware has
400 * hung and we may or may not have a buffer hanging of
401 * the screen object, best thing to do is not do anything
402 * if we where defined, if not just turn the crtc of.
403 * Not what userspace wants but it needs to htfu.
408 connector
->encoder
= NULL
;
409 encoder
->crtc
= NULL
;
410 crtc
->primary
->fb
= NULL
;
413 crtc
->enabled
= false;
418 vmw_sou_add_active(dev_priv
, sou
, vfb
);
420 connector
->encoder
= encoder
;
421 encoder
->crtc
= crtc
;
423 crtc
->primary
->fb
= fb
;
426 crtc
->enabled
= true;
432 * Returns if this unit can be page flipped.
433 * Must be called with the mode_config mutex held.
435 static bool vmw_sou_screen_object_flippable(struct vmw_private
*dev_priv
,
436 struct drm_crtc
*crtc
)
438 struct vmw_screen_object_unit
*sou
= vmw_crtc_to_sou(crtc
);
440 if (!sou
->base
.is_implicit
)
443 if (dev_priv
->sou_priv
->num_implicit
!= 1)
450 * Update the implicit fb to the current fb of this crtc.
451 * Must be called with the mode_config mutex held.
453 static void vmw_sou_update_implicit_fb(struct vmw_private
*dev_priv
,
454 struct drm_crtc
*crtc
)
456 struct vmw_screen_object_unit
*sou
= vmw_crtc_to_sou(crtc
);
458 BUG_ON(!sou
->base
.is_implicit
);
460 dev_priv
->sou_priv
->implicit_fb
=
461 vmw_framebuffer_to_vfb(sou
->base
.crtc
.primary
->fb
);
464 static int vmw_sou_crtc_page_flip(struct drm_crtc
*crtc
,
465 struct drm_framebuffer
*fb
,
466 struct drm_pending_vblank_event
*event
,
469 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
470 struct drm_framebuffer
*old_fb
= crtc
->primary
->fb
;
471 struct vmw_framebuffer
*vfb
= vmw_framebuffer_to_vfb(fb
);
472 struct vmw_fence_obj
*fence
= NULL
;
473 struct drm_clip_rect clips
;
476 /* require ScreenObject support for page flipping */
477 if (!dev_priv
->sou_priv
)
480 if (!vmw_sou_screen_object_flippable(dev_priv
, crtc
))
483 crtc
->primary
->fb
= fb
;
485 /* do a full screen dirty update */
486 clips
.x1
= clips
.y1
= 0;
487 clips
.x2
= fb
->width
;
488 clips
.y2
= fb
->height
;
491 ret
= vmw_kms_sou_do_dmabuf_dirty(dev_priv
, vfb
,
495 ret
= vmw_kms_sou_do_surface_dirty(dev_priv
, vfb
,
508 struct drm_file
*file_priv
= event
->base
.file_priv
;
510 ret
= vmw_event_fence_action_queue(file_priv
, fence
,
512 &event
->event
.tv_sec
,
513 &event
->event
.tv_usec
,
518 * No need to hold on to this now. The only cleanup
519 * we need to do if we fail is unref the fence.
521 vmw_fence_obj_unreference(&fence
);
523 if (vmw_crtc_to_du(crtc
)->is_implicit
)
524 vmw_sou_update_implicit_fb(dev_priv
, crtc
);
529 crtc
->primary
->fb
= old_fb
;
533 static const struct drm_crtc_funcs vmw_screen_object_crtc_funcs
= {
534 .cursor_set2
= vmw_du_crtc_cursor_set2
,
535 .cursor_move
= vmw_du_crtc_cursor_move
,
536 .gamma_set
= vmw_du_crtc_gamma_set
,
537 .destroy
= vmw_sou_crtc_destroy
,
538 .set_config
= vmw_sou_crtc_set_config
,
539 .page_flip
= vmw_sou_crtc_page_flip
,
543 * Screen Object Display Unit encoder functions
546 static void vmw_sou_encoder_destroy(struct drm_encoder
*encoder
)
548 vmw_sou_destroy(vmw_encoder_to_sou(encoder
));
551 static const struct drm_encoder_funcs vmw_screen_object_encoder_funcs
= {
552 .destroy
= vmw_sou_encoder_destroy
,
556 * Screen Object Display Unit connector functions
559 static void vmw_sou_connector_destroy(struct drm_connector
*connector
)
561 vmw_sou_destroy(vmw_connector_to_sou(connector
));
564 static const struct drm_connector_funcs vmw_sou_connector_funcs
= {
565 .dpms
= vmw_du_connector_dpms
,
566 .set_property
= vmw_du_connector_set_property
,
567 .destroy
= vmw_sou_connector_destroy
,
570 static int vmw_sou_init(struct vmw_private
*dev_priv
, unsigned unit
)
572 struct vmw_screen_object_unit
*sou
;
573 struct drm_device
*dev
= dev_priv
->dev
;
574 struct drm_connector
*connector
;
575 struct drm_encoder
*encoder
;
576 struct drm_crtc
*crtc
;
578 sou
= kzalloc(sizeof(*sou
), GFP_KERNEL
);
582 sou
->base
.unit
= unit
;
583 crtc
= &sou
->base
.crtc
;
584 encoder
= &sou
->base
.encoder
;
585 connector
= &sou
->base
.connector
;
587 sou
->active_implicit
= false;
589 sou
->base
.pref_active
= (unit
== 0);
590 sou
->base
.pref_width
= dev_priv
->initial_width
;
591 sou
->base
.pref_height
= dev_priv
->initial_height
;
592 sou
->base
.pref_mode
= NULL
;
593 sou
->base
.is_implicit
= true;
595 drm_connector_init(dev
, connector
, &vmw_sou_connector_funcs
,
596 DRM_MODE_CONNECTOR_VIRTUAL
);
597 connector
->status
= vmw_du_connector_detect(connector
, true);
599 drm_encoder_init(dev
, encoder
, &vmw_screen_object_encoder_funcs
,
600 DRM_MODE_ENCODER_VIRTUAL
, NULL
);
601 drm_mode_connector_attach_encoder(connector
, encoder
);
602 encoder
->possible_crtcs
= (1 << unit
);
603 encoder
->possible_clones
= 0;
605 (void) drm_connector_register(connector
);
607 drm_crtc_init(dev
, crtc
, &vmw_screen_object_crtc_funcs
);
609 drm_mode_crtc_set_gamma_size(crtc
, 256);
611 drm_object_attach_property(&connector
->base
,
612 dev
->mode_config
.dirty_info_property
,
618 int vmw_kms_sou_init_display(struct vmw_private
*dev_priv
)
620 struct drm_device
*dev
= dev_priv
->dev
;
623 if (dev_priv
->sou_priv
) {
624 DRM_INFO("sou system already on\n");
628 if (!(dev_priv
->capabilities
& SVGA_CAP_SCREEN_OBJECT_2
)) {
629 DRM_INFO("Not using screen objects,"
630 " missing cap SCREEN_OBJECT_2\n");
635 dev_priv
->sou_priv
= kmalloc(sizeof(*dev_priv
->sou_priv
), GFP_KERNEL
);
636 if (unlikely(!dev_priv
->sou_priv
))
639 dev_priv
->sou_priv
->num_implicit
= 0;
640 dev_priv
->sou_priv
->implicit_fb
= NULL
;
642 ret
= drm_vblank_init(dev
, VMWGFX_NUM_DISPLAY_UNITS
);
643 if (unlikely(ret
!= 0))
646 ret
= drm_mode_create_dirty_info_property(dev
);
647 if (unlikely(ret
!= 0))
648 goto err_vblank_cleanup
;
650 for (i
= 0; i
< VMWGFX_NUM_DISPLAY_UNITS
; ++i
)
651 vmw_sou_init(dev_priv
, i
);
653 dev_priv
->active_display_unit
= vmw_du_screen_object
;
655 DRM_INFO("Screen Objects Display Unit initialized\n");
660 drm_vblank_cleanup(dev
);
662 kfree(dev_priv
->sou_priv
);
663 dev_priv
->sou_priv
= NULL
;
668 int vmw_kms_sou_close_display(struct vmw_private
*dev_priv
)
670 struct drm_device
*dev
= dev_priv
->dev
;
672 if (!dev_priv
->sou_priv
)
675 drm_vblank_cleanup(dev
);
677 kfree(dev_priv
->sou_priv
);
682 static int do_dmabuf_define_gmrfb(struct vmw_private
*dev_priv
,
683 struct vmw_framebuffer
*framebuffer
)
685 struct vmw_dma_buffer
*buf
=
686 container_of(framebuffer
, struct vmw_framebuffer_dmabuf
,
688 int depth
= framebuffer
->base
.depth
;
691 SVGAFifoCmdDefineGMRFB body
;
694 /* Emulate RGBA support, contrary to svga_reg.h this is not
695 * supported by hosts. This is only a problem if we are reading
696 * this value later and expecting what we uploaded back.
701 cmd
= vmw_fifo_reserve(dev_priv
, sizeof(*cmd
));
703 DRM_ERROR("Out of fifo space for dirty framebuffer command.\n");
707 cmd
->header
= SVGA_CMD_DEFINE_GMRFB
;
708 cmd
->body
.format
.bitsPerPixel
= framebuffer
->base
.bits_per_pixel
;
709 cmd
->body
.format
.colorDepth
= depth
;
710 cmd
->body
.format
.reserved
= 0;
711 cmd
->body
.bytesPerLine
= framebuffer
->base
.pitches
[0];
712 /* Buffer is reserved in vram or GMR */
713 vmw_bo_get_guest_ptr(&buf
->base
, &cmd
->body
.ptr
);
714 vmw_fifo_commit(dev_priv
, sizeof(*cmd
));
720 * vmw_sou_surface_fifo_commit - Callback to fill in and submit a
721 * blit surface to screen command.
723 * @dirty: The closure structure.
725 * Fills in the missing fields in the command, and translates the cliprects
726 * to match the destination bounding box encoded.
728 static void vmw_sou_surface_fifo_commit(struct vmw_kms_dirty
*dirty
)
730 struct vmw_kms_sou_surface_dirty
*sdirty
=
731 container_of(dirty
, typeof(*sdirty
), base
);
732 struct vmw_kms_sou_dirty_cmd
*cmd
= dirty
->cmd
;
733 s32 trans_x
= dirty
->unit
->crtc
.x
- sdirty
->dst_x
;
734 s32 trans_y
= dirty
->unit
->crtc
.y
- sdirty
->dst_y
;
735 size_t region_size
= dirty
->num_hits
* sizeof(SVGASignedRect
);
736 SVGASignedRect
*blit
= (SVGASignedRect
*) &cmd
[1];
739 cmd
->header
.id
= SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN
;
740 cmd
->header
.size
= sizeof(cmd
->body
) + region_size
;
743 * Use the destination bounding box to specify destination - and
744 * source bounding regions.
746 cmd
->body
.destRect
.left
= sdirty
->left
;
747 cmd
->body
.destRect
.right
= sdirty
->right
;
748 cmd
->body
.destRect
.top
= sdirty
->top
;
749 cmd
->body
.destRect
.bottom
= sdirty
->bottom
;
751 cmd
->body
.srcRect
.left
= sdirty
->left
+ trans_x
;
752 cmd
->body
.srcRect
.right
= sdirty
->right
+ trans_x
;
753 cmd
->body
.srcRect
.top
= sdirty
->top
+ trans_y
;
754 cmd
->body
.srcRect
.bottom
= sdirty
->bottom
+ trans_y
;
756 cmd
->body
.srcImage
.sid
= sdirty
->sid
;
757 cmd
->body
.destScreenId
= dirty
->unit
->unit
;
759 /* Blits are relative to the destination rect. Translate. */
760 for (i
= 0; i
< dirty
->num_hits
; ++i
, ++blit
) {
761 blit
->left
-= sdirty
->left
;
762 blit
->right
-= sdirty
->left
;
763 blit
->top
-= sdirty
->top
;
764 blit
->bottom
-= sdirty
->top
;
767 vmw_fifo_commit(dirty
->dev_priv
, region_size
+ sizeof(*cmd
));
769 sdirty
->left
= sdirty
->top
= S32_MAX
;
770 sdirty
->right
= sdirty
->bottom
= S32_MIN
;
774 * vmw_sou_surface_clip - Callback to encode a blit surface to screen cliprect.
776 * @dirty: The closure structure
778 * Encodes a SVGASignedRect cliprect and updates the bounding box of the
779 * BLIT_SURFACE_TO_SCREEN command.
781 static void vmw_sou_surface_clip(struct vmw_kms_dirty
*dirty
)
783 struct vmw_kms_sou_surface_dirty
*sdirty
=
784 container_of(dirty
, typeof(*sdirty
), base
);
785 struct vmw_kms_sou_dirty_cmd
*cmd
= dirty
->cmd
;
786 SVGASignedRect
*blit
= (SVGASignedRect
*) &cmd
[1];
788 /* Destination rect. */
789 blit
+= dirty
->num_hits
;
790 blit
->left
= dirty
->unit_x1
;
791 blit
->top
= dirty
->unit_y1
;
792 blit
->right
= dirty
->unit_x2
;
793 blit
->bottom
= dirty
->unit_y2
;
795 /* Destination bounding box */
796 sdirty
->left
= min_t(s32
, sdirty
->left
, dirty
->unit_x1
);
797 sdirty
->top
= min_t(s32
, sdirty
->top
, dirty
->unit_y1
);
798 sdirty
->right
= max_t(s32
, sdirty
->right
, dirty
->unit_x2
);
799 sdirty
->bottom
= max_t(s32
, sdirty
->bottom
, dirty
->unit_y2
);
805 * vmw_kms_sou_do_surface_dirty - Dirty part of a surface backed framebuffer
807 * @dev_priv: Pointer to the device private structure.
808 * @framebuffer: Pointer to the surface-buffer backed framebuffer.
809 * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
810 * @vclips: Alternate array of clip rects. Either @clips or @vclips must
812 * @srf: Pointer to surface to blit from. If NULL, the surface attached
813 * to @framebuffer will be used.
814 * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
815 * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
816 * @num_clips: Number of clip rects in @clips.
817 * @inc: Increment to use when looping over @clips.
818 * @out_fence: If non-NULL, will return a ref-counted pointer to a
819 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
820 * case the device has already synchronized.
822 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
825 int vmw_kms_sou_do_surface_dirty(struct vmw_private
*dev_priv
,
826 struct vmw_framebuffer
*framebuffer
,
827 struct drm_clip_rect
*clips
,
828 struct drm_vmw_rect
*vclips
,
829 struct vmw_resource
*srf
,
832 unsigned num_clips
, int inc
,
833 struct vmw_fence_obj
**out_fence
)
835 struct vmw_framebuffer_surface
*vfbs
=
836 container_of(framebuffer
, typeof(*vfbs
), base
);
837 struct vmw_kms_sou_surface_dirty sdirty
;
841 srf
= &vfbs
->surface
->res
;
843 ret
= vmw_kms_helper_resource_prepare(srf
, true);
847 sdirty
.base
.fifo_commit
= vmw_sou_surface_fifo_commit
;
848 sdirty
.base
.clip
= vmw_sou_surface_clip
;
849 sdirty
.base
.dev_priv
= dev_priv
;
850 sdirty
.base
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_dirty_cmd
) +
851 sizeof(SVGASignedRect
) * num_clips
;
853 sdirty
.sid
= srf
->id
;
854 sdirty
.left
= sdirty
.top
= S32_MAX
;
855 sdirty
.right
= sdirty
.bottom
= S32_MIN
;
856 sdirty
.dst_x
= dest_x
;
857 sdirty
.dst_y
= dest_y
;
859 ret
= vmw_kms_helper_dirty(dev_priv
, framebuffer
, clips
, vclips
,
860 dest_x
, dest_y
, num_clips
, inc
,
862 vmw_kms_helper_resource_finish(srf
, out_fence
);
868 * vmw_sou_dmabuf_fifo_commit - Callback to submit a set of readback clips.
870 * @dirty: The closure structure.
872 * Commits a previously built command buffer of readback clips.
874 static void vmw_sou_dmabuf_fifo_commit(struct vmw_kms_dirty
*dirty
)
876 vmw_fifo_commit(dirty
->dev_priv
,
877 sizeof(struct vmw_kms_sou_dmabuf_blit
) *
882 * vmw_sou_dmabuf_clip - Callback to encode a readback cliprect.
884 * @dirty: The closure structure
886 * Encodes a BLIT_GMRFB_TO_SCREEN cliprect.
888 static void vmw_sou_dmabuf_clip(struct vmw_kms_dirty
*dirty
)
890 struct vmw_kms_sou_dmabuf_blit
*blit
= dirty
->cmd
;
892 blit
+= dirty
->num_hits
;
893 blit
->header
= SVGA_CMD_BLIT_GMRFB_TO_SCREEN
;
894 blit
->body
.destScreenId
= dirty
->unit
->unit
;
895 blit
->body
.srcOrigin
.x
= dirty
->fb_x
;
896 blit
->body
.srcOrigin
.y
= dirty
->fb_y
;
897 blit
->body
.destRect
.left
= dirty
->unit_x1
;
898 blit
->body
.destRect
.top
= dirty
->unit_y1
;
899 blit
->body
.destRect
.right
= dirty
->unit_x2
;
900 blit
->body
.destRect
.bottom
= dirty
->unit_y2
;
905 * vmw_kms_do_dmabuf_dirty - Dirty part of a dma-buffer backed framebuffer
907 * @dev_priv: Pointer to the device private structure.
908 * @framebuffer: Pointer to the dma-buffer backed framebuffer.
909 * @clips: Array of clip rects.
910 * @num_clips: Number of clip rects in @clips.
911 * @increment: Increment to use when looping over @clips.
912 * @interruptible: Whether to perform waits interruptible if possible.
913 * @out_fence: If non-NULL, will return a ref-counted pointer to a
914 * struct vmw_fence_obj. The returned fence pointer may be NULL in which
915 * case the device has already synchronized.
917 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
920 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private
*dev_priv
,
921 struct vmw_framebuffer
*framebuffer
,
922 struct drm_clip_rect
*clips
,
923 unsigned num_clips
, int increment
,
925 struct vmw_fence_obj
**out_fence
)
927 struct vmw_dma_buffer
*buf
=
928 container_of(framebuffer
, struct vmw_framebuffer_dmabuf
,
930 struct vmw_kms_dirty dirty
;
933 ret
= vmw_kms_helper_buffer_prepare(dev_priv
, buf
, interruptible
,
938 ret
= do_dmabuf_define_gmrfb(dev_priv
, framebuffer
);
939 if (unlikely(ret
!= 0))
942 dirty
.fifo_commit
= vmw_sou_dmabuf_fifo_commit
;
943 dirty
.clip
= vmw_sou_dmabuf_clip
;
944 dirty
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_dmabuf_blit
) *
946 ret
= vmw_kms_helper_dirty(dev_priv
, framebuffer
, clips
, NULL
,
947 0, 0, num_clips
, increment
, &dirty
);
948 vmw_kms_helper_buffer_finish(dev_priv
, NULL
, buf
, out_fence
, NULL
);
953 vmw_kms_helper_buffer_revert(buf
);
960 * vmw_sou_readback_fifo_commit - Callback to submit a set of readback clips.
962 * @dirty: The closure structure.
964 * Commits a previously built command buffer of readback clips.
966 static void vmw_sou_readback_fifo_commit(struct vmw_kms_dirty
*dirty
)
968 vmw_fifo_commit(dirty
->dev_priv
,
969 sizeof(struct vmw_kms_sou_readback_blit
) *
974 * vmw_sou_readback_clip - Callback to encode a readback cliprect.
976 * @dirty: The closure structure
978 * Encodes a BLIT_SCREEN_TO_GMRFB cliprect.
980 static void vmw_sou_readback_clip(struct vmw_kms_dirty
*dirty
)
982 struct vmw_kms_sou_readback_blit
*blit
= dirty
->cmd
;
984 blit
+= dirty
->num_hits
;
985 blit
->header
= SVGA_CMD_BLIT_SCREEN_TO_GMRFB
;
986 blit
->body
.srcScreenId
= dirty
->unit
->unit
;
987 blit
->body
.destOrigin
.x
= dirty
->fb_x
;
988 blit
->body
.destOrigin
.y
= dirty
->fb_y
;
989 blit
->body
.srcRect
.left
= dirty
->unit_x1
;
990 blit
->body
.srcRect
.top
= dirty
->unit_y1
;
991 blit
->body
.srcRect
.right
= dirty
->unit_x2
;
992 blit
->body
.srcRect
.bottom
= dirty
->unit_y2
;
997 * vmw_kms_sou_readback - Perform a readback from the screen object system to
998 * a dma-buffer backed framebuffer.
1000 * @dev_priv: Pointer to the device private structure.
1001 * @file_priv: Pointer to a struct drm_file identifying the caller.
1002 * Must be set to NULL if @user_fence_rep is NULL.
1003 * @vfb: Pointer to the dma-buffer backed framebuffer.
1004 * @user_fence_rep: User-space provided structure for fence information.
1005 * Must be set to non-NULL if @file_priv is non-NULL.
1006 * @vclips: Array of clip rects.
1007 * @num_clips: Number of clip rects in @vclips.
1009 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
1012 int vmw_kms_sou_readback(struct vmw_private
*dev_priv
,
1013 struct drm_file
*file_priv
,
1014 struct vmw_framebuffer
*vfb
,
1015 struct drm_vmw_fence_rep __user
*user_fence_rep
,
1016 struct drm_vmw_rect
*vclips
,
1019 struct vmw_dma_buffer
*buf
=
1020 container_of(vfb
, struct vmw_framebuffer_dmabuf
, base
)->buffer
;
1021 struct vmw_kms_dirty dirty
;
1024 ret
= vmw_kms_helper_buffer_prepare(dev_priv
, buf
, true, false);
1028 ret
= do_dmabuf_define_gmrfb(dev_priv
, vfb
);
1029 if (unlikely(ret
!= 0))
1032 dirty
.fifo_commit
= vmw_sou_readback_fifo_commit
;
1033 dirty
.clip
= vmw_sou_readback_clip
;
1034 dirty
.fifo_reserve_size
= sizeof(struct vmw_kms_sou_readback_blit
) *
1036 ret
= vmw_kms_helper_dirty(dev_priv
, vfb
, NULL
, vclips
,
1037 0, 0, num_clips
, 1, &dirty
);
1038 vmw_kms_helper_buffer_finish(dev_priv
, file_priv
, buf
, NULL
,
1044 vmw_kms_helper_buffer_revert(buf
);