]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
drm/vmwgfx: Add and connect CRTC helper functions
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / vmwgfx / vmwgfx_ldu.c
CommitLineData
fb1d9738
JB
1/**************************************************************************
2 *
54fbde8a 3 * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
fb1d9738
JB
4 * 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"
3cb9ae4f 29#include <drm/drm_plane_helper.h>
d7721ca7
SY
30#include <drm/drm_atomic.h>
31#include <drm/drm_atomic_helper.h>
fb1d9738 32
7a1c2f6c 33
fb1d9738
JB
34#define vmw_crtc_to_ldu(x) \
35 container_of(x, struct vmw_legacy_display_unit, base.crtc)
36#define vmw_encoder_to_ldu(x) \
37 container_of(x, struct vmw_legacy_display_unit, base.encoder)
38#define vmw_connector_to_ldu(x) \
39 container_of(x, struct vmw_legacy_display_unit, base.connector)
40
41struct vmw_legacy_display {
42 struct list_head active;
43
44 unsigned num_active;
d7e1958d 45 unsigned last_num_active;
fb1d9738
JB
46
47 struct vmw_framebuffer *fb;
48};
49
50/**
51 * Display unit using the legacy register interface.
52 */
53struct vmw_legacy_display_unit {
54 struct vmw_display_unit base;
55
56 struct list_head active;
fb1d9738
JB
57};
58
59static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu)
60{
61 list_del_init(&ldu->active);
c8261a96 62 vmw_du_cleanup(&ldu->base);
fb1d9738
JB
63 kfree(ldu);
64}
65
66
67/*
68 * Legacy Display Unit CRTC functions
69 */
70
fb1d9738
JB
71static void vmw_ldu_crtc_destroy(struct drm_crtc *crtc)
72{
73 vmw_ldu_destroy(vmw_crtc_to_ldu(crtc));
74}
75
76static int vmw_ldu_commit_list(struct vmw_private *dev_priv)
77{
78 struct vmw_legacy_display *lds = dev_priv->ldu_priv;
79 struct vmw_legacy_display_unit *entry;
d7e1958d
JB
80 struct drm_framebuffer *fb = NULL;
81 struct drm_crtc *crtc = NULL;
36cc79bc 82 int i = 0;
fb1d9738 83
d7e1958d
JB
84 /* If there is no display topology the host just assumes
85 * that the guest will set the same layout as the host.
86 */
87 if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) {
88 int w = 0, h = 0;
89 list_for_each_entry(entry, &lds->active, active) {
90 crtc = &entry->base.crtc;
91 w = max(w, crtc->x + crtc->mode.hdisplay);
92 h = max(h, crtc->y + crtc->mode.vdisplay);
93 i++;
94 }
95
96 if (crtc == NULL)
97 return 0;
f4510a27 98 fb = entry->base.crtc.primary->fb;
d7e1958d 99
01f2c773 100 return vmw_kms_write_svga(dev_priv, w, h, fb->pitches[0],
272725c7 101 fb->format->cpp[0] * 8,
b00c600e 102 fb->format->depth);
d7e1958d
JB
103 }
104
d7e1958d
JB
105 if (!list_empty(&lds->active)) {
106 entry = list_entry(lds->active.next, typeof(*entry), active);
f4510a27 107 fb = entry->base.crtc.primary->fb;
d7e1958d 108
01f2c773 109 vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitches[0],
272725c7 110 fb->format->cpp[0] * 8, fb->format->depth);
d7e1958d
JB
111 }
112
259600d5
JB
113 /* Make sure we always show something. */
114 vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS,
115 lds->num_active ? lds->num_active : 1);
116
fb1d9738
JB
117 i = 0;
118 list_for_each_entry(entry, &lds->active, active) {
119 crtc = &entry->base.crtc;
120
121 vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i);
122 vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i);
123 vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, crtc->x);
124 vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, crtc->y);
125 vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, crtc->mode.hdisplay);
126 vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, crtc->mode.vdisplay);
127 vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
128
129 i++;
130 }
131
d7e1958d
JB
132 BUG_ON(i != lds->num_active);
133
134 lds->last_num_active = lds->num_active;
135
fb1d9738
JB
136 return 0;
137}
138
139static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
140 struct vmw_legacy_display_unit *ldu)
141{
142 struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
143 if (list_empty(&ldu->active))
144 return 0;
145
6a591a96 146 /* Must init otherwise list_empty(&ldu->active) will not work. */
fb1d9738
JB
147 list_del_init(&ldu->active);
148 if (--(ld->num_active) == 0) {
149 BUG_ON(!ld->fb);
150 if (ld->fb->unpin)
151 ld->fb->unpin(ld->fb);
152 ld->fb = NULL;
153 }
154
155 return 0;
156}
157
158static int vmw_ldu_add_active(struct vmw_private *vmw_priv,
159 struct vmw_legacy_display_unit *ldu,
160 struct vmw_framebuffer *vfb)
161{
162 struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
163 struct vmw_legacy_display_unit *entry;
164 struct list_head *at;
165
04e9e94d
JB
166 BUG_ON(!ld->num_active && ld->fb);
167 if (vfb != ld->fb) {
168 if (ld->fb && ld->fb->unpin)
169 ld->fb->unpin(ld->fb);
06ec4190 170 vmw_svga_enable(vmw_priv);
04e9e94d
JB
171 if (vfb->pin)
172 vfb->pin(vfb);
173 ld->fb = vfb;
174 }
175
fb1d9738
JB
176 if (!list_empty(&ldu->active))
177 return 0;
178
179 at = &ld->active;
180 list_for_each_entry(entry, &ld->active, active) {
bbfad336 181 if (entry->base.unit > ldu->base.unit)
fb1d9738
JB
182 break;
183
184 at = &entry->active;
185 }
186
187 list_add(&ldu->active, at);
04e9e94d
JB
188
189 ld->num_active++;
fb1d9738
JB
190
191 return 0;
192}
193
06ec4190
SY
194/**
195 * vmw_ldu_crtc_mode_set_nofb - Enable svga
196 *
197 * @crtc: CRTC associated with the new screen
198 *
199 * For LDU, just enable the svga
200 */
201static void vmw_ldu_crtc_mode_set_nofb(struct drm_crtc *crtc)
202{
203}
204
205/**
206 * vmw_ldu_crtc_helper_prepare - Noop
207 *
208 * @crtc: CRTC associated with the new screen
209 *
210 * Prepares the CRTC for a mode set, but we don't need to do anything here.
211 *
212 */
213static void vmw_ldu_crtc_helper_prepare(struct drm_crtc *crtc)
214{
215}
216
217/**
218 * vmw_ldu_crtc_helper_commit - Noop
219 *
220 * @crtc: CRTC associated with the new screen
221 *
222 * This is called after a mode set has been completed. Here's
223 * usually a good place to call vmw_ldu_add_active/vmw_ldu_del_active
224 * but since for LDU the display plane is closely tied to the
225 * CRTC, it makes more sense to do those at plane update time.
226 */
227static void vmw_ldu_crtc_helper_commit(struct drm_crtc *crtc)
228{
229 struct vmw_private *dev_priv;
230 struct vmw_legacy_display_unit *ldu;
231 struct vmw_framebuffer *vfb;
232 struct drm_framebuffer *fb;
233
234
235 ldu = vmw_crtc_to_ldu(crtc);
236 dev_priv = vmw_priv(crtc->dev);
237 fb = crtc->primary->fb;
238
239 vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL;
240
241 if (vfb)
242 vmw_ldu_add_active(dev_priv, ldu, vfb);
243 else
244 vmw_ldu_del_active(dev_priv, ldu);
245}
246
247/**
248 * vmw_ldu_crtc_helper_disable - Turns off CRTC
249 *
250 * @crtc: CRTC to be turned off
251 */
252static void vmw_ldu_crtc_helper_disable(struct drm_crtc *crtc)
253{
254}
255
fb1d9738
JB
256static int vmw_ldu_crtc_set_config(struct drm_mode_set *set)
257{
258 struct vmw_private *dev_priv;
259 struct vmw_legacy_display_unit *ldu;
260 struct drm_connector *connector;
261 struct drm_display_mode *mode;
262 struct drm_encoder *encoder;
263 struct vmw_framebuffer *vfb;
264 struct drm_framebuffer *fb;
265 struct drm_crtc *crtc;
266
267 if (!set)
268 return -EINVAL;
269
270 if (!set->crtc)
271 return -EINVAL;
272
273 /* get the ldu */
274 crtc = set->crtc;
275 ldu = vmw_crtc_to_ldu(crtc);
276 vfb = set->fb ? vmw_framebuffer_to_vfb(set->fb) : NULL;
277 dev_priv = vmw_priv(crtc->dev);
278
279 if (set->num_connectors > 1) {
280 DRM_ERROR("to many connectors\n");
281 return -EINVAL;
282 }
283
284 if (set->num_connectors == 1 &&
285 set->connectors[0] != &ldu->base.connector) {
286 DRM_ERROR("connector doesn't match %p %p\n",
287 set->connectors[0], &ldu->base.connector);
288 return -EINVAL;
289 }
290
291 /* ldu only supports one fb active at the time */
292 if (dev_priv->ldu_priv->fb && vfb &&
6a591a96
JB
293 !(dev_priv->ldu_priv->num_active == 1 &&
294 !list_empty(&ldu->active)) &&
fb1d9738
JB
295 dev_priv->ldu_priv->fb != vfb) {
296 DRM_ERROR("Multiple framebuffers not supported\n");
297 return -EINVAL;
298 }
299
300 /* since they always map one to one these are safe */
301 connector = &ldu->base.connector;
302 encoder = &ldu->base.encoder;
303
304 /* should we turn the crtc off? */
305 if (set->num_connectors == 0 || !set->mode || !set->fb) {
306
307 connector->encoder = NULL;
308 encoder->crtc = NULL;
f4510a27 309 crtc->primary->fb = NULL;
c6c1f325 310 crtc->enabled = false;
fb1d9738
JB
311
312 vmw_ldu_del_active(dev_priv, ldu);
313
0bef23f9 314 return vmw_ldu_commit_list(dev_priv);
fb1d9738
JB
315 }
316
317
318 /* we now know we want to set a mode */
319 mode = set->mode;
320 fb = set->fb;
321
322 if (set->x + mode->hdisplay > fb->width ||
323 set->y + mode->vdisplay > fb->height) {
324 DRM_ERROR("set outside of framebuffer\n");
325 return -EINVAL;
326 }
327
153b3d5b 328 vmw_svga_enable(dev_priv);
fb1d9738 329
f4510a27 330 crtc->primary->fb = fb;
fb1d9738
JB
331 encoder->crtc = crtc;
332 connector->encoder = encoder;
333 crtc->x = set->x;
334 crtc->y = set->y;
335 crtc->mode = *mode;
c6c1f325 336 crtc->enabled = true;
6dd687b4
TH
337 ldu->base.set_gui_x = set->x;
338 ldu->base.set_gui_y = set->y;
fb1d9738
JB
339
340 vmw_ldu_add_active(dev_priv, ldu, vfb);
341
0bef23f9 342 return vmw_ldu_commit_list(dev_priv);
fb1d9738
JB
343}
344
d7955fcf 345static const struct drm_crtc_funcs vmw_legacy_crtc_funcs = {
626ab771 346 .gamma_set = vmw_du_crtc_gamma_set,
fb1d9738 347 .destroy = vmw_ldu_crtc_destroy,
9c2542a4
SY
348 .reset = vmw_du_crtc_reset,
349 .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
350 .atomic_destroy_state = vmw_du_crtc_destroy_state,
fb1d9738
JB
351 .set_config = vmw_ldu_crtc_set_config,
352};
353
626ab771 354
fb1d9738
JB
355/*
356 * Legacy Display Unit encoder functions
357 */
358
359static void vmw_ldu_encoder_destroy(struct drm_encoder *encoder)
360{
361 vmw_ldu_destroy(vmw_encoder_to_ldu(encoder));
362}
363
d7955fcf 364static const struct drm_encoder_funcs vmw_legacy_encoder_funcs = {
fb1d9738
JB
365 .destroy = vmw_ldu_encoder_destroy,
366};
367
368/*
369 * Legacy Display Unit connector functions
370 */
371
fb1d9738
JB
372static void vmw_ldu_connector_destroy(struct drm_connector *connector)
373{
374 vmw_ldu_destroy(vmw_connector_to_ldu(connector));
375}
376
d7955fcf 377static const struct drm_connector_funcs vmw_legacy_connector_funcs = {
626ab771 378 .dpms = vmw_du_connector_dpms,
626ab771
JB
379 .detect = vmw_du_connector_detect,
380 .fill_modes = vmw_du_connector_fill_modes,
381 .set_property = vmw_du_connector_set_property,
fb1d9738 382 .destroy = vmw_ldu_connector_destroy,
d7721ca7
SY
383 .reset = vmw_du_connector_reset,
384 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
385 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
386 .atomic_set_property = vmw_du_connector_atomic_set_property,
387 .atomic_get_property = vmw_du_connector_atomic_get_property,
fb1d9738
JB
388};
389
36cc79bc
SY
390/*
391 * Legacy Display Plane Functions
392 */
393
394static const struct drm_plane_funcs vmw_ldu_plane_funcs = {
395 .update_plane = drm_primary_helper_update,
396 .disable_plane = drm_primary_helper_disable,
397 .destroy = vmw_du_primary_plane_destroy,
cc5ec459
SY
398 .reset = vmw_du_plane_reset,
399 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
400 .atomic_destroy_state = vmw_du_plane_destroy_state,
36cc79bc
SY
401};
402
403static const struct drm_plane_funcs vmw_ldu_cursor_funcs = {
404 .update_plane = vmw_du_cursor_plane_update,
405 .disable_plane = vmw_du_cursor_plane_disable,
406 .destroy = vmw_du_cursor_plane_destroy,
cc5ec459
SY
407 .reset = vmw_du_plane_reset,
408 .atomic_duplicate_state = vmw_du_plane_duplicate_state,
409 .atomic_destroy_state = vmw_du_plane_destroy_state,
36cc79bc
SY
410};
411
06ec4190
SY
412/*
413 * Atomic Helpers
414 */
415static const struct drm_crtc_helper_funcs vmw_ldu_crtc_helper_funcs = {
416 .prepare = vmw_ldu_crtc_helper_prepare,
417 .commit = vmw_ldu_crtc_helper_commit,
418 .disable = vmw_ldu_crtc_helper_disable,
419 .mode_set = drm_helper_crtc_mode_set,
420 .mode_set_nofb = vmw_ldu_crtc_mode_set_nofb,
421 .atomic_check = vmw_du_crtc_atomic_check,
422 .atomic_begin = vmw_du_crtc_atomic_begin,
423 .atomic_flush = vmw_du_crtc_atomic_flush,
424};
425
36cc79bc 426
fb1d9738
JB
427static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
428{
429 struct vmw_legacy_display_unit *ldu;
430 struct drm_device *dev = dev_priv->dev;
431 struct drm_connector *connector;
432 struct drm_encoder *encoder;
cc5ec459 433 struct drm_plane *primary, *cursor;
fb1d9738 434 struct drm_crtc *crtc;
36cc79bc 435 int ret;
fb1d9738
JB
436
437 ldu = kzalloc(sizeof(*ldu), GFP_KERNEL);
438 if (!ldu)
439 return -ENOMEM;
440
bbfad336 441 ldu->base.unit = unit;
fb1d9738
JB
442 crtc = &ldu->base.crtc;
443 encoder = &ldu->base.encoder;
444 connector = &ldu->base.connector;
cc5ec459
SY
445 primary = &ldu->base.primary;
446 cursor = &ldu->base.cursor;
fb1d9738 447
1ae1ddd5
JB
448 INIT_LIST_HEAD(&ldu->active);
449
626ab771 450 ldu->base.pref_active = (unit == 0);
eb4f923b
JB
451 ldu->base.pref_width = dev_priv->initial_width;
452 ldu->base.pref_height = dev_priv->initial_height;
626ab771 453 ldu->base.pref_mode = NULL;
9c2542a4
SY
454
455 /*
456 * Remove this after enabling atomic because property values can
457 * only exist in a state object
458 */
6987427a 459 ldu->base.is_implicit = true;
d8bd19d2 460
36cc79bc 461 /* Initialize primary plane */
cc5ec459
SY
462 vmw_du_plane_reset(primary);
463
36cc79bc
SY
464 ret = drm_universal_plane_init(dev, &ldu->base.primary,
465 0, &vmw_ldu_plane_funcs,
466 vmw_primary_plane_formats,
467 ARRAY_SIZE(vmw_primary_plane_formats),
468 DRM_PLANE_TYPE_PRIMARY, NULL);
469 if (ret) {
470 DRM_ERROR("Failed to initialize primary plane");
471 goto err_free;
472 }
473
474 /* Initialize cursor plane */
cc5ec459
SY
475 vmw_du_plane_reset(cursor);
476
36cc79bc
SY
477 ret = drm_universal_plane_init(dev, &ldu->base.cursor,
478 0, &vmw_ldu_cursor_funcs,
479 vmw_cursor_plane_formats,
480 ARRAY_SIZE(vmw_cursor_plane_formats),
481 DRM_PLANE_TYPE_CURSOR, NULL);
482 if (ret) {
483 DRM_ERROR("Failed to initialize cursor plane");
484 drm_plane_cleanup(&ldu->base.primary);
485 goto err_free;
486 }
487
488 ret = drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
489 DRM_MODE_CONNECTOR_VIRTUAL);
490 if (ret) {
491 DRM_ERROR("Failed to initialize connector\n");
492 goto err_free;
493 }
626ab771 494 connector->status = vmw_du_connector_detect(connector, true);
d7721ca7
SY
495 vmw_connector_state_to_vcs(connector->state)->is_implicit = true;
496
fb1d9738 497
36cc79bc
SY
498 ret = drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
499 DRM_MODE_ENCODER_VIRTUAL, NULL);
500 if (ret) {
501 DRM_ERROR("Failed to initialize encoder\n");
502 goto err_free_connector;
503 }
504
505 (void) drm_mode_connector_attach_encoder(connector, encoder);
fb1d9738
JB
506 encoder->possible_crtcs = (1 << unit);
507 encoder->possible_clones = 0;
508
36cc79bc
SY
509 ret = drm_connector_register(connector);
510 if (ret) {
511 DRM_ERROR("Failed to register connector\n");
512 goto err_free_encoder;
513 }
6a0a7a9e 514
d7721ca7
SY
515
516 vmw_du_crtc_reset(crtc);
36cc79bc
SY
517 ret = drm_crtc_init_with_planes(dev, crtc, &ldu->base.primary,
518 &ldu->base.cursor,
519 &vmw_legacy_crtc_funcs, NULL);
520 if (ret) {
521 DRM_ERROR("Failed to initialize CRTC\n");
522 goto err_free_unregister;
523 }
fb1d9738 524
06ec4190
SY
525 drm_crtc_helper_add(crtc, &vmw_ldu_crtc_helper_funcs);
526
f01b7ba0
MD
527 drm_mode_crtc_set_gamma_size(crtc, 256);
528
578e609a
TH
529 drm_object_attach_property(&connector->base,
530 dev_priv->hotplug_mode_update_property, 1);
531 drm_object_attach_property(&connector->base,
532 dev->mode_config.suggested_x_property, 0);
533 drm_object_attach_property(&connector->base,
534 dev->mode_config.suggested_y_property, 0);
76404ac0
TH
535 if (dev_priv->implicit_placement_property)
536 drm_object_attach_property
537 (&connector->base,
538 dev_priv->implicit_placement_property,
539 1);
fb1d9738
JB
540
541 return 0;
36cc79bc
SY
542
543err_free_unregister:
544 drm_connector_unregister(connector);
545err_free_encoder:
546 drm_encoder_cleanup(encoder);
547err_free_connector:
548 drm_connector_cleanup(connector);
549err_free:
550 kfree(ldu);
551 return ret;
fb1d9738
JB
552}
553
c8261a96 554int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)
fb1d9738 555{
7a1c2f6c 556 struct drm_device *dev = dev_priv->dev;
74b5ea30 557 int i, ret;
7a1c2f6c 558
fb1d9738
JB
559 if (dev_priv->ldu_priv) {
560 DRM_INFO("ldu system already on\n");
561 return -EINVAL;
562 }
563
85b54e0c 564 dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL);
fb1d9738
JB
565 if (!dev_priv->ldu_priv)
566 return -ENOMEM;
567
568 INIT_LIST_HEAD(&dev_priv->ldu_priv->active);
569 dev_priv->ldu_priv->num_active = 0;
d7e1958d 570 dev_priv->ldu_priv->last_num_active = 0;
fb1d9738
JB
571 dev_priv->ldu_priv->fb = NULL;
572
60a16a30
JB
573 /* for old hardware without multimon only enable one display */
574 if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
575 ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
576 else
577 ret = drm_vblank_init(dev, 1);
578 if (ret != 0)
579 goto err_free;
fb1d9738 580
76404ac0
TH
581 vmw_kms_create_implicit_placement_property(dev_priv, true);
582
60a16a30 583 if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
56d1c78d 584 for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
7a1c2f6c 585 vmw_ldu_init(dev_priv, i);
60a16a30 586 else
7a1c2f6c 587 vmw_ldu_init(dev_priv, 0);
fb1d9738 588
c8261a96
SY
589 dev_priv->active_display_unit = vmw_du_legacy;
590
591 DRM_INFO("Legacy Display Unit initialized\n");
592
60a16a30
JB
593 return 0;
594
60a16a30
JB
595err_free:
596 kfree(dev_priv->ldu_priv);
597 dev_priv->ldu_priv = NULL;
7a1c2f6c 598 return ret;
fb1d9738
JB
599}
600
c8261a96 601int vmw_kms_ldu_close_display(struct vmw_private *dev_priv)
fb1d9738 602{
7a1c2f6c
TH
603 struct drm_device *dev = dev_priv->dev;
604
fb1d9738
JB
605 if (!dev_priv->ldu_priv)
606 return -ENOSYS;
607
60a16a30
JB
608 drm_vblank_cleanup(dev);
609
fb1d9738
JB
610 BUG_ON(!list_empty(&dev_priv->ldu_priv->active));
611
612 kfree(dev_priv->ldu_priv);
613
614 return 0;
615}
c8261a96
SY
616
617
618int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
619 struct vmw_framebuffer *framebuffer,
620 unsigned flags, unsigned color,
621 struct drm_clip_rect *clips,
622 unsigned num_clips, int increment)
623{
624 size_t fifo_size;
625 int i;
626
627 struct {
628 uint32_t header;
629 SVGAFifoCmdUpdate body;
630 } *cmd;
631
632 fifo_size = sizeof(*cmd) * num_clips;
633 cmd = vmw_fifo_reserve(dev_priv, fifo_size);
634 if (unlikely(cmd == NULL)) {
635 DRM_ERROR("Fifo reserve failed.\n");
636 return -ENOMEM;
637 }
638
639 memset(cmd, 0, fifo_size);
640 for (i = 0; i < num_clips; i++, clips += increment) {
b9eb1a61
TH
641 cmd[i].header = SVGA_CMD_UPDATE;
642 cmd[i].body.x = clips->x1;
643 cmd[i].body.y = clips->y1;
644 cmd[i].body.width = clips->x2 - clips->x1;
645 cmd[i].body.height = clips->y2 - clips->y1;
c8261a96
SY
646 }
647
648 vmw_fifo_commit(dev_priv, fifo_size);
649 return 0;
650}