blob: 36cd1fe5fa335649f389e5cae741fe49879d2f52 [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#include "vmwgfx_kms.h"
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010029#include <drm/drm_plane_helper.h>
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000030
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +020031
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000032#define vmw_crtc_to_ldu(x) \
33 container_of(x, struct vmw_legacy_display_unit, base.crtc)
34#define vmw_encoder_to_ldu(x) \
35 container_of(x, struct vmw_legacy_display_unit, base.encoder)
36#define vmw_connector_to_ldu(x) \
37 container_of(x, struct vmw_legacy_display_unit, base.connector)
38
39struct vmw_legacy_display {
40 struct list_head active;
41
42 unsigned num_active;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +020043 unsigned last_num_active;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000044
45 struct vmw_framebuffer *fb;
46};
47
48/**
49 * Display unit using the legacy register interface.
50 */
51struct vmw_legacy_display_unit {
52 struct vmw_display_unit base;
53
54 struct list_head active;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000055};
56
57static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu)
58{
59 list_del_init(&ldu->active);
Sinclair Yehc8261a92015-06-26 01:23:42 -070060 vmw_du_cleanup(&ldu->base);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000061 kfree(ldu);
62}
63
64
65/*
66 * Legacy Display Unit CRTC functions
67 */
68
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000069static void vmw_ldu_crtc_destroy(struct drm_crtc *crtc)
70{
71 vmw_ldu_destroy(vmw_crtc_to_ldu(crtc));
72}
73
74static int vmw_ldu_commit_list(struct vmw_private *dev_priv)
75{
76 struct vmw_legacy_display *lds = dev_priv->ldu_priv;
77 struct vmw_legacy_display_unit *entry;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +020078 struct drm_framebuffer *fb = NULL;
79 struct drm_crtc *crtc = NULL;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -070080 int i = 0;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000081
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +020082 /* If there is no display topology the host just assumes
83 * that the guest will set the same layout as the host.
84 */
85 if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) {
86 int w = 0, h = 0;
87 list_for_each_entry(entry, &lds->active, active) {
88 crtc = &entry->base.crtc;
89 w = max(w, crtc->x + crtc->mode.hdisplay);
90 h = max(h, crtc->y + crtc->mode.vdisplay);
91 i++;
92 }
93
94 if (crtc == NULL)
95 return 0;
Matt Roperf4510a22014-04-01 15:22:40 -070096 fb = entry->base.crtc.primary->fb;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +020097
Ville Syrjälä01f2c772011-12-20 00:06:49 +020098 return vmw_kms_write_svga(dev_priv, w, h, fb->pitches[0],
Ville Syrjälä272725c2016-12-14 23:32:20 +020099 fb->format->cpp[0] * 8,
Ville Syrjäläb00c6002016-12-14 23:31:35 +0200100 fb->format->depth);
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200101 }
102
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200103 if (!list_empty(&lds->active)) {
104 entry = list_entry(lds->active.next, typeof(*entry), active);
Matt Roperf4510a22014-04-01 15:22:40 -0700105 fb = entry->base.crtc.primary->fb;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200106
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200107 vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitches[0],
Ville Syrjälä272725c2016-12-14 23:32:20 +0200108 fb->format->cpp[0] * 8, fb->format->depth);
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200109 }
110
Jakob Bornecrantz259600d52010-05-28 11:22:03 +0200111 /* Make sure we always show something. */
112 vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS,
113 lds->num_active ? lds->num_active : 1);
114
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000115 i = 0;
116 list_for_each_entry(entry, &lds->active, active) {
117 crtc = &entry->base.crtc;
118
119 vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i);
120 vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i);
121 vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, crtc->x);
122 vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, crtc->y);
123 vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, crtc->mode.hdisplay);
124 vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, crtc->mode.vdisplay);
125 vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
126
127 i++;
128 }
129
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200130 BUG_ON(i != lds->num_active);
131
132 lds->last_num_active = lds->num_active;
133
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000134 return 0;
135}
136
137static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
138 struct vmw_legacy_display_unit *ldu)
139{
140 struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
141 if (list_empty(&ldu->active))
142 return 0;
143
Jakob Bornecrantz6a591a92010-05-28 11:21:55 +0200144 /* Must init otherwise list_empty(&ldu->active) will not work. */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000145 list_del_init(&ldu->active);
146 if (--(ld->num_active) == 0) {
147 BUG_ON(!ld->fb);
148 if (ld->fb->unpin)
149 ld->fb->unpin(ld->fb);
150 ld->fb = NULL;
151 }
152
153 return 0;
154}
155
156static int vmw_ldu_add_active(struct vmw_private *vmw_priv,
157 struct vmw_legacy_display_unit *ldu,
158 struct vmw_framebuffer *vfb)
159{
160 struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
161 struct vmw_legacy_display_unit *entry;
162 struct list_head *at;
163
Jakob Bornecrantz04e9e942010-05-28 11:21:56 +0200164 BUG_ON(!ld->num_active && ld->fb);
165 if (vfb != ld->fb) {
166 if (ld->fb && ld->fb->unpin)
167 ld->fb->unpin(ld->fb);
168 if (vfb->pin)
169 vfb->pin(vfb);
170 ld->fb = vfb;
171 }
172
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000173 if (!list_empty(&ldu->active))
174 return 0;
175
176 at = &ld->active;
177 list_for_each_entry(entry, &ld->active, active) {
Jakob Bornecrantzbbfad332010-05-28 11:22:01 +0200178 if (entry->base.unit > ldu->base.unit)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000179 break;
180
181 at = &entry->active;
182 }
183
184 list_add(&ldu->active, at);
Jakob Bornecrantz04e9e942010-05-28 11:21:56 +0200185
186 ld->num_active++;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000187
188 return 0;
189}
190
191static int vmw_ldu_crtc_set_config(struct drm_mode_set *set)
192{
193 struct vmw_private *dev_priv;
194 struct vmw_legacy_display_unit *ldu;
195 struct drm_connector *connector;
196 struct drm_display_mode *mode;
197 struct drm_encoder *encoder;
198 struct vmw_framebuffer *vfb;
199 struct drm_framebuffer *fb;
200 struct drm_crtc *crtc;
201
202 if (!set)
203 return -EINVAL;
204
205 if (!set->crtc)
206 return -EINVAL;
207
208 /* get the ldu */
209 crtc = set->crtc;
210 ldu = vmw_crtc_to_ldu(crtc);
211 vfb = set->fb ? vmw_framebuffer_to_vfb(set->fb) : NULL;
212 dev_priv = vmw_priv(crtc->dev);
213
214 if (set->num_connectors > 1) {
215 DRM_ERROR("to many connectors\n");
216 return -EINVAL;
217 }
218
219 if (set->num_connectors == 1 &&
220 set->connectors[0] != &ldu->base.connector) {
221 DRM_ERROR("connector doesn't match %p %p\n",
222 set->connectors[0], &ldu->base.connector);
223 return -EINVAL;
224 }
225
226 /* ldu only supports one fb active at the time */
227 if (dev_priv->ldu_priv->fb && vfb &&
Jakob Bornecrantz6a591a92010-05-28 11:21:55 +0200228 !(dev_priv->ldu_priv->num_active == 1 &&
229 !list_empty(&ldu->active)) &&
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000230 dev_priv->ldu_priv->fb != vfb) {
231 DRM_ERROR("Multiple framebuffers not supported\n");
232 return -EINVAL;
233 }
234
235 /* since they always map one to one these are safe */
236 connector = &ldu->base.connector;
237 encoder = &ldu->base.encoder;
238
239 /* should we turn the crtc off? */
240 if (set->num_connectors == 0 || !set->mode || !set->fb) {
241
242 connector->encoder = NULL;
243 encoder->crtc = NULL;
Matt Roperf4510a22014-04-01 15:22:40 -0700244 crtc->primary->fb = NULL;
Thomas Hellstromc6c1f322013-11-14 03:11:10 -0800245 crtc->enabled = false;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000246
247 vmw_ldu_del_active(dev_priv, ldu);
248
Michel Dänzer0bef23f2011-08-31 07:42:50 +0000249 return vmw_ldu_commit_list(dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000250 }
251
252
253 /* we now know we want to set a mode */
254 mode = set->mode;
255 fb = set->fb;
256
257 if (set->x + mode->hdisplay > fb->width ||
258 set->y + mode->vdisplay > fb->height) {
259 DRM_ERROR("set outside of framebuffer\n");
260 return -EINVAL;
261 }
262
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700263 vmw_svga_enable(dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000264
Matt Roperf4510a22014-04-01 15:22:40 -0700265 crtc->primary->fb = fb;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000266 encoder->crtc = crtc;
267 connector->encoder = encoder;
268 crtc->x = set->x;
269 crtc->y = set->y;
270 crtc->mode = *mode;
Thomas Hellstromc6c1f322013-11-14 03:11:10 -0800271 crtc->enabled = true;
Thomas Hellstrom6dd687b2016-02-12 09:57:15 +0100272 ldu->base.set_gui_x = set->x;
273 ldu->base.set_gui_y = set->y;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000274
275 vmw_ldu_add_active(dev_priv, ldu, vfb);
276
Michel Dänzer0bef23f2011-08-31 07:42:50 +0000277 return vmw_ldu_commit_list(dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000278}
279
Ville Syrjäläd7955fc2015-12-15 12:21:15 +0100280static const struct drm_crtc_funcs vmw_legacy_crtc_funcs = {
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200281 .gamma_set = vmw_du_crtc_gamma_set,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000282 .destroy = vmw_ldu_crtc_destroy,
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700283 .reset = vmw_du_crtc_reset,
284 .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
285 .atomic_destroy_state = vmw_du_crtc_destroy_state,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000286 .set_config = vmw_ldu_crtc_set_config,
287};
288
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200289
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000290/*
291 * Legacy Display Unit encoder functions
292 */
293
294static void vmw_ldu_encoder_destroy(struct drm_encoder *encoder)
295{
296 vmw_ldu_destroy(vmw_encoder_to_ldu(encoder));
297}
298
Ville Syrjäläd7955fc2015-12-15 12:21:15 +0100299static const struct drm_encoder_funcs vmw_legacy_encoder_funcs = {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000300 .destroy = vmw_ldu_encoder_destroy,
301};
302
303/*
304 * Legacy Display Unit connector functions
305 */
306
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000307static void vmw_ldu_connector_destroy(struct drm_connector *connector)
308{
309 vmw_ldu_destroy(vmw_connector_to_ldu(connector));
310}
311
Ville Syrjäläd7955fc2015-12-15 12:21:15 +0100312static const struct drm_connector_funcs vmw_legacy_connector_funcs = {
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200313 .dpms = vmw_du_connector_dpms,
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200314 .detect = vmw_du_connector_detect,
315 .fill_modes = vmw_du_connector_fill_modes,
316 .set_property = vmw_du_connector_set_property,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000317 .destroy = vmw_ldu_connector_destroy,
318};
319
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700320/*
321 * Legacy Display Plane Functions
322 */
323
324static const struct drm_plane_funcs vmw_ldu_plane_funcs = {
325 .update_plane = drm_primary_helper_update,
326 .disable_plane = drm_primary_helper_disable,
327 .destroy = vmw_du_primary_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700328 .reset = vmw_du_plane_reset,
329 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
330 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700331};
332
333static const struct drm_plane_funcs vmw_ldu_cursor_funcs = {
334 .update_plane = vmw_du_cursor_plane_update,
335 .disable_plane = vmw_du_cursor_plane_disable,
336 .destroy = vmw_du_cursor_plane_destroy,
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700337 .reset = vmw_du_plane_reset,
338 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
339 .atomic_destroy_state = vmw_du_plane_destroy_state,
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700340};
341
342
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000343static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
344{
345 struct vmw_legacy_display_unit *ldu;
346 struct drm_device *dev = dev_priv->dev;
347 struct drm_connector *connector;
348 struct drm_encoder *encoder;
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700349 struct drm_plane *primary, *cursor;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000350 struct drm_crtc *crtc;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700351 int ret;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000352
353 ldu = kzalloc(sizeof(*ldu), GFP_KERNEL);
354 if (!ldu)
355 return -ENOMEM;
356
Jakob Bornecrantzbbfad332010-05-28 11:22:01 +0200357 ldu->base.unit = unit;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000358 crtc = &ldu->base.crtc;
359 encoder = &ldu->base.encoder;
360 connector = &ldu->base.connector;
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700361 primary = &ldu->base.primary;
362 cursor = &ldu->base.cursor;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000363
Jakob Bornecrantz1ae1ddd2010-05-28 11:21:58 +0200364 INIT_LIST_HEAD(&ldu->active);
365
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200366 ldu->base.pref_active = (unit == 0);
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100367 ldu->base.pref_width = dev_priv->initial_width;
368 ldu->base.pref_height = dev_priv->initial_height;
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200369 ldu->base.pref_mode = NULL;
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700370
371 /*
372 * Remove this after enabling atomic because property values can
373 * only exist in a state object
374 */
Thomas Hellstrom69874272011-11-02 09:43:11 +0100375 ldu->base.is_implicit = true;
Jakob Bornecrantzd8bd19d2010-06-01 11:54:20 +0200376
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700377 /* Initialize primary plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700378 vmw_du_plane_reset(primary);
379
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700380 ret = drm_universal_plane_init(dev, &ldu->base.primary,
381 0, &vmw_ldu_plane_funcs,
382 vmw_primary_plane_formats,
383 ARRAY_SIZE(vmw_primary_plane_formats),
384 DRM_PLANE_TYPE_PRIMARY, NULL);
385 if (ret) {
386 DRM_ERROR("Failed to initialize primary plane");
387 goto err_free;
388 }
389
390 /* Initialize cursor plane */
Sinclair Yehcc5ec452017-03-23 11:36:05 -0700391 vmw_du_plane_reset(cursor);
392
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700393 ret = drm_universal_plane_init(dev, &ldu->base.cursor,
394 0, &vmw_ldu_cursor_funcs,
395 vmw_cursor_plane_formats,
396 ARRAY_SIZE(vmw_cursor_plane_formats),
397 DRM_PLANE_TYPE_CURSOR, NULL);
398 if (ret) {
399 DRM_ERROR("Failed to initialize cursor plane");
400 drm_plane_cleanup(&ldu->base.primary);
401 goto err_free;
402 }
403
404 ret = drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
405 DRM_MODE_CONNECTOR_VIRTUAL);
406 if (ret) {
407 DRM_ERROR("Failed to initialize connector\n");
408 goto err_free;
409 }
Jakob Bornecrantz626ab772011-10-04 20:13:20 +0200410 connector->status = vmw_du_connector_detect(connector, true);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000411
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700412 ret = drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
413 DRM_MODE_ENCODER_VIRTUAL, NULL);
414 if (ret) {
415 DRM_ERROR("Failed to initialize encoder\n");
416 goto err_free_connector;
417 }
418
419 (void) drm_mode_connector_attach_encoder(connector, encoder);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000420 encoder->possible_crtcs = (1 << unit);
421 encoder->possible_clones = 0;
422
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700423 ret = drm_connector_register(connector);
424 if (ret) {
425 DRM_ERROR("Failed to register connector\n");
426 goto err_free_encoder;
427 }
Thomas Hellstrom6a0a7a92013-12-02 06:04:38 -0800428
Sinclair Yeh9c2542a2017-03-23 11:33:39 -0700429 /* FIXME: Turn on after plane/connector states are implemented. */
430 /* vmw_du_crtc_reset(crtc); */
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700431 ret = drm_crtc_init_with_planes(dev, crtc, &ldu->base.primary,
432 &ldu->base.cursor,
433 &vmw_legacy_crtc_funcs, NULL);
434 if (ret) {
435 DRM_ERROR("Failed to initialize CRTC\n");
436 goto err_free_unregister;
437 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000438
Michel Dänzerf01b7ba2011-08-31 07:42:47 +0000439 drm_mode_crtc_set_gamma_size(crtc, 256);
440
Rob Clarkb8b163b2012-10-11 20:47:14 -0500441 drm_object_attach_property(&connector->base,
Thomas Hellstrom578e6092016-02-12 09:45:42 +0100442 dev_priv->hotplug_mode_update_property, 1);
443 drm_object_attach_property(&connector->base,
444 dev->mode_config.suggested_x_property, 0);
445 drm_object_attach_property(&connector->base,
446 dev->mode_config.suggested_y_property, 0);
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100447 if (dev_priv->implicit_placement_property)
448 drm_object_attach_property
449 (&connector->base,
450 dev_priv->implicit_placement_property,
451 1);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000452
453 return 0;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700454
455err_free_unregister:
456 drm_connector_unregister(connector);
457err_free_encoder:
458 drm_encoder_cleanup(encoder);
459err_free_connector:
460 drm_connector_cleanup(connector);
461err_free:
462 kfree(ldu);
463 return ret;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000464}
465
Sinclair Yehc8261a92015-06-26 01:23:42 -0700466int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000467{
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200468 struct drm_device *dev = dev_priv->dev;
Jakob Bornecrantz74b5ea32011-10-17 11:59:44 +0200469 int i, ret;
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200470
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000471 if (dev_priv->ldu_priv) {
472 DRM_INFO("ldu system already on\n");
473 return -EINVAL;
474 }
475
Joe Perches85b54e02010-10-31 22:33:53 +0000476 dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000477 if (!dev_priv->ldu_priv)
478 return -ENOMEM;
479
480 INIT_LIST_HEAD(&dev_priv->ldu_priv->active);
481 dev_priv->ldu_priv->num_active = 0;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200482 dev_priv->ldu_priv->last_num_active = 0;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000483 dev_priv->ldu_priv->fb = NULL;
484
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200485 /* for old hardware without multimon only enable one display */
486 if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
487 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
488 else
489 ret = drm_vblank_init(dev, 1);
490 if (ret != 0)
491 goto err_free;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000492
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100493 vmw_kms_create_implicit_placement_property(dev_priv, true);
494
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200495 if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200496 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200497 vmw_ldu_init(dev_priv, i);
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200498 else
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200499 vmw_ldu_init(dev_priv, 0);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000500
Sinclair Yehc8261a92015-06-26 01:23:42 -0700501 dev_priv->active_display_unit = vmw_du_legacy;
502
503 DRM_INFO("Legacy Display Unit initialized\n");
504
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200505 return 0;
506
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200507err_free:
508 kfree(dev_priv->ldu_priv);
509 dev_priv->ldu_priv = NULL;
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200510 return ret;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000511}
512
Sinclair Yehc8261a92015-06-26 01:23:42 -0700513int vmw_kms_ldu_close_display(struct vmw_private *dev_priv)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000514{
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200515 struct drm_device *dev = dev_priv->dev;
516
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000517 if (!dev_priv->ldu_priv)
518 return -ENOSYS;
519
Jakob Bornecrantz60a16a32011-10-17 11:59:43 +0200520 drm_vblank_cleanup(dev);
521
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000522 BUG_ON(!list_empty(&dev_priv->ldu_priv->active));
523
524 kfree(dev_priv->ldu_priv);
525
526 return 0;
527}
Sinclair Yehc8261a92015-06-26 01:23:42 -0700528
529
530int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
531 struct vmw_framebuffer *framebuffer,
532 unsigned flags, unsigned color,
533 struct drm_clip_rect *clips,
534 unsigned num_clips, int increment)
535{
536 size_t fifo_size;
537 int i;
538
539 struct {
540 uint32_t header;
541 SVGAFifoCmdUpdate body;
542 } *cmd;
543
544 fifo_size = sizeof(*cmd) * num_clips;
545 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
546 if (unlikely(cmd == NULL)) {
547 DRM_ERROR("Fifo reserve failed.\n");
548 return -ENOMEM;
549 }
550
551 memset(cmd, 0, fifo_size);
552 for (i = 0; i < num_clips; i++, clips += increment) {
Thomas Hellstromb9eb1a62015-04-02 02:39:45 -0700553 cmd[i].header = SVGA_CMD_UPDATE;
554 cmd[i].body.x = clips->x1;
555 cmd[i].body.y = clips->y1;
556 cmd[i].body.width = clips->x2 - clips->x1;
557 cmd[i].body.height = clips->y2 - clips->y1;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700558 }
559
560 vmw_fifo_commit(dev_priv, fifo_size);
561 return 0;
562}