Raspberry Pi 2 support
Subsystems (2)
cover Raspberry Pi 2 support
This patch series adds initial support for Raspberry Pi 2 (bcm2836). It is heavily based on the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi 1.
At the end of this series, it is possible to boot a recent raspbian kernel to a serial console using an invocation such as:
qemu-system-arm -M raspi2 -kernel raspbian-boot/kernel7.img -sd 2015-09-24-raspbian-jessie.vhd -append "rw earlyprintk loglevel=8 console=ttyAMA0 root=/dev/mmcblk0p2" -serial stdio
(where raspbian-boot is the boot partition from the matching image, and after commenting-out or removing /etc/ld.so.preload to avoid an unimplemented setend instruction).
I plan to add DMA, USB, framebuffer, timers, and other system devices (vchiq, power, mphi, aux/uart1) in future patches. In the meantime, the complete code is available at: https://github.com/0xabu/qemu
Although this series includes many of the peripherals common to Pi1 (aka bcm2835 aka Pi0), it's not yet possible to boot a Pi1, because it requires additional peripherals, so I'll also add that SoC and machine in a later patch.
Cheers,
Andrew
Andrew Baumann (8):
bcm2835_sbm: add BCM2835 mailboxes
bcm2835_property: add bcm2835 property channel
bcm2835_ic: add bcm2835 interrupt controller
bcm2835_emmc: add bcm2835 MMC/SD controller
bcm2835_peripherals: add rollup device for bcm2835 peripherals
bcm2836_control: add bcm2836 ARM control logic
bcm2836: add bcm2836 soc device
raspi: add raspberry pi 2 machine
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/bcm2835_peripherals.c | 185 ++++++++ hw/arm/bcm2836.c | 135 ++++++ hw/arm/raspi.c | 179 ++++++++ hw/intc/Makefile.objs | 1 + hw/intc/bcm2835_ic.c | 234 ++++++++++ hw/intc/bcm2836_control.c | 344 +++++++++++++++ hw/misc/Makefile.objs | 2 + hw/misc/bcm2835_property.c | 262 ++++++++++++ hw/misc/bcm2835_sbm.c | 280 ++++++++++++ hw/sd/Makefile.objs | 1 + hw/sd/bcm2835_emmc.c | 800 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_arm_control.h | 481 +++++++++++++++++++++ include/hw/arm/bcm2835_mbox.h | 19 + include/hw/arm/bcm2835_peripherals.h | 42 ++ include/hw/arm/bcm2836.h | 33 ++ include/hw/arm/raspi_platform.h | 161 +++++++ include/hw/intc/bcm2835_ic.h | 26 ++ include/hw/intc/bcm2836_control.h | 49 +++ include/hw/misc/bcm2835_property.h | 27 ++ include/hw/misc/bcm2835_sbm.h | 37 ++ include/hw/sd/bcm2835_emmc.h | 56 +++ 23 files changed, 3356 insertions(+) create mode 100644 hw/arm/bcm2835_peripherals.c create mode 100644 hw/arm/bcm2836.c create mode 100644 hw/arm/raspi.c create mode 100644 hw/intc/bcm2835_ic.c create mode 100644 hw/intc/bcm2836_control.c create mode 100644 hw/misc/bcm2835_property.c create mode 100644 hw/misc/bcm2835_sbm.c create mode 100644 hw/sd/bcm2835_emmc.c create mode 100644 include/hw/arm/bcm2835_arm_control.h create mode 100644 include/hw/arm/bcm2835_mbox.h create mode 100644 include/hw/arm/bcm2835_peripherals.h create mode 100644 include/hw/arm/bcm2836.h create mode 100644 include/hw/arm/raspi_platform.h create mode 100644 include/hw/intc/bcm2835_ic.h create mode 100644 include/hw/intc/bcm2836_control.h create mode 100644 include/hw/misc/bcm2835_property.h create mode 100644 include/hw/misc/bcm2835_sbm.h create mode 100644 include/hw/sd/bcm2835_emmc.h
Signature · 1 line
2.5.3
Quoted 3 lines
This patch series adds initial support for Raspberry Pi 2 (bcm2836). It is heavily based on the original (out of tree) work of Gregory Estrade, Stefan Weil and others to support Raspberry Pi 1.
Apologies for the silence on this thread. My outbound SMTP server seems to be rejecting the patch emails (maybe due to an over-zealous spam filter). Please hold tight while I look for a workaround... :(
Andrew
PATCH 2/8 bcm2835_property: add bcm2835 property channel
In reply to Andrew BaumannThis sits behind the mailbox interface, and implements request/response queries for system properties. The framebuffer-related properties will be added in a later patch.
--- hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_property.c | 262 +++++++++++++++++++++++++++++++++++++ include/hw/misc/bcm2835_property.h | 27 ++++ 3 files changed, 290 insertions(+) create mode 100644 hw/misc/bcm2835_property.c create mode 100644 include/hw/misc/bcm2835_property.h
hw/misc/Makefile.objs +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_OMAP) += omap_gpmc.o obj-$(CONFIG_OMAP) += omap_l4.o obj-$(CONFIG_OMAP) += omap_sdrc.o obj-$(CONFIG_OMAP) += omap_tap.o +obj-$(CONFIG_RASPI) += bcm2835_property.o obj-$(CONFIG_RASPI) += bcm2835_sbm.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o
hw/misc/bcm2835_property.c new file +262 -0
262 lines not on this page · raw message
include/hw/misc/bcm2835_property.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_PROPERTY_H +#define BCM2835_PROPERTY_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" + +#define TYPE_BCM2835_PROPERTY "bcm2835_property" +#define BCM2835_PROPERTY (obj) \ + OBJECT_CHECK(BCM2835PropertyState, (obj), TYPE_BCM2835_PROPERTY) + +typedef struct { +SysBusDevice busdev; +MemoryRegion *dma_mr; +AddressSpace dma_as; +MemoryRegion iomem; +uint32_t addr; +int pending; +qemu_irq mbox_irq; +uint32_t ram_size; +}BCM2835PropertyState ; + +#endif
Signature · 1 line
2.5.3
PATCH 3/8 bcm2835_ic: add bcm2835 interrupt controller
In reply to Andrew Baumann--- hw/intc/Makefile.objs | 1 + hw/intc/bcm2835_ic.c | 234 +++++++++++++++++++++++++++++++++++++++++++ include/hw/intc/bcm2835_ic.h | 26 +++++ 3 files changed, 261 insertions(+) create mode 100644 hw/intc/bcm2835_ic.c create mode 100644 include/hw/intc/bcm2835_ic.h
hw/intc/Makefile.objs +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.o obj-$(CONFIG_IOAPIC) += ioapic.o obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o +obj-$(CONFIG_RASPI) += bcm2835_ic.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o
hw/intc/bcm2835_ic.c new file +234 -0
234 lines not on this page · raw message
include/hw/intc/bcm2835_ic.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_IC_H +#define BCM2835_IC_H + +#include "hw/sysbus.h" + +#define TYPE_BCM2835_IC "bcm2835_ic" +#define BCM2835_IC (obj) OBJECT_CHECK(BCM2835IcState, (obj), TYPE_BCM2835_IC) + +typedef struct BCM2835IcState { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t level[3 ]; +uint32_t irq_enable[3 ]; +int fiq_enable; +int fiq_select; +qemu_irq irq; +qemu_irq fiq; +}BCM2835IcState ; + +#endif
Signature · 1 line
2.5.3
PATCH 5/8 bcm2835_peripherals: add rollup device for bcm2835 peripherals
In reply to Andrew BaumannThis device maintains all the non-CPU peripherals on bcm2835 (Pi1) which are also present on bcm2836 (Pi2). It also implements the private address space used for DMA.
--- hw/arm/Makefile.objs | 1 + hw/arm/bcm2835_peripherals.c | 185 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_peripherals.h | 42 ++++++++ include/hw/arm/raspi_platform.h | 161 ++++++++++++++++++++++++++++++ 4 files changed, 389 insertions(+) create mode 100644 hw/arm/bcm2835_peripherals.c create mode 100644 include/hw/arm/bcm2835_peripherals.h create mode 100644 include/hw/arm/raspi_platform.h
hw/arm/Makefile.objs +1 -0
@@ -11,6 +11,7 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o +obj-$(CONFIG_RASPI) += bcm2835_peripherals.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
hw/arm/bcm2835_peripherals.c new file +185 -0
185 lines not on this page · raw message
include/hw/arm/bcm2835_peripherals.h new file +42 -0
42 lines not on this page · raw message
include/hw/arm/raspi_platform.h new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.5.3
PATCH 1/8 bcm2835_sbm: add BCM2835 mailboxes
In reply to Andrew BaumannThis adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++ include/hw/arm/bcm2835_arm_control.h | 481 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_mbox.h | 19 ++ include/hw/misc/bcm2835_sbm.h | 37 +++ 6 files changed, 819 insertions(+) create mode 100644 hw/misc/bcm2835_sbm.c create mode 100644 include/hw/arm/bcm2835_arm_control.h create mode 100644 include/hw/arm/bcm2835_mbox.h create mode 100644 include/hw/misc/bcm2835_sbm.h
default-configs/arm-softmmu.mak +1 -0
@@ -79,6 +79,7 @@ CONFIG_TUSB6010=y CONFIG_IMX=y CONFIG_MAINSTONE=y CONFIG_NSERIES=y +CONFIG_RASPI=y CONFIG_REALVIEW=y CONFIG_ZAURUS=y CONFIG_ZYNQ=y
hw/misc/Makefile.objs +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_OMAP) += omap_gpmc.o obj-$(CONFIG_OMAP) += omap_l4.o obj-$(CONFIG_OMAP) += omap_sdrc.o obj-$(CONFIG_OMAP) += omap_tap.o +obj-$(CONFIG_RASPI) += bcm2835_sbm.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.o
hw/misc/bcm2835_sbm.c new file +280 -0
280 lines not on this page · raw message
include/hw/arm/bcm2835_arm_control.h new file +481 -0
481 lines not on this page · raw message
include/hw/arm/bcm2835_mbox.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_MBOX_H +#define BCM2835_MBOX_H + +/* Constants shared with the ARM identifying separate mailbox channels */ +#define MBOX_CHAN_POWER 0/* for use by the power management interface */ +#define MBOX_CHAN_FB 1/* for use by the frame buffer */ +#define MBOX_CHAN_VCHIQ 3/* for use by the VCHIQ interface */ +#define MBOX_CHAN_PROPERTY 8/* for use by the property channel */ +#define MBOX_CHAN_COUNT 9 + +#define MBOX_SIZE 32 +#define MBOX_INVALID_DATA 0x0f + +#endif /* BCM2835_MBOX_H */
include/hw/misc/bcm2835_sbm.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM (obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct { +MemoryRegion *mbox_mr; +AddressSpace mbox_as; +uint32_t reg[MBOX_SIZE ]; +int count; +uint32_t status; +uint32_t config; +}BCM2835Mbox ; + +typedef struct { +SysBusDevice busdev; +MemoryRegion *mbox_mr; +AddressSpace mbox_as; +MemoryRegion iomem; +int mbox_irq_disabled; +qemu_irq arm_irq; +int available[MBOX_CHAN_COUNT ]; +BCM2835Mbox mbox[2 ]; +}BCM2835SbmState ; + +#endif
Signature · 1 line
2.5.3
PATCH 4/8 bcm2835_emmc: add bcm2835 MMC/SD controller
--- hw/sd/Makefile.objs | 1 + hw/sd/bcm2835_emmc.c | 800 +++++++++++++++++++++++++++++++++++++++++++ include/hw/sd/bcm2835_emmc.h | 56 +++ 3 files changed, 857 insertions(+) create mode 100644 hw/sd/bcm2835_emmc.c create mode 100644 include/hw/sd/bcm2835_emmc.h
hw/sd/Makefile.objs +1 -0
@@ -6,3 +6,4 @@ common-obj-$(CONFIG_SDHCI) += sdhci.o obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o obj-$(CONFIG_OMAP) += omap_mmc.o obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o +obj-$(CONFIG_RASPI) += bcm2835_emmc.o
hw/sd/bcm2835_emmc.c new file +800 -0
800 lines not on this page · raw message
include/hw/sd/bcm2835_emmc.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.5.3
PATCH 7/8 bcm2836: add bcm2836 soc device
In reply to Andrew BaumannThis is the SoC for Raspberry Pi 2.
--- hw/arm/Makefile.objs | 2 +- hw/arm/bcm2836.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2836.h | 33 ++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 hw/arm/bcm2836.c create mode 100644 include/hw/arm/bcm2836.h
hw/arm/Makefile.objs +1 -1
@@ -11,7 +11,7 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_RASPI) += bcm2835_peripherals.o +obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
hw/arm/bcm2836.c new file +135 -0
135 lines not on this page · raw message
include/hw/arm/bcm2836.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous +* +* 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 BCM2836_H +#define BCM2836_H + +#include "hw/arm/arm.h" +#include "hw/arm/bcm2835_peripherals.h" +#include "hw/intc/bcm2836_control.h" + +#define TYPE_BCM2836 "bcm2836" +#define BCM2836 (obj) OBJECT_CHECK(BCM2836State, (obj), TYPE_BCM2836) + +#define BCM2836_NCPUS 4 + +typedef struct BCM2836State { +/*< private >*/ +DeviceState parent_obj; +/*< public >*/ + +ARMCPU cpus[BCM2836_NCPUS ]; +BCM2836ControlState ic; +BCM2835PeripheralState peripherals; +}BCM2836State ; + +#endif /* BCM2836_H */
Signature · 1 line
2.5.3
PATCH 6/8 bcm2836_control: add bcm2836 ARM control logic
In reply to Andrew BaumannThis module is specific to the bcm2836 (Pi2). It implements the top level interrupt controller, and mailboxes used for inter-processor synchronisation.
--- hw/intc/Makefile.objs | 2 +- hw/intc/bcm2836_control.c | 344 ++++++++++++++++++++++++++++++++++++++ include/hw/intc/bcm2836_control.h | 49 ++++++ 3 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 hw/intc/bcm2836_control.c create mode 100644 include/hw/intc/bcm2836_control.h
hw/intc/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.o obj-$(CONFIG_IOAPIC) += ioapic.o obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o -obj-$(CONFIG_RASPI) += bcm2835_ic.o +obj-$(CONFIG_RASPI) += bcm2835_ic.o bcm2836_control.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o
hw/intc/bcm2836_control.c new file +344 -0
344 lines not on this page · raw message
include/hw/intc/bcm2836_control.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.5.3
PATCH 8/8 raspi: add raspberry pi 2 machine
In reply to Andrew Baumannbcm2835/Pi1 requires more peripherals, and will be added in a later patch series.
--- hw/arm/Makefile.objs | 2 +- hw/arm/raspi.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 hw/arm/raspi.c
hw/arm/Makefile.objs +1 -1
@@ -11,7 +11,7 @@ obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-$(CONFIG_DIGIC) += digic.o obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o -obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o +obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp.o xlnx-ep108.o obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
hw/arm/raspi.c new file +179 -0
179 lines not on this page · raw message
Signature · 1 line
2.5.3
Re: [Qemu-arm] [PATCH 3/8] bcm2835_ic: add bcm2835 interrupt controller
In reply to Andrew BaumannQuoted 14 lines · Andrew Baumann
Signed-off-by Andrew Baumann <[email protected]>--- hw/intc/Makefile.objs | 1 + hw/intc/bcm2835_ic.c | 234 +++++++++++++++++++++++++++++++++++++++++++ include/hw/intc/bcm2835_ic.h | 26 +++++ 3 files changed, 261 insertions(+) create mode 100644 hw/intc/bcm2835_ic.c create mode 100644 include/hw/intc/bcm2835_ic.hhw/intc/Makefile.objs +0
-0
hw/intc/Makefile.objs obj-$(CONFIG_GRLIB) += grlib_irqmp.o · line 27
Quoted 4 lines
hw/intc/Makefile.objs +1
-0@@ -24,6 +24,7 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.o obj-$(CONFIG_IOAPIC) += ioapic.o obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o +obj-$(CONFIG_RASPI) += bcm2835_ic.o
We are trying to encourage -'s for the separators in new file names, although admittedly is does seem that intc/ is lagging here.
Quoted 9 lines
hw/intc/Makefile.objs +0
-0obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.ohw/intc/bcm2835_ic.c new file +0
-0
hw/intc/bcm2835_ic.c line 8
Quoted 8 lines
hw/intc/bcm2835_ic.c new file +8
-0@@ -0,0 +1,234 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +/* Heavily based on pl190.c, copyright terms below. */ + +/*
You can just make this one header comment rather than stop and start block comments again.
hw/intc/bcm2835_ic.c line 19
Quoted 11 lines
hw/intc/bcm2835_ic.c new file +11
-0+* Arm PrimeCell PL190 Vector Interrupt Controller +* +* Copyright (c) 2006 CodeSourcery. +* Written by Paul Brook +* +* This code is licensed under the GPL. +*/ + +#include "hw/intc/bcm2835_ic.h" + +#define IR_B 2
IR_B should move down. Although some of my following comment may obsolete this def anyway.
Quoted 18 lines
hw/intc/bcm2835_ic.c new file +18
-0+#define IR_1 0 +#define IR_2 1 + +/* Update interrupts. */ +static void bcm2835_ic_update (BCM2835IcState *s) +{ +int set; +int i; + + set =0 ; +if (s->fiq_enable) { + set = s->level[s->fiq_select >>5 ] & (1u << (s->fiq_select &0x1f )); + } +qemu_set_irq (s->fiq, set); + + set =0 ; +for (i =0 ; i <3 ; i++) { + set |= (s->level[i] & s->irq_enable[i]);
hw/intc/bcm2835_ic.c line 47
Quoted 10 lines
hw/intc/bcm2835_ic.c new file +10
-0+ } +qemu_set_irq (s->irq, set); + +} + +static void bcm2835_ic_set_irq (void *opaque,int irq,int level) +{ +BCM2835IcState *s = (BCM2835IcState *)opaque; + +if (irq >=0 && irq <=71 ) {
I assume the 72 comes from 64 GPU interrupts +8 ARM interrupts. Looking at the TRM, these seem to be different enumeration schemes and not considered one interrupt list. You should use named GPIOs to split it into the two named sets "GPU" and "ARM", I notice in patch 5 you have:
+#define ARM_IRQ0_BASE 64
To convert the ARM IRQ indexing scheme to the GPU one. This would go away with the separate name sets.
hw/intc/bcm2835_ic.c line 49
Quoted 2 lines
hw/intc/bcm2835_ic.c new file +2
-0+if (level) { + s->level[irq >>5 ] |=1u << (irq &0x1f );
It also means you can have a single uint64_t (perhaps named "gpu_level") in the state to hold the full GPU interrupt list, avoiding the need for the >> 5 ... & 0x1f logic that you need a few times. The ARM interrupts then become their own separate uint8_t (arm_level?).
hw/intc/bcm2835_ic.c line 52
Quoted 3 lines
hw/intc/bcm2835_ic.c new file +3
-0+ }else { + s->level[irq >>5 ] &= ~(1u << (irq &0x1f )); + }
So these 5 lines will reduce to:
s->gpu_level = deposit64(s->gpu_level, index, 1, !!level);
hw/intc/bcm2835_ic.c line 55
Quoted 3 lines
hw/intc/bcm2835_ic.c new file +3
-0+ }else { +qemu_log_mask (LOG_GUEST_ERROR , +"bcm2835_ic_set_irq: Bad irq %d\n" , irq);
As you explicitly define the length of the interrupts list at 72, this would be fatal and should g_assert_not_reached(). But I would drip the if-else (and the check) altogether as the GPIO API should be doing its own checking.
hw/intc/bcm2835_ic.c line 66
Quoted 11 lines
hw/intc/bcm2835_ic.c new file +11
-0+ } + +bcm2835_ic_update (s); +} + +static const int irq_dups[] = {7 ,9 ,10 ,18 ,19 ,53 ,54 ,55 ,56 ,57 ,62 ,-1 }; + +static uint64_t bcm2835_ic_read (void *opaque,hwaddr offset, +unsigned size) +{ +BCM2835IcState *s = (BCM2835IcState *)opaque;
Cast unneeded.
hw/intc/bcm2835_ic.c line 72
Quoted 6 lines
hw/intc/bcm2835_ic.c new file +6
-0+int i; +int p =0 ; +uint32_t res =0 ; + +switch (offset) { +case 0x00 :/* IRQ basic pending */
Rather than commenting the hex, define macros for the register map that are then used for both read and write switches.
hw/intc/bcm2835_ic.c line 80
Quoted 8 lines
hw/intc/bcm2835_ic.c new file +8
-0+/* bits 0-7 - ARM irqs */ + res = (s->level[IR_B ] & s->irq_enable[IR_B ]) &0xff ; +for (i =0 ; i <64 ; i++) { +if (i == irq_dups[p]) { +/* bits 10-20 - selected GPU irqs */ +if (s->level[i >>5 ] & s->irq_enable[i >>5 ] + & (1u << (i &0x1f ))) { + res |= (1u << (10 + p));
This will get simpler with the unit64_t GPU interrupt list.
hw/intc/bcm2835_ic.c line 86
Quoted 6 lines
hw/intc/bcm2835_ic.c new file +6
-0+ } + p++; + }else { +/* bits 8-9 - one or more bits set in pending registers 1-2 */ +if (s->level[i >>5 ] & s->irq_enable[i >>5 ] + & (1u << (i &0x1f ))) {
The common subexpression
s->level[i >> 5] & s->irq_enable[i >> 5] & (1u << (i & 0x1f))
can be avoided with a local variable (bool irq_pending).
hw/intc/bcm2835_ic.c line 87
Quoted 1 line
hw/intc/bcm2835_ic.c new file +1
-0+ res |= (1u << (8 + (i >>5 )));
A nit, but i /32 better documents the intent of the shift.
hw/intc/bcm2835_ic.c line 93
Quoted 6 lines
hw/intc/bcm2835_ic.c new file +6
-0+ } + } + } +break ; +case 0x04 :/* IRQ pending 1 */ + res = s->level[IR_1 ] & s->irq_enable[IR_1 ];
extract64 with a case-fallthrough would be usable for getting the two halves from a uint64_t:
something like:
case 0x08:
shift = 32;
/* fallthrough */
case 0x04:
res = extract64(s->gpu_level, shift, 32) &
extract64(s->gpu_irq_enable, shift, 32);
break;hw/intc/bcm2835_ic.c line 102
Quoted 9 lines
hw/intc/bcm2835_ic.c new file +9
-0+break ; +case 0x08 :/* IRQ pending 2 */ + res = s->level[IR_2 ] & s->irq_enable[IR_2 ]; +break ; +case 0x0C :/* FIQ register */ + res = (s->fiq_enable <<7 ) | s->fiq_select; +break ; +case 0x10 :/* Interrupt enable register 1 */ + res = s->irq_enable[IR_1 ];
irq_enable would also be split to gpu_irq_enable and arm_irq_enable separate variables under split GPIO namespace implementation.
Quoted 9 lines
hw/intc/bcm2835_ic.c new file +9
-0+break ; +case 0x14 :/* Interrupt enable register 2 */ + res = s->irq_enable[IR_2 ]; +break ; +case 0x18 :/* Base interrupt enable register */ + res = s->irq_enable[IR_B ]; +break ; +case 0x1C :/* Interrupt disable register 1 */ + res = ~s->irq_enable[IR_1 ];
hw/intc/bcm2835_ic.c line 121
Quoted 10 lines
hw/intc/bcm2835_ic.c new file +10
-0+break ; +case 0x20 :/* Interrupt disable register 2 */ + res = ~s->irq_enable[IR_2 ]; +break ; +case 0x24 :/* Base interrupt disable register */ + res = ~s->irq_enable[IR_B ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"bcm2835_ic_read: Bad offset %x\n" , (int )offset);
%s __func__ for the function name component. This guards against the message going stale if the function is renamed.
Use HWADDR_PRIx rather than cast the offset.
hw/intc/bcm2835_ic.c line 129
Quoted 8 lines
hw/intc/bcm2835_ic.c new file +8
-0+return 0 ; + } + +return res; +} + +static void bcm2835_ic_write (void *opaque,hwaddr offset, +uint64_t val,unsigned size)
Indentation of continued argument lists should indent to one past the "(" which started the list:
static void bcm2835_ic_write(void *opaque, hwaddr offset,
uint64_t val, unsigned size)
hw/intc/bcm2835_ic.c line 131
Quoted 2 lines
hw/intc/bcm2835_ic.c new file +2
-0+{ +BCM2835IcState *s = (BCM2835IcState *)opaque;
Cast unneeded.
Quoted 25 lines
hw/intc/bcm2835_ic.c new file +25
-0+ +switch (offset) { +case 0x0C :/* FIQ register */ + s->fiq_select = (val &0x7f ); + s->fiq_enable = (val >>7 ) &0x1 ; +break ; +case 0x10 :/* Interrupt enable register 1 */ + s->irq_enable[IR_1 ] |= val; +break ; +case 0x14 :/* Interrupt enable register 2 */ + s->irq_enable[IR_2 ] |= val; +break ; +case 0x18 :/* Base interrupt enable register */ + s->irq_enable[IR_B ] |= (val &0xff ); +break ; +case 0x1C :/* Interrupt disable register 1 */ + s->irq_enable[IR_1 ] &= ~val; +break ; +case 0x20 :/* Interrupt disable register 2 */ + s->irq_enable[IR_2 ] &= ~val; +break ; +case 0x24 :/* Base interrupt disable register */ + s->irq_enable[IR_B ] &= (~val &0xff ); +break ; +default :
hw/intc/bcm2835_ic.c line 166
Quoted 10 lines
hw/intc/bcm2835_ic.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"bcm2835_ic_write: Bad offset %x\n" , (int )offset); +return ; + } +bcm2835_ic_update (s); +} + +static const MemoryRegionOps bcm2835_ic_ops = { + .read = bcm2835_ic_read, + .write = bcm2835_ic_write,
You do not handle anything that is not a word access so you should add the min_access_size and max_access_size definitions.
Quoted 14 lines
hw/intc/bcm2835_ic.c new file +14
-0+ .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void bcm2835_ic_reset (DeviceState *d) +{ +BCM2835IcState *s =BCM2835_IC (d); +int i; + +for (i =0 ; i <3 ; i++) { + s->irq_enable[i] =0 ; + } + s->fiq_enable =0 ; + s->fiq_select =0 ; +}
hw/intc/bcm2835_ic.c line 190
Quoted 10 lines
hw/intc/bcm2835_ic.c new file +10
-0+ +static void bcm2835_ic_init (Object *obj) +{ +BCM2835IcState *s =BCM2835_IC (obj); + +memory_region_init_io (&s->iomem, obj, &bcm2835_ic_ops, s,TYPE_BCM2835_IC , +0x200 ); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); + +qdev_init_gpio_in (DEVICE (s), bcm2835_ic_set_irq,72 );
This is where the split would happen:
qdev_init_gpio_in_named(DEVICE(s), bcm2835_ic_set_irq, BCM2835_IC_GPU_IRQ, 64); qdev_init_gpio_in_named(DEVICE(s), bcm2835_ic_set_irq, BCM2835_IC_ARM_IRQ, 8);
Where the two macros are something like "gpu-irq" and "arm-irq".
hw/intc/bcm2835_ic.c line 197
Quoted 7 lines
hw/intc/bcm2835_ic.c new file +7
-0+sysbus_init_irq (SYS_BUS_DEVICE (s), &s->irq); +sysbus_init_irq (SYS_BUS_DEVICE (s), &s->fiq); +} + +static void bcm2835_ic_realize (DeviceState *dev,Error **errp) +{ +}
Nop realize is not needed. Just leave the callback unset in class_init.
hw/intc/bcm2835_ic.c line 207
Quoted 10 lines
hw/intc/bcm2835_ic.c new file +10
-0+ +static const VMStateDescription vmstate_bcm2835_ic = { + .name =TYPE_BCM2835_IC , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (level, BCM2835IcState,3 ), +VMSTATE_UINT32_ARRAY (irq_enable, BCM2835IcState,3 ), +VMSTATE_INT32 (fiq_enable, BCM2835IcState), +VMSTATE_INT32 (fiq_select, BCM2835IcState),
fiq_select should be a bool.
hw/intc/bcm2835_ic.c line 216
Quoted 9 lines
hw/intc/bcm2835_ic.c new file +9
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void bcm2835_ic_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = bcm2835_ic_realize;
So this line can be dropped.
Quoted 28 lines
hw/intc/bcm2835_ic.c new file +18
-0+ dc->reset = bcm2835_ic_reset; + dc->vmsd = &vmstate_bcm2835_ic; +} + +static TypeInfo bcm2835_ic_info = { + .name =TYPE_BCM2835_IC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (BCM2835IcState), + .class_init = bcm2835_ic_class_init, + .instance_init = bcm2835_ic_init, +}; + +static void bcm2835_ic_register_types (void ) +{ +type_register_static (&bcm2835_ic_info); +} + +type_init (bcm2835_ic_register_types)include/hw/intc/bcm2835_ic.h new file +4
-0@@ -0,0 +1,26 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/
include/hw/intc/bcm2835_ic.h line 14
Quoted 10 lines
include/hw/intc/bcm2835_ic.h new file +10
-0+ +#ifndef BCM2835_IC_H +#define BCM2835_IC_H + +#include "hw/sysbus.h" + +#define TYPE_BCM2835_IC "bcm2835_ic" +#define BCM2835_IC(obj) OBJECT_CHECK(BCM2835IcState, (obj), TYPE_BCM2835_IC) + +typedef struct BCM2835IcState {
Add the comments:
/*< private >*/
include/hw/intc/bcm2835_ic.h line 15
Quoted 1 line
include/hw/intc/bcm2835_ic.h new file +1
-0+SysBusDevice busdev;
and:
/*< public >*/
As they make some auto-generated documentation nicer.
include/hw/intc/bcm2835_ic.h line 20
Quoted 5 lines
include/hw/intc/bcm2835_ic.h new file +5
-0+MemoryRegion iomem; + +uint32_t level[3 ]; +uint32_t irq_enable[3 ]; +int fiq_enable;
You migrate this as a uint32_t so it must be a uint32_t here as well.
include/hw/intc/bcm2835_ic.h line 24
Quoted 4 lines
include/hw/intc/bcm2835_ic.h new file +4
-0+int fiq_select; +qemu_irq irq; +qemu_irq fiq; +} BCM2835IcState;
BCM2835ICState. Acronyms in camel case should be all caps.
Regards,
Peter
Quoted 5 lines
include/hw/intc/bcm2835_ic.h new file +2
-1+ +#endif --2.5.3
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Andrew BaumannQuoted 29 lines · Andrew Baumann
Signed-off-by Andrew Baumann <[email protected]>--- hw/sd/Makefile.objs | 1 + hw/sd/bcm2835_emmc.c | 800 +++++++++++++++++++++++++++++++++++++++++++ include/hw/sd/bcm2835_emmc.h | 56 +++ 3 files changed, 857 insertions(+) create mode 100644 hw/sd/bcm2835_emmc.c create mode 100644 include/hw/sd/bcm2835_emmc.hhw/sd/Makefile.objs +1
-0@@ -6,3 +6,4 @@ common-obj-$(CONFIG_SDHCI) += sdhci.o obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o obj-$(CONFIG_OMAP) += omap_mmc.o obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o +obj-$(CONFIG_RASPI) += bcm2835_emmc.ohw/sd/bcm2835_emmc.c new file +5
-0@@ -0,0 +1,800 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ +
hw/sd/bcm2835_emmc.c line 15
Quoted 10 lines
hw/sd/bcm2835_emmc.c new file +10
-0+#include "sysemu/blockdev.h" +#include "hw/sd/bcm2835_emmc.h" + +/* +* Controller registers +*/ + +#define SDHCI_DMA_ADDRESS 0x00 +#define SDHCI_ARGUMENT2 SDHCI_DMA_ADDRESS +
Is this IP just SDHCI? We already model SDHCI in QEMU, see hw/sd/sdhci.c. If there are RPi specific features to the SDHCI implementation they should be added as optional extensions (probabably via subclassing) to the existing SDHCI model.
Regards,
Peter
Re: [Qemu-devel] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Andrew BaumannQuoted 3 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Are there any publically available specs for this? I found the peripheral manual which documents the interrupts controller but I couldnt easily find a doc to cover this. I can review without docs, but it is a little harder. A few top level sentances about how it works and what it does would help in commit message if we can't get a doc.
Regards,
Peter
Quoted 2 lines
Signed-off-by Andrew Baumann <[email protected]>---
Re: [Qemu-devel] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
Quoted 8 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Sunday, 6 December 2015 22:37Quoted 3 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Quoted 6 lines
Are there any publically available specs for this? I found the peripheral manual which documents the interrupts controller but I couldnt easily find a doc to cover this. I can review without docs, but it is a little harder. A few top level sentances about how it works and what it does would help in commit message if we can't get a doc.
The only docs I could find are:
https://github.com/raspberrypi/firmware/wiki/Mailboxes
https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes
It probably doesn't hurt to add these links to either a header comment or commit message. I'll do that in v2.
Andrew
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Peter CrosthwaiteQuoted 6 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Saturday, 5 December 2015 21:26
Is this IP just SDHCI? We already model SDHCI in QEMU, seehw/sd/sdhci.c. If there are RPi specific features to the SDHCI implementation they should be added as optional extensions (probabably via subclassing) to the existing SDHCI model.
So yes, it turns out this is fairly similar to SDHCI (-> lots of wasted work by Gregory and me, sigh), and indeed Linux boots with the existing sdhci emulation. However, there are some quirks, and UEFI/Windows depend on them. Namely:
* The host control registers (offset 0x28 and above) seem to differ significantly. Maybe this is due to the SDHC version -- according to the BCM2835 peripherals spec, the controller implements "Version 3.0 Draft 1.0" of the SDHC spec, but of course I can't find that spec online anywhere. Luckily nothing seems to depend on this, besides a few spurious warnings about invalid writes.
* Power is assumed to be always on -- the sdhci model requires the guest to turn it on by a write at offset 0x29 before issuing any commands, but on pi this bit is marked reserved, and commands are issued immediately after reset.
* The card inserted interrupt is rather broken on pi: it is set at the start of day, but a reset command clears it and it stays clear thereafter (and never generates interrupts).
There's an inconsistency with response handling, too, although I'm not sure if it's a quirk of the Pi or a general bug in sdhci. Pi UEFI sends a CMD23 without setting any of the response bits, but this command does in fact generate a 4-byte R1 response. The question is whether this should be treated as an error, or whether it simply means that the host wants to ignore the response. In sdhci, the following code path (around line 246) raises a "command index" error in the case that a non-zero response is returned but no response bits were set in the command register:
} else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) {
s->errintsts |= SDHC_EIS_CMDIDX;
s->norintsts |= SDHC_NIS_ERR;
}I do not observe this behaviour on the real Pi2 (and it breaks UEFI). The hardware semantics appear to be "if the command generates a response, but you didn't want to see it, we'll successfully complete the command and ignore the response", whereas the sdhci implementation raises an error for this as well as signalling completion. I have read the "SD Specifications Part A2 SD Host Controller Simplified Specification Version 2.00", but did not find anything describing this case, so it could be that this is open to interpretation. (It could also be specified in SDHC v3.) The specific error also seems odd -- my understanding is that a "command index" error means that the index in the response didn't match the index of the issued command, but that's hardly what is happening here.
Assuming this latter bug can be fixed generically, how do you propose handling the Pi quirks? I could add a bool property for "bcm2835-quirks" or similar and just special-case the relevant code (my preferred approach). I'm also open to subclassing, but no idea how that would work in practice, so would need some pointers.
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 3/8] bcm2835_ic: add bcm2835 interrupt controller
In reply to Peter CrosthwaitePeter,
Thanks for the feedback on this patch. I agree with all of it, but I do have one minor quibble...
Quoted 4 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Saturday, 5 December 2015 21:20
On Thu, Dec 3, 2015 at 10:01 PM, Andrew Baumann <[email protected]> wrote:
Quoted 10 lines
hw/intc/Makefile.objs obj-$(CONFIG_GRLIB) += grlib_irqmp.o · line 27
Quoted 7 lines
hw/intc/Makefile.objs +1
-0@@ -24,6 +24,7 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.o obj-$(CONFIG_IOAPIC) += ioapic.o obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o +obj-$(CONFIG_RASPI) += bcm2835_ic.oWe are trying to encourage -'s for the separators in new file names, although admittedly is does seem that intc/ is lagging here.
Sigh. I can rename all the new files if you insist, but what's the rationale for this?
Just for the record:
% find qemu -iname *.[ch] | grep -c -
1728
% find qemu -iname *.[ch] | grep -c _
1166
Andrew
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Andrew BaumannQuoted 9 lines · Andrew Baumann
Quoted 6 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Saturday, 5 December 2015 21:26
Is this IP just SDHCI? We already model SDHCI in QEMU, seehw/sd/sdhci.c. If there are RPi specific features to the SDHCI implementation they should be added as optional extensions (probabably via subclassing) to the existing SDHCI model.So yes, it turns out this is fairly similar to SDHCI (-> lots of wasted work by Gregory and me, sigh), and indeed Linux boots with the existing sdhci emulation. However, there are some quirks, and UEFI/Windows depend on them. Namely:
* The host control registers (offset0x28and above) seem to differ significantly. Maybe this is due to the SDHC version -- according to the BCM2835 peripherals spec, the controller implements "Version 3.0 Draft 1.0" of the SDHC spec, but of course I can't find that spec online anywhere. Luckily nothing seems to depend on this, besides a few spurious warnings about invalid writes.
Looks reasonably consistent from a quick scan? 0x28 in shdci.c is only doing the ADMA stuff while there are other fields on the BCM model.
Quoted 1 line
* Power is assumed to be always on -- the sdhci model requires the guest to turn it on by a write at offset
0x29before issuing any commands, but on pi this bit is marked reserved, and commands are issued immediately after reset.
Does this help?:
https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg06271.html
Quoted 2 lines
* The card inserted interrupt is rather broken on pi: it is set at the start of day, but a reset command clears it and it stays clear thereafter (and never generates interrupts).
Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
Quoted 9 lines
There's an inconsistency with response handling, too, although I'm not sure if it's a quirk of the Pi or a general bug in sdhci. Pi UEFI sends a CMD23 without setting any of the response bits, but this command does in fact generate a 4-byte R1 response. The question is whether this should be treated as an error, or whether it simply means that the host wants to ignore the response. In sdhci, the following code path (around line 246) raises a "command index" error in the case that a non-zero response is returned but no response bits were set in the command register:
} else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |= SDHC_EIS_CMDIDX; s->norintsts |= SDHC_NIS_ERR; }I do not observe this behaviour on the real Pi2 (and it breaks UEFI). The hardware semantics appear to be "if the command generates a response, but you didn't want to see it, we'll successfully complete the command and ignore the response", whereas the sdhci implementation raises an error for this as well as signalling completion. I have read the "SD Specifications Part A2 SD Host Controller Simplified Specification Version 2.00", but did not find anything describing this case, so it could be that this is open to interpretation. (It could also be specified in SDHC v3.) The specific error also seems odd -- my understanding is that a "command index" error means that the index in the response didn't match the index of the issued command, but that's hardly what is happening here.
Starting to sound like a bug.
Quoted 2 lines
Assuming this latter bug can be fixed generically, how do you propose handling the Pi quirks? I could add a bool property for "bcm2835-quirks" or similar and just special-case the relevant code (my preferred approach). I'm also open to subclassing, but no idea how that would work in practice, so would need some pointers.
I think we need a more definitive list of the register level features that are different or added, I am not seeing what is BCM specific just yet.
Regards,
Peter
Quoted 2 lines
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
Quoted 16 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Tuesday, 8 December 2015 23:40Quoted 8 lines · Andrew Baumann
Quoted 6 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Saturday, 5 December 2015 21:26
Is this IP just SDHCI? We already model SDHCI in QEMU, seehw/sd/sdhci.c. If there are RPi specific features to the SDHCI implementation they should be added as optional extensions (probabably via subclassing) to the existing SDHCI model.So yes, it turns out this is fairly similar to SDHCI (-> lots of wasted work by
Gregory and me, sigh), and indeed Linux boots with the existing sdhci emulation. However, there are some quirks, and UEFI/Windows depend on them. Namely:
Quoted 1 line
* The host control registers (offset
0x28and above) seem to differ
Quoted 8 lines
significantly. Maybe this is due to the SDHC version -- according to the BCM2835 peripherals spec, the controller implements "Version 3.0 Draft 1.0" of the SDHC spec, but of course I can't find that spec online anywhere. Luckily nothing seems to depend on this, besides a few spurious warnings about invalid writes.
Looks reasonably consistent from a quick scan?
0x28inshdci.cis only doing the ADMA stuff while there are other fields on the BCM model.
You're right, upon closer examination, it's not as bad as I thought (just reserved / unimplemented bits). The one significant difference that seems likely to cause a problem is the first register (offset 0x0-0x3) which is ARG2 on Pi (used for auto CMD 23 support) but the SDMA system address on SDHCI (Pi doesn't support DMA in the controller). This will break if a guest wants to use auto cmd 23 -- I've yet to see one that does, but Gregory's model implements it, so perhaps he did.
Quoted 8 lines
Quoted 1 line
* Power is assumed to be always on -- the sdhci model requires the guest
to turn it on by a write at offset
0x29before issuing any commands, but on pi this bit is marked reserved, and commands are issued immediately after reset.Does this help?:
https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg06271.html
Yes, that's the same change I made. Is it going to be applied?
Quoted 7 lines
Quoted 1 line
* The card inserted interrupt is rather broken on pi: it is set at the start of
day, but a reset command clears it and it stays clear thereafter (and never generates interrupts).
Quoted 1 line
Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
That might be it, but in any case I still need to model it somehow.
Quoted 27 lines
Quoted 1 line
There's an inconsistency with response handling, too, although I'm not sure
if it's a quirk of the Pi or a general bug in sdhci. Pi UEFI sends a CMD23 without setting any of the response bits, but this command does in fact generate a 4-byte R1 response. The question is whether this should be treated as an error, or whether it simply means that the host wants to ignore the response. In sdhci, the following code path (around line 246) raises a "command index" error in the case that a non-zero response is returned but no response bits were set in the command register:
Quoted 7 lines
} else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |= SDHC_EIS_CMDIDX; s->norintsts |= SDHC_NIS_ERR; }I do not observe this behaviour on the real Pi2 (and it breaks UEFI). The
hardware semantics appear to be "if the command generates a response, but you didn't want to see it, we'll successfully complete the command and ignore the response", whereas the sdhci implementation raises an error for this as well as signalling completion. I have read the "SD Specifications Part A2 SD Host Controller Simplified Specification Version 2.00", but did not find anything describing this case, so it could be that this is open to interpretation. (It could also be specified in SDHC v3.) The specific error also seems odd -- my understanding is that a "command index" error means that the index in the response didn't match the index of the issued command, but that's hardly what is happening here.
Quoted 1 line
Quoted 1 line
Starting to sound like a bug.
I think so, yes. It was written this way in the original commit -- I'm adding the original author (Igor Mitsyanko) to the thread, in case he has any insight.
Quoted 10 lines
Quoted 1 line
Assuming this latter bug can be fixed generically, how do you propose
handling the Pi quirks? I could add a bool property for "bcm2835-quirks" or similar and just special-case the relevant code (my preferred approach). I'm also open to subclassing, but no idea how that would work in practice, so would need some pointers.
Quoted 1 line
I think we need a more definitive list of the register level features that are different or added, I am not seeing what is BCM specific just yet.
The complete diff needed to boot Windows appears below. The first hunk avoids re-triggering the insert interrupt on card reset, the second fixes the bug described above, and the last hunk is equivalent to your patch linked above. I propose that we make the first conditional under a suitably-named bool property to enable the quirk, and apply the second two fixes directly.
Thoughts?
Andrew
hw/sd/sdhci.c +4 -2
@@ -193,7 +193,7 @@ static void sdhci_reset(SDHCIState *s)* initialization */ memset (&s->sdmasysad,0 , (uintptr_t )&s->capareg - (uintptr_t )&s->sdmasysad); -sd_set_cb (s->card, s->ro_cb, s->eject_cb); +//sd_set_cb(s->card, s->ro_cb, s->eject_cb); s->data_count =0 ; s->stopped_state = sdhc_not_stopped; }
@@ -243,9 +243,11 @@ static void sdhci_send_command(SDHCIState *s) (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { s->norintsts |=SDHC_NIS_TRSCMP ; } +#if 0 } else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |=SDHC_EIS_CMDIDX ; s->norintsts |=SDHC_NIS_ERR ; +#endif }if (s->norintstsen &SDHC_NISEN_CMDCMP ) {
@@ -831,7 +833,7 @@ static void sdhci_data_transfer(void *opaque)static bool sdhci_can_issue_command (SDHCIState *s) { - if (!SDHC_CLOCK_IS_ON(s->clkcon) || !(s->pwrcon & SDHC_POWER_ON) || + if (!SDHC_CLOCK_IS_ON(s->clkcon) || /* !(s->pwrcon & SDHC_POWER_ON) || */ (((s->prnsts & SDHC_DATA_INHIBIT) || s->stopped_state) && ((s->cmdreg & SDHC_CMD_DATA_PRESENT) || ((s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY &&
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
Quoted 32 lines · Andrew Baumann
Quoted 16 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Tuesday, 8 December 2015 23:40Quoted 8 lines · Andrew Baumann
Quoted 6 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Saturday, 5 December 2015 21:26
Is this IP just SDHCI? We already model SDHCI in QEMU, seehw/sd/sdhci.c. If there are RPi specific features to the SDHCI implementation they should be added as optional extensions (probabably via subclassing) to the existing SDHCI model.So yes, it turns out this is fairly similar to SDHCI (-> lots of wasted work by
Gregory and me, sigh), and indeed Linux boots with the existing sdhci emulation. However, there are some quirks, and UEFI/Windows depend on them. Namely:
Quoted 1 line
* The host control registers (offset
0x28and above) seem to differQuoted 8 lines
significantly. Maybe this is due to the SDHC version -- according to the BCM2835 peripherals spec, the controller implements "Version 3.0 Draft 1.0" of the SDHC spec, but of course I can't find that spec online anywhere. Luckily nothing seems to depend on this, besides a few spurious warnings about invalid writes.
Looks reasonably consistent from a quick scan?
0x28inshdci.cis only doing the ADMA stuff while there are other fields on the BCM model.You're right, upon closer examination, it's not as bad as I thought (just reserved / unimplemented bits). The one significant difference that seems likely to cause a problem is the first register (offset 0x0-0x3) which is ARG2 on Pi (used for auto CMD 23 support) but the SDMA system address on SDHCI (Pi doesn't support DMA in the controller). This will break if a guest wants to use auto cmd 23 -- I've yet to see one that does, but Gregory's model implements it, so perhaps he did.
Quoted 5 lines
Quoted 1 line
* Power is assumed to be always on -- the sdhci model requires the guest
to turn it on by a write at offset
0x29before issuing any commands, but on pi this bit is marked reserved, and commands are issued immediately after reset.
Quoted 6 lines
Quoted 3 lines
Does this help?:
https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg06271.html
Yes, that's the same change I made. Is it going to be applied?
It missed the boat for 2.5, but you could help by putting a tested-by or reviewed-by to the patch.
Quoted 10 lines
Quoted 7 lines
Quoted 1 line
* The card inserted interrupt is rather broken on pi: it is set at the start of
day, but a reset command clears it and it stays clear thereafter (and never generates interrupts).
Quoted 1 line
Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
That might be it, but in any case I still need to model it somehow.
Ideally, this would be managed on the board level but it is kinda hard the way to code is organised. Currently SDHCI is managing the SD card instantiation due to a lack of QOMification. So for the moment, this would be valid as a boolean property which disables the card detect logic completely. If we get the SD QOMification though, the power, card detect and sd interface proper can then be more finely managed on the board level for all these varying connectivity configurations.
Quoted 38 lines
Quoted 27 lines
Quoted 1 line
There's an inconsistency with response handling, too, although I'm not sure
if it's a quirk of the Pi or a general bug in sdhci. Pi UEFI sends a CMD23 without setting any of the response bits, but this command does in fact generate a 4-byte R1 response. The question is whether this should be treated as an error, or whether it simply means that the host wants to ignore the response. In sdhci, the following code path (around line 246) raises a "command index" error in the case that a non-zero response is returned but no response bits were set in the command register:
Quoted 7 lines
} else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |= SDHC_EIS_CMDIDX; s->norintsts |= SDHC_NIS_ERR; }I do not observe this behaviour on the real Pi2 (and it breaks UEFI). The
hardware semantics appear to be "if the command generates a response, but you didn't want to see it, we'll successfully complete the command and ignore the response", whereas the sdhci implementation raises an error for this as well as signalling completion. I have read the "SD Specifications Part A2 SD Host Controller Simplified Specification Version 2.00", but did not find anything describing this case, so it could be that this is open to interpretation. (It could also be specified in SDHC v3.) The specific error also seems odd -- my understanding is that a "command index" error means that the index in the response didn't match the index of the issued command, but that's hardly what is happening here.
Quoted 1 line
Quoted 1 line
Starting to sound like a bug.
I think so, yes. It was written this way in the original commit -- I'm adding the original author (Igor Mitsyanko) to the thread, in case he has any insight.
Quoted 7 lines
Quoted 1 line
Assuming this latter bug can be fixed generically, how do you propose
handling the Pi quirks? I could add a bool property for "bcm2835-quirks" or similar and just special-case the relevant code (my preferred approach). I'm also open to subclassing, but no idea how that would work in practice, so would need some pointers.
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
I think we need a more definitive list of the register level features that are different or added, I am not seeing what is BCM specific just yet.
The complete diff needed to boot Windows appears below. The first hunk avoids re-triggering the insert interrupt on card reset,
Is this a runtime reset or an initial reset that is causing you grief? You patch is also patching the controller reset so is it more a case of the interrupt trigger on controller reset that is causing you issues?
Regards,
Peter
Quoted 40 lines
the second fixes the bug described above, and the last hunk is equivalent to your patch linked above. I propose that we make the first conditional under a suitably-named bool property to enable the quirk, and apply the second two fixes directly.
Thoughts?
Andrew
hw/sd/sdhci.c +4
-2@@ -193,7 +193,7 @@ static void sdhci_reset(SDHCIState *s)* initialization */ memset (&s->sdmasysad,0 , (uintptr_t )&s->capareg - (uintptr_t )&s->sdmasysad); -sd_set_cb (s->card, s->ro_cb, s->eject_cb); +//sd_set_cb(s->card, s->ro_cb, s->eject_cb); s->data_count =0 ; s->stopped_state = sdhc_not_stopped; }@@ -243,9 +243,11 @@ static void sdhci_send_command(SDHCIState *s) (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { s->norintsts |=SDHC_NIS_TRSCMP ; } +#if 0 } else if (rlen != 0 && (s->errintstsen & SDHC_EISEN_CMDIDX)) { s->errintsts |=SDHC_EIS_CMDIDX ; s->norintsts |=SDHC_NIS_ERR ; +#endif }if (s->norintstsen &SDHC_NISEN_CMDCMP ) {@@ -831,7 +833,7 @@ static void sdhci_data_transfer(void *opaque)static bool sdhci_can_issue_command (SDHCIState *s) { - if (!SDHC_CLOCK_IS_ON(s->clkcon) || !(s->pwrcon & SDHC_POWER_ON) || + if (!SDHC_CLOCK_IS_ON(s->clkcon) || /* !(s->pwrcon & SDHC_POWER_ON) || */ (((s->prnsts & SDHC_DATA_INHIBIT) || s->stopped_state) && ((s->cmdreg & SDHC_CMD_DATA_PRESENT) || ((s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY &&
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
Quoted 7 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Wednesday, 9 December 2015 10:55Quoted 2 lines
Yes, that's the same change I made. Is it going to be applied?
It missed the boat for 2.5, but you could help by putting a tested-by or reviewed-by to the patch.
Ok.
Quoted 7 lines
Quoted 1 line
The complete diff needed to boot Windows appears below. The first hunk
avoids re-triggering the insert interrupt on card reset,
Is this a runtime reset or an initial reset that is causing you grief? You patch is also patching the controller reset so is it more a case of the interrupt trigger on controller reset that is causing you issues?
It's the software-issued controller reset... at board power on, the insert interrupt bit is set (and UEFI depends on seeing it set), but when the Windows driver starts, it issues a reset command which clears the interrupt status. It also has a bug which livelocks the system if an insert interrupt is seen after that reset (which never happens on hardware, obviously).
Andrew
Re: [Qemu-arm] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Peter CrosthwaiteQuoted 9 lines · Peter Crosthwaite
Quoted 6 lines · Andrew Baumann
Quoted 3 lines
From: Peter Crosthwaite [mailto:[email protected]] Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
That might be it, but in any case I still need to model it somehow.
Quoted 7 lines
Ideally, this would be managed on the board level but it is kinda hard the way to code is organised. Currently SDHCI is managing the SD card instantiation due to a lack of QOMification. So for the moment, this would be valid as a boolean property which disables the card detect logic completely. If we get the SD QOMification though, the power, card detect and sd interface proper can then be more finely managed on the board level for all these varying connectivity configurations.
Card detect you should be able to handle on the board level without waiting for QOMification -- it's just modelled as a QEMU irq line (the vexpress board connects it up to a random register, or you could not connect it to anything, etc).
I'm working on the QOMification of sd.c this week, though I'm very rusty on how to properly model buses.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
Quoted 21 lines
From: Peter Maydell [mailto:[email protected]]
Sent: Wednesday, 9 December 2015 13:01Quoted 9 lines · Peter Crosthwaite
Quoted 6 lines · Andrew Baumann
Quoted 3 lines
From: Peter Crosthwaite [mailto:[email protected]] Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
That might be it, but in any case I still need to model it somehow.
Quoted 7 lines
Ideally, this would be managed on the board level but it is kinda hard the way to code is organised. Currently SDHCI is managing the SD card instantiation due to a lack of QOMification. So for the moment, this would be valid as a boolean property which disables the card detect logic completely. If we get the SD QOMification though, the power, card detect and sd interface proper can then be more finely managed on the board level for all these varying connectivity configurations.
Quoted 4 lines
Card detect you should be able to handle on the board level without waiting for QOMification -- it's just modelled as a QEMU irq line (the vexpress board connects it up to a random register, or you could not connect it to anything, etc).
Forgive me if I'm slow, but I don’t see how that could work for sdhci.
Vexpress uses pl181, which has GPIO _outputs_ for card inserted etc. sdhci multiplexes the card inserted interrupt (which originates in sd.c) along with other SD events like command completion into a single interrupt line.
If there was a way to interpose on the irq between sd and sdhci, I think I could do what I want, but right now they are allocated and wired up in sdhci's init routine.
Andrew
Re: [Qemu-devel] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Peter MaydellQuoted 19 lines · Peter Maydell
Quoted 9 lines · Peter Crosthwaite
Quoted 6 lines · Andrew Baumann
Quoted 3 lines
From: Peter Crosthwaite [mailto:[email protected]] Is that more likely to be an IP connectivity problem (wierd input to the card-detect pin in the SoC)?
That might be it, but in any case I still need to model it somehow.
Quoted 7 lines
Ideally, this would be managed on the board level but it is kinda hard the way to code is organised. Currently SDHCI is managing the SD card instantiation due to a lack of QOMification. So for the moment, this would be valid as a boolean property which disables the card detect logic completely. If we get the SD QOMification though, the power, card detect and sd interface proper can then be more finely managed on the board level for all these varying connectivity configurations.
Quoted 5 lines
Card detect you should be able to handle on the board level without waiting for QOMification -- it's just modelled as a QEMU irq line (the vexpress board connects it up to a random register, or you could not connect it to anything, etc).
It's probably worth waiting for the QOMification though, so the GPIO out has a correct formal owner.
Quoted 3 lines
I'm working on the QOMification of
sd.cthis week, though I'm very rusty on how to properly model buses.
The last bus I did was SSI (SPI) which I am reasonably confident that it is up to date unless we are trying to achieve the "busless" goal or pure QOM links. When I was looking at NAND QOMification (unfortunately I didn't make it to conclusion) I noticed that many of the features were common to SSI, mainly WRT GPIO based individual chip select lines. Since SD is has SPI compatibility mode an SD card should actually be a subclass of SSI_DEVICE. I'm thinking the same might apply on the bus side. So you could subclass SSI_BUS as SD_BUS which picks up SSI's CS stuff for free while quite naturally having the consequence of SD cards being SPI devices.
Regards,
Peter
Quoted 2 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH 4/8] bcm2835_emmc: add bcm2835 MMC/SD controller
In reply to Peter CrosthwaiteQuoted 8 lines · Peter Crosthwaite
Quoted 6 lines · Andrew Baumann
Quoted 6 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Tuesday, 8 December 2015 23:40Quoted 2 lines · Andrew Baumann
Quoted 1 line
From: Peter Crosthwaite [mailto:[email protected]]
I do not observe this behaviour on the real Pi2 (and it breaks UEFI). The
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hardware semantics appear to be "if the command generates a response, but you didn't want to see it, we'll successfully complete the command and ignore the response", whereas the sdhci implementation raises an error for this as well as signalling completion. I have read the "SD Specifications Part A2 SD Host Controller Simplified Specification Version 2.00", but did not find anything describing this case, so it could be that this is open to interpretation. (It could also be specified in SDHC v3.) The specific error also seems odd -- my understanding is that a "command index" error means that the index in the response didn't match the index of the issued command, but that's hardly what is happening here.
FYI the SDHCI v3 spec is available online. Confusingly, it's listed as an addendum instead of explicitly as the sdhci spec. The file is partA2_300.pdf .
-Kevin
Re: [Qemu-devel] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Andrew BaumannQuoted 10 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Signed-off-by Andrew Baumann <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++include/hw/arm/bcm2835_arm_control.h | 481 +++++++++++++++++++++++++++++++++++
Do we need this file as of this patch?
Quoted 48 lines
include/hw/arm/bcm2835_mbox.h | 19 ++ include/hw/misc/bcm2835_sbm.h | 37 +++ 6 files changed, 819 insertions(+) create mode 100644 hw/misc/bcm2835_sbm.c create mode 100644 include/hw/arm/bcm2835_arm_control.h create mode 100644 include/hw/arm/bcm2835_mbox.h create mode 100644 include/hw/misc/bcm2835_sbm.hdefault-configs/arm-softmmu.mak +1
-0@@ -79,6 +79,7 @@ CONFIG_TUSB6010=y CONFIG_IMX=y CONFIG_MAINSTONE=y CONFIG_NSERIES=y +CONFIG_RASPI=y CONFIG_REALVIEW=y CONFIG_ZAURUS=y CONFIG_ZYNQ=yhw/misc/Makefile.objs +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_OMAP) += omap_gpmc.o obj-$(CONFIG_OMAP) += omap_l4.o obj-$(CONFIG_OMAP) += omap_sdrc.o obj-$(CONFIG_OMAP) += omap_tap.o +obj-$(CONFIG_RASPI) += bcm2835_sbm.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.ohw/misc/bcm2835_sbm.c new file +10
-0@@ -0,0 +1,280 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#include "hw/misc/bcm2835_sbm.h" +#include "hw/arm/bcm2835_arm_control.h" + +static void mbox_update_status (BCM2835Mbox *mb) +{
hw/misc/bcm2835_sbm.c line 20
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+if (mb->count ==0 ) { + mb->status |=ARM_MS_EMPTY ; + }else { + mb->status &= ~ARM_MS_EMPTY ; + } +if (mb->count ==MBOX_SIZE ) { + mb->status |=ARM_MS_FULL ; + }else { + mb->status &= ~ARM_MS_FULL ; + }
The start-from-scratch approach makes this shorter:
mb->status &= ~(ARM_MS_EMPTY | ARM_MS_FULL);
if (mb->count == 0) {
mb->status |= ARM_MS_EMPTY;
}
if (mb->count == MBOX_SIZE) {
mb->status |= ARM_MS_FULL;
}hw/misc/bcm2835_sbm.c line 23
Quoted 3 lines
hw/misc/bcm2835_sbm.c new file +3
-0+} + +static void mbox_init (BCM2835Mbox *mb)
This looks like a reset function.
hw/misc/bcm2835_sbm.c line 25
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+{ +int n;
Blank line here.
Quoted 26 lines
hw/misc/bcm2835_sbm.c new file +26
-0+ mb->count =0 ; + mb->config =0 ; +for (n =0 ; n <MBOX_SIZE ; n++) { + mb->reg[n] =MBOX_INVALID_DATA ; + } +mbox_update_status (mb); +} + +static uint32_t mbox_pull (BCM2835Mbox *mb,int index) +{ +int n; +uint32_t val; + +assert (mb->count >0 ); +assert (index < mb->count); + + val = mb->reg[index]; +for (n = index +1 ; n < mb->count; n++) { + mb->reg[n -1 ] = mb->reg[n]; + } + mb->count--; + mb->reg[mb->count] =MBOX_INVALID_DATA ; + +mbox_update_status (mb); + +return val;
hw/misc/bcm2835_sbm.c line 61
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+} + +static void mbox_push (BCM2835Mbox *mb,uint32_t val) +{ +assert (mb->count <MBOX_SIZE ); + mb->reg[mb->count++] = val; +mbox_update_status (mb); +} + +static void bcm2835_sbm_update (BCM2835SbmState *s)
What does Sbm stand for? If it is acronym is should be all caps in camel case.
hw/misc/bcm2835_sbm.c line 63
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+{ +int set;
bool.
hw/misc/bcm2835_sbm.c line 75
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+int done, n; +uint32_t value; + +/* Avoid unwanted recursive calls */ + s->mbox_irq_disabled =1 ; + +/* Get pending responses and put them in the vc->arm mbox */ + done =0 ; +while (!done) { + done =1 ; +if (s->mbox[0 ].status &ARM_MS_FULL ) { +/* vc->arm mbox full, exit */
break here.
hw/misc/bcm2835_sbm.c line 76
Quoted 1 line
hw/misc/bcm2835_sbm.c new file +1
-0+ }else {
so you can drop the else and get back a level of indent.
hw/misc/bcm2835_sbm.c line 83
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { +if (s->available[n]) { + value =ldl_phys (&s->mbox_as, n<<4 ); +if (value !=MBOX_INVALID_DATA ) { +mbox_push (&s->mbox[0 ], value); + }else { +/* Hmmm... */
Needs more comment :)
Quoted 8 lines
hw/misc/bcm2835_sbm.c new file +8
-0+ } + done =0 ; +break ; + } + } + } + } +
hw/misc/bcm2835_sbm.c line 101
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+/* Try to push pending requests from the arm->vc mbox */ +/* TODO (?) */ + +/* Re-enable calls from the IRQ routine */ + s->mbox_irq_disabled =0 ; + +/* Update ARM IRQ status */ + set =0 ; +if (s->mbox[0 ].status &ARM_MS_EMPTY ) { + s->mbox[0 ].config &= ~ARM_MC_IHAVEDATAIRQPEND ;
This can also be reduced to just if (no else), by always clearing ARM_MC_IHAVEDATAIRQPEND. This makes it consistent with the way you handle set.
hw/misc/bcm2835_sbm.c line 113
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+ }else { + s->mbox[0 ].config |=ARM_MC_IHAVEDATAIRQPEND ; +if (s->mbox[0 ].config &ARM_MC_IHAVEDATAIRQEN ) { + set =1 ; + } + } +qemu_set_irq (s->arm_irq, set); +} + +static void bcm2835_sbm_set_irq (void *opaque,int irq,int level) +{ +BCM2835SbmState *s = (BCM2835SbmState *)opaque;
Blank line. No cast needed.
hw/misc/bcm2835_sbm.c line 115
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+ s->available[irq] = level; +if (!s->mbox_irq_disabled) {
I don't think you need this. IO devices are not thread safe and core-code knows it. So you don't need to worry about interruption and re-entry of your IRQ handler.
hw/misc/bcm2835_sbm.c line 123
Quoted 8 lines
hw/misc/bcm2835_sbm.c new file +8
-0+bcm2835_sbm_update (s); + } +} + +static uint64_t bcm2835_sbm_read (void *opaque,hwaddr offset, +unsigned size) +{ +BCM2835SbmState *s = (BCM2835SbmState *)opaque;
cast.
hw/misc/bcm2835_sbm.c line 132
Quoted 9 lines
hw/misc/bcm2835_sbm.c new file +9
-0+uint32_t res =0 ; + + offset &=0xff ; + +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :
case 0x80..0x8c
Quoted 41 lines
hw/misc/bcm2835_sbm.c new file +41
-0+if (s->mbox[0 ].status &ARM_MS_EMPTY ) { + res =MBOX_INVALID_DATA ; + }else { + res =mbox_pull (&s->mbox[0 ],0 ); + } +break ; +case 0x90 :/* MAIL0_PEEK */ + res = s->mbox[0 ].reg[0 ]; +break ; +case 0x94 :/* MAIL0_SENDER */ +break ; +case 0x98 :/* MAIL0_STATUS */ + res = s->mbox[0 ].status; +break ; +case 0x9c :/* MAIL0_CONFIG */ + res = s->mbox[0 ].config; +break ; +case 0xb8 :/* MAIL1_STATUS */ + res = s->mbox[1 ].status; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"bcm2835_sbm_read: Bad offset %x\n" , (int )offset); +return 0 ; + } + +bcm2835_sbm_update (s); + +return res; +} + +static void bcm2835_sbm_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +int ch; + +BCM2835SbmState *s = (BCM2835SbmState *)opaque; + + offset &=0xff ; + +switch (offset) {
hw/misc/bcm2835_sbm.c line 183
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+case 0x94 :/* MAIL0_SENDER */ +break ; +case 0x9c :/* MAIL0_CONFIG */ + s->mbox[0 ].config &= ~ARM_MC_IHAVEDATAIRQEN ; + s->mbox[0 ].config |= value &ARM_MC_IHAVEDATAIRQEN ; +break ; +case 0xa0 : +case 0xa4 : +case 0xa8 : +case 0xac :
case ...
hw/misc/bcm2835_sbm.c line 185
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+if (s->mbox[1 ].status &ARM_MS_FULL ) { +/* Guest error */
LOG_GUEST_ERROR.
hw/misc/bcm2835_sbm.c line 189
Quoted 4 lines
hw/misc/bcm2835_sbm.c new file +4
-0+ }else { + ch = value &0xf ; +if (ch <MBOX_CHAN_COUNT ) { +if (ldl_phys (&s->mbox_as, (ch<<4 ) +4 )) {
What is significance of memory offset +4? Can you have some macros for this for some hints as to what the functionality is?
hw/misc/bcm2835_sbm.c line 196
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+/* Push delayed, push it in the arm->vc mbox */ +mbox_push (&s->mbox[1 ], value); + }else { +stl_phys (&s->mbox_as, ch<<4 , value); + } + }else { +/* Invalid channel number */
LOG_GUEST_ERROR.
Quoted 5 lines
hw/misc/bcm2835_sbm.c new file +5
-0+ } + } +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR,
hw/misc/bcm2835_sbm.c line 211
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+ "bcm2835_sbm_write: Bad offset %x\n", (int)offset); +return ; + } + +bcm2835_sbm_update (s); +} + +static const MemoryRegionOps bcm2835_sbm_ops = { + .read = bcm2835_sbm_read, + .write = bcm2835_sbm_write,
Add access restrictions.
hw/misc/bcm2835_sbm.c line 220
Quoted 9 lines
hw/misc/bcm2835_sbm.c new file +9
-0+ .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static const VMStateDescription vmstate_bcm2835_sbm = { + .name =TYPE_BCM2835_SBM , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) {
Is the state missing?
Quoted 14 lines
hw/misc/bcm2835_sbm.c new file +14
-0+ VMSTATE_END_OF_LIST() + } +}; + +static void bcm2835_sbm_init (Object *obj) +{ +BCM2835SbmState *s =BCM2835_SBM (obj); +memory_region_init_io (&s->iomem, obj, &bcm2835_sbm_ops, s, +TYPE_BCM2835_SBM ,0x400 ); +sysbus_init_mmio (SYS_BUS_DEVICE (s), &s->iomem); +sysbus_init_irq (SYS_BUS_DEVICE (s), &s->arm_irq); +qdev_init_gpio_in (DEVICE (s), bcm2835_sbm_set_irq,MBOX_CHAN_COUNT ); +} +
hw/misc/bcm2835_sbm.c line 244
Quoted 10 lines
hw/misc/bcm2835_sbm.c new file +10
-0+static void bcm2835_sbm_realize (DeviceState *dev,Error **errp) +{ +int n; +BCM2835SbmState *s =BCM2835_SBM (dev); +Object *obj; +Error *err =NULL ; + + obj =object_property_get_link (OBJECT (dev),"mbox_mr" , &err); +if (err || obj ==NULL ) { +error_setg (errp,"bcm2835_sbm: required mbox_mr link not found" );
Propagate the original error along with this new mesage. %s with error_get_pretty(err) can do this.
hw/misc/bcm2835_sbm.c line 256
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+return ; + } + + s->mbox_mr =MEMORY_REGION (obj); +address_space_init (&s->mbox_as, s->mbox_mr,NULL ); + +mbox_init (&s->mbox[0 ]); +mbox_init (&s->mbox[1 ]); + s->mbox_irq_disabled =0 ; +for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { + s->available[n] =0 ; + }
This looks like reset behaviour, and should be moved into dc->reset callback.
Quoted 200 lines
hw/misc/bcm2835_sbm.c new file +24
-0+} + +static void bcm2835_sbm_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = bcm2835_sbm_realize; + dc->vmsd = &vmstate_bcm2835_sbm; +} + +static TypeInfo bcm2835_sbm_info = { + .name =TYPE_BCM2835_SBM , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (BCM2835SbmState), + .class_init = bcm2835_sbm_class_init, + .instance_init = bcm2835_sbm_init, +}; + +static void bcm2835_sbm_register_types (void ) +{ +type_register_static (&bcm2835_sbm_info); +} + +type_init (bcm2835_sbm_register_types)include/hw/arm/bcm2835_arm_control.h new file +170
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h +* +* Copyright (C) 2010 Broadcom +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef BCM2708_ARM_CONTROL_H_ +#define BCM2708_ARM_CONTROL_H_ + +/* +* Definitions and addresses for the ARM CONTROL logic +* This file is manually generated. +*/ + +#define ARM_BASE 0x7E00B000 + +/* Basic configuration */ +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000) +#define ARM_C0_SIZ128M 0x00000000 +#define ARM_C0_SIZ256M 0x00000001 +#define ARM_C0_SIZ512M 0x00000002 +#define ARM_C0_SIZ1G 0x00000003 +#define ARM_C0_BRESP0 0x00000000 +#define ARM_C0_BRESP1 0x00000004 +#define ARM_C0_BRESP2 0x00000008 +#define ARM_C0_BOOTHI 0x00000010 +#define ARM_C0_UNUSED05 0x00000020/* free */ +#define ARM_C0_FULLPERI 0x00000040 +#define ARM_C0_UNUSED78 0x00000180/* free */ +#define ARM_C0_JTAGMASK 0x00000E00 +#define ARM_C0_JTAGOFF 0x00000000 +#define ARM_C0_JTAGBASH 0x00000800/* Debug on GPIO off */ +#define ARM_C0_JTAGGPIO 0x00000C00/* Debug on GPIO on */ +#define ARM_C0_APROTMSK 0x0000F000 +#define ARM_C0_DBG0SYNC 0x00010000/* VPU0 halt sync */ +#define ARM_C0_DBG1SYNC 0x00020000/* VPU1 halt sync */ +#define ARM_C0_SWDBGREQ 0x00040000/* HW debug request */ +#define ARM_C0_PASSHALT 0x00080000/* ARM halt passed to debugger */ +#define ARM_C0_PRIO_PER 0x00F00000/* per priority mask */ +#define ARM_C0_PRIO_L2 0x0F000000 +#define ARM_C0_PRIO_UC 0xF0000000 + +#define ARM_C0_APROTPASS 0x0000A000/* Translate 1:1 */ +#define ARM_C0_APROTUSER 0x00000000/* Only user mode */ +#define ARM_C0_APROTSYST 0x0000F000/* Only system mode */ + + +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440) +#define ARM_C1_TIMER 0x00000001/* re-route timer IRQ to VC */ +#define ARM_C1_MAIL 0x00000002/* re-route Mail IRQ to VC */ +#define ARM_C1_BELL0 0x00000004/* re-route Doorbell 0 to VC */ +#define ARM_C1_BELL1 0x00000008/* re-route Doorbell 1 to VC */ +#define ARM_C1_PERSON 0x00000100/* peripherals on */ +#define ARM_C1_REQSTOP 0x00000200/* ASYNC bridge request stop */ + +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444) +#define ARM_S_ACKSTOP 0x80000000/* Bridge stopped */ +#define ARM_S_READPEND 0x000003FF/* pending reads counter */ +#define ARM_S_WRITPEND 0x000FFC00/* pending writes counter */ + +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448) +#define ARM_EH_PERIBURST 0x00000001/* Burst write seen on peri bus */ +#define ARM_EH_ILLADDRS1 0x00000002/* Address bits 25-27 error */ +#define ARM_EH_ILLADDRS2 0x00000004/* Address bits 31-28 error */ +#define ARM_EH_VPU0HALT 0x00000008/* VPU0 halted & in debug mode */ +#define ARM_EH_VPU1HALT 0x00000010/* VPU1 halted & in debug mode */ +#define ARM_EH_ARMHALT 0x00000020/* ARM in halted debug mode */ + +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C) +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C) +#define ARM_IDVAL 0x364D5241 + +/* Translation memory */ +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100) +/* 32 locations: 0x100.. 0x17F */ +/* 32 spare means we CAN go to 64 pages.... */ + + +/* Interrupts */ +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200)/* Top IRQ bits */ +#define ARM_I0_TIMER 0x00000001/* timer IRQ */ +#define ARM_I0_MAIL 0x00000002/* Mail IRQ */ +#define ARM_I0_BELL0 0x00000004/* Doorbell 0 */ +#define ARM_I0_BELL1 0x00000008/* Doorbell 1 */ +#define ARM_I0_BANK1 0x00000100/* Bank1 IRQ */ +#define ARM_I0_BANK2 0x00000200/* Bank2 IRQ */ + +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204)/* All bank1 IRQ bits */ +/* todo: all I1_interrupt sources */ +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208)/* All bank2 IRQ bits */ +/* todo: all I2_interrupt sources */ + +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C)/* FIQ control */ +#define ARM_IF_INDEX 0x0000007F/* FIQ select */ +#define ARM_IF_ENABLE 0x00000080/* FIQ enable */ +#define ARM_IF_VCMASK 0x0000003F/* FIQ = (index from VC source) */ +#define ARM_IF_TIMER 0x00000040/* FIQ = ARM timer */ +#define ARM_IF_MAIL 0x00000041/* FIQ = ARM Mail */ +#define ARM_IF_BELL0 0x00000042/* FIQ = ARM Doorbell 0 */ +#define ARM_IF_BELL1 0x00000043/* FIQ = ARM Doorbell 1 */ +#define ARM_IF_VP0HALT 0x00000044/* FIQ = VPU0 Halt seen */ +#define ARM_IF_VP1HALT 0x00000045/* FIQ = VPU1 Halt seen */ +#define ARM_IF_ILLEGAL 0x00000046/* FIQ = Illegal access seen */ + +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210)/* Bank1 enable bits */ +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214)/* Bank2 enable bits */ +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218)/* ARM irqs enable bits */ +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C)/* Bank1 disable bits */ +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220)/* Bank2 disable bits */ +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224)/* ARM irqs disable bits */ +#define ARM_IE_TIMER 0x00000001/* Timer IRQ */ +#define ARM_IE_MAIL 0x00000002/* Mail IRQ */ +#define ARM_IE_BELL0 0x00000004/* Doorbell 0 */ +#define ARM_IE_BELL1 0x00000008/* Doorbell 1 */ +#define ARM_IE_VP0HALT 0x00000010/* VPU0 Halt */ +#define ARM_IE_VP1HALT 0x00000020/* VPU1 Halt */ +#define ARM_IE_ILLEGAL 0x00000040/* Illegal access seen */ + +/* Timer */ +/* For reg. fields see sp804 spec. */ +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400) +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404) +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408) +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C) +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410) +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414) +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418) +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c) +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420) + +#define TIMER_CTRL_ONESHOT (1 << 0) +#define TIMER_CTRL_32BIT (1 << 1) +#define TIMER_CTRL_DIV1 (0 << 2) +#define TIMER_CTRL_DIV16 (1 << 2) +#define TIMER_CTRL_DIV256 (2 << 2) +#define TIMER_CTRL_IE (1 << 5) +#define TIMER_CTRL_PERIODIC (1 << 6) +#define TIMER_CTRL_ENABLE (1 << 7) +#define TIMER_CTRL_DBGHALT (1 << 8) +#define TIMER_CTRL_ENAFREE (1 << 9) +#define TIMER_CTRL_FREEDIV_SHIFT 16) +#define TIMER_CTRL_FREEDIV_MASK 0xff + +/* Semaphores, Doorbells, Mailboxes */ +#define ARM_SBM_OWN0 (ARM_BASE+0x800) +#define ARM_SBM_OWN1 (ARM_BASE+0x900) +#define ARM_SBM_OWN2 (ARM_BASE+0xA00) +#define ARM_SBM_OWN3 (ARM_BASE+0xB00) + +/* MAILBOXES +* Register flags are common across all +* owner registers. See end of this section +* +* Semaphores, Doorbells, Mailboxes Owner 0 +* +*/
include/hw/arm/bcm2835_arm_control.h line 180
Quoted 10 lines
include/hw/arm/bcm2835_arm_control.h new file +10
-0+ +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00) +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00) +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04) +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08) +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C) +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10) +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14) +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18) +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
When you have a regular structure like this, you should collapse it down using some arithmatic:
#define ARM_0_SEM(x) HW_REGISTER_RW(ARM_SBM_OWN0 + 0x4 * (x))
include/hw/arm/bcm2835_arm_control.h line 184
Quoted 4 lines
include/hw/arm/bcm2835_arm_control.h new file +4
-0+#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40) +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44) +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48) +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
Here as well.
Quoted 42 lines
include/hw/arm/bcm2835_arm_control.h new file +42
-0+/* MAILBOX 0 access in Owner 0 area */ +/* Some addresses should ONLY be used by owner 0 */ +#define ARM_0_MAIL0_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x80)/* .. 0x8C (4 locations) */ +#define ARM_0_MAIL0_RD \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x80)/* .. 0x8C (4 locs) Normal read */ +#define ARM_0_MAIL0_POL \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x90)/* none-pop read */ +#define ARM_0_MAIL0_SND \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x94)/* Sender read (only LS 2 bits) */ +#define ARM_0_MAIL0_STA \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x98)/* Status read */ +#define ARM_0_MAIL0_CNF \ + HW_REGISTER_RW(ARM_SBM_OWN0+0x9C)/* Config read/write */ +/* MAILBOX 1 access in Owner 0 area */ +/* Owner 0 should only WRITE to this mailbox */ +#define ARM_0_MAIL1_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xA0)/* .. 0xAC (4 locations) */ +/*#define ARM_0_MAIL1_RD \ +HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_0_MAIL1_POL \ +HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_0_MAIL1_SND \ +HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */ +#define ARM_0_MAIL1_STA \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xB8)/* Status read */ +/*#define ARM_0_MAIL1_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */ +/* General SEM, BELL, MAIL config/status */ +#define ARM_0_SEMCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xE0)/* semaphore clear/debug register */ +#define ARM_0_BELLCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xE4)/* Doorbells clear/debug register */ +#define ARM_0_ALL_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xF8)/* ALL interrupts */ +#define ARM_0_MY_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN0+0xFC)/* IRQS pending for owner 0 */ + +/* Semaphores, Doorbells, Mailboxes Owner 1 */ +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00) +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00) +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
include/hw/arm/bcm2835_arm_control.h line 236
Quoted 10 lines
include/hw/arm/bcm2835_arm_control.h new file +10
-0+#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08) +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C) +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10) +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14) +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18) +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C) +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40) +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44) +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48) +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
You have large repeitition between ARM_0 and ARM_1, should also be collapased using Macros args. It is however generally rare to need to have the individual defs for each window of a regular structure, as the switch case logic that implements the functionality, is also usually regular and just uses math on addresses to figure out what to index, rather than fully defining the address map.
Quoted 161 lines
include/hw/arm/bcm2835_arm_control.h new file +161
-0+/* MAILBOX 0 access in Owner 0 area */ +/* Owner 1 should only WRITE to this mailbox */ +#define ARM_1_MAIL0_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN1+0x80)/* .. 0x8C (4 locations) */ +/*#define ARM_1_MAIL0_RD \ +HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_1_MAIL0_POL \ +HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_1_MAIL0_SND \ +HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */ +#define ARM_1_MAIL0_STA \ + HW_REGISTER_RW(ARM_SBM_OWN1+0x98)/* Status read */ +/*#define ARM_1_MAIL0_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */ +/* MAILBOX 1 access in Owner 0 area */ +#define ARM_1_MAIL1_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xA0)/* .. 0xAC (4 locations) */ +#define ARM_1_MAIL1_RD \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xA0)/* .. 0xAC (4 locs) Normal read */ +#define ARM_1_MAIL1_POL \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xB0)/* none-pop read */ +#define ARM_1_MAIL1_SND \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xB4)/* Sender read (only LS 2 bits) */ +#define ARM_1_MAIL1_STA \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xB8)/* Status read */ +#define ARM_1_MAIL1_CNF \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xBC) +/* General SEM, BELL, MAIL config/status */ +#define ARM_1_SEMCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xE0)/* semaphore clear/debug register */ +#define ARM_1_BELLCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xE4)/* Doorbells clear/debug register */ +#define ARM_1_MY_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xFC)/* IRQS pending for owner 1 */ +#define ARM_1_ALL_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN1+0xF8)/* ALL interrupts */ + +/* Semaphores, Doorbells, Mailboxes Owner 2 */ +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00) +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00) +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04) +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08) +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C) +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10) +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14) +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18) +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C) +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40) +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44) +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48) +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C) +/* MAILBOX 0 access in Owner 2 area */ +/* Owner 2 should only WRITE to this mailbox */ +#define ARM_2_MAIL0_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN2+0x80)/* .. 0x8C (4 locations) */ +/*#define ARM_2_MAIL0_RD \ +HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_2_MAIL0_POL \ +HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_2_MAIL0_SND \ +HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */ +#define ARM_2_MAIL0_STA \ + HW_REGISTER_RW(ARM_SBM_OWN2+0x98)/* Status read */ +/*#define ARM_2_MAIL0_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */ +/* MAILBOX 1 access in Owner 2 area */ +/* Owner 2 should only WRITE to this mailbox */ +#define ARM_2_MAIL1_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xA0)/* .. 0xAC (4 locations) */ +/*#define ARM_2_MAIL1_RD \ +HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_2_MAIL1_POL \ +HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_2_MAIL1_SND \ +HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */ +#define ARM_2_MAIL1_STA \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xB8)/* Status read */ +/*#define ARM_2_MAIL1_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */ +/* General SEM, BELL, MAIL config/status */ +#define ARM_2_SEMCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xE0)/* semaphore clear/debug register */ +#define ARM_2_BELLCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xE4)/* Doorbells clear/debug register */ +#define ARM_2_MY_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xFC)/* IRQS pending for owner 2 */ +#define ARM_2_ALL_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN2+0xF8)/* ALL interrupts */ + +/* Semaphores, Doorbells, Mailboxes Owner 3 */ +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00) +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00) +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04) +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08) +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C) +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10) +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14) +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18) +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C) +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40) +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44) +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48) +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C) +/* MAILBOX 0 access in Owner 3 area */ +/* Owner 3 should only WRITE to this mailbox */ +#define ARM_3_MAIL0_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN3+0x80)/* .. 0x8C (4 locations) */ +/*#define ARM_3_MAIL0_RD \ +HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_3_MAIL0_POL \ +HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_3_MAIL0_SND \ +HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */ +#define ARM_3_MAIL0_STA \ + HW_REGISTER_RW(ARM_SBM_OWN3+0x98)/* Status read */ +/*#define ARM_3_MAIL0_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */ +/* MAILBOX 1 access in Owner 3 area */ +/* Owner 3 should only WRITE to this mailbox */ +#define ARM_3_MAIL1_WRT \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xA0)/* .. 0xAC (4 locations) */ +/*#define ARM_3_MAIL1_RD \ +HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_3_MAIL1_POL \ +HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */ +/*#define ARM_3_MAIL1_SND \ +HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */ +#define ARM_3_MAIL1_STA \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xB8)/* Status read */ +/*#define ARM_3_MAIL1_CNF \ +HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */ +/* General SEM, BELL, MAIL config/status */ +#define ARM_3_SEMCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xE0)/* semaphore clear/debug register */ +#define ARM_3_BELLCLRDBG \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xE4)/* Doorbells clear/debug register */ +#define ARM_3_MY_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xFC)/* IRQS pending for owner 3 */ +#define ARM_3_ALL_IRQS \ + HW_REGISTER_RW(ARM_SBM_OWN3+0xF8)/* ALL interrupts */ + +/* Mailbox flags. Valid for all owners */ + +/* Mailbox status register (...0x98) */ +#define ARM_MS_FULL 0x80000000 +#define ARM_MS_EMPTY 0x40000000 +#define ARM_MS_LEVEL 0x400000FF/* Max. value depends on mailbox depth */ + +/* MAILBOX config/status register (...0x9C) */ +/* ANY write to this register clears the error bits! */ +#define ARM_MC_IHAVEDATAIRQEN 0x00000001/* mbox irq enable: has data */ +#define ARM_MC_IHAVESPACEIRQEN 0x00000002/* mbox irq enable: has space */ +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004/* mbox irq enable: Opp is empty */ +#define ARM_MC_MAIL_CLEAR 0x00000008/* mbox clear write 1, then 0 */ +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010/* mbox irq pending: has space */ +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020/* mbox irq pending: Opp is empty */ +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040/* mbox irq pending */ +/* Bit 7 is unused */ +#define ARM_MC_ERRNOOWN 0x00000100/* error : none owner read from mailbox */ +#define ARM_MC_ERROVERFLW 0x00000200/* error : write to fill mailbox */ +#define ARM_MC_ERRUNDRFLW 0x00000400/* error : read from empty mailbox */
include/hw/arm/bcm2835_arm_control.h line 407
Quoted 10 lines
include/hw/arm/bcm2835_arm_control.h new file +10
-0+ +/* Semaphore clear/debug register (...0xE0) */ +#define ARM_SD_OWN0 0x00000003/* Owner of sem 0 */ +#define ARM_SD_OWN1 0x0000000C/* Owner of sem 1 */ +#define ARM_SD_OWN2 0x00000030/* Owner of sem 2 */ +#define ARM_SD_OWN3 0x000000C0/* Owner of sem 3 */ +#define ARM_SD_OWN4 0x00000300/* Owner of sem 4 */ +#define ARM_SD_OWN5 0x00000C00/* Owner of sem 5 */ +#define ARM_SD_OWN6 0x00003000/* Owner of sem 6 */ +#define ARM_SD_OWN7 0x0000C000/* Owner of sem 7 */
Regular structure.
include/hw/arm/bcm2835_arm_control.h line 416
Quoted 9 lines
include/hw/arm/bcm2835_arm_control.h new file +9
-0+#define ARM_SD_SEM0 0x00010000/* Status of sem 0 */ +#define ARM_SD_SEM1 0x00020000/* Status of sem 1 */ +#define ARM_SD_SEM2 0x00040000/* Status of sem 2 */ +#define ARM_SD_SEM3 0x00080000/* Status of sem 3 */ +#define ARM_SD_SEM4 0x00100000/* Status of sem 4 */ +#define ARM_SD_SEM5 0x00200000/* Status of sem 5 */ +#define ARM_SD_SEM6 0x00400000/* Status of sem 6 */ +#define ARM_SD_SEM7 0x00800000/* Status of sem 7 */ +
Regular structure. More below.
Quoted 105 lines
include/hw/arm/bcm2835_arm_control.h new file +65
-0+/* Doorbells clear/debug register (...0xE4) */ +#define ARM_BD_OWN0 0x00000003/* Owner of doorbell 0 */ +#define ARM_BD_OWN1 0x0000000C/* Owner of doorbell 1 */ +#define ARM_BD_OWN2 0x00000030/* Owner of doorbell 2 */ +#define ARM_BD_OWN3 0x000000C0/* Owner of doorbell 3 */ +#define ARM_BD_BELL0 0x00000100/* Status of doorbell 0 */ +#define ARM_BD_BELL1 0x00000200/* Status of doorbell 1 */ +#define ARM_BD_BELL2 0x00000400/* Status of doorbell 2 */ +#define ARM_BD_BELL3 0x00000800/* Status of doorbell 3 */ + +/* MY IRQS register (...0xF8) */ +#define ARM_MYIRQ_BELL 0x00000001/* This owner has a doorbell IRQ */ +#define ARM_MYIRQ_MAIL 0x00000002/* This owner has a mailbox IRQ */ + +/* ALL IRQS register (...0xF8) */ +#define ARM_AIS_BELL0 0x00000001/* Doorbell 0 IRQ pending */ +#define ARM_AIS_BELL1 0x00000002/* Doorbell 1 IRQ pending */ +#define ARM_AIS_BELL2 0x00000004/* Doorbell 2 IRQ pending */ +#define ARM_AIS_BELL3 0x00000008/* Doorbell 3 IRQ pending */ +#define ARM_AIS0_HAVEDATA 0x00000010/* MAIL 0 has data IRQ pending */ +#define ARM_AIS0_HAVESPAC 0x00000020/* MAIL 0 has space IRQ pending */ +#define ARM_AIS0_OPPEMPTY 0x00000040/* MAIL 0 opposite is empty IRQ */ +#define ARM_AIS1_HAVEDATA 0x00000080/* MAIL 1 has data IRQ pending */ +#define ARM_AIS1_HAVESPAC 0x00000100/* MAIL 1 has space IRQ pending */ +#define ARM_AIS1_OPPEMPTY 0x00000200/* MAIL 1 opposite is empty IRQ */ +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */ +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */ +/* */ +/* ARM JTAG BASH */ +/* */ +#define AJB_BASE 0x7e2000c0 + +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00) +#define AJB_BITS0 0x000000 +#define AJB_BITS4 0x000004 +#define AJB_BITS8 0x000008 +#define AJB_BITS12 0x00000C +#define AJB_BITS16 0x000010 +#define AJB_BITS20 0x000014 +#define AJB_BITS24 0x000018 +#define AJB_BITS28 0x00001C +#define AJB_BITS32 0x000020 +#define AJB_BITS34 0x000022 +#define AJB_OUT_MS 0x000040 +#define AJB_OUT_LS 0x000000 +#define AJB_INV_CLK 0x000080 +#define AJB_D0_RISE 0x000100 +#define AJB_D0_FALL 0x000000 +#define AJB_D1_RISE 0x000200 +#define AJB_D1_FALL 0x000000 +#define AJB_IN_RISE 0x000400 +#define AJB_IN_FALL 0x000000 +#define AJB_ENABLE 0x000800 +#define AJB_HOLD0 0x000000 +#define AJB_HOLD1 0x001000 +#define AJB_HOLD2 0x002000 +#define AJB_HOLD3 0x003000 +#define AJB_RESETN 0x004000 +#define AJB_CLKSHFT 16 +#define AJB_BUSY 0x80000000 +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04) +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08) +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c) + +#endif include/hw/arm/bcm2835_mbox.h new file +19
-0@@ -0,0 +1,19 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_MBOX_H +#define BCM2835_MBOX_H + +/* Constants shared with the ARM identifying separate mailbox channels */ +#define MBOX_CHAN_POWER 0/* for use by the power management interface */ +#define MBOX_CHAN_FB 1/* for use by the frame buffer */ +#define MBOX_CHAN_VCHIQ 3/* for use by the VCHIQ interface */ +#define MBOX_CHAN_PROPERTY 8/* for use by the property channel */ +#define MBOX_CHAN_COUNT 9 + +#define MBOX_SIZE 32 +#define MBOX_INVALID_DATA 0x0f + +#endif /* BCM2835_MBOX_H */ include/hw/misc/bcm2835_sbm.h new file +9
-0@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h"
include/hw/misc/bcm2835_sbm.h line 19
Quoted 10 lines
include/hw/misc/bcm2835_sbm.h new file +10
-0+#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM (obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct { + MemoryRegion *mbox_mr; + AddressSpace mbox_as;
I can't see where these two fields are used. A quick scan shows that the SbmState's copy is uses for all DMA ops. If these are needed, mbox_init should pass a pointer to the the SbmState then this saves the pointer and navigates as needed back to the container structure to get the AS.
include/hw/misc/bcm2835_sbm.h line 26
Quoted 7 lines
include/hw/misc/bcm2835_sbm.h new file +7
-0+uint32_t reg[MBOX_SIZE ]; +int count; +uint32_t status; +uint32_t config; +} BCM2835Mbox; + +typedef struct {
/*< private >*/
include/hw/misc/bcm2835_sbm.h line 27
Quoted 1 line
include/hw/misc/bcm2835_sbm.h new file +1
-0+SysBusDevice busdev;
/*< public >*/
Regards,
Peter
Quoted 13 lines
include/hw/misc/bcm2835_sbm.h new file +10
-1+MemoryRegion *mbox_mr; +AddressSpace mbox_as; +MemoryRegion iomem; +int mbox_irq_disabled; +qemu_irq arm_irq; +int available[MBOX_CHAN_COUNT ]; + BCM2835Mbox mbox[2]; +} BCM2835SbmState; + +#endif --2.5.3
Re: [Qemu-devel] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
Hi Peter,
Thanks for the review!
Quoted 13 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 14:49Quoted 8 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Signed-off-by Andrew Baumann <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++
Quoted 4 lines
Quoted 1 line
include/hw/arm/bcm2835_arm_control.h | 481+++++++++++++++++++++++++++++++++++
Do we need this file as of this patch?
Yes, for ARM_MC_IHAVEDATAIRQEN and other related defines.
[...]
Quoted 3 lines
Quoted 1 line
+static void
bcm2835_sbm_update(BCM2835SbmState *s)What does Sbm stand for? If it is acronym is should be all caps in camel case.
I'm not sure -- it comes from Gregory's code; maybe he can comment? Where this device gets instantiated, there is a comment of
/* Semaphores / Doorbells / Mailboxes */
... but only mailboxes are implemented here. I'm guessing maybe it's intended as "system mailboxes". I can rename it.
Quoted 32 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + int set;bool.
hw/misc/bcm2835_sbm.c line 75
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+int done, n; +uint32_t value; + +/* Avoid unwanted recursive calls */ + s->mbox_irq_disabled =1 ; + +/* Get pending responses and put them in the vc->arm mbox */ + done =0 ; +while (!done) { + done =1 ; +if (s->mbox[0 ].status &ARM_MS_FULL ) { +/* vc->arm mbox full, exit */ break here.
Quoted 1 line
+ } else {
so you can drop the else and get back a level of indent.
hw/misc/bcm2835_sbm.c line 83
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { +if (s->available[n]) { + value =ldl_phys (&s->mbox_as, n<<4 ); +if (value !=MBOX_INVALID_DATA ) { +mbox_push (&s->mbox[0 ], value); + }else { +/* Hmmm... */
Quoted 1 line
Needs more comment :)
Gregory -- help! :)
[...]
Quoted 6 lines
hw/misc/bcm2835_sbm.c line 115
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+ s->available[irq] = level; +if (!s->mbox_irq_disabled) {I don't think you need this. IO devices are not thread safe and core-code knows it. So you don't need to worry about interruption and re-entry of your IRQ handler.
I will have to put a debugger on this to confirm, but I think the issue is that we are using a private memory region and GPIOs to route mailbox data and interrupts to the relevant sub peripherals. The ldl_phys invokes another device emulation (such as bcm2835_property.c in this series), which may cause it to signal an interrupt back to us via qemu_set_irq which will recursively run our handler. We want that IRQ to be recorded but "squashed".
[...]
Quoted 8 lines
hw/misc/bcm2835_sbm.c line 132
Quoted 6 lines
hw/misc/bcm2835_sbm.c new file +6
-0+ +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :case 0x80..0x8c
Woah! Is that standard C?
[...]
Quoted 5 lines
Quoted 5 lines
include/hw/arm/bcm2835_arm_control.h new file +2
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h
[...]
Quoted 2 lines
When you have a regular structure like this, you should collapse it down using some arithmatic:
Notice that this file comes from Linux. I know it's not pretty, but can we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
Quoted 20 lines
Quoted 20 lines
include/hw/misc/bcm2835_sbm.h new file +17
-0@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM(obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct {
Quoted 8 lines
include/hw/misc/bcm2835_sbm.h line 19
Quoted 2 lines
include/hw/misc/bcm2835_sbm.h new file +2
-0+MemoryRegion *mbox_mr; +AddressSpace mbox_as;I can't see where these two fields are used. A quick scan shows that the SbmState's copy is uses for all DMA ops. If these are needed,
mbox_initshould pass a pointer to the the SbmState then this saves the pointer and navigates as needed back to the container structure to get the AS.
You're right. They're uninitialised/unused detritus from a previous refactor. I'll remove them.
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
Quoted 90 lines · Andrew Baumann
Hi Peter,
Thanks for the review!
Quoted 13 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 14:49Quoted 8 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Signed-off-by Andrew Baumann <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++Quoted 4 lines
Quoted 1 line
include/hw/arm/bcm2835_arm_control.h | 481+++++++++++++++++++++++++++++++++++
Do we need this file as of this patch?
Yes, for
ARM_MC_IHAVEDATAIRQENand other related defines.[...]
Quoted 3 lines
Quoted 1 line
+static void
bcm2835_sbm_update(BCM2835SbmState *s)What does Sbm stand for? If it is acronym is should be all caps in camel case.
I'm not sure -- it comes from Gregory's code; maybe he can comment? Where this device gets instantiated, there is a comment of
/* Semaphores / Doorbells / Mailboxes */
... but only mailboxes are implemented here. I'm guessing maybe it's intended as "system mailboxes". I can rename it.
Quoted 32 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + int set;bool.
hw/misc/bcm2835_sbm.c line 75
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+int done, n; +uint32_t value; + +/* Avoid unwanted recursive calls */ + s->mbox_irq_disabled =1 ; + +/* Get pending responses and put them in the vc->arm mbox */ + done =0 ; +while (!done) { + done =1 ; +if (s->mbox[0 ].status &ARM_MS_FULL ) { +/* vc->arm mbox full, exit */ break here.
Quoted 1 line
+ } else {
so you can drop the else and get back a level of indent.
hw/misc/bcm2835_sbm.c line 83
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { +if (s->available[n]) { + value =ldl_phys (&s->mbox_as, n<<4 ); +if (value !=MBOX_INVALID_DATA ) { +mbox_push (&s->mbox[0 ], value); + }else { +/* Hmmm... */ Quoted 1 line
Needs more comment :)
Gregory -- help! :)
[...]
Quoted 6 lines
hw/misc/bcm2835_sbm.c line 115
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+ s->available[irq] = level; +if (!s->mbox_irq_disabled) {I don't think you need this. IO devices are not thread safe and core-code knows it. So you don't need to worry about interruption and re-entry of your IRQ handler.
I will have to put a debugger on this to confirm, but I think the issue is that we are using a private memory region and GPIOs to route mailbox data and interrupts to the relevant sub peripherals. The
ldl_physinvokes another device emulation (such asbcm2835_property.cin this series), which may cause it to signal an interrupt back to us viaqemu_set_irqwhich will recursively run our handler. We want that IRQ to be recorded but "squashed".[...]
Quoted 7 lines
Quoted 6 lines
hw/misc/bcm2835_sbm.c new file +6
-0+ +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :
Quoted 4 lines
Quoted 1 line
case 0x80..0x8c
Woah! Is that standard C?
Yes, its probably one of the more recent language standards though. QEMU does use to more modern features liberally.
Quoted 7 lines
[...]
Quoted 5 lines
Quoted 5 lines
include/hw/arm/bcm2835_arm_control.h new file +2
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h [...]
Quoted 5 lines
Quoted 2 lines
When you have a regular structure like this, you should collapse it down using some arithmatic:
Notice that this file comes from Linux. I know it's not pretty, but can we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
It looks very autogenerated and seems pretty nasty on the repetition.
As implementers of the hardware, it is much rarer to need these repetitious defs than the software users on the other side. "Do something specific with CPU#3's Mbox#5" is going to appear in software, but hardware implementers generally don't have a choice to implement things specifically and it usually ends up being looped and the exploded defs are never used. If there are only a handful of genuinely single defs needed, can they be fished out?
Regards,
Peter
Quoted 33 lines
Quoted 20 lines
Quoted 20 lines
include/hw/misc/bcm2835_sbm.h new file +17
-0@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM(obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct {Quoted 8 lines
include/hw/misc/bcm2835_sbm.h line 19
Quoted 2 lines
include/hw/misc/bcm2835_sbm.h new file +2
-0+MemoryRegion *mbox_mr; +AddressSpace mbox_as;I can't see where these two fields are used. A quick scan shows that the SbmState's copy is uses for all DMA ops. If these are needed,
mbox_initshould pass a pointer to the the SbmState then this saves the pointer and navigates as needed back to the container structure to get the AS.You're right. They're uninitialised/unused detritus from a previous refactor. I'll remove them.
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Andrew BaumannHi,
The "sbm" is a typo. It was meant to be "smb": Semaphore MailBoxes... Sorry about that.
Regards,
Gregory
Quoted 151 lines · Andrew Baumann
Hi Peter,
Thanks for the review!
Quoted 13 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 14:49Quoted 8 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Signed-off-by Andrew Baumann <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++Quoted 4 lines
Quoted 1 line
include/hw/arm/bcm2835_arm_control.h | 481+++++++++++++++++++++++++++++++++++
Do we need this file as of this patch?
Yes, for
ARM_MC_IHAVEDATAIRQENand other related defines.[...]
Quoted 3 lines
Quoted 1 line
+static void
bcm2835_sbm_update(BCM2835SbmState *s)What does Sbm stand for? If it is acronym is should be all caps in camel
case.
I'm not sure -- it comes from Gregory's code; maybe he can comment? Where this device gets instantiated, there is a comment of
/* Semaphores / Doorbells / Mailboxes */
... but only mailboxes are implemented here. I'm guessing maybe it's intended as "system mailboxes". I can rename it.
Quoted 32 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+{ + int set;bool.
hw/misc/bcm2835_sbm.c line 75
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+int done, n; +uint32_t value; + +/* Avoid unwanted recursive calls */ + s->mbox_irq_disabled =1 ; + +/* Get pending responses and put them in the vc->arm mbox */ + done =0 ; +while (!done) { + done =1 ; +if (s->mbox[0 ].status &ARM_MS_FULL ) { +/* vc->arm mbox full, exit */ break here.
Quoted 1 line
+ } else {
so you can drop the else and get back a level of indent.
hw/misc/bcm2835_sbm.c line 83
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { +if (s->available[n]) { + value =ldl_phys (&s->mbox_as, n<<4 ); +if (value !=MBOX_INVALID_DATA ) { +mbox_push (&s->mbox[0 ], value); + }else { +/* Hmmm... */ Quoted 1 line
Needs more comment :)
Gregory -- help! :)
[...]
Quoted 6 lines
hw/misc/bcm2835_sbm.c line 115
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+ s->available[irq] = level; +if (!s->mbox_irq_disabled) {I don't think you need this. IO devices are not thread safe and core-code knows it. So you don't need to worry about interruption and re-entry of your IRQ handler.
I will have to put a debugger on this to confirm, but I think the issue is that we are using a private memory region and GPIOs to route mailbox data and interrupts to the relevant sub peripherals. The
ldl_physinvokes another device emulation (such asbcm2835_property.cin this series), which may cause it to signal an interrupt back to us viaqemu_set_irqwhich will recursively run our handler. We want that IRQ to be recorded but "squashed".[...]
Quoted 8 lines
hw/misc/bcm2835_sbm.c line 132
Quoted 6 lines
hw/misc/bcm2835_sbm.c new file +6
-0+ +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :case 0x80..0x8c
Woah! Is that standard C?
[...]
Quoted 5 lines
Quoted 5 lines
include/hw/arm/bcm2835_arm_control.h new file +2
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h [...]
Quoted 2 lines
When you have a regular structure like this, you should collapse it down using some arithmatic:
Notice that this file comes from Linux. I know it's not pretty, but can we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
Quoted 20 lines
Quoted 20 lines
include/hw/misc/bcm2835_sbm.h new file +17
-0@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM(obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct {Quoted 8 lines
include/hw/misc/bcm2835_sbm.h line 19
Quoted 2 lines
include/hw/misc/bcm2835_sbm.h new file +2
-0+MemoryRegion *mbox_mr; +AddressSpace mbox_as;I can't see where these two fields are used. A quick scan shows that the SbmState's copy is uses for all DMA ops. If these are needed,
mbox_initshould pass a pointer to the the SbmState then this saves the pointer and navigates as needed back to the container structure to get the AS.You're right. They're uninitialised/unused detritus from a previous refactor. I'll remove them.
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Peter CrosthwaiteIndeed, this header is generated from the Broadcom's Linux drivers headers, with a Perl script.
Quoted 171 lines · Peter Crosthwaite
Quoted 17 lines · Andrew Baumann
Hi Peter,
Thanks for the review!
Quoted 13 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 14:49Quoted 8 lines · Andrew Baumann
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
Signed-off-by Andrew Baumann <[email protected]>--- default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_sbm.c | 280 ++++++++++++++++++++Quoted 11 lines
Quoted 4 lines
Quoted 1 line
include/hw/arm/bcm2835_arm_control.h | 481+++++++++++++++++++++++++++++++++++
Do we need this file as of this patch?
Yes, for
ARM_MC_IHAVEDATAIRQENand other related defines.[...]
Quoted 3 lines
Quoted 1 line
+static void
bcm2835_sbm_update(BCM2835SbmState *s)What does Sbm stand for? If it is acronym is should be all caps in
camel case.
Quoted 2 lines
I'm not sure -- it comes from Gregory's code; maybe he can comment?
Where this device gets instantiated, there is a comment of
Quoted 4 lines
/* Semaphores / Doorbells / Mailboxes */
... but only mailboxes are implemented here. I'm guessing maybe it's
intended as "system mailboxes". I can rename it.
Quoted 39 lines
Quoted 34 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+{ + int set;bool.
hw/misc/bcm2835_sbm.c line 75
Quoted 12 lines
hw/misc/bcm2835_sbm.c new file +12
-0+int done, n; +uint32_t value; + +/* Avoid unwanted recursive calls */ + s->mbox_irq_disabled =1 ; + +/* Get pending responses and put them in the vc->arm mbox */ + done =0 ; +while (!done) { + done =1 ; +if (s->mbox[0 ].status &ARM_MS_FULL ) { +/* vc->arm mbox full, exit */ break here.
Quoted 1 line
+ } else {
so you can drop the else and get back a level of indent.
hw/misc/bcm2835_sbm.c line 83
Quoted 7 lines
hw/misc/bcm2835_sbm.c new file +7
-0+for (n =0 ; n <MBOX_CHAN_COUNT ; n++) { +if (s->available[n]) { + value =ldl_phys (&s->mbox_as, n<<4 ); +if (value !=MBOX_INVALID_DATA ) { +mbox_push (&s->mbox[0 ], value); + }else { +/* Hmmm... */ Quoted 1 line
Needs more comment :)
Gregory -- help! :)
[...]
Quoted 8 lines
Quoted 6 lines
hw/misc/bcm2835_sbm.c line 115
Quoted 2 lines
hw/misc/bcm2835_sbm.c new file +2
-0+ s->available[irq] = level; +if (!s->mbox_irq_disabled) {I don't think you need this. IO devices are not thread safe and core-code knows it. So you don't need to worry about interruption and re-entry of your IRQ handler.
I will have to put a debugger on this to confirm, but I think the issue
is that we are using a private memory region and GPIOs to route mailbox data and interrupts to the relevant sub peripherals. The
ldl_physinvokes another device emulation (such asbcm2835_property.cin this series), which may cause it to signal an interrupt back to us viaqemu_set_irqwhich will recursively run our handler. We want that IRQ to be recorded but "squashed".Quoted 9 lines
[...]
Quoted 7 lines
Quoted 6 lines
hw/misc/bcm2835_sbm.c new file +6
-0+ +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :Quoted 4 lines
Quoted 1 line
case 0x80..0x8c
Woah! Is that standard C?
Yes, its probably one of the more recent language standards though. QEMU does use to more modern features liberally.
Quoted 11 lines
[...]
Quoted 5 lines
Quoted 5 lines
include/hw/arm/bcm2835_arm_control.h new file +2
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h [...]
Quoted 2 lines
When you have a regular structure like this, you should collapse it down using some arithmatic:
Notice that this file comes from Linux. I know it's not pretty, but can
we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
Quoted 1 line
It looks very autogenerated and seems pretty nasty on the repetition.
As implementers of the hardware, it is much rarer to need these repetitious defs than the software users on the other side. "Do something specific with CPU#3's Mbox#5" is going to appear in software, but hardware implementers generally don't have a choice to implement things specifically and it usually ends up being looped and the exploded defs are never used. If there are only a handful of genuinely single defs needed, can they be fished out?
Regards,
PeterQuoted 29 lines
Quoted 20 lines
Quoted 20 lines
include/hw/misc/bcm2835_sbm.h new file +17
-0@@ -0,0 +1,37 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* This code is licensed under the GNU GPLv2 and later. +*/ + +#ifndef BCM2835_SBM_H +#define BCM2835_SBM_H + +#include "hw/sysbus.h" +#include "exec/address-spaces.h" +#include "hw/arm/bcm2835_mbox.h" + +#define TYPE_BCM2835_SBM "bcm2835_sbm" +#define BCM2835_SBM(obj) \ + OBJECT_CHECK(BCM2835SbmState, (obj), TYPE_BCM2835_SBM) + +typedef struct {Quoted 8 lines
include/hw/misc/bcm2835_sbm.h line 19
Quoted 2 lines
include/hw/misc/bcm2835_sbm.h new file +2
-0+MemoryRegion *mbox_mr; +AddressSpace mbox_as;I can't see where these two fields are used. A quick scan shows that the SbmState's copy is uses for all DMA ops. If these are needed,
mbox_initshould pass a pointer to the the SbmState then this saves the pointer and navigates as needed back to the container structure to get the AS.Quoted 1 line
You're right. They're uninitialised/unused detritus from a previous
refactor. I'll remove them.
Quoted 3 lines
Thanks,
Andrew
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Peter CrosthwaiteQuoted 15 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 15:33Quoted 11 lines · Andrew Baumann
Quoted 11 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Monday, 21 December 2015 14:49Quoted 6 lines · Andrew Baumann
hw/misc/bcm2835_sbm.c new file +6
-0+ +switch (offset) { +case 0x80 :/* MAIL0_READ */ +case 0x84 : +case 0x88 : +case 0x8c :
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
case 0x80..0x8c
Woah! Is that standard C?
Yes, its probably one of the more recent language standards though. QEMU does use to more modern features liberally.
Notwithstanding that it's widely used in QEMU (and a nice feature too), and not that I have a problem with adopting it, but just because I'm a pedant: this is definitely not in C99 (per qemu/HACKING). It doesn't appears in C11 either (at least not the final draft). It's a gcc extension:
http://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
Quoted 17 lines
Quoted 11 lines
[...]
Quoted 5 lines
Quoted 5 lines
include/hw/arm/bcm2835_arm_control.h new file +2
-0@@ -0,0 +1,481 @@ +/* +* linux/arch/arm/mach-bcm2708/arm_control.h [...]
Quoted 2 lines
When you have a regular structure like this, you should collapse it down using some arithmatic:
Notice that this file comes from Linux. I know it's not pretty, but can we
please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
Quoted 1 line
It looks very autogenerated and seems pretty nasty on the repetition.
Quoted 7 lines
As implementers of the hardware, it is much rarer to need these repetitious defs than the software users on the other side. "Do something specific with CPU#3's Mbox#5" is going to appear in software, but hardware implementers generally don't have a choice to implement things specifically and it usually ends up being looped and the exploded defs are never used. If there are only a handful of genuinely single defs needed, can they be fished out?
I think so. I'll do that then.
Andrew
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
In reply to Peter CrosthwaiteQuoted 7 lines · Peter Crosthwaite
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
case 0x80..0x8c
Woah! Is that standard C?
Yes, its probably one of the more recent language standards though. QEMU does use to more modern features liberally.
It's actually "case 0x80 ... 0x8c:".
Quoted 6 lines
Quoted 3 lines
Notice that this file comes from Linux. I know it's not pretty, but can we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
It looks very autogenerated and seems pretty nasty on the repetition.
Quoted 7 lines
As implementers of the hardware, it is much rarer to need these repetitious defs than the software users on the other side. "Do something specific with CPU#3's Mbox#5" is going to appear in software, but hardware implementers generally don't have a choice to implement things specifically and it usually ends up being looped and the exploded defs are never used. If there are only a handful of genuinely single defs needed, can they be fished out?
I see your point and I'm definitely in favor of rewriting headers from scratch when practical, but any cleanup made is a recipe for unwanted changes and bugs, especially if the source is full of repetitions.
Paolo
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Peter Crosthwaite
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
case 0x80..0x8c
Woah! Is that standard C?
Yes, its probably one of the more recent language standards though. QEMU does use to more modern features liberally.
It's actually "case
0x80...0x8c:".Quoted 1 line
Quoted 1 line
Notice that this file comes from Linux. I know it's not pretty, but
Where in Linux exactly? I am actually having trouble finding the original source. Grepping around linux-next, there is no mach bcm-2708. I can see this mach in an rPI specific fork, but I don't see it in upstream Linux.
Is it the case that Gregory did this work some time ago now, and that original source has been refactored away to something different anyway?
In the grepping I also notice that you are defining the regspecs in header for the SP804 timer, which we already model and manages its own defs. Those should be in an sp804 specific header, and Linux does the same:
$ git grep TIMER_CTRL_DIV1 drivers/clocksource/timer-integrator-ap.c: ctrl |= TIMER_CTRL_DIV16 drivers/clocksource/timer-integrator-ap.c: ctrl |= TIMER_CTRL_DIV16 drivers/clocksource/timer-sp.h:#define TIMER_CTRL_DIV1 (0 << 2) drivers/clocksource/timer-sp.h:#define TIMER_CTRL_DIV16 (1 << 2) /* ACVR
Quoted 13 lines
Quoted 5 lines
Quoted 2 lines
can we please keep it as-is, for comparison purposes? I'm not sure there's much value in cleaning it up locally...
It looks very autogenerated and seems pretty nasty on the repetition.
Quoted 7 lines
As implementers of the hardware, it is much rarer to need these repetitious defs than the software users on the other side. "Do something specific with CPU#3's Mbox#5" is going to appear in software, but hardware implementers generally don't have a choice to implement things specifically and it usually ends up being looped and the exploded defs are never used. If there are only a handful of genuinely single defs needed, can they be fished out?
Quoted 4 lines
I see your point and I'm definitely in favor of rewriting headers from scratch when practical, but any cleanup made is a recipe for unwanted changes and bugs, especially if the source is full of repetitions.
If this is from Linux, and we want this to be immutable, then shouldn't we be managing it via our existing linux-headers import scripts?
Regards,
Peter
Quoted 1 line
Paolo
Re: [Qemu-arm] [PATCH 1/8] bcm2835_sbm: add BCM2835 mailboxes
Quoted 8 lines
From: Peter Crosthwaite [mailto:[email protected]]
Sent: Wednesday, 23 December 2015 15:59Quoted 1 line
Quoted 1 line
Quoted 1 line
Notice that this file comes from Linux. I know it's not pretty, but
Where in Linux exactly? I am actually having trouble finding the original source. Grepping around linux-next, there is no mach bcm-2708. I can see this mach in an rPI specific fork, but I don't see it in upstream Linux.
After some grovelling, I think it originates from here:
https://github.com/raspberrypi/linux/blob/rpi-4.1.y/arch/arm/mach-bcm2708/include/mach/arm_control.h
However, there are some diffs between that and my version, which look like they originated from someone hacking it to get each line under 80 characteres (to satisfy checkpatch.pl?). This rather defeats the purpose of keeping it unmodified.
As far as I can tell, we only need the mailbox-related defs. I'll just pull those out into the relevant device emulation, and drop the file.
Andrew