Raspberry Pi 2 support
Subsystems (2)
v5 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. Thanks are also due to Peter Crosthwaite for the code reviews and feedback.
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 rootwait" -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 (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.
v2 changes:
* cleanup based on reviews of mbox and ic devices by Peter Crosthwaite (see specific notes on each patch)
* removed custom SD controller in favour of sdhci
v3 changes:
* cleanup/tweaks to mbox, ic, peripherals and bcm2836_control devices from v2 review
* changed how I allocate and pass ram from the board through to the SoC
* cleanup raspi_platform.h
* s/_/-/ in device/property/type names
v4 changes:
* refactoring in bcm2836_control
* minor cleanup / style tweaks in other device emulations
* use qemu MAC address in bcm2835_property
* avoid use of smp_cpus outside raspi.c
* made setup blobs relocatable, and merged with highbank's copy in common code
v5 changes:
* minor cleanup / style tweaks only
Cheers,
Andrew
Andrew Baumann (8):
bcm2835_mbox: add BCM2835 mailboxes
bcm2835_property: add bcm2835 property channel
bcm2835_ic: add bcm2835 interrupt controller
bcm2835_peripherals: add rollup device for bcm2835 peripherals
bcm2836_control: add bcm2836 ARM control logic
bcm2836: add bcm2836 SoC device
arm/boot: move highbank secure board setup code to common routine
raspi: add raspberry pi 2 machine
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 1 + hw/arm/bcm2835_peripherals.c | 204 +++++++++++++++++++++ hw/arm/bcm2836.c | 165 +++++++++++++++++ hw/arm/boot.c | 51 ++++++ hw/arm/highbank.c | 37 +--- hw/arm/raspi.c | 152 ++++++++++++++++ hw/intc/Makefile.objs | 1 + hw/intc/bcm2835_ic.c | 236 +++++++++++++++++++++++++ hw/intc/bcm2836_control.c | 303 +++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 2 + hw/misc/bcm2835_mbox.c | 333 +++++++++++++++++++++++++++++++++++ hw/misc/bcm2835_property.c | 287 ++++++++++++++++++++++++++++++ include/hw/arm/arm.h | 5 + include/hw/arm/bcm2835_peripherals.h | 42 +++++ include/hw/arm/bcm2836.h | 35 ++++ include/hw/arm/raspi_platform.h | 128 ++++++++++++++ include/hw/intc/bcm2835_ic.h | 33 ++++ include/hw/intc/bcm2836_control.h | 51 ++++++ include/hw/misc/bcm2835_mbox.h | 38 ++++ include/hw/misc/bcm2835_mbox_defs.h | 27 +++ include/hw/misc/bcm2835_property.h | 31 ++++ 22 files changed, 2128 insertions(+), 35 deletions(-) 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_mbox.c create mode 100644 hw/misc/bcm2835_property.c 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_mbox.h create mode 100644 include/hw/misc/bcm2835_mbox_defs.h create mode 100644 include/hw/misc/bcm2835_property.h
Signature · 1 line
2.5.3
PATCH v5 1/8 bcm2835_mbox: add BCM2835 mailboxes
This adds the system mailboxes which are used to communicate with a number of GPU peripherals on Pi/Pi2.
---
Notes:
v5:
* minor style tweaks only
v3:
* #define register offsets
* rename mbox_init -> mbox_reset
* s/_/-/ in property and type names
* avoid hw_error
* minor style tweaks
v2:
* renamed bcm2835_sbm to bcm2835_mbox
* dropped bcm2835_arm_control.h (needed defs moved to bcm2835_mbox.c)
* documented use of private address space through defines in bcm2835_mbox_defs.h
* remove unused fields from BCM2835Mbox
* s/int/bool/ where appropriate
* cleaned up logic in _update and _mbox_update_status for clarity/simplicity
* added vmstate
* misc cleanup
default-configs/arm-softmmu.mak | 1 + hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_mbox.c | 333 ++++++++++++++++++++++++++++++++++++ include/hw/misc/bcm2835_mbox.h | 38 ++++ include/hw/misc/bcm2835_mbox_defs.h | 27 +++ 5 files changed, 400 insertions(+) create mode 100644 hw/misc/bcm2835_mbox.c create mode 100644 include/hw/misc/bcm2835_mbox.h create mode 100644 include/hw/misc/bcm2835_mbox_defs.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
@@ -36,6 +36,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_mbox.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.o
hw/misc/bcm2835_mbox.c new file +333 -0
333 lines not on this page · raw message
include/hw/misc/bcm2835_mbox.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* 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 + +#include "bcm2835_mbox_defs.h" +#include "hw/sysbus.h" +#include "exec/address-spaces.h" + +#define TYPE_BCM2835_MBOX "bcm2835-mbox" +#define BCM2835_MBOX (obj) \ + OBJECT_CHECK(BCM2835MboxState, (obj), TYPE_BCM2835_MBOX) + +typedef struct { +uint32_t reg[MBOX_SIZE ]; +uint32_t count; +uint32_t status; +uint32_t config; +}BCM2835Mbox ; + +typedef struct { +/*< private >*/ +SysBusDevice busdev; +/*< public >*/ +MemoryRegion *mbox_mr; +AddressSpace mbox_as; +MemoryRegion iomem; +qemu_irq arm_irq; + +bool mbox_irq_disabled; +bool available[MBOX_CHAN_COUNT ]; +BCM2835Mbox mbox[2 ]; +}BCM2835MboxState ; + +#endif
include/hw/misc/bcm2835_mbox_defs.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_MBOX_DEFS_H +#define BCM2835_MBOX_DEFS_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 + +/* Layout of the private address space used for communication between +* the mbox device emulation, and child devices: each channel occupies +* 16 bytes of address space, but only two registers are presently defined. +*/ +#define MBOX_AS_CHAN_SHIFT 4 +#define MBOX_AS_DATA 0/* request / response data (RW at offset 0) */ +#define MBOX_AS_PENDING 4/* pending response status (RO at offset 4) */ + +#endif /* BCM2835_MBOX_DEFS_H */
Signature · 1 line
2.5.3
PATCH v5 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.
---
Notes:
v5:
* minor style tweak
v4:
* added LOG_UNIMP as appropriate
* use qemu_macaddr_default_if_unset to allocate a MAC address, and dma_memory_write to write it
* assert that we're not pending, rather than dropping a request on the floor
hw/misc/Makefile.objs | 1 + hw/misc/bcm2835_property.c | 287 +++++++++++++++++++++++++++++++++++++ include/hw/misc/bcm2835_property.h | 31 ++++ 3 files changed, 319 insertions(+) create mode 100644 hw/misc/bcm2835_property.c create mode 100644 include/hw/misc/bcm2835_property.h
hw/misc/Makefile.objs +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_OMAP) += omap_l4.o obj-$(CONFIG_OMAP) += omap_sdrc.o obj-$(CONFIG_OMAP) += omap_tap.o obj-$(CONFIG_RASPI) += bcm2835_mbox.o +obj-$(CONFIG_RASPI) += bcm2835_property.o obj-$(CONFIG_SLAVIO) += slavio_misc.o obj-$(CONFIG_ZYNQ) += zynq_slcr.o obj-$(CONFIG_ZYNQ) += zynq-xadc.o
hw/misc/bcm2835_property.c new file +287 -0
287 lines not on this page · raw message
include/hw/misc/bcm2835_property.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* 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" +#include "net/net.h" + +#define TYPE_BCM2835_PROPERTY "bcm2835-property" +#define BCM2835_PROPERTY (obj) \ + OBJECT_CHECK(BCM2835PropertyState, (obj), TYPE_BCM2835_PROPERTY) + +typedef struct { +/*< private >*/ +SysBusDevice busdev; +/*< public >*/ +MemoryRegion *dma_mr; +AddressSpace dma_as; +MemoryRegion iomem; +qemu_irq mbox_irq; +MACAddr macaddr; +uint32_t ram_size; +uint32_t addr; +bool pending; +}BCM2835PropertyState ; + +#endif
Signature · 1 line
2.5.3
PATCH v5 3/8 bcm2835_ic: add bcm2835 interrupt controller
In reply to Andrew Baumann---
Notes:
v3:
* minor style tweaks
* use extract32 in place of manual shift/masking
v2:
* split inputs to named gpu_irq and arm_irq gpio inputs
* use 64-bit gpu_irq and 8-bit arm_irq status rather than 3*32-bit bitfields
* added defined names for register offsets
* deleted nop realize method
* other misc cleanup suggested in review
hw/intc/Makefile.objs | 1 + hw/intc/bcm2835_ic.c | 236 +++++++++++++++++++++++++++++++++++++++++++ include/hw/intc/bcm2835_ic.h | 33 ++++++ 3 files changed, 270 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 +236 -0
236 lines not on this page · raw message
include/hw/intc/bcm2835_ic.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* 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) + +#define BCM2835_IC_GPU_IRQ "gpu-irq" +#define BCM2835_IC_ARM_IRQ "arm-irq" + +typedef struct BCM2835ICState { +/*< private >*/ +SysBusDevice busdev; +/*< public >*/ + +MemoryRegion iomem; +qemu_irq irq; +qemu_irq fiq; + +/* 64 GPU IRQs + 8 ARM IRQs = 72 total (GPU first) */ +uint64_t gpu_irq_level, gpu_irq_enable; +uint8_t arm_irq_level, arm_irq_enable; +bool fiq_enable; +uint8_t fiq_select; +}BCM2835ICState ; + +#endif
Signature · 1 line
2.5.3
PATCH v5 4/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 spaces used for DMA and mailboxes.
---
Notes:
v5:
* s/memory_region_init_io/memory_region_init/
v3:
* clean up raspi_platform.h
* s/_/-/ in type/property/child names
* use memory_region_init where appropriate rather than memory_region_init_io
* pass ram as link property
v2:
* adapted to use common SDHCI emulation
hw/arm/Makefile.objs | 1 + hw/arm/bcm2835_peripherals.c | 204 +++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2835_peripherals.h | 42 ++++++++ include/hw/arm/raspi_platform.h | 128 ++++++++++++++++++++++ 4 files changed, 375 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 +204 -0
204 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 +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.5.3
PATCH v5 5/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.
---
Notes:
v5:
* <= IRQ_CNTVIRQ rather than < IRQ_MAILBOX0 for clarity
* refactor state struct to keep derived state separate from migrated state
v4:
* delete unused defs
* s/localirqs/timerirqs/
* factor out deliver_local() from bcm2836_control_update
* use deposit32 in place of bit manipulation in set_local_irq
* introduced register offset defs, and reduced comments in read/write handlers
* delete commented code
* s/_/-/ rename GPIOs
v3:
* uint8 localirqs
* style tweaks
* add MR access size limits
hw/intc/Makefile.objs | 2 +- hw/intc/bcm2836_control.c | 303 ++++++++++++++++++++++++++++++++++++++ include/hw/intc/bcm2836_control.h | 51 +++++++ 3 files changed, 355 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 +303 -0
303 lines not on this page · raw message
include/hw/intc/bcm2836_control.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.5.3
PATCH v5 6/8 bcm2836: add bcm2836 SoC device
In reply to Andrew BaumannThis is the SoC for Raspberry Pi 2.
---
Notes:
v5:
* use qdev_connect_gpio_out to connect CPU timers, rather than direct assignment
* minor formatting tweaks
v4:
* s/ic/control/
* replace use of smp_cpus with enabled-cpus property
* propagate errors rather than exit(1)
hw/arm/Makefile.objs | 2 +- hw/arm/bcm2836.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/bcm2836.h | 35 ++++++++++ 3 files changed, 201 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 +165 -0
165 lines not on this page · raw message
include/hw/arm/bcm2836.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* 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 >*/ + +uint32_t enabled_cpus; + +ARMCPU cpus[BCM2836_NCPUS ]; +BCM2836ControlState control; +BCM2835PeripheralState peripherals; +}BCM2836State ; + +#endif /* BCM2836_H */
Signature · 1 line
2.5.3
PATCH v5 7/8 arm/boot: move highbank secure board setup code to common routine
In reply to Andrew BaumannThe new version is slightly different, to support Rasbperry Pi (in particular, Pi1's arm11 core which doesn't support v7 instructions such as MOVW).
---
Notes:
v5:
* style/formatting changes only
hw/arm/boot.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/highbank.c | 37 ++----------------------------------- include/hw/arm/arm.h | 5 +++++ 3 files changed, 58 insertions(+), 35 deletions(-)
hw/arm/boot.c +51 -0
@@ -178,6 +178,57 @@ static void default_write_secondary(ARMCPU *cpu, smpboot, fixupcontext); } +void arm_write_secure_board_setup_dummy_smc (ARMCPU *cpu, +const struct arm_boot_info *info, +hwaddr mvbar_addr) +{ +int n; +uint32_t mvbar_blob[] = { +/* mvbar_addr: secure monitor vectors +* Default unimplemented and unused vectors to spin. Makes it +* easier to debug (as opposed to the CPU running away). +*/ +0xeafffffe ,/* (spin) */ +0xeafffffe ,/* (spin) */ +0xe1b0f00e ,/* movs pc, lr ;SMC exception return */ +0xeafffffe ,/* (spin) */ +0xeafffffe ,/* (spin) */ +0xeafffffe ,/* (spin) */ +0xeafffffe ,/* (spin) */ +0xeafffffe ,/* (spin) */ + }; +uint32_t board_setup_blob[] = { +/* board setup addr */ +0xe3a00e00 + (mvbar_addr >>4 ),/* mov r0, #mvbar_addr */ +0xee0c0f30 ,/* mcr p15, 0, r0, c12, c0, 1 ;set MVBAR */ +0xee110f11 ,/* mrc p15, 0, r0, c1 , c1, 0 ;read SCR */ +0xe3800031 ,/* orr r0, #0x31 ;enable AW, FW, NS */ +0xee010f11 ,/* mcr p15, 0, r0, c1, c1, 0 ;write SCR */ +0xe1a0100e ,/* mov r1, lr ;save LR across SMC */ +0xe1600070 ,/* smc #0 ;call monitor to flush SCR */ +0xe1a0f001 ,/* mov pc, r1 ;return */ + }; + +/* check that mvbar_addr is correctly aligned and relocatable (using MOV) */ +assert ((mvbar_addr &0x1f ) ==0 && (mvbar_addr >>4 ) <0x100 ); + +/* check that these blobs don't overlap */ +assert ((mvbar_addr +sizeof (mvbar_blob) <= info->board_setup_addr) + || (info->board_setup_addr +sizeof (board_setup_blob) <= mvbar_addr)); + +for (n =0 ; n <ARRAY_SIZE (mvbar_blob); n++) { + mvbar_blob[n] =tswap32 (mvbar_blob[n]); + } +rom_add_blob_fixed ("board-setup-mvbar" , mvbar_blob,sizeof (mvbar_blob), + mvbar_addr); + +for (n =0 ; n <ARRAY_SIZE (board_setup_blob); n++) { + board_setup_blob[n] =tswap32 (board_setup_blob[n]); + } +rom_add_blob_fixed ("board-setup" , board_setup_blob, +sizeof (board_setup_blob), info->board_setup_addr); +} +static void default_reset_secondary (ARMCPU *cpu,const struct arm_boot_info *info) {
hw/arm/highbank.c +2 -35
@@ -35,49 +35,16 @@#define MPCORE_PERIPHBASE 0xfff10000#define MVBAR_ADDR 0x200 +#define BOARD_SETUP_ADDR (MVBAR_ADDR + 8 * sizeof(uint32_t))#define NIRQ_GIC 160/* Board init. */ -/* MVBAR_ADDR is limited by precision of movw */ - -QEMU_BUILD_BUG_ON (MVBAR_ADDR >= (1 <<16 )); - -#define ARMV7_IMM16 (x) (extract32((x), 0, 12) | \ - extract32((x), 12, 4) << 16) -static void hb_write_board_setup (ARMCPU *cpu,const struct arm_boot_info *info) { -int n; -uint32_t board_setup_blob[] = { -/* MVBAR_ADDR */ -/* Default unimplemented and unused vectors to spin. Makes it -* easier to debug (as opposed to the CPU running away). -*/ -0xeafffffe ,/* notused1: b notused */ -0xeafffffe ,/* notused2: b notused */ -0xe1b0f00e ,/* smc: movs pc, lr - exception return */ -0xeafffffe ,/* prefetch_abort: b prefetch_abort */ -0xeafffffe ,/* data_abort: b data_abort */ -0xeafffffe ,/* notused3: b notused3 */ -0xeafffffe ,/* irq: b irq */ -0xeafffffe ,/* fiq: b fiq */ -#define BOARD_SETUP_ADDR (MVBAR_ADDR + 8 * sizeof(uint32_t)) -0xe3000000 +ARMV7_IMM16 (MVBAR_ADDR ),/* movw r0, MVBAR_ADDR */ -0xee0c0f30 ,/* mcr p15, 0, r0, c12, c0, 1 - set MVBAR */ -0xee110f11 ,/* mrc p15, 0, r0, c1 , c1, 0 - get SCR */ -0xe3810001 ,/* orr r0, #1 - set NS */ -0xee010f11 ,/* mcr p15, 0, r0, c1 , c1, 0 - set SCR */ -0xe1600070 ,/* smc - go to monitor mode to flush NS change */ -0xe12fff1e ,/* bx lr - return to caller */ - }; -for (n =0 ; n <ARRAY_SIZE (board_setup_blob); n++) { - board_setup_blob[n] =tswap32 (board_setup_blob[n]); - } -rom_add_blob_fixed ("board-setup" , board_setup_blob, -sizeof (board_setup_blob),MVBAR_ADDR ); +arm_write_secure_board_setup_dummy_smc (cpu, info,MVBAR_ADDR ); }static void hb_write_secondary (ARMCPU *cpu,const struct arm_boot_info *info)
include/hw/arm/arm.h +5 -0
@@ -122,6 +122,11 @@ struct arm_boot_info {*/ void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info); +/* Write a secure board setup routine with a dummy handler for SMCs */ +void arm_write_secure_board_setup_dummy_smc (ARMCPU *cpu, +const struct arm_boot_info *info, +hwaddr mvbar_addr); +/* Multiplication factor to convert from system clock ticks to qemu timer ticks. */ extern int system_clock_scale;
Signature · 1 line
2.5.3
Peter Maydell
AppliedQuoted 5 lines · Andrew Baumann
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. Thanks are also due to Peter Crosthwaite for the code reviews and feedback.
Thanks, applied to target-arm.next.
-- PMM
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Qemu-arm] [PATCH v5 8/8] raspi: add raspberry pi 2 machine
The list server seems to have eaten this patch from this series for some reason, so I'm just replying here so we have a copy of it other than in my private email.
thanks
-- PMM
Quoted 206 lines · Andrew Baumann
Reviewed-by Peter Crosthwaite <[email protected]>Signed-off-by Andrew Baumann <[email protected]>---
Notes:
Pi1 requires more peripherals, and will be added in a later patch series.v5:
* s/RaspiState/RasPiState/
* drop use of soc union in RasPiState
* useQEMU_BUILD_BUG_ONfor static asserts inwrite_smpboot()
* other minor formatting/style tweaksv4:
* drop header comment from versatile
* made smpboot and board setup blobs relocatable (within limits:
we can't use ARMv7 MOVW for Pi1, so it's messier than highbank)
* move board setup blob to common code
* modify SCR using read-or-write
* s/RaspiMachineState/RaspiState/
* style tweaksv3:
* fix board setup to remain Pi1 compatible
* pass ram propertyhw/arm/Makefile.objs | 2 +- hw/arm/raspi.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 hw/arm/raspi.chw/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.ohw/arm/raspi.c new file +152
-1@@ -0,0 +1,152 @@ +/* +* Raspberry Pi emulation (c) 2012 Gregory Estrade +* Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous +* +* Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft +* Written by Andrew Baumann +* +* This code is licensed under the GNU GPLv2 and later. +*/ + +#include "hw/arm/bcm2836.h" +#include "qemu/error-report.h" +#include "hw/boards.h" +#include "hw/loader.h" +#include "hw/arm/arm.h" +#include "sysemu/sysemu.h" + +#define SMPBOOT_ADDR 0x300/* this should leave enough space for ATAGS */ +#define MVBAR_ADDR 0x400/* secure vectors */ +#define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20)/* board setup code */ +#define FIRMWARE_ADDR 0x8000/* Pi loads kernel.img here by default */ + +/* Table of Linux board IDs for different Pi versions */ +static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 }; + +typedef struct RasPiState { +BCM2836State soc; +MemoryRegion ram; +}RasPiState ; + +static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) +{ +static const uint32_t smpboot[] = { +0xe1a0e00f ,/* mov lr, pc */ +0xe3a0fe00 + (BOARDSETUP_ADDR >>4 ),/* mov pc, BOARDSETUP_ADDR */ +0xee100fb0 ,/* mrc p15, 0, r0, c0, c0, 5;get core ID */ +0xe7e10050 ,/* ubfx r0, r0, #0, #2 ;extract LSB */ +0xe59f5014 ,/* ldr r5, =0x400000CC ;load mbox base */ +0xe320f001 ,/* 1: yield */ +0xe7953200 ,/* ldr r3, [r5, r0, lsl #4] ;read mbox for our core*/ +0xe3530000 ,/* cmp r3, #0 ;spin while zero */ +0x0afffffb ,/* beq 1b */ +0xe7853200 ,/* str r3, [r5, r0, lsl #4] ;clear mbox */ +0xe12fff13 ,/* bx r3 ;jump to target */ +0x400000cc ,/* (constant: mailbox 3 read/clear base) */ + }; + +/* check that we don't overrun board setup vectors */ +QEMU_BUILD_BUG_ON (SMPBOOT_ADDR +sizeof (smpboot) >MVBAR_ADDR ); +/* check that board setup address is correctly relocated */ +QEMU_BUILD_BUG_ON ((BOARDSETUP_ADDR &0xf ) !=0 + || (BOARDSETUP_ADDR >>4 ) >=0x100 ); + +rom_add_blob_fixed ("raspi_smpboot" , smpboot,sizeof (smpboot), + info->smp_loader_start); +} + +static void write_board_setup (ARMCPU *cpu,const struct arm_boot_info *info) +{ +arm_write_secure_board_setup_dummy_smc (cpu, info,MVBAR_ADDR ); +} + +static void reset_secondary (ARMCPU *cpu,const struct arm_boot_info *info) +{ +CPUState *cs =CPU (cpu); +cpu_set_pc (cs, info->smp_loader_start); +} + +static void setup_boot (MachineState *machine,int version,size_t ram_size) +{ +static struct arm_boot_info binfo; +int r; + + binfo.board_id = raspi_boardid[version]; + binfo.ram_size = ram_size; + binfo.nb_cpus = smp_cpus; + binfo.board_setup_addr =BOARDSETUP_ADDR ; + binfo.write_board_setup = write_board_setup; + binfo.secure_board_setup = true; + binfo.secure_boot = true; + +/* Pi2 requires SMP setup */ +if (version ==2 ) { + binfo.smp_loader_start =SMPBOOT_ADDR ; + binfo.write_secondary_boot = write_smpboot; + binfo.secondary_cpu_reset_hook = reset_secondary; + } + +/* If the user specified a "firmware" image (e.g. UEFI), we bypass +* the normal Linux boot process +*/ +if (machine->firmware) { +/* load the firmware image (typically kernel.img) */ + r =load_image_targphys (machine->firmware,FIRMWARE_ADDR , + ram_size -FIRMWARE_ADDR ); +if (r <0 ) { +error_report ("Failed to load firmware from %s" , machine->firmware); +exit (1 ); + } + + binfo.entry =FIRMWARE_ADDR ; + binfo.firmware_loaded = true; + }else { + binfo.kernel_filename = machine->kernel_filename; + binfo.kernel_cmdline = machine->kernel_cmdline; + binfo.initrd_filename = machine->initrd_filename; + } + +arm_load_kernel (ARM_CPU (first_cpu), &binfo); +} + +static void raspi2_init (MachineState *machine) +{ +RasPiState *s =g_new0 (RasPiState,1 ); + +object_initialize (&s->soc,sizeof (s->soc),TYPE_BCM2836 ); +object_property_add_child (OBJECT (machine),"soc" ,OBJECT (&s->soc), + &error_abort); + +/* Allocate and map RAM */ +memory_region_allocate_system_memory (&s->ram,OBJECT (machine),"ram" , + machine->ram_size); +/* FIXME: Remove when we have custom CPU address space support */ +memory_region_add_subregion_overlap (get_system_memory (),0 , &s->ram,0 ); + +/* Setup the SOC */ +object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), + &error_abort); +object_property_set_int (OBJECT (&s->soc), smp_cpus,"enabled-cpus" , + &error_abort); +object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_abort); + +setup_boot (machine,2 , machine->ram_size); +} + +static void raspi2_machine_init (MachineClass *mc) +{ + mc->desc ="Raspberry Pi 2" ; + mc->init = raspi2_init; + mc->block_default_type =IF_SD ; + mc->no_parallel =1 ; + mc->no_floppy =1 ; + mc->no_cdrom =1 ; + mc->max_cpus =BCM2836_NCPUS ; + +/* XXX: Temporary restriction in RAM size from the full 1GB. Since +* we do not yet support the framebuffer / GPU, we need to limit +* RAM usable by the OS to sit below the peripherals. +*/ + mc->default_ram_size =0x3F000000 ;/* BCM2836_PERI_BASE */ +}; +DEFINE_MACHINE ("raspi2" , raspi2_machine_init) --2.5.3