Skip to content

Commit 94d705b

Browse files
ssvbpopcornmix
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 403914d commit 94d705b

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
@@ -1083,6 +1083,25 @@ fb_blank(struct fb_info *info, int blank)
10831083
}
10841084
EXPORT_SYMBOL(fb_blank);
10851085

1086+
static int fb_copyarea_user(struct fb_info *info,
1087+
struct fb_copyarea *copy)
1088+
{
1089+
int ret = 0;
1090+
if (!lock_fb_info(info))
1091+
return -ENODEV;
1092+
if (copy->dx + copy->width > info->var.xres ||
1093+
copy->sx + copy->width > info->var.xres ||
1094+
copy->dy + copy->height > info->var.yres ||
1095+
copy->sy + copy->height > info->var.yres) {
1096+
ret = -EINVAL;
1097+
goto out;
1098+
}
1099+
info->fbops->fb_copyarea(info, copy);
1100+
out:
1101+
unlock_fb_info(info);
1102+
return ret;
1103+
}
1104+
10861105
static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
10871106
unsigned long arg)
10881107
{
@@ -1093,6 +1112,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
10931112
struct fb_cmap cmap_from;
10941113
struct fb_cmap_user cmap;
10951114
struct fb_event event;
1115+
struct fb_copyarea copy;
10961116
void __user *argp = (void __user *)arg;
10971117
long ret = 0;
10981118

@@ -1210,6 +1230,15 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
12101230
unlock_fb_info(info);
12111231
console_unlock();
12121232
break;
1233+
case FBIOCOPYAREA:
1234+
if (info->flags & FBINFO_HWACCEL_COPYAREA) {
1235+
/* only provide this ioctl if it is accelerated */
1236+
if (copy_from_user(&copy, argp, sizeof(copy)))
1237+
return -EFAULT;
1238+
ret = fb_copyarea_user(info, &copy);
1239+
break;
1240+
}
1241+
/* fall through */
12131242
default:
12141243
if (!lock_fb_info(info))
12151244
return -ENODEV;
@@ -1364,6 +1393,7 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
13641393
case FBIOPAN_DISPLAY:
13651394
case FBIOGET_CON2FBMAP:
13661395
case FBIOPUT_CON2FBMAP:
1396+
case FBIOCOPYAREA:
13671397
arg = (unsigned long) compat_ptr(arg);
13681398
case FBIOBLANK:
13691399
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)