udl_fb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Copyright (C) 2012 Red Hat
  3. *
  4. * based in parts on udlfb.c:
  5. * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
  6. * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
  7. * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License v2. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/fb.h>
  16. #include <linux/dma-buf.h>
  17. #include <drm/drmP.h>
  18. #include <drm/drm_crtc.h>
  19. #include <drm/drm_crtc_helper.h>
  20. #include "udl_drv.h"
  21. #include <drm/drm_fb_helper.h>
  22. #define DL_DEFIO_WRITE_DELAY 5 /* fb_deferred_io.delay in jiffies */
  23. static int fb_defio = 1; /* Optionally enable experimental fb_defio mmap support */
  24. static int fb_bpp = 16;
  25. module_param(fb_bpp, int, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
  26. module_param(fb_defio, int, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP);
  27. struct udl_fbdev {
  28. struct drm_fb_helper helper;
  29. struct udl_framebuffer ufb;
  30. struct list_head fbdev_list;
  31. int fb_count;
  32. };
  33. #define DL_ALIGN_UP(x, a) ALIGN(x, a)
  34. #define DL_ALIGN_DOWN(x, a) ALIGN(x-(a-1), a)
  35. /** Read the red component (0..255) of a 32 bpp colour. */
  36. #define DLO_RGB_GETRED(col) (uint8_t)((col) & 0xFF)
  37. /** Read the green component (0..255) of a 32 bpp colour. */
  38. #define DLO_RGB_GETGRN(col) (uint8_t)(((col) >> 8) & 0xFF)
  39. /** Read the blue component (0..255) of a 32 bpp colour. */
  40. #define DLO_RGB_GETBLU(col) (uint8_t)(((col) >> 16) & 0xFF)
  41. /** Return red/green component of a 16 bpp colour number. */
  42. #define DLO_RG16(red, grn) (uint8_t)((((red) & 0xF8) | ((grn) >> 5)) & 0xFF)
  43. /** Return green/blue component of a 16 bpp colour number. */
  44. #define DLO_GB16(grn, blu) (uint8_t)(((((grn) & 0x1C) << 3) | ((blu) >> 3)) & 0xFF)
  45. /** Return 8 bpp colour number from red, green and blue components. */
  46. #define DLO_RGB8(red, grn, blu) ((((red) << 5) | (((grn) & 3) << 3) | ((blu) & 7)) & 0xFF)
  47. #if 0
  48. static uint8_t rgb8(uint32_t col)
  49. {
  50. uint8_t red = DLO_RGB_GETRED(col);
  51. uint8_t grn = DLO_RGB_GETGRN(col);
  52. uint8_t blu = DLO_RGB_GETBLU(col);
  53. return DLO_RGB8(red, grn, blu);
  54. }
  55. static uint16_t rgb16(uint32_t col)
  56. {
  57. uint8_t red = DLO_RGB_GETRED(col);
  58. uint8_t grn = DLO_RGB_GETGRN(col);
  59. uint8_t blu = DLO_RGB_GETBLU(col);
  60. return (DLO_RG16(red, grn) << 8) + DLO_GB16(grn, blu);
  61. }
  62. #endif
  63. /*
  64. * NOTE: fb_defio.c is holding info->fbdefio.mutex
  65. * Touching ANY framebuffer memory that triggers a page fault
  66. * in fb_defio will cause a deadlock, when it also tries to
  67. * grab the same mutex.
  68. */
  69. static void udlfb_dpy_deferred_io(struct fb_info *info,
  70. struct list_head *pagelist)
  71. {
  72. struct page *cur;
  73. struct fb_deferred_io *fbdefio = info->fbdefio;
  74. struct udl_fbdev *ufbdev = info->par;
  75. struct drm_device *dev = ufbdev->ufb.base.dev;
  76. struct udl_device *udl = dev->dev_private;
  77. struct urb *urb;
  78. char *cmd;
  79. cycles_t start_cycles, end_cycles;
  80. int bytes_sent = 0;
  81. int bytes_identical = 0;
  82. int bytes_rendered = 0;
  83. if (!fb_defio)
  84. return;
  85. start_cycles = get_cycles();
  86. urb = udl_get_urb(dev);
  87. if (!urb)
  88. return;
  89. cmd = urb->transfer_buffer;
  90. /* walk the written page list and render each to device */
  91. list_for_each_entry(cur, &fbdefio->pagelist, lru) {
  92. if (udl_render_hline(dev, (ufbdev->ufb.base.bits_per_pixel / 8),
  93. &urb, (char *) info->fix.smem_start,
  94. &cmd, cur->index << PAGE_SHIFT,
  95. cur->index << PAGE_SHIFT,
  96. PAGE_SIZE, &bytes_identical, &bytes_sent))
  97. goto error;
  98. bytes_rendered += PAGE_SIZE;
  99. }
  100. if (cmd > (char *) urb->transfer_buffer) {
  101. /* Send partial buffer remaining before exiting */
  102. int len = cmd - (char *) urb->transfer_buffer;
  103. udl_submit_urb(dev, urb, len);
  104. bytes_sent += len;
  105. } else
  106. udl_urb_completion(urb);
  107. error:
  108. atomic_add(bytes_sent, &udl->bytes_sent);
  109. atomic_add(bytes_identical, &udl->bytes_identical);
  110. atomic_add(bytes_rendered, &udl->bytes_rendered);
  111. end_cycles = get_cycles();
  112. atomic_add(((unsigned int) ((end_cycles - start_cycles)
  113. >> 10)), /* Kcycles */
  114. &udl->cpu_kcycles_used);
  115. }
  116. int udl_handle_damage(struct udl_framebuffer *fb, int x, int y,
  117. int width, int height)
  118. {
  119. struct drm_device *dev = fb->base.dev;
  120. struct udl_device *udl = dev->dev_private;
  121. int i, ret;
  122. char *cmd;
  123. cycles_t start_cycles, end_cycles;
  124. int bytes_sent = 0;
  125. int bytes_identical = 0;
  126. struct urb *urb;
  127. int aligned_x;
  128. int bpp = (fb->base.bits_per_pixel / 8);
  129. if (!fb->active_16)
  130. return 0;
  131. if (!fb->obj->vmapping) {
  132. ret = udl_gem_vmap(fb->obj);
  133. if (ret == -ENOMEM) {
  134. DRM_ERROR("failed to vmap fb\n");
  135. return 0;
  136. }
  137. if (!fb->obj->vmapping) {
  138. DRM_ERROR("failed to vmapping\n");
  139. return 0;
  140. }
  141. }
  142. start_cycles = get_cycles();
  143. aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long));
  144. width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long));
  145. x = aligned_x;
  146. if ((width <= 0) ||
  147. (x + width > fb->base.width) ||
  148. (y + height > fb->base.height))
  149. return -EINVAL;
  150. urb = udl_get_urb(dev);
  151. if (!urb)
  152. return 0;
  153. cmd = urb->transfer_buffer;
  154. for (i = y; i < y + height ; i++) {
  155. const int line_offset = fb->base.pitches[0] * i;
  156. const int byte_offset = line_offset + (x * bpp);
  157. const int dev_byte_offset = (fb->base.width * bpp * i) + (x * bpp);
  158. if (udl_render_hline(dev, bpp, &urb,
  159. (char *) fb->obj->vmapping,
  160. &cmd, byte_offset, dev_byte_offset,
  161. width * bpp,
  162. &bytes_identical, &bytes_sent))
  163. goto error;
  164. }
  165. if (cmd > (char *) urb->transfer_buffer) {
  166. /* Send partial buffer remaining before exiting */
  167. int len = cmd - (char *) urb->transfer_buffer;
  168. ret = udl_submit_urb(dev, urb, len);
  169. bytes_sent += len;
  170. } else
  171. udl_urb_completion(urb);
  172. error:
  173. atomic_add(bytes_sent, &udl->bytes_sent);
  174. atomic_add(bytes_identical, &udl->bytes_identical);
  175. atomic_add(width*height*bpp, &udl->bytes_rendered);
  176. end_cycles = get_cycles();
  177. atomic_add(((unsigned int) ((end_cycles - start_cycles)
  178. >> 10)), /* Kcycles */
  179. &udl->cpu_kcycles_used);
  180. return 0;
  181. }
  182. static int udl_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  183. {
  184. unsigned long start = vma->vm_start;
  185. unsigned long size = vma->vm_end - vma->vm_start;
  186. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  187. unsigned long page, pos;
  188. if (offset + size > info->fix.smem_len)
  189. return -EINVAL;
  190. pos = (unsigned long)info->fix.smem_start + offset;
  191. pr_notice("mmap() framebuffer addr:%lu size:%lu\n",
  192. pos, size);
  193. while (size > 0) {
  194. page = vmalloc_to_pfn((void *)pos);
  195. if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED))
  196. return -EAGAIN;
  197. start += PAGE_SIZE;
  198. pos += PAGE_SIZE;
  199. if (size > PAGE_SIZE)
  200. size -= PAGE_SIZE;
  201. else
  202. size = 0;
  203. }
  204. /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by remap_pfn_range() */
  205. return 0;
  206. }
  207. static void udl_fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  208. {
  209. struct udl_fbdev *ufbdev = info->par;
  210. sys_fillrect(info, rect);
  211. udl_handle_damage(&ufbdev->ufb, rect->dx, rect->dy, rect->width,
  212. rect->height);
  213. }
  214. static void udl_fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  215. {
  216. struct udl_fbdev *ufbdev = info->par;
  217. sys_copyarea(info, region);
  218. udl_handle_damage(&ufbdev->ufb, region->dx, region->dy, region->width,
  219. region->height);
  220. }
  221. static void udl_fb_imageblit(struct fb_info *info, const struct fb_image *image)
  222. {
  223. struct udl_fbdev *ufbdev = info->par;
  224. sys_imageblit(info, image);
  225. udl_handle_damage(&ufbdev->ufb, image->dx, image->dy, image->width,
  226. image->height);
  227. }
  228. /*
  229. * It's common for several clients to have framebuffer open simultaneously.
  230. * e.g. both fbcon and X. Makes things interesting.
  231. * Assumes caller is holding info->lock (for open and release at least)
  232. */
  233. static int udl_fb_open(struct fb_info *info, int user)
  234. {
  235. struct udl_fbdev *ufbdev = info->par;
  236. struct drm_device *dev = ufbdev->ufb.base.dev;
  237. struct udl_device *udl = dev->dev_private;
  238. /* If the USB device is gone, we don't accept new opens */
  239. if (drm_device_is_unplugged(udl->ddev))
  240. return -ENODEV;
  241. ufbdev->fb_count++;
  242. if (fb_defio && (info->fbdefio == NULL)) {
  243. /* enable defio at last moment if not disabled by client */
  244. struct fb_deferred_io *fbdefio;
  245. fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
  246. if (fbdefio) {
  247. fbdefio->delay = DL_DEFIO_WRITE_DELAY;
  248. fbdefio->deferred_io = udlfb_dpy_deferred_io;
  249. }
  250. info->fbdefio = fbdefio;
  251. fb_deferred_io_init(info);
  252. }
  253. pr_notice("open /dev/fb%d user=%d fb_info=%p count=%d\n",
  254. info->node, user, info, ufbdev->fb_count);
  255. return 0;
  256. }
  257. /*
  258. * Assumes caller is holding info->lock mutex (for open and release at least)
  259. */
  260. static int udl_fb_release(struct fb_info *info, int user)
  261. {
  262. struct udl_fbdev *ufbdev = info->par;
  263. ufbdev->fb_count--;
  264. if ((ufbdev->fb_count == 0) && (info->fbdefio)) {
  265. fb_deferred_io_cleanup(info);
  266. kfree(info->fbdefio);
  267. info->fbdefio = NULL;
  268. info->fbops->fb_mmap = udl_fb_mmap;
  269. }
  270. pr_warn("released /dev/fb%d user=%d count=%d\n",
  271. info->node, user, ufbdev->fb_count);
  272. return 0;
  273. }
  274. static struct fb_ops udlfb_ops = {
  275. .owner = THIS_MODULE,
  276. .fb_check_var = drm_fb_helper_check_var,
  277. .fb_set_par = drm_fb_helper_set_par,
  278. .fb_fillrect = udl_fb_fillrect,
  279. .fb_copyarea = udl_fb_copyarea,
  280. .fb_imageblit = udl_fb_imageblit,
  281. .fb_pan_display = drm_fb_helper_pan_display,
  282. .fb_blank = drm_fb_helper_blank,
  283. .fb_setcmap = drm_fb_helper_setcmap,
  284. .fb_debug_enter = drm_fb_helper_debug_enter,
  285. .fb_debug_leave = drm_fb_helper_debug_leave,
  286. .fb_mmap = udl_fb_mmap,
  287. .fb_open = udl_fb_open,
  288. .fb_release = udl_fb_release,
  289. };
  290. static void udl_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  291. u16 blue, int regno)
  292. {
  293. }
  294. static void udl_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  295. u16 *blue, int regno)
  296. {
  297. *red = 0;
  298. *green = 0;
  299. *blue = 0;
  300. }
  301. static int udl_user_framebuffer_dirty(struct drm_framebuffer *fb,
  302. struct drm_file *file,
  303. unsigned flags, unsigned color,
  304. struct drm_clip_rect *clips,
  305. unsigned num_clips)
  306. {
  307. struct udl_framebuffer *ufb = to_udl_fb(fb);
  308. int i;
  309. int ret = 0;
  310. if (!ufb->active_16)
  311. return 0;
  312. if (ufb->obj->base.import_attach) {
  313. ret = dma_buf_begin_cpu_access(ufb->obj->base.import_attach->dmabuf,
  314. 0, ufb->obj->base.size,
  315. DMA_FROM_DEVICE);
  316. if (ret)
  317. return ret;
  318. }
  319. for (i = 0; i < num_clips; i++) {
  320. ret = udl_handle_damage(ufb, clips[i].x1, clips[i].y1,
  321. clips[i].x2 - clips[i].x1,
  322. clips[i].y2 - clips[i].y1);
  323. if (ret)
  324. break;
  325. }
  326. if (ufb->obj->base.import_attach) {
  327. dma_buf_end_cpu_access(ufb->obj->base.import_attach->dmabuf,
  328. 0, ufb->obj->base.size,
  329. DMA_FROM_DEVICE);
  330. }
  331. return ret;
  332. }
  333. static void udl_user_framebuffer_destroy(struct drm_framebuffer *fb)
  334. {
  335. struct udl_framebuffer *ufb = to_udl_fb(fb);
  336. if (ufb->obj)
  337. drm_gem_object_unreference_unlocked(&ufb->obj->base);
  338. drm_framebuffer_cleanup(fb);
  339. kfree(ufb);
  340. }
  341. static const struct drm_framebuffer_funcs udlfb_funcs = {
  342. .destroy = udl_user_framebuffer_destroy,
  343. .dirty = udl_user_framebuffer_dirty,
  344. };
  345. static int
  346. udl_framebuffer_init(struct drm_device *dev,
  347. struct udl_framebuffer *ufb,
  348. struct drm_mode_fb_cmd2 *mode_cmd,
  349. struct udl_gem_object *obj)
  350. {
  351. int ret;
  352. ufb->obj = obj;
  353. drm_helper_mode_fill_fb_struct(&ufb->base, mode_cmd);
  354. ret = drm_framebuffer_init(dev, &ufb->base, &udlfb_funcs);
  355. return ret;
  356. }
  357. static int udlfb_create(struct udl_fbdev *ufbdev,
  358. struct drm_fb_helper_surface_size *sizes)
  359. {
  360. struct drm_device *dev = ufbdev->helper.dev;
  361. struct fb_info *info;
  362. struct device *device = &dev->usbdev->dev;
  363. struct drm_framebuffer *fb;
  364. struct drm_mode_fb_cmd2 mode_cmd;
  365. struct udl_gem_object *obj;
  366. uint32_t size;
  367. int ret = 0;
  368. if (sizes->surface_bpp == 24)
  369. sizes->surface_bpp = 32;
  370. mode_cmd.width = sizes->surface_width;
  371. mode_cmd.height = sizes->surface_height;
  372. mode_cmd.pitches[0] = mode_cmd.width * ((sizes->surface_bpp + 7) / 8);
  373. mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
  374. sizes->surface_depth);
  375. size = mode_cmd.pitches[0] * mode_cmd.height;
  376. size = ALIGN(size, PAGE_SIZE);
  377. obj = udl_gem_alloc_object(dev, size);
  378. if (!obj)
  379. goto out;
  380. ret = udl_gem_vmap(obj);
  381. if (ret) {
  382. DRM_ERROR("failed to vmap fb\n");
  383. goto out_gfree;
  384. }
  385. info = framebuffer_alloc(0, device);
  386. if (!info) {
  387. ret = -ENOMEM;
  388. goto out_gfree;
  389. }
  390. info->par = ufbdev;
  391. ret = udl_framebuffer_init(dev, &ufbdev->ufb, &mode_cmd, obj);
  392. if (ret)
  393. goto out_gfree;
  394. fb = &ufbdev->ufb.base;
  395. ufbdev->helper.fb = fb;
  396. ufbdev->helper.fbdev = info;
  397. strcpy(info->fix.id, "udldrmfb");
  398. info->screen_base = ufbdev->ufb.obj->vmapping;
  399. info->fix.smem_len = size;
  400. info->fix.smem_start = (unsigned long)ufbdev->ufb.obj->vmapping;
  401. info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
  402. info->fbops = &udlfb_ops;
  403. drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
  404. drm_fb_helper_fill_var(info, &ufbdev->helper, sizes->fb_width, sizes->fb_height);
  405. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  406. if (ret) {
  407. ret = -ENOMEM;
  408. goto out_gfree;
  409. }
  410. DRM_DEBUG_KMS("allocated %dx%d vmal %p\n",
  411. fb->width, fb->height,
  412. ufbdev->ufb.obj->vmapping);
  413. return ret;
  414. out_gfree:
  415. drm_gem_object_unreference(&ufbdev->ufb.obj->base);
  416. out:
  417. return ret;
  418. }
  419. static int udl_fb_find_or_create_single(struct drm_fb_helper *helper,
  420. struct drm_fb_helper_surface_size *sizes)
  421. {
  422. struct udl_fbdev *ufbdev = (struct udl_fbdev *)helper;
  423. int new_fb = 0;
  424. int ret;
  425. if (!helper->fb) {
  426. ret = udlfb_create(ufbdev, sizes);
  427. if (ret)
  428. return ret;
  429. new_fb = 1;
  430. }
  431. return new_fb;
  432. }
  433. static struct drm_fb_helper_funcs udl_fb_helper_funcs = {
  434. .gamma_set = udl_crtc_fb_gamma_set,
  435. .gamma_get = udl_crtc_fb_gamma_get,
  436. .fb_probe = udl_fb_find_or_create_single,
  437. };
  438. static void udl_fbdev_destroy(struct drm_device *dev,
  439. struct udl_fbdev *ufbdev)
  440. {
  441. struct fb_info *info;
  442. if (ufbdev->helper.fbdev) {
  443. info = ufbdev->helper.fbdev;
  444. unregister_framebuffer(info);
  445. if (info->cmap.len)
  446. fb_dealloc_cmap(&info->cmap);
  447. framebuffer_release(info);
  448. }
  449. drm_fb_helper_fini(&ufbdev->helper);
  450. drm_framebuffer_cleanup(&ufbdev->ufb.base);
  451. drm_gem_object_unreference_unlocked(&ufbdev->ufb.obj->base);
  452. }
  453. int udl_fbdev_init(struct drm_device *dev)
  454. {
  455. struct udl_device *udl = dev->dev_private;
  456. int bpp_sel = fb_bpp;
  457. struct udl_fbdev *ufbdev;
  458. int ret;
  459. ufbdev = kzalloc(sizeof(struct udl_fbdev), GFP_KERNEL);
  460. if (!ufbdev)
  461. return -ENOMEM;
  462. udl->fbdev = ufbdev;
  463. ufbdev->helper.funcs = &udl_fb_helper_funcs;
  464. ret = drm_fb_helper_init(dev, &ufbdev->helper,
  465. 1, 1);
  466. if (ret) {
  467. kfree(ufbdev);
  468. return ret;
  469. }
  470. drm_fb_helper_single_add_all_connectors(&ufbdev->helper);
  471. drm_fb_helper_initial_config(&ufbdev->helper, bpp_sel);
  472. return 0;
  473. }
  474. void udl_fbdev_cleanup(struct drm_device *dev)
  475. {
  476. struct udl_device *udl = dev->dev_private;
  477. if (!udl->fbdev)
  478. return;
  479. udl_fbdev_destroy(dev, udl->fbdev);
  480. kfree(udl->fbdev);
  481. udl->fbdev = NULL;
  482. }
  483. void udl_fbdev_unplug(struct drm_device *dev)
  484. {
  485. struct udl_device *udl = dev->dev_private;
  486. struct udl_fbdev *ufbdev;
  487. if (!udl->fbdev)
  488. return;
  489. ufbdev = udl->fbdev;
  490. if (ufbdev->helper.fbdev) {
  491. struct fb_info *info;
  492. info = ufbdev->helper.fbdev;
  493. unlink_framebuffer(info);
  494. }
  495. }
  496. struct drm_framebuffer *
  497. udl_fb_user_fb_create(struct drm_device *dev,
  498. struct drm_file *file,
  499. struct drm_mode_fb_cmd2 *mode_cmd)
  500. {
  501. struct drm_gem_object *obj;
  502. struct udl_framebuffer *ufb;
  503. int ret;
  504. uint32_t size;
  505. obj = drm_gem_object_lookup(dev, file, mode_cmd->handles[0]);
  506. if (obj == NULL)
  507. return ERR_PTR(-ENOENT);
  508. size = mode_cmd->pitches[0] * mode_cmd->height;
  509. size = ALIGN(size, PAGE_SIZE);
  510. if (size > obj->size) {
  511. DRM_ERROR("object size not sufficient for fb %d %zu %d %d\n", size, obj->size, mode_cmd->pitches[0], mode_cmd->height);
  512. return ERR_PTR(-ENOMEM);
  513. }
  514. ufb = kzalloc(sizeof(*ufb), GFP_KERNEL);
  515. if (ufb == NULL)
  516. return ERR_PTR(-ENOMEM);
  517. ret = udl_framebuffer_init(dev, ufb, mode_cmd, to_udl_bo(obj));
  518. if (ret) {
  519. kfree(ufb);
  520. return ERR_PTR(-EINVAL);
  521. }
  522. return &ufb->base;
  523. }