Skip to content

Commit 7433914

Browse files
Mikulas Patockabzolnier
authored andcommitted
udlfb: allow reallocating the framebuffer
This patch changes udlfb so that it may reallocate the framebuffer when setting higher-resolution mode. If we boot the system without monitor attached, udlfb creates a framebuffer with the size 800x600. This patch makes it possible to select higher videomode with the fbset command when a monitor is attached. Note that there is no reliable way to prevent the system from touching the old framebuffer, so we must not free it. We add it to the list dlfb->deferred_free and free it when the driver is unloaded. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> [b.zolnierkie: sparse fixes] Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
1 parent 0ac319b commit 7433914

2 files changed

Lines changed: 50 additions & 25 deletions

File tree

‎drivers/video/fbdev/udlfb.c‎

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ static bool fb_defio = 1; /* Detect mmap writes using page faults */
7373
static bool shadow = 1; /* Optionally disable shadow framebuffer */
7474
static int pixel_limit; /* Optionally force a pixel resolution limit */
7575

76+
struct dlfb_deferred_free {
77+
struct list_head list;
78+
void *mem;
79+
};
80+
81+
static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info, u32 new_len);
82+
7683
/* dlfb keeps a list of urbs for efficient bulk transfers */
7784
static void dlfb_urb_completion(struct urb *urb);
7885
static struct urb *dlfb_get_urb(struct dlfb_data *dlfb);
@@ -927,6 +934,12 @@ static void dlfb_free(struct kref *kref)
927934
{
928935
struct dlfb_data *dlfb = container_of(kref, struct dlfb_data, kref);
929936

937+
while (!list_empty(&dlfb->deferred_free)) {
938+
struct dlfb_deferred_free *d = list_entry(dlfb->deferred_free.next, struct dlfb_deferred_free, list);
939+
list_del(&d->list);
940+
vfree(d->mem);
941+
kfree(d);
942+
}
930943
vfree(dlfb->backing_buffer);
931944
kfree(dlfb->edid);
932945
kfree(dlfb);
@@ -1020,10 +1033,6 @@ static int dlfb_ops_check_var(struct fb_var_screeninfo *var,
10201033
struct fb_videomode mode;
10211034
struct dlfb_data *dlfb = info->par;
10221035

1023-
/* TODO: support dynamically changing framebuffer size */
1024-
if ((var->xres * var->yres * 2) > info->fix.smem_len)
1025-
return -EINVAL;
1026-
10271036
/* set device-specific elements of var unrelated to mode */
10281037
dlfb_var_color_format(var);
10291038

@@ -1042,6 +1051,7 @@ static int dlfb_ops_set_par(struct fb_info *info)
10421051
u16 *pix_framebuffer;
10431052
int i;
10441053
struct fb_var_screeninfo fvs;
1054+
u32 line_length = info->var.xres * (info->var.bits_per_pixel / 8);
10451055

10461056
/* clear the activate field because it causes spurious miscompares */
10471057
fvs = info->var;
@@ -1051,13 +1061,17 @@ static int dlfb_ops_set_par(struct fb_info *info)
10511061
if (!memcmp(&dlfb->current_mode, &fvs, sizeof(struct fb_var_screeninfo)))
10521062
return 0;
10531063

1064+
result = dlfb_realloc_framebuffer(dlfb, info, info->var.yres * line_length);
1065+
if (result)
1066+
return result;
1067+
10541068
result = dlfb_set_video_mode(dlfb, &info->var);
10551069

10561070
if (result)
10571071
return result;
10581072

10591073
dlfb->current_mode = fvs;
1060-
info->fix.line_length = info->var.xres * (info->var.bits_per_pixel / 8);
1074+
info->fix.line_length = line_length;
10611075

10621076
if (dlfb->fb_count == 0) {
10631077

@@ -1066,11 +1080,11 @@ static int dlfb_ops_set_par(struct fb_info *info)
10661080
pix_framebuffer = (u16 *) info->screen_base;
10671081
for (i = 0; i < info->fix.smem_len / 2; i++)
10681082
pix_framebuffer[i] = 0x37e6;
1069-
1070-
dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres,
1071-
info->screen_base);
10721083
}
10731084

1085+
dlfb_handle_damage(dlfb, 0, 0, info->var.xres, info->var.yres,
1086+
info->screen_base);
1087+
10741088
return 0;
10751089
}
10761090

@@ -1146,21 +1160,29 @@ static struct fb_ops dlfb_ops = {
11461160
};
11471161

11481162

