Raspberry Pi framebuffer and Windows support
Subsystems (2)
cover Raspberry Pi framebuffer and Windows support
This patch series adds support for the AUX (second UART) and framebuffer devices on Raspberry Pi 2, and enables booting Windows on this device. As with the previous series, it is heavily based on the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi 1.
After this series, it is possible to boot Windows by following the instructions at https://github.com/0xabu/qemu/wiki. There's also documentation for booting Linux on that page, but note that you can't load bcm2709-rpi-2-b.dtb because the DMA controller is not included.
I plan to add DMA, USB, and reamining timers / system devices in future patch series, along with support for pi1 (bcm2835). In the meantime, the complete code is available at https://github.com/0xabu/qemu
Cheers,
Andrew
Andrew Baumann (4):
bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry
pi
bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block
bcm2835_fb: add framebuffer device for Raspberry Pi
bcm2835_property: implement framebuffer control/configuration
properties
hw/arm/bcm2835_peripherals.c | 63 +++++- hw/arm/bcm2836.c | 2 + hw/arm/raspi.c | 12 +- hw/char/Makefile.objs | 1 + hw/char/bcm2835_aux.c | 241 ++++++++++++++++++++ hw/display/Makefile.objs | 1 + hw/display/bcm2835_fb.c | 421 +++++++++++++++++++++++++++++++++++ hw/misc/bcm2835_property.c | 139 +++++++++++- include/hw/arm/bcm2835_peripherals.h | 4 + include/hw/char/bcm2835_aux.h | 31 +++ include/hw/display/bcm2835_fb.h | 47 ++++ include/hw/misc/bcm2835_property.h | 5 +- 12 files changed, 954 insertions(+), 13 deletions(-) create mode 100644 hw/char/bcm2835_aux.c create mode 100644 hw/display/bcm2835_fb.c create mode 100644 include/hw/char/bcm2835_aux.h create mode 100644 include/hw/display/bcm2835_fb.h
Signature · 1 line
2.5.3
PATCH 1/4 bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry pi
--- hw/arm/bcm2835_peripherals.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/arm/bcm2835_peripherals.c +7 -0
@@ -171,6 +171,13 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)return ; } +object_property_set_bool (OBJECT (&s->sdhci), true,"pending-insert-quirk" , + &err); +if (err) { +error_propagate (errp, err); +return ; + } +object_property_set_bool (OBJECT (&s->sdhci), true,"realized" , &err);if (err) {error_propagate (errp, err);
Signature · 1 line
2.5.3
Re: [Qemu-arm] [PATCH 1/4] bcm2835_peripherals: enable sdhci pending-insert quirk for raspberry pi
Quoted 24 lines · Andrew Baumann
Signed-off-by Andrew Baumann <[email protected]>--- hw/arm/bcm2835_peripherals.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/arm/bcm2835_peripherals.c +7
-1@@ -171,6 +171,13 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)return ; } +object_property_set_bool (OBJECT (&s->sdhci), true,"pending-insert-quirk" , + &err); +if (err) { +error_propagate (errp, err); +return ; + } +object_property_set_bool (OBJECT (&s->sdhci), true,"realized" , &err);if (err) {error_propagate (errp, err); --
Quoted 1 line
2.5.3
thanks
-- PMM
PATCH 2/4 bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block
In reply to Andrew Baumann--- hw/arm/bcm2835_peripherals.c | 18 +++ hw/char/Makefile.objs | 1 + hw/char/bcm2835_aux.c | 241 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_peripherals.h | 2 + include/hw/char/bcm2835_aux.h | 31 +++++ 5 files changed, 293 insertions(+) create mode 100644 hw/char/bcm2835_aux.c create mode 100644 include/hw/char/bcm2835_aux.h
hw/arm/bcm2835_peripherals.c +18 -0
@@ -48,6 +48,11 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_child (obj,"uart0" ,OBJECT (s->uart0),NULL );qdev_set_parent_bus (DEVICE (s->uart0),sysbus_get_default ()); +/* AUX / UART1 */ +object_initialize (&s->aux,sizeof (s->aux),TYPE_BCM2835_AUX ); +object_property_add_child (obj,"aux" ,OBJECT (&s->aux),NULL ); +qdev_set_parent_bus (DEVICE (&s->aux),sysbus_get_default ()); +/* Mailboxes */ object_initialize (&s->mboxes,sizeof (s->mboxes),TYPE_BCM2835_MBOX );object_property_add_child (obj,"mbox" ,OBJECT (&s->mboxes),NULL );
@@ -131,6 +136,19 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_GPU_IRQ , INTERRUPT_UART)); +/* AUX / UART1 */ +object_property_set_bool (OBJECT (&s->aux), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +memory_region_add_subregion (&s->peri_mr,UART1_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->aux),0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->aux),0 , +qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_GPU_IRQ , +INTERRUPT_AUX )); +/* Mailboxes */ object_property_set_bool (OBJECT (&s->mboxes), true,"realized" , &err);if (err) {
hw/char/Makefile.objs +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SH4) += sh_serial.o obj-$(CONFIG_PSERIES) += spapr_vty.o obj-$(CONFIG_DIGIC) += digic-uart.o obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o +obj-$(CONFIG_RASPI) += bcm2835_aux.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
hw/char/bcm2835_aux.c new file +241 -0
241 lines not on this page · raw message
include/hw/arm/bcm2835_peripherals.h +2 -0
@@ -14,6 +14,7 @@#include "qemu-common.h" #include "exec/address-spaces.h" #include "hw/sysbus.h" +#include "hw/char/bcm2835_aux.h" #include "hw/intc/bcm2835_ic.h" #include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_mbox.h"
@@ -33,6 +34,7 @@ typedef struct BCM2835PeripheralState {qemu_irq irq, fiq;SysBusDevice *uart0; +BCM2835AuxState aux;BCM2835ICState ic;BCM2835PropertyState property;BCM2835MboxState mboxes;
include/hw/char/bcm2835_aux.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft +* Written by Andrew Baumann +* +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_AUX_H +#define BCM2835_AUX_H + +#include "hw/sysbus.h" +#include "sysemu/char.h" + +#define TYPE_BCM2835_AUX "bcm2835-aux" +#define BCM2835_AUX (obj) OBJECT_CHECK(BCM2835AuxState, (obj), TYPE_BCM2835_AUX) + +typedef struct { +/*< private >*/ +SysBusDevice parent_obj; +/*< public >*/ + +MemoryRegion iomem; +CharDriverState *chr; +qemu_irq irq; + +uint32_t read_fifo[8 ]; +uint8_t read_pos, read_count; +bool rx_int_enable, tx_int_enable; +}BCM2835AuxState ; + +#endif
Signature · 1 line
2.5.3
Re: [Qemu-arm] [PATCH 2/4] bcm2835_aux: add emulation of BCM2835 AUX (aka UART1) block
On 27 February 2016 at 00:16, Andrew Baumann
<[email protected]> wrote:
This bit of the commit message is a good place to list the "not yet implemented" parts of the device.
Quoted 16 lines
Signed-off-by Andrew Baumann <[email protected]>---
+/*
+ * BCM2835 (Raspberry Pi / Pi 2) Aux block (mini UART and SPI).
+ * Copyright (c) 2015, Microsoft
+ * Written by Andrew Baumann
+ * Based onpl011.c, copyright terms below:
+ *
+ * Arm PrimeCell PL011 UART
+ *
+ * Copyright (c) 2006 CodeSourcery.
+ * Written by Paul Brook
+ *
+ * This code is licensed under the GPL.
+ */
I'm looking at the documentation at
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf
for my review...
You should say in a comment that only the UART parts are currently implemented.
Quoted 4 lines
hw/char/bcm2835_aux.c new file +4
-0+#include "qemu/osdep.h" +#include "hw/char/bcm2835_aux.h" + +#define AUX_ENABLES 0x4
hw/char/bcm2835_aux.c line 28
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+#define AUX_MU_IO_REG 0x40 +#define AUX_MU_IER_REG 0x44 +#define AUX_MU_IIR_REG 0x48 +#define AUX_MU_LSR_REG 0x54 +#define AUX_MU_STAT_REG 0x64 + +static void bcm2835_aux_update (BCM2835AuxState *s) +{ +bool status = (s->rx_int_enable && s->read_count !=0 ) || s->tx_int_enable; +qemu_set_irq (s->irq, status);
Could use a comment somewhere to the effect that since we model the tx fifo as instantly-draining the 'tx fifo register empty' interrupt is always asserted.
hw/char/bcm2835_aux.c line 36
Quoted 8 lines
hw/char/bcm2835_aux.c new file +8
-0+} + +static uint64_t bcm2835_aux_read (void *opaque,hwaddr offset,unsigned size) +{ +BCM2835AuxState *s = opaque; +uint32_t c, res; + +switch (offset) {
No AUX_IRQ implementation? (You need the current interrupt status anyway for one of the other register bits.)
hw/char/bcm2835_aux.c line 41
Quoted 5 lines
hw/char/bcm2835_aux.c new file +5
-0+case AUX_ENABLES : +return 1 ;/* mini UART enabled */ + +case AUX_MU_IO_REG : + c = s->read_fifo[s->read_pos];
The datasheet says this is a byte UART but you've implemented the read_fifo and c as 32-bit.
hw/char/bcm2835_aux.c line 51
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+if (s->read_count >0 ) { + s->read_count--; +if (++s->read_pos ==8 ) { + s->read_pos =0 ; + } + } +if (s->chr) { +qemu_chr_accept_input (s->chr); + } +bcm2835_aux_update (s);
This doesn't implement the "if line control DLAB bit is set, then read/write the LS 8 bits of the baudrate register" behaviour described in the datasheet.
hw/char/bcm2835_aux.c line 61
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+return c; + +case AUX_MU_IER_REG : + res =0 ; +if (s->rx_int_enable) { + res |=0x2 ; + } +if (s->tx_int_enable) { + res |=0x1 ; + }
I suspect you'll find the code is clearer generally if you model this register with a uint8_t ier in the state structure rather than two bools (for instance "is interrupt asserted" is generally "enables | status".)
Doesn't implement "DLAB bit set means access MS 8 bits of the baudrate register".
hw/char/bcm2835_aux.c line 70
Quoted 9 lines
hw/char/bcm2835_aux.c new file +9
-0+return res; + +case AUX_MU_IIR_REG : + res =0xc0 ; +if (s->tx_int_enable) { + res |=0x1 ; + }else if (s->rx_int_enable && s->read_count !=0 ) { + res |=0x2 ; + }
This is kind of repeating the logic in bcm2835_aux_update(), would be nice to factor it out.
The data sheet says that the bit allocation here is different:
bit 0 is zero when an interrupt is pending, and bits 1 and 2 are the read and write information.
The data sheet also says that 0b11 for bits [2:1] is not possible, though it doesn't say why. It's not clear what the hardware reads as if the transmit holding register is empty *and* the receiver has a valid byte...
hw/char/bcm2835_aux.c line 81
Quoted 11 lines
hw/char/bcm2835_aux.c new file +11
-0+return res; + +case AUX_MU_LSR_REG : + res =0x60 ;/* tx idle, empty */ +if (s->read_count !=0 ) { + res |=0x1 ; + } +return res; + +case AUX_MU_STAT_REG : + res =0x302 ;/* space in the output buffer, empty tx fifo */
Shouldn't we set the "transmitter idle" bit too?
hw/char/bcm2835_aux.c line 88
Quoted 7 lines
hw/char/bcm2835_aux.c new file +7
-0+if (s->read_count >0 ) { + res |=0x1 ;/* data in input buffer */ +assert (s->read_count <8 ); + res |= ((uint32_t )s->read_count) <<16 ;/* rx fifo fill level */ + } +return res; +
No AUX_MU_LCR_REG ? No AUX_MU_MCR_REG ? No AUX_MU_MSR_REG ? AUX_MU_SCRATCH ? AUX_MU_CNTL_REG ? AUX_MU_BAUD ?
At least implementing them to log unimplemented would be nice.
Quoted 27 lines
hw/char/bcm2835_aux.c new file +27
-0+default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset %" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; + } +} + +static void bcm2835_aux_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +BCM2835AuxState *s = opaque; +unsigned char ch; + +switch (offset) { +case AUX_ENABLES : +if (value !=1 ) { +qemu_log_mask (LOG_UNIMP ,"%s: unsupported attempt to enable SPI " +"or disable UART\n" , __func__); + } +break ; + +case AUX_MU_IO_REG : + ch = value; +if (s->chr) { +qemu_chr_fe_write (s->chr, &ch,1 ); + } +break ;
hw/char/bcm2835_aux.c line 125
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+ +case AUX_MU_IER_REG : + s->rx_int_enable = (value &0x2 ) !=0 ; + s->tx_int_enable = (value &0x1 ) !=0 ; +break ; + +case AUX_MU_IIR_REG : +if (value &0x1 ) { + s->read_count =0 ; + }
Datasheet says bit 0 is read only, bit 1 clears the rx fifo.
Quoted 34 lines
hw/char/bcm2835_aux.c new file +34
-0+break ; + +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset %" HWADDR_PRIx"\n" , + __func__, offset); + } + +bcm2835_aux_update (s); +} + +static int bcm2835_aux_can_receive (void *opaque) +{ +BCM2835AuxState *s = opaque; + +return s->read_count <8 ; +} + +static void bcm2835_aux_put_fifo (void *opaque,uint32_t value) +{ +BCM2835AuxState *s = opaque; +int slot; + + slot = s->read_pos + s->read_count; +if (slot >=8 ) { + slot -=8 ; + } + s->read_fifo[slot] = value; + s->read_count++; +if (s->read_count ==8 ) { +/* buffer full */ + } +bcm2835_aux_update (s); +} +
hw/char/bcm2835_aux.c line 169
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+static void bcm2835_aux_receive (void *opaque,const uint8_t *buf,int size) +{ +bcm2835_aux_put_fifo (opaque, *buf); +} + +static void bcm2835_aux_event (void *opaque,int event) +{ +if (event ==CHR_EVENT_BREAK ) { +bcm2835_aux_put_fifo (opaque,0x400 ); + }
Data sheet says the UART does not have break detection.
Quoted 29 lines
hw/char/bcm2835_aux.c new file +29
-0+} + +static const MemoryRegionOps bcm2835_aux_ops = { + .read = bcm2835_aux_read, + .write = bcm2835_aux_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid.min_access_size =4 , + .valid.max_access_size =4 , +}; + +static const VMStateDescription vmstate_bcm2835_aux = { + .name =TYPE_BCM2835_AUX , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (read_fifo, BCM2835AuxState,8 ), +VMSTATE_UINT8 (read_pos, BCM2835AuxState), +VMSTATE_UINT8 (read_count, BCM2835AuxState), +VMSTATE_BOOL (rx_int_enable, BCM2835AuxState), +VMSTATE_BOOL (tx_int_enable, BCM2835AuxState), +VMSTATE_END_OF_LIST () + } +}; + +static void bcm2835_aux_init (Object *obj) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +BCM2835AuxState *s =BCM2835_AUX (obj); +
hw/char/bcm2835_aux.c line 209
Quoted 10 lines
hw/char/bcm2835_aux.c new file +10
-0+memory_region_init_io (&s->iomem,OBJECT (s), &bcm2835_aux_ops, s, +TYPE_BCM2835_AUX ,0x100 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); +} + +static void bcm2835_aux_realize (DeviceState *dev,Error **errp) +{ +BCM2835AuxState *s =BCM2835_AUX (dev); +/* FIXME use a qdev chardev prop instead of qemu_char_get_next_serial() */
Good idea :-) imx_serial.c has an example, you use DEFINE_PROP_CHR and then wire it up in the board construction with qdev_prop_set_chr(). (You probably want to create an alias property on the SoC object as we now do for spi etc; see the xilinx soc for an example.)
Quoted 1 line
+
s->chr=qemu_char_get_next_serial();
thanks
-- PMM
PATCH 3/4 bcm2835_fb: add framebuffer device for Raspberry Pi
In reply to Andrew BaumannThe framebuffer occupies the upper portion of memory (64MiB by default), but it can only be controlled/configured via a system mailbox or property channel (to be added by a subsequent patch).
--- hw/arm/bcm2835_peripherals.c | 38 +++- hw/arm/bcm2836.c | 2 + hw/arm/raspi.c | 12 +- hw/display/Makefile.objs | 1 + hw/display/bcm2835_fb.c | 421 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_peripherals.h | 2 + include/hw/display/bcm2835_fb.h | 47 ++++ 7 files changed, 515 insertions(+), 8 deletions(-) create mode 100644 hw/display/bcm2835_fb.c create mode 100644 include/hw/display/bcm2835_fb.h
hw/arm/bcm2835_peripherals.c +37 -1
@@ -61,6 +61,16 @@ static void bcm2835_peripherals_init(Object *obj)object_property_add_const_link (OBJECT (&s->mboxes),"mbox-mr" ,OBJECT (&s->mbox_mr), &error_abort); +/* Framebuffer */ +object_initialize (&s->fb,sizeof (s->fb),TYPE_BCM2835_FB ); +object_property_add_child (obj,"fb" ,OBJECT (&s->fb),NULL ); +object_property_add_alias (obj,"vcram-size" ,OBJECT (&s->fb),"vcram-size" , + &error_abort); +qdev_set_parent_bus (DEVICE (&s->fb),sysbus_get_default ()); + +object_property_add_const_link (OBJECT (&s->fb),"dma-mr" , +OBJECT (&s->gpu_bus_mr), &error_abort); +/* Property channel */ object_initialize (&s->property,sizeof (s->property),TYPE_BCM2835_PROPERTY );object_property_add_child (obj,"property" ,OBJECT (&s->property),NULL );
@@ -83,7 +93,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)Object *obj;MemoryRegion *ram;Error *err =NULL ; -uint32_t ram_size; +uint32_t ram_size, vcram_size;int n; obj =object_property_get_link (OBJECT (dev),"ram" , &err);
@@ -162,6 +172,32 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_ARM_IRQ , INTERRUPT_ARM_MAILBOX)); +/* Framebuffer */ + vcram_size = (uint32_t )object_property_get_int (OBJECT (s),"vcram-size" , + &err); +if (err) { +error_propagate (errp, err); +return ; + } + +object_property_set_int (OBJECT (&s->fb), ram_size - vcram_size, +"vcram-base" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +object_property_set_bool (OBJECT (&s->fb), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } + +memory_region_add_subregion (&s->mbox_mr,MBOX_CHAN_FB <<MBOX_AS_CHAN_SHIFT , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->fb),0 )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->fb),0 , +qdev_get_gpio_in (DEVICE (&s->mboxes),MBOX_CHAN_FB )); +/* Property channel */ object_property_set_int (OBJECT (&s->property), ram_size,"ram-size" , &err);if (err) {
hw/arm/bcm2836.c +2 -0
@@ -42,6 +42,8 @@ static void bcm2836_init(Object *obj) &error_abort);object_property_add_alias (obj,"board-rev" ,OBJECT (&s->peripherals),"board-rev" , &error_abort); +object_property_add_alias (obj,"vcram-size" ,OBJECT (&s->peripherals), +"vcram-size" , &error_abort);qdev_set_parent_bus (DEVICE (&s->peripherals),sysbus_get_default ()); }
hw/arm/raspi.c +5 -7
@@ -113,6 +113,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi2_init (MachineState *machine) {RasPiState *s =g_new0 (RasPiState,1 ); +uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;BusState *bus;
@@ -149,7 +150,9 @@ static void raspi2_init(MachineState *machine)qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal);object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); -setup_boot (machine,2 , machine->ram_size); + vcram_size =object_property_get_int (OBJECT (&s->soc),"vcram-size" , + &error_abort); +setup_boot (machine,2 , machine->ram_size - vcram_size); }static void raspi2_machine_init (MachineClass *mc)
@@ -161,11 +164,6 @@ static void raspi2_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->max_cpus =BCM2836_NCPUS ; - -/* XXX: Temporary restriction in RAM size from the full 1GB. Since -* we do not yet support the framebuffer / GPU, we need to limit -* RAM usable by the OS to sit below the peripherals. -*/ - mc->default_ram_size =0x3F000000 ;/* BCM2836_PERI_BASE */ + mc->default_ram_size =1024 *1024 *1024 ; };DEFINE_MACHINE ("raspi2" , raspi2_machine_init)
hw/display/Makefile.objs +1 -0
@@ -27,6 +27,7 @@ endif obj-$(CONFIG_OMAP) += omap_dss.o obj-$(CONFIG_OMAP) += omap_lcdc.o obj-$(CONFIG_PXA2XX) += pxa2xx_lcd.o +obj-$(CONFIG_RASPI) += bcm2835_fb.o obj-$(CONFIG_SM501) += sm501.o obj-$(CONFIG_TCX) += tcx.o obj-$(CONFIG_CG3) += cg3.o
hw/display/bcm2835_fb.c new file +421 -0
421 lines not on this page · raw message
include/hw/arm/bcm2835_peripherals.h +2 -0
@@ -15,6 +15,7 @@#include "exec/address-spaces.h" #include "hw/sysbus.h" #include "hw/char/bcm2835_aux.h" +#include "hw/display/bcm2835_fb.h" #include "hw/intc/bcm2835_ic.h" #include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_mbox.h"
@@ -35,6 +36,7 @@ typedef struct BCM2835PeripheralState {SysBusDevice *uart0;BCM2835AuxState aux; +BCM2835FBState fb;BCM2835ICState ic;BCM2835PropertyState property;BCM2835MboxState mboxes;
include/hw/display/bcm2835_fb.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.5.3
Re: [Qemu-devel] [PATCH 3/4] bcm2835_fb: add framebuffer device for Raspberry Pi
Quoted 5 lines · Andrew Baumann
The framebuffer occupies the upper portion of memory (64MiB by default), but it can only be controlled/configured via a system mailbox or property channel (to be added by a subsequent patch).
Signed-off-by Andrew Baumann <[email protected]>
Mostly looks ok, but a couple of points:
Quoted 4 lines
hw/display/bcm2835_fb.c new file +4
-0+static void draw_line_src16 (void *opaque,uint8_t *dst,const uint8_t *src, +int width,int deststep) +{ +BCM2835FBState *s = opaque;
hw/display/bcm2835_fb.c line 55
Quoted 10 lines
hw/display/bcm2835_fb.c new file +10
-0+uint16_t rgb565; +uint32_t rgb888; +uint8_t r, g, b; +DisplaySurface *surface =qemu_console_surface (s->con); +int bpp =surface_bits_per_pixel (surface); + +while (width--) { +switch (s->bpp) { +case 8 : + rgb888 =ldl_phys (&s->dma_as, s->vcram_base + (*src <<2 ));
Don't use ldl_phys() in device model code, please. It means "do a load with the endianness of the CPU's bus", and generally device behaviour doesn't depend on the what the CPU happens to be doing. If you do a grep for 'ld[a-z]*_phys' in hw/ you'll find that (apart from a few spurious matches) the only things doing this are some bcm2835 code that you should fix and the spapr hypercall device (which really is legitimately cpu-behaviour-dependent).
You need to determine what endianness the device uses to do its DMA accesses, and use either ldl_le_phys() or ldl_be_phys() as appropriate. (Or address_space_ldl_le/be if you care about memory attributes.)
More interestingly, why can't you just read from the source pointer you're passed in here? The framebuffer_update_display() code should have obtained it by looking up the location of the host RAM where the guest video RAM is, so if you ignore it and do a complete physical-address-to-memory-region lookup for every pixel it's going to make redraws unnecessarily slow.
Quoted 49 lines
hw/display/bcm2835_fb.c new file +46
-0+ r = (rgb888 >>0 ) &0xff ; + g = (rgb888 >>8 ) &0xff ; + b = (rgb888 >>16 ) &0xff ; + src++; +break ; +case 16 : + rgb565 =lduw_p (src); + r = ((rgb565 >>11 ) &0x1f ) <<3 ; + g = ((rgb565 >>5 ) &0x3f ) <<2 ; + b = ((rgb565 >>0 ) &0x1f ) <<3 ; + src +=2 ; +break ; +case 24 : + rgb888 =ldl_p (src); + r = (rgb888 >>0 ) &0xff ; + g = (rgb888 >>8 ) &0xff ; + b = (rgb888 >>16 ) &0xff ; + src +=3 ; +break ; +case 32 : + rgb888 =ldl_p (src); + r = (rgb888 >>0 ) &0xff ; + g = (rgb888 >>8 ) &0xff ; + b = (rgb888 >>16 ) &0xff ; + src +=4 ; +break ; +default : + r =0 ; + g =0 ; + b =0 ; +break ; +static void bcm2835_fb_mbox_push(BCM2835FBState *s, uint32_t value) +{ + value &= ~0xf ; + + s->lock = true; + + s->xres =ldl_phys (&s->dma_as, value); + s->yres =ldl_phys (&s->dma_as, value +4 ); + s->xres_virtual =ldl_phys (&s->dma_as, value +8 ); + s->yres_virtual =ldl_phys (&s->dma_as, value +12 ); + s->bpp =ldl_phys (&s->dma_as, value +20 ); + s->xoffset =ldl_phys (&s->dma_as, value +24 ); + s->yoffset =ldl_phys (&s->dma_as, value +28 ); + + s->base = s->vcram_base | (value &0xc0000000 );
hw/display/bcm2835_fb.c line 202
Quoted 10 lines
hw/display/bcm2835_fb.c new file +10
-0+ s->base +=BCM2835_FB_OFFSET ; + +/* TODO - Manage properly virtual resolution */ + + s->pitch = s->xres * (s->bpp >>3 ); + s->size = s->yres * s->pitch; + +stl_phys (&s->dma_as, value +16 , s->pitch); +stl_phys (&s->dma_as, value +32 , s->base); +stl_phys (&s->dma_as, value +36 , s->size);
These should all be specifying which endianness to write explicitly too.
hw/display/bcm2835_fb.c line 207
Quoted 5 lines
hw/display/bcm2835_fb.c new file +5
-0+ + s->invalidate = true; +qemu_console_resize (s->con, s->xres, s->yres); + s->lock = false; +}
thanks
-- PMM
Re: [Qemu-arm] [PATCH 3/4] bcm2835_fb: add framebuffer device for Raspberry Pi
Quoted 37 lines
From: Peter Maydell [mailto:[email protected]]
Sent: Tuesday, 1 March 2016 11:23 AMQuoted 5 lines · Andrew Baumann
The framebuffer occupies the upper portion of memory (64MiB by default), but it can only be controlled/configured via a system mailbox or property channel (to be added by a subsequent patch).
Signed-off-by Andrew Baumann <[email protected]>Mostly looks ok, but a couple of points:
Quoted 1 line
+static void draw_line_src16(void *opaque,
uint8_t*dst, constuint8_t*src,
hw/display/bcm2835_fb.c line 55
Quoted 13 lines
hw/display/bcm2835_fb.c new file +13
-0+ int width, int deststep) +{ +BCM2835FBState *s = opaque; +uint16_t rgb565; +uint32_t rgb888; +uint8_t r, g, b; +DisplaySurface *surface =qemu_console_surface (s->con); +int bpp =surface_bits_per_pixel (surface); + +while (width--) { +switch (s->bpp) { +case 8 : + rgb888 =ldl_phys (&s->dma_as, s->vcram_base + (*src <<2 ));Don't use
ldl_phys()in device model code, please. It means "do a load with the endianness of the CPU's bus", and generally device behaviour doesn't depend on the what the CPU happens to be doing. If you do a grep for 'ld[a-z]*_phys' in hw/ you'll find that (apart from a few spurious matches) the only things doing this are some bcm2835 code that you should fix and the spapr hypercall device (which really is legitimately cpu-behaviour-dependent).
Quoted 4 lines
You need to determine what endianness the device uses to do its DMA accesses, and use either
ldl_le_phys()orldl_be_phys()as appropriate. (Or address_space_ldl_le/be if you care about memory attributes.)
Thanks for pointing this out. I'll get the other instances fixed (they are all le).
Quoted 6 lines
More interestingly, why can't you just read from the source pointer you're passed in here? The
framebuffer_update_display()code should have obtained it by looking up the location of the host RAM where the guest video RAM is, so if you ignore it and do a complete physical-address-to-memory-region lookup for every pixel it's going to make redraws unnecessarily slow.
That is what's happening for the 16-, 24- and 32-bit modes. For 8-bit, it appears to be doing a palette lookup (using the 8-bit value at the pointer as an index into the 256-colour palette starting at vcram_base). Your point that this is inefficient stands, but the translation afforded by the existing framebuffer code doesn't help. I'm tempted to replace it with ldl_le_phys as a quick fix.
Regards,
Andrew
Re: [Qemu-arm] [PATCH 3/4] bcm2835_fb: add framebuffer device for Raspberry Pi
Quoted 8 lines · Andrew Baumann
Quoted 7 lines
From: Peter Maydell [mailto:[email protected]] More interestingly, why can't you just read from the source pointer you're passed in here? The
framebuffer_update_display()code should have obtained it by looking up the location of the host RAM where the guest video RAM is, so if you ignore it and do a complete physical-address-to-memory-region lookup for every pixel it's going to make redraws unnecessarily slow.
Quoted 4 lines
That is what's happening for the 16-, 24- and 32-bit modes. For 8-bit, it appears to be doing a palette lookup (using the 8-bit value at the pointer as an index into the 256-colour palette starting at
vcram_base).
Oh, right, it's a palette lookup. That's fine, then. A comment mentioning that this is doing palette lookup would help. I wouldn't worry about efficiency for this mode because who's using 8-bit colour in 2016 ?
thanks
-- PMM
PATCH 4/4 bcm2835_property: implement framebuffer control/configuration properties
In reply to Andrew BaumannThe property channel driver now interfaces with the framebuffer device to query and set framebuffer parameters. As a result of this, the "get ARM RAM size" query now correctly returns the video RAM base address (not total RAM size), and the ram-size property is no longer relevant here.
--- hw/arm/bcm2835_peripherals.c | 8 +-- hw/misc/bcm2835_property.c | 139 ++++++++++++++++++++++++++++++++++++- include/hw/misc/bcm2835_property.h | 5 +- 3 files changed, 143 insertions(+), 9 deletions(-)
hw/arm/bcm2835_peripherals.c +2 -6
@@ -78,6 +78,8 @@ static void bcm2835_peripherals_init(Object *obj) "board-rev", &error_abort);qdev_set_parent_bus (DEVICE (&s->property),sysbus_get_default ()); +object_property_add_const_link (OBJECT (&s->property),"fb" , +OBJECT (&s->fb), &error_abort);object_property_add_const_link (OBJECT (&s->property),"dma-mr" ,OBJECT (&s->gpu_bus_mr), &error_abort);
@@ -199,12 +201,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_FB));/* Property channel */ -object_property_set_int (OBJECT (&s->property), ram_size,"ram-size" , &err); -if (err) { -error_propagate (errp, err); -return ; - } -object_property_set_bool (OBJECT (&s->property), true,"realized" , &err);if (err) {error_propagate (errp, err);
hw/misc/bcm2835_property.c +137 -2
175 lines not on this page · raw message
include/hw/misc/bcm2835_property.h +4 -1
@@ -9,6 +9,7 @@#include "hw/sysbus.h" #include "exec/address-spaces.h" #include "net/net.h" +#include "hw/display/bcm2835_fb.h" #define TYPE_BCM2835_PROPERTY "bcm2835-property"#define BCM2835_PROPERTY (obj) \
@@ -18,13 +19,15 @@ typedef struct {/*< private >*/ SysBusDevice busdev;/*< public >*/ +MemoryRegion *dma_mr;AddressSpace dma_as;MemoryRegion iomem;qemu_irq mbox_irq; +BCM2835FBState *fbdev; +MACAddr macaddr;uint32_t board_rev; -uint32_t ram_size;uint32_t addr;bool pending; } BCM2835PropertyState;
Signature · 1 line
2.5.3
Re: [Qemu-arm] [PATCH 4/4] bcm2835_property: implement framebuffer control/configuration properties
Quoted 7 lines · Andrew Baumann
The property channel driver now interfaces with the framebuffer device to query and set framebuffer parameters. As a result of this, the "get ARM RAM size" query now correctly returns the video RAM base address (not total RAM size), and the ram-size property is no longer relevant here.
Signed-off-by Andrew Baumann <[email protected]>
This should all be specifying endianness of loads explicitly too, but otherwise looks OK.
thanks
-- PMM