xen-fbfront.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Xen para-virtual frame buffer device
  3. *
  4. * Copyright (C) 2005-2006 Anthony Liguori <aliguori@us.ibm.com>
  5. * Copyright (C) 2006-2008 Red Hat, Inc., Markus Armbruster <armbru@redhat.com>
  6. *
  7. * Based on linux/drivers/video/q40fb.c
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. /*
  14. * TODO:
  15. *
  16. * Switch to grant tables when they become capable of dealing with the
  17. * frame buffer.
  18. */
  19. #include <linux/console.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/fb.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/mm.h>
  27. #include <asm/xen/hypervisor.h>
  28. #include <xen/xen.h>
  29. #include <xen/events.h>
  30. #include <xen/page.h>
  31. #include <xen/interface/io/fbif.h>
  32. #include <xen/interface/io/protocols.h>
  33. #include <xen/xenbus.h>
  34. struct xenfb_info {
  35. unsigned char *fb;
  36. struct fb_info *fb_info;
  37. int x1, y1, x2, y2; /* dirty rectangle,
  38. protected by dirty_lock */
  39. spinlock_t dirty_lock;
  40. int nr_pages;
  41. int irq;
  42. struct xenfb_page *page;
  43. unsigned long *mfns;
  44. int update_wanted; /* XENFB_TYPE_UPDATE wanted */
  45. int feature_resize; /* XENFB_TYPE_RESIZE ok */
  46. struct xenfb_resize resize; /* protected by resize_lock */
  47. int resize_dpy; /* ditto */
  48. spinlock_t resize_lock;
  49. struct xenbus_device *xbdev;
  50. };
  51. #define XENFB_DEFAULT_FB_LEN (XENFB_WIDTH * XENFB_HEIGHT * XENFB_DEPTH / 8)
  52. enum { KPARAM_MEM, KPARAM_WIDTH, KPARAM_HEIGHT, KPARAM_CNT };
  53. static int video[KPARAM_CNT] = { 2, XENFB_WIDTH, XENFB_HEIGHT };
  54. module_param_array(video, int, NULL, 0);
  55. MODULE_PARM_DESC(video,
  56. "Video memory size in MB, width, height in pixels (default 2,800,600)");
  57. static void xenfb_make_preferred_console(void);
  58. static int xenfb_remove(struct xenbus_device *);
  59. static void xenfb_init_shared_page(struct xenfb_info *, struct fb_info *);
  60. static int xenfb_connect_backend(struct xenbus_device *, struct xenfb_info *);
  61. static void xenfb_disconnect_backend(struct xenfb_info *);
  62. static void xenfb_send_event(struct xenfb_info *info,
  63. union xenfb_out_event *event)
  64. {
  65. u32 prod;
  66. prod = info->page->out_prod;
  67. /* caller ensures !xenfb_queue_full() */
  68. mb(); /* ensure ring space available */
  69. XENFB_OUT_RING_REF(info->page, prod) = *event;
  70. wmb(); /* ensure ring contents visible */
  71. info->page->out_prod = prod + 1;
  72. notify_remote_via_irq(info->irq);
  73. }
  74. static void xenfb_do_update(struct xenfb_info *info,
  75. int x, int y, int w, int h)
  76. {
  77. union xenfb_out_event event;
  78. memset(&event, 0, sizeof(event));
  79. event.type = XENFB_TYPE_UPDATE;
  80. event.update.x = x;
  81. event.update.y = y;
  82. event.update.width = w;
  83. event.update.height = h;
  84. /* caller ensures !xenfb_queue_full() */
  85. xenfb_send_event(info, &event);
  86. }
  87. static void xenfb_do_resize(struct xenfb_info *info)
  88. {
  89. union xenfb_out_event event;
  90. memset(&event, 0, sizeof(event));
  91. event.resize = info->resize;
  92. /* caller ensures !xenfb_queue_full() */
  93. xenfb_send_event(info, &event);
  94. }
  95. static int xenfb_queue_full(struct xenfb_info *info)
  96. {
  97. u32 cons, prod;
  98. prod = info->page->out_prod;
  99. cons = info->page->out_cons;
  100. return prod - cons == XENFB_OUT_RING_LEN;
  101. }
  102. static void xenfb_handle_resize_dpy(struct xenfb_info *info)
  103. {
  104. unsigned long flags;
  105. spin_lock_irqsave(&info->resize_lock, flags);
  106. if (info->resize_dpy) {
  107. if (!xenfb_queue_full(info)) {
  108. info->resize_dpy = 0;
  109. xenfb_do_resize(info);
  110. }
  111. }
  112. spin_unlock_irqrestore(&info->resize_lock, flags);
  113. }
  114. static void xenfb_refresh(struct xenfb_info *info,
  115. int x1, int y1, int w, int h)
  116. {
  117. unsigned long flags;
  118. int x2 = x1 + w - 1;
  119. int y2 = y1 + h - 1;
  120. xenfb_handle_resize_dpy(info);
  121. if (!info->update_wanted)
  122. return;
  123. spin_lock_irqsave(&info->dirty_lock, flags);
  124. /* Combine with dirty rectangle: */
  125. if (info->y1 < y1)
  126. y1 = info->y1;
  127. if (info->y2 > y2)
  128. y2 = info->y2;
  129. if (info->x1 < x1)
  130. x1 = info->x1;
  131. if (info->x2 > x2)
  132. x2 = info->x2;
  133. if (xenfb_queue_full(info)) {
  134. /* Can't send right now, stash it in the dirty rectangle */
  135. info->x1 = x1;
  136. info->x2 = x2;
  137. info->y1 = y1;
  138. info->y2 = y2;
  139. spin_unlock_irqrestore(&info->dirty_lock, flags);
  140. return;
  141. }
  142. /* Clear dirty rectangle: */
  143. info->x1 = info->y1 = INT_MAX;
  144. info->x2 = info->y2 = 0;
  145. spin_unlock_irqrestore(&info->dirty_lock, flags);
  146. if (x1 <= x2 && y1 <= y2)
  147. xenfb_do_update(info, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
  148. }
  149. static void xenfb_deferred_io(struct fb_info *fb_info,
  150. struct list_head *pagelist)
  151. {
  152. struct xenfb_info *info = fb_info->par;
  153. struct page *page;
  154. unsigned long beg, end;
  155. int y1, y2, miny, maxy;
  156. miny = INT_MAX;
  157. maxy = 0;
  158. list_for_each_entry(page, pagelist, lru) {
  159. beg = page->index << PAGE_SHIFT;
  160. end = beg + PAGE_SIZE - 1;
  161. y1 = beg / fb_info->fix.line_length;
  162. y2 = end / fb_info->fix.line_length;
  163. if (y2 >= fb_info->var.yres)
  164. y2 = fb_info->var.yres - 1;
  165. if (miny > y1)
  166. miny = y1;
  167. if (maxy < y2)
  168. maxy = y2;
  169. }
  170. xenfb_refresh(info, 0, miny, fb_info->var.xres, maxy - miny + 1);
  171. }
  172. static struct fb_deferred_io xenfb_defio = {
  173. .delay = HZ / 20,
  174. .deferred_io = xenfb_deferred_io,
  175. };
  176. static int xenfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  177. unsigned blue, unsigned transp,
  178. struct fb_info *info)
  179. {
  180. u32 v;
  181. if (regno > info->cmap.len)
  182. return 1;
  183. #define CNVT_TOHW(val, width) ((((val)<<(width))+0x7FFF-(val))>>16)
  184. red = CNVT_TOHW(red, info->var.red.length);
  185. green = CNVT_TOHW(green, info->var.green.length);
  186. blue = CNVT_TOHW(blue, info->var.blue.length);
  187. transp = CNVT_TOHW(transp, info->var.transp.length);
  188. #undef CNVT_TOHW
  189. v = (red << info->var.red.offset) |
  190. (green << info->var.green.offset) |
  191. (blue << info->var.blue.offset);
  192. switch (info->var.bits_per_pixel) {
  193. case 16:
  194. case 24:
  195. case 32:
  196. ((u32 *)info->pseudo_palette)[regno] = v;
  197. break;
  198. }
  199. return 0;
  200. }
  201. static void xenfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
  202. {
  203. struct xenfb_info *info = p->par;
  204. sys_fillrect(p, rect);
  205. xenfb_refresh(info, rect->dx, rect->dy, rect->width, rect->height);
  206. }
  207. static void xenfb_imageblit(struct fb_info *p, const struct fb_image *image)
  208. {
  209. struct xenfb_info *info = p->par;
  210. sys_imageblit(p, image);
  211. xenfb_refresh(info, image->dx, image->dy, image->width, image->height);
  212. }
  213. static void xenfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
  214. {
  215. struct xenfb_info *info = p->par;
  216. sys_copyarea(p, area);
  217. xenfb_refresh(info, area->dx, area->dy, area->width, area->height);
  218. }
  219. static ssize_t xenfb_write(struct fb_info *p, const char __user *buf,
  220. size_t count, loff_t *ppos)
  221. {
  222. struct xenfb_info *info = p->par;
  223. ssize_t res;
  224. res = fb_sys_write(p, buf, count, ppos);
  225. xenfb_refresh(info, 0, 0, info->page->width, info->page->height);
  226. return res;
  227. }
  228. static int
  229. xenfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  230. {
  231. struct xenfb_info *xenfb_info;
  232. int required_mem_len;
  233. xenfb_info = info->par;
  234. if (!xenfb_info->feature_resize) {
  235. if (var->xres == video[KPARAM_WIDTH] &&
  236. var->yres == video[KPARAM_HEIGHT] &&
  237. var->bits_per_pixel == xenfb_info->page->depth) {
  238. return 0;
  239. }
  240. return -EINVAL;
  241. }
  242. /* Can't resize past initial width and height */
  243. if (var->xres > video[KPARAM_WIDTH] || var->yres > video[KPARAM_HEIGHT])
  244. return -EINVAL;
  245. required_mem_len = var->xres * var->yres * xenfb_info->page->depth / 8;
  246. if (var->bits_per_pixel == xenfb_info->page->depth &&
  247. var->xres <= info->fix.line_length / (XENFB_DEPTH / 8) &&
  248. required_mem_len <= info->fix.smem_len) {
  249. var->xres_virtual = var->xres;
  250. var->yres_virtual = var->yres;
  251. return 0;
  252. }
  253. return -EINVAL;
  254. }
  255. static int xenfb_set_par(struct fb_info *info)
  256. {
  257. struct xenfb_info *xenfb_info;
  258. unsigned long flags;
  259. xenfb_info = info->par;
  260. spin_lock_irqsave(&xenfb_info->resize_lock, flags);
  261. xenfb_info->resize.type = XENFB_TYPE_RESIZE;
  262. xenfb_info->resize.width = info->var.xres;
  263. xenfb_info->resize.height = info->var.yres;
  264. xenfb_info->resize.stride = info->fix.line_length;
  265. xenfb_info->resize.depth = info->var.bits_per_pixel;
  266. xenfb_info->resize.offset = 0;
  267. xenfb_info->resize_dpy = 1;
  268. spin_unlock_irqrestore(&xenfb_info->resize_lock, flags);
  269. return 0;
  270. }
  271. static struct fb_ops xenfb_fb_ops = {
  272. .owner = THIS_MODULE,
  273. .fb_read = fb_sys_read,
  274. .fb_write = xenfb_write,
  275. .fb_setcolreg = xenfb_setcolreg,
  276. .fb_fillrect = xenfb_fillrect,
  277. .fb_copyarea = xenfb_copyarea,
  278. .fb_imageblit = xenfb_imageblit,
  279. .fb_check_var = xenfb_check_var,
  280. .fb_set_par = xenfb_set_par,
  281. };
  282. static irqreturn_t xenfb_event_handler(int rq, void *dev_id)
  283. {
  284. /*
  285. * No in events recognized, simply ignore them all.
  286. * If you need to recognize some, see xen-kbdfront's
  287. * input_handler() for how to do that.
  288. */
  289. struct xenfb_info *info = dev_id;
  290. struct xenfb_page *page = info->page;
  291. if (page->in_cons != page->in_prod) {
  292. info->page->in_cons = info->page->in_prod;
  293. notify_remote_via_irq(info->irq);
  294. }
  295. /* Flush dirty rectangle: */
  296. xenfb_refresh(info, INT_MAX, INT_MAX, -INT_MAX, -INT_MAX);
  297. return IRQ_HANDLED;
  298. }
  299. static int __devinit xenfb_probe(struct xenbus_device *dev,
  300. const struct xenbus_device_id *id)
  301. {
  302. struct xenfb_info *info;
  303. struct fb_info *fb_info;
  304. int fb_size;
  305. int val;
  306. int ret;
  307. info = kzalloc(sizeof(*info), GFP_KERNEL);
  308. if (info == NULL) {
  309. xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
  310. return -ENOMEM;
  311. }
  312. /* Limit kernel param videoram amount to what is in xenstore */
  313. if (xenbus_scanf(XBT_NIL, dev->otherend, "videoram", "%d", &val) == 1) {
  314. if (val < video[KPARAM_MEM])
  315. video[KPARAM_MEM] = val;
  316. }
  317. /* If requested res does not fit in available memory, use default */
  318. fb_size = video[KPARAM_MEM] * 1024 * 1024;
  319. if (video[KPARAM_WIDTH] * video[KPARAM_HEIGHT] * XENFB_DEPTH / 8
  320. > fb_size) {
  321. video[KPARAM_WIDTH] = XENFB_WIDTH;
  322. video[KPARAM_HEIGHT] = XENFB_HEIGHT;
  323. fb_size = XENFB_DEFAULT_FB_LEN;
  324. }
  325. dev_set_drvdata(&dev->dev, info);
  326. info->xbdev = dev;
  327. info->irq = -1;
  328. info->x1 = info->y1 = INT_MAX;
  329. spin_lock_init(&info->dirty_lock);
  330. spin_lock_init(&info->resize_lock);
  331. info->fb = vzalloc(fb_size);
  332. if (info->fb == NULL)
  333. goto error_nomem;
  334. info->nr_pages = (fb_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
  335. info->mfns = vmalloc(sizeof(unsigned long) * info->nr_pages);
  336. if (!info->mfns)
  337. goto error_nomem;
  338. /* set up shared page */
  339. info->page = (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
  340. if (!info->page)
  341. goto error_nomem;
  342. /* abusing framebuffer_alloc() to allocate pseudo_palette */
  343. fb_info = framebuffer_alloc(sizeof(u32) * 256, NULL);
  344. if (fb_info == NULL)
  345. goto error_nomem;
  346. /* complete the abuse: */
  347. fb_info->pseudo_palette = fb_info->par;
  348. fb_info->par = info;
  349. fb_info->screen_base = info->fb;
  350. fb_info->fbops = &xenfb_fb_ops;
  351. fb_info->var.xres_virtual = fb_info->var.xres = video[KPARAM_WIDTH];
  352. fb_info->var.yres_virtual = fb_info->var.yres = video[KPARAM_HEIGHT];
  353. fb_info->var.bits_per_pixel = XENFB_DEPTH;
  354. fb_info->var.red = (struct fb_bitfield){16, 8, 0};
  355. fb_info->var.green = (struct fb_bitfield){8, 8, 0};
  356. fb_info->var.blue = (struct fb_bitfield){0, 8, 0};
  357. fb_info->var.activate = FB_ACTIVATE_NOW;
  358. fb_info->var.height = -1;
  359. fb_info->var.width = -1;
  360. fb_info->var.vmode = FB_VMODE_NONINTERLACED;
  361. fb_info->fix.visual = FB_VISUAL_TRUECOLOR;
  362. fb_info->fix.line_length = fb_info->var.xres * XENFB_DEPTH / 8;
  363. fb_info->fix.smem_start = 0;
  364. fb_info->fix.smem_len = fb_size;
  365. strcpy(fb_info->fix.id, "xen");
  366. fb_info->fix.type = FB_TYPE_PACKED_PIXELS;
  367. fb_info->fix.accel = FB_ACCEL_NONE;
  368. fb_info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
  369. ret = fb_alloc_cmap(&fb_info->cmap, 256, 0);
  370. if (ret < 0) {
  371. framebuffer_release(fb_info);
  372. xenbus_dev_fatal(dev, ret, "fb_alloc_cmap");
  373. goto error;
  374. }
  375. fb_info->fbdefio = &xenfb_defio;
  376. fb_deferred_io_init(fb_info);
  377. xenfb_init_shared_page(info, fb_info);
  378. ret = xenfb_connect_backend(dev, info);
  379. if (ret < 0)
  380. goto error;
  381. ret = register_framebuffer(fb_info);
  382. if (ret) {
  383. fb_deferred_io_cleanup(fb_info);
  384. fb_dealloc_cmap(&fb_info->cmap);
  385. framebuffer_release(fb_info);
  386. xenbus_dev_fatal(dev, ret, "register_framebuffer");
  387. goto error;
  388. }
  389. info->fb_info = fb_info;
  390. xenfb_make_preferred_console();
  391. return 0;
  392. error_nomem:
  393. ret = -ENOMEM;
  394. xenbus_dev_fatal(dev, ret, "allocating device memory");
  395. error:
  396. xenfb_remove(dev);
  397. return ret;
  398. }
  399. static __devinit void
  400. xenfb_make_preferred_console(void)
  401. {
  402. struct console *c;
  403. if (console_set_on_cmdline)
  404. return;
  405. console_lock();
  406. for_each_console(c) {
  407. if (!strcmp(c->name, "tty") && c->index == 0)
  408. break;
  409. }
  410. console_unlock();
  411. if (c) {
  412. unregister_console(c);
  413. c->flags |= CON_CONSDEV;
  414. c->flags &= ~CON_PRINTBUFFER; /* don't print again */
  415. register_console(c);
  416. }
  417. }
  418. static int xenfb_resume(struct xenbus_device *dev)
  419. {
  420. struct xenfb_info *info = dev_get_drvdata(&dev->dev);
  421. xenfb_disconnect_backend(info);
  422. xenfb_init_shared_page(info, info->fb_info);
  423. return xenfb_connect_backend(dev, info);
  424. }
  425. static int xenfb_remove(struct xenbus_device *dev)
  426. {
  427. struct xenfb_info *info = dev_get_drvdata(&dev->dev);
  428. xenfb_disconnect_backend(info);
  429. if (info->fb_info) {
  430. fb_deferred_io_cleanup(info->fb_info);
  431. unregister_framebuffer(info->fb_info);
  432. fb_dealloc_cmap(&info->fb_info->cmap);
  433. framebuffer_release(info->fb_info);
  434. }
  435. free_page((unsigned long)info->page);
  436. vfree(info->mfns);
  437. vfree(info->fb);
  438. kfree(info);
  439. return 0;
  440. }
  441. static unsigned long vmalloc_to_mfn(void *address)
  442. {
  443. return pfn_to_mfn(vmalloc_to_pfn(address));
  444. }
  445. static void xenfb_init_shared_page(struct xenfb_info *info,
  446. struct fb_info *fb_info)
  447. {
  448. int i;
  449. int epd = PAGE_SIZE / sizeof(info->mfns[0]);
  450. for (i = 0; i < info->nr_pages; i++)
  451. info->mfns[i] = vmalloc_to_mfn(info->fb + i * PAGE_SIZE);
  452. for (i = 0; i * epd < info->nr_pages; i++)
  453. info->page->pd[i] = vmalloc_to_mfn(&info->mfns[i * epd]);
  454. info->page->width = fb_info->var.xres;
  455. info->page->height = fb_info->var.yres;
  456. info->page->depth = fb_info->var.bits_per_pixel;
  457. info->page->line_length = fb_info->fix.line_length;
  458. info->page->mem_length = fb_info->fix.smem_len;
  459. info->page->in_cons = info->page->in_prod = 0;
  460. info->page->out_cons = info->page->out_prod = 0;
  461. }
  462. static int xenfb_connect_backend(struct xenbus_device *dev,
  463. struct xenfb_info *info)
  464. {
  465. int ret, evtchn, irq;
  466. struct xenbus_transaction xbt;
  467. ret = xenbus_alloc_evtchn(dev, &evtchn);
  468. if (ret)
  469. return ret;
  470. irq = bind_evtchn_to_irqhandler(evtchn, xenfb_event_handler,
  471. 0, dev->devicetype, info);
  472. if (irq < 0) {
  473. xenbus_free_evtchn(dev, evtchn);
  474. xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
  475. return irq;
  476. }
  477. again:
  478. ret = xenbus_transaction_start(&xbt);
  479. if (ret) {
  480. xenbus_dev_fatal(dev, ret, "starting transaction");
  481. goto unbind_irq;
  482. }
  483. ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
  484. virt_to_mfn(info->page));
  485. if (ret)
  486. goto error_xenbus;
  487. ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
  488. evtchn);
  489. if (ret)
  490. goto error_xenbus;
  491. ret = xenbus_printf(xbt, dev->nodename, "protocol", "%s",
  492. XEN_IO_PROTO_ABI_NATIVE);
  493. if (ret)
  494. goto error_xenbus;
  495. ret = xenbus_printf(xbt, dev->nodename, "feature-update", "1");
  496. if (ret)
  497. goto error_xenbus;
  498. ret = xenbus_transaction_end(xbt, 0);
  499. if (ret) {
  500. if (ret == -EAGAIN)
  501. goto again;
  502. xenbus_dev_fatal(dev, ret, "completing transaction");
  503. goto unbind_irq;
  504. }
  505. xenbus_switch_state(dev, XenbusStateInitialised);
  506. info->irq = irq;
  507. return 0;
  508. error_xenbus:
  509. xenbus_transaction_end(xbt, 1);
  510. xenbus_dev_fatal(dev, ret, "writing xenstore");
  511. unbind_irq:
  512. unbind_from_irqhandler(irq, info);
  513. return ret;
  514. }
  515. static void xenfb_disconnect_backend(struct xenfb_info *info)
  516. {
  517. /* Prevent xenfb refresh */
  518. info->update_wanted = 0;
  519. if (info->irq >= 0)
  520. unbind_from_irqhandler(info->irq, info);
  521. info->irq = -1;
  522. }
  523. static void xenfb_backend_changed(struct xenbus_device *dev,
  524. enum xenbus_state backend_state)
  525. {
  526. struct xenfb_info *info = dev_get_drvdata(&dev->dev);
  527. int val;
  528. switch (backend_state) {
  529. case XenbusStateInitialising:
  530. case XenbusStateInitialised:
  531. case XenbusStateReconfiguring:
  532. case XenbusStateReconfigured:
  533. case XenbusStateUnknown:
  534. case XenbusStateClosed:
  535. break;
  536. case XenbusStateInitWait:
  537. InitWait:
  538. xenbus_switch_state(dev, XenbusStateConnected);
  539. break;
  540. case XenbusStateConnected:
  541. /*
  542. * Work around xenbus race condition: If backend goes
  543. * through InitWait to Connected fast enough, we can
  544. * get Connected twice here.
  545. */
  546. if (dev->state != XenbusStateConnected)
  547. goto InitWait; /* no InitWait seen yet, fudge it */
  548. if (xenbus_scanf(XBT_NIL, info->xbdev->otherend,
  549. "request-update", "%d", &val) < 0)
  550. val = 0;
  551. if (val)
  552. info->update_wanted = 1;
  553. if (xenbus_scanf(XBT_NIL, dev->otherend,
  554. "feature-resize", "%d", &val) < 0)
  555. val = 0;
  556. info->feature_resize = val;
  557. break;
  558. case XenbusStateClosing:
  559. xenbus_frontend_closed(dev);
  560. break;
  561. }
  562. }
  563. static struct xenbus_device_id xenfb_ids[] = {
  564. { "vfb" },
  565. { "" }
  566. };
  567. static struct xenbus_driver xenfb_driver = {
  568. .name = "vfb",
  569. .owner = THIS_MODULE,
  570. .ids = xenfb_ids,
  571. .probe = xenfb_probe,
  572. .remove = xenfb_remove,
  573. .resume = xenfb_resume,
  574. .otherend_changed = xenfb_backend_changed,
  575. };
  576. static int __init xenfb_init(void)
  577. {
  578. if (!xen_pv_domain())
  579. return -ENODEV;
  580. /* Nothing to do if running in dom0. */
  581. if (xen_initial_domain())
  582. return -ENODEV;
  583. return xenbus_register_frontend(&xenfb_driver);
  584. }
  585. static void __exit xenfb_cleanup(void)
  586. {
  587. xenbus_unregister_driver(&xenfb_driver);
  588. }
  589. module_init(xenfb_init);
  590. module_exit(xenfb_cleanup);
  591. MODULE_DESCRIPTION("Xen virtual framebuffer device frontend");
  592. MODULE_LICENSE("GPL");
  593. MODULE_ALIAS("xen:vfb");