0008-fbdev-add-FBIOCOPYAREA-ioctl.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From f67ad61f5999035fad1610d00a966989f34e3ce5 Mon Sep 17 00:00:00 2001
  2. From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
  3. Date: Mon, 17 Jun 2013 13:32:11 +0300
  4. Subject: [PATCH 008/114] fbdev: add FBIOCOPYAREA ioctl
  5. Based on the patch authored by Ali Gholami Rudi at
  6. https://lkml.org/lkml/2009/7/13/153
  7. Provide an ioctl for userspace applications, but only if this operation
  8. is hardware accelerated (otherwide it does not make any sense).
  9. Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
  10. ---
  11. drivers/video/fbdev/core/fbmem.c | 30 ++++++++++++++++++++++++++++++
  12. include/uapi/linux/fb.h | 5 +++++
  13. 2 files changed, 35 insertions(+)
  14. --- a/drivers/video/fbdev/core/fbmem.c
  15. +++ b/drivers/video/fbdev/core/fbmem.c
  16. @@ -1084,6 +1084,25 @@ fb_blank(struct fb_info *info, int blank
  17. }
  18. EXPORT_SYMBOL(fb_blank);
  19. +static int fb_copyarea_user(struct fb_info *info,
  20. + struct fb_copyarea *copy)
  21. +{
  22. + int ret = 0;
  23. + if (!lock_fb_info(info))
  24. + return -ENODEV;
  25. + if (copy->dx + copy->width > info->var.xres ||
  26. + copy->sx + copy->width > info->var.xres ||
  27. + copy->dy + copy->height > info->var.yres ||
  28. + copy->sy + copy->height > info->var.yres) {
  29. + ret = -EINVAL;
  30. + goto out;
  31. + }
  32. + info->fbops->fb_copyarea(info, copy);
  33. +out:
  34. + unlock_fb_info(info);
  35. + return ret;
  36. +}
  37. +
  38. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  39. unsigned long arg)
  40. {
  41. @@ -1094,6 +1113,7 @@ static long do_fb_ioctl(struct fb_info *
  42. struct fb_cmap cmap_from;
  43. struct fb_cmap_user cmap;
  44. struct fb_event event;
  45. + struct fb_copyarea copy;
  46. void __user *argp = (void __user *)arg;
  47. long ret = 0;
  48. @@ -1211,6 +1231,15 @@ static long do_fb_ioctl(struct fb_info *
  49. unlock_fb_info(info);
  50. console_unlock();
  51. break;
  52. + case FBIOCOPYAREA:
  53. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  54. + /* only provide this ioctl if it is accelerated */
  55. + if (copy_from_user(&copy, argp, sizeof(copy)))
  56. + return -EFAULT;
  57. + ret = fb_copyarea_user(info, &copy);
  58. + break;
  59. + }
  60. + /* fall through */
  61. default:
  62. if (!lock_fb_info(info))
  63. return -ENODEV;
  64. @@ -1365,6 +1394,7 @@ static long fb_compat_ioctl(struct file
  65. case FBIOPAN_DISPLAY:
  66. case FBIOGET_CON2FBMAP:
  67. case FBIOPUT_CON2FBMAP:
  68. + case FBIOCOPYAREA:
  69. arg = (unsigned long) compat_ptr(arg);
  70. case FBIOBLANK:
  71. ret = do_fb_ioctl(info, cmd, arg);
  72. --- a/include/uapi/linux/fb.h
  73. +++ b/include/uapi/linux/fb.h
  74. @@ -34,6 +34,11 @@
  75. #define FBIOPUT_MODEINFO 0x4617
  76. #define FBIOGET_DISPINFO 0x4618
  77. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  78. +/*
  79. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  80. + * be concurrently added to the mainline kernel
  81. + */
  82. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  83. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  84. #define FB_TYPE_PLANES 1 /* Non interleaved planes */