xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Gareth Stockwell <gareth.stockwell@arm.com>
To: xen-devel@lists.xen.org
Subject: Modifying xenfb colour depth from Android domU
Date: Thu, 28 Aug 2014 10:21:05 +0100	[thread overview]
Message-ID: <53FEF481.1080201@arm.com> (raw)

I'm facing some problems getting xenfb to work with an Android domU, on ARM.

The issue is that the framebuffer is created with a depth of 32bpp,
while the Android guest is rendering RGB565.

I tried to fix this by using the fbdev API to request a change of pixel
format, during the Android startup:

int set_fb_pixel_format()
{
     int fd = open("/dev/graphics/fb0", O_RDWR, 0);

     struct fb_var_screeninfo info;
     if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
         return -errno;
     }

     info.red.offset = 11;
     info.red.length = 5;
     info.green.offset = 5;
     info.green.length = 6;
     info.blue.offset = 0;
     info.blue.length = 5;
     info.transp.offset = 0;
     info.transp.length = 0;
     info.bits_per_pixel = 16;

     info.activate = FB_ACTIVATE_NOW;

     if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
         ALOGE("Selecting RGB565 failed");
         return -errno;
     }

     ...
}

This however fails in the xen-fbfront driver, due to bits_per_pixel not
matching the current framebuffer depth (which comes from #define
XENFB_DEPTH 32):

static int
xenfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
{
      ...

if (var->bits_per_pixel == xenfb_info->page->depth &&
         var->xres <= info->fix.line_length / (XENFB_DEPTH / 8) &&
         required_mem_len <= info->fix.smem_len) {
         var->xres_virtual = var->xres;
         var->yres_virtual = var->yres;
         return 0;
     }
     return -EINVAL;
}

I found that I can fix this in one of two ways:

1. Change the initial depth to 16.  This of course means that guest
rendering in other depths is incorrectly displayed.

diff --git a/include/xen/interface/io/fbif.h
b/include/xen/interface/io/fbif.h
index 974a51e..42b1258 100644
--- a/include/xen/interface/io/fbif.h
+++ b/include/xen/interface/io/fbif.h
@@ -137,7 +137,7 @@ struct xenfb_page {
  #ifdef __KERNEL__
  #define XENFB_WIDTH 800
  #define XENFB_HEIGHT 600
-#define XENFB_DEPTH 32
+#define XENFB_DEPTH 16
  #endif

2. Allow the guest to modify the framebuffer depth.

diff --git a/drivers/video/xen-fbfront.c b/drivers/video/xen-fbfront.c
index 02e1c01..b65a485 100644
--- a/drivers/video/xen-fbfront.c
+++ b/drivers/video/xen-fbfront.c
@@ -295,12 +295,11 @@ xenfb_check_var(struct fb_var_screeninfo *var,
struct fb_info *info)
         if (var->xres > video[KPARAM_WIDTH] || var->yres >
video[KPARAM_HEIGHT])
                 return -EINVAL;

-       required_mem_len = var->xres * var->yres *
xenfb_info->page->depth / 8;
-       if (var->bits_per_pixel == xenfb_info->page->depth &&
-           var->xres <= info->fix.line_length / (XENFB_DEPTH / 8) &&
-           required_mem_len <= info->fix.smem_len) {
+       required_mem_len = var->xres * var->yres * var->bits_per_pixel / 8;
+       if (required_mem_len <= info->fix.smem_len) {
                 var->xres_virtual = var->xres;
                 var->yres_virtual = var->yres;
+               info->fix.line_length = var->xres * var->bits_per_pixel / 8;
                 return 0;
         }
         return -EINVAL;

This works for my case, but involves modifying the
fb_info.fix.line_length value - is this allowed?

Code being used:
linux: refs/tags/v3.10.16, plus "b1a3b1c xen/fb: allow xenfb
initialization for hvm guests"
qemu: refs/tags/v2.1.0-rc3
xen: refs/tags/RELEASE-4.4.0

Note that xenfb_check_var is unchanged in linux master.

Gareth


-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2548782

             reply	other threads:[~2014-08-28  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28  9:21 Gareth Stockwell [this message]
2014-08-28 10:15 ` Modifying xenfb colour depth from Android domU David Vrabel
2014-08-28 11:16   ` Gareth Stockwell
2014-08-28 12:43 ` David Vrabel
2014-09-04 22:38   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53FEF481.1080201@arm.com \
    --to=gareth.stockwell@arm.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).