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