vmwgfx_kms.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. /**************************************************************************
  2. *
  3. * Copyright © 2009 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. /* Might need a hrtimer here? */
  29. #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1)
  30. static int vmw_surface_dmabuf_pin(struct vmw_framebuffer *vfb);
  31. static int vmw_surface_dmabuf_unpin(struct vmw_framebuffer *vfb);
  32. void vmw_display_unit_cleanup(struct vmw_display_unit *du)
  33. {
  34. if (du->cursor_surface)
  35. vmw_surface_unreference(&du->cursor_surface);
  36. if (du->cursor_dmabuf)
  37. vmw_dmabuf_unreference(&du->cursor_dmabuf);
  38. drm_crtc_cleanup(&du->crtc);
  39. drm_encoder_cleanup(&du->encoder);
  40. drm_connector_cleanup(&du->connector);
  41. }
  42. /*
  43. * Display Unit Cursor functions
  44. */
  45. int vmw_cursor_update_image(struct vmw_private *dev_priv,
  46. u32 *image, u32 width, u32 height,
  47. u32 hotspotX, u32 hotspotY)
  48. {
  49. struct {
  50. u32 cmd;
  51. SVGAFifoCmdDefineAlphaCursor cursor;
  52. } *cmd;
  53. u32 image_size = width * height * 4;
  54. u32 cmd_size = sizeof(*cmd) + image_size;
  55. if (!image)
  56. return -EINVAL;
  57. cmd = vmw_fifo_reserve(dev_priv, cmd_size);
  58. if (unlikely(cmd == NULL)) {
  59. DRM_ERROR("Fifo reserve failed.\n");
  60. return -ENOMEM;
  61. }
  62. memset(cmd, 0, sizeof(*cmd));
  63. memcpy(&cmd[1], image, image_size);
  64. cmd->cmd = cpu_to_le32(SVGA_CMD_DEFINE_ALPHA_CURSOR);
  65. cmd->cursor.id = cpu_to_le32(0);
  66. cmd->cursor.width = cpu_to_le32(width);
  67. cmd->cursor.height = cpu_to_le32(height);
  68. cmd->cursor.hotspotX = cpu_to_le32(hotspotX);
  69. cmd->cursor.hotspotY = cpu_to_le32(hotspotY);
  70. vmw_fifo_commit(dev_priv, cmd_size);
  71. return 0;
  72. }
  73. void vmw_cursor_update_position(struct vmw_private *dev_priv,
  74. bool show, int x, int y)
  75. {
  76. __le32 __iomem *fifo_mem = dev_priv->mmio_virt;
  77. uint32_t count;
  78. iowrite32(show ? 1 : 0, fifo_mem + SVGA_FIFO_CURSOR_ON);
  79. iowrite32(x, fifo_mem + SVGA_FIFO_CURSOR_X);
  80. iowrite32(y, fifo_mem + SVGA_FIFO_CURSOR_Y);
  81. count = ioread32(fifo_mem + SVGA_FIFO_CURSOR_COUNT);
  82. iowrite32(++count, fifo_mem + SVGA_FIFO_CURSOR_COUNT);
  83. }
  84. int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
  85. uint32_t handle, uint32_t width, uint32_t height)
  86. {
  87. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  88. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  89. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  90. struct vmw_surface *surface = NULL;
  91. struct vmw_dma_buffer *dmabuf = NULL;
  92. int ret;
  93. if (handle) {
  94. ret = vmw_user_surface_lookup_handle(dev_priv, tfile,
  95. handle, &surface);
  96. if (!ret) {
  97. if (!surface->snooper.image) {
  98. DRM_ERROR("surface not suitable for cursor\n");
  99. return -EINVAL;
  100. }
  101. } else {
  102. ret = vmw_user_dmabuf_lookup(tfile,
  103. handle, &dmabuf);
  104. if (ret) {
  105. DRM_ERROR("failed to find surface or dmabuf: %i\n", ret);
  106. return -EINVAL;
  107. }
  108. }
  109. }
  110. /* takedown old cursor */
  111. if (du->cursor_surface) {
  112. du->cursor_surface->snooper.crtc = NULL;
  113. vmw_surface_unreference(&du->cursor_surface);
  114. }
  115. if (du->cursor_dmabuf)
  116. vmw_dmabuf_unreference(&du->cursor_dmabuf);
  117. /* setup new image */
  118. if (surface) {
  119. /* vmw_user_surface_lookup takes one reference */
  120. du->cursor_surface = surface;
  121. du->cursor_surface->snooper.crtc = crtc;
  122. du->cursor_age = du->cursor_surface->snooper.age;
  123. vmw_cursor_update_image(dev_priv, surface->snooper.image,
  124. 64, 64, du->hotspot_x, du->hotspot_y);
  125. } else if (dmabuf) {
  126. struct ttm_bo_kmap_obj map;
  127. unsigned long kmap_offset;
  128. unsigned long kmap_num;
  129. void *virtual;
  130. bool dummy;
  131. /* vmw_user_surface_lookup takes one reference */
  132. du->cursor_dmabuf = dmabuf;
  133. kmap_offset = 0;
  134. kmap_num = (64*64*4) >> PAGE_SHIFT;
  135. ret = ttm_bo_reserve(&dmabuf->base, true, false, false, 0);
  136. if (unlikely(ret != 0)) {
  137. DRM_ERROR("reserve failed\n");
  138. return -EINVAL;
  139. }
  140. ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map);
  141. if (unlikely(ret != 0))
  142. goto err_unreserve;
  143. virtual = ttm_kmap_obj_virtual(&map, &dummy);
  144. vmw_cursor_update_image(dev_priv, virtual, 64, 64,
  145. du->hotspot_x, du->hotspot_y);
  146. ttm_bo_kunmap(&map);
  147. err_unreserve:
  148. ttm_bo_unreserve(&dmabuf->base);
  149. } else {
  150. vmw_cursor_update_position(dev_priv, false, 0, 0);
  151. return 0;
  152. }
  153. vmw_cursor_update_position(dev_priv, true, du->cursor_x, du->cursor_y);
  154. return 0;
  155. }
  156. int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  157. {
  158. struct vmw_private *dev_priv = vmw_priv(crtc->dev);
  159. struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
  160. bool shown = du->cursor_surface || du->cursor_dmabuf ? true : false;
  161. du->cursor_x = x + crtc->x;
  162. du->cursor_y = y + crtc->y;
  163. vmw_cursor_update_position(dev_priv, shown,
  164. du->cursor_x, du->cursor_y);
  165. return 0;
  166. }
  167. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  168. struct ttm_object_file *tfile,
  169. struct ttm_buffer_object *bo,
  170. SVGA3dCmdHeader *header)
  171. {
  172. struct ttm_bo_kmap_obj map;
  173. unsigned long kmap_offset;
  174. unsigned long kmap_num;
  175. SVGA3dCopyBox *box;
  176. unsigned box_count;
  177. void *virtual;
  178. bool dummy;
  179. struct vmw_dma_cmd {
  180. SVGA3dCmdHeader header;
  181. SVGA3dCmdSurfaceDMA dma;
  182. } *cmd;
  183. int ret;
  184. cmd = container_of(header, struct vmw_dma_cmd, header);
  185. /* No snooper installed */
  186. if (!srf->snooper.image)
  187. return;
  188. if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) {
  189. DRM_ERROR("face and mipmap for cursors should never != 0\n");
  190. return;
  191. }
  192. if (cmd->header.size < 64) {
  193. DRM_ERROR("at least one full copy box must be given\n");
  194. return;
  195. }
  196. box = (SVGA3dCopyBox *)&cmd[1];
  197. box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) /
  198. sizeof(SVGA3dCopyBox);
  199. if (cmd->dma.guest.pitch != (64 * 4) ||
  200. cmd->dma.guest.ptr.offset % PAGE_SIZE ||
  201. box->x != 0 || box->y != 0 || box->z != 0 ||
  202. box->srcx != 0 || box->srcy != 0 || box->srcz != 0 ||
  203. box->w != 64 || box->h != 64 || box->d != 1 ||
  204. box_count != 1) {
  205. /* TODO handle none page aligned offsets */
  206. /* TODO handle partial uploads and pitch != 256 */
  207. /* TODO handle more then one copy (size != 64) */
  208. DRM_ERROR("lazy programmer, can't handle weird stuff\n");
  209. return;
  210. }
  211. kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT;
  212. kmap_num = (64*64*4) >> PAGE_SHIFT;
  213. ret = ttm_bo_reserve(bo, true, false, false, 0);
  214. if (unlikely(ret != 0)) {
  215. DRM_ERROR("reserve failed\n");
  216. return;
  217. }
  218. ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map);
  219. if (unlikely(ret != 0))
  220. goto err_unreserve;
  221. virtual = ttm_kmap_obj_virtual(&map, &dummy);
  222. memcpy(srf->snooper.image, virtual, 64*64*4);
  223. srf->snooper.age++;
  224. /* we can't call this function from this function since execbuf has
  225. * reserved fifo space.
  226. *
  227. * if (srf->snooper.crtc)
  228. * vmw_ldu_crtc_cursor_update_image(dev_priv,
  229. * srf->snooper.image, 64, 64,
  230. * du->hotspot_x, du->hotspot_y);
  231. */
  232. ttm_bo_kunmap(&map);
  233. err_unreserve:
  234. ttm_bo_unreserve(bo);
  235. }
  236. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv)
  237. {
  238. struct drm_device *dev = dev_priv->dev;
  239. struct vmw_display_unit *du;
  240. struct drm_crtc *crtc;
  241. mutex_lock(&dev->mode_config.mutex);
  242. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  243. du = vmw_crtc_to_du(crtc);
  244. if (!du->cursor_surface ||
  245. du->cursor_age == du->cursor_surface->snooper.age)
  246. continue;
  247. du->cursor_age = du->cursor_surface->snooper.age;
  248. vmw_cursor_update_image(dev_priv,
  249. du->cursor_surface->snooper.image,
  250. 64, 64, du->hotspot_x, du->hotspot_y);
  251. }
  252. mutex_unlock(&dev->mode_config.mutex);
  253. }
  254. /*
  255. * Generic framebuffer code
  256. */
  257. int vmw_framebuffer_create_handle(struct drm_framebuffer *fb,
  258. struct drm_file *file_priv,
  259. unsigned int *handle)
  260. {
  261. if (handle)
  262. handle = 0;
  263. return 0;
  264. }
  265. /*
  266. * Surface framebuffer code
  267. */
  268. #define vmw_framebuffer_to_vfbs(x) \
  269. container_of(x, struct vmw_framebuffer_surface, base.base)
  270. struct vmw_framebuffer_surface {
  271. struct vmw_framebuffer base;
  272. struct vmw_surface *surface;
  273. struct vmw_dma_buffer *buffer;
  274. struct delayed_work d_work;
  275. struct mutex work_lock;
  276. bool present_fs;
  277. struct list_head head;
  278. struct drm_master *master;
  279. };
  280. /**
  281. * vmw_kms_idle_workqueues - Flush workqueues on this master
  282. *
  283. * @vmaster - Pointer identifying the master, for the surfaces of which
  284. * we idle the dirty work queues.
  285. *
  286. * This function should be called with the ttm lock held in exclusive mode
  287. * to idle all dirty work queues before the fifo is taken down.
  288. *
  289. * The work task may actually requeue itself, but after the flush returns we're
  290. * sure that there's nothing to present, since the ttm lock is held in
  291. * exclusive mode, so the fifo will never get used.
  292. */
  293. void vmw_kms_idle_workqueues(struct vmw_master *vmaster)
  294. {
  295. struct vmw_framebuffer_surface *entry;
  296. mutex_lock(&vmaster->fb_surf_mutex);
  297. list_for_each_entry(entry, &vmaster->fb_surf, head) {
  298. if (cancel_delayed_work_sync(&entry->d_work))
  299. (void) entry->d_work.work.func(&entry->d_work.work);
  300. (void) cancel_delayed_work_sync(&entry->d_work);
  301. }
  302. mutex_unlock(&vmaster->fb_surf_mutex);
  303. }
  304. void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer)
  305. {
  306. struct vmw_framebuffer_surface *vfbs =
  307. vmw_framebuffer_to_vfbs(framebuffer);
  308. struct vmw_master *vmaster = vmw_master(vfbs->master);
  309. mutex_lock(&vmaster->fb_surf_mutex);
  310. list_del(&vfbs->head);
  311. mutex_unlock(&vmaster->fb_surf_mutex);
  312. cancel_delayed_work_sync(&vfbs->d_work);
  313. drm_master_put(&vfbs->master);
  314. drm_framebuffer_cleanup(framebuffer);
  315. vmw_surface_unreference(&vfbs->surface);
  316. kfree(vfbs);
  317. }
  318. static void vmw_framebuffer_present_fs_callback(struct work_struct *work)
  319. {
  320. struct delayed_work *d_work =
  321. container_of(work, struct delayed_work, work);
  322. struct vmw_framebuffer_surface *vfbs =
  323. container_of(d_work, struct vmw_framebuffer_surface, d_work);
  324. struct vmw_surface *surf = vfbs->surface;
  325. struct drm_framebuffer *framebuffer = &vfbs->base.base;
  326. struct vmw_private *dev_priv = vmw_priv(framebuffer->dev);
  327. struct {
  328. SVGA3dCmdHeader header;
  329. SVGA3dCmdPresent body;
  330. SVGA3dCopyRect cr;
  331. } *cmd;
  332. /**
  333. * Strictly we should take the ttm_lock in read mode before accessing
  334. * the fifo, to make sure the fifo is present and up. However,
  335. * instead we flush all workqueues under the ttm lock in exclusive mode
  336. * before taking down the fifo.
  337. */
  338. mutex_lock(&vfbs->work_lock);
  339. if (!vfbs->present_fs)
  340. goto out_unlock;
  341. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
  342. if (unlikely(cmd == NULL))
  343. goto out_resched;
  344. cmd->header.id = cpu_to_le32(SVGA_3D_CMD_PRESENT);
  345. cmd->header.size = cpu_to_le32(sizeof(cmd->body) + sizeof(cmd->cr));
  346. cmd->body.sid = cpu_to_le32(surf->res.id);
  347. cmd->cr.x = cpu_to_le32(0);
  348. cmd->cr.y = cpu_to_le32(0);
  349. cmd->cr.srcx = cmd->cr.x;
  350. cmd->cr.srcy = cmd->cr.y;
  351. cmd->cr.w = cpu_to_le32(framebuffer->width);
  352. cmd->cr.h = cpu_to_le32(framebuffer->height);
  353. vfbs->present_fs = false;
  354. vmw_fifo_commit(dev_priv, sizeof(*cmd));
  355. out_resched:
  356. /**
  357. * Will not re-add if already pending.
  358. */
  359. schedule_delayed_work(&vfbs->d_work, VMWGFX_PRESENT_RATE);
  360. out_unlock:
  361. mutex_unlock(&vfbs->work_lock);
  362. }
  363. int vmw_framebuffer_surface_dirty(struct drm_framebuffer *framebuffer,
  364. struct drm_file *file_priv,
  365. unsigned flags, unsigned color,
  366. struct drm_clip_rect *clips,
  367. unsigned num_clips)
  368. {
  369. struct vmw_private *dev_priv = vmw_priv(framebuffer->dev);
  370. struct vmw_master *vmaster = vmw_master(file_priv->master);
  371. struct vmw_framebuffer_surface *vfbs =
  372. vmw_framebuffer_to_vfbs(framebuffer);
  373. struct vmw_surface *surf = vfbs->surface;
  374. struct drm_clip_rect norect;
  375. SVGA3dCopyRect *cr;
  376. int i, inc = 1;
  377. int ret;
  378. struct {
  379. SVGA3dCmdHeader header;
  380. SVGA3dCmdPresent body;
  381. SVGA3dCopyRect cr;
  382. } *cmd;
  383. if (unlikely(vfbs->master != file_priv->master))
  384. return -EINVAL;
  385. ret = ttm_read_lock(&vmaster->lock, true);
  386. if (unlikely(ret != 0))
  387. return ret;
  388. if (!num_clips ||
  389. !(dev_priv->fifo.capabilities &
  390. SVGA_FIFO_CAP_SCREEN_OBJECT)) {
  391. int ret;
  392. mutex_lock(&vfbs->work_lock);
  393. vfbs->present_fs = true;
  394. ret = schedule_delayed_work(&vfbs->d_work, VMWGFX_PRESENT_RATE);
  395. mutex_unlock(&vfbs->work_lock);
  396. if (ret) {
  397. /**
  398. * No work pending, Force immediate present.
  399. */
  400. vmw_framebuffer_present_fs_callback(&vfbs->d_work.work);
  401. }
  402. ttm_read_unlock(&vmaster->lock);
  403. return 0;
  404. }
  405. if (!num_clips) {
  406. num_clips = 1;
  407. clips = &norect;
  408. norect.x1 = norect.y1 = 0;
  409. norect.x2 = framebuffer->width;
  410. norect.y2 = framebuffer->height;
  411. } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
  412. num_clips /= 2;
  413. inc = 2; /* skip source rects */
  414. }
  415. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd) + (num_clips - 1) * sizeof(cmd->cr));
  416. if (unlikely(cmd == NULL)) {
  417. DRM_ERROR("Fifo reserve failed.\n");
  418. ttm_read_unlock(&vmaster->lock);
  419. return -ENOMEM;
  420. }
  421. memset(cmd, 0, sizeof(*cmd));
  422. cmd->header.id = cpu_to_le32(SVGA_3D_CMD_PRESENT);
  423. cmd->header.size = cpu_to_le32(sizeof(cmd->body) + num_clips * sizeof(cmd->cr));
  424. cmd->body.sid = cpu_to_le32(surf->res.id);
  425. for (i = 0, cr = &cmd->cr; i < num_clips; i++, cr++, clips += inc) {
  426. cr->x = cpu_to_le16(clips->x1);
  427. cr->y = cpu_to_le16(clips->y1);
  428. cr->srcx = cr->x;
  429. cr->srcy = cr->y;
  430. cr->w = cpu_to_le16(clips->x2 - clips->x1);
  431. cr->h = cpu_to_le16(clips->y2 - clips->y1);
  432. }
  433. vmw_fifo_commit(dev_priv, sizeof(*cmd) + (num_clips - 1) * sizeof(cmd->cr));
  434. ttm_read_unlock(&vmaster->lock);
  435. return 0;
  436. }
  437. static struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = {
  438. .destroy = vmw_framebuffer_surface_destroy,
  439. .dirty = vmw_framebuffer_surface_dirty,
  440. .create_handle = vmw_framebuffer_create_handle,
  441. };
  442. static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv,
  443. struct drm_file *file_priv,
  444. struct vmw_surface *surface,
  445. struct vmw_framebuffer **out,
  446. const struct drm_mode_fb_cmd
  447. *mode_cmd)
  448. {
  449. struct drm_device *dev = dev_priv->dev;
  450. struct vmw_framebuffer_surface *vfbs;
  451. enum SVGA3dSurfaceFormat format;
  452. struct vmw_master *vmaster = vmw_master(file_priv->master);
  453. int ret;
  454. /*
  455. * Sanity checks.
  456. */
  457. if (unlikely(surface->mip_levels[0] != 1 ||
  458. surface->num_sizes != 1 ||
  459. surface->sizes[0].width < mode_cmd->width ||
  460. surface->sizes[0].height < mode_cmd->height ||
  461. surface->sizes[0].depth != 1)) {
  462. DRM_ERROR("Incompatible surface dimensions "
  463. "for requested mode.\n");
  464. return -EINVAL;
  465. }
  466. switch (mode_cmd->depth) {
  467. case 32:
  468. format = SVGA3D_A8R8G8B8;
  469. break;
  470. case 24:
  471. format = SVGA3D_X8R8G8B8;
  472. break;
  473. case 16:
  474. format = SVGA3D_R5G6B5;
  475. break;
  476. case 15:
  477. format = SVGA3D_A1R5G5B5;
  478. break;
  479. default:
  480. DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth);
  481. return -EINVAL;
  482. }
  483. if (unlikely(format != surface->format)) {
  484. DRM_ERROR("Invalid surface format for requested mode.\n");
  485. return -EINVAL;
  486. }
  487. vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL);
  488. if (!vfbs) {
  489. ret = -ENOMEM;
  490. goto out_err1;
  491. }
  492. ret = drm_framebuffer_init(dev, &vfbs->base.base,
  493. &vmw_framebuffer_surface_funcs);
  494. if (ret)
  495. goto out_err2;
  496. if (!vmw_surface_reference(surface)) {
  497. DRM_ERROR("failed to reference surface %p\n", surface);
  498. goto out_err3;
  499. }
  500. /* XXX get the first 3 from the surface info */
  501. vfbs->base.base.bits_per_pixel = mode_cmd->bpp;
  502. vfbs->base.base.pitch = mode_cmd->pitch;
  503. vfbs->base.base.depth = mode_cmd->depth;
  504. vfbs->base.base.width = mode_cmd->width;
  505. vfbs->base.base.height = mode_cmd->height;
  506. vfbs->base.pin = &vmw_surface_dmabuf_pin;
  507. vfbs->base.unpin = &vmw_surface_dmabuf_unpin;
  508. vfbs->surface = surface;
  509. vfbs->master = drm_master_get(file_priv->master);
  510. mutex_init(&vfbs->work_lock);
  511. mutex_lock(&vmaster->fb_surf_mutex);
  512. INIT_DELAYED_WORK(&vfbs->d_work, &vmw_framebuffer_present_fs_callback);
  513. list_add_tail(&vfbs->head, &vmaster->fb_surf);
  514. mutex_unlock(&vmaster->fb_surf_mutex);
  515. *out = &vfbs->base;
  516. return 0;
  517. out_err3:
  518. drm_framebuffer_cleanup(&vfbs->base.base);
  519. out_err2:
  520. kfree(vfbs);
  521. out_err1:
  522. return ret;
  523. }
  524. /*
  525. * Dmabuf framebuffer code
  526. */
  527. #define vmw_framebuffer_to_vfbd(x) \
  528. container_of(x, struct vmw_framebuffer_dmabuf, base.base)
  529. struct vmw_framebuffer_dmabuf {
  530. struct vmw_framebuffer base;
  531. struct vmw_dma_buffer *buffer;
  532. };
  533. void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer)
  534. {
  535. struct vmw_framebuffer_dmabuf *vfbd =
  536. vmw_framebuffer_to_vfbd(framebuffer);
  537. drm_framebuffer_cleanup(framebuffer);
  538. vmw_dmabuf_unreference(&vfbd->buffer);
  539. kfree(vfbd);
  540. }
  541. int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer,
  542. struct drm_file *file_priv,
  543. unsigned flags, unsigned color,
  544. struct drm_clip_rect *clips,
  545. unsigned num_clips)
  546. {
  547. struct vmw_private *dev_priv = vmw_priv(framebuffer->dev);
  548. struct vmw_master *vmaster = vmw_master(file_priv->master);
  549. struct drm_clip_rect norect;
  550. int ret;
  551. struct {
  552. uint32_t header;
  553. SVGAFifoCmdUpdate body;
  554. } *cmd;
  555. int i, increment = 1;
  556. ret = ttm_read_lock(&vmaster->lock, true);
  557. if (unlikely(ret != 0))
  558. return ret;
  559. if (!num_clips) {
  560. num_clips = 1;
  561. clips = &norect;
  562. norect.x1 = norect.y1 = 0;
  563. norect.x2 = framebuffer->width;
  564. norect.y2 = framebuffer->height;
  565. } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
  566. num_clips /= 2;
  567. increment = 2;
  568. }
  569. cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd) * num_clips);
  570. if (unlikely(cmd == NULL)) {
  571. DRM_ERROR("Fifo reserve failed.\n");
  572. ttm_read_unlock(&vmaster->lock);
  573. return -ENOMEM;
  574. }
  575. for (i = 0; i < num_clips; i++, clips += increment) {
  576. cmd[i].header = cpu_to_le32(SVGA_CMD_UPDATE);
  577. cmd[i].body.x = cpu_to_le32(clips->x1);
  578. cmd[i].body.y = cpu_to_le32(clips->y1);
  579. cmd[i].body.width = cpu_to_le32(clips->x2 - clips->x1);
  580. cmd[i].body.height = cpu_to_le32(clips->y2 - clips->y1);
  581. }
  582. vmw_fifo_commit(dev_priv, sizeof(*cmd) * num_clips);
  583. ttm_read_unlock(&vmaster->lock);
  584. return 0;
  585. }
  586. static struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = {
  587. .destroy = vmw_framebuffer_dmabuf_destroy,
  588. .dirty = vmw_framebuffer_dmabuf_dirty,
  589. .create_handle = vmw_framebuffer_create_handle,
  590. };
  591. static int vmw_surface_dmabuf_pin(struct vmw_framebuffer *vfb)
  592. {
  593. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  594. struct vmw_framebuffer_surface *vfbs =
  595. vmw_framebuffer_to_vfbs(&vfb->base);
  596. unsigned long size = vfbs->base.base.pitch * vfbs->base.base.height;
  597. int ret;
  598. vfbs->buffer = kzalloc(sizeof(*vfbs->buffer), GFP_KERNEL);
  599. if (unlikely(vfbs->buffer == NULL))
  600. return -ENOMEM;
  601. vmw_overlay_pause_all(dev_priv);
  602. ret = vmw_dmabuf_init(dev_priv, vfbs->buffer, size,
  603. &vmw_vram_ne_placement,
  604. false, &vmw_dmabuf_bo_free);
  605. vmw_overlay_resume_all(dev_priv);
  606. if (unlikely(ret != 0))
  607. vfbs->buffer = NULL;
  608. return ret;
  609. }
  610. static int vmw_surface_dmabuf_unpin(struct vmw_framebuffer *vfb)
  611. {
  612. struct ttm_buffer_object *bo;
  613. struct vmw_framebuffer_surface *vfbs =
  614. vmw_framebuffer_to_vfbs(&vfb->base);
  615. if (unlikely(vfbs->buffer == NULL))
  616. return 0;
  617. bo = &vfbs->buffer->base;
  618. ttm_bo_unref(&bo);
  619. vfbs->buffer = NULL;
  620. return 0;
  621. }
  622. static int vmw_framebuffer_dmabuf_pin(struct vmw_framebuffer *vfb)
  623. {
  624. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  625. struct vmw_framebuffer_dmabuf *vfbd =
  626. vmw_framebuffer_to_vfbd(&vfb->base);
  627. int ret;
  628. vmw_overlay_pause_all(dev_priv);
  629. ret = vmw_dmabuf_to_start_of_vram(dev_priv, vfbd->buffer);
  630. vmw_overlay_resume_all(dev_priv);
  631. WARN_ON(ret != 0);
  632. return 0;
  633. }
  634. static int vmw_framebuffer_dmabuf_unpin(struct vmw_framebuffer *vfb)
  635. {
  636. struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
  637. struct vmw_framebuffer_dmabuf *vfbd =
  638. vmw_framebuffer_to_vfbd(&vfb->base);
  639. if (!vfbd->buffer) {
  640. WARN_ON(!vfbd->buffer);
  641. return 0;
  642. }
  643. return vmw_dmabuf_from_vram(dev_priv, vfbd->buffer);
  644. }
  645. static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv,
  646. struct vmw_dma_buffer *dmabuf,
  647. struct vmw_framebuffer **out,
  648. const struct drm_mode_fb_cmd
  649. *mode_cmd)
  650. {
  651. struct drm_device *dev = dev_priv->dev;
  652. struct vmw_framebuffer_dmabuf *vfbd;
  653. unsigned int requested_size;
  654. int ret;
  655. requested_size = mode_cmd->height * mode_cmd->pitch;
  656. if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) {
  657. DRM_ERROR("Screen buffer object size is too small "
  658. "for requested mode.\n");
  659. return -EINVAL;
  660. }
  661. vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL);
  662. if (!vfbd) {
  663. ret = -ENOMEM;
  664. goto out_err1;
  665. }
  666. ret = drm_framebuffer_init(dev, &vfbd->base.base,
  667. &vmw_framebuffer_dmabuf_funcs);
  668. if (ret)
  669. goto out_err2;
  670. if (!vmw_dmabuf_reference(dmabuf)) {
  671. DRM_ERROR("failed to reference dmabuf %p\n", dmabuf);
  672. goto out_err3;
  673. }
  674. vfbd->base.base.bits_per_pixel = mode_cmd->bpp;
  675. vfbd->base.base.pitch = mode_cmd->pitch;
  676. vfbd->base.base.depth = mode_cmd->depth;
  677. vfbd->base.base.width = mode_cmd->width;
  678. vfbd->base.base.height = mode_cmd->height;
  679. vfbd->base.pin = vmw_framebuffer_dmabuf_pin;
  680. vfbd->base.unpin = vmw_framebuffer_dmabuf_unpin;
  681. vfbd->buffer = dmabuf;
  682. *out = &vfbd->base;
  683. return 0;
  684. out_err3:
  685. drm_framebuffer_cleanup(&vfbd->base.base);
  686. out_err2:
  687. kfree(vfbd);
  688. out_err1:
  689. return ret;
  690. }
  691. /*
  692. * Generic Kernel modesetting functions
  693. */
  694. static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
  695. struct drm_file *file_priv,
  696. struct drm_mode_fb_cmd *mode_cmd)
  697. {
  698. struct vmw_private *dev_priv = vmw_priv(dev);
  699. struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
  700. struct vmw_framebuffer *vfb = NULL;
  701. struct vmw_surface *surface = NULL;
  702. struct vmw_dma_buffer *bo = NULL;
  703. u64 required_size;
  704. int ret;
  705. /**
  706. * This code should be conditioned on Screen Objects not being used.
  707. * If screen objects are used, we can allocate a GMR to hold the
  708. * requested framebuffer.
  709. */
  710. required_size = mode_cmd->pitch * mode_cmd->height;
  711. if (unlikely(required_size > (u64) dev_priv->vram_size)) {
  712. DRM_ERROR("VRAM size is too small for requested mode.\n");
  713. return NULL;
  714. }
  715. /**
  716. * End conditioned code.
  717. */
  718. ret = vmw_user_surface_lookup_handle(dev_priv, tfile,
  719. mode_cmd->handle, &surface);
  720. if (ret)
  721. goto try_dmabuf;
  722. if (!surface->scanout)
  723. goto err_not_scanout;
  724. ret = vmw_kms_new_framebuffer_surface(dev_priv, file_priv, surface,
  725. &vfb, mode_cmd);
  726. /* vmw_user_surface_lookup takes one ref so does new_fb */
  727. vmw_surface_unreference(&surface);
  728. if (ret) {
  729. DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
  730. return ERR_PTR(ret);
  731. }
  732. return &vfb->base;
  733. try_dmabuf:
  734. DRM_INFO("%s: trying buffer\n", __func__);
  735. ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo);
  736. if (ret) {
  737. DRM_ERROR("failed to find buffer: %i\n", ret);
  738. return ERR_PTR(-ENOENT);
  739. }
  740. ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
  741. mode_cmd);
  742. /* vmw_user_dmabuf_lookup takes one ref so does new_fb */
  743. vmw_dmabuf_unreference(&bo);
  744. if (ret) {
  745. DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
  746. return ERR_PTR(ret);
  747. }
  748. return &vfb->base;
  749. err_not_scanout:
  750. DRM_ERROR("surface not marked as scanout\n");
  751. /* vmw_user_surface_lookup takes one ref */
  752. vmw_surface_unreference(&surface);
  753. return ERR_PTR(-EINVAL);
  754. }
  755. static struct drm_mode_config_funcs vmw_kms_funcs = {
  756. .fb_create = vmw_kms_fb_create,
  757. };
  758. int vmw_kms_init(struct vmw_private *dev_priv)
  759. {
  760. struct drm_device *dev = dev_priv->dev;
  761. int ret;
  762. drm_mode_config_init(dev);
  763. dev->mode_config.funcs = &vmw_kms_funcs;
  764. dev->mode_config.min_width = 1;
  765. dev->mode_config.min_height = 1;
  766. /* assumed largest fb size */
  767. dev->mode_config.max_width = 8192;
  768. dev->mode_config.max_height = 8192;
  769. ret = vmw_kms_init_legacy_display_system(dev_priv);
  770. return 0;
  771. }
  772. int vmw_kms_close(struct vmw_private *dev_priv)
  773. {
  774. /*
  775. * Docs says we should take the lock before calling this function
  776. * but since it destroys encoders and our destructor calls
  777. * drm_encoder_cleanup which takes the lock we deadlock.
  778. */
  779. drm_mode_config_cleanup(dev_priv->dev);
  780. vmw_kms_close_legacy_display_system(dev_priv);
  781. return 0;
  782. }
  783. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  784. struct drm_file *file_priv)
  785. {
  786. struct drm_vmw_cursor_bypass_arg *arg = data;
  787. struct vmw_display_unit *du;
  788. struct drm_mode_object *obj;
  789. struct drm_crtc *crtc;
  790. int ret = 0;
  791. mutex_lock(&dev->mode_config.mutex);
  792. if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) {
  793. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  794. du = vmw_crtc_to_du(crtc);
  795. du->hotspot_x = arg->xhot;
  796. du->hotspot_y = arg->yhot;
  797. }
  798. mutex_unlock(&dev->mode_config.mutex);
  799. return 0;
  800. }
  801. obj = drm_mode_object_find(dev, arg->crtc_id, DRM_MODE_OBJECT_CRTC);
  802. if (!obj) {
  803. ret = -EINVAL;
  804. goto out;
  805. }
  806. crtc = obj_to_crtc(obj);
  807. du = vmw_crtc_to_du(crtc);
  808. du->hotspot_x = arg->xhot;
  809. du->hotspot_y = arg->yhot;
  810. out:
  811. mutex_unlock(&dev->mode_config.mutex);
  812. return ret;
  813. }
  814. void vmw_kms_write_svga(struct vmw_private *vmw_priv,
  815. unsigned width, unsigned height, unsigned pitch,
  816. unsigned bbp, unsigned depth)
  817. {
  818. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  819. vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch);
  820. else if (vmw_fifo_have_pitchlock(vmw_priv))
  821. iowrite32(pitch, vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK);
  822. vmw_write(vmw_priv, SVGA_REG_WIDTH, width);
  823. vmw_write(vmw_priv, SVGA_REG_HEIGHT, height);
  824. vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bbp);
  825. vmw_write(vmw_priv, SVGA_REG_DEPTH, depth);
  826. vmw_write(vmw_priv, SVGA_REG_RED_MASK, 0x00ff0000);
  827. vmw_write(vmw_priv, SVGA_REG_GREEN_MASK, 0x0000ff00);
  828. vmw_write(vmw_priv, SVGA_REG_BLUE_MASK, 0x000000ff);
  829. }
  830. int vmw_kms_save_vga(struct vmw_private *vmw_priv)
  831. {
  832. struct vmw_vga_topology_state *save;
  833. uint32_t i;
  834. vmw_priv->vga_width = vmw_read(vmw_priv, SVGA_REG_WIDTH);
  835. vmw_priv->vga_height = vmw_read(vmw_priv, SVGA_REG_HEIGHT);
  836. vmw_priv->vga_depth = vmw_read(vmw_priv, SVGA_REG_DEPTH);
  837. vmw_priv->vga_bpp = vmw_read(vmw_priv, SVGA_REG_BITS_PER_PIXEL);
  838. vmw_priv->vga_pseudo = vmw_read(vmw_priv, SVGA_REG_PSEUDOCOLOR);
  839. vmw_priv->vga_red_mask = vmw_read(vmw_priv, SVGA_REG_RED_MASK);
  840. vmw_priv->vga_blue_mask = vmw_read(vmw_priv, SVGA_REG_BLUE_MASK);
  841. vmw_priv->vga_green_mask = vmw_read(vmw_priv, SVGA_REG_GREEN_MASK);
  842. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  843. vmw_priv->vga_pitchlock =
  844. vmw_read(vmw_priv, SVGA_REG_PITCHLOCK);
  845. else if (vmw_fifo_have_pitchlock(vmw_priv))
  846. vmw_priv->vga_pitchlock = ioread32(vmw_priv->mmio_virt +
  847. SVGA_FIFO_PITCHLOCK);
  848. if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY))
  849. return 0;
  850. vmw_priv->num_displays = vmw_read(vmw_priv,
  851. SVGA_REG_NUM_GUEST_DISPLAYS);
  852. if (vmw_priv->num_displays == 0)
  853. vmw_priv->num_displays = 1;
  854. for (i = 0; i < vmw_priv->num_displays; ++i) {
  855. save = &vmw_priv->vga_save[i];
  856. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i);
  857. save->primary = vmw_read(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY);
  858. save->pos_x = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_X);
  859. save->pos_y = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y);
  860. save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH);
  861. save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT);
  862. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  863. if (i == 0 && vmw_priv->num_displays == 1 &&
  864. save->width == 0 && save->height == 0) {
  865. /*
  866. * It should be fairly safe to assume that these
  867. * values are uninitialized.
  868. */
  869. save->width = vmw_priv->vga_width - save->pos_x;
  870. save->height = vmw_priv->vga_height - save->pos_y;
  871. }
  872. }
  873. return 0;
  874. }
  875. int vmw_kms_restore_vga(struct vmw_private *vmw_priv)
  876. {
  877. struct vmw_vga_topology_state *save;
  878. uint32_t i;
  879. vmw_write(vmw_priv, SVGA_REG_WIDTH, vmw_priv->vga_width);
  880. vmw_write(vmw_priv, SVGA_REG_HEIGHT, vmw_priv->vga_height);
  881. vmw_write(vmw_priv, SVGA_REG_DEPTH, vmw_priv->vga_depth);
  882. vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, vmw_priv->vga_bpp);
  883. vmw_write(vmw_priv, SVGA_REG_PSEUDOCOLOR, vmw_priv->vga_pseudo);
  884. vmw_write(vmw_priv, SVGA_REG_RED_MASK, vmw_priv->vga_red_mask);
  885. vmw_write(vmw_priv, SVGA_REG_GREEN_MASK, vmw_priv->vga_green_mask);
  886. vmw_write(vmw_priv, SVGA_REG_BLUE_MASK, vmw_priv->vga_blue_mask);
  887. if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK)
  888. vmw_write(vmw_priv, SVGA_REG_PITCHLOCK,
  889. vmw_priv->vga_pitchlock);
  890. else if (vmw_fifo_have_pitchlock(vmw_priv))
  891. iowrite32(vmw_priv->vga_pitchlock,
  892. vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK);
  893. if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY))
  894. return 0;
  895. for (i = 0; i < vmw_priv->num_displays; ++i) {
  896. save = &vmw_priv->vga_save[i];
  897. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i);
  898. vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, save->primary);
  899. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, save->pos_x);
  900. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, save->pos_y);
  901. vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, save->width);
  902. vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, save->height);
  903. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  904. }
  905. return 0;
  906. }
  907. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  908. struct drm_file *file_priv)
  909. {
  910. struct vmw_private *dev_priv = vmw_priv(dev);
  911. struct drm_vmw_update_layout_arg *arg =
  912. (struct drm_vmw_update_layout_arg *)data;
  913. struct vmw_master *vmaster = vmw_master(file_priv->master);
  914. void __user *user_rects;
  915. struct drm_vmw_rect *rects;
  916. unsigned rects_size;
  917. int ret;
  918. ret = ttm_read_lock(&vmaster->lock, true);
  919. if (unlikely(ret != 0))
  920. return ret;
  921. if (!arg->num_outputs) {
  922. struct drm_vmw_rect def_rect = {0, 0, 800, 600};
  923. vmw_kms_ldu_update_layout(dev_priv, 1, &def_rect);
  924. goto out_unlock;
  925. }
  926. rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect);
  927. rects = kzalloc(rects_size, GFP_KERNEL);
  928. if (unlikely(!rects)) {
  929. ret = -ENOMEM;
  930. goto out_unlock;
  931. }
  932. user_rects = (void __user *)(unsigned long)arg->rects;
  933. ret = copy_from_user(rects, user_rects, rects_size);
  934. if (unlikely(ret != 0)) {
  935. DRM_ERROR("Failed to get rects.\n");
  936. ret = -EFAULT;
  937. goto out_free;
  938. }
  939. vmw_kms_ldu_update_layout(dev_priv, arg->num_outputs, rects);
  940. out_free:
  941. kfree(rects);
  942. out_unlock:
  943. ttm_read_unlock(&vmaster->lock);
  944. return ret;
  945. }
  946. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  947. uint32_t pitch,
  948. uint32_t height)
  949. {
  950. return ((u64) pitch * (u64) height) < (u64) dev_priv->vram_size;
  951. }
  952. u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc)
  953. {
  954. return 0;
  955. }