vmwgfx_stdu.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /******************************************************************************
  2. *
  3. * COPYRIGHT © 2014-2015 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. #include "device_include/svga3d_surfacedefs.h"
  29. #include <drm/drm_plane_helper.h>
  30. #define vmw_crtc_to_stdu(x) \
  31. container_of(x, struct vmw_screen_target_display_unit, base.crtc)
  32. #define vmw_encoder_to_stdu(x) \
  33. container_of(x, struct vmw_screen_target_display_unit, base.encoder)
  34. #define vmw_connector_to_stdu(x) \
  35. container_of(x, struct vmw_screen_target_display_unit, base.connector)
  36. enum stdu_content_type {
  37. SAME_AS_DISPLAY = 0,
  38. SEPARATE_SURFACE,
  39. SEPARATE_DMA
  40. };
  41. /**
  42. * struct vmw_stdu_dirty - closure structure for the update functions
  43. *
  44. * @base: The base type we derive from. Used by vmw_kms_helper_dirty().
  45. * @transfer: Transfer direction for DMA command.
  46. * @left: Left side of bounding box.
  47. * @right: Right side of bounding box.
  48. * @top: Top side of bounding box.
  49. * @bottom: Bottom side of bounding box.
  50. * @buf: DMA buffer when DMA-ing between buffer and screen targets.
  51. * @sid: Surface ID when copying between surface and screen targets.
  52. */
  53. struct vmw_stdu_dirty {
  54. struct vmw_kms_dirty base;
  55. SVGA3dTransferType transfer;
  56. s32 left, right, top, bottom;
  57. u32 pitch;
  58. union {
  59. struct vmw_dma_buffer *buf;
  60. u32 sid;
  61. };
  62. };
  63. /*
  64. * SVGA commands that are used by this code. Please see the device headers
  65. * for explanation.
  66. */
  67. struct vmw_stdu_update {
  68. SVGA3dCmdHeader header;
  69. SVGA3dCmdUpdateGBScreenTarget body;
  70. };
  71. struct vmw_stdu_dma {
  72. SVGA3dCmdHeader header;
  73. SVGA3dCmdSurfaceDMA body;
  74. };
  75. struct vmw_stdu_surface_copy {
  76. SVGA3dCmdHeader header;
  77. SVGA3dCmdSurfaceCopy body;
  78. };
  79. /**
  80. * struct vmw_screen_target_display_unit
  81. *
  82. * @base: VMW specific DU structure
  83. * @display_srf: surface to be displayed. The dimension of this will always
  84. * match the display mode. If the display mode matches
  85. * content_vfbs dimensions, then this is a pointer into the
  86. * corresponding field in content_vfbs. If not, then this
  87. * is a separate buffer to which content_vfbs will blit to.
  88. * @content_fb: holds the rendered content, can be a surface or DMA buffer
  89. * @content_type: content_fb type
  90. * @defined: true if the current display unit has been initialized
  91. */
  92. struct vmw_screen_target_display_unit {
  93. struct vmw_display_unit base;
  94. struct vmw_surface *display_srf;
  95. struct drm_framebuffer *content_fb;
  96. enum stdu_content_type content_fb_type;
  97. bool defined;
  98. };
  99. static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu);
  100. /******************************************************************************
  101. * Screen Target Display Unit helper Functions
  102. *****************************************************************************/
  103. /**
  104. * vmw_stdu_pin_display - pins the resource associated with the display surface
  105. *
  106. * @stdu: contains the display surface
  107. *
  108. * Since the display surface can either be a private surface allocated by us,
  109. * or it can point to the content surface, we use this function to not pin the
  110. * same resource twice.
  111. */
  112. static int vmw_stdu_pin_display(struct vmw_screen_target_display_unit *stdu)
  113. {
  114. return vmw_resource_pin(&stdu->display_srf->res, false);
  115. }
  116. /**
  117. * vmw_stdu_unpin_display - unpins the resource associated with display surface
  118. *
  119. * @stdu: contains the display surface
  120. *
  121. * If the display surface was privatedly allocated by
  122. * vmw_surface_gb_priv_define() and not registered as a framebuffer, then it
  123. * won't be automatically cleaned up when all the framebuffers are freed. As
  124. * such, we have to explicitly call vmw_resource_unreference() to get it freed.
  125. */
  126. static void vmw_stdu_unpin_display(struct vmw_screen_target_display_unit *stdu)
  127. {
  128. if (stdu->display_srf) {
  129. struct vmw_resource *res = &stdu->display_srf->res;
  130. vmw_resource_unpin(res);
  131. if (stdu->content_fb_type != SAME_AS_DISPLAY) {
  132. vmw_resource_unreference(&res);
  133. stdu->content_fb_type = SAME_AS_DISPLAY;
  134. }
  135. stdu->display_srf = NULL;
  136. }
  137. }
  138. /******************************************************************************
  139. * Screen Target Display Unit CRTC Functions
  140. *****************************************************************************/
  141. /**
  142. * vmw_stdu_crtc_destroy - cleans up the STDU
  143. *
  144. * @crtc: used to get a reference to the containing STDU
  145. */
  146. static void vmw_stdu_crtc_destroy(struct drm_crtc *crtc)
  147. {
  148. vmw_stdu_destroy(vmw_crtc_to_stdu(crtc));
  149. }
  150. /**
  151. * vmw_stdu_define_st - Defines a Screen Target
  152. *
  153. * @dev_priv: VMW DRM device
  154. * @stdu: display unit to create a Screen Target for
  155. *
  156. * Creates a STDU that we can used later. This function is called whenever the
  157. * framebuffer size changes.
  158. *
  159. * RETURNs:
  160. * 0 on success, error code on failure
  161. */
  162. static int vmw_stdu_define_st(struct vmw_private *dev_priv,
  163. struct vmw_screen_target_display_unit *stdu)
  164. {
  165. struct {
  166. SVGA3dCmdHeader header;
  167. SVGA3dCmdDefineGBScreenTarget body;
  168. } *cmd;
  169. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  170. if (unlikely(cmd == NULL)) {
  171. DRM_ERROR("Out of FIFO space defining Screen Target\n");
  172. return -ENOMEM;
  173. }
  174. cmd->header.id = SVGA_3D_CMD_DEFINE_GB_SCREENTARGET;
  175. cmd->header.size = sizeof(cmd->body);
  176. cmd->body.stid = stdu->base.unit;
  177. cmd->body.width = stdu->display_srf->base_size.width;
  178. cmd->body.height = stdu->display_srf->base_size.height;
  179. cmd->body.flags = (0 == cmd->body.stid) ? SVGA_STFLAG_PRIMARY : 0;
  180. cmd->body.dpi = 0;
  181. cmd->body.xRoot = stdu->base.crtc.x;
  182. cmd->body.yRoot = stdu->base.crtc.y;
  183. if (!stdu->base.is_implicit) {
  184. cmd->body.xRoot = stdu->base.gui_x;
  185. cmd->body.yRoot = stdu->base.gui_y;
  186. }
  187. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  188. stdu->defined = true;
  189. return 0;
  190. }
  191. /**
  192. * vmw_stdu_bind_st - Binds a surface to a Screen Target
  193. *
  194. * @dev_priv: VMW DRM device
  195. * @stdu: display unit affected
  196. * @res: Buffer to bind to the screen target. Set to NULL to blank screen.
  197. *
  198. * Binding a surface to a Screen Target the same as flipping
  199. */
  200. static int vmw_stdu_bind_st(struct vmw_private *dev_priv,
  201. struct vmw_screen_target_display_unit *stdu,
  202. struct vmw_resource *res)
  203. {
  204. SVGA3dSurfaceImageId image;
  205. struct {
  206. SVGA3dCmdHeader header;
  207. SVGA3dCmdBindGBScreenTarget body;
  208. } *cmd;
  209. if (!stdu->defined) {
  210. DRM_ERROR("No screen target defined\n");
  211. return -EINVAL;
  212. }
  213. /* Set up image using information in vfb */
  214. memset(&image, 0, sizeof(image));
  215. image.sid = res ? res->id : SVGA3D_INVALID_ID;
  216. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  217. if (unlikely(cmd == NULL)) {
  218. DRM_ERROR("Out of FIFO space binding a screen target\n");
  219. return -ENOMEM;
  220. }
  221. cmd->header.id = SVGA_3D_CMD_BIND_GB_SCREENTARGET;
  222. cmd->header.size = sizeof(cmd->body);
  223. cmd->body.stid = stdu->base.unit;
  224. cmd->body.image = image;
  225. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  226. return 0;
  227. }
  228. /**
  229. * vmw_stdu_populate_update - populate an UPDATE_GB_SCREENTARGET command with a
  230. * bounding box.
  231. *
  232. * @cmd: Pointer to command stream.
  233. * @unit: Screen target unit.
  234. * @left: Left side of bounding box.
  235. * @right: Right side of bounding box.
  236. * @top: Top side of bounding box.
  237. * @bottom: Bottom side of bounding box.
  238. */
  239. static void vmw_stdu_populate_update(void *cmd, int unit,
  240. s32 left, s32 right, s32 top, s32 bottom)
  241. {
  242. struct vmw_stdu_update *update = cmd;
  243. update->header.id = SVGA_3D_CMD_UPDATE_GB_SCREENTARGET;
  244. update->header.size = sizeof(update->body);
  245. update->body.stid = unit;
  246. update->body.rect.x = left;
  247. update->body.rect.y = top;
  248. update->body.rect.w = right - left;
  249. update->body.rect.h = bottom - top;
  250. }
  251. /**
  252. * vmw_stdu_update_st - Full update of a Screen Target
  253. *
  254. * @dev_priv: VMW DRM device
  255. * @stdu: display unit affected
  256. *
  257. * This function needs to be called whenever the content of a screen
  258. * target has changed completely. Typically as a result of a backing
  259. * surface change.
  260. *
  261. * RETURNS:
  262. * 0 on success, error code on failure
  263. */
  264. static int vmw_stdu_update_st(struct vmw_private *dev_priv,
  265. struct vmw_screen_target_display_unit *stdu)
  266. {
  267. struct vmw_stdu_update *cmd;
  268. struct drm_crtc *crtc = &stdu->base.crtc;
  269. if (!stdu->defined) {
  270. DRM_ERROR("No screen target defined");
  271. return -EINVAL;
  272. }
  273. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  274. if (unlikely(cmd == NULL)) {
  275. DRM_ERROR("Out of FIFO space updating a Screen Target\n");
  276. return -ENOMEM;
  277. }
  278. vmw_stdu_populate_update(cmd, stdu->base.unit, 0, crtc->mode.hdisplay,
  279. 0, crtc->mode.vdisplay);
  280. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  281. return 0;
  282. }
  283. /**
  284. * vmw_stdu_destroy_st - Destroy a Screen Target
  285. *
  286. * @dev_priv: VMW DRM device
  287. * @stdu: display unit to destroy
  288. */
  289. static int vmw_stdu_destroy_st(struct vmw_private *dev_priv,
  290. struct vmw_screen_target_display_unit *stdu)
  291. {
  292. int ret;
  293. struct {
  294. SVGA3dCmdHeader header;
  295. SVGA3dCmdDestroyGBScreenTarget body;
  296. } *cmd;
  297. /* Nothing to do if not successfully defined */
  298. if (unlikely(!stdu->defined))
  299. return 0;
  300. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  301. if (unlikely(cmd == NULL)) {
  302. DRM_ERROR("Out of FIFO space, screen target not destroyed\n");
  303. return -ENOMEM;
  304. }
  305. cmd->header.id = SVGA_3D_CMD_DESTROY_GB_SCREENTARGET;
  306. cmd->header.size = sizeof(cmd->body);
  307. cmd->body.stid = stdu->base.unit;
  308. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  309. /* Force sync */
  310. ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ);
  311. if (unlikely(ret != 0))
  312. DRM_ERROR("Failed to sync with HW");
  313. stdu->defined = false;
  314. return ret;
  315. }
  316. /**
  317. * vmw_stdu_crtc_set_config - Sets a mode
  318. *
  319. * @set: mode parameters
  320. *
  321. * This function is the device-specific portion of the DRM CRTC mode set.
  322. * For the SVGA device, we do this by defining a Screen Target, binding a
  323. * GB Surface to that target, and finally update the screen target.
  324. *
  325. * RETURNS:
  326. * 0 on success, error code otherwise
  327. */
  328. static int vmw_stdu_crtc_set_config(struct drm_mode_set *set)
  329. {
  330. struct vmw_private *dev_priv;
  331. struct vmw_screen_target_display_unit *stdu;
  332. struct vmw_framebuffer *vfb;
  333. struct vmw_framebuffer_surface *new_vfbs;
  334. struct drm_display_mode *mode;
  335. struct drm_framebuffer *new_fb;
  336. struct drm_crtc *crtc;
  337. struct drm_encoder *encoder;
  338. struct drm_connector *connector;
  339. int ret;
  340. if (!set || !set->crtc)
  341. return -EINVAL;
  342. crtc = set->crtc;
  343. crtc->x = set->x;
  344. crtc->y = set->y;
  345. stdu = vmw_crtc_to_stdu(crtc);
  346. mode = set->mode;
  347. new_fb = set->fb;
  348. dev_priv = vmw_priv(crtc->dev);
  349. if (set->num_connectors > 1) {
  350. DRM_ERROR("Too many connectors\n");
  351. return -EINVAL;
  352. }
  353. if (set->num_connectors == 1 &&
  354. set->connectors[0] != &stdu->base.connector) {
  355. DRM_ERROR("Connectors don't match %p %p\n",
  356. set->connectors[0], &stdu->base.connector);
  357. return -EINVAL;
  358. }
  359. /* Since they always map one to one these are safe */
  360. connector = &stdu->base.connector;
  361. encoder = &stdu->base.encoder;
  362. /*
  363. * After this point the CRTC will be considered off unless a new fb
  364. * is bound
  365. */
  366. if (stdu->defined) {
  367. /* Unbind current surface by binding an invalid one */
  368. ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
  369. if (unlikely(ret != 0))
  370. return ret;
  371. /* Update Screen Target, display will now be blank */
  372. if (crtc->primary->fb) {
  373. vmw_stdu_update_st(dev_priv, stdu);
  374. if (unlikely(ret != 0))
  375. return ret;
  376. }
  377. crtc->primary->fb = NULL;
  378. crtc->enabled = false;
  379. encoder->crtc = NULL;
  380. connector->encoder = NULL;
  381. vmw_stdu_unpin_display(stdu);
  382. stdu->content_fb = NULL;
  383. stdu->content_fb_type = SAME_AS_DISPLAY;
  384. ret = vmw_stdu_destroy_st(dev_priv, stdu);
  385. /* The hardware is hung, give up */
  386. if (unlikely(ret != 0))
  387. return ret;
  388. }
  389. /* Any of these conditions means the caller wants CRTC off */
  390. if (set->num_connectors == 0 || !mode || !new_fb)
  391. return 0;
  392. if (set->x + mode->hdisplay > new_fb->width ||
  393. set->y + mode->vdisplay > new_fb->height) {
  394. DRM_ERROR("Set outside of framebuffer\n");
  395. return -EINVAL;
  396. }
  397. stdu->content_fb = new_fb;
  398. vfb = vmw_framebuffer_to_vfb(stdu->content_fb);
  399. if (vfb->dmabuf)
  400. stdu->content_fb_type = SEPARATE_DMA;
  401. /*
  402. * If the requested mode is different than the width and height
  403. * of the FB or if the content buffer is a DMA buf, then allocate
  404. * a display FB that matches the dimension of the mode
  405. */
  406. if (mode->hdisplay != new_fb->width ||
  407. mode->vdisplay != new_fb->height ||
  408. stdu->content_fb_type != SAME_AS_DISPLAY) {
  409. struct vmw_surface content_srf;
  410. struct drm_vmw_size display_base_size = {0};
  411. struct vmw_surface *display_srf;
  412. display_base_size.width = mode->hdisplay;
  413. display_base_size.height = mode->vdisplay;
  414. display_base_size.depth = 1;
  415. /*
  416. * If content buffer is a DMA buf, then we have to construct
  417. * surface info
  418. */
  419. if (stdu->content_fb_type == SEPARATE_DMA) {
  420. switch (new_fb->bits_per_pixel) {
  421. case 32:
  422. content_srf.format = SVGA3D_X8R8G8B8;
  423. break;
  424. case 16:
  425. content_srf.format = SVGA3D_R5G6B5;
  426. break;
  427. case 8:
  428. content_srf.format = SVGA3D_P8;
  429. break;
  430. default:
  431. DRM_ERROR("Invalid format\n");
  432. ret = -EINVAL;
  433. goto err_unref_content;
  434. }
  435. content_srf.flags = 0;
  436. content_srf.mip_levels[0] = 1;
  437. content_srf.multisample_count = 0;
  438. } else {
  439. stdu->content_fb_type = SEPARATE_SURFACE;
  440. new_vfbs = vmw_framebuffer_to_vfbs(new_fb);
  441. content_srf = *new_vfbs->surface;
  442. }
  443. ret = vmw_surface_gb_priv_define(crtc->dev,
  444. 0, /* because kernel visible only */
  445. content_srf.flags,
  446. content_srf.format,
  447. true, /* a scanout buffer */
  448. content_srf.mip_levels[0],
  449. content_srf.multisample_count,
  450. 0,
  451. display_base_size,
  452. &display_srf);
  453. if (unlikely(ret != 0)) {
  454. DRM_ERROR("Cannot allocate a display FB.\n");
  455. goto err_unref_content;
  456. }
  457. stdu->display_srf = display_srf;
  458. } else {
  459. new_vfbs = vmw_framebuffer_to_vfbs(new_fb);
  460. stdu->display_srf = new_vfbs->surface;
  461. }
  462. ret = vmw_stdu_pin_display(stdu);
  463. if (unlikely(ret != 0)) {
  464. stdu->display_srf = NULL;
  465. goto err_unref_content;
  466. }
  467. vmw_svga_enable(dev_priv);
  468. /*
  469. * Steps to displaying a surface, assume surface is already
  470. * bound:
  471. * 1. define a screen target
  472. * 2. bind a fb to the screen target
  473. * 3. update that screen target (this is done later by
  474. * vmw_kms_stdu_do_surface_dirty_or_present)
  475. */
  476. ret = vmw_stdu_define_st(dev_priv, stdu);
  477. if (unlikely(ret != 0))
  478. goto err_unpin_display_and_content;
  479. ret = vmw_stdu_bind_st(dev_priv, stdu, &stdu->display_srf->res);
  480. if (unlikely(ret != 0))
  481. goto err_unpin_destroy_st;
  482. connector->encoder = encoder;
  483. encoder->crtc = crtc;
  484. crtc->mode = *mode;
  485. crtc->primary->fb = new_fb;
  486. crtc->enabled = true;
  487. return ret;
  488. err_unpin_destroy_st:
  489. vmw_stdu_destroy_st(dev_priv, stdu);
  490. err_unpin_display_and_content:
  491. vmw_stdu_unpin_display(stdu);
  492. err_unref_content:
  493. stdu->content_fb = NULL;
  494. return ret;
  495. }
  496. /**
  497. * vmw_stdu_crtc_page_flip - Binds a buffer to a screen target
  498. *
  499. * @crtc: CRTC to attach FB to
  500. * @fb: FB to attach
  501. * @event: Event to be posted. This event should've been alloced
  502. * using k[mz]alloc, and should've been completely initialized.
  503. * @page_flip_flags: Input flags.
  504. *
  505. * If the STDU uses the same display and content buffers, i.e. a true flip,
  506. * this function will replace the existing display buffer with the new content
  507. * buffer.
  508. *
  509. * If the STDU uses different display and content buffers, i.e. a blit, then
  510. * only the content buffer will be updated.
  511. *
  512. * RETURNS:
  513. * 0 on success, error code on failure
  514. */
  515. static int vmw_stdu_crtc_page_flip(struct drm_crtc *crtc,
  516. struct drm_framebuffer *new_fb,
  517. struct drm_pending_vblank_event *event,
  518. uint32_t flags)
  519. {
  520. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  521. struct vmw_screen_target_display_unit *stdu;
  522. int ret;
  523. if (crtc == NULL)
  524. return -EINVAL;
  525. dev_priv = vmw_priv(crtc->dev);
  526. stdu = vmw_crtc_to_stdu(crtc);
  527. crtc->primary->fb = new_fb;
  528. stdu->content_fb = new_fb;
  529. if (stdu->display_srf) {
  530. /*
  531. * If the display surface is the same as the content surface
  532. * then remove the reference
  533. */
  534. if (stdu->content_fb_type == SAME_AS_DISPLAY) {
  535. if (stdu->defined) {
  536. /* Unbind the current surface */
  537. ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
  538. if (unlikely(ret != 0))
  539. goto err_out;
  540. }
  541. vmw_stdu_unpin_display(stdu);
  542. stdu->display_srf = NULL;
  543. }
  544. }
  545. if (!new_fb) {
  546. /* Blanks the display */
  547. (void) vmw_stdu_update_st(dev_priv, stdu);
  548. return 0;
  549. }
  550. if (stdu->content_fb_type == SAME_AS_DISPLAY) {
  551. stdu->display_srf = vmw_framebuffer_to_vfbs(new_fb)->surface;
  552. ret = vmw_stdu_pin_display(stdu);
  553. if (ret) {
  554. stdu->display_srf = NULL;
  555. goto err_out;
  556. }
  557. /* Bind display surface */
  558. ret = vmw_stdu_bind_st(dev_priv, stdu, &stdu->display_srf->res);
  559. if (unlikely(ret != 0))
  560. goto err_unpin_display_and_content;
  561. }
  562. /* Update display surface: after this point everything is bound */
  563. ret = vmw_stdu_update_st(dev_priv, stdu);
  564. if (unlikely(ret != 0))
  565. return ret;
  566. if (event) {
  567. struct vmw_fence_obj *fence = NULL;
  568. struct drm_file *file_priv = event->base.file_priv;
  569. vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL);
  570. if (!fence)
  571. return -ENOMEM;
  572. ret = vmw_event_fence_action_queue(file_priv, fence,
  573. &event->base,
  574. &event->event.tv_sec,
  575. &event->event.tv_usec,
  576. true);
  577. vmw_fence_obj_unreference(&fence);
  578. } else {
  579. vmw_fifo_flush(dev_priv, false);
  580. }
  581. return ret;
  582. err_unpin_display_and_content:
  583. vmw_stdu_unpin_display(stdu);
  584. err_out:
  585. crtc->primary->fb = NULL;
  586. stdu->content_fb = NULL;
  587. return ret;
  588. }
  589. /**
  590. * vmw_stdu_dmabuf_clip - Callback to encode a suface DMA command cliprect
  591. *
  592. * @dirty: The closure structure.
  593. *
  594. * Encodes a surface DMA command cliprect and updates the bounding box
  595. * for the DMA.
  596. */
  597. static void vmw_stdu_dmabuf_clip(struct vmw_kms_dirty *dirty)
  598. {
  599. struct vmw_stdu_dirty *ddirty =
  600. container_of(dirty, struct vmw_stdu_dirty, base);
  601. struct vmw_stdu_dma *cmd = dirty->cmd;
  602. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  603. blit += dirty->num_hits;
  604. blit->srcx = dirty->fb_x;
  605. blit->srcy = dirty->fb_y;
  606. blit->x = dirty->unit_x1;
  607. blit->y = dirty->unit_y1;
  608. blit->d = 1;
  609. blit->w = dirty->unit_x2 - dirty->unit_x1;
  610. blit->h = dirty->unit_y2 - dirty->unit_y1;
  611. dirty->num_hits++;
  612. if (ddirty->transfer != SVGA3D_WRITE_HOST_VRAM)
  613. return;
  614. /* Destination bounding box */
  615. ddirty->left = min_t(s32, ddirty->left, dirty->unit_x1);
  616. ddirty->top = min_t(s32, ddirty->top, dirty->unit_y1);
  617. ddirty->right = max_t(s32, ddirty->right, dirty->unit_x2);
  618. ddirty->bottom = max_t(s32, ddirty->bottom, dirty->unit_y2);
  619. }
  620. /**
  621. * vmw_stdu_dmabuf_fifo_commit - Callback to fill in and submit a DMA command.
  622. *
  623. * @dirty: The closure structure.
  624. *
  625. * Fills in the missing fields in a DMA command, and optionally encodes
  626. * a screen target update command, depending on transfer direction.
  627. */
  628. static void vmw_stdu_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
  629. {
  630. struct vmw_stdu_dirty *ddirty =
  631. container_of(dirty, struct vmw_stdu_dirty, base);
  632. struct vmw_screen_target_display_unit *stdu =
  633. container_of(dirty->unit, typeof(*stdu), base);
  634. struct vmw_stdu_dma *cmd = dirty->cmd;
  635. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  636. SVGA3dCmdSurfaceDMASuffix *suffix =
  637. (SVGA3dCmdSurfaceDMASuffix *) &blit[dirty->num_hits];
  638. size_t blit_size = sizeof(*blit) * dirty->num_hits + sizeof(*suffix);
  639. if (!dirty->num_hits) {
  640. vmw_fifo_commit(dirty->dev_priv, 0);
  641. return;
  642. }
  643. cmd->header.id = SVGA_3D_CMD_SURFACE_DMA;
  644. cmd->header.size = sizeof(cmd->body) + blit_size;
  645. vmw_bo_get_guest_ptr(&ddirty->buf->base, &cmd->body.guest.ptr);
  646. cmd->body.guest.pitch = ddirty->pitch;
  647. cmd->body.host.sid = stdu->display_srf->res.id;
  648. cmd->body.host.face = 0;
  649. cmd->body.host.mipmap = 0;
  650. cmd->body.transfer = ddirty->transfer;
  651. suffix->suffixSize = sizeof(*suffix);
  652. suffix->maximumOffset = ddirty->buf->base.num_pages * PAGE_SIZE;
  653. if (ddirty->transfer == SVGA3D_WRITE_HOST_VRAM) {
  654. blit_size += sizeof(struct vmw_stdu_update);
  655. vmw_stdu_populate_update(&suffix[1], stdu->base.unit,
  656. ddirty->left, ddirty->right,
  657. ddirty->top, ddirty->bottom);
  658. }
  659. vmw_fifo_commit(dirty->dev_priv, sizeof(*cmd) + blit_size);
  660. ddirty->left = ddirty->top = S32_MAX;
  661. ddirty->right = ddirty->bottom = S32_MIN;
  662. }
  663. /**
  664. * vmw_kms_stdu_dma - Perform a DMA transfer between a dma-buffer backed
  665. * framebuffer and the screen target system.
  666. *
  667. * @dev_priv: Pointer to the device private structure.
  668. * @file_priv: Pointer to a struct drm-file identifying the caller. May be
  669. * set to NULL, but then @user_fence_rep must also be set to NULL.
  670. * @vfb: Pointer to the dma-buffer backed framebuffer.
  671. * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
  672. * @vclips: Alternate array of clip rects. Either @clips or @vclips must
  673. * be NULL.
  674. * @num_clips: Number of clip rects in @clips or @vclips.
  675. * @increment: Increment to use when looping over @clips or @vclips.
  676. * @to_surface: Whether to DMA to the screen target system as opposed to
  677. * from the screen target system.
  678. * @interruptible: Whether to perform waits interruptible if possible.
  679. *
  680. * If DMA-ing till the screen target system, the function will also notify
  681. * the screen target system that a bounding box of the cliprects has been
  682. * updated.
  683. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  684. * interrupted.
  685. */
  686. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  687. struct drm_file *file_priv,
  688. struct vmw_framebuffer *vfb,
  689. struct drm_vmw_fence_rep __user *user_fence_rep,
  690. struct drm_clip_rect *clips,
  691. struct drm_vmw_rect *vclips,
  692. uint32_t num_clips,
  693. int increment,
  694. bool to_surface,
  695. bool interruptible)
  696. {
  697. struct vmw_dma_buffer *buf =
  698. container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
  699. struct vmw_stdu_dirty ddirty;
  700. int ret;
  701. ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
  702. false);
  703. if (ret)
  704. return ret;
  705. ddirty.transfer = (to_surface) ? SVGA3D_WRITE_HOST_VRAM :
  706. SVGA3D_READ_HOST_VRAM;
  707. ddirty.left = ddirty.top = S32_MAX;
  708. ddirty.right = ddirty.bottom = S32_MIN;
  709. ddirty.pitch = vfb->base.pitches[0];
  710. ddirty.buf = buf;
  711. ddirty.base.fifo_commit = vmw_stdu_dmabuf_fifo_commit;
  712. ddirty.base.clip = vmw_stdu_dmabuf_clip;
  713. ddirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_dma) +
  714. num_clips * sizeof(SVGA3dCopyBox) +
  715. sizeof(SVGA3dCmdSurfaceDMASuffix);
  716. if (to_surface)
  717. ddirty.base.fifo_reserve_size += sizeof(struct vmw_stdu_update);
  718. ret = vmw_kms_helper_dirty(dev_priv, vfb, clips, vclips,
  719. 0, 0, num_clips, increment, &ddirty.base);
  720. vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
  721. user_fence_rep);
  722. return ret;
  723. }
  724. /**
  725. * vmw_stdu_surface_clip - Callback to encode a surface copy command cliprect
  726. *
  727. * @dirty: The closure structure.
  728. *
  729. * Encodes a surface copy command cliprect and updates the bounding box
  730. * for the copy.
  731. */
  732. static void vmw_kms_stdu_surface_clip(struct vmw_kms_dirty *dirty)
  733. {
  734. struct vmw_stdu_dirty *sdirty =
  735. container_of(dirty, struct vmw_stdu_dirty, base);
  736. struct vmw_stdu_surface_copy *cmd = dirty->cmd;
  737. struct vmw_screen_target_display_unit *stdu =
  738. container_of(dirty->unit, typeof(*stdu), base);
  739. if (sdirty->sid != stdu->display_srf->res.id) {
  740. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  741. blit += dirty->num_hits;
  742. blit->srcx = dirty->fb_x;
  743. blit->srcy = dirty->fb_y;
  744. blit->x = dirty->unit_x1;
  745. blit->y = dirty->unit_y1;
  746. blit->d = 1;
  747. blit->w = dirty->unit_x2 - dirty->unit_x1;
  748. blit->h = dirty->unit_y2 - dirty->unit_y1;
  749. }
  750. dirty->num_hits++;
  751. /* Destination bounding box */
  752. sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
  753. sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
  754. sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
  755. sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
  756. }
  757. /**
  758. * vmw_stdu_surface_fifo_commit - Callback to fill in and submit a surface
  759. * copy command.
  760. *
  761. * @dirty: The closure structure.
  762. *
  763. * Fills in the missing fields in a surface copy command, and encodes a screen
  764. * target update command.
  765. */
  766. static void vmw_kms_stdu_surface_fifo_commit(struct vmw_kms_dirty *dirty)
  767. {
  768. struct vmw_stdu_dirty *sdirty =
  769. container_of(dirty, struct vmw_stdu_dirty, base);
  770. struct vmw_screen_target_display_unit *stdu =
  771. container_of(dirty->unit, typeof(*stdu), base);
  772. struct vmw_stdu_surface_copy *cmd = dirty->cmd;
  773. struct vmw_stdu_update *update;
  774. size_t blit_size = sizeof(SVGA3dCopyBox) * dirty->num_hits;
  775. size_t commit_size;
  776. if (!dirty->num_hits) {
  777. vmw_fifo_commit(dirty->dev_priv, 0);
  778. return;
  779. }
  780. if (sdirty->sid != stdu->display_srf->res.id) {
  781. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  782. cmd->header.id = SVGA_3D_CMD_SURFACE_COPY;
  783. cmd->header.size = sizeof(cmd->body) + blit_size;
  784. cmd->body.src.sid = sdirty->sid;
  785. cmd->body.dest.sid = stdu->display_srf->res.id;
  786. update = (struct vmw_stdu_update *) &blit[dirty->num_hits];
  787. commit_size = sizeof(*cmd) + blit_size + sizeof(*update);
  788. } else {
  789. update = dirty->cmd;
  790. commit_size = sizeof(*update);
  791. }
  792. vmw_stdu_populate_update(update, stdu->base.unit, sdirty->left,
  793. sdirty->right, sdirty->top, sdirty->bottom);
  794. vmw_fifo_commit(dirty->dev_priv, commit_size);
  795. sdirty->left = sdirty->top = S32_MAX;
  796. sdirty->right = sdirty->bottom = S32_MIN;
  797. }
  798. /**
  799. * vmw_kms_stdu_surface_dirty - Dirty part of a surface backed framebuffer
  800. *
  801. * @dev_priv: Pointer to the device private structure.
  802. * @framebuffer: Pointer to the surface-buffer backed framebuffer.
  803. * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
  804. * @vclips: Alternate array of clip rects. Either @clips or @vclips must
  805. * be NULL.
  806. * @srf: Pointer to surface to blit from. If NULL, the surface attached
  807. * to @framebuffer will be used.
  808. * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
  809. * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
  810. * @num_clips: Number of clip rects in @clips.
  811. * @inc: Increment to use when looping over @clips.
  812. * @out_fence: If non-NULL, will return a ref-counted pointer to a
  813. * struct vmw_fence_obj. The returned fence pointer may be NULL in which
  814. * case the device has already synchronized.
  815. *
  816. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  817. * interrupted.
  818. */
  819. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  820. struct vmw_framebuffer *framebuffer,
  821. struct drm_clip_rect *clips,
  822. struct drm_vmw_rect *vclips,
  823. struct vmw_resource *srf,
  824. s32 dest_x,
  825. s32 dest_y,
  826. unsigned num_clips, int inc,
  827. struct vmw_fence_obj **out_fence)
  828. {
  829. struct vmw_framebuffer_surface *vfbs =
  830. container_of(framebuffer, typeof(*vfbs), base);
  831. struct vmw_stdu_dirty sdirty;
  832. struct vmw_validation_ctx ctx;
  833. int ret;
  834. if (!srf)
  835. srf = &vfbs->surface->res;
  836. ret = vmw_kms_helper_resource_prepare(srf, true, &ctx);
  837. if (ret)
  838. return ret;
  839. if (vfbs->is_dmabuf_proxy) {
  840. ret = vmw_kms_update_proxy(srf, clips, num_clips, inc);
  841. if (ret)
  842. goto out_finish;
  843. }
  844. sdirty.base.fifo_commit = vmw_kms_stdu_surface_fifo_commit;
  845. sdirty.base.clip = vmw_kms_stdu_surface_clip;
  846. sdirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_surface_copy) +
  847. sizeof(SVGA3dCopyBox) * num_clips +
  848. sizeof(struct vmw_stdu_update);
  849. sdirty.sid = srf->id;
  850. sdirty.left = sdirty.top = S32_MAX;
  851. sdirty.right = sdirty.bottom = S32_MIN;
  852. ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
  853. dest_x, dest_y, num_clips, inc,
  854. &sdirty.base);
  855. out_finish:
  856. vmw_kms_helper_resource_finish(&ctx, out_fence);
  857. return ret;
  858. }
  859. /*
  860. * Screen Target CRTC dispatch table
  861. */
  862. static struct drm_crtc_funcs vmw_stdu_crtc_funcs = {
  863. .save = vmw_du_crtc_save,
  864. .restore = vmw_du_crtc_restore,
  865. .cursor_set2 = vmw_du_crtc_cursor_set2,
  866. .cursor_move = vmw_du_crtc_cursor_move,
  867. .gamma_set = vmw_du_crtc_gamma_set,
  868. .destroy = vmw_stdu_crtc_destroy,
  869. .set_config = vmw_stdu_crtc_set_config,
  870. .page_flip = vmw_stdu_crtc_page_flip,
  871. };
  872. /******************************************************************************
  873. * Screen Target Display Unit Encoder Functions
  874. *****************************************************************************/
  875. /**
  876. * vmw_stdu_encoder_destroy - cleans up the STDU
  877. *
  878. * @encoder: used the get the containing STDU
  879. *
  880. * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
  881. * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
  882. * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
  883. * get called.
  884. */
  885. static void vmw_stdu_encoder_destroy(struct drm_encoder *encoder)
  886. {
  887. vmw_stdu_destroy(vmw_encoder_to_stdu(encoder));
  888. }
  889. static struct drm_encoder_funcs vmw_stdu_encoder_funcs = {
  890. .destroy = vmw_stdu_encoder_destroy,
  891. };
  892. /******************************************************************************
  893. * Screen Target Display Unit Connector Functions
  894. *****************************************************************************/
  895. /**
  896. * vmw_stdu_connector_destroy - cleans up the STDU
  897. *
  898. * @connector: used to get the containing STDU
  899. *
  900. * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
  901. * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
  902. * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
  903. * get called.
  904. */
  905. static void vmw_stdu_connector_destroy(struct drm_connector *connector)
  906. {
  907. vmw_stdu_destroy(vmw_connector_to_stdu(connector));
  908. }
  909. static struct drm_connector_funcs vmw_stdu_connector_funcs = {
  910. .dpms = vmw_du_connector_dpms,
  911. .save = vmw_du_connector_save,
  912. .restore = vmw_du_connector_restore,
  913. .detect = vmw_du_connector_detect,
  914. .fill_modes = vmw_du_connector_fill_modes,
  915. .set_property = vmw_du_connector_set_property,
  916. .destroy = vmw_stdu_connector_destroy,
  917. };
  918. /**
  919. * vmw_stdu_init - Sets up a Screen Target Display Unit
  920. *
  921. * @dev_priv: VMW DRM device
  922. * @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS
  923. *
  924. * This function is called once per CRTC, and allocates one Screen Target
  925. * display unit to represent that CRTC. Since the SVGA device does not separate
  926. * out encoder and connector, they are represented as part of the STDU as well.
  927. */
  928. static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit)
  929. {
  930. struct vmw_screen_target_display_unit *stdu;
  931. struct drm_device *dev = dev_priv->dev;
  932. struct drm_connector *connector;
  933. struct drm_encoder *encoder;
  934. struct drm_crtc *crtc;
  935. stdu = kzalloc(sizeof(*stdu), GFP_KERNEL);
  936. if (!stdu)
  937. return -ENOMEM;
  938. stdu->base.unit = unit;
  939. crtc = &stdu->base.crtc;
  940. encoder = &stdu->base.encoder;
  941. connector = &stdu->base.connector;
  942. stdu->base.pref_active = (unit == 0);
  943. stdu->base.pref_width = dev_priv->initial_width;
  944. stdu->base.pref_height = dev_priv->initial_height;
  945. stdu->base.is_implicit = true;
  946. drm_connector_init(dev, connector, &vmw_stdu_connector_funcs,
  947. DRM_MODE_CONNECTOR_VIRTUAL);
  948. connector->status = vmw_du_connector_detect(connector, false);
  949. drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs,
  950. DRM_MODE_ENCODER_VIRTUAL);
  951. drm_mode_connector_attach_encoder(connector, encoder);
  952. encoder->possible_crtcs = (1 << unit);
  953. encoder->possible_clones = 0;
  954. (void) drm_connector_register(connector);
  955. drm_crtc_init(dev, crtc, &vmw_stdu_crtc_funcs);
  956. drm_mode_crtc_set_gamma_size(crtc, 256);
  957. drm_object_attach_property(&connector->base,
  958. dev->mode_config.dirty_info_property,
  959. 1);
  960. return 0;
  961. }
  962. /**
  963. * vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit
  964. *
  965. * @stdu: Screen Target Display Unit to be destroyed
  966. *
  967. * Clean up after vmw_stdu_init
  968. */
  969. static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu)
  970. {
  971. vmw_stdu_unpin_display(stdu);
  972. vmw_du_cleanup(&stdu->base);
  973. kfree(stdu);
  974. }
  975. /******************************************************************************
  976. * Screen Target Display KMS Functions
  977. *
  978. * These functions are called by the common KMS code in vmwgfx_kms.c
  979. *****************************************************************************/
  980. /**
  981. * vmw_kms_stdu_init_display - Initializes a Screen Target based display
  982. *
  983. * @dev_priv: VMW DRM device
  984. *
  985. * This function initialize a Screen Target based display device. It checks
  986. * the capability bits to make sure the underlying hardware can support
  987. * screen targets, and then creates the maximum number of CRTCs, a.k.a Display
  988. * Units, as supported by the display hardware.
  989. *
  990. * RETURNS:
  991. * 0 on success, error code otherwise
  992. */
  993. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
  994. {
  995. struct drm_device *dev = dev_priv->dev;
  996. int i, ret;
  997. /* Do nothing if Screen Target support is turned off */
  998. if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE)
  999. return -ENOSYS;
  1000. if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS))
  1001. return -ENOSYS;
  1002. ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
  1003. if (unlikely(ret != 0))
  1004. return ret;
  1005. ret = drm_mode_create_dirty_info_property(dev);
  1006. if (unlikely(ret != 0))
  1007. goto err_vblank_cleanup;
  1008. dev_priv->active_display_unit = vmw_du_screen_target;
  1009. for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) {
  1010. ret = vmw_stdu_init(dev_priv, i);
  1011. if (unlikely(ret != 0)) {
  1012. DRM_ERROR("Failed to initialize STDU %d", i);
  1013. goto err_vblank_cleanup;
  1014. }
  1015. }
  1016. DRM_INFO("Screen Target Display device initialized\n");
  1017. return 0;
  1018. err_vblank_cleanup:
  1019. drm_vblank_cleanup(dev);
  1020. return ret;
  1021. }
  1022. /**
  1023. * vmw_kms_stdu_close_display - Cleans up after vmw_kms_stdu_init_display
  1024. *
  1025. * @dev_priv: VMW DRM device
  1026. *
  1027. * Frees up any resources allocated by vmw_kms_stdu_init_display
  1028. *
  1029. * RETURNS:
  1030. * 0 on success
  1031. */
  1032. int vmw_kms_stdu_close_display(struct vmw_private *dev_priv)
  1033. {
  1034. struct drm_device *dev = dev_priv->dev;
  1035. drm_vblank_cleanup(dev);
  1036. return 0;
  1037. }