Skip to content

Commit e4dcff1

Browse files
Markus ArmbrusterKAGA-KOKO
authored andcommitted
xen pvfb: Dynamic mode support (screen resizing)
The pvfb backend indicates dynamic mode support by creating node feature_resize with a non-zero value in its xenstore directory. xen-fbfront sends a resize notification event on mode change. Fully backwards compatible both ways. Framebuffer size and initial resolution can be controlled through kernel parameter xen_fbfront.video. The backend enforces a separate size limit, which it advertises in node videoram in its xenstore directory. xen-kbdfront gets the maximum screen resolution from nodes width and height in the backend's xenstore directory instead of hardcoding it. Additional goodie: support for larger framebuffers (512M on a 64-bit system with 4K pages). Changing the number of bits per pixels dynamically is not supported, yet. Ported from http://xenbits.xensource.com/linux-2.6.18-xen.hg?rev/92f7b3144f41 http://xenbits.xensource.com/linux-2.6.18-xen.hg?rev/bfc040135633 Signed-off-by: Pat Campbell <plc@novell.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent f4ad1eb commit e4dcff1

3 files changed

Lines changed: 188 additions & 34 deletions

File tree

‎drivers/input/xen-kbdfront.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ static void xenkbd_backend_changed(struct xenbus_device *dev,
300300
*/
301301
if (dev->state != XenbusStateConnected)
302302
goto InitWait; /* no InitWait seen yet, fudge it */
303+
304+
/* Set input abs params to match backend screen res */
305+
if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
306+
"width", "%d", &val) > 0)
307+
input_set_abs_params(info->ptr, ABS_X, 0, val, 0, 0);
308+
309+
if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
310+
"height", "%d", &val) > 0)
311+
input_set_abs_params(info->ptr, ABS_Y, 0, val, 0, 0);
312+
303313
break;
304314

305315
case XenbusStateClosing:

‎drivers/video/xen-fbfront.c‎

Lines changed: 154 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,47 @@ struct xenfb_info {
4343
struct xenfb_page *page;
4444
unsigned long *mfns;
4545
int update_wanted; /* XENFB_TYPE_UPDATE wanted */
46+
int feature_resize; /* XENFB_TYPE_RESIZE ok */
47+
struct xenfb_resize resize; /* protected by resize_lock */
48+
int resize_dpy; /* ditto */
49+
spinlock_t resize_lock;
4650

4751
struct xenbus_device *xbdev;
4852
};
4953

50-
static u32 xenfb_mem_len = XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8;
54+
#define XENFB_DEFAULT_FB_LEN (XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8)
55+
56+
enum { KPARAM_MEM, KPARAM_WIDTH, KPARAM_HEIGHT, KPARAM_CNT };
57+
static int video[KPARAM_CNT] = { 2, XENFB_WIDTH, XENFB_HEIGHT };
58+
module_param_array(video, int, NULL, 0);
59+
MODULE_PARM_DESC(video,
60+
"Video memory size in MB, width, height in pixels (default 2,800,600)");
5161

5262
static void xenfb_make_preferred_console(void);
5363
static int xenfb_remove(struct xenbus_device *);
54-
static void xenfb_init_shared_page(struct xenfb_info *);
64+
static void xenfb_init_shared_page(struct xenfb_info *, struct fb_info *);
5565
static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
5666
static void xenfb_disconnect_backend(struct xenfb_info *);
5767

68+
static void xenfb_send_event(struct xenfb_info *info,
69+
union xenfb_out_event *event)
70+
{
71+
u32 prod;
72+
73+
prod = info->page->out_prod;
74+
/* caller ensures !xenfb_queue_full() */
75+
mb(); /* ensure ring space available */
76+
XENFB_OUT_RING_REF(info->page, prod) = *event;
77+
wmb(); /* ensure ring contents visible */
78+
info->page->out_prod = prod + 1;
79+
80+
notify_remote_via_irq(info->irq);
81+
}
82+
5883
static void xenfb_do_update(struct xenfb_info *info,
5984
int x, int y, int w, int h)
6085
{
6186
union xenfb_out_event event;
62-
u32 prod;
6387

6488
memset(&event, 0, sizeof(event));
6589
event.type = XENFB_TYPE_UPDATE;
@@ -68,14 +92,19 @@ static void xenfb_do_update(struct xenfb_info *info,
6892
event.update.width = w;
6993
event.update.height = h;
7094

71-
prod = info->page->out_prod;
7295
/* caller ensures !xenfb_queue_full() */
73-
mb(); /* ensure ring space available */
74-
XENFB_OUT_RING_REF(info->page, prod) = event;
75-
wmb(); /* ensure ring contents visible */
76-
info->page->out_prod = prod + 1;
96+
xenfb_send_event(info, &event);
97+
}
7798

78-
notify_remote_via_irq(info->irq);
99+
static void xenfb_do_resize(struct xenfb_info *info)
100+
{
101+
union xenfb_out_event event;
102+
103+
memset(&event, 0, sizeof(event));
104+
event.resize = info->resize;
105+
106+
/* caller ensures !xenfb_queue_full() */
107+
xenfb_send_event(info, &event);
79108
}
80109

81110
static int xenfb_queue_full(struct xenfb_info *info)
@@ -87,12 +116,28 @@ static int xenfb_queue_full(struct xenfb_info *info)
87116
return prod - cons == XENFB_OUT_RING_LEN;
88117
}
89118

