vmwgfx_ldu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. uint32_t num_displays;
  273. struct drm_device *dev = connector->dev;
  274. struct vmw_private *dev_priv = vmw_priv(dev);
  275. mutex_lock(&dev_priv->hw_mutex);
  276. num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS);
  277. mutex_unlock(&dev_priv->hw_mutex);
  278. return ((vmw_connector_to_ldu(connector)->base.unit < num_displays) ?
  279. connector_status_connected : connector_status_disconnected);
  280. }
  281. static const struct drm_display_mode vmw_ldu_connector_builtin[] = {
  282. /* 640x480@60Hz */
  283. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  284. 752, 800, 0, 480, 489, 492, 525, 0,
  285. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  286. /* 800x600@60Hz */
  287. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  288. 968, 1056, 0, 600, 601, 605, 628, 0,
  289. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  290. /* 1024x768@60Hz */
  291. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  292. 1184, 1344, 0, 768, 771, 777, 806, 0,
  293. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  294. /* 1152x864@75Hz */
  295. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  296. 1344, 1600, 0, 864, 865, 868, 900, 0,
  297. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  298. /* 1280x768@60Hz */
  299. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
  300. 1472, 1664, 0, 768, 771, 778, 798, 0,
  301. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  302. /* 1280x800@60Hz */
  303. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
  304. 1480, 1680, 0, 800, 803, 809, 831, 0,
  305. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  306. /* 1280x960@60Hz */
  307. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
  308. 1488, 1800, 0, 960, 961, 964, 1000, 0,
  309. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  310. /* 1280x1024@60Hz */
  311. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
  312. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  313. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  314. /* 1360x768@60Hz */
  315. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
  316. 1536, 1792, 0, 768, 771, 777, 795, 0,
  317. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  318. /* 1440x1050@60Hz */
  319. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
  320. 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
  321. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  322. /* 1440x900@60Hz */
  323. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
  324. 1672, 1904, 0, 900, 903, 909, 934, 0,
  325. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  326. /* 1600x1200@60Hz */
  327. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
  328. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  329. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  330. /* 1680x1050@60Hz */
  331. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
  332. 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
  333. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  334. /* 1792x1344@60Hz */
  335. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
  336. 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
  337. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  338. /* 1853x1392@60Hz */
  339. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
  340. 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
  341. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  342. /* 1920x1200@60Hz */
  343. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
  344. 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
  345. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  346. /* 1920x1440@60Hz */
  347. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
  348. 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
  349. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  350. /* 2560x1600@60Hz */
  351. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
  352. 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
  353. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  354. /* Terminate */
  355. { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) },
  356. };
  357. static int vmw_ldu_connector_fill_modes(struct drm_connector *connector,
  358. uint32_t max_width, uint32_t max_height)
  359. {
  360. struct vmw_legacy_display_unit *ldu = vmw_connector_to_ldu(connector);
  361. struct drm_device *dev = connector->dev;
  362. struct vmw_private *dev_priv = vmw_priv(dev);
  363. struct drm_display_mode *mode = NULL;
  364. struct drm_display_mode prefmode = { DRM_MODE("preferred",
  365. DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
  366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  367. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC)
  368. };
  369. int i;
  370. /* Add preferred mode */
  371. {
  372. mode = drm_mode_duplicate(dev, &prefmode);
  373. if (!mode)
  374. return 0;
  375. mode->hdisplay = ldu->pref_width;
  376. mode->vdisplay = ldu->pref_height;
  377. mode->vrefresh = drm_mode_vrefresh(mode);
  378. if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2,
  379. mode->vdisplay)) {
  380. drm_mode_probed_add(connector, mode);
  381. if (ldu->pref_mode) {
  382. list_del_init(&ldu->pref_mode->head);
  383. drm_mode_destroy(dev, ldu->pref_mode);
  384. }
  385. ldu->pref_mode = mode;
  386. }
  387. }
  388. for (i = 0; vmw_ldu_connector_builtin[i].type != 0; i++) {
  389. const struct drm_display_mode *bmode;
  390. bmode = &vmw_ldu_connector_builtin[i];
  391. if (bmode->hdisplay > max_width ||
  392. bmode->vdisplay > max_height)
  393. continue;
  394. if (!vmw_kms_validate_mode_vram(dev_priv, bmode->hdisplay * 2,
  395. bmode->vdisplay))
  396. continue;
  397. mode = drm_mode_duplicate(dev, bmode);
  398. if (!mode)
  399. return 0;
  400. mode->vrefresh = drm_mode_vrefresh(mode);
  401. drm_mode_probed_add(connector, mode);
  402. }
  403. drm_mode_connector_list_update(connector);
  404. return 1;
  405. }
  406. static int vmw_ldu_connector_set_property(struct drm_connector *connector,
  407. struct drm_property *property,
  408. uint64_t val)
  409. {
  410. return 0;
  411. }
  412. static void vmw_ldu_connector_destroy(struct drm_connector *connector)
  413. {
  414. vmw_ldu_destroy(vmw_connector_to_ldu(connector));
  415. }
  416. static struct drm_connector_funcs vmw_legacy_connector_funcs = {
  417. .dpms = vmw_ldu_connector_dpms,
  418. .save = vmw_ldu_connector_save,
  419. .restore = vmw_ldu_connector_restore,
  420. .detect = vmw_ldu_connector_detect,
  421. .fill_modes = vmw_ldu_connector_fill_modes,
  422. .set_property = vmw_ldu_connector_set_property,
  423. .destroy = vmw_ldu_connector_destroy,
  424. };
  425. static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
  426. {
  427. struct vmw_legacy_display_unit *ldu;
  428. struct drm_device *dev = dev_priv->dev;
  429. struct drm_connector *connector;
  430. struct drm_encoder *encoder;
  431. struct drm_crtc *crtc;
  432. ldu = kzalloc(sizeof(*ldu), GFP_KERNEL);
  433. if (!ldu)
  434. return -ENOMEM;
  435. ldu->base.unit = unit;
  436. crtc = &ldu->base.crtc;
  437. encoder = &ldu->base.encoder;
  438. connector = &ldu->base.connector;
  439. INIT_LIST_HEAD(&ldu->active);
  440. ldu->pref_active = (unit == 0);
  441. ldu->pref_width = 800;
  442. ldu->pref_height = 600;
  443. ldu->pref_mode = NULL;
  444. drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
  445. DRM_MODE_CONNECTOR_LVDS);
  446. connector->status = vmw_ldu_connector_detect(connector, true);
  447. drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
  448. DRM_MODE_ENCODER_LVDS);
  449. drm_mode_connector_attach_encoder(connector, encoder);
  450. encoder->possible_crtcs = (1 << unit);
  451. encoder->possible_clones = 0;
  452. drm_crtc_init(dev, crtc, &vmw_legacy_crtc_funcs);
  453. drm_connector_attach_property(connector,
  454. dev->mode_config.dirty_info_property,
  455. 1);
  456. return 0;
  457. }
  458. int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv)
  459. {
  460. struct drm_device *dev = dev_priv->dev;
  461. int i;
  462. int ret;
  463. if (dev_priv->ldu_priv) {
  464. DRM_INFO("ldu system already on\n");
  465. return -EINVAL;
  466. }
  467. dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL);
  468. if (!dev_priv->ldu_priv)
  469. return -ENOMEM;
  470. INIT_LIST_HEAD(&dev_priv->ldu_priv->active);
  471. dev_priv->ldu_priv->num_active = 0;
  472. dev_priv->ldu_priv->last_num_active = 0;
  473. dev_priv->ldu_priv->fb = NULL;
  474. drm_mode_create_dirty_info_property(dev_priv->dev);
  475. if (dev_priv->capabilities & SVGA_CAP_MULTIMON) {
  476. for (i = 0; i < VMWGFX_LDU_NUM_DU; ++i)
  477. vmw_ldu_init(dev_priv, i);
  478. ret = drm_vblank_init(dev, VMWGFX_LDU_NUM_DU);
  479. } else {
  480. /* for old hardware without multimon only enable one display */
  481. vmw_ldu_init(dev_priv, 0);
  482. ret = drm_vblank_init(dev, 1);
  483. }
  484. return ret;
  485. }
  486. int vmw_kms_close_legacy_display_system(struct vmw_private *dev_priv)
  487. {
  488. struct drm_device *dev = dev_priv->dev;
  489. drm_vblank_cleanup(dev);
  490. if (!dev_priv->ldu_priv)
  491. return -ENOSYS;
  492. BUG_ON(!list_empty(&dev_priv->ldu_priv->active));
  493. kfree(dev_priv->ldu_priv);
  494. return 0;
  495. }
  496. int vmw_kms_ldu_update_layout(struct vmw_private *dev_priv, unsigned num,
  497. struct drm_vmw_rect *rects)
  498. {
  499. struct drm_device *dev = dev_priv->dev;
  500. struct vmw_legacy_display_unit *ldu;
  501. struct drm_connector *con;
  502. int i;
  503. mutex_lock(&dev->mode_config.mutex);
  504. #if 0
  505. DRM_INFO("%s: new layout ", __func__);
  506. for (i = 0; i < (int)num; i++)
  507. DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y,
  508. rects[i].w, rects[i].h);
  509. DRM_INFO("\n");
  510. #else
  511. (void)i;
  512. #endif
  513. list_for_each_entry(con, &dev->mode_config.connector_list, head) {
  514. ldu = vmw_connector_to_ldu(con);
  515. if (num > ldu->base.unit) {
  516. ldu->pref_width = rects[ldu->base.unit].w;
  517. ldu->pref_height = rects[ldu->base.unit].h;
  518. ldu->pref_active = true;
  519. } else {
  520. ldu->pref_width = 800;
  521. ldu->pref_height = 600;
  522. ldu->pref_active = false;
  523. }
  524. con->status = vmw_ldu_connector_detect(con, true);
  525. }
  526. mutex_unlock(&dev->mode_config.mutex);
  527. return 0;
  528. }