All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bin.meng@processmission.com>
To: QEMU <qemu-devel@nongnu.org>
Cc: Peter Maydell <peter.maydell@linaro.org>, qemu-arm@nongnu.org
Subject: [PATCH v2 18/32] hw/arm: phytium: Select the Phytium E2000 PBR boot medium
Date: Tue,  8 Sep 2026 18:41:27 +0800	[thread overview]
Message-ID: <20260908104159.1621764-19-bin.meng@processmission.com> (raw)
In-Reply-To: <20260908104159.1621764-1-bin.meng@processmission.com>

Introduce an abstract E2000 machine class and keep the Phytium Pi
board strap fixed to SD0. Pass the selected backend and boot-mode
property to the PBR device so firmware-visible boot-media state is
owned by PBR rather than a user-settable machine option.

The class-level selection also provides the board-specific hook
required by a later E2000Q COMe machine without allowing either
board to change its physical boot strap.

Signed-off-by: Bin Meng <bin.meng@processmission.com>

---

Changes in v2:
- Keep board boot straps and media policy in the machine layer

 hw/arm/phytium_e2000_machine.c | 89 +++++++++++++++++++++++++---------
 1 file changed, 65 insertions(+), 24 deletions(-)

diff --git a/hw/arm/phytium_e2000_machine.c b/hw/arm/phytium_e2000_machine.c
index 3ab82c5fff..0337795f2d 100644
--- a/hw/arm/phytium_e2000_machine.c
+++ b/hw/arm/phytium_e2000_machine.c
@@ -24,10 +24,14 @@
 #include "qom/object.h"
 #include "target/arm/cpu-qom.h"
 
+#define TYPE_PHYTIUM_E2000_MACHINE \
+    MACHINE_TYPE_NAME("phytium-e2000-base")
+OBJECT_DECLARE_TYPE(PhytiumE2000MachineState, PhytiumE2000MachineClass,
+                    PHYTIUM_E2000_MACHINE)
+
 #define TYPE_PHYTIUM_PI MACHINE_TYPE_NAME("phytium-pi")
-OBJECT_DECLARE_SIMPLE_TYPE(PhytiumPiMachineState, PHYTIUM_PI)
 
-struct PhytiumPiMachineState {
+struct PhytiumE2000MachineState {
     MachineState parent_obj;
 
     struct arm_boot_info bootinfo;
@@ -36,6 +40,13 @@ struct PhytiumPiMachineState {
     MemoryRegion ram_high;
 };
 
+struct PhytiumE2000MachineClass {
+    MachineClass parent_class;
+
+    const char *machine_name;
+    const char *pbr_boot_mode;
+};
+
 static BlockBackend *phytium_e2000_sd_blk(int index)
 {
     DriveInfo *dinfo = drive_get(IF_SD, 0, index);
@@ -43,7 +54,7 @@ static BlockBackend *phytium_e2000_sd_blk(int index)
     return dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
 }
 
-static void phytium_e2000_attach_sd_cards(PhytiumPiMachineState *s)
+static void phytium_e2000_attach_sd_cards(PhytiumE2000MachineState *s)
 {
     int i;
 
@@ -53,16 +64,21 @@ static void phytium_e2000_attach_sd_cards(PhytiumPiMachineState *s)
     }
 }
 
-static void phytium_e2000_reject_legacy_firmware(MachineState *ms)
+static void phytium_e2000_reject_legacy_firmware(
+    MachineState *ms, PhytiumE2000MachineClass *pemc)
 {
     if (ms->firmware || drive_get(IF_PFLASH, 0, 0)) {
-        error_report("phytium-pi: -bios and pflash firmware are not "
-                     "supported; use an if=sd,index=0 image");
+        error_report("%s: -bios and pflash firmware are not supported; "
+                     "use an if=%s,index=0 image",
+                     pemc->machine_name,
+                     !strcmp(pemc->pbr_boot_mode,
+                             PHYTIUM_E2000_PBR_BOOT_MODE_QSPI) ?
+                         "mtd" : "sd");
         exit(1);
     }
 }
 
-static void phytium_e2000_create_ram(PhytiumPiMachineState *s)
+static void phytium_e2000_create_ram(PhytiumE2000MachineState *s)
 {
     MachineState *ms = MACHINE(s);
     uint64_t low_size =
@@ -89,9 +105,11 @@ static void phytium_e2000_create_ram(PhytiumPiMachineState *s)
         phytium_e2000_memmap[PHYTIUM_E2000_RAM_HIGH].base, &s->ram_high);
 }
 
