From nobody Wed Nov 12 16:28:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1571529412; cv=none; d=zoho.com; s=zohoarc; b=b2a7qzx3xQaXfNnvBH3ido6kYt+XLtU0oTMX5z6kE/QFb9gXlF+u2IACjW4m8pTlcGPPOMePqdq26Ds+gN8ziXSUmXvPcPiss5H8+ocGwBLocf5PzuQgYezs8CFHM5HGTWQqTT8/WkjTmF1OI1WG011YvgefqhZ6gm/omQKDEqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571529412; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/zFVPjuAiYGtT3eOPkbE1HDbnoPdHl9DaAfhFHqH+Qw=; b=UxzjkD4dXs3fHDMCrSW2mc0cuD82vhGyPfeF1XzAoK9RFI/O/Y0y+gE+ure/l1h5yDDM0/Xdhz8dOXgA3GsH+DBNu/egtc4AYy3xl+lGBIcp8kFN4D3M+BfJnN492jzHMAab+qBlDVpl0jx4i0aUZc7NYCvDcbaV/KMFOccKR+U= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571529412686944.2161282553741; Sat, 19 Oct 2019 16:56:52 -0700 (PDT) Received: from localhost ([::1]:42226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLyaZ-0004Pw-BF for importer@patchew.org; Sat, 19 Oct 2019 19:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34701) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iLyRj-0000W5-G3 for qemu-devel@nongnu.org; Sat, 19 Oct 2019 19:47:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iLyRh-0005g5-RY for qemu-devel@nongnu.org; Sat, 19 Oct 2019 19:47:43 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:33755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iLyRh-0005fo-L8; Sat, 19 Oct 2019 19:47:41 -0400 Received: by mail-wm1-x341.google.com with SMTP id r17so11892155wme.0; Sat, 19 Oct 2019 16:47:41 -0700 (PDT) Received: from x1w.redhat.com (14.red-88-21-201.staticip.rima-tde.net. [88.21.201.14]) by smtp.gmail.com with ESMTPSA id u1sm10433763wrp.56.2019.10.19.16.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 16:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/zFVPjuAiYGtT3eOPkbE1HDbnoPdHl9DaAfhFHqH+Qw=; b=t/pEgVtGZdKrTtAtQtarzSMXmo07HjtOI3GpSUmw6fKHOQ6M0V0ZS/NuBb23I6RTsu BfI7OL9QxVhnfVVceeGfNLwxk3JuvSj801MPMPbHKc6qH2XSoGuM8Zn67SIWc7Z5vX72 Q7gKlMkFzCS91c5eeKlPjOrlqjAMrR5tOR28zosWLAksg/TSa6e+09H1ucJapFUMQ6Wg bOBoSMjdR24Q7pZLgTB3dWVGpHfOMAKd7qecBLoT3Bxvh+XE/ioNtmDwsu87CH5AswvI De6y+n9x12uMaJAykdwag+WuVa+mw+aCtrLiEEyrWU3Sxe/WIqma55B8OLvcvl4QE4vG Rvig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/zFVPjuAiYGtT3eOPkbE1HDbnoPdHl9DaAfhFHqH+Qw=; b=nONkAclewCtjLGBlPTT4vOMNDpJhBP3ChD3dc73CYjdVOYYmTeyb+6BdJpkztasB30 Ry0PwRFCD7vpuaVluvNIdLl4wvWIWMhYJ8sU80/goIsbzBfjU2gXiuSU+KJh2q3iJ0AQ SzuApAKpviVb655JnC6MSZ8jsw5gB3QaEw2V3YUO6gZAlWhJPsKhjHKOqJk5QhWk1w4x i1tLeWZE/YIsaL3xrOWr+WSoOOQKwe8GdXVx8PX6rDfV/aDwEBHo360xEgcR3CPst4uQ VmMMGQx0eo1fGAU2KsD9B/7yGDTflZq/PqOlTpWzZMapEkqqUBaZkcsjLFrLwCuq3sOW h7/g== X-Gm-Message-State: APjAAAUyo4nt18h3zXGwWhyBegvKTWSKP5VE8Awt8NIKD3tTucZ4URaZ y8lqeLIwIynd1i1EemujGEkTNbDr X-Google-Smtp-Source: APXvYqwEzJ04bviIfXR2Si9rnfC7y0OycHhw8Eq0icutULMJWzElqeZF8hueUlkWJ31cMXtE2hJJnA== X-Received: by 2002:a1c:1bd8:: with SMTP id b207mr12774993wmb.62.1571528860433; Sat, 19 Oct 2019 16:47:40 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v3 13/16] hw/arm/raspi: Make the board code modular Date: Sun, 20 Oct 2019 01:47:12 +0200 Message-Id: <20191019234715.25750-14-f4bug@amsat.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191019234715.25750-1-f4bug@amsat.org> References: <20191019234715.25750-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Matthias Brugger , Rob Herring , Alistair Francis , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Andrew Baumann , Esteban Bosse , "Emilio G . Cota" , Clement Deschamps , qemu-arm@nongnu.org, Cleber Rosa , Laurent Bonnans , Cheng Xiang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Pekka Enberg , Pete Batard Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Our code currently create the raspi2 (based on the BCM2836) and the raspi3 (on the BCM2837). Similarly, the raspi4 is based on the BCM2838. To be able to add the new board, make the current code more modular: - Dynamically fills the 'board-rev' value - Allow DRAM sizes different than 1 GiB Rename the board model name as 'B' since this is the one encoded in the 'board-rev' tag. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/raspi.c | 107 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 13 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index b1b488ca53..004804bdb3 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -13,6 +13,7 @@ =20 #include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "cpu.h" #include "hw/arm/bcm2836.h" @@ -29,8 +30,67 @@ #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ #define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ =20 -/* Table of Linux board IDs for different Pi versions */ -static const int raspi_boardid[] =3D {[1] =3D 0xc42, [2] =3D 0xc43, [3] = =3D 0xc44}; +enum BoardIdManufacturer { + M_SONY_UK =3D 0, + M_EMBEST =3D 2, +}; + +enum BoardIdChip { + C_BCM2835 =3D 0, + C_BCM2836 =3D 1, + C_BCM2837 =3D 2, +}; + +enum BoardIdType { + T_2B =3D 0x04, + T_3B =3D 0x08, +}; + +enum BoardIdRevision { + R_1_0 =3D 0, + R_1_1 =3D 1, + R_1_2 =3D 2, + R_1_3 =3D 3, +}; + +static const char *processor_typename[] =3D { + [C_BCM2836] =3D TYPE_BCM2836, + [C_BCM2837] =3D TYPE_BCM2837, +}; + +typedef struct BoardInfo BoardInfo; + +struct BoardInfo { + /* Table of Linux board IDs for different Pi versions */ + int board_id; + /* + * Board revision codes: + * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-cod= es/ + */ + struct { + enum BoardIdType type; + enum BoardIdRevision revision; + enum BoardIdChip chip; + enum BoardIdManufacturer manufacturer; + } board_rev; + uint64_t ram_size_min; + uint64_t ram_size_max; +}; + +static const BoardInfo bcm283x_boards[] =3D { + [2] =3D { + .board_id =3D 0xc43, + .board_rev =3D { T_2B, R_1_1, C_BCM2836, M_EMBEST }, + .ram_size_min =3D 1 * GiB, + .ram_size_max =3D 1 * GiB, + }, + [3] =3D { + .board_id =3D 0xc44, + .board_rev =3D { T_3B, R_1_2, C_BCM2837, M_SONY_UK }, + .ram_size_min =3D 1 * GiB, + .ram_size_max =3D 1 * GiB, + }, +}; =20 typedef struct RasPiState { BCM283XState soc; @@ -116,7 +176,7 @@ static void setup_boot(MachineState *machine, int versi= on, size_t ram_size) static struct arm_boot_info binfo; int r; =20 - binfo.board_id =3D raspi_boardid[version]; + binfo.board_id =3D bcm283x_boards[version].board_id; binfo.ram_size =3D ram_size; binfo.nb_cpus =3D machine->smp.cpus; =20 @@ -148,7 +208,7 @@ static void setup_boot(MachineState *machine, int versi= on, size_t ram_size) * the normal Linux boot process */ if (machine->firmware) { - hwaddr firmware_addr =3D version =3D=3D 3 ? FIRMWARE_ADDR_3 : FIRM= WARE_ADDR_2; + hwaddr firmware_addr =3D version >=3D 3 ? FIRMWARE_ADDR_3 : FIRMWA= RE_ADDR_2; /* load the firmware image (typically kernel.img) */ r =3D load_image_targphys(machine->firmware, firmware_addr, ram_size - firmware_addr); @@ -172,16 +232,32 @@ static void raspi_init(MachineState *machine, int ver= sion) BlockBackend *blk; BusState *bus; DeviceState *carddev; + char *size_str; + int board_rev; + const char *soc_type; =20 - if (machine->ram_size > 1 * GiB) { + if (machine->ram_size < bcm283x_boards[version].ram_size_min) { + size_str =3D size_to_str(bcm283x_boards[version].ram_size_min); + error_report("Requested ram size is too small for this machine: " + "minimum is %s", size_str); + g_free(size_str); + exit(1); + } + if (machine->ram_size > bcm283x_boards[version].ram_size_max) { + size_str =3D size_to_str(bcm283x_boards[version].ram_size_max); error_report("Requested ram size is too large for this machine: " - "maximum is 1GB"); + "maximum is %s", size_str); + g_free(size_str); + exit(1); + } + if (!is_power_of_2(machine->ram_size)) { + error_report("Requested ram size is not a power of 2"); exit(1); } =20 + soc_type =3D processor_typename[bcm283x_boards[version].board_rev.chip= ]; object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc= ), - version =3D=3D 3 ? TYPE_BCM2837 : TYPE_BCM2836, - &error_abort, NULL); + soc_type, &error_abort, NULL); =20 /* Allocate and map RAM */ memory_region_allocate_system_memory(&s->ram, OBJECT(machine), "ram", @@ -192,9 +268,14 @@ static void raspi_init(MachineState *machine, int vers= ion) &error_abort); object_property_set_int(OBJECT(&s->soc), machine->smp.cores, "enabled-cores", &error_abort); - int board_rev =3D version =3D=3D 3 ? 0xa02082 : 0xa21041; - object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev", - &error_abort); + + board_rev =3D ((63 - clz64(machine->ram_size / MiB)) << 20) + | (bcm283x_boards[version].board_rev.manufacturer << 16) + | (bcm283x_boards[version].board_rev.chip << 12) + | (bcm283x_boards[version].board_rev.type << 4) + | (bcm283x_boards[version].board_rev.revision << 0); + object_property_set_int(OBJECT(&s->soc), board_rev, + "board-rev", &error_abort); object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abo= rt); =20 /* Create and plug in the SD cards */ @@ -221,7 +302,7 @@ static void raspi2_init(MachineState *machine) =20 static void raspi2_machine_init(MachineClass *mc) { - mc->desc =3D "Raspberry Pi 2"; + mc->desc =3D "Raspberry Pi 2B"; mc->init =3D raspi2_init; mc->block_default_type =3D IF_SD; mc->no_parallel =3D 1; @@ -243,7 +324,7 @@ static void raspi3_init(MachineState *machine) =20 static void raspi3_machine_init(MachineClass *mc) { - mc->desc =3D "Raspberry Pi 3"; + mc->desc =3D "Raspberry Pi 3B"; mc->init =3D raspi3_init; mc->block_default_type =3D IF_SD; mc->no_parallel =3D 1; --=20 2.21.0