blob: cb36e1d70133e62486728d2d93707f0721bc6c93 [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
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -070036/**
37 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
38 * function.
39 *
40 * @fifo_commit: Callback that is called once for each display unit after
41 * all clip rects. This function must commit the fifo space reserved by the
42 * helper. Set up by the caller.
43 * @clip: Callback that is called for each cliprect on each display unit.
44 * Set up by the caller.
45 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
46 * each display unit. Set up by the caller.
47 * @dev_priv: Pointer to the device private. Set up by the helper.
48 * @unit: The current display unit. Set up by the helper before a call to @clip.
49 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
50 * call.
51 * @num_hits: Number of clip rect commands for this display unit.
52 * Cleared by the helper before the first @clip call. Updated by the @clip
53 * callback.
54 * @fb_x: Clip rect left side in framebuffer coordinates.
55 * @fb_y: Clip rect right side in framebuffer coordinates.
56 * @unit_x1: Clip rect left side in crtc coordinates.
57 * @unit_y1: Clip rect top side in crtc coordinates.
58 * @unit_x2: Clip rect right side in crtc coordinates.
59 * @unit_y2: Clip rect bottom side in crtc coordinates.
60 *
61 * The clip rect coordinates are updated by the helper for each @clip call.
62 * Note that this may be derived from if more info needs to be passed between
63 * helper caller and helper callbacks.
64 */
65struct vmw_kms_dirty {
66 void (*fifo_commit)(struct vmw_kms_dirty *);
67 void (*clip)(struct vmw_kms_dirty *);
68 size_t fifo_reserve_size;
69 struct vmw_private *dev_priv;
70 struct vmw_display_unit *unit;
71 void *cmd;
72 u32 num_hits;
73 s32 fb_x;
74 s32 fb_y;
75 s32 unit_x1;
76 s32 unit_y1;
77 s32 unit_x2;
78 s32 unit_y2;
79};
Sinclair Yehc8261a92015-06-26 01:23:42 -070080
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020081#define VMWGFX_NUM_DISPLAY_UNITS 8
82
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000083
84#define vmw_framebuffer_to_vfb(x) \
85 container_of(x, struct vmw_framebuffer, base)
Sinclair Yehc8261a92015-06-26 01:23:42 -070086#define vmw_framebuffer_to_vfbs(x) \
87 container_of(x, struct vmw_framebuffer_surface, base.base)
88#define vmw_framebuffer_to_vfbd(x) \
89 container_of(x, struct vmw_framebuffer_dmabuf, base.base)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000090
91/**
92 * Base class for framebuffers
93 *
94 * @pin is called the when ever a crtc uses this framebuffer
95 * @unpin is called
96 */
97struct vmw_framebuffer {
98 struct drm_framebuffer base;
99 int (*pin)(struct vmw_framebuffer *fb);
100 int (*unpin)(struct vmw_framebuffer *fb);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200101 bool dmabuf;
Thomas Hellstrom90ff18b2011-10-04 20:13:32 +0200102 struct ttm_base_object *user_obj;
103 uint32_t user_handle;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000104};
105
Sinclair Yehc8261a92015-06-26 01:23:42 -0700106/*
107 * Clip rectangle
108 */
109struct vmw_clip_rect {
110 int x1, x2, y1, y2;
111};
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000112
Sinclair Yehc8261a92015-06-26 01:23:42 -0700113struct vmw_framebuffer_surface {
114 struct vmw_framebuffer base;
115 struct vmw_surface *surface;
116 struct vmw_dma_buffer *buffer;
117 struct list_head head;
Sinclair Yehf89c6c32015-06-26 01:54:28 -0700118 bool is_dmabuf_proxy; /* true if this is proxy surface for DMA buf */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700119};
120
121
122struct vmw_framebuffer_dmabuf {
123 struct vmw_framebuffer base;
124 struct vmw_dma_buffer *buffer;
125};
126
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000127
128/*
129 * Basic cursor manipulation
130 */
131int vmw_cursor_update_image(struct vmw_private *dev_priv,
132 u32 *image, u32 width, u32 height,
133 u32 hotspotX, u32 hotspotY);
Jakob Bornecrantzbfc26382011-11-28 13:19:14 +0100134int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
135 struct vmw_dma_buffer *dmabuf,
136 u32 width, u32 height,
137 u32 hotspotX, u32 hotspotY);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000138void vmw_cursor_update_position(struct vmw_private *dev_priv,
139 bool show, int x, int y);
140
Jakob Bornecrantzbfc26382011-11-28 13:19:14 +0100141
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000142/**
143 * Base class display unit.
144 *
145 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
146 * so the display unit is all of them at the same time. This is true for both
147 * legacy multimon and screen objects.
148 */
149struct vmw_display_unit {
150 struct drm_crtc crtc;
151 struct drm_encoder encoder;
152 struct drm_connector connector;
153
154 struct vmw_surface *cursor_surface;
155 struct vmw_dma_buffer *cursor_dmabuf;
156 size_t cursor_age;
157
158 int cursor_x;
159 int cursor_y;
160
161 int hotspot_x;
162 int hotspot_y;
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100163 s32 core_hotspot_x;
164 s32 core_hotspot_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000165
166 unsigned unit;
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200167
168 /*
169 * Prefered mode tracking.
170 */
171 unsigned pref_width;
172 unsigned pref_height;
173 bool pref_active;
174 struct drm_display_mode *pref_mode;
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200175
176 /*
177 * Gui positioning
178 */
179 int gui_x;
180 int gui_y;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100181 bool is_implicit;
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100182 bool active_implicit;
Thomas Hellstrom6dd687b2016-02-12 09:57:15 +0100183 int set_gui_x;
184 int set_gui_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000185};
186
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200187#define vmw_crtc_to_du(x) \
188 container_of(x, struct vmw_display_unit, crtc)
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200189#define vmw_connector_to_du(x) \
190 container_of(x, struct vmw_display_unit, connector)
191
192
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000193/*
194 * Shared display unit functions - vmwgfx_kms.c
195 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700196void vmw_du_cleanup(struct vmw_display_unit *du);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200197void vmw_du_crtc_save(struct drm_crtc *crtc);
198void vmw_du_crtc_restore(struct drm_crtc *crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200199int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200200 u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200201 uint32_t size);
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100202int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
203 uint32_t handle, uint32_t width, uint32_t height,
204 int32_t hot_x, int32_t hot_y);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000205int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200206int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200207void vmw_du_connector_save(struct drm_connector *connector);
208void vmw_du_connector_restore(struct drm_connector *connector);
209enum drm_connector_status
210vmw_du_connector_detect(struct drm_connector *connector, bool force);
211int vmw_du_connector_fill_modes(struct drm_connector *connector,
212 uint32_t max_width, uint32_t max_height);
213int vmw_du_connector_set_property(struct drm_connector *connector,
214 struct drm_property *property,
215 uint64_t val);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700216int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
217 struct vmw_framebuffer *framebuffer,
218 const struct drm_clip_rect *clips,
219 const struct drm_vmw_rect *vclips,
220 s32 dest_x, s32 dest_y,
221 int num_clips,
222 int increment,
223 struct vmw_kms_dirty *dirty);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200224
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700225int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
226 struct vmw_dma_buffer *buf,
227 bool interruptible,
228 bool validate_as_mob);
229void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
230void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
231 struct drm_file *file_priv,
232 struct vmw_dma_buffer *buf,
233 struct vmw_fence_obj **out_fence,
234 struct drm_vmw_fence_rep __user *
235 user_fence_rep);
236int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
237 bool interruptible);
238void vmw_kms_helper_resource_revert(struct vmw_resource *res);
239void vmw_kms_helper_resource_finish(struct vmw_resource *res,
240 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700241int vmw_kms_readback(struct vmw_private *dev_priv,
242 struct drm_file *file_priv,
243 struct vmw_framebuffer *vfb,
244 struct drm_vmw_fence_rep __user *user_fence_rep,
245 struct drm_vmw_rect *vclips,
246 uint32_t num_clips);
Thomas Hellstromfd006a42015-06-28 02:50:56 -0700247struct vmw_framebuffer *
248vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
249 struct vmw_dma_buffer *dmabuf,
250 struct vmw_surface *surface,
251 bool only_2d,
Daniel Vetterdabdcdc2016-12-02 08:07:40 +0100252 const struct drm_mode_fb_cmd2 *mode_cmd);
Thomas Hellstroma2787242015-06-29 12:55:07 -0700253int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
254 unsigned unit,
255 u32 max_width,
256 u32 max_height,
257 struct drm_connector **p_con,
258 struct drm_crtc **p_crtc,
259 struct drm_display_mode **p_mode);
260void vmw_guess_mode_timing(struct drm_display_mode *mode);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100261void vmw_kms_del_active(struct vmw_private *dev_priv,
262 struct vmw_display_unit *du);
263void vmw_kms_add_active(struct vmw_private *dev_priv,
264 struct vmw_display_unit *du,
265 struct vmw_framebuffer *vfb);
266bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
267 struct drm_crtc *crtc);
268void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
269 struct drm_crtc *crtc);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100270void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
271 bool immutable);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100272
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000273
274/*
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200275 * Legacy display unit functions - vmwgfx_ldu.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000276 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700277int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
278int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
279int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
280 struct vmw_framebuffer *framebuffer,
281 unsigned flags, unsigned color,
282 struct drm_clip_rect *clips,
283 unsigned num_clips, int increment);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700284int vmw_kms_update_proxy(struct vmw_resource *res,
285 const struct drm_clip_rect *clips,
286 unsigned num_clips,
287 int increment);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000288
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200289/*
290 * Screen Objects display functions - vmwgfx_scrn.c
291 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700292int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
293int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
294int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700295 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700296 struct drm_clip_rect *clips,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700297 struct drm_vmw_rect *vclips,
298 struct vmw_resource *srf,
299 s32 dest_x,
300 s32 dest_y,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700301 unsigned num_clips, int inc,
302 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700303int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700304 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700305 struct drm_clip_rect *clips,
Thomas Hellstrom897b8182016-02-12 08:32:08 +0100306 struct drm_vmw_rect *vclips,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700307 unsigned num_clips, int increment,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700308 bool interruptible,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700309 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700310int vmw_kms_sou_readback(struct vmw_private *dev_priv,
311 struct drm_file *file_priv,
312 struct vmw_framebuffer *vfb,
313 struct drm_vmw_fence_rep __user *user_fence_rep,
314 struct drm_vmw_rect *vclips,
315 uint32_t num_clips);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700316
317/*
318 * Screen Target Display Unit functions - vmwgfx_stdu.c
319 */
320int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
321int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700322int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
323 struct vmw_framebuffer *framebuffer,
324 struct drm_clip_rect *clips,
325 struct drm_vmw_rect *vclips,
326 struct vmw_resource *srf,
327 s32 dest_x,
328 s32 dest_y,
329 unsigned num_clips, int inc,
330 struct vmw_fence_obj **out_fence);
331int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
332 struct drm_file *file_priv,
333 struct vmw_framebuffer *vfb,
334 struct drm_vmw_fence_rep __user *user_fence_rep,
335 struct drm_clip_rect *clips,
336 struct drm_vmw_rect *vclips,
337 uint32_t num_clips,
338 int increment,
339 bool to_surface,
340 bool interruptible);
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100341
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200342
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000343#endif