-static void phytium_pi_init(MachineState *ms)
+static void phytium_e2000_init(MachineState *ms)
 {
-    PhytiumPiMachineState *s = PHYTIUM_PI(ms);
+    PhytiumE2000MachineState *s = PHYTIUM_E2000_MACHINE(ms);
+    PhytiumE2000MachineClass *pemc =
+        PHYTIUM_E2000_MACHINE_GET_CLASS(ms);
     BlockBackend *boot_blk;
     bool firmware_loaded;
 
@@ -101,12 +119,12 @@ static void phytium_pi_init(MachineState *ms)
      * Phytium-specific system registers that KVM cannot provide.
      */
     if (kvm_enabled()) {
-        error_report("phytium-pi: KVM is not supported");
+        error_report("%s: KVM is not supported", pemc->machine_name);
         exit(1);
     }
 
     if (ms->smp.cpus > PHYTIUM_E2000_NUM_CPUS) {
-        error_report("phytium-pi supports at most %d CPUs",
+        error_report("%s supports at most %d CPUs", pemc->machine_name,
                      PHYTIUM_E2000_NUM_CPUS);
         exit(1);
     }
@@ -114,18 +132,22 @@ static void phytium_pi_init(MachineState *ms)
     if (ms->ram_size >
         phytium_e2000_memmap[PHYTIUM_E2000_RAM].size +
         phytium_e2000_memmap[PHYTIUM_E2000_RAM_HIGH].size) {
-        error_report("phytium-pi supports at most 8 GiB RAM");
+        error_report("%s supports at most 8 GiB RAM", pemc->machine_name);
         exit(1);
     }
 
-    phytium_e2000_reject_legacy_firmware(ms);
+    phytium_e2000_reject_legacy_firmware(ms, pemc);
     phytium_e2000_create_ram(s);
-    boot_blk = ms->kernel_filename ? NULL : phytium_e2000_sd_blk(0);
+    if (!ms->kernel_filename &&
+        !strcmp(pemc->pbr_boot_mode, PHYTIUM_E2000_PBR_BOOT_MODE_SD0)) {
+        boot_blk = phytium_e2000_sd_blk(0);
+    } else {
+        boot_blk = NULL;
+    }
 
     object_initialize_child(OBJECT(s), "soc", &s->soc,
                             TYPE_PHYTIUM_E2000_SOC);
-    phytium_e2000_soc_configure(&s->soc,
-                                PHYTIUM_E2000_PBR_BOOT_MODE_SD0,
+    phytium_e2000_soc_configure(&s->soc, pemc->pbr_boot_mode,
                                 boot_blk, ms->ram_size, ms->smp.cpus);
     sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal);
     phytium_e2000_attach_sd_cards(s);
@@ -169,7 +191,7 @@ static const CPUArchIdList *phytium_e2000_possible_cpu_arch_ids(
     return ms->possible_cpus;
 }
 
-static void phytium_pi_class_init(ObjectClass *oc, const void *data)
+static void phytium_e2000_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     static const char * const valid_cpu_types[] = {
@@ -177,8 +199,7 @@ static void phytium_pi_class_init(ObjectClass *oc, const void *data)
         NULL,
     };
 
-    mc->init = phytium_pi_init;
-    mc->desc = "Phytium Pi board (Phytium E2000Q)";
+    mc->init = phytium_e2000_init;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a72");
     mc->valid_cpu_types = valid_cpu_types;
     mc->max_cpus = PHYTIUM_E2000_NUM_CPUS;
@@ -190,21 +211,41 @@ static void phytium_pi_class_init(ObjectClass *oc, const void *data)
     mc->default_ram_size = 2 * GiB;
     mc->default_ram_id = "phytium-e2000.ram";
     mc->minimum_page_bits = 12;
-    mc->block_default_type = IF_SD;
     mc->no_cdrom = 1;
     mc->possible_cpu_arch_ids = phytium_e2000_possible_cpu_arch_ids;
 }
 
+static void phytium_pi_class_init(ObjectClass *oc, const void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+    PhytiumE2000MachineClass *pemc =
+        PHYTIUM_E2000_MACHINE_CLASS(oc);
+
+    mc->desc = "Phytium Pi board (Phytium E2000Q)";
+    mc->block_default_type = IF_SD;
+    pemc->machine_name = "phytium-pi";
+    pemc->pbr_boot_mode = PHYTIUM_E2000_PBR_BOOT_MODE_SD0;
+}
+
+static const TypeInfo phytium_e2000_base_info = {
+    .name = TYPE_PHYTIUM_E2000_MACHINE,
+    .parent = TYPE_MACHINE,
+    .abstract = true,
+    .class_init = phytium_e2000_class_init,
+    .class_size = sizeof(PhytiumE2000MachineClass),
+    .instance_size = sizeof(PhytiumE2000MachineState),
+};
+
 static const TypeInfo phytium_pi_info = {
     .name = TYPE_PHYTIUM_PI,
-    .parent = TYPE_MACHINE,
+    .parent = TYPE_PHYTIUM_E2000_MACHINE,
     .class_init = phytium_pi_class_init,
-    .instance_size = sizeof(PhytiumPiMachineState),
 };
 
-static void phytium_pi_machine_init(void)
+static void phytium_e2000_machine_init(void)
 {
+    type_register_static(&phytium_e2000_base_info);
     type_register_static(&phytium_pi_info);
 }
 
-type_init(phytium_pi_machine_init);
+type_init(phytium_e2000_machine_init);
-- 
2.53.0



  parent reply	other threads:[~2026-09-08 10:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 10:41 [PATCH v2 00/32] hw/arm: Add Phytium E2000Q SoC and board support Bin Meng
2026-09-08 10:41 ` [PATCH v2 01/32] hw/arm: Add Phytium E2000 SoC and Phytium Pi machine Bin Meng
2026-09-08 10:41 ` [PATCH v2 02/32] hw/arm: phytium: Add Phytium E2000 PCIe host Bin Meng
2026-09-08 10:41 ` [PATCH v2 03/32] hw/sd: Add Synopsys DesignWare MCI controller Bin Meng
2026-09-08 10:41 ` [PATCH v2 04/32] hw/sd: Add Phytium E2000 " Bin Meng
2026-09-08 10:41 ` [PATCH v2 05/32] hw/arm: phytium: Connect Phytium E2000 MCI controllers Bin Meng
2026-09-08 10:41 ` [PATCH v2 06/32] tests/qtest: Add Synopsys DesignWare MCI coverage Bin Meng
2026-09-08 10:41 ` [PATCH v2 07/32] hw/arm: phytium: Connect Phytium E2000 GEM controllers Bin Meng
2026-09-08 10:41 ` [PATCH v2 08/32] hw/misc: Add Phytium E2000 DDR controller Bin Meng
2026-09-08 10:41 ` [PATCH v2 09/32] hw/arm: phytium: Connect the " Bin Meng
2026-09-08 10:41 ` [PATCH v2 10/32] hw/misc: Add Phytium E2000 MHU doorbell Bin Meng
2026-09-08 10:41 ` [PATCH v2 11/32] hw/arm: phytium: Connect the Phytium E2000 MHU Bin Meng
2026-09-08 10:41 ` [PATCH v2 12/32] hw/ssi: Add Phytium E2000 QSPI controller Bin Meng
2026-09-08 10:41 ` [PATCH v2 13/32] hw/arm: phytium: Connect the " Bin Meng
2026-09-08 10:41 ` [PATCH v2 14/32] hw/misc: Add Phytium E2000 PBR model Bin Meng
2026-09-08 10:41 ` [PATCH v2 15/32] hw/arm: phytium: Integrate the Phytium E2000 PBR Bin Meng
2026-09-08 10:41 ` [PATCH v2 16/32] hw/arm: phytium: Add Phytium E2000 control region placeholders Bin Meng
2026-09-08 10:41 ` [PATCH v2 17/32] hw/misc: Support Phytium E2000 SCMI CPU power control Bin Meng
2026-09-08 10:41 ` Bin Meng [this message]
2026-09-08 10:41 ` [PATCH v2 19/32] hw/arm: phytium: Connect the Phytium E2000 I2C controller Bin Meng
2026-09-08 10:41 ` [PATCH v2 20/32] hw/arm: phytium: Add Phytium E2000 xHCI controllers Bin Meng
2026-09-08 10:41 ` [PATCH v2 21/32] hw/misc: Model the Phytium E2000 random generator Bin Meng
2026-09-08 10:41 ` [PATCH v2 22/32] hw/arm: phytium: Connect " Bin Meng
2026-09-08 10:41 ` [PATCH v2 23/32] hw/arm: phytium: Support Phytium E2000 direct Linux boot Bin Meng
2026-09-08 10:41 ` [PATCH v2 24/32] hw/arm: phytium: Add Phytium E2000Q COMe machine Bin Meng
2026-09-08 10:41 ` [PATCH v2 25/32] hw/block: m25p80: Add GigaDevice GD25Q128 flash Bin Meng
2026-09-08 10:41 ` [PATCH v2 26/32] hw/arm: phytium: Connect the Phytium E2000Q COMe QSPI flash Bin Meng
2026-09-08 10:41 ` [PATCH v2 27/32] hw/arm: phytium: Add Phytium E2000 AHCI controllers Bin Meng
2026-09-08 10:41 ` [PATCH v2 28/32] hw/arm: Add Phytium E2000 Linux SCMI channel Bin Meng
2026-09-08 10:41 ` [PATCH v2 29/32] hw/arm: phytium: Connect the Phytium E2000 SMMUv3 Bin Meng
2026-09-08 10:41 ` [PATCH v2 30/32] docs/system/arm: Document Phytium E2000 machines Bin Meng
2026-09-08 10:41 ` [PATCH v2 31/32] tests/functional/aarch64: Add Phytium Pi boot tests Bin Meng
2026-09-08 10:41 ` [PATCH v2 32/32] MAINTAINERS: Add Phytium E2000Q machines Bin Meng

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=20260908104159.1621764-19-bin.meng@processmission.com \
    --to=bin.meng@processmission.com \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.