vmwgfx_stdu.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  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. if (!turning_off && stdu->base.is_implicit && dev_priv->implicit_fb &&
  459. !(dev_priv->num_implicit == 1 && stdu->base.active_implicit)
  460. && dev_priv->implicit_fb != vfb) {
  461. DRM_ERROR("Multiple implicit framebuffers not supported.\n");
  462. return -EINVAL;
  463. }
  464. /* Since they always map one to one these are safe */
  465. connector = &stdu->base.connector;
  466. encoder = &stdu->base.encoder;
  467. if (stdu->defined) {
  468. ret = vmw_stdu_bind_st(dev_priv, stdu, NULL);
  469. if (ret)
  470. return ret;
  471. vmw_stdu_unpin_display(stdu);
  472. (void) vmw_stdu_update_st(dev_priv, stdu);
  473. vmw_kms_del_active(dev_priv, &stdu->base);
  474. ret = vmw_stdu_destroy_st(dev_priv, stdu);
  475. if (ret)
  476. return ret;
  477. crtc->primary->fb = NULL;
  478. crtc->enabled = false;
  479. encoder->crtc = NULL;
  480. connector->encoder = NULL;
  481. stdu->content_fb_type = SAME_AS_DISPLAY;
  482. crtc->x = set->x;
  483. crtc->y = set->y;
  484. }
  485. if (turning_off)
  486. return 0;
  487. /*
  488. * Steps to displaying a surface, assume surface is already
  489. * bound:
  490. * 1. define a screen target
  491. * 2. bind a fb to the screen target
  492. * 3. update that screen target (this is done later by
  493. * vmw_kms_stdu_do_surface_dirty_or_present)
  494. */
  495. /*
  496. * Note on error handling: We can't really restore the crtc to
  497. * it's original state on error, but we at least update the
  498. * current state to what's submitted to hardware to enable
  499. * future recovery.
  500. */
  501. vmw_svga_enable(dev_priv);
  502. ret = vmw_stdu_define_st(dev_priv, stdu, mode, set->x, set->y);
  503. if (ret)
  504. return ret;
  505. crtc->x = set->x;
  506. crtc->y = set->y;
  507. crtc->mode = *mode;
  508. ret = vmw_stdu_bind_fb(dev_priv, crtc, mode, new_fb);
  509. if (ret)
  510. return ret;
  511. vmw_kms_add_active(dev_priv, &stdu->base, vfb);
  512. crtc->enabled = true;
  513. connector->encoder = encoder;
  514. encoder->crtc = crtc;
  515. return 0;
  516. }
  517. /**
  518. * vmw_stdu_crtc_page_flip - Binds a buffer to a screen target
  519. *
  520. * @crtc: CRTC to attach FB to
  521. * @fb: FB to attach
  522. * @event: Event to be posted. This event should've been alloced
  523. * using k[mz]alloc, and should've been completely initialized.
  524. * @page_flip_flags: Input flags.
  525. *
  526. * If the STDU uses the same display and content buffers, i.e. a true flip,
  527. * this function will replace the existing display buffer with the new content
  528. * buffer.
  529. *
  530. * If the STDU uses different display and content buffers, i.e. a blit, then
  531. * only the content buffer will be updated.
  532. *
  533. * RETURNS:
  534. * 0 on success, error code on failure
  535. */
  536. static int vmw_stdu_crtc_page_flip(struct drm_crtc *crtc,
  537. struct drm_framebuffer *new_fb,
  538. struct drm_pending_vblank_event *event,
  539. uint32_t flags)
  540. {
  541. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  542. struct vmw_screen_target_display_unit *stdu;
  543. struct drm_vmw_rect vclips;
  544. struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb);
  545. int ret;
  546. dev_priv = vmw_priv(crtc->dev);
  547. stdu = vmw_crtc_to_stdu(crtc);
  548. if (!stdu->defined || !vmw_kms_crtc_flippable(dev_priv, crtc))
  549. return -EINVAL;
  550. ret = vmw_stdu_bind_fb(dev_priv, crtc, &crtc->mode, new_fb);
  551. if (ret)
  552. return ret;
  553. if (stdu->base.is_implicit)
  554. vmw_kms_update_implicit_fb(dev_priv, crtc);
  555. vclips.x = crtc->x;
  556. vclips.y = crtc->y;
  557. vclips.w = crtc->mode.hdisplay;
  558. vclips.h = crtc->mode.vdisplay;
  559. if (vfb->dmabuf)
  560. ret = vmw_kms_stdu_dma(dev_priv, NULL, vfb, NULL, NULL, &vclips,
  561. 1, 1, true, false);
  562. else
  563. ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, &vclips,
  564. NULL, 0, 0, 1, 1, NULL);
  565. if (ret)
  566. return ret;
  567. if (event) {
  568. struct vmw_fence_obj *fence = NULL;
  569. struct drm_file *file_priv = event->base.file_priv;
  570. vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL);
  571. if (!fence)
  572. return -ENOMEM;
  573. ret = vmw_event_fence_action_queue(file_priv, fence,
  574. &event->base,
  575. &event->event.tv_sec,
  576. &event->event.tv_usec,
  577. true);
  578. vmw_fence_obj_unreference(&fence);
  579. } else {
  580. vmw_fifo_flush(dev_priv, false);
  581. }
  582. return 0;
  583. }
  584. /**
  585. * vmw_stdu_dmabuf_clip - Callback to encode a suface DMA command cliprect
  586. *
  587. * @dirty: The closure structure.
  588. *
  589. * Encodes a surface DMA command cliprect and updates the bounding box
  590. * for the DMA.
  591. */
  592. static void vmw_stdu_dmabuf_clip(struct vmw_kms_dirty *dirty)
  593. {
  594. struct vmw_stdu_dirty *ddirty =
  595. container_of(dirty, struct vmw_stdu_dirty, base);
  596. struct vmw_stdu_dma *cmd = dirty->cmd;
  597. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  598. blit += dirty->num_hits;
  599. blit->srcx = dirty->fb_x;
  600. blit->srcy = dirty->fb_y;
  601. blit->x = dirty->unit_x1;
  602. blit->y = dirty->unit_y1;
  603. blit->d = 1;
  604. blit->w = dirty->unit_x2 - dirty->unit_x1;
  605. blit->h = dirty->unit_y2 - dirty->unit_y1;
  606. dirty->num_hits++;
  607. if (ddirty->transfer != SVGA3D_WRITE_HOST_VRAM)
  608. return;
  609. /* Destination bounding box */
  610. ddirty->left = min_t(s32, ddirty->left, dirty->unit_x1);
  611. ddirty->top = min_t(s32, ddirty->top, dirty->unit_y1);
  612. ddirty->right = max_t(s32, ddirty->right, dirty->unit_x2);
  613. ddirty->bottom = max_t(s32, ddirty->bottom, dirty->unit_y2);
  614. }
  615. /**
  616. * vmw_stdu_dmabuf_fifo_commit - Callback to fill in and submit a DMA command.
  617. *
  618. * @dirty: The closure structure.
  619. *
  620. * Fills in the missing fields in a DMA command, and optionally encodes
  621. * a screen target update command, depending on transfer direction.
  622. */
  623. static void vmw_stdu_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty)
  624. {
  625. struct vmw_stdu_dirty *ddirty =
  626. container_of(dirty, struct vmw_stdu_dirty, base);
  627. struct vmw_screen_target_display_unit *stdu =
  628. container_of(dirty->unit, typeof(*stdu), base);
  629. struct vmw_stdu_dma *cmd = dirty->cmd;
  630. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  631. SVGA3dCmdSurfaceDMASuffix *suffix =
  632. (SVGA3dCmdSurfaceDMASuffix *) &blit[dirty->num_hits];
  633. size_t blit_size = sizeof(*blit) * dirty->num_hits + sizeof(*suffix);
  634. if (!dirty->num_hits) {
  635. vmw_fifo_commit(dirty->dev_priv, 0);
  636. return;
  637. }
  638. cmd->header.id = SVGA_3D_CMD_SURFACE_DMA;
  639. cmd->header.size = sizeof(cmd->body) + blit_size;
  640. vmw_bo_get_guest_ptr(&ddirty->buf->base, &cmd->body.guest.ptr);
  641. cmd->body.guest.pitch = ddirty->pitch;
  642. cmd->body.host.sid = stdu->display_srf->res.id;
  643. cmd->body.host.face = 0;
  644. cmd->body.host.mipmap = 0;
  645. cmd->body.transfer = ddirty->transfer;
  646. suffix->suffixSize = sizeof(*suffix);
  647. suffix->maximumOffset = ddirty->buf->base.num_pages * PAGE_SIZE;
  648. if (ddirty->transfer == SVGA3D_WRITE_HOST_VRAM) {
  649. blit_size += sizeof(struct vmw_stdu_update);
  650. vmw_stdu_populate_update(&suffix[1], stdu->base.unit,
  651. ddirty->left, ddirty->right,
  652. ddirty->top, ddirty->bottom);
  653. }
  654. vmw_fifo_commit(dirty->dev_priv, sizeof(*cmd) + blit_size);
  655. ddirty->left = ddirty->top = S32_MAX;
  656. ddirty->right = ddirty->bottom = S32_MIN;
  657. }
  658. /**
  659. * vmw_kms_stdu_dma - Perform a DMA transfer between a dma-buffer backed
  660. * framebuffer and the screen target system.
  661. *
  662. * @dev_priv: Pointer to the device private structure.
  663. * @file_priv: Pointer to a struct drm-file identifying the caller. May be
  664. * set to NULL, but then @user_fence_rep must also be set to NULL.
  665. * @vfb: Pointer to the dma-buffer backed framebuffer.
  666. * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
  667. * @vclips: Alternate array of clip rects. Either @clips or @vclips must
  668. * be NULL.
  669. * @num_clips: Number of clip rects in @clips or @vclips.
  670. * @increment: Increment to use when looping over @clips or @vclips.
  671. * @to_surface: Whether to DMA to the screen target system as opposed to
  672. * from the screen target system.
  673. * @interruptible: Whether to perform waits interruptible if possible.
  674. *
  675. * If DMA-ing till the screen target system, the function will also notify
  676. * the screen target system that a bounding box of the cliprects has been
  677. * updated.
  678. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  679. * interrupted.
  680. */
  681. int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
  682. struct drm_file *file_priv,
  683. struct vmw_framebuffer *vfb,
  684. struct drm_vmw_fence_rep __user *user_fence_rep,
  685. struct drm_clip_rect *clips,
  686. struct drm_vmw_rect *vclips,
  687. uint32_t num_clips,
  688. int increment,
  689. bool to_surface,
  690. bool interruptible)
  691. {
  692. struct vmw_dma_buffer *buf =
  693. container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer;
  694. struct vmw_stdu_dirty ddirty;
  695. int ret;
  696. ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible,
  697. false);
  698. if (ret)
  699. return ret;
  700. ddirty.transfer = (to_surface) ? SVGA3D_WRITE_HOST_VRAM :
  701. SVGA3D_READ_HOST_VRAM;
  702. ddirty.left = ddirty.top = S32_MAX;
  703. ddirty.right = ddirty.bottom = S32_MIN;
  704. ddirty.pitch = vfb->base.pitches[0];
  705. ddirty.buf = buf;
  706. ddirty.base.fifo_commit = vmw_stdu_dmabuf_fifo_commit;
  707. ddirty.base.clip = vmw_stdu_dmabuf_clip;
  708. ddirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_dma) +
  709. num_clips * sizeof(SVGA3dCopyBox) +
  710. sizeof(SVGA3dCmdSurfaceDMASuffix);
  711. if (to_surface)
  712. ddirty.base.fifo_reserve_size += sizeof(struct vmw_stdu_update);
  713. ret = vmw_kms_helper_dirty(dev_priv, vfb, clips, vclips,
  714. 0, 0, num_clips, increment, &ddirty.base);
  715. vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL,
  716. user_fence_rep);
  717. return ret;
  718. }
  719. /**
  720. * vmw_stdu_surface_clip - Callback to encode a surface copy command cliprect
  721. *
  722. * @dirty: The closure structure.
  723. *
  724. * Encodes a surface copy command cliprect and updates the bounding box
  725. * for the copy.
  726. */
  727. static void vmw_kms_stdu_surface_clip(struct vmw_kms_dirty *dirty)
  728. {
  729. struct vmw_stdu_dirty *sdirty =
  730. container_of(dirty, struct vmw_stdu_dirty, base);
  731. struct vmw_stdu_surface_copy *cmd = dirty->cmd;
  732. struct vmw_screen_target_display_unit *stdu =
  733. container_of(dirty->unit, typeof(*stdu), base);
  734. if (sdirty->sid != stdu->display_srf->res.id) {
  735. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  736. blit += dirty->num_hits;
  737. blit->srcx = dirty->fb_x;
  738. blit->srcy = dirty->fb_y;
  739. blit->x = dirty->unit_x1;
  740. blit->y = dirty->unit_y1;
  741. blit->d = 1;
  742. blit->w = dirty->unit_x2 - dirty->unit_x1;
  743. blit->h = dirty->unit_y2 - dirty->unit_y1;
  744. }
  745. dirty->num_hits++;
  746. /* Destination bounding box */
  747. sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1);
  748. sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1);
  749. sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2);
  750. sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2);
  751. }
  752. /**
  753. * vmw_stdu_surface_fifo_commit - Callback to fill in and submit a surface
  754. * copy command.
  755. *
  756. * @dirty: The closure structure.
  757. *
  758. * Fills in the missing fields in a surface copy command, and encodes a screen
  759. * target update command.
  760. */
  761. static void vmw_kms_stdu_surface_fifo_commit(struct vmw_kms_dirty *dirty)
  762. {
  763. struct vmw_stdu_dirty *sdirty =
  764. container_of(dirty, struct vmw_stdu_dirty, base);
  765. struct vmw_screen_target_display_unit *stdu =
  766. container_of(dirty->unit, typeof(*stdu), base);
  767. struct vmw_stdu_surface_copy *cmd = dirty->cmd;
  768. struct vmw_stdu_update *update;
  769. size_t blit_size = sizeof(SVGA3dCopyBox) * dirty->num_hits;
  770. size_t commit_size;
  771. if (!dirty->num_hits) {
  772. vmw_fifo_commit(dirty->dev_priv, 0);
  773. return;
  774. }
  775. if (sdirty->sid != stdu->display_srf->res.id) {
  776. struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1];
  777. cmd->header.id = SVGA_3D_CMD_SURFACE_COPY;
  778. cmd->header.size = sizeof(cmd->body) + blit_size;
  779. cmd->body.src.sid = sdirty->sid;
  780. cmd->body.dest.sid = stdu->display_srf->res.id;
  781. update = (struct vmw_stdu_update *) &blit[dirty->num_hits];
  782. commit_size = sizeof(*cmd) + blit_size + sizeof(*update);
  783. } else {
  784. update = dirty->cmd;
  785. commit_size = sizeof(*update);
  786. }
  787. vmw_stdu_populate_update(update, stdu->base.unit, sdirty->left,
  788. sdirty->right, sdirty->top, sdirty->bottom);
  789. vmw_fifo_commit(dirty->dev_priv, commit_size);
  790. sdirty->left = sdirty->top = S32_MAX;
  791. sdirty->right = sdirty->bottom = S32_MIN;
  792. }
  793. /**
  794. * vmw_kms_stdu_surface_dirty - Dirty part of a surface backed framebuffer
  795. *
  796. * @dev_priv: Pointer to the device private structure.
  797. * @framebuffer: Pointer to the surface-buffer backed framebuffer.
  798. * @clips: Array of clip rects. Either @clips or @vclips must be NULL.
  799. * @vclips: Alternate array of clip rects. Either @clips or @vclips must
  800. * be NULL.
  801. * @srf: Pointer to surface to blit from. If NULL, the surface attached
  802. * to @framebuffer will be used.
  803. * @dest_x: X coordinate offset to align @srf with framebuffer coordinates.
  804. * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates.
  805. * @num_clips: Number of clip rects in @clips.
  806. * @inc: Increment to use when looping over @clips.
  807. * @out_fence: If non-NULL, will return a ref-counted pointer to a
  808. * struct vmw_fence_obj. The returned fence pointer may be NULL in which
  809. * case the device has already synchronized.
  810. *
  811. * Returns 0 on success, negative error code on failure. -ERESTARTSYS if
  812. * interrupted.
  813. */
  814. int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
  815. struct vmw_framebuffer *framebuffer,
  816. struct drm_clip_rect *clips,
  817. struct drm_vmw_rect *vclips,
  818. struct vmw_resource *srf,
  819. s32 dest_x,
  820. s32 dest_y,
  821. unsigned num_clips, int inc,
  822. struct vmw_fence_obj **out_fence)
  823. {
  824. struct vmw_framebuffer_surface *vfbs =
  825. container_of(framebuffer, typeof(*vfbs), base);
  826. struct vmw_stdu_dirty sdirty;
  827. int ret;
  828. if (!srf)
  829. srf = &vfbs->surface->res;
  830. ret = vmw_kms_helper_resource_prepare(srf, true);
  831. if (ret)
  832. return ret;
  833. if (vfbs->is_dmabuf_proxy) {
  834. ret = vmw_kms_update_proxy(srf, clips, num_clips, inc);
  835. if (ret)
  836. goto out_finish;
  837. }
  838. sdirty.base.fifo_commit = vmw_kms_stdu_surface_fifo_commit;
  839. sdirty.base.clip = vmw_kms_stdu_surface_clip;
  840. sdirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_surface_copy) +
  841. sizeof(SVGA3dCopyBox) * num_clips +
  842. sizeof(struct vmw_stdu_update);
  843. sdirty.sid = srf->id;
  844. sdirty.left = sdirty.top = S32_MAX;
  845. sdirty.right = sdirty.bottom = S32_MIN;
  846. ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips,
  847. dest_x, dest_y, num_clips, inc,
  848. &sdirty.base);
  849. out_finish:
  850. vmw_kms_helper_resource_finish(srf, out_fence);
  851. return ret;
  852. }
  853. /*
  854. * Screen Target CRTC dispatch table
  855. */
  856. static const struct drm_crtc_funcs vmw_stdu_crtc_funcs = {
  857. .cursor_set2 = vmw_du_crtc_cursor_set2,
  858. .cursor_move = vmw_du_crtc_cursor_move,
  859. .gamma_set = vmw_du_crtc_gamma_set,
  860. .destroy = vmw_stdu_crtc_destroy,
  861. .set_config = vmw_stdu_crtc_set_config,
  862. .page_flip = vmw_stdu_crtc_page_flip,
  863. };
  864. /******************************************************************************
  865. * Screen Target Display Unit Encoder Functions
  866. *****************************************************************************/
  867. /**
  868. * vmw_stdu_encoder_destroy - cleans up the STDU
  869. *
  870. * @encoder: used the get the containing STDU
  871. *
  872. * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
  873. * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
  874. * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
  875. * get called.
  876. */
  877. static void vmw_stdu_encoder_destroy(struct drm_encoder *encoder)
  878. {
  879. vmw_stdu_destroy(vmw_encoder_to_stdu(encoder));
  880. }
  881. static const struct drm_encoder_funcs vmw_stdu_encoder_funcs = {
  882. .destroy = vmw_stdu_encoder_destroy,
  883. };
  884. /******************************************************************************
  885. * Screen Target Display Unit Connector Functions
  886. *****************************************************************************/
  887. /**
  888. * vmw_stdu_connector_destroy - cleans up the STDU
  889. *
  890. * @connector: used to get the containing STDU
  891. *
  892. * vmwgfx cleans up crtc/encoder/connector all at the same time so technically
  893. * this can be a no-op. Nevertheless, it doesn't hurt of have this in case
  894. * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't
  895. * get called.
  896. */
  897. static void vmw_stdu_connector_destroy(struct drm_connector *connector)
  898. {
  899. vmw_stdu_destroy(vmw_connector_to_stdu(connector));
  900. }
  901. static const struct drm_connector_funcs vmw_stdu_connector_funcs = {
  902. .dpms = vmw_du_connector_dpms,
  903. .detect = vmw_du_connector_detect,
  904. .fill_modes = vmw_du_connector_fill_modes,
  905. .set_property = vmw_du_connector_set_property,
  906. .destroy = vmw_stdu_connector_destroy,
  907. };
  908. /**
  909. * vmw_stdu_init - Sets up a Screen Target Display Unit
  910. *
  911. * @dev_priv: VMW DRM device
  912. * @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS
  913. *
  914. * This function is called once per CRTC, and allocates one Screen Target
  915. * display unit to represent that CRTC. Since the SVGA device does not separate
  916. * out encoder and connector, they are represented as part of the STDU as well.
  917. */
  918. static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit)
  919. {
  920. struct vmw_screen_target_display_unit *stdu;
  921. struct drm_device *dev = dev_priv->dev;
  922. struct drm_connector *connector;
  923. struct drm_encoder *encoder;
  924. struct drm_crtc *crtc;
  925. stdu = kzalloc(sizeof(*stdu), GFP_KERNEL);
  926. if (!stdu)
  927. return -ENOMEM;
  928. stdu->base.unit = unit;
  929. crtc = &stdu->base.crtc;
  930. encoder = &stdu->base.encoder;
  931. connector = &stdu->base.connector;
  932. stdu->base.pref_active = (unit == 0);
  933. stdu->base.pref_width = dev_priv->initial_width;
  934. stdu->base.pref_height = dev_priv->initial_height;
  935. stdu->base.is_implicit = false;
  936. drm_connector_init(dev, connector, &vmw_stdu_connector_funcs,
  937. DRM_MODE_CONNECTOR_VIRTUAL);
  938. connector->status = vmw_du_connector_detect(connector, false);
  939. drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs,
  940. DRM_MODE_ENCODER_VIRTUAL, NULL);
  941. drm_mode_connector_attach_encoder(connector, encoder);
  942. encoder->possible_crtcs = (1 << unit);
  943. encoder->possible_clones = 0;
  944. (void) drm_connector_register(connector);
  945. drm_crtc_init(dev, crtc, &vmw_stdu_crtc_funcs);
  946. drm_mode_crtc_set_gamma_size(crtc, 256);
  947. drm_object_attach_property(&connector->base,
  948. dev->mode_config.dirty_info_property,
  949. 1);
  950. drm_object_attach_property(&connector->base,
  951. dev_priv->hotplug_mode_update_property, 1);
  952. drm_object_attach_property(&connector->base,
  953. dev->mode_config.suggested_x_property, 0);
  954. drm_object_attach_property(&connector->base,
  955. dev->mode_config.suggested_y_property, 0);
  956. if (dev_priv->implicit_placement_property)
  957. drm_object_attach_property
  958. (&connector->base,
  959. dev_priv->implicit_placement_property,
  960. stdu->base.is_implicit);
  961. return 0;
  962. }
  963. /**
  964. * vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit
  965. *
  966. * @stdu: Screen Target Display Unit to be destroyed
  967. *
  968. * Clean up after vmw_stdu_init
  969. */
  970. static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu)
  971. {
  972. vmw_stdu_unpin_display(stdu);
  973. vmw_du_cleanup(&stdu->base);
  974. kfree(stdu);
  975. }
  976. /******************************************************************************
  977. * Screen Target Display KMS Functions
  978. *
  979. * These functions are called by the common KMS code in vmwgfx_kms.c
  980. *****************************************************************************/
  981. /**
  982. * vmw_kms_stdu_init_display - Initializes a Screen Target based display
  983. *
  984. * @dev_priv: VMW DRM device
  985. *
  986. * This function initialize a Screen Target based display device. It checks
  987. * the capability bits to make sure the underlying hardware can support
  988. * screen targets, and then creates the maximum number of CRTCs, a.k.a Display
  989. * Units, as supported by the display hardware.
  990. *
  991. * RETURNS:
  992. * 0 on success, error code otherwise
  993. */
  994. int vmw_kms_stdu_init_display(struct vmw_private *dev_priv)
  995. {
  996. struct drm_device *dev = dev_priv->dev;
  997. int i, ret;
  998. /* Do nothing if Screen Target support is turned off */
  999. if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE)
  1000. return -ENOSYS;
  1001. if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS))
  1002. return -ENOSYS;
  1003. ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
  1004. if (unlikely(ret != 0))
  1005. return ret;
  1006. ret = drm_mode_create_dirty_info_property(dev);
  1007. if (unlikely(ret != 0))
  1008. goto err_vblank_cleanup;
  1009. dev_priv->active_display_unit = vmw_du_screen_target;
  1010. vmw_kms_create_implicit_placement_property(dev_priv, false);
  1011. for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) {
  1012. ret = vmw_stdu_init(dev_priv, i);
  1013. if (unlikely(ret != 0)) {
  1014. DRM_ERROR("Failed to initialize STDU %d", i);
  1015. goto err_vblank_cleanup;
  1016. }
  1017. }
  1018. DRM_INFO("Screen Target Display device initialized\n");
  1019. return 0;
  1020. err_vblank_cleanup:
  1021. drm_vblank_cleanup(dev);
  1022. return ret;
  1023. }
  1024. /**
  1025. * vmw_kms_stdu_close_display - Cleans up after vmw_kms_stdu_init_display
  1026. *
  1027. * @dev_priv: VMW DRM device
  1028. *
  1029. * Frees up any resources allocated by vmw_kms_stdu_init_display
  1030. *
  1031. * RETURNS:
  1032. * 0 on success
  1033. */
  1034. int vmw_kms_stdu_close_display(struct vmw_private *dev_priv)
  1035. {
  1036. struct drm_device *dev = dev_priv->dev;
  1037. drm_vblank_cleanup(dev);
  1038. return 0;
  1039. }