qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"Esteban Bosse" <estebanbosse@gmail.com>,
	"Andrew Baumann" <Andrew.Baumann@microsoft.com>,
	qemu-devel@nongnu.org, "Pekka Enberg" <penberg@iki.fi>,
	"Zoltán Baldaszti" <bztemail@gmail.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-arm@nongnu.org,
	"Clement Deschamps" <clement.deschamps@antfield.fr>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Luc Michel" <luc.michel@greensocs.com>
Subject: [Qemu-devel] [PATCH 09/14] hw/arm/raspi: Make the board code modular
Date: Wed,  4 Sep 2019 19:13:10 +0200	[thread overview]
Message-ID: <20190904171315.8354-10-f4bug@amsat.org> (raw)
In-Reply-To: <20190904171315.8354-1-f4bug@amsat.org>

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é <f4bug@amsat.org>
---
 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 615d755879..b4db39661f 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"
@@ -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 */
 
-/* Table of Linux board IDs for different Pi versions */
-static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44};
+enum BoardIdManufacturer {
+    M_SONY_UK = 0,
+    M_EMBEST = 2,
+};
+
+enum BoardIdChip {
+    C_BCM2835 = 0,
+    C_BCM2836 = 1,
+    C_BCM2837 = 2,
+};
+
+enum BoardIdType {
+    T_2B = 0x04,
+    T_3B = 0x08,
+};
+
+enum BoardIdRevision {
+    R_1_0 = 0,
+    R_1_1 = 1,
+    R_1_2 = 2,
+    R_1_3 = 3,
+};
+
+static const char *processor_typename[] = {
+    [C_BCM2836] = TYPE_BCM2836,
+    [C_BCM2837] = 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-codes/
+     */
+    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[] = {
+    [2] = {
+        .board_id = 0xc43,
+        .board_rev = { T_2B, R_1_1, C_BCM2836, M_EMBEST },
+        .ram_size_min = 1 * GiB,
+        .ram_size_max = 1 * GiB,
+    },
+    [3] = {
+        .board_id = 0xc44,
+        .board_rev = { T_3B, R_1_2, C_BCM2837, M_SONY_UK },
+        .ram_size_min = 1 * GiB,
+        .ram_size_max = 1 * GiB,
+    },
+};
 
 typedef struct RasPiState {
     BCM283XState soc;
@@ -114,7 +174,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
     static struct arm_boot_info binfo;
     int r;
 
-    binfo.board_id = raspi_boardid[version];
+    binfo.board_id = bcm283x_boards[version].board_id;
     binfo.ram_size = ram_size;
     binfo.nb_cpus = machine->smp.cpus;
 
@@ -146,7 +206,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
      * the normal Linux boot process
      */
     if (machine->firmware) {
-        hwaddr firmware_addr = version == 3 ? FIRMWARE_ADDR_3 : FIRMWARE_ADDR_2;
+        hwaddr firmware_addr = version >= 3 ? FIRMWARE_ADDR_3 : FIRMWARE_ADDR_2;
         /* load the firmware image (typically kernel.img) */
         r = load_image_targphys(machine->firmware, firmware_addr,
                                 ram_size - firmware_addr);
@@ -170,16 +230,32 @@ static void raspi_init(MachineState *machine, int version)
     BlockBackend *blk;
     BusState *bus;
     DeviceState *carddev;
+    char *size_str;
+    int board_rev;
+    const char *soc_type;
 
-    if (machine->ram_size > 1 * GiB) {
+    if (machine->ram_size < bcm283x_boards[version].ram_size_min) {
+        size_str = 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 = 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);
     }
 
+    soc_type = processor_typename[bcm283x_boards[version].board_rev.chip];
     object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
-                            version == 3 ? TYPE_BCM2837 : TYPE_BCM2836,
-                            &error_abort, NULL);
+                            soc_type, &error_abort, NULL);
 
     /* 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 version)
                                    &error_abort);
     object_property_set_int(OBJECT(&s->soc), machine->smp.cpus, "enabled-cpus",
                             &error_abort);
-    int board_rev = version == 3 ? 0xa02082 : 0xa21041;
-    object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev",
-                            &error_abort);
+
+    board_rev = ((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_abort);
 
     /* Create and plug in the SD cards */
@@ -221,7 +302,7 @@ static void raspi2_init(MachineState *machine)
 
 static void raspi2_machine_init(MachineClass *mc)
 {
-    mc->desc = "Raspberry Pi 2";
+    mc->desc = "Raspberry Pi 2B";
     mc->init = raspi2_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
@@ -243,7 +324,7 @@ static void raspi3_init(MachineState *machine)
 
 static void raspi3_machine_init(MachineClass *mc)
 {
-    mc->desc = "Raspberry Pi 3";
+    mc->desc = "Raspberry Pi 3B";
     mc->init = raspi3_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
-- 
2.20.1



  parent reply	other threads:[~2019-09-04 17:25 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-04 17:13 [Qemu-devel] [RFC PATCH 00/14] hw/arm: Add the Raspberry Pi 4B Philippe Mathieu-Daudé
2019-09-04 17:13 ` [Qemu-devel] [PATCH 01/14] hw/arm/raspi: Use the IEC binary prefix definitions Philippe Mathieu-Daudé
2019-09-27 19:46   ` Esteban Bosse
2019-09-29  6:57   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 02/14] hw/misc/bcm2835_property: Add FIXME comment for uninitialized memory Philippe Mathieu-Daudé
2019-09-04 17:13 ` [Qemu-devel] [RFC PATCH 03/14] hw/misc/bcm2835_property: Handle the 'domain state' property Philippe Mathieu-Daudé
2019-09-27 20:51   ` Esteban Bosse
2019-09-29  7:01   ` Esteban Bosse
2019-10-08  9:32     ` Philippe Mathieu-Daudé
2019-10-24  9:15       ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 04/14] hw/arm/bcm2835_peripherals: Improve logging Philippe Mathieu-Daudé
2019-09-27 21:25   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 05/14] hw/arm/bcm2835_peripherals: Name various address spaces Philippe Mathieu-Daudé
2019-09-29  7:08   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 06/14] hw/arm/bcm2835: Rename some definitions Philippe Mathieu-Daudé
2019-09-29 14:27   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 07/14] hw/arm/bcm2835: Add various unimplemented peripherals Philippe Mathieu-Daudé
2019-09-29 14:35   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [PATCH 08/14] hw/arm/bcm2836: Make the SoC code modular Philippe Mathieu-Daudé
2019-09-29 14:39   ` Esteban Bosse
2019-09-04 17:13 ` Philippe Mathieu-Daudé [this message]
2019-09-04 17:13 ` [Qemu-devel] [PATCH 10/14] hw/arm/raspi: Define various blocks base addresses Philippe Mathieu-Daudé
2019-09-06 10:07   ` Philippe Mathieu-Daudé
2019-09-29 15:27     ` Esteban Bosse
2019-10-08  9:16       ` Philippe Mathieu-Daudé
2019-09-04 17:13 ` [Qemu-devel] [PATCH 11/14] hw/arm/bcm2835_peripherals: Map various BCM2838 blocks Philippe Mathieu-Daudé
2019-09-29 15:44   ` Esteban Bosse
2019-09-04 17:13 ` [Qemu-devel] [RFC PATCH 12/14] hw/arm/bcm2836: Add the BCM2838 which uses a GICv2 Philippe Mathieu-Daudé
2019-09-05  8:41   ` Luc Michel
2019-09-09 17:10     ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2019-09-04 17:13 ` [Qemu-devel] [RFC PATCH 13/14] hw/arm/bcm2838: Map the PCIe memory space Philippe Mathieu-Daudé
2019-09-04 17:13 ` [Qemu-devel] [RFC PATCH 14/14] hw/arm/raspi: Add the Raspberry Pi 4B board Philippe Mathieu-Daudé
2019-09-29 15:53   ` Esteban Bosse
2019-10-08  9:04     ` Philippe Mathieu-Daudé
2019-10-24  9:07       ` Peter Maydell
2019-10-24 12:26         ` Esteban Bosse
2019-10-24  9:01   ` Esteban Bosse
2019-09-21 13:25 ` [Qemu-arm] [RFC PATCH 00/14] hw/arm: Add the Raspberry Pi 4B Stewart Hildebrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190904171315.8354-10-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=bztemail@gmail.com \
    --cc=clement.deschamps@antfield.fr \
    --cc=estebanbosse@gmail.com \
    --cc=luc.michel@greensocs.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=penberg@iki.fi \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).