On Mon, 3 Feb 2020 09:26:17 +0100
Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> The amount of RAM is encoded in the board revision.
> Add the board_ram_size() helper, it will allow us to quickly
> support new boards.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Igor Mammedov <imammedo@redhat.com>
> ---
> hw/arm/raspi.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
> index f5e54fe876..656d834e07 100644
> --- a/hw/arm/raspi.c
> +++ b/hw/arm/raspi.c
> @@ -13,6 +13,7 @@
>
> #include "qemu/osdep.h"
> #include "qemu/units.h"
> +#include "qemu/cutils.h"
> #include "qapi/error.h"
> #include "cpu.h"
> #include "hw/arm/bcm2836.h"
> @@ -71,6 +72,11 @@ static const RaspiBoardInfo raspi_boards[] = {
> #endif
> };
>
> +static uint64_t board_ram_size(const RaspiBoardInfo *config)
> +{
> + return 1 * MiB << extract32(config->board_rev, 20, 4);
> +}
> +
> static int board_chip_id(const RaspiBoardInfo *config)
> {
> return extract32(config->board_rev, 12, 4);
> @@ -222,10 +228,13 @@ static void raspi_init(MachineState *machine, const RaspiBoardInfo *config)
> BlockBackend *blk;
> BusState *bus;
> DeviceState *carddev;
> + uint64_t ram_size;
>
> - if (machine->ram_size > 1 * GiB) {
> - error_report("Requested ram size is too large for this machine: "
> - "maximum is 1GB");
> + ram_size = board_ram_size(config);
> + if (machine->ram_size != ram_size) {
> + char *size_str = size_to_str(ram_size);
> + error_report("This machine can only be used with %s", size_str);
> + g_free(size_str);
> exit(1);
> }
>