vmwgfx_ldu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. // SPDX-License-Identifier: GPL-2.0 OR MIT
  2. /**************************************************************************
  3. *
  4. * Copyright (c) 2009-2024 Broadcom. All Rights Reserved. The term
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  23. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  25. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. **************************************************************************/
  28. #include "vmwgfx_bo.h"
  29. #include "vmwgfx_kms.h"
  30. #include "vmwgfx_vkms.h"
  31. #include <drm/drm_atomic.h>
  32. #include <drm/drm_atomic_helper.h>
  33. #include <drm/drm_fourcc.h>
  34. #define vmw_crtc_to_ldu(x) \
  35. container_of(x, struct vmw_legacy_display_unit, base.crtc)
  36. #define vmw_encoder_to_ldu(x) \
  37. container_of(x, struct vmw_legacy_display_unit, base.encoder)
  38. #define vmw_connector_to_ldu(x) \
  39. container_of(x, struct vmw_legacy_display_unit, base.connector)
  40. struct vmw_legacy_display {
  41. struct list_head active;
  42. unsigned num_active;
  43. unsigned last_num_active;
  44. struct vmw_framebuffer *fb;
  45. };
  46. /*
  47. * Display unit using the legacy register interface.
  48. */
  49. struct vmw_legacy_display_unit {
  50. struct vmw_display_unit base;
  51. struct list_head active;
  52. };
  53. static void vmw_ldu_destroy(struct vmw_legacy_display_unit *ldu)
  54. {
  55. list_del_init(&ldu->active);
  56. vmw_du_cleanup(&ldu->base);
  57. kfree(ldu);
  58. }
  59. /*
  60. * Legacy Display Unit CRTC functions
  61. */
  62. static void vmw_ldu_crtc_destroy(struct drm_crtc *crtc)
  63. {
  64. vmw_ldu_destroy(vmw_crtc_to_ldu(crtc));
  65. }
  66. static int vmw_ldu_commit_list(struct vmw_private *dev_priv)
  67. {
  68. struct vmw_legacy_display *lds = dev_priv->ldu_priv;
  69. struct vmw_legacy_display_unit *entry;
  70. struct drm_framebuffer *fb = NULL;
  71. struct drm_crtc *crtc = NULL;
  72. int i;
  73. /* If there is no display topology the host just assumes
  74. * that the guest will set the same layout as the host.
  75. */
  76. if (!(dev_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) {
  77. int w = 0, h = 0;
  78. list_for_each_entry(entry, &lds->active, active) {
  79. crtc = &entry->base.crtc;
  80. w = max(w, crtc->x + crtc->mode.hdisplay);
  81. h = max(h, crtc->y + crtc->mode.vdisplay);
  82. }
  83. if (crtc == NULL)
  84. return 0;
  85. fb = crtc->primary->state->fb;
  86. return vmw_kms_write_svga(dev_priv, w, h, fb->pitches[0],
  87. fb->format->cpp[0] * 8,
  88. fb->format->depth);
  89. }
  90. if (!list_empty(&lds->active)) {
  91. entry = list_entry(lds->active.next, typeof(*entry), active);
  92. fb = entry->base.crtc.primary->state->fb;
  93. vmw_kms_write_svga(dev_priv, fb->width, fb->height, fb->pitches[0],
  94. fb->format->cpp[0] * 8, fb->format->depth);
  95. }
  96. /* Make sure we always show something. */
  97. vmw_write(dev_priv, SVGA_REG_NUM_GUEST_DISPLAYS,
  98. lds->num_active ? lds->num_active : 1);
  99. i = 0;
  100. list_for_each_entry(entry, &lds->active, active) {
  101. crtc = &entry->base.crtc;
  102. vmw_write(dev_priv, SVGA_REG_DISPLAY_ID, i);
  103. vmw_write(dev_priv, SVGA_REG_DISPLAY_IS_PRIMARY, !i);
  104. vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_X, crtc->x);
  105. vmw_write(dev_priv, SVGA_REG_DISPLAY_POSITION_Y, crtc->y);
  106. vmw_write(dev_priv, SVGA_REG_DISPLAY_WIDTH, crtc->mode.hdisplay);
  107. vmw_write(dev_priv, SVGA_REG_DISPLAY_HEIGHT, crtc->mode.vdisplay);
  108. i++;
  109. }
  110. BUG_ON(i != lds->num_active);
  111. lds->last_num_active = lds->num_active;
  112. return 0;
  113. }
  114. /*
  115. * Pin the buffer in a location suitable for access by the
  116. * display system.
  117. */
  118. static int vmw_ldu_fb_pin(struct vmw_framebuffer *vfb)
  119. {
  120. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  121. struct vmw_bo *buf;
  122. int ret;
  123. buf = vfb->bo ?
  124. vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
  125. vmw_user_object_buffer(&vmw_framebuffer_to_vfbs(&vfb->base)->uo);
  126. if (!buf)
  127. return 0;
  128. WARN_ON(dev_priv->active_display_unit != vmw_du_legacy);
  129. if (dev_priv->active_display_unit == vmw_du_legacy) {
  130. vmw_overlay_pause_all(dev_priv);
  131. ret = vmw_bo_pin_in_start_of_vram(dev_priv, buf, false);
  132. vmw_overlay_resume_all(dev_priv);
  133. } else
  134. ret = -EINVAL;
  135. return ret;
  136. }
  137. static int vmw_ldu_fb_unpin(struct vmw_framebuffer *vfb)
  138. {
  139. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  140. struct vmw_bo *buf;
  141. buf = vfb->bo ?
  142. vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
  143. vmw_user_object_buffer(&vmw_framebuffer_to_vfbs(&vfb->base)->uo);
  144. if (WARN_ON(!buf))
  145. return 0;
  146. return vmw_bo_unpin(dev_priv, buf, false);
  147. }
  148. static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
  149. struct vmw_legacy_display_unit *ldu)
  150. {
  151. struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
  152. if (list_empty(&ldu->active))
  153. return 0;
  154. /* Must init otherwise list_empty(&ldu->active) will not work. */
  155. list_del_init(&ldu->active);
  156. if (--(ld->num_active) == 0) {
  157. BUG_ON(!ld->fb);
  158. WARN_ON(vmw_ldu_fb_unpin(ld->fb));
  159. ld->fb = NULL;
  160. }
  161. return 0;
  162. }
  163. static int vmw_ldu_add_active(struct vmw_private *vmw_priv,
  164. struct vmw_legacy_display_unit *ldu,
  165. struct vmw_framebuffer *vfb)
  166. {
  167. struct vmw_legacy_display *ld = vmw_priv->ldu_priv;
  168. struct vmw_legacy_display_unit *entry;
  169. struct list_head *at;
  170. BUG_ON(!ld->num_active && ld->fb);
  171. if (vfb != ld->fb) {
  172. if (ld->fb)
  173. WARN_ON(vmw_ldu_fb_unpin(ld->fb));
  174. vmw_svga_enable(vmw_priv);
  175. WARN_ON(vmw_ldu_fb_pin(vfb));
  176. ld->fb = vfb;
  177. }
  178. if (!list_empty(&ldu->active))
  179. return 0;
  180. at = &ld->active;
  181. list_for_each_entry(entry, &ld->active, active) {
  182. if (entry->base.unit > ldu->base.unit)
  183. break;
  184. at = &entry->active;
  185. }
  186. list_add(&ldu->active, at);
  187. ld->num_active++;
  188. return 0;
  189. }
  190. /**
  191. * vmw_ldu_crtc_mode_set_nofb - Enable svga
  192. *
  193. * @crtc: CRTC associated with the new screen
  194. *
  195. * For LDU, just enable the svga
  196. */
  197. static void vmw_ldu_crtc_mode_set_nofb(struct drm_crtc *crtc)
  198. {
  199. }
  200. static const struct drm_crtc_funcs vmw_legacy_crtc_funcs = {
  201. .gamma_set = vmw_du_crtc_gamma_set,
  202. .destroy = vmw_ldu_crtc_destroy,
  203. .reset = vmw_du_crtc_reset,
  204. .atomic_duplicate_state = vmw_du_crtc_duplicate_state,
  205. .atomic_destroy_state = vmw_du_crtc_destroy_state,
  206. .set_config = drm_atomic_helper_set_config,
  207. .page_flip = drm_atomic_helper_page_flip,
  208. .enable_vblank = vmw_vkms_enable_vblank,
  209. .disable_vblank = vmw_vkms_disable_vblank,
  210. .get_vblank_timestamp = vmw_vkms_get_vblank_timestamp,
  211. };
  212. /*
  213. * Legacy Display Unit encoder functions
  214. */
  215. static void vmw_ldu_encoder_destroy(struct drm_encoder *encoder)
  216. {
  217. vmw_ldu_destroy(vmw_encoder_to_ldu(encoder));
  218. }
  219. static const struct drm_encoder_funcs vmw_legacy_encoder_funcs = {
  220. .destroy = vmw_ldu_encoder_destroy,
  221. };
  222. /*
  223. * Legacy Display Unit connector functions
  224. */
  225. static void vmw_ldu_connector_destroy(struct drm_connector *connector)
  226. {
  227. vmw_ldu_destroy(vmw_connector_to_ldu(connector));
  228. }
  229. static const struct drm_connector_funcs vmw_legacy_connector_funcs = {
  230. .dpms = vmw_du_connector_dpms,
  231. .detect = vmw_du_connector_detect,
  232. .fill_modes = drm_helper_probe_single_connector_modes,
  233. .destroy = vmw_ldu_connector_destroy,
  234. .reset = vmw_du_connector_reset,
  235. .atomic_duplicate_state = vmw_du_connector_duplicate_state,
  236. .atomic_destroy_state = vmw_du_connector_destroy_state,
  237. };
  238. static const struct
  239. drm_connector_helper_funcs vmw_ldu_connector_helper_funcs = {
  240. .get_modes = vmw_connector_get_modes,
  241. .mode_valid = vmw_connector_mode_valid
  242. };
  243. static int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv,
  244. struct vmw_framebuffer *framebuffer,
  245. unsigned int flags, unsigned int color,
  246. struct drm_mode_rect *clips,
  247. unsigned int num_clips);
  248. /*
  249. * Legacy Display Plane Functions
  250. */
  251. static void
  252. vmw_ldu_primary_plane_atomic_update(struct drm_plane *plane,
  253. struct drm_atomic_state *state)
  254. {
  255. struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
  256. plane);
  257. struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  258. plane);
  259. struct vmw_private *dev_priv;
  260. struct vmw_legacy_display_unit *ldu;
  261. struct vmw_framebuffer *vfb;
  262. struct drm_framebuffer *fb;
  263. struct drm_crtc *crtc = new_state->crtc ?: old_state->crtc;
  264. ldu = vmw_crtc_to_ldu(crtc);
  265. dev_priv = vmw_priv(plane->dev);
  266. fb = new_state->fb;
  267. vfb = (fb) ? vmw_framebuffer_to_vfb(fb) : NULL;
  268. if (vfb)
  269. vmw_ldu_add_active(dev_priv, ldu, vfb);
  270. else
  271. vmw_ldu_del_active(dev_priv, ldu);
  272. vmw_ldu_commit_list(dev_priv);
  273. if (vfb && vmw_cmd_supported(dev_priv)) {
  274. struct drm_mode_rect fb_rect = {
  275. .x1 = 0,
  276. .y1 = 0,
  277. .x2 = vfb->base.width,
  278. .y2 = vfb->base.height
  279. };
  280. struct drm_mode_rect *damage_rects = drm_plane_get_damage_clips(new_state);
  281. u32 rect_count = drm_plane_get_damage_clips_count(new_state);
  282. int ret;
  283. if (!damage_rects) {
  284. damage_rects = &fb_rect;
  285. rect_count = 1;
  286. }
  287. ret = vmw_kms_ldu_do_bo_dirty(dev_priv, vfb, 0, 0, damage_rects, rect_count);
  288. drm_WARN_ONCE(plane->dev, ret,
  289. "vmw_kms_ldu_do_bo_dirty failed with: ret=%d\n", ret);
  290. vmw_cmd_flush(dev_priv, false);
  291. }
  292. }
  293. static const struct drm_plane_funcs vmw_ldu_plane_funcs = {
  294. .update_plane = drm_atomic_helper_update_plane,
  295. .disable_plane = drm_atomic_helper_disable_plane,
  296. .destroy = vmw_du_primary_plane_destroy,
  297. .reset = vmw_du_plane_reset,
  298. .atomic_duplicate_state = vmw_du_plane_duplicate_state,
  299. .atomic_destroy_state = vmw_du_plane_destroy_state,
  300. };
  301. static const struct drm_plane_funcs vmw_ldu_cursor_funcs = {
  302. .update_plane = drm_atomic_helper_update_plane,
  303. .disable_plane = drm_atomic_helper_disable_plane,
  304. .destroy = vmw_cursor_plane_destroy,
  305. .reset = vmw_du_plane_reset,
  306. .atomic_duplicate_state = vmw_du_plane_duplicate_state,
  307. .atomic_destroy_state = vmw_du_plane_destroy_state,
  308. };
  309. /*
  310. * Atomic Helpers
  311. */
  312. static const struct
  313. drm_plane_helper_funcs vmw_ldu_cursor_plane_helper_funcs = {
  314. .atomic_check = vmw_cursor_plane_atomic_check,
  315. .atomic_update = vmw_cursor_plane_atomic_update,
  316. .prepare_fb = vmw_cursor_plane_prepare_fb,
  317. .cleanup_fb = vmw_cursor_plane_cleanup_fb,
  318. };
  319. static const struct
  320. drm_plane_helper_funcs vmw_ldu_primary_plane_helper_funcs = {
  321. .atomic_check = vmw_du_primary_plane_atomic_check,
  322. .atomic_update = vmw_ldu_primary_plane_atomic_update,
  323. };
  324. static const struct drm_crtc_helper_funcs vmw_ldu_crtc_helper_funcs = {
  325. .mode_set_nofb = vmw_ldu_crtc_mode_set_nofb,
  326. .atomic_check = vmw_du_crtc_atomic_check,
  327. .atomic_begin = vmw_du_crtc_atomic_begin,
  328. .atomic_flush = vmw_vkms_crtc_atomic_flush,
  329. .atomic_enable = vmw_vkms_crtc_atomic_enable,
  330. .atomic_disable = vmw_vkms_crtc_atomic_disable,
  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->drm;
  336. struct drm_connector *connector;
  337. struct drm_encoder *encoder;
  338. struct drm_plane *primary;
  339. struct vmw_cursor_plane *cursor;
  340. struct drm_crtc *crtc;
  341. int ret;
  342. ldu = kzalloc_obj(*ldu);
  343. if (!ldu)
  344. return -ENOMEM;
  345. ldu->base.unit = unit;
  346. crtc = &ldu->base.crtc;
  347. encoder = &ldu->base.encoder;
  348. connector = &ldu->base.connector;
  349. primary = &ldu->base.primary;
  350. cursor = &ldu->base.cursor;
  351. INIT_LIST_HEAD(&ldu->active);
  352. ldu->base.pref_active = (unit == 0);
  353. ldu->base.pref_width = dev_priv->initial_width;
  354. ldu->base.pref_height = dev_priv->initial_height;
  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. ret = drm_universal_plane_init(dev, primary,
  362. 0, &vmw_ldu_plane_funcs,
  363. vmw_primary_plane_formats,
  364. ARRAY_SIZE(vmw_primary_plane_formats),
  365. NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
  366. if (ret) {
  367. DRM_ERROR("Failed to initialize primary plane");
  368. goto err_free;
  369. }
  370. drm_plane_helper_add(primary, &vmw_ldu_primary_plane_helper_funcs);
  371. /*
  372. * We're going to be using traces and software cursors
  373. */
  374. if (vmw_cmd_supported(dev_priv)) {
  375. /* Initialize cursor plane */
  376. ret = drm_universal_plane_init(dev, &cursor->base,
  377. 0, &vmw_ldu_cursor_funcs,
  378. vmw_cursor_plane_formats,
  379. ARRAY_SIZE(vmw_cursor_plane_formats),
  380. NULL, DRM_PLANE_TYPE_CURSOR, NULL);
  381. if (ret) {
  382. DRM_ERROR("Failed to initialize cursor plane");
  383. drm_plane_cleanup(&ldu->base.primary);
  384. goto err_free;
  385. }
  386. drm_plane_helper_add(&cursor->base, &vmw_ldu_cursor_plane_helper_funcs);
  387. }
  388. ret = drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
  389. DRM_MODE_CONNECTOR_VIRTUAL);
  390. if (ret) {
  391. DRM_ERROR("Failed to initialize connector\n");
  392. goto err_free;
  393. }
  394. drm_connector_helper_add(connector, &vmw_ldu_connector_helper_funcs);
  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_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. ret = drm_crtc_init_with_planes(dev, crtc, primary,
  410. vmw_cmd_supported(dev_priv) ? &cursor->base : NULL,
  411. &vmw_legacy_crtc_funcs, NULL);
  412. if (ret) {
  413. DRM_ERROR("Failed to initialize CRTC\n");
  414. goto err_free_unregister;
  415. }
  416. drm_crtc_helper_add(crtc, &vmw_ldu_crtc_helper_funcs);
  417. drm_mode_crtc_set_gamma_size(crtc, 256);
  418. drm_object_attach_property(&connector->base,
  419. dev_priv->hotplug_mode_update_property, 1);
  420. drm_object_attach_property(&connector->base,
  421. dev->mode_config.suggested_x_property, 0);
  422. drm_object_attach_property(&connector->base,
  423. dev->mode_config.suggested_y_property, 0);
  424. if (dev_priv->implicit_placement_property)
  425. drm_object_attach_property
  426. (&connector->base,
  427. dev_priv->implicit_placement_property,
  428. 1);
  429. vmw_du_init(&ldu->base);
  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->drm;
  444. int i, ret;
  445. int num_display_units = (dev_priv->capabilities & SVGA_CAP_MULTIMON) ?
  446. VMWGFX_NUM_DISPLAY_UNITS : 1;
  447. if (unlikely(dev_priv->ldu_priv)) {
  448. return -EINVAL;
  449. }
  450. dev_priv->ldu_priv = kmalloc_obj(*dev_priv->ldu_priv);
  451. if (!dev_priv->ldu_priv)
  452. return -ENOMEM;
  453. INIT_LIST_HEAD(&dev_priv->ldu_priv->active);
  454. dev_priv->ldu_priv->num_active = 0;
  455. dev_priv->ldu_priv->last_num_active = 0;
  456. dev_priv->ldu_priv->fb = NULL;
  457. vmw_kms_create_implicit_placement_property(dev_priv);
  458. for (i = 0; i < num_display_units; ++i) {
  459. ret = vmw_ldu_init(dev_priv, i);
  460. if (ret != 0)
  461. goto err_free;
  462. }
  463. dev_priv->active_display_unit = vmw_du_legacy;
  464. drm_mode_config_reset(dev);
  465. return 0;
  466. err_free:
  467. kfree(dev_priv->ldu_priv);
  468. dev_priv->ldu_priv = NULL;
  469. return ret;
  470. }
  471. int vmw_kms_ldu_close_display(struct vmw_private *dev_priv)
  472. {
  473. if (!dev_priv->ldu_priv)
  474. return -ENOSYS;
  475. BUG_ON(!list_empty(&dev_priv->ldu_priv->active));
  476. kfree(dev_priv->ldu_priv);
  477. return 0;
  478. }
  479. static int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv,
  480. struct vmw_framebuffer *framebuffer,
  481. unsigned int flags, unsigned int color,
  482. struct drm_mode_rect *clips,
  483. unsigned int num_clips)
  484. {
  485. size_t fifo_size;
  486. int i;
  487. struct {
  488. uint32_t header;
  489. SVGAFifoCmdUpdate body;
  490. } *cmd;
  491. fifo_size = sizeof(*cmd) * num_clips;
  492. cmd = VMW_CMD_RESERVE(dev_priv, fifo_size);
  493. if (unlikely(cmd == NULL))
  494. return -ENOMEM;
  495. memset(cmd, 0, fifo_size);
  496. for (i = 0; i < num_clips; i++, clips++) {
  497. cmd[i].header = SVGA_CMD_UPDATE;
  498. cmd[i].body.x = clips->x1;
  499. cmd[i].body.y = clips->y1;
  500. cmd[i].body.width = clips->x2 - clips->x1;
  501. cmd[i].body.height = clips->y2 - clips->y1;
  502. }
  503. vmw_cmd_commit(dev_priv, fifo_size);
  504. return 0;
  505. }