1 /**************************************************************************
3 * Copyright © 2009-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>
30 #include <drm/drm_atomic.h>
31 #include <drm/drm_atomic_helper.h>
32 #include <drm/drm_rect.h>
35 /* Might need a hrtimer here? */
36 #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1)
38 void vmw_du_cleanup(struct vmw_display_unit
*du
)
40 drm_plane_cleanup(&du
->primary
);
41 drm_plane_cleanup(&du
->cursor
);
43 drm_connector_unregister(&du
->connector
);
44 drm_crtc_cleanup(&du
->crtc
);
45 drm_encoder_cleanup(&du
->encoder
);
46 drm_connector_cleanup(&du
->connector
);
50 * Display Unit Cursor functions
53 static int vmw_cursor_update_image(struct vmw_private
*dev_priv
,
54 u32
*image
, u32 width
, u32 height
,
55 u32 hotspotX
, u32 hotspotY
)
59 SVGAFifoCmdDefineAlphaCursor cursor
;
61 u32 image_size
= width
* height
* 4;
62 u32 cmd_size
= sizeof(*cmd
) + image_size
;
67 cmd
= vmw_fifo_reserve(dev_priv
, cmd_size
);
68 if (unlikely(cmd
== NULL
)) {
69 DRM_ERROR("Fifo reserve failed.\n");
73 memset(cmd
, 0, sizeof(*cmd
));
75 memcpy(&cmd
[1], image
, image_size
);
77 cmd
->cmd
= SVGA_CMD_DEFINE_ALPHA_CURSOR
;
79 cmd
->cursor
.width
= width
;
80 cmd
->cursor
.height
= height
;
81 cmd
->cursor
.hotspotX
= hotspotX
;
82 cmd
->cursor
.hotspotY
= hotspotY
;
84 vmw_fifo_commit_flush(dev_priv
, cmd_size
);
89 static int vmw_cursor_update_dmabuf(struct vmw_private
*dev_priv
,
90 struct vmw_dma_buffer
*dmabuf
,
91 u32 width
, u32 height
,
92 u32 hotspotX
, u32 hotspotY
)
94 struct ttm_bo_kmap_obj map
;
95 unsigned long kmap_offset
;
96 unsigned long kmap_num
;
102 kmap_num
= (width
*height
*4 + PAGE_SIZE
- 1) >> PAGE_SHIFT
;
104 ret
= ttm_bo_reserve(&dmabuf
->base
, true, false, NULL
);
105 if (unlikely(ret
!= 0)) {
106 DRM_ERROR("reserve failed\n");
110 ret
= ttm_bo_kmap(&dmabuf
->base
, kmap_offset
, kmap_num
, &map
);
111 if (unlikely(ret
!= 0))
114 virtual = ttm_kmap_obj_virtual(&map
, &dummy
);
115 ret
= vmw_cursor_update_image(dev_priv
, virtual, width
, height
,
120 ttm_bo_unreserve(&dmabuf
->base
);
126 static void vmw_cursor_update_position(struct vmw_private
*dev_priv
,
127 bool show
, int x
, int y
)
129 u32
*fifo_mem
= dev_priv
->mmio_virt
;
132 spin_lock(&dev_priv
->cursor_lock
);
133 vmw_mmio_write(show
? 1 : 0, fifo_mem
+ SVGA_FIFO_CURSOR_ON
);
134 vmw_mmio_write(x
, fifo_mem
+ SVGA_FIFO_CURSOR_X
);
135 vmw_mmio_write(y
, fifo_mem
+ SVGA_FIFO_CURSOR_Y
);
136 count
= vmw_mmio_read(fifo_mem
+ SVGA_FIFO_CURSOR_COUNT
);
137 vmw_mmio_write(++count
, fifo_mem
+ SVGA_FIFO_CURSOR_COUNT
);
138 spin_unlock(&dev_priv
->cursor_lock
);
142 void vmw_kms_cursor_snoop(struct vmw_surface
*srf
,
143 struct ttm_object_file
*tfile
,
144 struct ttm_buffer_object
*bo
,
145 SVGA3dCmdHeader
*header
)
147 struct ttm_bo_kmap_obj map
;
148 unsigned long kmap_offset
;
149 unsigned long kmap_num
;
155 SVGA3dCmdHeader header
;
156 SVGA3dCmdSurfaceDMA dma
;
160 cmd
= container_of(header
, struct vmw_dma_cmd
, header
);
162 /* No snooper installed */
163 if (!srf
->snooper
.image
)
166 if (cmd
->dma
.host
.face
!= 0 || cmd
->dma
.host
.mipmap
!= 0) {
167 DRM_ERROR("face and mipmap for cursors should never != 0\n");
171 if (cmd
->header
.size
< 64) {
172 DRM_ERROR("at least one full copy box must be given\n");
176 box
= (SVGA3dCopyBox
*)&cmd
[1];
177 box_count
= (cmd
->header
.size
- sizeof(SVGA3dCmdSurfaceDMA
)) /
178 sizeof(SVGA3dCopyBox
);
180 if (cmd
->dma
.guest
.ptr
.offset
% PAGE_SIZE
||
181 box
->x
!= 0 || box
->y
!= 0 || box
->z
!= 0 ||
182 box
->srcx
!= 0 || box
->srcy
!= 0 || box
->srcz
!= 0 ||
183 box
->d
!= 1 || box_count
!= 1) {
184 /* TODO handle none page aligned offsets */
185 /* TODO handle more dst & src != 0 */
186 /* TODO handle more then one copy */
187 DRM_ERROR("Cant snoop dma request for cursor!\n");
188 DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n",
189 box
->srcx
, box
->srcy
, box
->srcz
,
190 box
->x
, box
->y
, box
->z
,
191 box
->w
, box
->h
, box
->d
, box_count
,
192 cmd
->dma
.guest
.ptr
.offset
);
196 kmap_offset
= cmd
->dma
.guest
.ptr
.offset
>> PAGE_SHIFT
;
197 kmap_num
= (64*64*4) >> PAGE_SHIFT
;
199 ret
= ttm_bo_reserve(bo
, true, false, NULL
);
200 if (unlikely(ret
!= 0)) {
201 DRM_ERROR("reserve failed\n");
205 ret
= ttm_bo_kmap(bo
, kmap_offset
, kmap_num
, &map
);
206 if (unlikely(ret
!= 0))
209 virtual = ttm_kmap_obj_virtual(&map
, &dummy
);
211 if (box
->w
== 64 && cmd
->dma
.guest
.pitch
== 64*4) {
212 memcpy(srf
->snooper
.image
, virtual, 64*64*4);
214 /* Image is unsigned pointer. */
215 for (i
= 0; i
< box
->h
; i
++)
216 memcpy(srf
->snooper
.image
+ i
* 64,
217 virtual + i
* cmd
->dma
.guest
.pitch
,
225 ttm_bo_unreserve(bo
);
229 * vmw_kms_legacy_hotspot_clear - Clear legacy hotspots
231 * @dev_priv: Pointer to the device private struct.
233 * Clears all legacy hotspots.
235 void vmw_kms_legacy_hotspot_clear(struct vmw_private
*dev_priv
)
237 struct drm_device
*dev
= dev_priv
->dev
;
238 struct vmw_display_unit
*du
;
239 struct drm_crtc
*crtc
;
241 drm_modeset_lock_all(dev
);
242 drm_for_each_crtc(crtc
, dev
) {
243 du
= vmw_crtc_to_du(crtc
);
248 drm_modeset_unlock_all(dev
);
251 void vmw_kms_cursor_post_execbuf(struct vmw_private
*dev_priv
)
253 struct drm_device
*dev
= dev_priv
->dev
;
254 struct vmw_display_unit
*du
;
255 struct drm_crtc
*crtc
;
257 mutex_lock(&dev
->mode_config
.mutex
);
259 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
260 du
= vmw_crtc_to_du(crtc
);
261 if (!du
->cursor_surface
||
262 du
->cursor_age
== du
->cursor_surface
->snooper
.age
)
265 du
->cursor_age
= du
->cursor_surface
->snooper
.age
;
266 vmw_cursor_update_image(dev_priv
,
267 du
->cursor_surface
->snooper
.image
,
269 du
->hotspot_x
+ du
->core_hotspot_x
,
270 du
->hotspot_y
+ du
->core_hotspot_y
);
273 mutex_unlock(&dev
->mode_config
.mutex
);
279 * vmw_du_cursor_plane_update() - Update cursor image and location
281 * @plane: plane object to update
282 * @crtc: owning CRTC of @plane
283 * @fb: framebuffer to flip onto plane
284 * @crtc_x: x offset of plane on crtc
285 * @crtc_y: y offset of plane on crtc
286 * @crtc_w: width of plane rectangle on crtc
287 * @crtc_h: height of plane rectangle on crtc
295 * Zero on success, error code on failure
297 int vmw_du_cursor_plane_update(struct drm_plane
*plane
,
298 struct drm_crtc
*crtc
,
299 struct drm_framebuffer
*fb
,
300 int crtc_x
, int crtc_y
,
303 uint32_t src_x
, uint32_t src_y
,
304 uint32_t src_w
, uint32_t src_h
)
306 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
307 struct vmw_display_unit
*du
= vmw_crtc_to_du(crtc
);
308 struct vmw_surface
*surface
= NULL
;
309 struct vmw_dma_buffer
*dmabuf
= NULL
;
310 s32 hotspot_x
, hotspot_y
;
313 hotspot_x
= du
->hotspot_x
+ fb
->hot_x
;
314 hotspot_y
= du
->hotspot_y
+ fb
->hot_y
;
316 /* A lot of the code assumes this */
317 if (crtc_w
!= 64 || crtc_h
!= 64) {
322 if (vmw_framebuffer_to_vfb(fb
)->dmabuf
)
323 dmabuf
= vmw_framebuffer_to_vfbd(fb
)->buffer
;
325 surface
= vmw_framebuffer_to_vfbs(fb
)->surface
;
327 if (surface
&& !surface
->snooper
.image
) {
328 DRM_ERROR("surface not suitable for cursor\n");
333 /* setup new image */
336 /* vmw_user_surface_lookup takes one reference */
337 du
->cursor_surface
= surface
;
339 du
->cursor_age
= du
->cursor_surface
->snooper
.age
;
341 ret
= vmw_cursor_update_image(dev_priv
, surface
->snooper
.image
,
342 64, 64, hotspot_x
, hotspot_y
);
344 /* vmw_user_surface_lookup takes one reference */
345 du
->cursor_dmabuf
= dmabuf
;
347 ret
= vmw_cursor_update_dmabuf(dev_priv
, dmabuf
, crtc_w
, crtc_h
,
348 hotspot_x
, hotspot_y
);
350 vmw_cursor_update_position(dev_priv
, false, 0, 0);
355 du
->cursor_x
= crtc_x
+ du
->set_gui_x
;
356 du
->cursor_y
= crtc_y
+ du
->set_gui_y
;
358 vmw_cursor_update_position(dev_priv
, true,
359 du
->cursor_x
+ hotspot_x
,
360 du
->cursor_y
+ hotspot_y
);
368 int vmw_du_cursor_plane_disable(struct drm_plane
*plane
)
371 drm_framebuffer_unreference(plane
->fb
);
379 void vmw_du_cursor_plane_destroy(struct drm_plane
*plane
)
381 vmw_cursor_update_position(plane
->dev
->dev_private
, false, 0, 0);
383 drm_plane_cleanup(plane
);
387 void vmw_du_primary_plane_destroy(struct drm_plane
*plane
)
389 drm_plane_cleanup(plane
);
391 /* Planes are static in our case so we don't free it */
396 * vmw_du_vps_unpin_surf - unpins resource associated with a framebuffer surface
398 * @vps: plane state associated with the display surface
399 * @unreference: true if we also want to unreference the display.
401 void vmw_du_plane_unpin_surf(struct vmw_plane_state
*vps
,
406 vmw_resource_unpin(&vps
->surf
->res
);
412 DRM_ERROR("Surface still pinned\n");
413 vmw_surface_unreference(&vps
->surf
);
420 * vmw_du_plane_cleanup_fb - Unpins the cursor
422 * @plane: display plane
423 * @old_state: Contains the FB to clean up
425 * Unpins the framebuffer surface
427 * Returns 0 on success
430 vmw_du_plane_cleanup_fb(struct drm_plane
*plane
,
431 struct drm_plane_state
*old_state
)
433 struct vmw_plane_state
*vps
= vmw_plane_state_to_vps(old_state
);
435 vmw_du_plane_unpin_surf(vps
, false);
440 * vmw_du_cursor_plane_prepare_fb - Readies the cursor by referencing it
442 * @plane: display plane
443 * @new_state: info on the new plane state, including the FB
445 * Returns 0 on success
448 vmw_du_cursor_plane_prepare_fb(struct drm_plane
*plane
,
449 struct drm_plane_state
*new_state
)
451 struct drm_framebuffer
*fb
= new_state
->fb
;
452 struct vmw_plane_state
*vps
= vmw_plane_state_to_vps(new_state
);
456 vmw_surface_unreference(&vps
->surf
);
459 vmw_dmabuf_unreference(&vps
->dmabuf
);
462 if (vmw_framebuffer_to_vfb(fb
)->dmabuf
) {
463 vps
->dmabuf
= vmw_framebuffer_to_vfbd(fb
)->buffer
;
464 vmw_dmabuf_reference(vps
->dmabuf
);
466 vps
->surf
= vmw_framebuffer_to_vfbs(fb
)->surface
;
467 vmw_surface_reference(vps
->surf
);
476 vmw_du_cursor_plane_atomic_disable(struct drm_plane
*plane
,
477 struct drm_plane_state
*old_state
)
479 struct drm_crtc
*crtc
= plane
->state
->crtc
?: old_state
->crtc
;
480 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
482 drm_atomic_set_fb_for_plane(plane
->state
, NULL
);
483 vmw_cursor_update_position(dev_priv
, false, 0, 0);
488 vmw_du_cursor_plane_atomic_update(struct drm_plane
*plane
,
489 struct drm_plane_state
*old_state
)
491 struct drm_crtc
*crtc
= plane
->state
->crtc
?: old_state
->crtc
;
492 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
493 struct vmw_display_unit
*du
= vmw_crtc_to_du(crtc
);
494 struct vmw_plane_state
*vps
= vmw_plane_state_to_vps(plane
->state
);
495 s32 hotspot_x
, hotspot_y
;
499 hotspot_x
= du
->hotspot_x
;
500 hotspot_y
= du
->hotspot_y
;
501 du
->cursor_surface
= vps
->surf
;
502 du
->cursor_dmabuf
= vps
->dmabuf
;
504 /* setup new image */
506 du
->cursor_age
= du
->cursor_surface
->snooper
.age
;
508 ret
= vmw_cursor_update_image(dev_priv
,
509 vps
->surf
->snooper
.image
,
510 64, 64, hotspot_x
, hotspot_y
);
511 } else if (vps
->dmabuf
) {
512 ret
= vmw_cursor_update_dmabuf(dev_priv
, vps
->dmabuf
,
513 plane
->state
->crtc_w
,
514 plane
->state
->crtc_h
,
515 hotspot_x
, hotspot_y
);
517 vmw_cursor_update_position(dev_priv
, false, 0, 0);
522 du
->cursor_x
= plane
->state
->crtc_x
+ du
->set_gui_x
;
523 du
->cursor_y
= plane
->state
->crtc_y
+ du
->set_gui_y
;
525 vmw_cursor_update_position(dev_priv
, true,
526 du
->cursor_x
+ hotspot_x
,
527 du
->cursor_y
+ hotspot_y
);
529 DRM_ERROR("Failed to update cursor image\n");
535 * vmw_du_primary_plane_atomic_check - check if the new state is okay
537 * @plane: display plane
538 * @state: info on the new plane state, including the FB
540 * Check if the new state is settable given the current state. Other
541 * than what the atomic helper checks, we care about crtc fitting
542 * the FB and maintaining one active framebuffer.
544 * Returns 0 on success
546 int vmw_du_primary_plane_atomic_check(struct drm_plane
*plane
,
547 struct drm_plane_state
*state
)
549 struct drm_framebuffer
*new_fb
= state
->fb
;
552 struct drm_rect src
= {
555 .x2
= state
->src_x
+ state
->src_w
,
556 .y2
= state
->src_y
+ state
->src_h
,
558 struct drm_rect dest
= {
561 .x2
= state
->crtc_x
+ state
->crtc_w
,
562 .y2
= state
->crtc_y
+ state
->crtc_h
,
564 struct drm_rect clip
= dest
;
567 ret
= drm_plane_helper_check_update(plane
, state
->crtc
, new_fb
,
570 DRM_PLANE_HELPER_NO_SCALING
,
571 DRM_PLANE_HELPER_NO_SCALING
,
572 false, true, &visible
);
575 if (!ret
&& new_fb
) {
576 struct drm_crtc
*crtc
= state
->crtc
;
577 struct vmw_connector_state
*vcs
;
578 struct vmw_display_unit
*du
= vmw_crtc_to_du(crtc
);
579 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
580 struct vmw_framebuffer
*vfb
= vmw_framebuffer_to_vfb(new_fb
);
582 vcs
= vmw_connector_state_to_vcs(du
->connector
.state
);
584 if ((dest
.x2
> new_fb
->width
||
585 dest
.y2
> new_fb
->height
)) {
586 DRM_ERROR("CRTC area outside of framebuffer\n");
590 /* Only one active implicit framebuffer at a time. */
591 mutex_lock(&dev_priv
->global_kms_state_mutex
);
592 if (vcs
->is_implicit
&& dev_priv
->implicit_fb
&&
593 !(dev_priv
->num_implicit
== 1 && du
->active_implicit
)
594 && dev_priv
->implicit_fb
!= vfb
) {
595 DRM_ERROR("Multiple implicit framebuffers "
599 mutex_unlock(&dev_priv
->global_kms_state_mutex
);
608 * vmw_du_cursor_plane_atomic_check - check if the new state is okay
610 * @plane: cursor plane
611 * @state: info on the new plane state
613 * This is a chance to fail if the new cursor state does not fit
616 * Returns 0 on success
618 int vmw_du_cursor_plane_atomic_check(struct drm_plane
*plane
,
619 struct drm_plane_state
*new_state
)
622 struct vmw_surface
*surface
= NULL
;
623 struct drm_framebuffer
*fb
= new_state
->fb
;
630 /* A lot of the code assumes this */
631 if (new_state
->crtc_w
!= 64 || new_state
->crtc_h
!= 64) {
632 DRM_ERROR("Invalid cursor dimensions (%d, %d)\n",
633 new_state
->crtc_w
, new_state
->crtc_h
);
637 if (!vmw_framebuffer_to_vfb(fb
)->dmabuf
)
638 surface
= vmw_framebuffer_to_vfbs(fb
)->surface
;
640 if (surface
&& !surface
->snooper
.image
) {
641 DRM_ERROR("surface not suitable for cursor\n");
649 int vmw_du_crtc_atomic_check(struct drm_crtc
*crtc
,
650 struct drm_crtc_state
*new_state
)
652 struct vmw_display_unit
*du
= vmw_crtc_to_du(new_state
->crtc
);
653 int connector_mask
= 1 << drm_connector_index(&du
->connector
);
654 bool has_primary
= new_state
->plane_mask
&
655 BIT(drm_plane_index(crtc
->primary
));
657 /* We always want to have an active plane with an active CRTC */
658 if (has_primary
!= new_state
->enable
)
662 if (new_state
->connector_mask
!= connector_mask
&&
663 new_state
->connector_mask
!= 0) {
664 DRM_ERROR("Invalid connectors configuration\n");
669 * Our virtual device does not have a dot clock, so use the logical
670 * clock value as the dot clock.
672 if (new_state
->mode
.crtc_clock
== 0)
673 new_state
->adjusted_mode
.crtc_clock
= new_state
->mode
.clock
;
679 void vmw_du_crtc_atomic_begin(struct drm_crtc
*crtc
,
680 struct drm_crtc_state
*old_crtc_state
)
685 void vmw_du_crtc_atomic_flush(struct drm_crtc
*crtc
,
686 struct drm_crtc_state
*old_crtc_state
)
688 struct drm_pending_vblank_event
*event
= crtc
->state
->event
;
691 crtc
->state
->event
= NULL
;
693 spin_lock_irq(&crtc
->dev
->event_lock
);
694 if (drm_crtc_vblank_get(crtc
) == 0)
695 drm_crtc_arm_vblank_event(crtc
, event
);
697 drm_crtc_send_vblank_event(crtc
, event
);
698 spin_unlock_irq(&crtc
->dev
->event_lock
);
705 * vmw_du_crtc_duplicate_state - duplicate crtc state
708 * Allocates and returns a copy of the crtc state (both common and
709 * vmw-specific) for the specified crtc.
711 * Returns: The newly allocated crtc state, or NULL on failure.
713 struct drm_crtc_state
*
714 vmw_du_crtc_duplicate_state(struct drm_crtc
*crtc
)
716 struct drm_crtc_state
*state
;
717 struct vmw_crtc_state
*vcs
;
719 if (WARN_ON(!crtc
->state
))
722 vcs
= kmemdup(crtc
->state
, sizeof(*vcs
), GFP_KERNEL
);
729 __drm_atomic_helper_crtc_duplicate_state(crtc
, state
);
736 * vmw_du_crtc_reset - creates a blank vmw crtc state
739 * Resets the atomic state for @crtc by freeing the state pointer (which
740 * might be NULL, e.g. at driver load time) and allocating a new empty state
743 void vmw_du_crtc_reset(struct drm_crtc
*crtc
)
745 struct vmw_crtc_state
*vcs
;
749 __drm_atomic_helper_crtc_destroy_state(crtc
->state
);
751 kfree(vmw_crtc_state_to_vcs(crtc
->state
));
754 vcs
= kzalloc(sizeof(*vcs
), GFP_KERNEL
);
757 DRM_ERROR("Cannot allocate vmw_crtc_state\n");
761 crtc
->state
= &vcs
->base
;
762 crtc
->state
->crtc
= crtc
;
767 * vmw_du_crtc_destroy_state - destroy crtc state
769 * @state: state object to destroy
771 * Destroys the crtc state (both common and vmw-specific) for the
775 vmw_du_crtc_destroy_state(struct drm_crtc
*crtc
,
776 struct drm_crtc_state
*state
)
778 drm_atomic_helper_crtc_destroy_state(crtc
, state
);
783 * vmw_du_plane_duplicate_state - duplicate plane state
786 * Allocates and returns a copy of the plane state (both common and
787 * vmw-specific) for the specified plane.
789 * Returns: The newly allocated plane state, or NULL on failure.
791 struct drm_plane_state
*
792 vmw_du_plane_duplicate_state(struct drm_plane
*plane
)
794 struct drm_plane_state
*state
;
795 struct vmw_plane_state
*vps
;
797 vps
= kmemdup(plane
->state
, sizeof(*vps
), GFP_KERNEL
);
804 /* Mapping is managed by prepare_fb/cleanup_fb */
805 memset(&vps
->guest_map
, 0, sizeof(vps
->guest_map
));
806 memset(&vps
->host_map
, 0, sizeof(vps
->host_map
));
809 /* Each ref counted resource needs to be acquired again */
811 (void) vmw_surface_reference(vps
->surf
);
814 (void) vmw_dmabuf_reference(vps
->dmabuf
);
818 __drm_atomic_helper_plane_duplicate_state(plane
, state
);
825 * vmw_du_plane_reset - creates a blank vmw plane state
828 * Resets the atomic state for @plane by freeing the state pointer (which might
829 * be NULL, e.g. at driver load time) and allocating a new empty state object.
831 void vmw_du_plane_reset(struct drm_plane
*plane
)
833 struct vmw_plane_state
*vps
;
837 vmw_du_plane_destroy_state(plane
, plane
->state
);
839 vps
= kzalloc(sizeof(*vps
), GFP_KERNEL
);
842 DRM_ERROR("Cannot allocate vmw_plane_state\n");
846 plane
->state
= &vps
->base
;
847 plane
->state
->plane
= plane
;
848 plane
->state
->rotation
= DRM_ROTATE_0
;
853 * vmw_du_plane_destroy_state - destroy plane state
855 * @state: state object to destroy
857 * Destroys the plane state (both common and vmw-specific) for the
861 vmw_du_plane_destroy_state(struct drm_plane
*plane
,
862 struct drm_plane_state
*state
)
864 struct vmw_plane_state
*vps
= vmw_plane_state_to_vps(state
);
867 /* Should have been freed by cleanup_fb */
868 if (vps
->guest_map
.virtual) {
869 DRM_ERROR("Guest mapping not freed\n");
870 ttm_bo_kunmap(&vps
->guest_map
);
873 if (vps
->host_map
.virtual) {
874 DRM_ERROR("Host mapping not freed\n");
875 ttm_bo_kunmap(&vps
->host_map
);
879 vmw_surface_unreference(&vps
->surf
);
882 vmw_dmabuf_unreference(&vps
->dmabuf
);
884 drm_atomic_helper_plane_destroy_state(plane
, state
);
889 * vmw_du_connector_duplicate_state - duplicate connector state
890 * @connector: DRM connector
892 * Allocates and returns a copy of the connector state (both common and
893 * vmw-specific) for the specified connector.
895 * Returns: The newly allocated connector state, or NULL on failure.
897 struct drm_connector_state
*
898 vmw_du_connector_duplicate_state(struct drm_connector
*connector
)
900 struct drm_connector_state
*state
;
901 struct vmw_connector_state
*vcs
;
903 if (WARN_ON(!connector
->state
))
906 vcs
= kmemdup(connector
->state
, sizeof(*vcs
), GFP_KERNEL
);
913 __drm_atomic_helper_connector_duplicate_state(connector
, state
);
920 * vmw_du_connector_reset - creates a blank vmw connector state
921 * @connector: DRM connector
923 * Resets the atomic state for @connector by freeing the state pointer (which
924 * might be NULL, e.g. at driver load time) and allocating a new empty state
927 void vmw_du_connector_reset(struct drm_connector
*connector
)
929 struct vmw_connector_state
*vcs
;
932 if (connector
->state
) {
933 __drm_atomic_helper_connector_destroy_state(connector
->state
);
935 kfree(vmw_connector_state_to_vcs(connector
->state
));
938 vcs
= kzalloc(sizeof(*vcs
), GFP_KERNEL
);
941 DRM_ERROR("Cannot allocate vmw_connector_state\n");
945 __drm_atomic_helper_connector_reset(connector
, &vcs
->base
);
950 * vmw_du_connector_destroy_state - destroy connector state
951 * @connector: DRM connector
952 * @state: state object to destroy
954 * Destroys the connector state (both common and vmw-specific) for the
958 vmw_du_connector_destroy_state(struct drm_connector
*connector
,
959 struct drm_connector_state
*state
)
961 drm_atomic_helper_connector_destroy_state(connector
, state
);
964 * Generic framebuffer code
968 * Surface framebuffer code
971 static void vmw_framebuffer_surface_destroy(struct drm_framebuffer
*framebuffer
)
973 struct vmw_framebuffer_surface
*vfbs
=
974 vmw_framebuffer_to_vfbs(framebuffer
);
976 drm_framebuffer_cleanup(framebuffer
);
977 vmw_surface_unreference(&vfbs
->surface
);
978 if (vfbs
->base
.user_obj
)
979 ttm_base_object_unref(&vfbs
->base
.user_obj
);
984 static int vmw_framebuffer_surface_dirty(struct drm_framebuffer
*framebuffer
,
985 struct drm_file
*file_priv
,
986 unsigned flags
, unsigned color
,
987 struct drm_clip_rect
*clips
,
990 struct vmw_private
*dev_priv
= vmw_priv(framebuffer
->dev
);
991 struct vmw_framebuffer_surface
*vfbs
=
992 vmw_framebuffer_to_vfbs(framebuffer
);
993 struct drm_clip_rect norect
;
996 /* Legacy Display Unit does not support 3D */
997 if (dev_priv
->active_display_unit
== vmw_du_legacy
)
1000 drm_modeset_lock_all(dev_priv
->dev
);
1002 ret
= ttm_read_lock(&dev_priv
->reservation_sem
, true);
1003 if (unlikely(ret
!= 0)) {
1004 drm_modeset_unlock_all(dev_priv
->dev
);
1011 norect
.x1
= norect
.y1
= 0;
1012 norect
.x2
= framebuffer
->width
;
1013 norect
.y2
= framebuffer
->height
;
1014 } else if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
) {
1016 inc
= 2; /* skip source rects */
1019 if (dev_priv
->active_display_unit
== vmw_du_screen_object
)
1020 ret
= vmw_kms_sou_do_surface_dirty(dev_priv
, &vfbs
->base
,
1021 clips
, NULL
, NULL
, 0, 0,
1022 num_clips
, inc
, NULL
);
1024 ret
= vmw_kms_stdu_surface_dirty(dev_priv
, &vfbs
->base
,
1025 clips
, NULL
, NULL
, 0, 0,
1026 num_clips
, inc
, NULL
);
1028 vmw_fifo_flush(dev_priv
, false);
1029 ttm_read_unlock(&dev_priv
->reservation_sem
);
1031 drm_modeset_unlock_all(dev_priv
->dev
);
1037 * vmw_kms_readback - Perform a readback from the screen system to
1038 * a dma-buffer backed framebuffer.
1040 * @dev_priv: Pointer to the device private structure.
1041 * @file_priv: Pointer to a struct drm_file identifying the caller.
1042 * Must be set to NULL if @user_fence_rep is NULL.
1043 * @vfb: Pointer to the dma-buffer backed framebuffer.
1044 * @user_fence_rep: User-space provided structure for fence information.
1045 * Must be set to non-NULL if @file_priv is non-NULL.
1046 * @vclips: Array of clip rects.
1047 * @num_clips: Number of clip rects in @vclips.
1049 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
1052 int vmw_kms_readback(struct vmw_private
*dev_priv
,
1053 struct drm_file
*file_priv
,
1054 struct vmw_framebuffer
*vfb
,
1055 struct drm_vmw_fence_rep __user
*user_fence_rep
,
1056 struct drm_vmw_rect
*vclips
,
1059 switch (dev_priv
->active_display_unit
) {
1060 case vmw_du_screen_object
:
1061 return vmw_kms_sou_readback(dev_priv
, file_priv
, vfb
,
1062 user_fence_rep
, vclips
, num_clips
);
1063 case vmw_du_screen_target
:
1064 return vmw_kms_stdu_dma(dev_priv
, file_priv
, vfb
,
1065 user_fence_rep
, NULL
, vclips
, num_clips
,
1069 "Readback called with invalid display system.\n");
1076 static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs
= {
1077 .destroy
= vmw_framebuffer_surface_destroy
,
1078 .dirty
= vmw_framebuffer_surface_dirty
,
1081 static int vmw_kms_new_framebuffer_surface(struct vmw_private
*dev_priv
,
1082 struct vmw_surface
*surface
,
1083 struct vmw_framebuffer
**out
,
1084 const struct drm_mode_fb_cmd2
1086 bool is_dmabuf_proxy
)
1089 struct drm_device
*dev
= dev_priv
->dev
;
1090 struct vmw_framebuffer_surface
*vfbs
;
1091 enum SVGA3dSurfaceFormat format
;
1093 struct drm_format_name_buf format_name
;
1095 /* 3D is only supported on HWv8 and newer hosts */
1096 if (dev_priv
->active_display_unit
== vmw_du_legacy
)
1103 /* Surface must be marked as a scanout. */
1104 if (unlikely(!surface
->scanout
))
1107 if (unlikely(surface
->mip_levels
[0] != 1 ||
1108 surface
->num_sizes
!= 1 ||
1109 surface
->base_size
.width
< mode_cmd
->width
||
1110 surface
->base_size
.height
< mode_cmd
->height
||
1111 surface
->base_size
.depth
!= 1)) {
1112 DRM_ERROR("Incompatible surface dimensions "
1113 "for requested mode.\n");
1117 switch (mode_cmd
->pixel_format
) {
1118 case DRM_FORMAT_ARGB8888
:
1119 format
= SVGA3D_A8R8G8B8
;
1121 case DRM_FORMAT_XRGB8888
:
1122 format
= SVGA3D_X8R8G8B8
;
1124 case DRM_FORMAT_RGB565
:
1125 format
= SVGA3D_R5G6B5
;
1127 case DRM_FORMAT_XRGB1555
:
1128 format
= SVGA3D_A1R5G5B5
;
1131 DRM_ERROR("Invalid pixel format: %s\n",
1132 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
1137 * For DX, surface format validation is done when surface->scanout
1140 if (!dev_priv
->has_dx
&& format
!= surface
->format
) {
1141 DRM_ERROR("Invalid surface format for requested mode.\n");
1145 vfbs
= kzalloc(sizeof(*vfbs
), GFP_KERNEL
);
1151 drm_helper_mode_fill_fb_struct(dev
, &vfbs
->base
.base
, mode_cmd
);
1152 vfbs
->surface
= vmw_surface_reference(surface
);
1153 vfbs
->base
.user_handle
= mode_cmd
->handles
[0];
1154 vfbs
->is_dmabuf_proxy
= is_dmabuf_proxy
;
1158 ret
= drm_framebuffer_init(dev
, &vfbs
->base
.base
,
1159 &vmw_framebuffer_surface_funcs
);
1166 vmw_surface_unreference(&surface
);
1173 * Dmabuf framebuffer code
1176 static void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer
*framebuffer
)
1178 struct vmw_framebuffer_dmabuf
*vfbd
=
1179 vmw_framebuffer_to_vfbd(framebuffer
);
1181 drm_framebuffer_cleanup(framebuffer
);
1182 vmw_dmabuf_unreference(&vfbd
->buffer
);
1183 if (vfbd
->base
.user_obj
)
1184 ttm_base_object_unref(&vfbd
->base
.user_obj
);
1189 static int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer
*framebuffer
,
1190 struct drm_file
*file_priv
,
1191 unsigned flags
, unsigned color
,
1192 struct drm_clip_rect
*clips
,
1195 struct vmw_private
*dev_priv
= vmw_priv(framebuffer
->dev
);
1196 struct vmw_framebuffer_dmabuf
*vfbd
=
1197 vmw_framebuffer_to_vfbd(framebuffer
);
1198 struct drm_clip_rect norect
;
1199 int ret
, increment
= 1;
1201 drm_modeset_lock_all(dev_priv
->dev
);
1203 ret
= ttm_read_lock(&dev_priv
->reservation_sem
, true);
1204 if (unlikely(ret
!= 0)) {
1205 drm_modeset_unlock_all(dev_priv
->dev
);
1212 norect
.x1
= norect
.y1
= 0;
1213 norect
.x2
= framebuffer
->width
;
1214 norect
.y2
= framebuffer
->height
;
1215 } else if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
) {
1220 switch (dev_priv
->active_display_unit
) {
1221 case vmw_du_screen_target
:
1222 ret
= vmw_kms_stdu_dma(dev_priv
, NULL
, &vfbd
->base
, NULL
,
1223 clips
, NULL
, num_clips
, increment
,
1226 case vmw_du_screen_object
:
1227 ret
= vmw_kms_sou_do_dmabuf_dirty(dev_priv
, &vfbd
->base
,
1228 clips
, NULL
, num_clips
,
1229 increment
, true, NULL
);
1232 ret
= vmw_kms_ldu_do_dmabuf_dirty(dev_priv
, &vfbd
->base
, 0, 0,
1233 clips
, num_clips
, increment
);
1237 WARN_ONCE(true, "Dirty called with invalid display system.\n");
1241 vmw_fifo_flush(dev_priv
, false);
1242 ttm_read_unlock(&dev_priv
->reservation_sem
);
1244 drm_modeset_unlock_all(dev_priv
->dev
);
1249 static const struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs
= {
1250 .destroy
= vmw_framebuffer_dmabuf_destroy
,
1251 .dirty
= vmw_framebuffer_dmabuf_dirty
,
1255 * Pin the dmabuffer to the start of vram.
1257 static int vmw_framebuffer_pin(struct vmw_framebuffer
*vfb
)
1259 struct vmw_private
*dev_priv
= vmw_priv(vfb
->base
.dev
);
1260 struct vmw_dma_buffer
*buf
;
1263 buf
= vfb
->dmabuf
? vmw_framebuffer_to_vfbd(&vfb
->base
)->buffer
:
1264 vmw_framebuffer_to_vfbs(&vfb
->base
)->surface
->res
.backup
;
1269 switch (dev_priv
->active_display_unit
) {
1271 vmw_overlay_pause_all(dev_priv
);
1272 ret
= vmw_dmabuf_pin_in_start_of_vram(dev_priv
, buf
, false);
1273 vmw_overlay_resume_all(dev_priv
);
1275 case vmw_du_screen_object
:
1276 case vmw_du_screen_target
:
1278 return vmw_dmabuf_pin_in_vram_or_gmr(dev_priv
, buf
,
1281 return vmw_dmabuf_pin_in_placement(dev_priv
, buf
,
1282 &vmw_mob_placement
, false);
1290 static int vmw_framebuffer_unpin(struct vmw_framebuffer
*vfb
)
1292 struct vmw_private
*dev_priv
= vmw_priv(vfb
->base
.dev
);
1293 struct vmw_dma_buffer
*buf
;
1295 buf
= vfb
->dmabuf
? vmw_framebuffer_to_vfbd(&vfb
->base
)->buffer
:
1296 vmw_framebuffer_to_vfbs(&vfb
->base
)->surface
->res
.backup
;
1301 return vmw_dmabuf_unpin(dev_priv
, buf
, false);
1305 * vmw_create_dmabuf_proxy - create a proxy surface for the DMA buf
1308 * @mode_cmd: parameters for the new surface
1309 * @dmabuf_mob: MOB backing the DMA buf
1310 * @srf_out: newly created surface
1312 * When the content FB is a DMA buf, we create a surface as a proxy to the
1313 * same buffer. This way we can do a surface copy rather than a surface DMA.
1314 * This is a more efficient approach
1317 * 0 on success, error code otherwise
1319 static int vmw_create_dmabuf_proxy(struct drm_device
*dev
,
1320 const struct drm_mode_fb_cmd2
*mode_cmd
,
1321 struct vmw_dma_buffer
*dmabuf_mob
,
1322 struct vmw_surface
**srf_out
)
1325 struct drm_vmw_size content_base_size
= {0};
1326 struct vmw_resource
*res
;
1327 unsigned int bytes_pp
;
1328 struct drm_format_name_buf format_name
;
1331 switch (mode_cmd
->pixel_format
) {
1332 case DRM_FORMAT_ARGB8888
:
1333 case DRM_FORMAT_XRGB8888
:
1334 format
= SVGA3D_X8R8G8B8
;
1338 case DRM_FORMAT_RGB565
:
1339 case DRM_FORMAT_XRGB1555
:
1340 format
= SVGA3D_R5G6B5
;
1350 DRM_ERROR("Invalid framebuffer format %s\n",
1351 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
1355 content_base_size
.width
= mode_cmd
->pitches
[0] / bytes_pp
;
1356 content_base_size
.height
= mode_cmd
->height
;
1357 content_base_size
.depth
= 1;
1359 ret
= vmw_surface_gb_priv_define(dev
,
1360 0, /* kernel visible only */
1363 true, /* can be a scanout buffer */
1364 1, /* num of mip levels */
1370 DRM_ERROR("Failed to allocate proxy content buffer\n");
1374 res
= &(*srf_out
)->res
;
1376 /* Reserve and switch the backing mob. */
1377 mutex_lock(&res
->dev_priv
->cmdbuf_mutex
);
1378 (void) vmw_resource_reserve(res
, false, true);
1379 vmw_dmabuf_unreference(&res
->backup
);
1380 res
->backup
= vmw_dmabuf_reference(dmabuf_mob
);
1381 res
->backup_offset
= 0;
1382 vmw_resource_unreserve(res
, false, NULL
, 0);
1383 mutex_unlock(&res
->dev_priv
->cmdbuf_mutex
);
1390 static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private
*dev_priv
,
1391 struct vmw_dma_buffer
*dmabuf
,
1392 struct vmw_framebuffer
**out
,
1393 const struct drm_mode_fb_cmd2
1397 struct drm_device
*dev
= dev_priv
->dev
;
1398 struct vmw_framebuffer_dmabuf
*vfbd
;
1399 unsigned int requested_size
;
1400 struct drm_format_name_buf format_name
;
1403 requested_size
= mode_cmd
->height
* mode_cmd
->pitches
[0];
1404 if (unlikely(requested_size
> dmabuf
->base
.num_pages
* PAGE_SIZE
)) {
1405 DRM_ERROR("Screen buffer object size is too small "
1406 "for requested mode.\n");
1410 /* Limited framebuffer color depth support for screen objects */
1411 if (dev_priv
->active_display_unit
== vmw_du_screen_object
) {
1412 switch (mode_cmd
->pixel_format
) {
1413 case DRM_FORMAT_XRGB8888
:
1414 case DRM_FORMAT_ARGB8888
:
1416 case DRM_FORMAT_XRGB1555
:
1417 case DRM_FORMAT_RGB565
:
1420 DRM_ERROR("Invalid pixel format: %s\n",
1421 drm_get_format_name(mode_cmd
->pixel_format
, &format_name
));
1426 vfbd
= kzalloc(sizeof(*vfbd
), GFP_KERNEL
);
1432 drm_helper_mode_fill_fb_struct(dev
, &vfbd
->base
.base
, mode_cmd
);
1433 vfbd
->base
.dmabuf
= true;
1434 vfbd
->buffer
= vmw_dmabuf_reference(dmabuf
);
1435 vfbd
->base
.user_handle
= mode_cmd
->handles
[0];
1438 ret
= drm_framebuffer_init(dev
, &vfbd
->base
.base
,
1439 &vmw_framebuffer_dmabuf_funcs
);
1446 vmw_dmabuf_unreference(&dmabuf
);
1454 * vmw_kms_srf_ok - check if a surface can be created
1456 * @width: requested width
1457 * @height: requested height
1459 * Surfaces need to be less than texture size
1462 vmw_kms_srf_ok(struct vmw_private
*dev_priv
, uint32_t width
, uint32_t height
)
1464 if (width
> dev_priv
->texture_max_width
||
1465 height
> dev_priv
->texture_max_height
)
1472 * vmw_kms_new_framebuffer - Create a new framebuffer.
1474 * @dev_priv: Pointer to device private struct.
1475 * @dmabuf: Pointer to dma buffer to wrap the kms framebuffer around.
1476 * Either @dmabuf or @surface must be NULL.
1477 * @surface: Pointer to a surface to wrap the kms framebuffer around.
1478 * Either @dmabuf or @surface must be NULL.
1479 * @only_2d: No presents will occur to this dma buffer based framebuffer. This
1480 * Helps the code to do some important optimizations.
1481 * @mode_cmd: Frame-buffer metadata.
1483 struct vmw_framebuffer
*
1484 vmw_kms_new_framebuffer(struct vmw_private
*dev_priv
,
1485 struct vmw_dma_buffer
*dmabuf
,
1486 struct vmw_surface
*surface
,
1488 const struct drm_mode_fb_cmd2
*mode_cmd
)
1490 struct vmw_framebuffer
*vfb
= NULL
;
1491 bool is_dmabuf_proxy
= false;
1495 * We cannot use the SurfaceDMA command in an non-accelerated VM,
1496 * therefore, wrap the DMA buf in a surface so we can use the
1497 * SurfaceCopy command.
1499 if (vmw_kms_srf_ok(dev_priv
, mode_cmd
->width
, mode_cmd
->height
) &&
1500 dmabuf
&& only_2d
&&
1501 dev_priv
->active_display_unit
== vmw_du_screen_target
) {
1502 ret
= vmw_create_dmabuf_proxy(dev_priv
->dev
, mode_cmd
,
1505 return ERR_PTR(ret
);
1507 is_dmabuf_proxy
= true;
1510 /* Create the new framebuffer depending one what we have */
1512 ret
= vmw_kms_new_framebuffer_surface(dev_priv
, surface
, &vfb
,
1517 * vmw_create_dmabuf_proxy() adds a reference that is no longer
1520 if (is_dmabuf_proxy
)
1521 vmw_surface_unreference(&surface
);
1522 } else if (dmabuf
) {
1523 ret
= vmw_kms_new_framebuffer_dmabuf(dev_priv
, dmabuf
, &vfb
,
1530 return ERR_PTR(ret
);
1532 vfb
->pin
= vmw_framebuffer_pin
;
1533 vfb
->unpin
= vmw_framebuffer_unpin
;
1539 * Generic Kernel modesetting functions
1542 static struct drm_framebuffer
*vmw_kms_fb_create(struct drm_device
*dev
,
1543 struct drm_file
*file_priv
,
1544 const struct drm_mode_fb_cmd2
*mode_cmd
)
1546 struct vmw_private
*dev_priv
= vmw_priv(dev
);
1547 struct ttm_object_file
*tfile
= vmw_fpriv(file_priv
)->tfile
;
1548 struct vmw_framebuffer
*vfb
= NULL
;
1549 struct vmw_surface
*surface
= NULL
;
1550 struct vmw_dma_buffer
*bo
= NULL
;
1551 struct ttm_base_object
*user_obj
;
1555 * This code should be conditioned on Screen Objects not being used.
1556 * If screen objects are used, we can allocate a GMR to hold the
1557 * requested framebuffer.
1560 if (!vmw_kms_validate_mode_vram(dev_priv
,
1561 mode_cmd
->pitches
[0],
1562 mode_cmd
->height
)) {
1563 DRM_ERROR("Requested mode exceed bounding box limit.\n");
1564 return ERR_PTR(-ENOMEM
);
1568 * Take a reference on the user object of the resource
1569 * backing the kms fb. This ensures that user-space handle
1570 * lookups on that resource will always work as long as
1571 * it's registered with a kms framebuffer. This is important,
1572 * since vmw_execbuf_process identifies resources in the
1573 * command stream using user-space handles.
1576 user_obj
= ttm_base_object_lookup(tfile
, mode_cmd
->handles
[0]);
1577 if (unlikely(user_obj
== NULL
)) {
1578 DRM_ERROR("Could not locate requested kms frame buffer.\n");
1579 return ERR_PTR(-ENOENT
);
1583 * End conditioned code.
1586 /* returns either a dmabuf or surface */
1587 ret
= vmw_user_lookup_handle(dev_priv
, tfile
,
1588 mode_cmd
->handles
[0],
1595 !vmw_kms_srf_ok(dev_priv
, mode_cmd
->width
, mode_cmd
->height
)) {
1596 DRM_ERROR("Surface size cannot exceed %dx%d",
1597 dev_priv
->texture_max_width
,
1598 dev_priv
->texture_max_height
);
1603 vfb
= vmw_kms_new_framebuffer(dev_priv
, bo
, surface
,
1604 !(dev_priv
->capabilities
& SVGA_CAP_3D
),
1612 /* vmw_user_lookup_handle takes one ref so does new_fb */
1614 vmw_dmabuf_unreference(&bo
);
1616 vmw_surface_unreference(&surface
);
1619 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret
);
1620 ttm_base_object_unref(&user_obj
);
1621 return ERR_PTR(ret
);
1623 vfb
->user_obj
= user_obj
;
1631 * vmw_kms_atomic_check_modeset- validate state object for modeset changes
1634 * @state: the driver state object
1636 * This is a simple wrapper around drm_atomic_helper_check_modeset() for
1637 * us to assign a value to mode->crtc_clock so that
1638 * drm_calc_timestamping_constants() won't throw an error message
1641 * Zero for success or -errno
1644 vmw_kms_atomic_check_modeset(struct drm_device
*dev
,
1645 struct drm_atomic_state
*state
)
1647 struct drm_crtc_state
*crtc_state
;
1648 struct drm_crtc
*crtc
;
1649 struct vmw_private
*dev_priv
= vmw_priv(dev
);
1653 for_each_crtc_in_state(state
, crtc
, crtc_state
, i
) {
1654 unsigned long requested_bb_mem
= 0;
1656 if (dev_priv
->active_display_unit
== vmw_du_screen_target
) {
1657 if (crtc
->primary
->fb
) {
1658 int cpp
= crtc
->primary
->fb
->pitches
[0] /
1659 crtc
->primary
->fb
->width
;
1661 requested_bb_mem
+= crtc
->mode
.hdisplay
* cpp
*
1662 crtc
->mode
.vdisplay
;
1665 if (requested_bb_mem
> dev_priv
->prim_bb_mem
)
1670 return drm_atomic_helper_check(dev
, state
);
1674 static const struct drm_mode_config_funcs vmw_kms_funcs
= {
1675 .fb_create
= vmw_kms_fb_create
,
1676 .atomic_check
= vmw_kms_atomic_check_modeset
,
1677 .atomic_commit
= drm_atomic_helper_commit
,
1680 static int vmw_kms_generic_present(struct vmw_private
*dev_priv
,
1681 struct drm_file
*file_priv
,
1682 struct vmw_framebuffer
*vfb
,
1683 struct vmw_surface
*surface
,
1685 int32_t destX
, int32_t destY
,
1686 struct drm_vmw_rect
*clips
,
1689 return vmw_kms_sou_do_surface_dirty(dev_priv
, vfb
, NULL
, clips
,
1690 &surface
->res
, destX
, destY
,
1691 num_clips
, 1, NULL
);
1695 int vmw_kms_present(struct vmw_private
*dev_priv
,
1696 struct drm_file
*file_priv
,
1697 struct vmw_framebuffer
*vfb
,
1698 struct vmw_surface
*surface
,
1700 int32_t destX
, int32_t destY
,
1701 struct drm_vmw_rect
*clips
,
1706 switch (dev_priv
->active_display_unit
) {
1707 case vmw_du_screen_target
:
1708 ret
= vmw_kms_stdu_surface_dirty(dev_priv
, vfb
, NULL
, clips
,
1709 &surface
->res
, destX
, destY
,
1710 num_clips
, 1, NULL
);
1712 case vmw_du_screen_object
:
1713 ret
= vmw_kms_generic_present(dev_priv
, file_priv
, vfb
, surface
,
1714 sid
, destX
, destY
, clips
,
1719 "Present called with invalid display system.\n");
1726 vmw_fifo_flush(dev_priv
, false);
1732 vmw_kms_create_hotplug_mode_update_property(struct vmw_private
*dev_priv
)
1734 if (dev_priv
->hotplug_mode_update_property
)
1737 dev_priv
->hotplug_mode_update_property
=
1738 drm_property_create_range(dev_priv
->dev
,
1739 DRM_MODE_PROP_IMMUTABLE
,
1740 "hotplug_mode_update", 0, 1);
1742 if (!dev_priv
->hotplug_mode_update_property
)
1747 int vmw_kms_init(struct vmw_private
*dev_priv
)
1749 struct drm_device
*dev
= dev_priv
->dev
;
1752 drm_mode_config_init(dev
);
1753 dev
->mode_config
.funcs
= &vmw_kms_funcs
;
1754 dev
->mode_config
.min_width
= 1;
1755 dev
->mode_config
.min_height
= 1;
1756 dev
->mode_config
.max_width
= dev_priv
->texture_max_width
;
1757 dev
->mode_config
.max_height
= dev_priv
->texture_max_height
;
1759 drm_mode_create_suggested_offset_properties(dev
);
1760 vmw_kms_create_hotplug_mode_update_property(dev_priv
);
1762 ret
= vmw_kms_stdu_init_display(dev_priv
);
1764 ret
= vmw_kms_sou_init_display(dev_priv
);
1765 if (ret
) /* Fallback */
1766 ret
= vmw_kms_ldu_init_display(dev_priv
);
1772 int vmw_kms_close(struct vmw_private
*dev_priv
)
1777 * Docs says we should take the lock before calling this function
1778 * but since it destroys encoders and our destructor calls
1779 * drm_encoder_cleanup which takes the lock we deadlock.
1781 drm_mode_config_cleanup(dev_priv
->dev
);
1782 if (dev_priv
->active_display_unit
== vmw_du_screen_object
)
1783 ret
= vmw_kms_sou_close_display(dev_priv
);
1784 else if (dev_priv
->active_display_unit
== vmw_du_screen_target
)
1785 ret
= vmw_kms_stdu_close_display(dev_priv
);
1787 ret
= vmw_kms_ldu_close_display(dev_priv
);
1792 int vmw_kms_cursor_bypass_ioctl(struct drm_device
*dev
, void *data
,
1793 struct drm_file
*file_priv
)
1795 struct drm_vmw_cursor_bypass_arg
*arg
= data
;
1796 struct vmw_display_unit
*du
;
1797 struct drm_crtc
*crtc
;
1801 mutex_lock(&dev
->mode_config
.mutex
);
1802 if (arg
->flags
& DRM_VMW_CURSOR_BYPASS_ALL
) {
1804 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
1805 du
= vmw_crtc_to_du(crtc
);
1806 du
->hotspot_x
= arg
->xhot
;
1807 du
->hotspot_y
= arg
->yhot
;
1810 mutex_unlock(&dev
->mode_config
.mutex
);
1814 crtc
= drm_crtc_find(dev
, arg
->crtc_id
);
1820 du
= vmw_crtc_to_du(crtc
);
1822 du
->hotspot_x
= arg
->xhot
;
1823 du
->hotspot_y
= arg
->yhot
;
1826 mutex_unlock(&dev
->mode_config
.mutex
);
1831 int vmw_kms_write_svga(struct vmw_private
*vmw_priv
,
1832 unsigned width
, unsigned height
, unsigned pitch
,
1833 unsigned bpp
, unsigned depth
)
1835 if (vmw_priv
->capabilities
& SVGA_CAP_PITCHLOCK
)
1836 vmw_write(vmw_priv
, SVGA_REG_PITCHLOCK
, pitch
);
1837 else if (vmw_fifo_have_pitchlock(vmw_priv
))
1838 vmw_mmio_write(pitch
, vmw_priv
->mmio_virt
+
1839 SVGA_FIFO_PITCHLOCK
);
1840 vmw_write(vmw_priv
, SVGA_REG_WIDTH
, width
);
1841 vmw_write(vmw_priv
, SVGA_REG_HEIGHT
, height
);
1842 vmw_write(vmw_priv
, SVGA_REG_BITS_PER_PIXEL
, bpp
);
1844 if (vmw_read(vmw_priv
, SVGA_REG_DEPTH
) != depth
) {
1845 DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n",
1846 depth
, bpp
, vmw_read(vmw_priv
, SVGA_REG_DEPTH
));
1853 int vmw_kms_save_vga(struct vmw_private
*vmw_priv
)
1855 struct vmw_vga_topology_state
*save
;
1858 vmw_priv
->vga_width
= vmw_read(vmw_priv
, SVGA_REG_WIDTH
);
1859 vmw_priv
->vga_height
= vmw_read(vmw_priv
, SVGA_REG_HEIGHT
);
1860 vmw_priv
->vga_bpp
= vmw_read(vmw_priv
, SVGA_REG_BITS_PER_PIXEL
);
1861 if (vmw_priv
->capabilities
& SVGA_CAP_PITCHLOCK
)
1862 vmw_priv
->vga_pitchlock
=
1863 vmw_read(vmw_priv
, SVGA_REG_PITCHLOCK
);
1864 else if (vmw_fifo_have_pitchlock(vmw_priv
))
1865 vmw_priv
->vga_pitchlock
= vmw_mmio_read(vmw_priv
->mmio_virt
+
1866 SVGA_FIFO_PITCHLOCK
);
1868 if (!(vmw_priv
->capabilities
& SVGA_CAP_DISPLAY_TOPOLOGY
))
1871 vmw_priv
->num_displays
= vmw_read(vmw_priv
,
1872 SVGA_REG_NUM_GUEST_DISPLAYS
);
1874 if (vmw_priv
->num_displays
== 0)
1875 vmw_priv
->num_displays
= 1;
1877 for (i
= 0; i
< vmw_priv
->num_displays
; ++i
) {
1878 save
= &vmw_priv
->vga_save
[i
];
1879 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_ID
, i
);
1880 save
->primary
= vmw_read(vmw_priv
, SVGA_REG_DISPLAY_IS_PRIMARY
);
1881 save
->pos_x
= vmw_read(vmw_priv
, SVGA_REG_DISPLAY_POSITION_X
);
1882 save
->pos_y
= vmw_read(vmw_priv
, SVGA_REG_DISPLAY_POSITION_Y
);
1883 save
->width
= vmw_read(vmw_priv
, SVGA_REG_DISPLAY_WIDTH
);
1884 save
->height
= vmw_read(vmw_priv
, SVGA_REG_DISPLAY_HEIGHT
);
1885 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_ID
, SVGA_ID_INVALID
);
1886 if (i
== 0 && vmw_priv
->num_displays
== 1 &&
1887 save
->width
== 0 && save
->height
== 0) {
1890 * It should be fairly safe to assume that these
1891 * values are uninitialized.
1894 save
->width
= vmw_priv
->vga_width
- save
->pos_x
;
1895 save
->height
= vmw_priv
->vga_height
- save
->pos_y
;
1902 int vmw_kms_restore_vga(struct vmw_private
*vmw_priv
)
1904 struct vmw_vga_topology_state
*save
;
1907 vmw_write(vmw_priv
, SVGA_REG_WIDTH
, vmw_priv
->vga_width
);
1908 vmw_write(vmw_priv
, SVGA_REG_HEIGHT
, vmw_priv
->vga_height
);
1909 vmw_write(vmw_priv
, SVGA_REG_BITS_PER_PIXEL
, vmw_priv
->vga_bpp
);
1910 if (vmw_priv
->capabilities
& SVGA_CAP_PITCHLOCK
)
1911 vmw_write(vmw_priv
, SVGA_REG_PITCHLOCK
,
1912 vmw_priv
->vga_pitchlock
);
1913 else if (vmw_fifo_have_pitchlock(vmw_priv
))
1914 vmw_mmio_write(vmw_priv
->vga_pitchlock
,
1915 vmw_priv
->mmio_virt
+ SVGA_FIFO_PITCHLOCK
);
1917 if (!(vmw_priv
->capabilities
& SVGA_CAP_DISPLAY_TOPOLOGY
))
1920 for (i
= 0; i
< vmw_priv
->num_displays
; ++i
) {
1921 save
= &vmw_priv
->vga_save
[i
];
1922 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_ID
, i
);
1923 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_IS_PRIMARY
, save
->primary
);
1924 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_POSITION_X
, save
->pos_x
);
1925 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_POSITION_Y
, save
->pos_y
);
1926 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_WIDTH
, save
->width
);
1927 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_HEIGHT
, save
->height
);
1928 vmw_write(vmw_priv
, SVGA_REG_DISPLAY_ID
, SVGA_ID_INVALID
);
1934 bool vmw_kms_validate_mode_vram(struct vmw_private
*dev_priv
,
1938 return ((u64
) pitch
* (u64
) height
) < (u64
)
1939 ((dev_priv
->active_display_unit
== vmw_du_screen_target
) ?
1940 dev_priv
->prim_bb_mem
: dev_priv
->vram_size
);
1945 * Function called by DRM code called with vbl_lock held.
1947 u32
vmw_get_vblank_counter(struct drm_device
*dev
, unsigned int pipe
)
1953 * Function called by DRM code called with vbl_lock held.
1955 int vmw_enable_vblank(struct drm_device
*dev
, unsigned int pipe
)
1961 * Function called by DRM code called with vbl_lock held.
1963 void vmw_disable_vblank(struct drm_device
*dev
, unsigned int pipe
)
1969 * Small shared kms functions.
1972 static int vmw_du_update_layout(struct vmw_private
*dev_priv
, unsigned num
,
1973 struct drm_vmw_rect
*rects
)
1975 struct drm_device
*dev
= dev_priv
->dev
;
1976 struct vmw_display_unit
*du
;
1977 struct drm_connector
*con
;
1979 mutex_lock(&dev
->mode_config
.mutex
);
1985 DRM_INFO("%s: new layout ", __func__
);
1986 for (i
= 0; i
< num
; i
++)
1987 DRM_INFO("(%i, %i %ux%u) ", rects
[i
].x
, rects
[i
].y
,
1988 rects
[i
].w
, rects
[i
].h
);
1993 list_for_each_entry(con
, &dev
->mode_config
.connector_list
, head
) {
1994 du
= vmw_connector_to_du(con
);
1995 if (num
> du
->unit
) {
1996 du
->pref_width
= rects
[du
->unit
].w
;
1997 du
->pref_height
= rects
[du
->unit
].h
;
1998 du
->pref_active
= true;
1999 du
->gui_x
= rects
[du
->unit
].x
;
2000 du
->gui_y
= rects
[du
->unit
].y
;
2001 drm_object_property_set_value
2002 (&con
->base
, dev
->mode_config
.suggested_x_property
,
2004 drm_object_property_set_value
2005 (&con
->base
, dev
->mode_config
.suggested_y_property
,
2008 du
->pref_width
= 800;
2009 du
->pref_height
= 600;
2010 du
->pref_active
= false;
2011 drm_object_property_set_value
2012 (&con
->base
, dev
->mode_config
.suggested_x_property
,
2014 drm_object_property_set_value
2015 (&con
->base
, dev
->mode_config
.suggested_y_property
,
2018 con
->status
= vmw_du_connector_detect(con
, true);
2021 mutex_unlock(&dev
->mode_config
.mutex
);
2022 drm_sysfs_hotplug_event(dev
);
2027 int vmw_du_crtc_gamma_set(struct drm_crtc
*crtc
,
2028 u16
*r
, u16
*g
, u16
*b
,
2030 struct drm_modeset_acquire_ctx
*ctx
)
2032 struct vmw_private
*dev_priv
= vmw_priv(crtc
->dev
);
2035 for (i
= 0; i
< size
; i
++) {
2036 DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i
,
2038 vmw_write(dev_priv
, SVGA_PALETTE_BASE
+ i
* 3 + 0, r
[i
] >> 8);
2039 vmw_write(dev_priv
, SVGA_PALETTE_BASE
+ i
* 3 + 1, g
[i
] >> 8);
2040 vmw_write(dev_priv
, SVGA_PALETTE_BASE
+ i
* 3 + 2, b
[i
] >> 8);
2046 int vmw_du_connector_dpms(struct drm_connector
*connector
, int mode
)
2051 enum drm_connector_status
2052 vmw_du_connector_detect(struct drm_connector
*connector
, bool force
)
2054 uint32_t num_displays
;
2055 struct drm_device
*dev
= connector
->dev
;
2056 struct vmw_private
*dev_priv
= vmw_priv(dev
);
2057 struct vmw_display_unit
*du
= vmw_connector_to_du(connector
);
2059 num_displays
= vmw_read(dev_priv
, SVGA_REG_NUM_DISPLAYS
);
2061 return ((vmw_connector_to_du(connector
)->unit
< num_displays
&&
2063 connector_status_connected
: connector_status_disconnected
);
2066 static struct drm_display_mode vmw_kms_connector_builtin
[] = {
2068 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
2069 752, 800, 0, 480, 489, 492, 525, 0,
2070 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
2072 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 40000, 800, 840,
2073 968, 1056, 0, 600, 601, 605, 628, 0,
2074 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2076 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
2077 1184, 1344, 0, 768, 771, 777, 806, 0,
2078 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
2080 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER
, 108000, 1152, 1216,
2081 1344, 1600, 0, 864, 865, 868, 900, 0,
2082 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2084 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 79500, 1280, 1344,
2085 1472, 1664, 0, 768, 771, 778, 798, 0,
2086 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2088 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 83500, 1280, 1352,
2089 1480, 1680, 0, 800, 803, 809, 831, 0,
2090 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
2092 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1376,
2093 1488, 1800, 0, 960, 961, 964, 1000, 0,
2094 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2095 /* 1280x1024@60Hz */
2096 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1328,
2097 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
2098 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2100 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER
, 85500, 1360, 1424,
2101 1536, 1792, 0, 768, 771, 777, 795, 0,
2102 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2103 /* 1440x1050@60Hz */
2104 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 121750, 1400, 1488,
2105 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
2106 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2108 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 106500, 1440, 1520,
2109 1672, 1904, 0, 900, 903, 909, 934, 0,
2110 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2111 /* 1600x1200@60Hz */
2112 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 162000, 1600, 1664,
2113 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
2114 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2115 /* 1680x1050@60Hz */
2116 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 146250, 1680, 1784,
2117 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
2118 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2119 /* 1792x1344@60Hz */
2120 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 204750, 1792, 1920,
2121 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
2122 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2123 /* 1853x1392@60Hz */
2124 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 218250, 1856, 1952,
2125 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
2126 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2127 /* 1920x1200@60Hz */
2128 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 193250, 1920, 2056,
2129 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
2130 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2131 /* 1920x1440@60Hz */
2132 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 234000, 1920, 2048,
2133 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
2134 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2135 /* 2560x1600@60Hz */
2136 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 348500, 2560, 2752,
2137 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
2138 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
2140 { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) },
2144 * vmw_guess_mode_timing - Provide fake timings for a
2145 * 60Hz vrefresh mode.
2147 * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay
2148 * members filled in.
2150 void vmw_guess_mode_timing(struct drm_display_mode
*mode
)
2152 mode
->hsync_start
= mode
->hdisplay
+ 50;
2153 mode
->hsync_end
= mode
->hsync_start
+ 50;
2154 mode
->htotal
= mode
->hsync_end
+ 50;
2156 mode
->vsync_start
= mode
->vdisplay
+ 50;
2157 mode
->vsync_end
= mode
->vsync_start
+ 50;
2158 mode
->vtotal
= mode
->vsync_end
+ 50;
2160 mode
->clock
= (u32
)mode
->htotal
* (u32
)mode
->vtotal
/ 100 * 6;
2161 mode
->vrefresh
= drm_mode_vrefresh(mode
);
2165 int vmw_du_connector_fill_modes(struct drm_connector
*connector
,
2166 uint32_t max_width
, uint32_t max_height
)
2168 struct vmw_display_unit
*du
= vmw_connector_to_du(connector
);
2169 struct drm_device
*dev
= connector
->dev
;
2170 struct vmw_private
*dev_priv
= vmw_priv(dev
);
2171 struct drm_display_mode
*mode
= NULL
;
2172 struct drm_display_mode
*bmode
;
2173 struct drm_display_mode prefmode
= { DRM_MODE("preferred",
2174 DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
,
2175 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2176 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
)
2179 u32 assumed_bpp
= 4;
2181 if (dev_priv
->assume_16bpp
)
2184 if (dev_priv
->active_display_unit
== vmw_du_screen_target
) {
2185 max_width
= min(max_width
, dev_priv
->stdu_max_width
);
2186 max_width
= min(max_width
, dev_priv
->texture_max_width
);
2188 max_height
= min(max_height
, dev_priv
->stdu_max_height
);
2189 max_height
= min(max_height
, dev_priv
->texture_max_height
);
2192 /* Add preferred mode */
2193 mode
= drm_mode_duplicate(dev
, &prefmode
);
2196 mode
->hdisplay
= du
->pref_width
;
2197 mode
->vdisplay
= du
->pref_height
;
2198 vmw_guess_mode_timing(mode
);
2200 if (vmw_kms_validate_mode_vram(dev_priv
,
2201 mode
->hdisplay
* assumed_bpp
,
2203 drm_mode_probed_add(connector
, mode
);
2205 drm_mode_destroy(dev
, mode
);
2209 if (du
->pref_mode
) {
2210 list_del_init(&du
->pref_mode
->head
);
2211 drm_mode_destroy(dev
, du
->pref_mode
);
2214 /* mode might be null here, this is intended */
2215 du
->pref_mode
= mode
;
2217 for (i
= 0; vmw_kms_connector_builtin
[i
].type
!= 0; i
++) {
2218 bmode
= &vmw_kms_connector_builtin
[i
];
2219 if (bmode
->hdisplay
> max_width
||
2220 bmode
->vdisplay
> max_height
)
2223 if (!vmw_kms_validate_mode_vram(dev_priv
,
2224 bmode
->hdisplay
* assumed_bpp
,
2228 mode
= drm_mode_duplicate(dev
, bmode
);
2231 mode
->vrefresh
= drm_mode_vrefresh(mode
);
2233 drm_mode_probed_add(connector
, mode
);
2236 drm_mode_connector_list_update(connector
);
2237 /* Move the prefered mode first, help apps pick the right mode. */
2238 drm_mode_sort(&connector
->modes
);
2243 int vmw_du_connector_set_property(struct drm_connector
*connector
,
2244 struct drm_property
*property
,
2247 struct vmw_display_unit
*du
= vmw_connector_to_du(connector
);
2248 struct vmw_private
*dev_priv
= vmw_priv(connector
->dev
);
2250 if (property
== dev_priv
->implicit_placement_property
)
2251 du
->is_implicit
= val
;
2259 * vmw_du_connector_atomic_set_property - Atomic version of get property
2261 * @crtc - crtc the property is associated with
2264 * Zero on success, negative errno on failure.
2267 vmw_du_connector_atomic_set_property(struct drm_connector
*connector
,
2268 struct drm_connector_state
*state
,
2269 struct drm_property
*property
,
2272 struct vmw_private
*dev_priv
= vmw_priv(connector
->dev
);
2273 struct vmw_connector_state
*vcs
= vmw_connector_state_to_vcs(state
);
2274 struct vmw_display_unit
*du
= vmw_connector_to_du(connector
);
2277 if (property
== dev_priv
->implicit_placement_property
) {
2278 vcs
->is_implicit
= val
;
2281 * We should really be doing a drm_atomic_commit() to
2282 * commit the new state, but since this doesn't cause
2283 * an immedate state change, this is probably ok
2285 du
->is_implicit
= vcs
->is_implicit
;
2295 * vmw_du_connector_atomic_get_property - Atomic version of get property
2297 * @connector - connector the property is associated with
2300 * Zero on success, negative errno on failure.
2303 vmw_du_connector_atomic_get_property(struct drm_connector
*connector
,
2304 const struct drm_connector_state
*state
,
2305 struct drm_property
*property
,
2308 struct vmw_private
*dev_priv
= vmw_priv(connector
->dev
);
2309 struct vmw_connector_state
*vcs
= vmw_connector_state_to_vcs(state
);
2311 if (property
== dev_priv
->implicit_placement_property
)
2312 *val
= vcs
->is_implicit
;
2314 DRM_ERROR("Invalid Property %s\n", property
->name
);
2322 int vmw_kms_update_layout_ioctl(struct drm_device
*dev
, void *data
,
2323 struct drm_file
*file_priv
)
2325 struct vmw_private
*dev_priv
= vmw_priv(dev
);
2326 struct drm_vmw_update_layout_arg
*arg
=
2327 (struct drm_vmw_update_layout_arg
*)data
;
2328 void __user
*user_rects
;
2329 struct drm_vmw_rect
*rects
;
2330 unsigned rects_size
;
2333 u64 total_pixels
= 0;
2334 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
2335 struct drm_vmw_rect bounding_box
= {0};
2337 if (!arg
->num_outputs
) {
2338 struct drm_vmw_rect def_rect
= {0, 0, 800, 600};
2339 vmw_du_update_layout(dev_priv
, 1, &def_rect
);
2343 rects_size
= arg
->num_outputs
* sizeof(struct drm_vmw_rect
);
2344 rects
= kcalloc(arg
->num_outputs
, sizeof(struct drm_vmw_rect
),
2346 if (unlikely(!rects
))
2349 user_rects
= (void __user
*)(unsigned long)arg
->rects
;
2350 ret
= copy_from_user(rects
, user_rects
, rects_size
);
2351 if (unlikely(ret
!= 0)) {
2352 DRM_ERROR("Failed to get rects.\n");
2357 for (i
= 0; i
< arg
->num_outputs
; ++i
) {
2358 if (rects
[i
].x
< 0 ||
2360 rects
[i
].x
+ rects
[i
].w
> mode_config
->max_width
||
2361 rects
[i
].y
+ rects
[i
].h
> mode_config
->max_height
) {
2362 DRM_ERROR("Invalid GUI layout.\n");
2368 * bounding_box.w and bunding_box.h are used as
2369 * lower-right coordinates
2371 if (rects
[i
].x
+ rects
[i
].w
> bounding_box
.w
)
2372 bounding_box
.w
= rects
[i
].x
+ rects
[i
].w
;
2374 if (rects
[i
].y
+ rects
[i
].h
> bounding_box
.h
)
2375 bounding_box
.h
= rects
[i
].y
+ rects
[i
].h
;
2377 total_pixels
+= (u64
) rects
[i
].w
* (u64
) rects
[i
].h
;
2380 if (dev_priv
->active_display_unit
== vmw_du_screen_target
) {
2382 * For Screen Targets, the limits for a toplogy are:
2383 * 1. Bounding box (assuming 32bpp) must be < prim_bb_mem
2384 * 2. Total pixels (assuming 32bpp) must be < prim_bb_mem
2386 u64 bb_mem
= (u64
) bounding_box
.w
* bounding_box
.h
* 4;
2387 u64 pixel_mem
= total_pixels
* 4;
2389 if (bb_mem
> dev_priv
->prim_bb_mem
) {
2390 DRM_ERROR("Topology is beyond supported limits.\n");
2395 if (pixel_mem
> dev_priv
->prim_bb_mem
) {
2396 DRM_ERROR("Combined output size too large\n");
2402 vmw_du_update_layout(dev_priv
, arg
->num_outputs
, rects
);
2410 * vmw_kms_helper_dirty - Helper to build commands and perform actions based
2411 * on a set of cliprects and a set of display units.
2413 * @dev_priv: Pointer to a device private structure.
2414 * @framebuffer: Pointer to the framebuffer on which to perform the actions.
2415 * @clips: A set of struct drm_clip_rect. Either this os @vclips must be NULL.
2416 * Cliprects are given in framebuffer coordinates.
2417 * @vclips: A set of struct drm_vmw_rect cliprects. Either this or @clips must
2418 * be NULL. Cliprects are given in source coordinates.
2419 * @dest_x: X coordinate offset for the crtc / destination clip rects.
2420 * @dest_y: Y coordinate offset for the crtc / destination clip rects.
2421 * @num_clips: Number of cliprects in the @clips or @vclips array.
2422 * @increment: Integer with which to increment the clip counter when looping.
2423 * Used to skip a predetermined number of clip rects.
2424 * @dirty: Closure structure. See the description of struct vmw_kms_dirty.
2426 int vmw_kms_helper_dirty(struct vmw_private
*dev_priv
,
2427 struct vmw_framebuffer
*framebuffer
,
2428 const struct drm_clip_rect
*clips
,
2429 const struct drm_vmw_rect
*vclips
,
2430 s32 dest_x
, s32 dest_y
,
2433 struct vmw_kms_dirty
*dirty
)
2435 struct vmw_display_unit
*units
[VMWGFX_NUM_DISPLAY_UNITS
];
2436 struct drm_crtc
*crtc
;
2440 dirty
->dev_priv
= dev_priv
;
2442 list_for_each_entry(crtc
, &dev_priv
->dev
->mode_config
.crtc_list
, head
) {
2443 if (crtc
->primary
->fb
!= &framebuffer
->base
)
2445 units
[num_units
++] = vmw_crtc_to_du(crtc
);
2448 for (k
= 0; k
< num_units
; k
++) {
2449 struct vmw_display_unit
*unit
= units
[k
];
2450 s32 crtc_x
= unit
->crtc
.x
;
2451 s32 crtc_y
= unit
->crtc
.y
;
2452 s32 crtc_width
= unit
->crtc
.mode
.hdisplay
;
2453 s32 crtc_height
= unit
->crtc
.mode
.vdisplay
;
2454 const struct drm_clip_rect
*clips_ptr
= clips
;
2455 const struct drm_vmw_rect
*vclips_ptr
= vclips
;
2458 if (dirty
->fifo_reserve_size
> 0) {
2459 dirty
->cmd
= vmw_fifo_reserve(dev_priv
,
2460 dirty
->fifo_reserve_size
);
2462 DRM_ERROR("Couldn't reserve fifo space "
2463 "for dirty blits.\n");
2466 memset(dirty
->cmd
, 0, dirty
->fifo_reserve_size
);
2468 dirty
->num_hits
= 0;
2469 for (i
= 0; i
< num_clips
; i
++, clips_ptr
+= increment
,
2470 vclips_ptr
+= increment
) {
2475 * Select clip array type. Note that integer type
2476 * in @clips is unsigned short, whereas in @vclips
2480 dirty
->fb_x
= (s32
) clips_ptr
->x1
;
2481 dirty
->fb_y
= (s32
) clips_ptr
->y1
;
2482 dirty
->unit_x2
= (s32
) clips_ptr
->x2
+ dest_x
-
2484 dirty
->unit_y2
= (s32
) clips_ptr
->y2
+ dest_y
-
2487 dirty
->fb_x
= vclips_ptr
->x
;
2488 dirty
->fb_y
= vclips_ptr
->y
;
2489 dirty
->unit_x2
= dirty
->fb_x
+ vclips_ptr
->w
+
2491 dirty
->unit_y2
= dirty
->fb_y
+ vclips_ptr
->h
+
2495 dirty
->unit_x1
= dirty
->fb_x
+ dest_x
- crtc_x
;
2496 dirty
->unit_y1
= dirty
->fb_y
+ dest_y
- crtc_y
;
2498 /* Skip this clip if it's outside the crtc region */
2499 if (dirty
->unit_x1
>= crtc_width
||
2500 dirty
->unit_y1
>= crtc_height
||
2501 dirty
->unit_x2
<= 0 || dirty
->unit_y2
<= 0)
2504 /* Clip right and bottom to crtc limits */
2505 dirty
->unit_x2
= min_t(s32
, dirty
->unit_x2
,
2507 dirty
->unit_y2
= min_t(s32
, dirty
->unit_y2
,
2510 /* Clip left and top to crtc limits */
2511 clip_left
= min_t(s32
, dirty
->unit_x1
, 0);
2512 clip_top
= min_t(s32
, dirty
->unit_y1
, 0);
2513 dirty
->unit_x1
-= clip_left
;
2514 dirty
->unit_y1
-= clip_top
;
2515 dirty
->fb_x
-= clip_left
;
2516 dirty
->fb_y
-= clip_top
;
2521 dirty
->fifo_commit(dirty
);
2528 * vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before
2529 * command submission.
2531 * @dev_priv. Pointer to a device private structure.
2532 * @buf: The buffer object
2533 * @interruptible: Whether to perform waits as interruptible.
2534 * @validate_as_mob: Whether the buffer should be validated as a MOB. If false,
2535 * The buffer will be validated as a GMR. Already pinned buffers will not be
2538 * Returns 0 on success, negative error code on failure, -ERESTARTSYS if
2539 * interrupted by a signal.
2541 int vmw_kms_helper_buffer_prepare(struct vmw_private
*dev_priv
,
2542 struct vmw_dma_buffer
*buf
,
2544 bool validate_as_mob
)
2546 struct ttm_buffer_object
*bo
= &buf
->base
;
2549 ttm_bo_reserve(bo
, false, false, NULL
);
2550 ret
= vmw_validate_single_buffer(dev_priv
, bo
, interruptible
,
2553 ttm_bo_unreserve(bo
);
2559 * vmw_kms_helper_buffer_revert - Undo the actions of
2560 * vmw_kms_helper_buffer_prepare.
2562 * @res: Pointer to the buffer object.
2564 * Helper to be used if an error forces the caller to undo the actions of
2565 * vmw_kms_helper_buffer_prepare.
2567 void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer
*buf
)
2570 ttm_bo_unreserve(&buf
->base
);
2574 * vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after
2575 * kms command submission.
2577 * @dev_priv: Pointer to a device private structure.
2578 * @file_priv: Pointer to a struct drm_file representing the caller's
2579 * connection. Must be set to NULL if @user_fence_rep is NULL, and conversely
2580 * if non-NULL, @user_fence_rep must be non-NULL.
2581 * @buf: The buffer object.
2582 * @out_fence: Optional pointer to a fence pointer. If non-NULL, a
2583 * ref-counted fence pointer is returned here.
2584 * @user_fence_rep: Optional pointer to a user-space provided struct
2585 * drm_vmw_fence_rep. If provided, @file_priv must also be provided and the
2586 * function copies fence data to user-space in a fail-safe manner.
2588 void vmw_kms_helper_buffer_finish(struct vmw_private
*dev_priv
,
2589 struct drm_file
*file_priv
,
2590 struct vmw_dma_buffer
*buf
,
2591 struct vmw_fence_obj
**out_fence
,
2592 struct drm_vmw_fence_rep __user
*
2595 struct vmw_fence_obj
*fence
;
2599 ret
= vmw_execbuf_fence_commands(file_priv
, dev_priv
, &fence
,
2600 file_priv
? &handle
: NULL
);
2602 vmw_fence_single_bo(&buf
->base
, fence
);
2604 vmw_execbuf_copy_fence_user(dev_priv
, vmw_fpriv(file_priv
),
2605 ret
, user_fence_rep
, fence
,
2610 vmw_fence_obj_unreference(&fence
);
2612 vmw_kms_helper_buffer_revert(buf
);
2617 * vmw_kms_helper_resource_revert - Undo the actions of
2618 * vmw_kms_helper_resource_prepare.
2620 * @res: Pointer to the resource. Typically a surface.
2622 * Helper to be used if an error forces the caller to undo the actions of
2623 * vmw_kms_helper_resource_prepare.
2625 void vmw_kms_helper_resource_revert(struct vmw_resource
*res
)
2627 vmw_kms_helper_buffer_revert(res
->backup
);
2628 vmw_resource_unreserve(res
, false, NULL
, 0);
2629 mutex_unlock(&res
->dev_priv
->cmdbuf_mutex
);
2633 * vmw_kms_helper_resource_prepare - Reserve and validate a resource before
2634 * command submission.
2636 * @res: Pointer to the resource. Typically a surface.
2637 * @interruptible: Whether to perform waits as interruptible.
2639 * Reserves and validates also the backup buffer if a guest-backed resource.
2640 * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
2641 * interrupted by a signal.
2643 int vmw_kms_helper_resource_prepare(struct vmw_resource
*res
,
2649 ret
= mutex_lock_interruptible(&res
->dev_priv
->cmdbuf_mutex
);
2651 mutex_lock(&res
->dev_priv
->cmdbuf_mutex
);
2653 if (unlikely(ret
!= 0))
2654 return -ERESTARTSYS
;
2656 ret
= vmw_resource_reserve(res
, interruptible
, false);
2661 ret
= vmw_kms_helper_buffer_prepare(res
->dev_priv
, res
->backup
,
2663 res
->dev_priv
->has_mob
);
2667 ret
= vmw_resource_validate(res
);
2673 vmw_kms_helper_buffer_revert(res
->backup
);
2675 vmw_resource_unreserve(res
, false, NULL
, 0);
2677 mutex_unlock(&res
->dev_priv
->cmdbuf_mutex
);
2682 * vmw_kms_helper_resource_finish - Unreserve and fence a resource after
2683 * kms command submission.
2685 * @res: Pointer to the resource. Typically a surface.
2686 * @out_fence: Optional pointer to a fence pointer. If non-NULL, a
2687 * ref-counted fence pointer is returned here.
2689 void vmw_kms_helper_resource_finish(struct vmw_resource
*res
,
2690 struct vmw_fence_obj
**out_fence
)
2692 if (res
->backup
|| out_fence
)
2693 vmw_kms_helper_buffer_finish(res
->dev_priv
, NULL
, res
->backup
,
2696 vmw_resource_unreserve(res
, false, NULL
, 0);
2697 mutex_unlock(&res
->dev_priv
->cmdbuf_mutex
);
2701 * vmw_kms_update_proxy - Helper function to update a proxy surface from
2704 * @res: Pointer to the surface resource
2705 * @clips: Clip rects in framebuffer (surface) space.
2706 * @num_clips: Number of clips in @clips.
2707 * @increment: Integer with which to increment the clip counter when looping.
2708 * Used to skip a predetermined number of clip rects.
2710 * This function makes sure the proxy surface is updated from its backing MOB
2711 * using the region given by @clips. The surface resource @res and its backing
2712 * MOB needs to be reserved and validated on call.
2714 int vmw_kms_update_proxy(struct vmw_resource
*res
,
2715 const struct drm_clip_rect
*clips
,
2719 struct vmw_private
*dev_priv
= res
->dev_priv
;
2720 struct drm_vmw_size
*size
= &vmw_res_to_srf(res
)->base_size
;
2722 SVGA3dCmdHeader header
;
2723 SVGA3dCmdUpdateGBImage body
;
2726 size_t copy_size
= 0;
2732 cmd
= vmw_fifo_reserve(dev_priv
, sizeof(*cmd
) * num_clips
);
2734 DRM_ERROR("Couldn't reserve fifo space for proxy surface "
2739 for (i
= 0; i
< num_clips
; ++i
, clips
+= increment
, ++cmd
) {
2740 box
= &cmd
->body
.box
;
2742 cmd
->header
.id
= SVGA_3D_CMD_UPDATE_GB_IMAGE
;
2743 cmd
->header
.size
= sizeof(cmd
->body
);
2744 cmd
->body
.image
.sid
= res
->id
;
2745 cmd
->body
.image
.face
= 0;
2746 cmd
->body
.image
.mipmap
= 0;
2748 if (clips
->x1
> size
->width
|| clips
->x2
> size
->width
||
2749 clips
->y1
> size
->height
|| clips
->y2
> size
->height
) {
2750 DRM_ERROR("Invalid clips outsize of framebuffer.\n");
2757 box
->w
= clips
->x2
- clips
->x1
;
2758 box
->h
= clips
->y2
- clips
->y1
;
2761 copy_size
+= sizeof(*cmd
);
2764 vmw_fifo_commit(dev_priv
, copy_size
);
2769 int vmw_kms_fbdev_init_data(struct vmw_private
*dev_priv
,
2773 struct drm_connector
**p_con
,
2774 struct drm_crtc
**p_crtc
,
2775 struct drm_display_mode
**p_mode
)
2777 struct drm_connector
*con
;
2778 struct vmw_display_unit
*du
;
2779 struct drm_display_mode
*mode
;
2782 list_for_each_entry(con
, &dev_priv
->dev
->mode_config
.connector_list
,
2791 DRM_ERROR("Could not find initial display unit.\n");
2795 if (list_empty(&con
->modes
))
2796 (void) vmw_du_connector_fill_modes(con
, max_width
, max_height
);
2798 if (list_empty(&con
->modes
)) {
2799 DRM_ERROR("Could not find initial display mode.\n");
2803 du
= vmw_connector_to_du(con
);
2805 *p_crtc
= &du
->crtc
;
2807 list_for_each_entry(mode
, &con
->modes
, head
) {
2808 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
)
2812 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
)
2815 WARN_ONCE(true, "Could not find initial preferred mode.\n");
2816 *p_mode
= list_first_entry(&con
->modes
,
2817 struct drm_display_mode
,
2825 * vmw_kms_del_active - unregister a crtc binding to the implicit framebuffer
2827 * @dev_priv: Pointer to a device private struct.
2828 * @du: The display unit of the crtc.
2830 void vmw_kms_del_active(struct vmw_private
*dev_priv
,
2831 struct vmw_display_unit
*du
)
2833 mutex_lock(&dev_priv
->global_kms_state_mutex
);
2834 if (du
->active_implicit
) {
2835 if (--(dev_priv
->num_implicit
) == 0)
2836 dev_priv
->implicit_fb
= NULL
;
2837 du
->active_implicit
= false;
2839 mutex_unlock(&dev_priv
->global_kms_state_mutex
);
2843 * vmw_kms_add_active - register a crtc binding to an implicit framebuffer
2845 * @vmw_priv: Pointer to a device private struct.
2846 * @du: The display unit of the crtc.
2847 * @vfb: The implicit framebuffer
2849 * Registers a binding to an implicit framebuffer.
2851 void vmw_kms_add_active(struct vmw_private
*dev_priv
,
2852 struct vmw_display_unit
*du
,
2853 struct vmw_framebuffer
*vfb
)
2855 mutex_lock(&dev_priv
->global_kms_state_mutex
);
2856 WARN_ON_ONCE(!dev_priv
->num_implicit
&& dev_priv
->implicit_fb
);
2858 if (!du
->active_implicit
&& du
->is_implicit
) {
2859 dev_priv
->implicit_fb
= vfb
;
2860 du
->active_implicit
= true;
2861 dev_priv
->num_implicit
++;
2863 mutex_unlock(&dev_priv
->global_kms_state_mutex
);
2867 * vmw_kms_screen_object_flippable - Check whether we can page-flip a crtc.
2869 * @dev_priv: Pointer to device-private struct.
2870 * @crtc: The crtc we want to flip.
2872 * Returns true or false depending whether it's OK to flip this crtc
2873 * based on the criterion that we must not have more than one implicit
2874 * frame-buffer at any one time.
2876 bool vmw_kms_crtc_flippable(struct vmw_private
*dev_priv
,
2877 struct drm_crtc
*crtc
)
2879 struct vmw_display_unit
*du
= vmw_crtc_to_du(crtc
);
2882 mutex_lock(&dev_priv
->global_kms_state_mutex
);
2883 ret
= !du
->is_implicit
|| dev_priv
->num_implicit
== 1;
2884 mutex_unlock(&dev_priv
->global_kms_state_mutex
);
2890 * vmw_kms_update_implicit_fb - Update the implicit fb.
2892 * @dev_priv: Pointer to device-private struct.
2893 * @crtc: The crtc the new implicit frame-buffer is bound to.
2895 void vmw_kms_update_implicit_fb(struct vmw_private
*dev_priv
,
2896 struct drm_crtc
*crtc
)
2898 struct vmw_display_unit
*du
= vmw_crtc_to_du(crtc
);
2899 struct vmw_framebuffer
*vfb
;
2901 mutex_lock(&dev_priv
->global_kms_state_mutex
);
2903 if (!du
->is_implicit
)
2906 vfb
= vmw_framebuffer_to_vfb(crtc
->primary
->fb
);
2907 WARN_ON_ONCE(dev_priv
->num_implicit
!= 1 &&
2908 dev_priv
->implicit_fb
!= vfb
);
2910 dev_priv
->implicit_fb
= vfb
;
2912 mutex_unlock(&dev_priv
->global_kms_state_mutex
);
2916 * vmw_kms_create_implicit_placement_proparty - Set up the implicit placement
2919 * @dev_priv: Pointer to a device private struct.
2920 * @immutable: Whether the property is immutable.
2922 * Sets up the implicit placement property unless it's already set up.
2925 vmw_kms_create_implicit_placement_property(struct vmw_private
*dev_priv
,
2928 if (dev_priv
->implicit_placement_property
)
2931 dev_priv
->implicit_placement_property
=
2932 drm_property_create_range(dev_priv
->dev
,
2934 DRM_MODE_PROP_IMMUTABLE
: 0,
2935 "implicit_placement", 0, 1);
2941 * vmw_kms_set_config - Wrapper around drm_atomic_helper_set_config
2943 * @set: The configuration to set.
2945 * The vmwgfx Xorg driver doesn't assign the mode::type member, which
2946 * when drm_mode_set_crtcinfo is called as part of the configuration setting
2947 * causes it to return incorrect crtc dimensions causing severe problems in
2948 * the vmwgfx modesetting. So explicitly clear that member before calling
2949 * into drm_atomic_helper_set_config.
2951 int vmw_kms_set_config(struct drm_mode_set
*set
,
2952 struct drm_modeset_acquire_ctx
*ctx
)
2954 if (set
&& set
->mode
)
2955 set
->mode
->type
= 0;
2957 return drm_atomic_helper_set_config(set
, ctx
);