119+
static void xenfb_handle_resize_dpy(struct xenfb_info *info)
120+
{
121+
unsigned long flags;
122+
123+
spin_lock_irqsave(&info->resize_lock, flags);
124+
if (info->resize_dpy) {
125+
if (!xenfb_queue_full(info)) {
126+
info->resize_dpy = 0;
127+
xenfb_do_resize(info);
128+
}
129+
}
130+
spin_unlock_irqrestore(&info->resize_lock, flags);
131+
}
132+
90133
static void xenfb_refresh(struct xenfb_info *info,
91134
int x1, int y1, int w, int h)
92135
{
93136
unsigned long flags;
94-
int y2 = y1 + h - 1;
95137
int x2 = x1 + w - 1;
138+
int y2 = y1 + h - 1;
139+
140+
xenfb_handle_resize_dpy(info);
96141

97142
if (!info->update_wanted)
98143
return;
@@ -225,6 +270,57 @@ static ssize_t xenfb_write(struct fb_info *p, const char __user *buf,
225270
return res;
226271
}
227272

273+
static int
274+
xenfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
275+
{
276+
struct xenfb_info *xenfb_info;
277+
int required_mem_len;
278+
279+
xenfb_info = info->par;
280+
281+
if (!xenfb_info->feature_resize) {
282+
if (var->xres == video[KPARAM_WIDTH] &&
283+
var->yres == video[KPARAM_HEIGHT] &&
284+
var->bits_per_pixel == xenfb_info->page->depth) {
285+
return 0;
286+
}
287+
return -EINVAL;
288+
}
289+
290+
/* Can't resize past initial width and height */
291+
if (var->xres > video[KPARAM_WIDTH] || var->yres > video[KPARAM_HEIGHT])
292+
return -EINVAL;
293+
294+
required_mem_len = var->xres * var->yres * xenfb_info->page->depth / 8;
295+
if (var->bits_per_pixel == xenfb_info->page->depth &&
296+
var->xres <= info->fix.line_length / (XENFB_DEPTH / 8) &&
297+
required_mem_len <= info->fix.smem_len) {
298+
var->xres_virtual = var->xres;
299+
var->yres_virtual = var->yres;
300+
return 0;
301+
}
302+
return -EINVAL;
303+
}
304+
305+
static int xenfb_set_par(struct fb_info *info)
306+
{
307+
struct xenfb_info *xenfb_info;
308+
unsigned long flags;
309+
310+
xenfb_info = info->par;
311+
312+
spin_lock_irqsave(&xenfb_info->resize_lock, flags);
313+
xenfb_info->resize.type = XENFB_TYPE_RESIZE;
314+
xenfb_info->resize.width = info->var.xres;
315+
xenfb_info->resize.height = info->var.yres;
316+
xenfb_info->resize.stride = info->fix.line_length;
317+
xenfb_info->resize.depth = info->var.bits_per_pixel;
318+
xenfb_info->resize.offset = 0;
319+
xenfb_info->resize_dpy = 1;
320+
spin_unlock_irqrestore(&xenfb_info->resize_lock, flags);
321+
return 0;
322+
}
323+
228324
static struct fb_ops xenfb_fb_ops = {
229325
.owner = THIS_MODULE,
230326
.fb_read = fb_sys_read,
@@ -233,6 +329,8 @@ static struct fb_ops xenfb_fb_ops = {
233329
.fb_fillrect = xenfb_fillrect,
234330
.fb_copyarea = xenfb_copyarea,
235331
.fb_imageblit = xenfb_imageblit,
332+
.fb_check_var = xenfb_check_var,
333+
.fb_set_par = xenfb_set_par,
236334
};
237335

238336
static irqreturn_t xenfb_event_handler(int rq, void *dev_id)
@@ -261,25 +359,44 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
261359
{
262360
struct xenfb_info *info;
263361
struct fb_info *fb_info;
362+
int fb_size;
363+
int val;
264364
int ret;
265365

266366
info = kzalloc(sizeof(*info), GFP_KERNEL);
267367
if (info == NULL) {
268368
xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
269369
return -ENOMEM;
270370
}
371+
372+
/* Limit kernel param videoram amount to what is in xenstore */
373+
if (xenbus_scanf(XBT_NIL, dev->otherend, "videoram", "%d", &val) == 1) {
374+
if (val < video[KPARAM_MEM])
375+
video[KPARAM_MEM] = val;
376+
}
377+
378+
/* If requested res does not fit in available memory, use default */
379+
fb_size = video[KPARAM_MEM] * 1024 * 1024;
380+
if (video[KPARAM_WIDTH] * video[KPARAM_HEIGHT] * XENFB_DEPTH / 8
381+
> fb_size) {
382+
video[KPARAM_WIDTH] = XENFB_WIDTH;
383+
video[KPARAM_HEIGHT] = XENFB_HEIGHT;
384+
fb_size = XENFB_DEFAULT_FB_LEN;
385+
}
386+
271387
dev->dev.driver_data = info;
272388
info->xbdev = dev;
273389
info->irq = -1;
274390
info->x1 = info->y1 = INT_MAX;
275391
spin_lock_init(&info->dirty_lock);
392+
spin_lock_init(&info->resize_lock);
276393

277-
info->fb = vmalloc(xenfb_mem_len);
394+
info->fb = vmalloc(fb_size);
278395
if (info->fb == NULL)
279396
goto error_nomem;
280-
memset(info->fb, 0, xenfb_mem_len);
397+
memset(info->fb, 0, fb_size);
281398

282-
info->nr_pages = (xenfb_mem_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
399+
info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
283400

284401
info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
285402
if (!info->mfns)
@@ -290,8 +407,6 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
290407
if (!info->page)
291408
goto error_nomem;
292409

293-
xenfb_init_shared_page(info);
294-
295410
/* abusing framebuffer_alloc() to allocate pseudo_palette */
296411
fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
297412
if (fb_info == NULL)
@@ -304,9 +419,9 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
304419
fb_info->screen_base = info->fb;
305420

306421
fb_info->fbops = &xenfb_fb_ops;
307-
fb_info->var.xres_virtual = fb_info->var.xres = info->page->width;
308-
fb_info->var.yres_virtual = fb_info->var.yres = info->page->height;
309-
fb_info->var.bits_per_pixel = info->page->depth;
422+
fb_info->var.xres_virtual = fb_info->var.xres = video[KPARAM_WIDTH];
423+
fb_info->var.yres_virtual = fb_info->var.yres = video[KPARAM_HEIGHT];
424+
fb_info->var.bits_per_pixel = XENFB_DEPTH;
310425

311426
fb_info->var.red = (struct fb_bitfield){16, 8, 0};
312427
fb_info->var.green = (struct fb_bitfield){8, 8, 0};
@@ -318,9 +433,9 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
318433
fb_info->var.vmode = FB_VMODE_NONINTERLACED;
319434

320435
fb_info->fix.visual = FB_VISUAL_TRUECOLOR;
321-
fb_info->fix.line_length = info->page->line_length;
436+
fb_info->fix.line_length = fb_info->var.xres * XENFB_DEPTH / 8;
322437
fb_info->fix.smem_start = 0;
323-
fb_info->fix.smem_len = xenfb_mem_len;
438+
fb_info->fix.smem_len = fb_size;
324439
strcpy(fb_info->fix.id, "xen");
325440
fb_info->fix.type = FB_TYPE_PACKED_PIXELS;
326441
fb_info->fix.accel = FB_ACCEL_NONE;
@@ -337,6 +452,8 @@ static int __devinit xenfb_probe(struct xenbus_device *dev,
337452
fb_info->fbdefio = &xenfb_defio;
338453
fb_deferred_io_init(fb_info);
339454

455+
xenfb_init_shared_page(info, fb_info);
456+
340457
ret = register_framebuffer(fb_info);
341458
if (ret) {
342459
fb_deferred_io_cleanup(fb_info);
@@ -389,7 +506,7 @@ static int xenfb_resume(struct xenbus_device *dev)
389506
struct xenfb_info *info = dev->dev.driver_data;
390507

391508
xenfb_disconnect_backend(info);
392-
xenfb_init_shared_page(info);
509+
xenfb_init_shared_page(info, info->fb_info);
393510
return xenfb_connect_backend(dev, info);
394511
}
395512

@@ -417,20 +534,23 @@ static unsigned long vmalloc_to_mfn(void *address)
417534
return pfn_to_mfn(vmalloc_to_pfn(address));
418535
}
419536

420-
static void xenfb_init_shared_page(struct xenfb_info *info)
537+
static void xenfb_init_shared_page(struct xenfb_info *info,
538+
struct fb_info *fb_info)
421539
{
422540
int i;
541+
int epd = PAGE_SIZE / sizeof(info->mfns[0]);
423542

424543
for (i = 0; i < info->nr_pages; i++)
425544
info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
426545

427-
info->page->pd[0] = vmalloc_to_mfn(info->mfns);
428-
info->page->pd[1] = 0;
429-
info->page->width = XENFB_WIDTH;
430-
info->page->height = XENFB_HEIGHT;
431-
info->page->depth = XENFB_DEPTH;
432-
info->page->line_length = (info->page->depth / 8) * info->page->width;
433-
info->page->mem_length = xenfb_mem_len;
546+
for (i = 0; i * epd < info->nr_pages; i++)
547+
info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
548+
549+
info->page->width = fb_info->var.xres;
550+
info->page->height = fb_info->var.yres;
551+
info->page->depth = fb_info->var.bits_per_pixel;
552+
info->page->line_length = fb_info->fix.line_length;
553+
info->page->mem_length = fb_info->fix.smem_len;
434554
info->page->in_cons = info->page->in_prod = 0;
435555
info->page->out_cons = info->page->out_prod = 0;
436556
}
@@ -530,6 +650,11 @@ static void xenfb_backend_changed(struct xenbus_device *dev,
530650
val = 0;
531651
if (val)
532652
info->update_wanted = 1;
653+
654+
if (xenbus_scanf(XBT_NIL, dev->otherend,
655+
"feature-resize", "%d", &val) < 0)
656+
val = 0;
657+
info->feature_resize = val;
533658
break;
534659

535660
case XenbusStateClosing:

‎include/xen/interface/io/fbif.h‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ struct xenfb_update {
4949
int32_t height; /* rect height */
5050
};
5151

52+
/*
53+
* Framebuffer resize notification event
54+
* Capable backend sets feature-resize in xenstore.
55+
*/
56+
#define XENFB_TYPE_RESIZE 3
57+
58+
struct xenfb_resize {
59+
uint8_t type; /* XENFB_TYPE_RESIZE */
60+
int32_t width; /* width in pixels */
61+
int32_t height; /* height in pixels */
62+
int32_t stride; /* stride in bytes */
63+
int32_t depth; /* depth in bits */
64+
int32_t offset; /* start offset within framebuffer */
65+
};
66+
5267
#define XENFB_OUT_EVENT_SIZE 40
5368

5469
union xenfb_out_event {
5570
uint8_t type;
5671
struct xenfb_update update;
72+
struct xenfb_resize resize;
5773
char pad[XENFB_OUT_EVENT_SIZE];
5874
};
5975

@@ -105,15 +121,18 @@ struct xenfb_page {
105121
* Each directory page holds PAGE_SIZE / sizeof(*pd)
106122
* framebuffer pages, and can thus map up to PAGE_SIZE *
107123
* PAGE_SIZE / sizeof(*pd) bytes. With PAGE_SIZE == 4096 and
108-
* sizeof(unsigned long) == 4, that's 4 Megs. Two directory
109-
* pages should be enough for a while.
124+
* sizeof(unsigned long) == 4/8, that's 4 Megs 32 bit and 2
125+
* Megs 64 bit. 256 directories give enough room for a 512
126+
* Meg framebuffer with a max resolution of 12,800x10,240.
127+
* Should be enough for a while with room leftover for
128+
* expansion.
110129
*/
111-
unsigned long pd[2];
130+
unsigned long pd[256];
112131
};
113132

114133
/*
115-
* Wart: xenkbd needs to know resolution. Put it here until a better
116-
* solution is found, but don't leak it to the backend.
134+
* Wart: xenkbd needs to know default resolution. Put it here until a
135+
* better solution is found, but don't leak it to the backend.
117136
*/
118137
#ifdef __KERNEL__
119138
#define XENFB_WIDTH 800

0 commit comments

Comments
 (0)