Skip to content

Commit 6f75f22

Browse files
ssvbkinsamanka
authored andcommitted
fbdev: add FBIOCOPYAREA ioctl
Based on the patch authored by Ali Gholami Rudi at https://lkml.org/lkml/2009/7/13/153 Provide an ioctl for userspace applications, but only if this operation is hardware accelerated (otherwide it does not make any sense). Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
1 parent 7865237 commit 6f75f22

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎drivers/video/fbmem.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,25 @@ fb_blank(struct fb_info *info, int blank)
10741074
return ret;
10751075
}
10761076

1077+
static int fb_copyarea_user(struct fb_info *info,
1078+
struct fb_copyarea *copy)
1079+
{
1080+
int ret = 0;
1081+
if (!lock_fb_info(info))
1082+
return -ENODEV;
1083+
if (copy->dx + copy->width > info->var.xres ||
1084+
copy->sx + copy->width > info->var.xres ||
1085+
copy->dy + copy->height > info->var.yres ||
1086+
copy->sy + copy->height > info->var.yres) {
1087+
ret = -EINVAL;
1088+
goto out;
1089+
}
1090+
info->fbops->fb_copyarea(info, copy);
1091+
out:
1092+
unlock_fb_info(info);
1093+
return ret;
1094+
}
1095+
10771096
static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
10781097
unsigned long arg)
10791098
{
@@ -1084,6 +1103,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
10841103
struct fb_cmap cmap_from;
10851104
struct fb_cmap_user cmap;
10861105
struct fb_event event;
1106+
struct fb_copyarea copy;
10871107
void __user *argp = (void __user *)arg;
10881108
long ret = 0;
10891109

@@ -1193,6 +1213,15 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
11931213
console_unlock();
11941214
unlock_fb_info(info);
11951215
break;
1216+
case FBIOCOPYAREA:
1217+
if (info->flags & FBINFO_HWACCEL_COPYAREA) {
1218+
/* only provide this ioctl if it is accelerated */
1219+
if (copy_from_user(&copy, argp, sizeof(copy)))
1220+
return -EFAULT;
1221+
ret = fb_copyarea_user(info, &copy);
1222+
break;
1223+
}
1224+
/* fall through */
11961225
default:
11971226
if (!lock_fb_info(info))
11981227
return -ENODEV;
@@ -1345,6 +1374,7 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
13451374
case FBIOPAN_DISPLAY:
13461375
case FBIOGET_CON2FBMAP:
13471376
case FBIOPUT_CON2FBMAP:
1377+
case FBIOCOPYAREA:
13481378
arg = (unsigned long) compat_ptr(arg);
13491379
case FBIOBLANK:
13501380
ret = do_fb_ioctl(info, cmd, arg);

‎include/uapi/linux/fb.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#define FBIOPUT_MODEINFO 0x4617
3535
#define FBIOGET_DISPINFO 0x4618
3636
#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
37+
/*
38+
* HACK: use 'z' in order not to clash with any other ioctl numbers which might
39+
* be concurrently added to the mainline kernel
40+
*/
41+
#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
3742

3843
#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
3944
#define FB_TYPE_PLANES 1 /* Non interleaved planes */

0 commit comments

Comments
 (0)