#include "qapi/error.h"
#include "cpu.h"
#include "hw/arm/bcm2836.h"
+#include "hw/registerfields.h"
#include "qemu/error-report.h"
#include "hw/boards.h"
#include "hw/loader.h"
MemoryRegion ram;
} RasPiState;
+/*
+ * Board revision codes:
+ * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/
+ */
+FIELD(REV_CODE, REVISION, 0, 4);
+FIELD(REV_CODE, TYPE, 4, 8);
+FIELD(REV_CODE, PROCESSOR, 12, 4);
+FIELD(REV_CODE, MANUFACTURER, 16, 4);
+FIELD(REV_CODE, MEMORY_SIZE, 20, 3);
+FIELD(REV_CODE, STYLE, 23, 1);
+
+static int board_processor_id(uint32_t board_rev)
+{
+ assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
+ return FIELD_EX32(board_rev, REV_CODE, PROCESSOR);
+}
+
+static int board_version(uint32_t board_rev)
+{
+ return board_processor_id(board_rev) + 1;
+}
+
static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info)
{
static const uint32_t smpboot[] = {
arm_load_kernel(ARM_CPU(first_cpu), machine, &binfo);
}
-static void raspi_init(MachineState *machine, int version)
+static void raspi_init(MachineState *machine, uint32_t board_rev)
{
RasPiState *s = g_new0(RasPiState, 1);
+ int version = board_version(board_rev);
uint32_t vcram_size;
DriveInfo *di;
BlockBackend *blk;
/* Setup the SOC */
object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram),
&error_abort);
- int board_rev = version == 3 ? 0xa02082 : 0xa21041;
object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev",
&error_abort);
object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort);
static void raspi2_init(MachineState *machine)
{
- raspi_init(machine, 2);
+ raspi_init(machine, 0xa21041);
}
static void raspi2_machine_init(MachineClass *mc)
#ifdef TARGET_AARCH64
static void raspi3_init(MachineState *machine)
{
- raspi_init(machine, 3);
+ raspi_init(machine, 0xa02082);
}
static void raspi3_machine_init(MachineClass *mc)