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 **************************************************************************/
32 #include <drm/drm_crtc_helper.h>
33 #include <drm/drm_encoder.h>
34 #include "vmwgfx_drv.h"
39 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
42 * @fifo_commit: Callback that is called once for each display unit after
43 * all clip rects. This function must commit the fifo space reserved by the
44 * helper. Set up by the caller.
45 * @clip: Callback that is called for each cliprect on each display unit.
46 * Set up by the caller.
47 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
48 * each display unit. Set up by the caller.
49 * @dev_priv: Pointer to the device private. Set up by the helper.
50 * @unit: The current display unit. Set up by the helper before a call to @clip.
51 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
53 * @num_hits: Number of clip rect commands for this display unit.
54 * Cleared by the helper before the first @clip call. Updated by the @clip
56 * @fb_x: Clip rect left side in framebuffer coordinates.
57 * @fb_y: Clip rect right side in framebuffer coordinates.
58 * @unit_x1: Clip rect left side in crtc coordinates.
59 * @unit_y1: Clip rect top side in crtc coordinates.
60 * @unit_x2: Clip rect right side in crtc coordinates.
61 * @unit_y2: Clip rect bottom side in crtc coordinates.
63 * The clip rect coordinates are updated by the helper for each @clip call.
64 * Note that this may be derived from if more info needs to be passed between
65 * helper caller and helper callbacks.
67 struct vmw_kms_dirty {
68 void (*fifo_commit)(struct vmw_kms_dirty *);
69 void (*clip)(struct vmw_kms_dirty *);
70 size_t fifo_reserve_size;
71 struct vmw_private *dev_priv;
72 struct vmw_display_unit *unit;
83 #define VMWGFX_NUM_DISPLAY_UNITS 8
86 #define vmw_framebuffer_to_vfb(x) \
87 container_of(x, struct vmw_framebuffer, base)
88 #define vmw_framebuffer_to_vfbs(x) \
89 container_of(x, struct vmw_framebuffer_surface, base.base)
90 #define vmw_framebuffer_to_vfbd(x) \
91 container_of(x, struct vmw_framebuffer_dmabuf, base.base)
94 * Base class for framebuffers
96 * @pin is called the when ever a crtc uses this framebuffer
99 struct vmw_framebuffer {
100 struct drm_framebuffer base;
101 int (*pin)(struct vmw_framebuffer *fb);
102 int (*unpin)(struct vmw_framebuffer *fb);
104 struct ttm_base_object *user_obj;
105 uint32_t user_handle;
111 struct vmw_clip_rect {
115 struct vmw_framebuffer_surface {
116 struct vmw_framebuffer base;
117 struct vmw_surface *surface;
118 struct vmw_dma_buffer *buffer;
119 struct list_head head;
120 bool is_dmabuf_proxy; /* true if this is proxy surface for DMA buf */
124 struct vmw_framebuffer_dmabuf {
125 struct vmw_framebuffer base;
126 struct vmw_dma_buffer *buffer;
130 static const uint32_t vmw_primary_plane_formats[] = {
138 static const uint32_t vmw_cursor_plane_formats[] = {
143 #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
144 #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
145 #define vmw_connector_state_to_vcs(x) \
146 container_of(x, struct vmw_connector_state, base)
149 * Derived class for crtc state object
151 * @base DRM crtc object
153 struct vmw_crtc_state {
154 struct drm_crtc_state base;
158 * Derived class for plane state object
160 * @base DRM plane object
161 * @surf Display surface for STDU
162 * @dmabuf display dmabuf for SOU
163 * @content_fb_type Used by STDU.
164 * @dmabuf_size Size of the dmabuf, used by Screen Object Display Unit
165 * @pinned pin count for STDU display surface
167 struct vmw_plane_state {
168 struct drm_plane_state base;
169 struct vmw_surface *surf;
170 struct vmw_dma_buffer *dmabuf;
173 unsigned long dmabuf_size;
178 struct ttm_bo_kmap_obj host_map;
184 * Derived class for connector state object
186 * @base DRM connector object
187 * @is_implicit connector property
190 struct vmw_connector_state {
191 struct drm_connector_state base;
197 * Base class display unit.
199 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
200 * so the display unit is all of them at the same time. This is true for both
201 * legacy multimon and screen objects.
203 struct vmw_display_unit {
204 struct drm_crtc crtc;
205 struct drm_encoder encoder;
206 struct drm_connector connector;
207 struct drm_plane primary;
208 struct drm_plane cursor;
210 struct vmw_surface *cursor_surface;
211 struct vmw_dma_buffer *cursor_dmabuf;
225 * Prefered mode tracking.
228 unsigned pref_height;
230 struct drm_display_mode *pref_mode;
238 bool active_implicit;
243 struct vmw_validation_ctx {
244 struct vmw_resource *res;
245 struct vmw_dma_buffer *buf;
248 #define vmw_crtc_to_du(x) \
249 container_of(x, struct vmw_display_unit, crtc)
250 #define vmw_connector_to_du(x) \
251 container_of(x, struct vmw_display_unit, connector)
255 * Shared display unit functions - vmwgfx_kms.c
257 void vmw_du_cleanup(struct vmw_display_unit *du);
258 void vmw_du_crtc_save(struct drm_crtc *crtc);
259 void vmw_du_crtc_restore(struct drm_crtc *crtc);
260 int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
261 u16 *r, u16 *g, u16 *b,
263 struct drm_modeset_acquire_ctx *ctx);
264 int vmw_du_connector_set_property(struct drm_connector *connector,
265 struct drm_property *property,
267 int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
268 struct drm_connector_state *state,
269 struct drm_property *property,
272 vmw_du_connector_atomic_get_property(struct drm_connector *connector,
273 const struct drm_connector_state *state,
274 struct drm_property *property,
276 int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
277 void vmw_du_connector_save(struct drm_connector *connector);
278 void vmw_du_connector_restore(struct drm_connector *connector);
279 enum drm_connector_status
280 vmw_du_connector_detect(struct drm_connector *connector, bool force);
281 int vmw_du_connector_fill_modes(struct drm_connector *connector,
282 uint32_t max_width, uint32_t max_height);
283 int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
284 struct vmw_framebuffer *framebuffer,
285 const struct drm_clip_rect *clips,
286 const struct drm_vmw_rect *vclips,
287 s32 dest_x, s32 dest_y,
290 struct vmw_kms_dirty *dirty);
292 int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
293 struct vmw_dma_buffer *buf,
295 bool validate_as_mob);
296 void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
297 void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
298 struct drm_file *file_priv,
299 struct vmw_dma_buffer *buf,
300 struct vmw_fence_obj **out_fence,
301 struct drm_vmw_fence_rep __user *
303 int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
305 struct vmw_validation_ctx *ctx);
306 void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx);
307 void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
308 struct vmw_fence_obj **out_fence);
309 int vmw_kms_readback(struct vmw_private *dev_priv,
310 struct drm_file *file_priv,
311 struct vmw_framebuffer *vfb,
312 struct drm_vmw_fence_rep __user *user_fence_rep,
313 struct drm_vmw_rect *vclips,
315 struct vmw_framebuffer *
316 vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
317 struct vmw_dma_buffer *dmabuf,
318 struct vmw_surface *surface,
320 const struct drm_mode_fb_cmd2 *mode_cmd);
321 int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
325 struct drm_connector **p_con,
326 struct drm_crtc **p_crtc,
327 struct drm_display_mode **p_mode);
328 void vmw_guess_mode_timing(struct drm_display_mode *mode);
329 void vmw_kms_del_active(struct vmw_private *dev_priv,
330 struct vmw_display_unit *du);
331 void vmw_kms_add_active(struct vmw_private *dev_priv,
332 struct vmw_display_unit *du,
333 struct vmw_framebuffer *vfb);
334 bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
335 struct drm_crtc *crtc);
336 void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
337 struct drm_crtc *crtc);
338 void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
341 /* Universal Plane Helpers */
342 void vmw_du_primary_plane_destroy(struct drm_plane *plane);
343 void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
346 int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
347 struct drm_plane_state *state);
348 int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
349 struct drm_plane_state *state);
350 void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
351 struct drm_plane_state *old_state);
352 int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
353 struct drm_plane_state *new_state);
354 void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
355 struct drm_plane_state *old_state);
356 void vmw_du_plane_reset(struct drm_plane *plane);
357 struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
358 void vmw_du_plane_destroy_state(struct drm_plane *plane,
359 struct drm_plane_state *state);
360 void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
363 int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
364 struct drm_crtc_state *state);
365 void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
366 struct drm_crtc_state *old_crtc_state);
367 void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
368 struct drm_crtc_state *old_crtc_state);
369 void vmw_du_crtc_reset(struct drm_crtc *crtc);
370 struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
371 void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
372 struct drm_crtc_state *state);
373 void vmw_du_connector_reset(struct drm_connector *connector);
374 struct drm_connector_state *
375 vmw_du_connector_duplicate_state(struct drm_connector *connector);
377 void vmw_du_connector_destroy_state(struct drm_connector *connector,
378 struct drm_connector_state *state);
381 * Legacy display unit functions - vmwgfx_ldu.c
383 int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
384 int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
385 int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
386 struct vmw_framebuffer *framebuffer,
387 unsigned flags, unsigned color,
388 struct drm_clip_rect *clips,
389 unsigned num_clips, int increment);
390 int vmw_kms_update_proxy(struct vmw_resource *res,
391 const struct drm_clip_rect *clips,
396 * Screen Objects display functions - vmwgfx_scrn.c
398 int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
399 int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
400 struct vmw_framebuffer *framebuffer,
401 struct drm_clip_rect *clips,
402 struct drm_vmw_rect *vclips,
403 struct vmw_resource *srf,
406 unsigned num_clips, int inc,
407 struct vmw_fence_obj **out_fence);
408 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
409 struct vmw_framebuffer *framebuffer,
410 struct drm_clip_rect *clips,
411 struct drm_vmw_rect *vclips,
412 unsigned num_clips, int increment,
414 struct vmw_fence_obj **out_fence);
415 int vmw_kms_sou_readback(struct vmw_private *dev_priv,
416 struct drm_file *file_priv,
417 struct vmw_framebuffer *vfb,
418 struct drm_vmw_fence_rep __user *user_fence_rep,
419 struct drm_vmw_rect *vclips,
423 * Screen Target Display Unit functions - vmwgfx_stdu.c
425 int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
426 int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
427 struct vmw_framebuffer *framebuffer,
428 struct drm_clip_rect *clips,
429 struct drm_vmw_rect *vclips,
430 struct vmw_resource *srf,
433 unsigned num_clips, int inc,
434 struct vmw_fence_obj **out_fence);
435 int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
436 struct drm_file *file_priv,
437 struct vmw_framebuffer *vfb,
438 struct drm_vmw_fence_rep __user *user_fence_rep,
439 struct drm_clip_rect *clips,
440 struct drm_vmw_rect *vclips,
446 int vmw_kms_set_config(struct drm_mode_set *set,
447 struct drm_modeset_acquire_ctx *ctx);