blob: c19a515b139b144979966e163ea5feb4a3607d57 [file] [log] [blame]
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001/**************************************************************************
2 *
Sinclair Yehc8261a92015-06-26 01:23:42 -07003 * Copyright © 2009-2014 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>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000033#include "vmwgfx_drv.h"
34
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -070035/**
36 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
37 * function.
38 *
39 * @fifo_commit: Callback that is called once for each display unit after
40 * all clip rects. This function must commit the fifo space reserved by the
41 * helper. Set up by the caller.
42 * @clip: Callback that is called for each cliprect on each display unit.
43 * Set up by the caller.
44 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
45 * each display unit. Set up by the caller.
46 * @dev_priv: Pointer to the device private. Set up by the helper.
47 * @unit: The current display unit. Set up by the helper before a call to @clip.
48 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
49 * call.
50 * @num_hits: Number of clip rect commands for this display unit.
51 * Cleared by the helper before the first @clip call. Updated by the @clip
52 * callback.
53 * @fb_x: Clip rect left side in framebuffer coordinates.
54 * @fb_y: Clip rect right side in framebuffer coordinates.
55 * @unit_x1: Clip rect left side in crtc coordinates.
56 * @unit_y1: Clip rect top side in crtc coordinates.
57 * @unit_x2: Clip rect right side in crtc coordinates.
58 * @unit_y2: Clip rect bottom side in crtc coordinates.
59 *
60 * The clip rect coordinates are updated by the helper for each @clip call.
61 * Note that this may be derived from if more info needs to be passed between
62 * helper caller and helper callbacks.
63 */
64struct vmw_kms_dirty {
65 void (*fifo_commit)(struct vmw_kms_dirty *);
66 void (*clip)(struct vmw_kms_dirty *);
67 size_t fifo_reserve_size;
68 struct vmw_private *dev_priv;
69 struct vmw_display_unit *unit;
70 void *cmd;
71 u32 num_hits;
72 s32 fb_x;
73 s32 fb_y;
74 s32 unit_x1;
75 s32 unit_y1;
76 s32 unit_x2;
77 s32 unit_y2;
78};
Sinclair Yehc8261a92015-06-26 01:23:42 -070079
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +020080#define VMWGFX_NUM_DISPLAY_UNITS 8
81
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000082
83#define vmw_framebuffer_to_vfb(x) \
84 container_of(x, struct vmw_framebuffer, base)
Sinclair Yehc8261a92015-06-26 01:23:42 -070085#define vmw_framebuffer_to_vfbs(x) \
86 container_of(x, struct vmw_framebuffer_surface, base.base)
87#define vmw_framebuffer_to_vfbd(x) \
88 container_of(x, struct vmw_framebuffer_dmabuf, base.base)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000089
90/**
91 * Base class for framebuffers
92 *
93 * @pin is called the when ever a crtc uses this framebuffer
94 * @unpin is called
95 */
96struct vmw_framebuffer {
97 struct drm_framebuffer base;
98 int (*pin)(struct vmw_framebuffer *fb);
99 int (*unpin)(struct vmw_framebuffer *fb);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200100 bool dmabuf;
Thomas Hellstrom90ff18b2011-10-04 20:13:32 +0200101 struct ttm_base_object *user_obj;
102 uint32_t user_handle;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000103};
104
Sinclair Yehc8261a92015-06-26 01:23:42 -0700105/*
106 * Clip rectangle
107 */
108struct vmw_clip_rect {
109 int x1, x2, y1, y2;
110};
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000111
Sinclair Yehc8261a92015-06-26 01:23:42 -0700112struct vmw_framebuffer_surface {
113 struct vmw_framebuffer base;
114 struct vmw_surface *surface;
115 struct vmw_dma_buffer *buffer;
116 struct list_head head;
117 struct drm_master *master;
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
127
128/*
129 * Basic clip rect manipulation
130 */
131void vmw_clip_cliprects(struct drm_clip_rect *rects,
132 int num_rects,
133 struct vmw_clip_rect clip,
134 SVGASignedRect *out_rects,
135 int *out_num);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000136
137/*
138 * Basic cursor manipulation
139 */
140int vmw_cursor_update_image(struct vmw_private *dev_priv,
141 u32 *image, u32 width, u32 height,
142 u32 hotspotX, u32 hotspotY);
Jakob Bornecrantzbfc26382011-11-28 13:19:14 +0100143int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
144 struct vmw_dma_buffer *dmabuf,
145 u32 width, u32 height,
146 u32 hotspotX, u32 hotspotY);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000147void vmw_cursor_update_position(struct vmw_private *dev_priv,
148 bool show, int x, int y);
149
Jakob Bornecrantzbfc26382011-11-28 13:19:14 +0100150
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000151/**
152 * Base class display unit.
153 *
154 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
155 * so the display unit is all of them at the same time. This is true for both
156 * legacy multimon and screen objects.
157 */
158struct vmw_display_unit {
159 struct drm_crtc crtc;
160 struct drm_encoder encoder;
161 struct drm_connector connector;
162
163 struct vmw_surface *cursor_surface;
164 struct vmw_dma_buffer *cursor_dmabuf;
165 size_t cursor_age;
166
167 int cursor_x;
168 int cursor_y;
169
170 int hotspot_x;
171 int hotspot_y;
172
173 unsigned unit;
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200174
175 /*
176 * Prefered mode tracking.
177 */
178 unsigned pref_width;
179 unsigned pref_height;
180 bool pref_active;
181 struct drm_display_mode *pref_mode;
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200182
183 /*
184 * Gui positioning
185 */
186 int gui_x;
187 int gui_y;
Thomas Hellstrom69874272011-11-02 09:43:11 +0100188 bool is_implicit;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000189};
190
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200191#define vmw_crtc_to_du(x) \
192 container_of(x, struct vmw_display_unit, crtc)
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200193#define vmw_connector_to_du(x) \
194 container_of(x, struct vmw_display_unit, connector)
195
196
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000197/*
198 * Shared display unit functions - vmwgfx_kms.c
199 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700200void vmw_du_cleanup(struct vmw_display_unit *du);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200201void vmw_du_crtc_save(struct drm_crtc *crtc);
202void vmw_du_crtc_restore(struct drm_crtc *crtc);
203void vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
204 u16 *r, u16 *g, u16 *b,
205 uint32_t start, uint32_t size);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000206int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
207 uint32_t handle, uint32_t width, uint32_t height);
208int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200209void vmw_du_connector_dpms(struct drm_connector *connector, int mode);
210void vmw_du_connector_save(struct drm_connector *connector);
211void vmw_du_connector_restore(struct drm_connector *connector);
212enum drm_connector_status
213vmw_du_connector_detect(struct drm_connector *connector, bool force);
214int vmw_du_connector_fill_modes(struct drm_connector *connector,
215 uint32_t max_width, uint32_t max_height);
216int vmw_du_connector_set_property(struct drm_connector *connector,
217 struct drm_property *property,
218 uint64_t val);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700219int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
220 struct vmw_framebuffer *framebuffer,
221 const struct drm_clip_rect *clips,
222 const struct drm_vmw_rect *vclips,
223 s32 dest_x, s32 dest_y,
224 int num_clips,
225 int increment,
226 struct vmw_kms_dirty *dirty);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200227
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700228int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
229 struct vmw_dma_buffer *buf,
230 bool interruptible,
231 bool validate_as_mob);
232void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
233void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
234 struct drm_file *file_priv,
235 struct vmw_dma_buffer *buf,
236 struct vmw_fence_obj **out_fence,
237 struct drm_vmw_fence_rep __user *
238 user_fence_rep);
239int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
240 bool interruptible);
241void vmw_kms_helper_resource_revert(struct vmw_resource *res);
242void vmw_kms_helper_resource_finish(struct vmw_resource *res,
243 struct vmw_fence_obj **out_fence);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000244
245/*
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200246 * Legacy display unit functions - vmwgfx_ldu.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000247 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700248int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
249int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
250int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
251 struct vmw_framebuffer *framebuffer,
252 unsigned flags, unsigned color,
253 struct drm_clip_rect *clips,
254 unsigned num_clips, int increment);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000255
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200256/*
257 * Screen Objects display functions - vmwgfx_scrn.c
258 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700259int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
260int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
261int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
262 struct drm_file *file_priv,
263 struct vmw_framebuffer *framebuffer,
264 unsigned flags, unsigned color,
265 struct drm_clip_rect *clips,
266 unsigned num_clips, int inc,
267 struct vmw_fence_obj **out_fence);
268int vmw_kms_sou_do_dmabuf_dirty(struct drm_file *file_priv,
269 struct vmw_private *dev_priv,
270 struct vmw_framebuffer *framebuffer,
271 unsigned flags, unsigned color,
272 struct drm_clip_rect *clips,
273 unsigned num_clips, int increment,
274 struct vmw_fence_obj **out_fence);
Sinclair Yeh35c05122015-06-26 01:42:06 -0700275
276
277/*
278 * Screen Target Display Unit functions - vmwgfx_stdu.c
279 */
280int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
281int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
282int vmw_kms_stdu_do_surface_dirty(struct vmw_private *dev_priv,
283 struct drm_file *file_priv,
284 struct vmw_framebuffer *framebuffer,
285 struct drm_clip_rect *clips,
286 unsigned num_clips, int increment);
287int vmw_kms_stdu_present(struct vmw_private *dev_priv,
288 struct drm_file *file_priv,
289 struct vmw_framebuffer *vfb,
290 uint32_t user_handle,
291 int32_t dest_x, int32_t dest_y,
292 struct drm_vmw_rect *clips,
293 uint32_t num_clips);
294
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000295#endif