hw/arm/raspi: Split out raspi machine common part

Pre-setup for raspberry pi 4 introduction

Signed-off-by: Sergey Kambalin <sergey.kambalin@auriga.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20240226000259.2752893-4-sergey.kambalin@auriga.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Sergey Kambalin 2024-02-25 18:02:21 -06:00 committed by Peter Maydell
parent 7d04d630ba
commit 08df067636
2 changed files with 85 additions and 48 deletions

View File

@ -18,6 +18,7 @@
#include "qapi/error.h" #include "qapi/error.h"
#include "hw/arm/boot.h" #include "hw/arm/boot.h"
#include "hw/arm/bcm2836.h" #include "hw/arm/bcm2836.h"
#include "hw/arm/raspi_platform.h"
#include "hw/registerfields.h" #include "hw/registerfields.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "hw/boards.h" #include "hw/boards.h"
@ -25,6 +26,9 @@
#include "hw/arm/boot.h" #include "hw/arm/boot.h"
#include "qom/object.h" #include "qom/object.h"
#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common")
OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE)
#define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */
#define MVBAR_ADDR 0x400 /* secure vectors */ #define MVBAR_ADDR 0x400 /* secure vectors */
#define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */
@ -37,25 +41,10 @@
struct RaspiMachineState { struct RaspiMachineState {
/*< private >*/ /*< private >*/
MachineState parent_obj; RaspiBaseMachineState parent_obj;
/*< public >*/ /*< public >*/
BCM283XState soc; BCM283XState soc;
struct arm_boot_info binfo;
}; };
typedef struct RaspiMachineState RaspiMachineState;
struct RaspiMachineClass {
/*< private >*/
MachineClass parent_obj;
/*< public >*/
uint32_t board_rev;
};
typedef struct RaspiMachineClass RaspiMachineClass;
#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common")
DECLARE_OBJ_CHECKERS(RaspiMachineState, RaspiMachineClass,
RASPI_MACHINE, TYPE_RASPI_MACHINE)
/* /*
* Board revision codes: * Board revision codes:
@ -83,6 +72,11 @@ static const struct {
[PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS},
}; };
static void raspi_base_machine_init(MachineState *machine,
BCM283XBaseState *soc);
static void raspi_machine_class_common_init(MachineClass *mc,
uint32_t board_rev);
static uint64_t board_ram_size(uint32_t board_rev) static uint64_t board_ram_size(uint32_t board_rev)
{ {
assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
@ -200,13 +194,12 @@ static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)
cpu_set_pc(cs, info->smp_loader_start); cpu_set_pc(cs, info->smp_loader_start);
} }
static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, static void setup_boot(MachineState *machine, ARMCPU *cpu,
size_t ram_size) RaspiProcessorId processor_id, size_t ram_size)
{ {
RaspiMachineState *s = RASPI_MACHINE(machine); RaspiBaseMachineState *s = RASPI_BASE_MACHINE(machine);
int r; int r;
s->binfo.board_id = MACH_TYPE_BCM2708;
s->binfo.ram_size = ram_size; s->binfo.ram_size = ram_size;
if (processor_id <= PROCESSOR_ID_BCM2836) { if (processor_id <= PROCESSOR_ID_BCM2836) {
@ -252,13 +245,13 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id,
s->binfo.firmware_loaded = true; s->binfo.firmware_loaded = true;
} }
arm_load_kernel(&s->soc.parent_obj.cpu[0].core, machine, &s->binfo); arm_load_kernel(cpu, machine, &s->binfo);
} }
static void raspi_machine_init(MachineState *machine) static void raspi_base_machine_init(MachineState *machine,
BCM283XBaseState *soc)
{ {
RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine); RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine);
RaspiMachineState *s = RASPI_MACHINE(machine);
uint32_t board_rev = mc->board_rev; uint32_t board_rev = mc->board_rev;
uint64_t ram_size = board_ram_size(board_rev); uint64_t ram_size = board_ram_size(board_rev);
uint32_t vcram_size; uint32_t vcram_size;
@ -279,19 +272,17 @@ static void raspi_machine_init(MachineState *machine)
machine->ram, 0); machine->ram, 0);
/* Setup the SOC */ /* Setup the SOC */
object_initialize_child(OBJECT(machine), "soc", &s->soc, object_property_add_const_link(OBJECT(soc), "ram", OBJECT(machine->ram));
board_soc_type(board_rev)); object_property_set_int(OBJECT(soc), "board-rev", board_rev,
object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(machine->ram));
object_property_set_int(OBJECT(&s->soc), "board-rev", board_rev,
&error_abort); &error_abort);
object_property_set_str(OBJECT(&s->soc), "command-line", object_property_set_str(OBJECT(soc), "command-line",
machine->kernel_cmdline, &error_abort); machine->kernel_cmdline, &error_abort);
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal); qdev_realize(DEVICE(soc), NULL, &error_fatal);
/* Create and plug in the SD cards */ /* Create and plug in the SD cards */
di = drive_get(IF_SD, 0, 0); di = drive_get(IF_SD, 0, 0);
blk = di ? blk_by_legacy_dinfo(di) : NULL; blk = di ? blk_by_legacy_dinfo(di) : NULL;
bus = qdev_get_child_bus(DEVICE(&s->soc), "sd-bus"); bus = qdev_get_child_bus(DEVICE(soc), "sd-bus");
if (bus == NULL) { if (bus == NULL) {
error_report("No SD bus found in SOC object"); error_report("No SD bus found in SOC object");
exit(1); exit(1);
@ -300,19 +291,32 @@ static void raspi_machine_init(MachineState *machine)
qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
qdev_realize_and_unref(carddev, bus, &error_fatal); qdev_realize_and_unref(carddev, bus, &error_fatal);
vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size", vcram_size = object_property_get_uint(OBJECT(soc), "vcram-size",
&error_abort); &error_abort);
setup_boot(machine, board_processor_id(mc->board_rev), setup_boot(machine, &soc->cpu[0].core, board_processor_id(board_rev),
machine->ram_size - vcram_size); machine->ram_size - vcram_size);
} }
static void raspi_machine_class_common_init(MachineClass *mc, static void raspi_machine_init(MachineState *machine)
uint32_t board_rev) {
RaspiMachineState *s = RASPI_MACHINE(machine);
RaspiBaseMachineState *s_base = RASPI_BASE_MACHINE(machine);
RaspiBaseMachineClass *mc = RASPI_BASE_MACHINE_GET_CLASS(machine);
BCM283XState *soc = &s->soc;
s_base->binfo.board_id = MACH_TYPE_BCM2708;
object_initialize_child(OBJECT(machine), "soc", soc,
board_soc_type(mc->board_rev));
raspi_base_machine_init(machine, &soc->parent_obj);
}
void raspi_machine_class_common_init(MachineClass *mc,
uint32_t board_rev)
{ {
mc->desc = g_strdup_printf("Raspberry Pi %s (revision 1.%u)", mc->desc = g_strdup_printf("Raspberry Pi %s (revision 1.%u)",
board_type(board_rev), board_type(board_rev),
FIELD_EX32(board_rev, REV_CODE, REVISION)); FIELD_EX32(board_rev, REV_CODE, REVISION));
mc->init = raspi_machine_init;
mc->block_default_type = IF_SD; mc->block_default_type = IF_SD;
mc->no_parallel = 1; mc->no_parallel = 1;
mc->no_floppy = 1; mc->no_floppy = 1;
@ -322,50 +326,57 @@ static void raspi_machine_class_common_init(MachineClass *mc,
mc->default_ram_id = "ram"; mc->default_ram_id = "ram";
}; };
static void raspi_machine_class_init(MachineClass *mc,
uint32_t board_rev)
{
raspi_machine_class_common_init(mc, board_rev);
mc->init = raspi_machine_init;
};
static void raspi0_machine_class_init(ObjectClass *oc, void *data) static void raspi0_machine_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc);
rmc->board_rev = 0x920092; /* Revision 1.2 */ rmc->board_rev = 0x920092; /* Revision 1.2 */
raspi_machine_class_common_init(mc, rmc->board_rev); raspi_machine_class_init(mc, rmc->board_rev);
}; };
static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc);
rmc->board_rev = 0x900021; /* Revision 1.1 */ rmc->board_rev = 0x900021; /* Revision 1.1 */
raspi_machine_class_common_init(mc, rmc->board_rev); raspi_machine_class_init(mc, rmc->board_rev);
}; };
static void raspi2b_machine_class_init(ObjectClass *oc, void *data) static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc);
rmc->board_rev = 0xa21041; rmc->board_rev = 0xa21041;
raspi_machine_class_common_init(mc, rmc->board_rev); raspi_machine_class_init(mc, rmc->board_rev);
}; };
#ifdef TARGET_AARCH64 #ifdef TARGET_AARCH64
static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) static void raspi3ap_machine_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc);
rmc->board_rev = 0x9020e0; /* Revision 1.0 */ rmc->board_rev = 0x9020e0; /* Revision 1.0 */
raspi_machine_class_common_init(mc, rmc->board_rev); raspi_machine_class_init(mc, rmc->board_rev);
}; };
static void raspi3b_machine_class_init(ObjectClass *oc, void *data) static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
{ {
MachineClass *mc = MACHINE_CLASS(oc); MachineClass *mc = MACHINE_CLASS(oc);
RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); RaspiBaseMachineClass *rmc = RASPI_BASE_MACHINE_CLASS(oc);
rmc->board_rev = 0xa02082; rmc->board_rev = 0xa02082;
raspi_machine_class_common_init(mc, rmc->board_rev); raspi_machine_class_init(mc, rmc->board_rev);
}; };
#endif /* TARGET_AARCH64 */ #endif /* TARGET_AARCH64 */
@ -394,9 +405,14 @@ static const TypeInfo raspi_machine_types[] = {
#endif #endif
}, { }, {
.name = TYPE_RASPI_MACHINE, .name = TYPE_RASPI_MACHINE,
.parent = TYPE_MACHINE, .parent = TYPE_RASPI_BASE_MACHINE,
.instance_size = sizeof(RaspiMachineState), .instance_size = sizeof(RaspiMachineState),
.class_size = sizeof(RaspiMachineClass), .abstract = true,
}, {
.name = TYPE_RASPI_BASE_MACHINE,
.parent = TYPE_MACHINE,
.instance_size = sizeof(RaspiBaseMachineState),
.class_size = sizeof(RaspiBaseMachineClass),
.abstract = true, .abstract = true,
} }
}; };

View File

@ -28,6 +28,27 @@
#ifndef HW_ARM_RASPI_PLATFORM_H #ifndef HW_ARM_RASPI_PLATFORM_H
#define HW_ARM_RASPI_PLATFORM_H #define HW_ARM_RASPI_PLATFORM_H
#include "hw/boards.h"
#include "hw/arm/boot.h"
#define TYPE_RASPI_BASE_MACHINE MACHINE_TYPE_NAME("raspi-base")
OBJECT_DECLARE_TYPE(RaspiBaseMachineState, RaspiBaseMachineClass,
RASPI_BASE_MACHINE)
struct RaspiBaseMachineState {
/*< private >*/
MachineState parent_obj;
/*< public >*/
struct arm_boot_info binfo;
};
struct RaspiBaseMachineClass {
/*< private >*/
MachineClass parent_obj;
/*< public >*/
uint32_t board_rev;
};
#define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */ #define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */
#define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */ #define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */
#define INTE_OFFSET 0x2000 /* VC Interrupt controller */ #define INTE_OFFSET 0x2000 /* VC Interrupt controller */