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