1163+
static void dlfb_deferred_vfree(struct dlfb_data *dlfb, void *mem)
1164+
{
1165+
struct dlfb_deferred_free *d = kmalloc(sizeof(struct dlfb_deferred_free), GFP_KERNEL);
1166+
if (!d)
1167+
return;
1168+
d->mem = mem;
1169+
list_add(&d->list, &dlfb->deferred_free);
1170+
}
1171+
11491172
/*
11501173
* Assumes &info->lock held by caller
11511174
* Assumes no active clients have framebuffer open
11521175
*/
1153-
static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info)
1176+
static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info, u32 new_len)
11541177
{
1155-
int old_len = info->fix.smem_len;
1156-
int new_len;
1157-
unsigned char *old_fb = info->screen_base;
1178+
u32 old_len = info->fix.smem_len;
1179+
const void *old_fb = (const void __force *)info->screen_base;
11581180
unsigned char *new_fb;
11591181
unsigned char *new_back = NULL;
11601182

1161-
new_len = info->fix.line_length * info->var.yres;
1183+
new_len = PAGE_ALIGN(new_len);
11621184

1163-
if (PAGE_ALIGN(new_len) > old_len) {
1185+
if (new_len > old_len) {
11641186
/*
11651187
* Alloc system memory for virtual framebuffer
11661188
*/
@@ -1169,14 +1191,15 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info
11691191
dev_err(info->dev, "Virtual framebuffer alloc failed\n");
11701192
return -ENOMEM;
11711193
}
1194+
memset(new_fb, 0xff, new_len);
11721195

11731196
if (info->screen_base) {
11741197
memcpy(new_fb, old_fb, old_len);
1175-
vfree(info->screen_base);
1198+
dlfb_deferred_vfree(dlfb, (void __force *)info->screen_base);
11761199
}
11771200

1178-
info->screen_base = new_fb;
1179-
info->fix.smem_len = PAGE_ALIGN(new_len);
1201+
info->screen_base = (char __iomem *)new_fb;
1202+
info->fix.smem_len = new_len;
11801203
info->fix.smem_start = (unsigned long) new_fb;
11811204
info->flags = udlfb_info_flags;
11821205

@@ -1192,7 +1215,7 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dlfb, struct fb_info *info
11921215
dev_info(info->dev,
11931216
"No shadow/backing buffer allocated\n");
11941217
else {
1195-
vfree(dlfb->backing_buffer);
1218+
dlfb_deferred_vfree(dlfb, dlfb->backing_buffer);
11961219
dlfb->backing_buffer = new_back;
11971220
}
11981221
}
@@ -1344,11 +1367,6 @@ static int dlfb_setup_modes(struct dlfb_data *dlfb,
13441367
* with mode size info, we can now alloc our framebuffer.
13451368
*/
13461369
memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix));
1347-
info->fix.line_length = info->var.xres *
1348-
(info->var.bits_per_pixel / 8);
1349-
1350-
result = dlfb_realloc_framebuffer(dlfb, info);
1351-
13521370
} else
13531371
result = -EINVAL;
13541372

@@ -1436,7 +1454,10 @@ static ssize_t edid_store(
14361454
if (!dlfb->edid || memcmp(src, dlfb->edid, src_size))
14371455
return -EINVAL;
14381456

1439-
dlfb_ops_set_par(fb_info);
1457+
ret = dlfb_ops_set_par(fb_info);
1458+
if (ret)
1459+
return ret;
1460+
14401461
return src_size;
14411462
}
14421463

@@ -1596,6 +1617,7 @@ static int dlfb_usb_probe(struct usb_interface *intf,
15961617
}
15971618

15981619
kref_init(&dlfb->kref); /* matching kref_put in usb .disconnect fn */
1620+
INIT_LIST_HEAD(&dlfb->deferred_free);
15991621

16001622
dlfb->udev = usbdev;
16011623
usb_set_intfdata(intf, dlfb);
@@ -1693,7 +1715,9 @@ static void dlfb_init_framebuffer_work(struct work_struct *work)
16931715
dlfb_select_std_channel(dlfb);
16941716

16951717
dlfb_ops_check_var(&info->var, info);
1696-
dlfb_ops_set_par(info);
1718+
retval = dlfb_ops_set_par(info);
1719+
if (retval)
1720+
goto error;
16971721

16981722
retval = register_framebuffer(info);
16991723
if (retval < 0) {

‎include/video/udlfb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct dlfb_data {
5858
atomic_t bytes_sent; /* to usb, after compression including overhead */
5959
atomic_t cpu_kcycles_used; /* transpired during pixel processing */
6060
struct fb_var_screeninfo current_mode;
61+
struct list_head deferred_free;
6162
};
6263

6364
#define NR_USB_REQUEST_I2C_SUB_IO 0x02

0 commit comments

Comments
 (0)