From nobody Tue Apr 15 15:44:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535105864331447.1494934607134; Fri, 24 Aug 2018 03:17:44 -0700 (PDT) Received: from localhost ([::1]:40894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft99y-0000Lp-VZ for importer@patchew.org; Fri, 24 Aug 2018 06:17:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft8UK-0007gj-Sv for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ft8UI-0004nK-Sc for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:34:40 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:44896) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ft8UH-0004eK-5m for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:34:37 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1ft8UF-0006eQ-GQ for qemu-devel@nongnu.org; Fri, 24 Aug 2018 10:34:35 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 24 Aug 2018 10:33:35 +0100 Message-Id: <20180824093343.11346-45-peter.maydell@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180824093343.11346-1-peter.maydell@linaro.org> References: <20180824093343.11346-1-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 44/52] hw/misc/bcm2835_fb: Move config fields to their own struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The handling of framebuffer properties in the bcm2835_property code is a bit clumsy, because for each of the many fb related properties we try to track the value we're about to set and whether we're going to be setting a value, and then we hand all the new values off to the framebuffer via a function which takes them all as separate arguments. It would be simpler if the property code could easily copy all the framebuffer's current settings, update them with the new specified values and then ask the framebuffer to switch to the new set. As the first part of this refactoring, pull all the fb config settings fields in BCM2835FBState out into their own struct. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20180814144436.679-2-peter.maydell@linaro.org --- include/hw/display/bcm2835_fb.h | 26 ++++++-- hw/display/bcm2835_fb.c | 114 +++++++++++++++++--------------- hw/misc/bcm2835_property.c | 28 ++++---- 3 files changed, 94 insertions(+), 74 deletions(-) diff --git a/include/hw/display/bcm2835_fb.h b/include/hw/display/bcm2835_f= b.h index ae0a3807f2c..8485825ba5f 100644 --- a/include/hw/display/bcm2835_fb.h +++ b/include/hw/display/bcm2835_fb.h @@ -17,6 +17,20 @@ #define TYPE_BCM2835_FB "bcm2835-fb" #define BCM2835_FB(obj) OBJECT_CHECK(BCM2835FBState, (obj), TYPE_BCM2835_F= B) =20 +/* + * Configuration information about the fb which the guest can program + * via the mailbox property interface. + */ +typedef struct { + uint32_t xres, yres; + uint32_t xres_virtual, yres_virtual; + uint32_t xoffset, yoffset; + uint32_t bpp; + uint32_t base; + uint32_t pixo; + uint32_t alpha; +} BCM2835FBConfig; + typedef struct { /*< private >*/ SysBusDevice busdev; @@ -31,12 +45,12 @@ typedef struct { qemu_irq mbox_irq; =20 bool lock, invalidate, pending; - uint32_t xres, yres; - uint32_t xres_virtual, yres_virtual; - uint32_t xoffset, yoffset; - uint32_t bpp; - uint32_t base, pitch, size; - uint32_t pixo, alpha; + + BCM2835FBConfig config; + + /* These are just cached values calculated from the config settings */ + uint32_t size; + uint32_t pitch; } BCM2835FBState; =20 void bcm2835_fb_reconfigure(BCM2835FBState *s, uint32_t *xres, uint32_t *y= res, diff --git a/hw/display/bcm2835_fb.c b/hw/display/bcm2835_fb.c index 3355f4c131b..0ffad49ab8f 100644 --- a/hw/display/bcm2835_fb.c +++ b/hw/display/bcm2835_fb.c @@ -52,7 +52,7 @@ static void draw_line_src16(void *opaque, uint8_t *dst, c= onst uint8_t *src, int bpp =3D surface_bits_per_pixel(surface); =20 while (width--) { - switch (s->bpp) { + switch (s->config.bpp) { case 8: /* lookup palette starting at video ram base * TODO: cache translation, rather than doing this each time! @@ -91,7 +91,7 @@ static void draw_line_src16(void *opaque, uint8_t *dst, c= onst uint8_t *src, break; } =20 - if (s->pixo =3D=3D 0) { + if (s->config.pixo =3D=3D 0) { /* swap to BGR pixel format */ uint8_t tmp =3D r; r =3D b; @@ -135,12 +135,12 @@ static void fb_update_display(void *opaque) int src_width =3D 0; int dest_width =3D 0; =20 - if (s->lock || !s->xres) { + if (s->lock || !s->config.xres) { return; } =20 - src_width =3D s->xres * (s->bpp >> 3); - dest_width =3D s->xres; + src_width =3D s->config.xres * (s->config.bpp >> 3); + dest_width =3D s->config.xres; =20 switch (surface_bits_per_pixel(surface)) { case 0: @@ -165,16 +165,18 @@ static void fb_update_display(void *opaque) } =20 if (s->invalidate) { - framebuffer_update_memory_section(&s->fbsection, s->dma_mr, s->bas= e, - s->yres, src_width); + framebuffer_update_memory_section(&s->fbsection, s->dma_mr, + s->config.base, + s->config.yres, src_width); } =20 - framebuffer_update_display(surface, &s->fbsection, s->xres, s->yres, + framebuffer_update_display(surface, &s->fbsection, + s->config.xres, s->config.yres, src_width, dest_width, 0, s->invalidate, draw_line_src16, s, &first, &last); =20 if (first >=3D 0) { - dpy_gfx_update(s->con, 0, first, s->xres, last - first + 1); + dpy_gfx_update(s->con, 0, first, s->config.xres, last - first + 1); } =20 s->invalidate =3D false; @@ -186,28 +188,28 @@ static void bcm2835_fb_mbox_push(BCM2835FBState *s, u= int32_t value) =20 s->lock =3D true; =20 - s->xres =3D ldl_le_phys(&s->dma_as, value); - s->yres =3D ldl_le_phys(&s->dma_as, value + 4); - s->xres_virtual =3D ldl_le_phys(&s->dma_as, value + 8); - s->yres_virtual =3D ldl_le_phys(&s->dma_as, value + 12); - s->bpp =3D ldl_le_phys(&s->dma_as, value + 20); - s->xoffset =3D ldl_le_phys(&s->dma_as, value + 24); - s->yoffset =3D ldl_le_phys(&s->dma_as, value + 28); + s->config.xres =3D ldl_le_phys(&s->dma_as, value); + s->config.yres =3D ldl_le_phys(&s->dma_as, value + 4); + s->config.xres_virtual =3D ldl_le_phys(&s->dma_as, value + 8); + s->config.yres_virtual =3D ldl_le_phys(&s->dma_as, value + 12); + s->config.bpp =3D ldl_le_phys(&s->dma_as, value + 20); + s->config.xoffset =3D ldl_le_phys(&s->dma_as, value + 24); + s->config.yoffset =3D ldl_le_phys(&s->dma_as, value + 28); =20 - s->base =3D s->vcram_base | (value & 0xc0000000); - s->base +=3D BCM2835_FB_OFFSET; + s->config.base =3D s->vcram_base | (value & 0xc0000000); + s->config.base +=3D BCM2835_FB_OFFSET; =20 /* TODO - Manage properly virtual resolution */ =20 - s->pitch =3D s->xres * (s->bpp >> 3); - s->size =3D s->yres * s->pitch; + s->pitch =3D s->config.xres * (s->config.bpp >> 3); + s->size =3D s->config.yres * s->pitch; =20 stl_le_phys(&s->dma_as, value + 16, s->pitch); - stl_le_phys(&s->dma_as, value + 32, s->base); + stl_le_phys(&s->dma_as, value + 32, s->config.base); stl_le_phys(&s->dma_as, value + 36, s->size); =20 s->invalidate =3D true; - qemu_console_resize(s->con, s->xres, s->yres); + qemu_console_resize(s->con, s->config.xres, s->config.yres); s->lock =3D false; } =20 @@ -219,34 +221,34 @@ void bcm2835_fb_reconfigure(BCM2835FBState *s, uint32= _t *xres, uint32_t *yres, =20 /* TODO: input validation! */ if (xres) { - s->xres =3D *xres; + s->config.xres =3D *xres; } if (yres) { - s->yres =3D *yres; + s->config.yres =3D *yres; } if (xoffset) { - s->xoffset =3D *xoffset; + s->config.xoffset =3D *xoffset; } if (yoffset) { - s->yoffset =3D *yoffset; + s->config.yoffset =3D *yoffset; } if (bpp) { - s->bpp =3D *bpp; + s->config.bpp =3D *bpp; } if (pixo) { - s->pixo =3D *pixo; + s->config.pixo =3D *pixo; } if (alpha) { - s->alpha =3D *alpha; + s->config.alpha =3D *alpha; } =20 /* TODO - Manage properly virtual resolution */ =20 - s->pitch =3D s->xres * (s->bpp >> 3); - s->size =3D s->yres * s->pitch; + s->pitch =3D s->config.xres * (s->config.bpp >> 3); + s->size =3D s->config.yres * s->pitch; =20 s->invalidate =3D true; - qemu_console_resize(s->con, s->xres, s->yres); + qemu_console_resize(s->con, s->config.xres, s->config.yres); s->lock =3D false; } =20 @@ -312,18 +314,18 @@ static const VMStateDescription vmstate_bcm2835_fb = =3D { VMSTATE_BOOL(lock, BCM2835FBState), VMSTATE_BOOL(invalidate, BCM2835FBState), VMSTATE_BOOL(pending, BCM2835FBState), - VMSTATE_UINT32(xres, BCM2835FBState), - VMSTATE_UINT32(yres, BCM2835FBState), - VMSTATE_UINT32(xres_virtual, BCM2835FBState), - VMSTATE_UINT32(yres_virtual, BCM2835FBState), - VMSTATE_UINT32(xoffset, BCM2835FBState), - VMSTATE_UINT32(yoffset, BCM2835FBState), - VMSTATE_UINT32(bpp, BCM2835FBState), - VMSTATE_UINT32(base, BCM2835FBState), + VMSTATE_UINT32(config.xres, BCM2835FBState), + VMSTATE_UINT32(config.yres, BCM2835FBState), + VMSTATE_UINT32(config.xres_virtual, BCM2835FBState), + VMSTATE_UINT32(config.yres_virtual, BCM2835FBState), + VMSTATE_UINT32(config.xoffset, BCM2835FBState), + VMSTATE_UINT32(config.yoffset, BCM2835FBState), + VMSTATE_UINT32(config.bpp, BCM2835FBState), + VMSTATE_UINT32(config.base, BCM2835FBState), VMSTATE_UINT32(pitch, BCM2835FBState), VMSTATE_UINT32(size, BCM2835FBState), - VMSTATE_UINT32(pixo, BCM2835FBState), - VMSTATE_UINT32(alpha, BCM2835FBState), + VMSTATE_UINT32(config.pixo, BCM2835FBState), + VMSTATE_UINT32(config.alpha, BCM2835FBState), VMSTATE_END_OF_LIST() } }; @@ -349,13 +351,13 @@ static void bcm2835_fb_reset(DeviceState *dev) =20 s->pending =3D false; =20 - s->xres_virtual =3D s->xres; - s->yres_virtual =3D s->yres; - s->xoffset =3D 0; - s->yoffset =3D 0; - s->base =3D s->vcram_base + BCM2835_FB_OFFSET; - s->pitch =3D s->xres * (s->bpp >> 3); - s->size =3D s->yres * s->pitch; + s->config.xres_virtual =3D s->config.xres; + s->config.yres_virtual =3D s->config.yres; + s->config.xoffset =3D 0; + s->config.yoffset =3D 0; + s->config.base =3D s->vcram_base + BCM2835_FB_OFFSET; + s->pitch =3D s->config.xres * (s->config.bpp >> 3); + s->size =3D s->config.yres * s->pitch; =20 s->invalidate =3D true; s->lock =3D false; @@ -385,18 +387,20 @@ static void bcm2835_fb_realize(DeviceState *dev, Erro= r **errp) bcm2835_fb_reset(dev); =20 s->con =3D graphic_console_init(dev, 0, &vgafb_ops, s); - qemu_console_resize(s->con, s->xres, s->yres); + qemu_console_resize(s->con, s->config.xres, s->config.yres); } =20 static Property bcm2835_fb_props[] =3D { DEFINE_PROP_UINT32("vcram-base", BCM2835FBState, vcram_base, 0),/*requ= ired*/ DEFINE_PROP_UINT32("vcram-size", BCM2835FBState, vcram_size, DEFAULT_VCRAM_SIZE), - DEFINE_PROP_UINT32("xres", BCM2835FBState, xres, 640), - DEFINE_PROP_UINT32("yres", BCM2835FBState, yres, 480), - DEFINE_PROP_UINT32("bpp", BCM2835FBState, bpp, 16), - DEFINE_PROP_UINT32("pixo", BCM2835FBState, pixo, 1), /* 1=3DRGB, 0=3DB= GR */ - DEFINE_PROP_UINT32("alpha", BCM2835FBState, alpha, 2), /* alpha ignore= d */ + DEFINE_PROP_UINT32("xres", BCM2835FBState, config.xres, 640), + DEFINE_PROP_UINT32("yres", BCM2835FBState, config.yres, 480), + DEFINE_PROP_UINT32("bpp", BCM2835FBState, config.bpp, 16), + DEFINE_PROP_UINT32("pixo", + BCM2835FBState, config.pixo, 1), /* 1=3DRGB, 0=3DBG= R */ + DEFINE_PROP_UINT32("alpha", + BCM2835FBState, config.alpha, 2), /* alpha ignored = */ DEFINE_PROP_END_OF_LIST() }; =20 diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c index 70eaafd325f..c79f358702d 100644 --- a/hw/misc/bcm2835_property.c +++ b/hw/misc/bcm2835_property.c @@ -141,10 +141,10 @@ static void bcm2835_property_mbox_push(BCM2835Propert= yState *s, uint32_t value) /* Frame buffer */ =20 case 0x00040001: /* Allocate buffer */ - stl_le_phys(&s->dma_as, value + 12, s->fbdev->base); - tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->xres; - tmp_yres =3D newyres !=3D NULL ? *newyres : s->fbdev->yres; - tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->bpp; + stl_le_phys(&s->dma_as, value + 12, s->fbdev->config.base); + tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->config.x= res; + tmp_yres =3D newyres !=3D NULL ? *newyres : s->fbdev->config.y= res; + tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->config.bpp; stl_le_phys(&s->dma_as, value + 16, tmp_xres * tmp_yres * tmp_bpp / 8); resplen =3D 8; @@ -157,8 +157,8 @@ static void bcm2835_property_mbox_push(BCM2835PropertyS= tate *s, uint32_t value) break; case 0x00040003: /* Get display width/height */ case 0x00040004: - tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->xres; - tmp_yres =3D newyres !=3D NULL ? *newyres : s->fbdev->yres; + tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->config.x= res; + tmp_yres =3D newyres !=3D NULL ? *newyres : s->fbdev->config.y= res; stl_le_phys(&s->dma_as, value + 12, tmp_xres); stl_le_phys(&s->dma_as, value + 16, tmp_yres); resplen =3D 8; @@ -176,7 +176,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyS= tate *s, uint32_t value) resplen =3D 8; break; case 0x00040005: /* Get depth */ - tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->bpp; + tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->config.bpp; stl_le_phys(&s->dma_as, value + 12, tmp_bpp); resplen =3D 4; break; @@ -189,7 +189,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyS= tate *s, uint32_t value) resplen =3D 4; break; case 0x00040006: /* Get pixel order */ - tmp_pixo =3D newpixo !=3D NULL ? *newpixo : s->fbdev->pixo; + tmp_pixo =3D newpixo !=3D NULL ? *newpixo : s->fbdev->config.p= ixo; stl_le_phys(&s->dma_as, value + 12, tmp_pixo); resplen =3D 4; break; @@ -202,7 +202,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyS= tate *s, uint32_t value) resplen =3D 4; break; case 0x00040007: /* Get alpha */ - tmp_alpha =3D newalpha !=3D NULL ? *newalpha : s->fbdev->alpha; + tmp_alpha =3D newalpha !=3D NULL ? *newalpha : s->fbdev->confi= g.alpha; stl_le_phys(&s->dma_as, value + 12, tmp_alpha); resplen =3D 4; break; @@ -215,14 +215,16 @@ static void bcm2835_property_mbox_push(BCM2835Propert= yState *s, uint32_t value) resplen =3D 4; break; case 0x00040008: /* Get pitch */ - tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->xres; - tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->bpp; + tmp_xres =3D newxres !=3D NULL ? *newxres : s->fbdev->config.x= res; + tmp_bpp =3D newbpp !=3D NULL ? *newbpp : s->fbdev->config.bpp; stl_le_phys(&s->dma_as, value + 12, tmp_xres * tmp_bpp / 8); resplen =3D 4; break; case 0x00040009: /* Get virtual offset */ - tmp_xoffset =3D newxoffset !=3D NULL ? *newxoffset : s->fbdev-= >xoffset; - tmp_yoffset =3D newyoffset !=3D NULL ? *newyoffset : s->fbdev-= >yoffset; + tmp_xoffset =3D newxoffset !=3D NULL ? + *newxoffset : s->fbdev->config.xoffset; + tmp_yoffset =3D newyoffset !=3D NULL ? + *newyoffset : s->fbdev->config.yoffset; stl_le_phys(&s->dma_as, value + 12, tmp_xoffset); stl_le_phys(&s->dma_as, value + 16, tmp_yoffset); resplen =3D 8; --=20 2.18.0