vmwgfx_ldu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009-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 <drm/drm_plane_helper.h>
  29. #include <drm/drm_atomic.h>
  30. #include <drm/drm_atomic_helper.h>
  31. #define vmw_crtc_to_ldu(x) \
  32. container_of(x, struct vmw_legacy_display_unit, base.crtc)
  33. #define vmw_encoder_to_ldu(x) \
  34. container_of(x, struct vmw_legacy_display_unit, base.encoder)
  35. #define vmw_connector_to_ldu(x) \
  36. container_of(x, struct vmw_legacy_display_unit, base.connector)
  37. struct vmw_legacy_display {
  38. struct list_head active;
  39. unsigned num_active;
  40. unsigned last_num_active;
  41. struct vmw_framebuffer *fb;
  42. };
  43. /**
  44. * Display unit using the legacy register interface.
  45. */
  46. struct vmw_legacy_display_unit {
  47. struct vmw_display_unit base;
  48. struct list_head active;
  49. };
  50. static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu)
  51. {
  52. list_del_init(&ldu->active);
  53. vmw_du_cleanup(&ldu->base);
  54. kfree(ldu);
  55. }
  56. /*
  57. * Legacy Display Unit CRTC functions
  58. */
  59. static void vmw_ldu_crtc_destroy(struct drm_crtc *crtc)
  60. {
  61. vmw_ldu_destroy(vmw_crtc_to_ldu(crtc));
  62. }
  63. static int vmw_ldu_commit_list(struct vmw_private *dev_priv)
  64. {
  65. struct vmw_legacy_display *lds = dev_priv->ldu_priv;
  66. struct vmw_legacy_display_unit *entry;
  67. struct drm_framebuffer *fb = NULL;
  68. struct drm_crtc *crtc = NULL;
  69. int i = 0;
  70. /* If there is no display topology the host just assumes
  71. * that the guest will set the same layout as the host.
  72. */
  73. if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) {
  74. int w = 0, h = 0;
  75. list_for_each_entry(entry, &lds->active, active) {
  76. crtc = &entry->base.crtc;
  77. w = max(w, crtc->x + crtc->mode.hdisplay);
  78. h = max(h, crtc->y + crtc->mode.vdisplay);
  79. i++;
  80. }
  81. if (crtc == NULL)
  82. return 0;
  83. fb = entry->base.crtc.primary->state->fb;
  84. return vmw_kms_write_svga(dev_priv, w, h, fb->pitches[0],
  85. fb->format->cpp[0] * 8,
  86. fb->format->depth);
  87. }
  88. if (!list_empty(&lds->active)) {
  89. entry = list_entry(lds->active.next, typeof(*entry), active);
  90. fb = entry->base.crtc.primary->state->fb;
  91. vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitches[0],
  92. fb->format->cpp[0] * 8, fb->format->depth);
  93. }
  94. /* Make sure we always show something. */
  95. vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS,
  96. lds->num_active ? lds->num_active : 1);
  97. i = 0;
  98. list_for_each_entry(entry, &lds->active, active) {
  99. crtc = &entry->base.crtc;
  100. vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i);
  101. vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i);
  102. vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, crtc->x);
  103. vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, crtc->y);
  104. vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, crtc->mode.hdisplay);
  105. vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, crtc->mode.vdisplay);
  106. vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  107. i++;
  108. }
  109. BUG_ON(i != lds->num_active);
  110. lds->last_num_active = lds->num_active;
  111. return 0;
  112. }
  113. static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
  114. struct vmw_legacy_display_unit *ldu)
  115. {
  116. struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
  117. if (list_empty(&ldu->active))
  118. return 0;
  119. /* Must init otherwise list_empty(&ldu->active) will not work. */
  120. list_del_init(&ldu->active);
  121. if (--(ld->num_active) == 0) {
  122. BUG_ON(!ld->fb);
  123. if (ld->fb->unpin)
  124. ld->fb->unpin(ld->fb);
  125. ld->fb = NULL;
  126. }
  127. return 0;
  128. }
  129. static int vmw_ldu_add_active(struct vmw_private *vmw_priv,
  130. struct vmw_legacy_display_unit *ldu,
  131. struct vmw_framebuffer *vfb)
  132. {
  133. struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
  134. struct vmw_legacy_display_unit *entry;
  135. struct list_head *at;
  136. BUG_ON(!ld->num_active && ld->fb);
  137. if (vfb != ld->fb) {
  138. if (ld->fb && ld->fb->unpin)
  139. ld->fb->unpin(ld->fb);
  140. vmw_svga_enable(vmw_priv);
  141. if (vfb->pin)
  142. vfb->pin(vfb);
  143. ld->fb = vfb;
  144. }
  145. if (!list_empty(&ldu->active))
  146. return 0;
  147. at = &ld->active;
  148. list_for_each_entry(entry, &ld->active, active) {
  149. if (entry->base.unit > ldu->base.unit)
  150. break;
  151. at = &entry->active;
  152. }
  153. list_add(&ldu->active, at);
  154. ld->num_active++;
  155. return 0;
  156. }
  157. /**
  158. * vmw_ldu_crtc_mode_set_nofb - Enable svga
  159. *
  160. * @crtc: CRTC associated with the new screen
  161. *
  162. * For LDU, just enable the svga
  163. */
  164. static void vmw_ldu_crtc_mode_set_nofb(struct drm_crtc *crtc)
  165. {
  166. }
  167. /**
  168. * vmw_ldu_crtc_helper_prepare - Noop
  169. *
  170. * @crtc: CRTC associated with the new screen
  171. *
  172. * Prepares the CRTC for a mode set, but we don't need to do anything here.
  173. *
  174. */
  175. static void vmw_ldu_crtc_helper_prepare(struct drm_crtc *crtc)
  176. {
  177. }
  178. /**
  179. * vmw_ldu_crtc_helper_commit - Noop
  180. *
  181. * @crtc: CRTC associated with the new screen
  182. *
  183. * This is called after a mode set has been completed. Here's
  184. * usually a good place to call vmw_ldu_add_active/vmw_ldu_del_active
  185. * but since for LDU the display plane is closely tied to the
  186. * CRTC, it makes more sense to do those at plane update time.
  187. */
  188. static void vmw_ldu_crtc_helper_commit(struct drm_crtc *crtc)
  189. {
  190. struct vmw_private *dev_priv;
  191. struct vmw_legacy_display_unit *ldu;
  192. struct vmw_framebuffer *vfb;
  193. struct drm_framebuffer *fb;
  194. ldu = vmw_crtc_to_ldu(crtc);
  195. dev_priv = vmw_priv(crtc->dev);
  196. fb = crtc->primary->state->fb;
  197. vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL;
  198. if (vfb)
  199. vmw_ldu_add_active(dev_priv, ldu, vfb);
  200. else
  201. vmw_ldu_del_active(dev_priv, ldu);
  202. vmw_ldu_commit_list(dev_priv);
  203. }
  204. /**
  205. * vmw_ldu_crtc_helper_disable - Turns off CRTC
  206. *
  207. * @crtc: CRTC to be turned off
  208. */
  209. static void vmw_ldu_crtc_helper_disable(struct drm_crtc *crtc)
  210. {
  211. }
  212. static const struct drm_crtc_funcs vmw_legacy_crtc_funcs = {
  213. .gamma_set = vmw_du_crtc_gamma_set,
  214. .destroy = vmw_ldu_crtc_destroy,
  215. .reset = vmw_du_crtc_reset,
  216. .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
  217. .atomic_destroy_state = vmw_du_crtc_destroy_state,
  218. .set_config = vmw_kms_set_config,
  219. };
  220. /*
  221. * Legacy Display Unit encoder functions
  222. */
  223. static void vmw_ldu_encoder_destroy(struct drm_encoder *encoder)
  224. {
  225. vmw_ldu_destroy(vmw_encoder_to_ldu(encoder));
  226. }
  227. static const struct drm_encoder_funcs vmw_legacy_encoder_funcs = {
  228. .destroy = vmw_ldu_encoder_destroy,
  229. };
  230. /*
  231. * Legacy Display Unit connector functions
  232. */
  233. static void vmw_ldu_connector_destroy(struct drm_connector *connector)
  234. {
  235. vmw_ldu_destroy(vmw_connector_to_ldu(connector));
  236. }
  237. static const struct drm_connector_funcs vmw_legacy_connector_funcs = {
  238. .dpms = vmw_du_connector_dpms,
  239. .detect = vmw_du_connector_detect,
  240. .fill_modes = vmw_du_connector_fill_modes,
  241. .set_property = vmw_du_connector_set_property,
  242. .destroy = vmw_ldu_connector_destroy,
  243. .reset = vmw_du_connector_reset,
  244. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  245. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  246. .atomic_set_property = vmw_du_connector_atomic_set_property,
  247. .atomic_get_property = vmw_du_connector_atomic_get_property,
  248. };
  249. static const struct
  250. drm_connector_helper_funcs vmw_ldu_connector_helper_funcs = {
  251. .best_encoder = drm_atomic_helper_best_encoder,
  252. };
  253. /*
  254. * Legacy Display Plane Functions
  255. */
  256. /**
  257. * vmw_ldu_primary_plane_cleanup_fb - Unpin fb
  258. *
  259. * @plane: display plane
  260. * @old_state: Contains the FB to clean up
  261. *
  262. * Unpins the display surface
  263. *
  264. * Returns 0 on success
  265. */
  266. static void
  267. vmw_ldu_primary_plane_cleanup_fb(struct drm_plane *plane,
  268. struct drm_plane_state *old_state)
  269. {
  270. }
  271. /**
  272. * vmw_ldu_primary_plane_prepare_fb -
  273. *
  274. * @plane: display plane
  275. * @new_state: info on the new plane state, including the FB
  276. *
  277. * Returns 0 on success
  278. */
  279. static int
  280. vmw_ldu_primary_plane_prepare_fb(struct drm_plane *plane,
  281. struct drm_plane_state *new_state)
  282. {
  283. return 0;
  284. }
  285. static void
  286. vmw_ldu_primary_plane_atomic_update(struct drm_plane *plane,
  287. struct drm_plane_state *old_state)
  288. {
  289. }
  290. static const struct drm_plane_funcs vmw_ldu_plane_funcs = {
  291. .update_plane = drm_atomic_helper_update_plane,
  292. .disable_plane = drm_atomic_helper_disable_plane,
  293. .destroy = vmw_du_primary_plane_destroy,
  294. .reset = vmw_du_plane_reset,
  295. .atomic_duplicate_state = vmw_du_plane_duplicate_state,
  296. .atomic_destroy_state = vmw_du_plane_destroy_state,
  297. };
  298. static const struct drm_plane_funcs vmw_ldu_cursor_funcs = {
  299. .update_plane = drm_atomic_helper_update_plane,
  300. .disable_plane = drm_atomic_helper_disable_plane,
  301. .destroy = vmw_du_cursor_plane_destroy,
  302. .reset = vmw_du_plane_reset,
  303. .atomic_duplicate_state = vmw_du_plane_duplicate_state,
  304. .atomic_destroy_state = vmw_du_plane_destroy_state,
  305. };
  306. /*
  307. * Atomic Helpers
  308. */
  309. static const struct
  310. drm_plane_helper_funcs vmw_ldu_cursor_plane_helper_funcs = {
  311. .atomic_check = vmw_du_cursor_plane_atomic_check,
  312. .atomic_update = vmw_du_cursor_plane_atomic_update,
  313. .prepare_fb = vmw_du_cursor_plane_prepare_fb,
  314. .cleanup_fb = vmw_du_plane_cleanup_fb,
  315. };
  316. static const struct
  317. drm_plane_helper_funcs vmw_ldu_primary_plane_helper_funcs = {
  318. .atomic_check = vmw_du_primary_plane_atomic_check,
  319. .atomic_update = vmw_ldu_primary_plane_atomic_update,
  320. .prepare_fb = vmw_ldu_primary_plane_prepare_fb,
  321. .cleanup_fb = vmw_ldu_primary_plane_cleanup_fb,
  322. };
  323. static const struct drm_crtc_helper_funcs vmw_ldu_crtc_helper_funcs = {
  324. .prepare = vmw_ldu_crtc_helper_prepare,
  325. .commit = vmw_ldu_crtc_helper_commit,
  326. .disable = vmw_ldu_crtc_helper_disable,
  327. .mode_set_nofb = vmw_ldu_crtc_mode_set_nofb,
  328. .atomic_check = vmw_du_crtc_atomic_check,
  329. .atomic_begin = vmw_du_crtc_atomic_begin,
  330. .atomic_flush = vmw_du_crtc_atomic_flush,
  331. };
  332. static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
  333. {
  334. struct vmw_legacy_display_unit *ldu;
  335. struct drm_device *dev = dev_priv->dev;
  336. struct drm_connector *connector;
  337. struct drm_encoder *encoder;
  338. struct drm_plane *primary, *cursor;
  339. struct drm_crtc *crtc;
  340. int ret;
  341. ldu = kzalloc(sizeof(*ldu), GFP_KERNEL);
  342. if (!ldu)
  343. return -ENOMEM;
  344. ldu->base.unit = unit;
  345. crtc = &ldu->base.crtc;
  346. encoder = &ldu->base.encoder;
  347. connector = &ldu->base.connector;
  348. primary = &ldu->base.primary;
  349. cursor = &ldu->base.cursor;
  350. INIT_LIST_HEAD(&ldu->active);
  351. ldu->base.pref_active = (unit == 0);
  352. ldu->base.pref_width = dev_priv->initial_width;
  353. ldu->base.pref_height = dev_priv->initial_height;
  354. ldu->base.pref_mode = NULL;
  355. /*
  356. * Remove this after enabling atomic because property values can
  357. * only exist in a state object
  358. */
  359. ldu->base.is_implicit = true;
  360. /* Initialize primary plane */
  361. vmw_du_plane_reset(primary);
  362. ret = drm_universal_plane_init(dev, &ldu->base.primary,
  363. 0, &vmw_ldu_plane_funcs,
  364. vmw_primary_plane_formats,
  365. ARRAY_SIZE(vmw_primary_plane_formats),
  366. DRM_PLANE_TYPE_PRIMARY, NULL);
  367. if (ret) {
  368. DRM_ERROR("Failed to initialize primary plane");
  369. goto err_free;
  370. }
  371. drm_plane_helper_add(primary, &vmw_ldu_primary_plane_helper_funcs);
  372. /* Initialize cursor plane */
  373. vmw_du_plane_reset(cursor);
  374. ret = drm_universal_plane_init(dev, &ldu->base.cursor,
  375. 0, &vmw_ldu_cursor_funcs,
  376. vmw_cursor_plane_formats,
  377. ARRAY_SIZE(vmw_cursor_plane_formats),
  378. DRM_PLANE_TYPE_CURSOR, NULL);
  379. if (ret) {
  380. DRM_ERROR("Failed to initialize cursor plane");
  381. drm_plane_cleanup(&ldu->base.primary);
  382. goto err_free;
  383. }
  384. drm_plane_helper_add(cursor, &vmw_ldu_cursor_plane_helper_funcs);
  385. vmw_du_connector_reset(connector);
  386. ret = drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
  387. DRM_MODE_CONNECTOR_VIRTUAL);
  388. if (ret) {
  389. DRM_ERROR("Failed to initialize connector\n");
  390. goto err_free;
  391. }
  392. drm_connector_helper_add(connector, &vmw_ldu_connector_helper_funcs);
  393. connector->status = vmw_du_connector_detect(connector, true);
  394. vmw_connector_state_to_vcs(connector->state)->is_implicit = true;
  395. ret = drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
  396. DRM_MODE_ENCODER_VIRTUAL, NULL);
  397. if (ret) {
  398. DRM_ERROR("Failed to initialize encoder\n");
  399. goto err_free_connector;
  400. }
  401. (void) drm_mode_connector_attach_encoder(connector, encoder);
  402. encoder->possible_crtcs = (1 << unit);
  403. encoder->possible_clones = 0;
  404. ret = drm_connector_register(connector);
  405. if (ret) {
  406. DRM_ERROR("Failed to register connector\n");
  407. goto err_free_encoder;
  408. }
  409. vmw_du_crtc_reset(crtc);
  410. ret = drm_crtc_init_with_planes(dev, crtc, &ldu->base.primary,
  411. &ldu->base.cursor,
  412. &vmw_legacy_crtc_funcs, NULL);
  413. if (ret) {
  414. DRM_ERROR("Failed to initialize CRTC\n");
  415. goto err_free_unregister;
  416. }
  417. drm_crtc_helper_add(crtc, &vmw_ldu_crtc_helper_funcs);
  418. drm_mode_crtc_set_gamma_size(crtc, 256);
  419. drm_object_attach_property(&connector->base,
  420. dev_priv->hotplug_mode_update_property, 1);
  421. drm_object_attach_property(&connector->base,
  422. dev->mode_config.suggested_x_property, 0);
  423. drm_object_attach_property(&connector->base,
  424. dev->mode_config.suggested_y_property, 0);
  425. if (dev_priv->implicit_placement_property)
  426. drm_object_attach_property
  427. (&connector->base,
  428. dev_priv->implicit_placement_property,
  429. 1);
  430. return 0;
  431. err_free_unregister:
  432. drm_connector_unregister(connector);
  433. err_free_encoder:
  434. drm_encoder_cleanup(encoder);
  435. err_free_connector:
  436. drm_connector_cleanup(connector);
  437. err_free:
  438. kfree(ldu);
  439. return ret;
  440. }
  441. int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)
  442. {
  443. struct drm_device *dev = dev_priv->dev;
  444. int i, ret;
  445. if (dev_priv->ldu_priv) {
  446. DRM_INFO("ldu system already on\n");
  447. return -EINVAL;
  448. }
  449. dev_priv->ldu_priv = kmalloc(sizeof(*dev_priv->ldu_priv), GFP_KERNEL);
  450. if (!dev_priv->ldu_priv)
  451. return -ENOMEM;
  452. INIT_LIST_HEAD(&dev_priv->ldu_priv->active);
  453. dev_priv->ldu_priv->num_active = 0;
  454. dev_priv->ldu_priv->last_num_active = 0;
  455. dev_priv->ldu_priv->fb = NULL;
  456. /* for old hardware without multimon only enable one display */
  457. if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
  458. ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS);
  459. else
  460. ret = drm_vblank_init(dev, 1);
  461. if (ret != 0)
  462. goto err_free;
  463. vmw_kms_create_implicit_placement_property(dev_priv, true);
  464. if (dev_priv->capabilities & SVGA_CAP_MULTIMON)
  465. for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i)
  466. vmw_ldu_init(dev_priv, i);
  467. else
  468. vmw_ldu_init(dev_priv, 0);
  469. dev_priv->active_display_unit = vmw_du_legacy;
  470. DRM_INFO("Legacy Display Unit initialized\n");
  471. return 0;
  472. err_free:
  473. kfree(dev_priv->ldu_priv);
  474. dev_priv->ldu_priv = NULL;
  475. return ret;
  476. }
  477. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv)
  478. {
  479. struct drm_device *dev = dev_priv->dev;
  480. if (!dev_priv->ldu_priv)
  481. return -ENOSYS;
  482. drm_vblank_cleanup(dev);
  483. BUG_ON(!list_empty(&dev_priv->ldu_priv->active));
  484. kfree(dev_priv->ldu_priv);
  485. return 0;
  486. }
  487. int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
  488. struct vmw_framebuffer *framebuffer,
  489. unsigned flags, unsigned color,
  490. struct drm_clip_rect *clips,
  491. unsigned num_clips, int increment)
  492. {
  493. size_t fifo_size;
  494. int i;
  495. struct {
  496. uint32_t header;
  497. SVGAFifoCmdUpdate body;
  498. } *cmd;
  499. fifo_size = sizeof(*cmd) * num_clips;
  500. cmd = vmw_fifo_reserve(dev_priv, fifo_size);
  501. if (unlikely(cmd == NULL)) {
  502. DRM_ERROR("Fifo reserve failed.\n");
  503. return -ENOMEM;
  504. }
  505. memset(cmd, 0, fifo_size);
  506. for (i = 0; i < num_clips; i++, clips += increment) {
  507. cmd[i].header = SVGA_CMD_UPDATE;
  508. cmd[i].body.x = clips->x1;
  509. cmd[i].body.y = clips->y1;
  510. cmd[i].body.width = clips->x2 - clips->x1;
  511. cmd[i].body.height = clips->y2 - clips->y1;
  512. }
  513. vmw_fifo_commit(dev_priv, fifo_size);
  514. return 0;
  515. }