diff options
Diffstat (limited to 'drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 189 |
1 files changed, 146 insertions, 43 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c index 90891593bf6c..cfaf690a5b2f 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | |||
@@ -38,6 +38,7 @@ struct vmw_legacy_display { | |||
38 | struct list_head active; | 38 | struct list_head active; |
39 | 39 | ||
40 | unsigned num_active; | 40 | unsigned num_active; |
41 | unsigned last_num_active; | ||
41 | 42 | ||
42 | struct vmw_framebuffer *fb; | 43 | struct vmw_framebuffer *fb; |
43 | }; | 44 | }; |
@@ -48,9 +49,12 @@ struct vmw_legacy_display { | |||
48 | struct vmw_legacy_display_unit { | 49 | struct vmw_legacy_display_unit { |
49 | struct vmw_display_unit base; | 50 | struct vmw_display_unit base; |
50 | 51 | ||
51 | struct list_head active; | 52 | unsigned pref_width; |
53 | unsigned pref_height; | ||
54 | bool pref_active; | ||
55 | struct drm_display_mode *pref_mode; | ||
52 | 56 | ||
53 | unsigned unit; | 57 | struct list_head active; |
54 | }; | 58 | }; |
55 | 59 | ||
56 | static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu) | 60 | static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu) |
@@ -88,23 +92,44 @@ static int vmw_ldu_commit_list(struct vmw_private *dev_priv) | |||
88 | { | 92 | { |
89 | struct vmw_legacy_display *lds = dev_priv->ldu_priv; | 93 | struct vmw_legacy_display *lds = dev_priv->ldu_priv; |
90 | struct vmw_legacy_display_unit *entry; | 94 | struct vmw_legacy_display_unit *entry; |
91 | struct drm_crtc *crtc; | 95 | struct drm_framebuffer *fb = NULL; |
96 | struct drm_crtc *crtc = NULL; | ||
92 | int i = 0; | 97 | int i = 0; |
93 | 98 | ||
94 | /* to stop the screen from changing size on resize */ | 99 | /* If there is no display topology the host just assumes |
95 | vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS, 0); | 100 | * that the guest will set the same layout as the host. |
96 | for (i = 0; i < lds->num_active; i++) { | 101 | */ |
97 | vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i); | 102 | if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) { |
98 | vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i); | 103 | int w = 0, h = 0; |
99 | vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, 0); | 104 | list_for_each_entry(entry, &lds->active, active) { |
100 | vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, 0); | 105 | crtc = &entry->base.crtc; |
101 | vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, 0); | 106 | w = max(w, crtc->x + crtc->mode.hdisplay); |
102 | vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, 0); | 107 | h = max(h, crtc->y + crtc->mode.vdisplay); |
103 | vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); | 108 | i++; |
109 | } | ||
110 | |||
111 | if (crtc == NULL) | ||
112 | return 0; | ||
113 | fb = entry->base.crtc.fb; | ||
114 | |||
115 | vmw_kms_write_svga(dev_priv, w, h, fb->pitch, | ||
116 | fb->bits_per_pixel, fb->depth); | ||
117 | |||
118 | return 0; | ||
104 | } | 119 | } |
105 | 120 | ||
106 | /* Now set the mode */ | 121 | if (!list_empty(&lds->active)) { |
107 | vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS, lds->num_active); | 122 | entry = list_entry(lds->active.next, typeof(*entry), active); |
123 | fb = entry->base.crtc.fb; | ||
124 | |||
125 | vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitch, | ||
126 | fb->bits_per_pixel, fb->depth); | ||
127 | } | ||
128 | |||
129 | /* Make sure we always show something. */ | ||
130 | vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS, | ||
131 | lds->num_active ? lds->num_active : 1); | ||
132 | |||
108 | i = 0; | 133 | i = 0; |
109 | list_for_each_entry(entry, &lds->active, active) { | 134 | list_for_each_entry(entry, &lds->active, active) { |
110 | crtc = &entry->base.crtc; | 135 | crtc = &entry->base.crtc; |
@@ -120,6 +145,10 @@ static int vmw_ldu_commit_list(struct vmw_private *dev_priv) | |||
120 | i++; | 145 | i++; |
121 | } | 146 | } |
122 | 147 | ||
148 | BUG_ON(i != lds->num_active); | ||
149 | |||
150 | lds->last_num_active = lds->num_active; | ||
151 | |||
123 | return 0; | 152 | return 0; |
124 | } | 153 | } |
125 | 154 | ||
@@ -130,6 +159,7 @@ static int vmw_ldu_del_active(struct vmw_private *vmw_priv, | |||
130 | if (list_empty(&ldu->active)) | 159 | if (list_empty(&ldu->active)) |
131 | return 0; | 160 | return 0; |
132 | 161 | ||
162 | /* Must init otherwise list_empty(&ldu->active) will not work. */ | ||
133 | list_del_init(&ldu->active); | 163 | list_del_init(&ldu->active); |
134 | if (--(ld->num_active) == 0) { | 164 | if (--(ld->num_active) == 0) { |
135 | BUG_ON(!ld->fb); | 165 | BUG_ON(!ld->fb); |
@@ -149,24 +179,29 @@ static int vmw_ldu_add_active(struct vmw_private *vmw_priv, | |||
149 | struct vmw_legacy_display_unit *entry; | 179 | struct vmw_legacy_display_unit *entry; |
150 | struct list_head *at; | 180 | struct list_head *at; |
151 | 181 | ||
182 | BUG_ON(!ld->num_active && ld->fb); | ||
183 | if (vfb != ld->fb) { | ||
184 | if (ld->fb && ld->fb->unpin) | ||
185 | ld->fb->unpin(ld->fb); | ||
186 | if (vfb->pin) | ||
187 | vfb->pin(vfb); | ||
188 | ld->fb = vfb; | ||
189 | } | ||
190 | |||
152 | if (!list_empty(&ldu->active)) | 191 | if (!list_empty(&ldu->active)) |
153 | return 0; | 192 | return 0; |
154 | 193 | ||
155 | at = &ld->active; | 194 | at = &ld->active; |
156 | list_for_each_entry(entry, &ld->active, active) { | 195 | list_for_each_entry(entry, &ld->active, active) { |
157 | if (entry->unit > ldu->unit) | 196 | if (entry->base.unit > ldu->base.unit) |
158 | break; | 197 | break; |
159 | 198 | ||
160 | at = &entry->active; | 199 | at = &entry->active; |
161 | } | 200 | } |
162 | 201 | ||
163 | list_add(&ldu->active, at); | 202 | list_add(&ldu->active, at); |
164 | if (ld->num_active++ == 0) { | 203 | |
165 | BUG_ON(ld->fb); | 204 | ld->num_active++; |
166 | if (vfb->pin) | ||
167 | vfb->pin(vfb); | ||
168 | ld->fb = vfb; | ||
169 | } | ||
170 | 205 | ||
171 | return 0; | 206 | return 0; |
172 | } | 207 | } |
@@ -208,6 +243,8 @@ static int vmw_ldu_crtc_set_config(struct drm_mode_set *set) | |||
208 | 243 | ||
209 | /* ldu only supports one fb active at the time */ | 244 | /* ldu only supports one fb active at the time */ |
210 | if (dev_priv->ldu_priv->fb && vfb && | 245 | if (dev_priv->ldu_priv->fb && vfb && |
246 | !(dev_priv->ldu_priv->num_active == 1 && | ||
247 | !list_empty(&ldu->active)) && | ||
211 | dev_priv->ldu_priv->fb != vfb) { | 248 | dev_priv->ldu_priv->fb != vfb) { |
212 | DRM_ERROR("Multiple framebuffers not supported\n"); | 249 | DRM_ERROR("Multiple framebuffers not supported\n"); |
213 | return -EINVAL; | 250 | return -EINVAL; |
@@ -300,8 +337,7 @@ static void vmw_ldu_connector_restore(struct drm_connector *connector) | |||
300 | static enum drm_connector_status | 337 | static enum drm_connector_status |
301 | vmw_ldu_connector_detect(struct drm_connector *connector) | 338 | vmw_ldu_connector_detect(struct drm_connector *connector) |
302 | { | 339 | { |
303 | /* XXX vmwctrl should control connection status */ | 340 | if (vmw_connector_to_ldu(connector)->pref_active) |
304 | if (vmw_connector_to_ldu(connector)->base.unit == 0) | ||
305 | return connector_status_connected; | 341 | return connector_status_connected; |
306 | return connector_status_disconnected; | 342 | return connector_status_disconnected; |
307 | } | 343 | } |
@@ -312,10 +348,9 @@ static struct drm_display_mode vmw_ldu_connector_builtin[] = { | |||
312 | 752, 800, 0, 480, 489, 492, 525, 0, | 348 | 752, 800, 0, 480, 489, 492, 525, 0, |
313 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, | 349 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
314 | /* 800x600@60Hz */ | 350 | /* 800x600@60Hz */ |
315 | { DRM_MODE("800x600", | 351 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
316 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, | 352 | 968, 1056, 0, 600, 601, 605, 628, 0, |
317 | 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, | 353 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
318 | 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, | ||
319 | /* 1024x768@60Hz */ | 354 | /* 1024x768@60Hz */ |
320 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, | 355 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
321 | 1184, 1344, 0, 768, 771, 777, 806, 0, | 356 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
@@ -387,10 +422,34 @@ static struct drm_display_mode vmw_ldu_connector_builtin[] = { | |||
387 | static int vmw_ldu_connector_fill_modes(struct drm_connector *connector, | 422 | static int vmw_ldu_connector_fill_modes(struct drm_connector *connector, |
388 | uint32_t max_width, uint32_t max_height) | 423 | uint32_t max_width, uint32_t max_height) |
389 | { | 424 | { |
425 | struct vmw_legacy_display_unit *ldu = vmw_connector_to_ldu(connector); | ||
390 | struct drm_device *dev = connector->dev; | 426 | struct drm_device *dev = connector->dev; |
391 | struct drm_display_mode *mode = NULL; | 427 | struct drm_display_mode *mode = NULL; |
428 | struct drm_display_mode prefmode = { DRM_MODE("preferred", | ||
429 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, | ||
430 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
431 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) | ||
432 | }; | ||
392 | int i; | 433 | int i; |
393 | 434 | ||
435 | /* Add preferred mode */ | ||
436 | { | ||
437 | mode = drm_mode_duplicate(dev, &prefmode); | ||
438 | if (!mode) | ||
439 | return 0; | ||
440 | mode->hdisplay = ldu->pref_width; | ||
441 | mode->vdisplay = ldu->pref_height; | ||
442 | mode->vrefresh = drm_mode_vrefresh(mode); | ||
443 | drm_mode_probed_add(connector, mode); | ||
444 | |||
445 | if (ldu->pref_mode) { | ||
446 | list_del_init(&ldu->pref_mode->head); | ||
447 | drm_mode_destroy(dev, ldu->pref_mode); | ||
448 | } | ||
449 | |||
450 | ldu->pref_mode = mode; | ||
451 | } | ||
452 | |||
394 | for (i = 0; vmw_ldu_connector_builtin[i].type != 0; i++) { | 453 | for (i = 0; vmw_ldu_connector_builtin[i].type != 0; i++) { |
395 | if (vmw_ldu_connector_builtin[i].hdisplay > max_width || | 454 | if (vmw_ldu_connector_builtin[i].hdisplay > max_width || |
396 | vmw_ldu_connector_builtin[i].vdisplay > max_height) | 455 | vmw_ldu_connector_builtin[i].vdisplay > max_height) |
@@ -443,18 +502,21 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit) | |||
443 | if (!ldu) | 502 | if (!ldu) |
444 | return -ENOMEM; | 503 | return -ENOMEM; |
445 | 504 | ||
446 | ldu->unit = unit; | 505 | ldu->base.unit = unit; |
447 | crtc = &ldu->base.crtc; | 506 | crtc = &ldu->base.crtc; |
448 | encoder = &ldu->base.encoder; | 507 | encoder = &ldu->base.encoder; |
449 | connector = &ldu->base.connector; | 508 | connector = &ldu->base.connector; |
450 | 509 | ||
510 | INIT_LIST_HEAD(&ldu->active); | ||
511 | |||
512 | ldu->pref_active = (unit == 0); | ||
513 | ldu->pref_width = 800; | ||
514 | ldu->pref_height = 600; | ||
515 | ldu->pref_mode = NULL; | ||
516 | |||
451 | drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, | 517 | drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, |
452 | DRM_MODE_CONNECTOR_LVDS); | 518 | DRM_MODE_CONNECTOR_LVDS); |
453 | /* Initial status */ | 519 | connector->status = vmw_ldu_connector_detect(connector); |
454 | if (unit == 0) | ||
455 | connector->status = connector_status_connected; | ||
456 | else | ||
457 | connector->status = connector_status_disconnected; | ||
458 | 520 | ||
459 | drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs, | 521 | drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs, |
460 | DRM_MODE_ENCODER_LVDS); | 522 | DRM_MODE_ENCODER_LVDS); |
@@ -462,8 +524,6 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit) | |||
462 | encoder->possible_crtcs = (1 << unit); | 524 | encoder->possible_crtcs = (1 << unit); |
463 | encoder->possible_clones = 0; | 525 | encoder->possible_clones = 0; |
464 | 526 | ||
465 | INIT_LIST_HEAD(&ldu->active); | ||
466 | |||
467 | drm_crtc_init(dev, crtc, &vmw_legacy_crtc_funcs); | 527 | drm_crtc_init(dev, crtc, &vmw_legacy_crtc_funcs); |
468 | 528 | ||
469 | drm_connector_attach_property(connector, | 529 | drm_connector_attach_property(connector, |
@@ -487,18 +547,22 @@ int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv) | |||
487 | 547 | ||
488 | INIT_LIST_HEAD(&dev_priv->ldu_priv->active); | 548 | INIT_LIST_HEAD(&dev_priv->ldu_priv->active); |
489 | dev_priv->ldu_priv->num_active = 0; | 549 | dev_priv->ldu_priv->num_active = 0; |
550 | dev_priv->ldu_priv->last_num_active = 0; | ||
490 | dev_priv->ldu_priv->fb = NULL; | 551 | dev_priv->ldu_priv->fb = NULL; |
491 | 552 | ||
492 | drm_mode_create_dirty_info_property(dev_priv->dev); | 553 | drm_mode_create_dirty_info_property(dev_priv->dev); |
493 | 554 | ||
494 | vmw_ldu_init(dev_priv, 0); | 555 | vmw_ldu_init(dev_priv, 0); |
495 | vmw_ldu_init(dev_priv, 1); | 556 | /* for old hardware without multimon only enable one display */ |
496 | vmw_ldu_init(dev_priv, 2); | 557 | if (dev_priv->capabilities & SVGA_CAP_MULTIMON) { |
497 | vmw_ldu_init(dev_priv, 3); | 558 | vmw_ldu_init(dev_priv, 1); |
498 | vmw_ldu_init(dev_priv, 4); | 559 | vmw_ldu_init(dev_priv, 2); |
499 | vmw_ldu_init(dev_priv, 5); | 560 | vmw_ldu_init(dev_priv, 3); |
500 | vmw_ldu_init(dev_priv, 6); | 561 | vmw_ldu_init(dev_priv, 4); |
501 | vmw_ldu_init(dev_priv, 7); | 562 | vmw_ldu_init(dev_priv, 5); |
563 | vmw_ldu_init(dev_priv, 6); | ||
564 | vmw_ldu_init(dev_priv, 7); | ||
565 | } | ||
502 | 566 | ||
503 | return 0; | 567 | return 0; |
504 | } | 568 | } |
@@ -514,3 +578,42 @@ int vmw_kms_close_legacy_display_system(struct vmw_private *dev_priv) | |||
514 | 578 | ||
515 | return 0; | 579 | return 0; |
516 | } | 580 | } |
581 | |||
582 | int vmw_kms_ldu_update_layout(struct vmw_private *dev_priv, unsigned num, | ||
583 | struct drm_vmw_rect *rects) | ||
584 | { | ||
585 | struct drm_device *dev = dev_priv->dev; | ||
586 | struct vmw_legacy_display_unit *ldu; | ||
587 | struct drm_connector *con; | ||
588 | int i; | ||
589 | |||
590 | mutex_lock(&dev->mode_config.mutex); | ||
591 | |||
592 | #if 0 | ||
593 | DRM_INFO("%s: new layout ", __func__); | ||
594 | for (i = 0; i < (int)num; i++) | ||
595 | DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, | ||
596 | rects[i].w, rects[i].h); | ||
597 | DRM_INFO("\n"); | ||
598 | #else | ||
599 | (void)i; | ||
600 | #endif | ||
601 | |||
602 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { | ||
603 | ldu = vmw_connector_to_ldu(con); | ||
604 | if (num > ldu->base.unit) { | ||
605 | ldu->pref_width = rects[ldu->base.unit].w; | ||
606 | ldu->pref_height = rects[ldu->base.unit].h; | ||
607 | ldu->pref_active = true; | ||
608 | } else { | ||
609 | ldu->pref_width = 800; | ||
610 | ldu->pref_height = 600; | ||
611 | ldu->pref_active = false; | ||
612 | } | ||
613 | con->status = vmw_ldu_connector_detect(con); | ||
614 | } | ||
615 | |||
616 | mutex_unlock(&dev->mode_config.mutex); | ||
617 | |||
618 | return 0; | ||
619 | } | ||