vmwgfx_stdu.c 35 KB

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