vmwgfx_ldu.c 17 KB

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