vmwgfx_fb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /**************************************************************************
  2. *
  3. * Copyright © 2007 David Airlie
  4. * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
  5. * All Rights Reserved.
  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 "drmP.h"
  29. #include "vmwgfx_drv.h"
  30. #include "ttm/ttm_placement.h"
  31. #define VMW_DIRTY_DELAY (HZ / 30)
  32. struct vmw_fb_par {
  33. struct vmw_private *vmw_priv;
  34. void *vmalloc;
  35. struct vmw_dma_buffer *vmw_bo;
  36. struct ttm_bo_kmap_obj map;
  37. u32 pseudo_palette[17];
  38. unsigned depth;
  39. unsigned bpp;
  40. unsigned max_width;
  41. unsigned max_height;
  42. void *bo_ptr;
  43. unsigned bo_size;
  44. bool bo_iowrite;
  45. struct {
  46. spinlock_t lock;
  47. bool active;
  48. unsigned x1;
  49. unsigned y1;
  50. unsigned x2;
  51. unsigned y2;
  52. } dirty;
  53. };
  54. static int vmw_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  55. unsigned blue, unsigned transp,
  56. struct fb_info *info)
  57. {
  58. struct vmw_fb_par *par = info->par;
  59. u32 *pal = par->pseudo_palette;
  60. if (regno > 15) {
  61. DRM_ERROR("Bad regno %u.\n", regno);
  62. return 1;
  63. }
  64. switch (par->depth) {
  65. case 24:
  66. case 32:
  67. pal[regno] = ((red & 0xff00) << 8) |
  68. (green & 0xff00) |
  69. ((blue & 0xff00) >> 8);
  70. break;
  71. default:
  72. DRM_ERROR("Bad depth %u, bpp %u.\n", par->depth, par->bpp);
  73. return 1;
  74. }
  75. return 0;
  76. }
  77. static int vmw_fb_check_var(struct fb_var_screeninfo *var,
  78. struct fb_info *info)
  79. {
  80. int depth = var->bits_per_pixel;
  81. struct vmw_fb_par *par = info->par;
  82. struct vmw_private *vmw_priv = par->vmw_priv;
  83. switch (var->bits_per_pixel) {
  84. case 32:
  85. depth = (var->transp.length > 0) ? 32 : 24;
  86. break;
  87. default:
  88. DRM_ERROR("Bad bpp %u.\n", var->bits_per_pixel);
  89. return -EINVAL;
  90. }
  91. switch (depth) {
  92. case 24:
  93. var->red.offset = 16;
  94. var->green.offset = 8;
  95. var->blue.offset = 0;
  96. var->red.length = 8;
  97. var->green.length = 8;
  98. var->blue.length = 8;
  99. var->transp.length = 0;
  100. var->transp.offset = 0;
  101. break;
  102. case 32:
  103. var->red.offset = 16;
  104. var->green.offset = 8;
  105. var->blue.offset = 0;
  106. var->red.length = 8;
  107. var->green.length = 8;
  108. var->blue.length = 8;
  109. var->transp.length = 8;
  110. var->transp.offset = 24;
  111. break;
  112. default:
  113. DRM_ERROR("Bad depth %u.\n", depth);
  114. return -EINVAL;
  115. }
  116. if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY) &&
  117. (var->xoffset != 0 || var->yoffset != 0)) {
  118. DRM_ERROR("Can not handle panning without display topology\n");
  119. return -EINVAL;
  120. }
  121. if ((var->xoffset + var->xres) > par->max_width ||
  122. (var->yoffset + var->yres) > par->max_height) {
  123. DRM_ERROR("Requested geom can not fit in framebuffer\n");
  124. return -EINVAL;
  125. }
  126. return 0;
  127. }
  128. static int vmw_fb_set_par(struct fb_info *info)
  129. {
  130. struct vmw_fb_par *par = info->par;
  131. struct vmw_private *vmw_priv = par->vmw_priv;
  132. vmw_kms_write_svga(vmw_priv, info->var.xres, info->var.yres,
  133. info->fix.line_length,
  134. par->bpp, par->depth);
  135. if (vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY) {
  136. /* TODO check if pitch and offset changes */
  137. vmw_write(vmw_priv, SVGA_REG_NUM_GUEST_DISPLAYS, 1);
  138. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, 0);
  139. vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, true);
  140. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, info->var.xoffset);
  141. vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, info->var.yoffset);
  142. vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, info->var.xres);
  143. vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, info->var.yres);
  144. vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
  145. }
  146. /* This is really helpful since if this fails the user
  147. * can probably not see anything on the screen.
  148. */
  149. WARN_ON(vmw_read(vmw_priv, SVGA_REG_FB_OFFSET) != 0);
  150. return 0;
  151. }
  152. static int vmw_fb_pan_display(struct fb_var_screeninfo *var,
  153. struct fb_info *info)
  154. {
  155. return 0;
  156. }
  157. static int vmw_fb_blank(int blank, struct fb_info *info)
  158. {
  159. return 0;
  160. }
  161. /*
  162. * Dirty code
  163. */
  164. static void vmw_fb_dirty_flush(struct vmw_fb_par *par)
  165. {
  166. struct vmw_private *vmw_priv = par->vmw_priv;
  167. struct fb_info *info = vmw_priv->fb_info;
  168. int stride = (info->fix.line_length / 4);
  169. int *src = (int *)info->screen_base;
  170. __le32 __iomem *vram_mem = par->bo_ptr;
  171. unsigned long flags;
  172. unsigned x, y, w, h;
  173. int i, k;
  174. struct {
  175. uint32_t header;
  176. SVGAFifoCmdUpdate body;
  177. } *cmd;
  178. spin_lock_irqsave(&par->dirty.lock, flags);
  179. if (!par->dirty.active) {
  180. spin_unlock_irqrestore(&par->dirty.lock, flags);
  181. return;
  182. }
  183. x = par->dirty.x1;
  184. y = par->dirty.y1;
  185. w = min(par->dirty.x2, info->var.xres) - x;
  186. h = min(par->dirty.y2, info->var.yres) - y;
  187. par->dirty.x1 = par->dirty.x2 = 0;
  188. par->dirty.y1 = par->dirty.y2 = 0;
  189. spin_unlock_irqrestore(&par->dirty.lock, flags);
  190. for (i = y * stride; i < info->fix.smem_len / 4; i += stride) {
  191. for (k = i+x; k < i+x+w && k < info->fix.smem_len / 4; k++)
  192. iowrite32(src[k], vram_mem + k);
  193. }
  194. #if 0
  195. DRM_INFO("%s, (%u, %u) (%ux%u)\n", __func__, x, y, w, h);
  196. #endif
  197. cmd = vmw_fifo_reserve(vmw_priv, sizeof(*cmd));
  198. if (unlikely(cmd == NULL)) {
  199. DRM_ERROR("Fifo reserve failed.\n");
  200. return;
  201. }
  202. cmd->header = cpu_to_le32(SVGA_CMD_UPDATE);
  203. cmd->body.x = cpu_to_le32(x);
  204. cmd->body.y = cpu_to_le32(y);
  205. cmd->body.width = cpu_to_le32(w);
  206. cmd->body.height = cpu_to_le32(h);
  207. vmw_fifo_commit(vmw_priv, sizeof(*cmd));
  208. }
  209. static void vmw_fb_dirty_mark(struct vmw_fb_par *par,
  210. unsigned x1, unsigned y1,
  211. unsigned width, unsigned height)
  212. {
  213. struct fb_info *info = par->vmw_priv->fb_info;
  214. unsigned long flags;
  215. unsigned x2 = x1 + width;
  216. unsigned y2 = y1 + height;
  217. spin_lock_irqsave(&par->dirty.lock, flags);
  218. if (par->dirty.x1 == par->dirty.x2) {
  219. par->dirty.x1 = x1;
  220. par->dirty.y1 = y1;
  221. par->dirty.x2 = x2;
  222. par->dirty.y2 = y2;
  223. /* if we are active start the dirty work
  224. * we share the work with the defio system */
  225. if (par->dirty.active)
  226. schedule_delayed_work(&info->deferred_work, VMW_DIRTY_DELAY);
  227. } else {
  228. if (x1 < par->dirty.x1)
  229. par->dirty.x1 = x1;
  230. if (y1 < par->dirty.y1)
  231. par->dirty.y1 = y1;
  232. if (x2 > par->dirty.x2)
  233. par->dirty.x2 = x2;
  234. if (y2 > par->dirty.y2)
  235. par->dirty.y2 = y2;
  236. }
  237. spin_unlock_irqrestore(&par->dirty.lock, flags);
  238. }
  239. static void vmw_deferred_io(struct fb_info *info,
  240. struct list_head *pagelist)
  241. {
  242. struct vmw_fb_par *par = info->par;
  243. unsigned long start, end, min, max;
  244. unsigned long flags;
  245. struct page *page;
  246. int y1, y2;
  247. min = ULONG_MAX;
  248. max = 0;
  249. list_for_each_entry(page, pagelist, lru) {
  250. start = page->index << PAGE_SHIFT;
  251. end = start + PAGE_SIZE - 1;
  252. min = min(min, start);
  253. max = max(max, end);
  254. }
  255. if (min < max) {
  256. y1 = min / info->fix.line_length;
  257. y2 = (max / info->fix.line_length) + 1;
  258. spin_lock_irqsave(&par->dirty.lock, flags);
  259. par->dirty.x1 = 0;
  260. par->dirty.y1 = y1;
  261. par->dirty.x2 = info->var.xres;
  262. par->dirty.y2 = y2;
  263. spin_unlock_irqrestore(&par->dirty.lock, flags);
  264. }
  265. vmw_fb_dirty_flush(par);
  266. };
  267. struct fb_deferred_io vmw_defio = {
  268. .delay = VMW_DIRTY_DELAY,
  269. .deferred_io = vmw_deferred_io,
  270. };
  271. /*
  272. * Draw code
  273. */
  274. static void vmw_fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  275. {
  276. cfb_fillrect(info, rect);
  277. vmw_fb_dirty_mark(info->par, rect->dx, rect->dy,
  278. rect->width, rect->height);
  279. }
  280. static void vmw_fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  281. {
  282. cfb_copyarea(info, region);
  283. vmw_fb_dirty_mark(info->par, region->dx, region->dy,
  284. region->width, region->height);
  285. }
  286. static void vmw_fb_imageblit(struct fb_info *info, const struct fb_image *image)
  287. {
  288. cfb_imageblit(info, image);
  289. vmw_fb_dirty_mark(info->par, image->dx, image->dy,
  290. image->width, image->height);
  291. }
  292. /*
  293. * Bring up code
  294. */
  295. static struct fb_ops vmw_fb_ops = {
  296. .owner = THIS_MODULE,
  297. .fb_check_var = vmw_fb_check_var,
  298. .fb_set_par = vmw_fb_set_par,
  299. .fb_setcolreg = vmw_fb_setcolreg,
  300. .fb_fillrect = vmw_fb_fillrect,
  301. .fb_copyarea = vmw_fb_copyarea,
  302. .fb_imageblit = vmw_fb_imageblit,
  303. .fb_pan_display = vmw_fb_pan_display,
  304. .fb_blank = vmw_fb_blank,
  305. };
  306. static int vmw_fb_create_bo(struct vmw_private *vmw_priv,
  307. size_t size, struct vmw_dma_buffer **out)
  308. {
  309. struct vmw_dma_buffer *vmw_bo;
  310. struct ttm_placement ne_placement = vmw_vram_ne_placement;
  311. int ret;
  312. ne_placement.lpfn = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
  313. /* interuptable? */
  314. ret = ttm_write_lock(&vmw_priv->fbdev_master.lock, false);
  315. if (unlikely(ret != 0))
  316. return ret;
  317. vmw_bo = kmalloc(sizeof(*vmw_bo), GFP_KERNEL);
  318. if (!vmw_bo)
  319. goto err_unlock;
  320. ret = vmw_dmabuf_init(vmw_priv, vmw_bo, size,
  321. &ne_placement,
  322. false,
  323. &vmw_dmabuf_bo_free);
  324. if (unlikely(ret != 0))
  325. goto err_unlock; /* init frees the buffer on failure */
  326. *out = vmw_bo;
  327. ttm_write_unlock(&vmw_priv->fbdev_master.lock);
  328. return 0;
  329. err_unlock:
  330. ttm_write_unlock(&vmw_priv->fbdev_master.lock);
  331. return ret;
  332. }
  333. int vmw_fb_init(struct vmw_private *vmw_priv)
  334. {
  335. struct device *device = &vmw_priv->dev->pdev->dev;
  336. struct vmw_fb_par *par;
  337. struct fb_info *info;
  338. unsigned initial_width, initial_height;
  339. unsigned fb_width, fb_height;
  340. unsigned fb_bbp, fb_depth, fb_offset, fb_pitch, fb_size;
  341. int ret;
  342. /* XXX These shouldn't be hardcoded. */
  343. initial_width = 800;
  344. initial_height = 600;
  345. fb_bbp = 32;
  346. fb_depth = 24;
  347. /* XXX As shouldn't these be as well. */
  348. fb_width = min(vmw_priv->fb_max_width, (unsigned)2048);
  349. fb_height = min(vmw_priv->fb_max_height, (unsigned)2048);
  350. initial_width = min(fb_width, initial_width);
  351. initial_height = min(fb_height, initial_height);
  352. fb_pitch = fb_width * fb_bbp / 8;
  353. fb_size = fb_pitch * fb_height;
  354. fb_offset = vmw_read(vmw_priv, SVGA_REG_FB_OFFSET);
  355. info = framebuffer_alloc(sizeof(*par), device);
  356. if (!info)
  357. return -ENOMEM;
  358. /*
  359. * Par
  360. */
  361. vmw_priv->fb_info = info;
  362. par = info->par;
  363. par->vmw_priv = vmw_priv;
  364. par->depth = fb_depth;
  365. par->bpp = fb_bbp;
  366. par->vmalloc = NULL;
  367. par->max_width = fb_width;
  368. par->max_height = fb_height;
  369. /*
  370. * Create buffers and alloc memory
  371. */
  372. par->vmalloc = vmalloc(fb_size);
  373. if (unlikely(par->vmalloc == NULL)) {
  374. ret = -ENOMEM;
  375. goto err_free;
  376. }
  377. ret = vmw_fb_create_bo(vmw_priv, fb_size, &par->vmw_bo);
  378. if (unlikely(ret != 0))
  379. goto err_free;
  380. ret = ttm_bo_kmap(&par->vmw_bo->base,
  381. 0,
  382. par->vmw_bo->base.num_pages,
  383. &par->map);
  384. if (unlikely(ret != 0))
  385. goto err_unref;
  386. par->bo_ptr = ttm_kmap_obj_virtual(&par->map, &par->bo_iowrite);
  387. par->bo_size = fb_size;
  388. /*
  389. * Fixed and var
  390. */
  391. strcpy(info->fix.id, "svgadrmfb");
  392. info->fix.type = FB_TYPE_PACKED_PIXELS;
  393. info->fix.visual = FB_VISUAL_TRUECOLOR;
  394. info->fix.type_aux = 0;
  395. info->fix.xpanstep = 1; /* doing it in hw */
  396. info->fix.ypanstep = 1; /* doing it in hw */
  397. info->fix.ywrapstep = 0;
  398. info->fix.accel = FB_ACCEL_NONE;
  399. info->fix.line_length = fb_pitch;
  400. info->fix.smem_start = 0;
  401. info->fix.smem_len = fb_size;
  402. info->fix.mmio_start = 0;
  403. info->fix.mmio_len = 0;
  404. info->pseudo_palette = par->pseudo_palette;
  405. info->screen_base = par->vmalloc;
  406. info->screen_size = fb_size;
  407. info->flags = FBINFO_DEFAULT;
  408. info->fbops = &vmw_fb_ops;
  409. /* 24 depth per default */
  410. info->var.red.offset = 16;
  411. info->var.green.offset = 8;
  412. info->var.blue.offset = 0;
  413. info->var.red.length = 8;
  414. info->var.green.length = 8;
  415. info->var.blue.length = 8;
  416. info->var.transp.offset = 0;
  417. info->var.transp.length = 0;
  418. info->var.xres_virtual = fb_width;
  419. info->var.yres_virtual = fb_height;
  420. info->var.bits_per_pixel = par->bpp;
  421. info->var.xoffset = 0;
  422. info->var.yoffset = 0;
  423. info->var.activate = FB_ACTIVATE_NOW;
  424. info->var.height = -1;
  425. info->var.width = -1;
  426. info->var.xres = initial_width;
  427. info->var.yres = initial_height;
  428. #if 0
  429. info->pixmap.size = 64*1024;
  430. info->pixmap.buf_align = 8;
  431. info->pixmap.access_align = 32;
  432. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  433. info->pixmap.scan_align = 1;
  434. #else
  435. info->pixmap.size = 0;
  436. info->pixmap.buf_align = 8;
  437. info->pixmap.access_align = 32;
  438. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  439. info->pixmap.scan_align = 1;
  440. #endif
  441. info->apertures = alloc_apertures(1);
  442. if (!info->apertures) {
  443. ret = -ENOMEM;
  444. goto err_aper;
  445. }
  446. info->apertures->ranges[0].base = vmw_priv->vram_start;
  447. info->apertures->ranges[0].size = vmw_priv->vram_size;
  448. /*
  449. * Dirty & Deferred IO
  450. */
  451. par->dirty.x1 = par->dirty.x2 = 0;
  452. par->dirty.y1 = par->dirty.y1 = 0;
  453. par->dirty.active = true;
  454. spin_lock_init(&par->dirty.lock);
  455. info->fbdefio = &vmw_defio;
  456. fb_deferred_io_init(info);
  457. ret = register_framebuffer(info);
  458. if (unlikely(ret != 0))
  459. goto err_defio;
  460. return 0;
  461. err_defio:
  462. fb_deferred_io_cleanup(info);
  463. err_aper:
  464. ttm_bo_kunmap(&par->map);
  465. err_unref:
  466. ttm_bo_unref((struct ttm_buffer_object **)&par->vmw_bo);
  467. err_free:
  468. vfree(par->vmalloc);
  469. framebuffer_release(info);
  470. vmw_priv->fb_info = NULL;
  471. return ret;
  472. }
  473. int vmw_fb_close(struct vmw_private *vmw_priv)
  474. {
  475. struct fb_info *info;
  476. struct vmw_fb_par *par;
  477. struct ttm_buffer_object *bo;
  478. if (!vmw_priv->fb_info)
  479. return 0;
  480. info = vmw_priv->fb_info;
  481. par = info->par;
  482. bo = &par->vmw_bo->base;
  483. par->vmw_bo = NULL;
  484. /* ??? order */
  485. fb_deferred_io_cleanup(info);
  486. unregister_framebuffer(info);
  487. ttm_bo_kunmap(&par->map);
  488. ttm_bo_unref(&bo);
  489. vfree(par->vmalloc);
  490. framebuffer_release(info);
  491. return 0;
  492. }
  493. int vmw_dmabuf_from_vram(struct vmw_private *vmw_priv,
  494. struct vmw_dma_buffer *vmw_bo)
  495. {
  496. struct ttm_buffer_object *bo = &vmw_bo->base;
  497. int ret = 0;
  498. ret = ttm_bo_reserve(bo, false, false, false, 0);
  499. if (unlikely(ret != 0))
  500. return ret;
  501. ret = ttm_bo_validate(bo, &vmw_sys_placement, false, false, false);
  502. ttm_bo_unreserve(bo);
  503. return ret;
  504. }
  505. int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
  506. struct vmw_dma_buffer *vmw_bo)
  507. {
  508. struct ttm_buffer_object *bo = &vmw_bo->base;
  509. struct ttm_placement ne_placement = vmw_vram_ne_placement;
  510. int ret = 0;
  511. ne_placement.lpfn = bo->num_pages;
  512. /* interuptable? */
  513. ret = ttm_write_lock(&vmw_priv->active_master->lock, false);
  514. if (unlikely(ret != 0))
  515. return ret;
  516. ret = ttm_bo_reserve(bo, false, false, false, 0);
  517. if (unlikely(ret != 0))
  518. goto err_unlock;
  519. ret = ttm_bo_validate(bo, &ne_placement, false, false, false);
  520. /* Could probably bug on */
  521. WARN_ON(bo->offset != 0);
  522. ttm_bo_unreserve(bo);
  523. err_unlock:
  524. ttm_write_unlock(&vmw_priv->active_master->lock);
  525. return ret;
  526. }
  527. int vmw_fb_off(struct vmw_private *vmw_priv)
  528. {
  529. struct fb_info *info;
  530. struct vmw_fb_par *par;
  531. unsigned long flags;
  532. if (!vmw_priv->fb_info)
  533. return -EINVAL;
  534. info = vmw_priv->fb_info;
  535. par = info->par;
  536. spin_lock_irqsave(&par->dirty.lock, flags);
  537. par->dirty.active = false;
  538. spin_unlock_irqrestore(&par->dirty.lock, flags);
  539. flush_scheduled_work();
  540. par->bo_ptr = NULL;
  541. ttm_bo_kunmap(&par->map);
  542. vmw_dmabuf_from_vram(vmw_priv, par->vmw_bo);
  543. return 0;
  544. }
  545. int vmw_fb_on(struct vmw_private *vmw_priv)
  546. {
  547. struct fb_info *info;
  548. struct vmw_fb_par *par;
  549. unsigned long flags;
  550. bool dummy;
  551. int ret;
  552. if (!vmw_priv->fb_info)
  553. return -EINVAL;
  554. info = vmw_priv->fb_info;
  555. par = info->par;
  556. /* we are already active */
  557. if (par->bo_ptr != NULL)
  558. return 0;
  559. /* Make sure that all overlays are stoped when we take over */
  560. vmw_overlay_stop_all(vmw_priv);
  561. ret = vmw_dmabuf_to_start_of_vram(vmw_priv, par->vmw_bo);
  562. if (unlikely(ret != 0)) {
  563. DRM_ERROR("could not move buffer to start of VRAM\n");
  564. goto err_no_buffer;
  565. }
  566. ret = ttm_bo_kmap(&par->vmw_bo->base,
  567. 0,
  568. par->vmw_bo->base.num_pages,
  569. &par->map);
  570. BUG_ON(ret != 0);
  571. par->bo_ptr = ttm_kmap_obj_virtual(&par->map, &dummy);
  572. spin_lock_irqsave(&par->dirty.lock, flags);
  573. par->dirty.active = true;
  574. spin_unlock_irqrestore(&par->dirty.lock, flags);
  575. err_no_buffer:
  576. vmw_fb_set_par(info);
  577. vmw_fb_dirty_mark(par, 0, 0, info->var.xres, info->var.yres);
  578. /* If there already was stuff dirty we wont
  579. * schedule a new work, so lets do it now */
  580. schedule_delayed_work(&info->deferred_work, 0);
  581. return 0;
  582. }