blob: e400bfb26167eb431b4ebe24bc636b7c3795c754 [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
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;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700153 struct drm_plane primary;
154 struct drm_plane cursor;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000155
156 struct vmw_surface *cursor_surface;
157 struct vmw_dma_buffer *cursor_dmabuf;
158 size_t cursor_age;
159
160 int cursor_x;
161 int cursor_y;
162
163 int hotspot_x;
164 int hotspot_y;
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100165 s32 core_hotspot_x;
166 s32 core_hotspot_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000167
168 unsigned unit;
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200169
170 /*
171 * Prefered mode tracking.
172 */
173 unsigned pref_width;
174 unsigned pref_height;
175 bool pref_active;
176 struct drm_display_mode *pref_mode;
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200177
178 /*
179 * Gui positioning
180 */
181 int gui_x;
182 int gui_y;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100183 bool is_implicit;
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100184 bool active_implicit;
Thomas Hellstrom6dd687b2016-02-12 09:57:15 +0100185 int set_gui_x;
186 int set_gui_y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000187};
188
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200189#define vmw_crtc_to_du(x) \
190 container_of(x, struct vmw_display_unit, crtc)
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200191#define vmw_connector_to_du(x) \
192 container_of(x, struct vmw_display_unit, connector)
193
194
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000195/*
196 * Shared display unit functions - vmwgfx_kms.c
197 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700198void vmw_du_cleanup(struct vmw_display_unit *du);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200199void vmw_du_crtc_save(struct drm_crtc *crtc);
200void vmw_du_crtc_restore(struct drm_crtc *crtc);
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200201int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200202 u16 *r, u16 *g, u16 *b,
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200203 uint32_t size);
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +0100204int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
205 uint32_t handle, uint32_t width, uint32_t height,
206 int32_t hot_x, int32_t hot_y);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000207int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200208int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200209void vmw_du_connector_save(struct drm_connector *connector);
210void vmw_du_connector_restore(struct drm_connector *connector);
211enum drm_connector_status
212vmw_du_connector_detect(struct drm_connector *connector, bool force);
213int vmw_du_connector_fill_modes(struct drm_connector *connector,
214 uint32_t max_width, uint32_t max_height);
215int vmw_du_connector_set_property(struct drm_connector *connector,
216 struct drm_property *property,
217 uint64_t val);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700218int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
219 struct vmw_framebuffer *framebuffer,
220 const struct drm_clip_rect *clips,
221 const struct drm_vmw_rect *vclips,
222 s32 dest_x, s32 dest_y,
223 int num_clips,
224 int increment,
225 struct vmw_kms_dirty *dirty);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200226
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700227int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
228 struct vmw_dma_buffer *buf,
229 bool interruptible,
230 bool validate_as_mob);
231void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
232void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
233 struct drm_file *file_priv,
234 struct vmw_dma_buffer *buf,
235 struct vmw_fence_obj **out_fence,
236 struct drm_vmw_fence_rep __user *
237 user_fence_rep);
238int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
239 bool interruptible);
240void vmw_kms_helper_resource_revert(struct vmw_resource *res);
241void vmw_kms_helper_resource_finish(struct vmw_resource *res,
242 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700243int vmw_kms_readback(struct vmw_private *dev_priv,
244 struct drm_file *file_priv,
245 struct vmw_framebuffer *vfb,
246 struct drm_vmw_fence_rep __user *user_fence_rep,
247 struct drm_vmw_rect *vclips,
248 uint32_t num_clips);
Thomas Hellstromfd006a42015-06-28 02:50:56 -0700249struct vmw_framebuffer *
250vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
251 struct vmw_dma_buffer *dmabuf,
252 struct vmw_surface *surface,
253 bool only_2d,
Daniel Vetterdabdcdc2016-12-02 08:07:40 +0100254 const struct drm_mode_fb_cmd2 *mode_cmd);
Thomas Hellstroma2787242015-06-29 12:55:07 -0700255int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
256 unsigned unit,
257 u32 max_width,
258 u32 max_height,
259 struct drm_connector **p_con,
260 struct drm_crtc **p_crtc,
261 struct drm_display_mode **p_mode);
262void vmw_guess_mode_timing(struct drm_display_mode *mode);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100263void vmw_kms_del_active(struct vmw_private *dev_priv,
264 struct vmw_display_unit *du);
265void vmw_kms_add_active(struct vmw_private *dev_priv,
266 struct vmw_display_unit *du,
267 struct vmw_framebuffer *vfb);
268bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
269 struct drm_crtc *crtc);
270void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
271 struct drm_crtc *crtc);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100272void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
273 bool immutable);
Thomas Hellstrom75c06852016-02-12 09:00:26 +0100274
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700275/* Universal Plane Helpers */
276void vmw_du_primary_plane_destroy(struct drm_plane *plane);
277void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
278int vmw_du_cursor_plane_disable(struct drm_plane *plane);
279int vmw_du_cursor_plane_update(struct drm_plane *plane,
280 struct drm_crtc *crtc,
281 struct drm_framebuffer *fb,
282 int crtc_x, int crtc_y,
283 unsigned int crtc_w,
284 unsigned int crtc_h,
285 uint32_t src_x, uint32_t src_y,
286 uint32_t src_w, uint32_t src_h);
287
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000288
289/*
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200290 * Legacy display unit functions - vmwgfx_ldu.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000291 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700292int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
293int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
294int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
295 struct vmw_framebuffer *framebuffer,
296 unsigned flags, unsigned color,
297 struct drm_clip_rect *clips,
298 unsigned num_clips, int increment);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700299int vmw_kms_update_proxy(struct vmw_resource *res,
300 const struct drm_clip_rect *clips,
301 unsigned num_clips,
302 int increment);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000303
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200304/*
305 * Screen Objects display functions - vmwgfx_scrn.c
306 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700307int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
308int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
309int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700310 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700311 struct drm_clip_rect *clips,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700312 struct drm_vmw_rect *vclips,
313 struct vmw_resource *srf,
314 s32 dest_x,
315 s32 dest_y,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700316 unsigned num_clips, int inc,
317 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700318int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700319 struct vmw_framebuffer *framebuffer,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700320 struct drm_clip_rect *clips,
Thomas Hellstrom897b8182016-02-12 08:32:08 +0100321 struct drm_vmw_rect *vclips,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700322 unsigned num_clips, int increment,
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700323 bool interruptible,
Sinclair Yehc8261a92015-06-26 01:23:42 -0700324 struct vmw_fence_obj **out_fence);
Thomas Hellstrom10b1e0c2015-06-26 02:14:27 -0700325int vmw_kms_sou_readback(struct vmw_private *dev_priv,
326 struct drm_file *file_priv,
327 struct vmw_framebuffer *vfb,
328 struct drm_vmw_fence_rep __user *user_fence_rep,
329 struct drm_vmw_rect *vclips,
330 uint32_t num_clips);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700331
332/*
333 * Screen Target Display Unit functions - vmwgfx_stdu.c
334 */
335int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
336int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
Thomas Hellstrom6bf6bf02015-06-26 02:22:40 -0700337int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
338 struct vmw_framebuffer *framebuffer,
339 struct drm_clip_rect *clips,
340 struct drm_vmw_rect *vclips,
341 struct vmw_resource *srf,
342 s32 dest_x,
343 s32 dest_y,
344 unsigned num_clips, int inc,
345 struct vmw_fence_obj **out_fence);
346int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
347 struct drm_file *file_priv,
348 struct vmw_framebuffer *vfb,
349 struct drm_vmw_fence_rep __user *user_fence_rep,
350 struct drm_clip_rect *clips,
351 struct drm_vmw_rect *vclips,
352 uint32_t num_clips,
353 int increment,
354 bool to_surface,
355 bool interruptible);
Jakob Bornecrantzb5ec4272012-02-09 16:56:45 +0100356
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200357
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000358#endif