Skip to content

Commit

Permalink
hw/arm/raspi: Remove use of the 'version' value in the board code
Browse files Browse the repository at this point in the history
We expected the 'version' ID to match the board processor ID,
but this is not always true (for example boards with revision
id 0xa02042/0xa22042 are Raspberry Pi 2 with a BCM2837 SoC).
This was not important because we were not modelling them, but
since the recent refactor now allow to model these boards, it
is safer to check the processor id directly. Remove the version
check.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20200924111808.77168-9-f4bug@amsat.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
philmd authored and pm215 committed Oct 1, 2020
1 parent 1af7026 commit cdfaa57
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions hw/arm/raspi.c
Expand Up @@ -98,11 +98,6 @@ static RaspiProcessorId board_processor_id(uint32_t board_rev)
return proc_id;
}

static int board_version(uint32_t board_rev)
{
return board_processor_id(board_rev) + 1;
}

static const char *board_soc_type(uint32_t board_rev)
{
return soc_property[board_processor_id(board_rev)].type;
Expand Down Expand Up @@ -201,7 +196,8 @@ static void reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)
cpu_set_pc(cs, info->smp_loader_start);
}

static void setup_boot(MachineState *machine, int version, size_t ram_size)
static void setup_boot(MachineState *machine, RaspiProcessorId processor_id,
size_t ram_size)
{
RaspiMachineState *s = RASPI_MACHINE(machine);
int r;
Expand All @@ -210,23 +206,24 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
s->binfo.ram_size = ram_size;
s->binfo.nb_cpus = machine->smp.cpus;

if (version <= 2) {
/* The rpi1 and 2 require some custom setup code to run in Secure
* mode before booting a kernel (to set up the SMC vectors so
* that we get a no-op SMC; this is used by Linux to call the
if (processor_id <= PROCESSOR_ID_BCM2836) {
/*
* The BCM2835 and BCM2836 require some custom setup code to run
* in Secure mode before booting a kernel (to set up the SMC vectors
* so that we get a no-op SMC; this is used by Linux to call the
* firmware for some cache maintenance operations.
* The rpi3 doesn't need this.
* The BCM2837 doesn't need this.
*/
s->binfo.board_setup_addr = BOARDSETUP_ADDR;
s->binfo.write_board_setup = write_board_setup;
s->binfo.secure_board_setup = true;
s->binfo.secure_boot = true;
}

/* Pi2 and Pi3 requires SMP setup */
if (version >= 2) {
/* BCM2836 and BCM2837 requires SMP setup */
if (processor_id >= PROCESSOR_ID_BCM2836) {
s->binfo.smp_loader_start = SMPBOOT_ADDR;
if (version == 2) {
if (processor_id == PROCESSOR_ID_BCM2836) {
s->binfo.write_secondary_boot = write_smpboot;
} else {
s->binfo.write_secondary_boot = write_smpboot64;
Expand Down Expand Up @@ -260,7 +257,6 @@ static void raspi_machine_init(MachineState *machine)
RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine);
RaspiMachineState *s = RASPI_MACHINE(machine);
uint32_t board_rev = mc->board_rev;
int version = board_version(board_rev);
uint64_t ram_size = board_ram_size(board_rev);
uint32_t vcram_size;
DriveInfo *di;
Expand Down Expand Up @@ -301,7 +297,8 @@ static void raspi_machine_init(MachineState *machine)

vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size",
&error_abort);
setup_boot(machine, version, machine->ram_size - vcram_size);
setup_boot(machine, board_processor_id(mc->board_rev),
machine->ram_size - vcram_size);
}

static void raspi_machine_class_common_init(MachineClass *mc,
Expand Down

0 comments on commit cdfaa57

Please sign in to comment.