blob: 370f75c95f5635c7123d6f912b268c22c3425150 [file] [log] [blame]
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001/**************************************************************************
2 *
Sinclair Yeh54fbde82015-07-29 12:38:02 -07003 * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00004 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28#ifndef VMWGFX_KMS_H_
29#define VMWGFX_KMS_H_
30
David Howells760285e2012-10-02 18:01:07 +010031#include <drm/drmP.h>
32#include <drm/drm_crtc_helper.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020033#include <drm/drm_encoder.h>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000034#include "vmwgfx_drv.h"
35
Sinclair Yeh36cc79b2017-03-23 11:28:11 -070036
37
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -070038/**
39 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
40 * function.
41 *
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
52 * call.
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
55 * callback.
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.
62 *
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.
66 */
67struct 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;
73 void *cmd;
74 u32 num_hits;
75 s32 fb_x;
76 s32 fb_y;
77 s32 unit_x1;
78 s32 unit_y1;
79 s32 unit_x2;
80 s32 unit_y2;
81};
Sinclair Yehc8261a92015-06-26 01:23:42 -070082
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020083#define VMWGFX_NUM_DISPLAY_UNITS 8
84
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000085
86#define vmw_framebuffer_to_vfb(x) \
87 container_of(x, struct vmw_framebuffer, base)
Sinclair Yehc8261a92015-06-26 01:23:42 -070088#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)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000092
93/**
94 * Base class for framebuffers
95 *
96 * @pin is called the when ever a crtc uses this framebuffer
97 * @unpin is called
98 */
99struct vmw_framebuffer {
100 struct drm_framebuffer base;
101 int (*pin)(struct vmw_framebuffer *fb);
102 int (*unpin)(struct vmw_framebuffer *fb);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200103 bool dmabuf;
Thomas Hellstrom90ff18b2011-10-04 20:13:32 +0200104 struct ttm_base_object *user_obj;
105 uint32_t user_handle;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000106};
107
Sinclair Yehc8261a92015-06-26 01:23:42 -0700108/*
109 * Clip rectangle
110 */
111struct vmw_clip_rect {
112 int x1, x2, y1, y2;
113};
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000114
Sinclair Yehc8261a92015-06-26 01:23:42 -0700115struct vmw_framebuffer_surface {
116 struct vmw_framebuffer base;
117 struct vmw_surface *surface;
118 struct vmw_dma_buffer *buffer;
119 struct list_head head;
Sinclair Yehf89c6c32015-06-26 01:54:28 -0700120 bool is_dmabuf_proxy; /* true if this is proxy surface for DMA buf */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700121};
122
123
124struct vmw_framebuffer_dmabuf {
125 struct vmw_framebuffer base;
126 struct vmw_dma_buffer *buffer;
127};
128
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000129
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700130static const uint32_t vmw_primary_plane_formats[] = {
131 DRM_FORMAT_XRGB1555,
132 DRM_FORMAT_RGB565,
133 DRM_FORMAT_RGB888,
134 DRM_FORMAT_XRGB8888,
135 DRM_FORMAT_ARGB8888,
136};
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000137
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700138static const uint32_t vmw_cursor_plane_formats[] = {
139 DRM_FORMAT_ARGB8888,
140};
Jakob Bornecrantzbfc26382011-11-28 13:19:14 +0100141
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700142
143#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
144
145
146/**
147 * Derived class for crtc state object
148 *
149 * @base DRM crtc object
150 */
151struct vmw_crtc_state {
152 struct drm_crtc_state base;
153};
154
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000155/**
156 * Base class display unit.
157 *
158 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
159 * so the display unit is all of them at the same time. This is true for both
160 * legacy multimon and screen objects.
161 */
162struct vmw_display_unit {
163 struct drm_crtc crtc;
164 struct drm_encoder encoder;
165 struct drm_connector connector;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700166 struct drm_plane primary;
167 struct drm_plane cursor;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000168
169 struct vmw_surface *cursor_surface;
170 struct vmw_dma_buffer *cursor_dmabuf;
171 size_t cursor_age;
172
173 int cursor_x;
174 int cursor_y;
175
176 int hotspot_x;
177 int hotspot_y;
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100178 s32 core_hotspot_x;
179 s32 core_hotspot_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000180
181 unsigned unit;
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200182
183 /*
184 * Prefered mode tracking.
185 */
186 unsigned pref_width;
187 unsigned pref_height;
188 bool pref_active;
189 struct drm_display_mode *pref_mode;
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200190
191 /*
192 * Gui positioning
193 */
194 int gui_x;
195 int gui_y;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100196 bool is_implicit;
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100197 bool active_implicit;
Thomas Hellstrom6dd687b2016-02-12 09:57:15 +0100198 int set_gui_x;
199 int set_gui_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000200};
201
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200202#define vmw_crtc_to_du(x) \
203 container_of(x, struct vmw_display_unit, crtc)
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200204#define vmw_connector_to_du(x) \
205 container_of(x, struct vmw_display_unit, connector)
206
207
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000208/*
209 * Shared display unit functions - vmwgfx_kms.c
210 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700211void vmw_du_cleanup(struct vmw_display_unit *du);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200212void vmw_du_crtc_save(struct drm_crtc *crtc);
213void vmw_du_crtc_restore(struct drm_crtc *crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200214int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200215 u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200216 uint32_t size);
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100217int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
218 uint32_t handle, uint32_t width, uint32_t height,
219 int32_t hot_x, int32_t hot_y);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000220int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700221int vmw_du_connector_set_property(struct drm_connector *connector,
222 struct drm_property *property,
223 uint64_t val);
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200224int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200225void vmw_du_connector_save(struct drm_connector *connector);
226void vmw_du_connector_restore(struct drm_connector *connector);
227enum drm_connector_status
228vmw_du_connector_detect(struct drm_connector *connector, bool force);
229int vmw_du_connector_fill_modes(struct drm_connector *connector,
230 uint32_t max_width, uint32_t max_height);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700231int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
232 struct vmw_framebuffer *framebuffer,
233 const struct drm_clip_rect *clips,
234 const struct drm_vmw_rect *vclips,
235 s32 dest_x, s32 dest_y,
236 int num_clips,
237 int increment,
238 struct vmw_kms_dirty *dirty);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200239
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700240int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
241 struct vmw_dma_buffer *buf,
242 bool interruptible,
243 bool validate_as_mob);
244void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
245void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
246 struct drm_file *file_priv,
247 struct vmw_dma_buffer *buf,
248 struct vmw_fence_obj **out_fence,
249 struct drm_vmw_fence_rep __user *
250 user_fence_rep);
251int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
252 bool interruptible);
253void vmw_kms_helper_resource_revert(struct vmw_resource *res);
254void vmw_kms_helper_resource_finish(struct vmw_resource *res,
255 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700256int vmw_kms_readback(struct vmw_private *dev_priv,
257 struct drm_file *file_priv,
258 struct vmw_framebuffer *vfb,
259 struct drm_vmw_fence_rep __user *user_fence_rep,
260 struct drm_vmw_rect *vclips,
261 uint32_t num_clips);
Thomas Hellstromfd006a42015-06-28 02:50:56 -0700262struct vmw_framebuffer *
263vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
264 struct vmw_dma_buffer *dmabuf,
265 struct vmw_surface *surface,
266 bool only_2d,
Daniel Vetterdabdcdc2016-12-02 08:07:40 +0100267 const struct drm_mode_fb_cmd2 *mode_cmd);
Thomas Hellstroma2787242015-06-29 12:55:07 -0700268int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
269 unsigned unit,
270 u32 max_width,
271 u32 max_height,
272 struct drm_connector **p_con,
273 struct drm_crtc **p_crtc,
274 struct drm_display_mode **p_mode);
275void vmw_guess_mode_timing(struct drm_display_mode *mode);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100276void vmw_kms_del_active(struct vmw_private *dev_priv,
277 struct vmw_display_unit *du);
278void vmw_kms_add_active(struct vmw_private *dev_priv,
279 struct vmw_display_unit *du,
280 struct vmw_framebuffer *vfb);
281bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
282 struct drm_crtc *crtc);
283void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
284 struct drm_crtc *crtc);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100285void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
286 bool immutable);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100287
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700288/* Universal Plane Helpers */
289void vmw_du_primary_plane_destroy(struct drm_plane *plane);
290void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
291int vmw_du_cursor_plane_disable(struct drm_plane *plane);
292int vmw_du_cursor_plane_update(struct drm_plane *plane,
293 struct drm_crtc *crtc,
294 struct drm_framebuffer *fb,
295 int crtc_x, int crtc_y,
296 unsigned int crtc_w,
297 unsigned int crtc_h,
298 uint32_t src_x, uint32_t src_y,
299 uint32_t src_w, uint32_t src_h);
300
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700301void vmw_du_crtc_reset(struct drm_crtc *crtc);
302struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
303void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
304 struct drm_crtc_state *state);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000305
306/*
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200307 * Legacy display unit functions - vmwgfx_ldu.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000308 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700309int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
310int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
311int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
312 struct vmw_framebuffer *framebuffer,
313 unsigned flags, unsigned color,
314 struct drm_clip_rect *clips,
315 unsigned num_clips, int increment);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700316int vmw_kms_update_proxy(struct vmw_resource *res,
317 const struct drm_clip_rect *clips,
318 unsigned num_clips,
319 int increment);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000320
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200321/*
322 * Screen Objects display functions - vmwgfx_scrn.c
323 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700324int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
325int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
326int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700327 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700328 struct drm_clip_rect *clips,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700329 struct drm_vmw_rect *vclips,
330 struct vmw_resource *srf,
331 s32 dest_x,
332 s32 dest_y,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700333 unsigned num_clips, int inc,
334 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700335int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700336 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700337 struct drm_clip_rect *clips,
Thomas Hellstrom897b8182016-02-12 08:32:08 +0100338 struct drm_vmw_rect *vclips,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700339 unsigned num_clips, int increment,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700340 bool interruptible,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700341 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700342int vmw_kms_sou_readback(struct vmw_private *dev_priv,
343 struct drm_file *file_priv,
344 struct vmw_framebuffer *vfb,
345 struct drm_vmw_fence_rep __user *user_fence_rep,
346 struct drm_vmw_rect *vclips,
347 uint32_t num_clips);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700348
349/*
350 * Screen Target Display Unit functions - vmwgfx_stdu.c
351 */
352int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
353int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700354int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
355 struct vmw_framebuffer *framebuffer,
356 struct drm_clip_rect *clips,
357 struct drm_vmw_rect *vclips,
358 struct vmw_resource *srf,
359 s32 dest_x,
360 s32 dest_y,
361 unsigned num_clips, int inc,
362 struct vmw_fence_obj **out_fence);
363int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
364 struct drm_file *file_priv,
365 struct vmw_framebuffer *vfb,
366 struct drm_vmw_fence_rep __user *user_fence_rep,
367 struct drm_clip_rect *clips,
368 struct drm_vmw_rect *vclips,
369 uint32_t num_clips,
370 int increment,
371 bool to_surface,
372 bool interruptible);
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100373
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200374
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000375#endif