hw/arm: Add the Raspberry Pi 4B
Subsystems (2)
v2 cover hw/arm: Add the Raspberry Pi 4B
Still not complete as we need to implement more firmware properties. However state good enough for review, or in case someone want to work on it and improve it.
Since RFC v1:
- Rebased
- Used recommendations from Luc
https://www.mail-archive.com/[email protected]/msg642450.html
Based-on: <[email protected]>
Philippe Mathieu-Daudé (3):
hw/arm/bcm2836: Add the ARMv8 BCM2838
hw/arm/raspi: Add the Raspberry Pi 4 model B hw/arm/raspi: Remove unsupported raspi4 peripherals from device tree
include/hw/arm/bcm2836.h | 3 + hw/arm/bcm2836.c | 179 +++++++++++++++++++++++++++++++++++++++ hw/arm/raspi.c | 55 ++++++++++++ hw/arm/trace-events | 2 + 4 files changed, 239 insertions(+)
Signature · 1 line
2.26.2
RFC PATCH v2 1/3 hw/arm/bcm2836: Add the ARMv8 BCM2838
The BCM2838 share the same peripheral base block from the BCM283x family, but connects 4 Cortex-A72 cores via a GICv2.
--- include/hw/arm/bcm2836.h | 3 + hw/arm/bcm2836.c | 179 +++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 2 + 3 files changed, 184 insertions(+)
include/hw/arm/bcm2836.h +3 -0
@@ -14,6 +14,7 @@#include "hw/arm/bcm2835_peripherals.h" #include "hw/intc/bcm2836_control.h" +#include "hw/intc/arm_gic.h" #include "target/arm/cpu.h" #include "qom/object.h"
@@ -29,6 +30,7 @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X)#define TYPE_BCM2835 "bcm2835"#define TYPE_BCM2836 "bcm2836"#define TYPE_BCM2837 "bcm2837" +#define TYPE_BCM2838 "bcm2838"struct BCM283XState {/*< private >*/
@@ -40,6 +42,7 @@ struct BCM283XState {struct {ARMCPU core; } cpu[BCM283X_NCPUS ]; +GICState gic;BCM2836ControlState control;BCM2835PeripheralState peripherals; };
hw/arm/bcm2836.c +179 -0
215 lines not on this page · raw message
hw/arm/trace-events +2 -0
@@ -53,3 +53,5 @@ smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu mr=%s" smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint64_t iova, uint8_t tg, uint64_t num_pages) "iommu mr=%s asid=%d iova=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64 +# bcm2836.c +bcm2838_gic_set_irq(int irq, int level) "gic irq:%d lvl:%d"
Signature · 1 line
2.26.2
RFC PATCH v2 2/3 hw/arm/raspi: Add the Raspberry Pi 4 model B
In reply to Philippe Mathieu-DaudéAdd 2 variants of the raspi4:
- raspi4b1g: Raspberry Pi 4B (revision 1.1, with 1 GiB of RAM)
- raspi4b2g Raspberry Pi 4B (revision 1.2, with 2 GiB)
Example booting the 2GiB machine using content from [*]:
$ qemu-system-aarch64 -M raspi4b2g -serial stdio \
-kernel raspberrypi/firmware/boot/kernel8.img \
-dtb raspberrypi/firmware/boot/bcm2711-rpi-4-b.dtb \
-append 'printk.time=0 earlycon=pl011,0xfe201000 console=ttyAMA0'
[ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd083]
[ 0.000000] Linux version 5.4.51-v8+ (dom@buildbot) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)) #1333 SMP PREEMPT Mon Aug 10 16:58:35 BST 2020
[ 0.000000] Machine model: Raspberry Pi 4 Model B
[ 0.000000] earlycon: pl11 at MMIO 0x00000000fe201000 (options '')
[ 0.000000] printk: bootconsole [pl11] enabled
[ 0.000000] efi: Getting EFI parameters from FDT:
[ 0.000000] efi: UEFI not found.
[ 0.000000] Reserved memory: created CMA memory pool at 0x000000002c000000, size 64 MiB
[ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[ 0.000000] Detected PIPT I-cache on CPU0
[ 0.000000] CPU features: detected: EL2 vector hardening
[ 0.000000] ARM_SMCCC_ARCH_WORKAROUND_1 missing from firmware
[ 0.000000] software IO TLB: mapped [mem 0x3bfff000-0x3ffff000] (64MB)
[ 0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[ 0.000000] GIC: Using split EOI/Deactivate mode
[ 0.633289] smp: Bringing up secondary CPUs ...
[ 0.694226] Detected PIPT I-cache on CPU1
[ 0.699002] CPU1: Booted secondary processor 0x0000000001 [0x410fd083]
[ 0.782443] Detected PIPT I-cache on CPU2
[ 0.783511] CPU2: Booted secondary processor 0x0000000002 [0x410fd083]
[ 0.848854] Detected PIPT I-cache on CPU3
[ 0.850003] CPU3: Booted secondary processor 0x0000000003 [0x410fd083]
[ 0.857099] smp: Brought up 1 node, 4 CPUs
[ 0.863500] SMP: Total of 4 processors activated.
[ 0.865446] CPU features: detected: 32-bit EL0 Support
[ 0.866667] CPU features: detected: CRC32 instructions
[ 2.235648] CPU: All CPU(s) started at EL2
...--- hw/arm/raspi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
hw/arm/raspi.c +28 -0
@@ -73,6 +73,7 @@ typedef enum RaspiProcessorId {PROCESSOR_ID_BCM2835 =0 ,PROCESSOR_ID_BCM2836 =1 ,PROCESSOR_ID_BCM2837 =2 , +PROCESSOR_ID_BCM2838 =3 , } RaspiProcessorId; static const struct {
@@ -82,6 +83,7 @@ static const struct { [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1}, [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, + [PROCESSOR_ID_BCM2838] = {TYPE_BCM2838, BCM283X_NCPUS}, };static uint64_t board_ram_size (uint32_t board_rev)
@@ -366,6 +368,24 @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) rmc->board_rev =0xa02082 ;raspi_machine_class_common_init (mc, rmc->board_rev); }; + +static void raspi4b1g_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc); + + rmc->board_rev =0xa03111 ; +raspi_machine_class_common_init (mc, rmc->board_rev); +}; + +static void raspi4b2g_machine_class_init (ObjectClass *oc,void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +RaspiMachineClass *rmc =RASPI_MACHINE_CLASS (oc); + + rmc->board_rev =0xb03112 ; +raspi_machine_class_common_init (mc, rmc->board_rev); +};#endif /* TARGET_AARCH64 */ static const TypeInfo raspi_machine_types[] = {
@@ -390,6 +410,14 @@ static const TypeInfo raspi_machine_types[] = { .name = MACHINE_TYPE_NAME("raspi3b"), .parent = TYPE_RASPI_MACHINE, .class_init = raspi3b_machine_class_init, + }, { + .name = MACHINE_TYPE_NAME("raspi4b1g"), + .parent = TYPE_RASPI_MACHINE, + .class_init = raspi4b1g_machine_class_init, + }, { + .name = MACHINE_TYPE_NAME("raspi4b2g"), + .parent = TYPE_RASPI_MACHINE, + .class_init = raspi4b2g_machine_class_init, #endif }, { .name = TYPE_RASPI_MACHINE,
Signature · 1 line
2.26.2
PATCH v2 3/3 hw/arm/raspi: Remove unsupported raspi4 peripherals from device tree
In reply to Philippe Mathieu-DaudéKludge when using Linux kernels to reach userland. No device in DT -> no hardware initialization.
Linux 5.9 uses the RPI_FIRMWARE_GET_CLOCKS so we now need to implement that feature too. Look like a cat and mouse game...
--- hw/arm/raspi.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
hw/arm/raspi.c +27 -0
@@ -25,6 +25,7 @@#include "hw/arm/boot.h" #include "sysemu/sysemu.h" #include "qom/object.h" +#include <libfdt.h> #define SMPBOOT_ADDR 0x300/* this should leave enough space for ATAGS */ #define MVBAR_ADDR 0x400/* secure vectors */
@@ -200,6 +201,29 @@ static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)cpu_set_pc (cs, info->smp_loader_start); } +static void raspi4_modify_dtb (const struct arm_boot_info *info,void *fdt) +{ +int offset; + + offset =fdt_node_offset_by_compatible (fdt,-1 ,"brcm,genet-v5" ); +if (offset >=0 ) { +/* FIXME we shouldn't nop the parent */ + offset =fdt_parent_offset (fdt, offset); +if (offset >=0 ) { +if (!fdt_nop_node (fdt, offset)) { +warn_report ("dtc: bcm2838-genet removed!" ); + } + } + } + + offset =fdt_node_offset_by_compatible (fdt,-1 ,"brcm,avs-tmon-bcm2838" ); +if (offset >=0 ) { +if (!fdt_nop_node (fdt, offset)) { +warn_report ("dtc: bcm2838-tmon removed!" ); + } + } +} +static void setup_boot (MachineState *machine,RaspiProcessorId processor_id,size_t ram_size) {
@@ -234,6 +258,9 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, } s->binfo.secondary_cpu_reset_hook = reset_secondary; } +if (processor_id >=PROCESSOR_ID_BCM2838 ) { + s->binfo.modify_dtb = raspi4_modify_dtb; + }/* If the user specified a "firmware" image (e.g. UEFI), we bypass * the normal Linux boot process
Signature · 1 line
2.26.2