Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA |
| 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" |
| 29 | |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 30 | #define VMWGFX_LDU_NUM_DU 8 |
| 31 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 32 | #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 | |
| 39 | struct vmw_legacy_display { |
| 40 | struct list_head active; |
| 41 | |
| 42 | unsigned num_active; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 43 | unsigned last_num_active; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 44 | |
| 45 | struct vmw_framebuffer *fb; |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * Display unit using the legacy register interface. |
| 50 | */ |
| 51 | struct vmw_legacy_display_unit { |
| 52 | struct vmw_display_unit base; |
| 53 | |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 54 | unsigned pref_width; |
| 55 | unsigned pref_height; |
| 56 | bool pref_active; |
| 57 | struct drm_display_mode *pref_mode; |
| 58 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 59 | struct list_head active; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu) |
| 63 | { |
| 64 | list_del_init(&ldu->active); |
| 65 | vmw_display_unit_cleanup(&ldu->base); |
| 66 | kfree(ldu); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * Legacy Display Unit CRTC functions |
| 72 | */ |
| 73 | |
| 74 | static void vmw_ldu_crtc_save(struct drm_crtc *crtc) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | static void vmw_ldu_crtc_restore(struct drm_crtc *crtc) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | static void vmw_ldu_crtc_gamma_set(struct drm_crtc *crtc, |
| 83 | u16 *r, u16 *g, u16 *b, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 84 | uint32_t start, uint32_t size) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 85 | { |
Michel Dänzer | f01b7ba | 2011-08-31 07:42:47 +0000 | [diff] [blame] | 86 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 87 | int i; |
| 88 | |
| 89 | for (i = 0; i < size; i++) { |
| 90 | DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i, r[i], g[i], b[i]); |
| 91 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8); |
| 92 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8); |
| 93 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8); |
| 94 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static void vmw_ldu_crtc_destroy(struct drm_crtc *crtc) |
| 98 | { |
| 99 | vmw_ldu_destroy(vmw_crtc_to_ldu(crtc)); |
| 100 | } |
| 101 | |
| 102 | static int vmw_ldu_commit_list(struct vmw_private *dev_priv) |
| 103 | { |
| 104 | struct vmw_legacy_display *lds = dev_priv->ldu_priv; |
| 105 | struct vmw_legacy_display_unit *entry; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 106 | struct drm_framebuffer *fb = NULL; |
| 107 | struct drm_crtc *crtc = NULL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 108 | int i = 0; |
| 109 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 110 | /* If there is no display topology the host just assumes |
| 111 | * that the guest will set the same layout as the host. |
| 112 | */ |
| 113 | if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) { |
| 114 | int w = 0, h = 0; |
| 115 | list_for_each_entry(entry, &lds->active, active) { |
| 116 | crtc = &entry->base.crtc; |
| 117 | w = max(w, crtc->x + crtc->mode.hdisplay); |
| 118 | h = max(h, crtc->y + crtc->mode.vdisplay); |
| 119 | i++; |
| 120 | } |
| 121 | |
| 122 | if (crtc == NULL) |
| 123 | return 0; |
| 124 | fb = entry->base.crtc.fb; |
| 125 | |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 126 | return vmw_kms_write_svga(dev_priv, w, h, fb->pitch, |
| 127 | fb->bits_per_pixel, fb->depth); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 130 | if (!list_empty(&lds->active)) { |
| 131 | entry = list_entry(lds->active.next, typeof(*entry), active); |
| 132 | fb = entry->base.crtc.fb; |
| 133 | |
| 134 | vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitch, |
| 135 | fb->bits_per_pixel, fb->depth); |
| 136 | } |
| 137 | |
Jakob Bornecrantz | 259600d5 | 2010-05-28 11:22:03 +0200 | [diff] [blame] | 138 | /* Make sure we always show something. */ |
| 139 | vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS, |
| 140 | lds->num_active ? lds->num_active : 1); |
| 141 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 142 | i = 0; |
| 143 | list_for_each_entry(entry, &lds->active, active) { |
| 144 | crtc = &entry->base.crtc; |
| 145 | |
| 146 | vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i); |
| 147 | vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i); |
| 148 | vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, crtc->x); |
| 149 | vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, crtc->y); |
| 150 | vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, crtc->mode.hdisplay); |
| 151 | vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, crtc->mode.vdisplay); |
| 152 | vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 153 | |
| 154 | i++; |
| 155 | } |
| 156 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 157 | BUG_ON(i != lds->num_active); |
| 158 | |
| 159 | lds->last_num_active = lds->num_active; |
| 160 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static int vmw_ldu_del_active(struct vmw_private *vmw_priv, |
| 165 | struct vmw_legacy_display_unit *ldu) |
| 166 | { |
| 167 | struct vmw_legacy_display *ld = vmw_priv->ldu_priv; |
| 168 | if (list_empty(&ldu->active)) |
| 169 | return 0; |
| 170 | |
Jakob Bornecrantz | 6a591a9 | 2010-05-28 11:21:55 +0200 | [diff] [blame] | 171 | /* Must init otherwise list_empty(&ldu->active) will not work. */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 172 | list_del_init(&ldu->active); |
| 173 | if (--(ld->num_active) == 0) { |
| 174 | BUG_ON(!ld->fb); |
| 175 | if (ld->fb->unpin) |
| 176 | ld->fb->unpin(ld->fb); |
| 177 | ld->fb = NULL; |
| 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | static int vmw_ldu_add_active(struct vmw_private *vmw_priv, |
| 184 | struct vmw_legacy_display_unit *ldu, |
| 185 | struct vmw_framebuffer *vfb) |
| 186 | { |
| 187 | struct vmw_legacy_display *ld = vmw_priv->ldu_priv; |
| 188 | struct vmw_legacy_display_unit *entry; |
| 189 | struct list_head *at; |
| 190 | |
Jakob Bornecrantz | 04e9e94 | 2010-05-28 11:21:56 +0200 | [diff] [blame] | 191 | BUG_ON(!ld->num_active && ld->fb); |
| 192 | if (vfb != ld->fb) { |
| 193 | if (ld->fb && ld->fb->unpin) |
| 194 | ld->fb->unpin(ld->fb); |
| 195 | if (vfb->pin) |
| 196 | vfb->pin(vfb); |
| 197 | ld->fb = vfb; |
| 198 | } |
| 199 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 200 | if (!list_empty(&ldu->active)) |
| 201 | return 0; |
| 202 | |
| 203 | at = &ld->active; |
| 204 | list_for_each_entry(entry, &ld->active, active) { |
Jakob Bornecrantz | bbfad33 | 2010-05-28 11:22:01 +0200 | [diff] [blame] | 205 | if (entry->base.unit > ldu->base.unit) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 206 | break; |
| 207 | |
| 208 | at = &entry->active; |
| 209 | } |
| 210 | |
| 211 | list_add(&ldu->active, at); |
Jakob Bornecrantz | 04e9e94 | 2010-05-28 11:21:56 +0200 | [diff] [blame] | 212 | |
| 213 | ld->num_active++; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int vmw_ldu_crtc_set_config(struct drm_mode_set *set) |
| 219 | { |
| 220 | struct vmw_private *dev_priv; |
| 221 | struct vmw_legacy_display_unit *ldu; |
| 222 | struct drm_connector *connector; |
| 223 | struct drm_display_mode *mode; |
| 224 | struct drm_encoder *encoder; |
| 225 | struct vmw_framebuffer *vfb; |
| 226 | struct drm_framebuffer *fb; |
| 227 | struct drm_crtc *crtc; |
| 228 | |
| 229 | if (!set) |
| 230 | return -EINVAL; |
| 231 | |
| 232 | if (!set->crtc) |
| 233 | return -EINVAL; |
| 234 | |
| 235 | /* get the ldu */ |
| 236 | crtc = set->crtc; |
| 237 | ldu = vmw_crtc_to_ldu(crtc); |
| 238 | vfb = set->fb ? vmw_framebuffer_to_vfb(set->fb) : NULL; |
| 239 | dev_priv = vmw_priv(crtc->dev); |
| 240 | |
| 241 | if (set->num_connectors > 1) { |
| 242 | DRM_ERROR("to many connectors\n"); |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | |
| 246 | if (set->num_connectors == 1 && |
| 247 | set->connectors[0] != &ldu->base.connector) { |
| 248 | DRM_ERROR("connector doesn't match %p %p\n", |
| 249 | set->connectors[0], &ldu->base.connector); |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | |
| 253 | /* ldu only supports one fb active at the time */ |
| 254 | if (dev_priv->ldu_priv->fb && vfb && |
Jakob Bornecrantz | 6a591a9 | 2010-05-28 11:21:55 +0200 | [diff] [blame] | 255 | !(dev_priv->ldu_priv->num_active == 1 && |
| 256 | !list_empty(&ldu->active)) && |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 257 | dev_priv->ldu_priv->fb != vfb) { |
| 258 | DRM_ERROR("Multiple framebuffers not supported\n"); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
| 262 | /* since they always map one to one these are safe */ |
| 263 | connector = &ldu->base.connector; |
| 264 | encoder = &ldu->base.encoder; |
| 265 | |
| 266 | /* should we turn the crtc off? */ |
| 267 | if (set->num_connectors == 0 || !set->mode || !set->fb) { |
| 268 | |
| 269 | connector->encoder = NULL; |
| 270 | encoder->crtc = NULL; |
| 271 | crtc->fb = NULL; |
| 272 | |
| 273 | vmw_ldu_del_active(dev_priv, ldu); |
| 274 | |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 275 | return vmw_ldu_commit_list(dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
| 279 | /* we now know we want to set a mode */ |
| 280 | mode = set->mode; |
| 281 | fb = set->fb; |
| 282 | |
| 283 | if (set->x + mode->hdisplay > fb->width || |
| 284 | set->y + mode->vdisplay > fb->height) { |
| 285 | DRM_ERROR("set outside of framebuffer\n"); |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | |
| 289 | vmw_fb_off(dev_priv); |
| 290 | |
| 291 | crtc->fb = fb; |
| 292 | encoder->crtc = crtc; |
| 293 | connector->encoder = encoder; |
| 294 | crtc->x = set->x; |
| 295 | crtc->y = set->y; |
| 296 | crtc->mode = *mode; |
| 297 | |
| 298 | vmw_ldu_add_active(dev_priv, ldu, vfb); |
| 299 | |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 300 | return vmw_ldu_commit_list(dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static struct drm_crtc_funcs vmw_legacy_crtc_funcs = { |
| 304 | .save = vmw_ldu_crtc_save, |
| 305 | .restore = vmw_ldu_crtc_restore, |
| 306 | .cursor_set = vmw_du_crtc_cursor_set, |
| 307 | .cursor_move = vmw_du_crtc_cursor_move, |
| 308 | .gamma_set = vmw_ldu_crtc_gamma_set, |
| 309 | .destroy = vmw_ldu_crtc_destroy, |
| 310 | .set_config = vmw_ldu_crtc_set_config, |
| 311 | }; |
| 312 | |
| 313 | /* |
| 314 | * Legacy Display Unit encoder functions |
| 315 | */ |
| 316 | |
| 317 | static void vmw_ldu_encoder_destroy(struct drm_encoder *encoder) |
| 318 | { |
| 319 | vmw_ldu_destroy(vmw_encoder_to_ldu(encoder)); |
| 320 | } |
| 321 | |
| 322 | static struct drm_encoder_funcs vmw_legacy_encoder_funcs = { |
| 323 | .destroy = vmw_ldu_encoder_destroy, |
| 324 | }; |
| 325 | |
| 326 | /* |
| 327 | * Legacy Display Unit connector functions |
| 328 | */ |
| 329 | |
| 330 | static void vmw_ldu_connector_dpms(struct drm_connector *connector, int mode) |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | static void vmw_ldu_connector_save(struct drm_connector *connector) |
| 335 | { |
| 336 | } |
| 337 | |
| 338 | static void vmw_ldu_connector_restore(struct drm_connector *connector) |
| 339 | { |
| 340 | } |
| 341 | |
| 342 | static enum drm_connector_status |
Chris Wilson | 7b334fc | 2010-09-09 23:51:02 +0100 | [diff] [blame] | 343 | vmw_ldu_connector_detect(struct drm_connector *connector, |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 344 | bool force) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 345 | { |
Thomas Hellstrom | 654a4ef | 2011-08-31 07:13:40 +0000 | [diff] [blame] | 346 | uint32_t num_displays; |
| 347 | struct drm_device *dev = connector->dev; |
| 348 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 349 | |
| 350 | mutex_lock(&dev_priv->hw_mutex); |
| 351 | num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); |
| 352 | mutex_unlock(&dev_priv->hw_mutex); |
| 353 | |
| 354 | return ((vmw_connector_to_ldu(connector)->base.unit < num_displays) ? |
| 355 | connector_status_connected : connector_status_disconnected); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Chris Wilson | b1f559e | 2011-01-26 09:49:47 +0000 | [diff] [blame] | 358 | static const struct drm_display_mode vmw_ldu_connector_builtin[] = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 359 | /* 640x480@60Hz */ |
| 360 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 361 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 362 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 363 | /* 800x600@60Hz */ |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 364 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
| 365 | 968, 1056, 0, 600, 601, 605, 628, 0, |
| 366 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 367 | /* 1024x768@60Hz */ |
| 368 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
| 369 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
| 370 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 371 | /* 1152x864@75Hz */ |
| 372 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
| 373 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
| 374 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 375 | /* 1280x768@60Hz */ |
| 376 | { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344, |
| 377 | 1472, 1664, 0, 768, 771, 778, 798, 0, |
| 378 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 379 | /* 1280x800@60Hz */ |
| 380 | { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352, |
| 381 | 1480, 1680, 0, 800, 803, 809, 831, 0, |
| 382 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 383 | /* 1280x960@60Hz */ |
| 384 | { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376, |
| 385 | 1488, 1800, 0, 960, 961, 964, 1000, 0, |
| 386 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 387 | /* 1280x1024@60Hz */ |
| 388 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328, |
| 389 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
| 390 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 391 | /* 1360x768@60Hz */ |
| 392 | { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424, |
| 393 | 1536, 1792, 0, 768, 771, 777, 795, 0, |
| 394 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 395 | /* 1440x1050@60Hz */ |
| 396 | { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488, |
| 397 | 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, |
| 398 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 399 | /* 1440x900@60Hz */ |
| 400 | { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520, |
| 401 | 1672, 1904, 0, 900, 903, 909, 934, 0, |
| 402 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 403 | /* 1600x1200@60Hz */ |
| 404 | { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664, |
| 405 | 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, |
| 406 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 407 | /* 1680x1050@60Hz */ |
| 408 | { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784, |
| 409 | 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, |
| 410 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 411 | /* 1792x1344@60Hz */ |
| 412 | { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920, |
| 413 | 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, |
| 414 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 415 | /* 1853x1392@60Hz */ |
| 416 | { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952, |
| 417 | 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, |
| 418 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 419 | /* 1920x1200@60Hz */ |
| 420 | { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056, |
| 421 | 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, |
| 422 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 423 | /* 1920x1440@60Hz */ |
| 424 | { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048, |
| 425 | 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, |
| 426 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 427 | /* 2560x1600@60Hz */ |
| 428 | { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752, |
| 429 | 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, |
| 430 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 431 | /* Terminate */ |
| 432 | { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, |
| 433 | }; |
| 434 | |
| 435 | static int vmw_ldu_connector_fill_modes(struct drm_connector *connector, |
| 436 | uint32_t max_width, uint32_t max_height) |
| 437 | { |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 438 | struct vmw_legacy_display_unit *ldu = vmw_connector_to_ldu(connector); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 439 | struct drm_device *dev = connector->dev; |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 440 | struct vmw_private *dev_priv = vmw_priv(dev); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 441 | struct drm_display_mode *mode = NULL; |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 442 | struct drm_display_mode prefmode = { DRM_MODE("preferred", |
| 443 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, |
| 444 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 445 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) |
| 446 | }; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 447 | int i; |
| 448 | |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 449 | /* Add preferred mode */ |
| 450 | { |
| 451 | mode = drm_mode_duplicate(dev, &prefmode); |
| 452 | if (!mode) |
| 453 | return 0; |
| 454 | mode->hdisplay = ldu->pref_width; |
| 455 | mode->vdisplay = ldu->pref_height; |
| 456 | mode->vrefresh = drm_mode_vrefresh(mode); |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 457 | if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2, |
| 458 | mode->vdisplay)) { |
| 459 | drm_mode_probed_add(connector, mode); |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 460 | |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 461 | if (ldu->pref_mode) { |
| 462 | list_del_init(&ldu->pref_mode->head); |
| 463 | drm_mode_destroy(dev, ldu->pref_mode); |
| 464 | } |
| 465 | |
| 466 | ldu->pref_mode = mode; |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 467 | } |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 470 | for (i = 0; vmw_ldu_connector_builtin[i].type != 0; i++) { |
Chris Wilson | b1f559e | 2011-01-26 09:49:47 +0000 | [diff] [blame] | 471 | const struct drm_display_mode *bmode; |
| 472 | |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 473 | bmode = &vmw_ldu_connector_builtin[i]; |
| 474 | if (bmode->hdisplay > max_width || |
| 475 | bmode->vdisplay > max_height) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 476 | continue; |
| 477 | |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 478 | if (!vmw_kms_validate_mode_vram(dev_priv, bmode->hdisplay * 2, |
| 479 | bmode->vdisplay)) |
| 480 | continue; |
| 481 | |
| 482 | mode = drm_mode_duplicate(dev, bmode); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 483 | if (!mode) |
| 484 | return 0; |
| 485 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 486 | |
| 487 | drm_mode_probed_add(connector, mode); |
| 488 | } |
| 489 | |
| 490 | drm_mode_connector_list_update(connector); |
| 491 | |
| 492 | return 1; |
| 493 | } |
| 494 | |
| 495 | static int vmw_ldu_connector_set_property(struct drm_connector *connector, |
| 496 | struct drm_property *property, |
| 497 | uint64_t val) |
| 498 | { |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | static void vmw_ldu_connector_destroy(struct drm_connector *connector) |
| 503 | { |
| 504 | vmw_ldu_destroy(vmw_connector_to_ldu(connector)); |
| 505 | } |
| 506 | |
| 507 | static struct drm_connector_funcs vmw_legacy_connector_funcs = { |
| 508 | .dpms = vmw_ldu_connector_dpms, |
| 509 | .save = vmw_ldu_connector_save, |
| 510 | .restore = vmw_ldu_connector_restore, |
| 511 | .detect = vmw_ldu_connector_detect, |
| 512 | .fill_modes = vmw_ldu_connector_fill_modes, |
| 513 | .set_property = vmw_ldu_connector_set_property, |
| 514 | .destroy = vmw_ldu_connector_destroy, |
| 515 | }; |
| 516 | |
| 517 | static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit) |
| 518 | { |
| 519 | struct vmw_legacy_display_unit *ldu; |
| 520 | struct drm_device *dev = dev_priv->dev; |
| 521 | struct drm_connector *connector; |
| 522 | struct drm_encoder *encoder; |
| 523 | struct drm_crtc *crtc; |
| 524 | |
| 525 | ldu = kzalloc(sizeof(*ldu), GFP_KERNEL); |
| 526 | if (!ldu) |
| 527 | return -ENOMEM; |
| 528 | |
Jakob Bornecrantz | bbfad33 | 2010-05-28 11:22:01 +0200 | [diff] [blame] | 529 | ldu->base.unit = unit; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 530 | crtc = &ldu->base.crtc; |
| 531 | encoder = &ldu->base.encoder; |
| 532 | connector = &ldu->base.connector; |
| 533 | |
Jakob Bornecrantz | 1ae1ddd | 2010-05-28 11:21:58 +0200 | [diff] [blame] | 534 | INIT_LIST_HEAD(&ldu->active); |
| 535 | |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 536 | ldu->pref_active = (unit == 0); |
| 537 | ldu->pref_width = 800; |
| 538 | ldu->pref_height = 600; |
| 539 | ldu->pref_mode = NULL; |
| 540 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 541 | drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, |
| 542 | DRM_MODE_CONNECTOR_LVDS); |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 543 | connector->status = vmw_ldu_connector_detect(connector, true); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 544 | |
| 545 | drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs, |
| 546 | DRM_MODE_ENCODER_LVDS); |
| 547 | drm_mode_connector_attach_encoder(connector, encoder); |
| 548 | encoder->possible_crtcs = (1 << unit); |
| 549 | encoder->possible_clones = 0; |
| 550 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 551 | drm_crtc_init(dev, crtc, &vmw_legacy_crtc_funcs); |
| 552 | |
Michel Dänzer | f01b7ba | 2011-08-31 07:42:47 +0000 | [diff] [blame] | 553 | drm_mode_crtc_set_gamma_size(crtc, 256); |
| 554 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 555 | drm_connector_attach_property(connector, |
| 556 | dev->mode_config.dirty_info_property, |
| 557 | 1); |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv) |
| 563 | { |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 564 | struct drm_device *dev = dev_priv->dev; |
| 565 | int i; |
| 566 | int ret; |
| 567 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 568 | if (dev_priv->ldu_priv) { |
| 569 | DRM_INFO("ldu system already on\n"); |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
Joe Perches | 85b54e0 | 2010-10-31 22:33:53 +0000 | [diff] [blame] | 573 | dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 574 | |
| 575 | if (!dev_priv->ldu_priv) |
| 576 | return -ENOMEM; |
| 577 | |
| 578 | INIT_LIST_HEAD(&dev_priv->ldu_priv->active); |
| 579 | dev_priv->ldu_priv->num_active = 0; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 580 | dev_priv->ldu_priv->last_num_active = 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 581 | dev_priv->ldu_priv->fb = NULL; |
| 582 | |
| 583 | drm_mode_create_dirty_info_property(dev_priv->dev); |
| 584 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 585 | if (dev_priv->capabilities & SVGA_CAP_MULTIMON) { |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 586 | for (i = 0; i < VMWGFX_LDU_NUM_DU; ++i) |
| 587 | vmw_ldu_init(dev_priv, i); |
| 588 | ret = drm_vblank_init(dev, VMWGFX_LDU_NUM_DU); |
| 589 | } else { |
| 590 | /* for old hardware without multimon only enable one display */ |
| 591 | vmw_ldu_init(dev_priv, 0); |
| 592 | ret = drm_vblank_init(dev, 1); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 593 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 594 | |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 595 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | int vmw_kms_close_legacy_display_system(struct vmw_private *dev_priv) |
| 599 | { |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 600 | struct drm_device *dev = dev_priv->dev; |
| 601 | |
| 602 | drm_vblank_cleanup(dev); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 603 | if (!dev_priv->ldu_priv) |
| 604 | return -ENOSYS; |
| 605 | |
| 606 | BUG_ON(!list_empty(&dev_priv->ldu_priv->active)); |
| 607 | |
| 608 | kfree(dev_priv->ldu_priv); |
| 609 | |
| 610 | return 0; |
| 611 | } |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 612 | |
| 613 | int vmw_kms_ldu_update_layout(struct vmw_private *dev_priv, unsigned num, |
| 614 | struct drm_vmw_rect *rects) |
| 615 | { |
| 616 | struct drm_device *dev = dev_priv->dev; |
| 617 | struct vmw_legacy_display_unit *ldu; |
| 618 | struct drm_connector *con; |
| 619 | int i; |
| 620 | |
| 621 | mutex_lock(&dev->mode_config.mutex); |
| 622 | |
| 623 | #if 0 |
| 624 | DRM_INFO("%s: new layout ", __func__); |
| 625 | for (i = 0; i < (int)num; i++) |
| 626 | DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, |
| 627 | rects[i].w, rects[i].h); |
| 628 | DRM_INFO("\n"); |
| 629 | #else |
| 630 | (void)i; |
| 631 | #endif |
| 632 | |
| 633 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { |
| 634 | ldu = vmw_connector_to_ldu(con); |
| 635 | if (num > ldu->base.unit) { |
| 636 | ldu->pref_width = rects[ldu->base.unit].w; |
| 637 | ldu->pref_height = rects[ldu->base.unit].h; |
| 638 | ldu->pref_active = true; |
| 639 | } else { |
| 640 | ldu->pref_width = 800; |
| 641 | ldu->pref_height = 600; |
| 642 | ldu->pref_active = false; |
| 643 | } |
Chris Wilson | 930a9e2 | 2010-09-14 11:07:23 +0100 | [diff] [blame] | 644 | con->status = vmw_ldu_connector_detect(con, true); |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | mutex_unlock(&dev->mode_config.mutex); |
| 648 | |
| 649 | return 0; |
| 650 | } |