Skip to contentSkip to conversation

Add a valid_cpu_types property

PATCH Superseded Alistair Francis 2 participants 10 messages Oct 13, 2017

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add a valid_cpu_types property

There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.

I have added the valid_cpu_types for some ARM machines only at the moment.

Here is what specifying the CPUs looks like now:

$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m3" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) info cpus
* CPU #0: thread_id=24175
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m4" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m5" -S
qemu-system-aarch64: unable to find CPU model 'cortex-m5'
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-a9" -S
qemu-system-aarch64: Invalid CPU type: cortex-a9-arm-cpu
The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpu

V2:
- Rebase
- Reorder patches
- Add a Raspberry Pi 2 CPU fix
V1:
- Small fixes to prepare a series instead of RFC
- Add commit messages for the commits
- Expand the machine support to ARM machines
RFC v2:
- Rebase on Igor's work
- Use more QEMUisms inside the code
- List the supported machines in a NULL terminated array

Alistair Francis (5):
netduino2: Specify the valid CPUs
bcm2836: Use the Cortex-A7 instead of Cortex-A15
raspi: Specify the valid CPUs
xlnx-zcu102: Specify the valid CPUs
xilinx_zynq: : Specify the valid CPUs

 hw/arm/bcm2836.c     |  2 +-
 hw/arm/netduino2.c   | 10 +++++++++-
 hw/arm/raspi.c       |  7 +++++++
 hw/arm/xilinx_zynq.c |  6 ++++++
 hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/5 netduino2: Specify the valid CPUs

List all possible valid CPU options.

Although the board only ever has a Cortex-M3 we mark the Cortex-M4 as supported because the Netduino2 Plus supports the Cortex-M4 and the Netduino2 Plus is similar to the Netduino2.

---

V2:
- Fixup allignment
RFC v2:
- Use a NULL terminated list
- Add the Cortex-M4 for testing

 hw/arm/netduino2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/arm/netduino2.c +9 -1
index f936017d4a..6427552a72 100644
@@ -34,18 +34,26 @@ static void netduino2_init(MachineState *machine)
     DeviceState *dev;
 
     dev = qdev_create(NULL, TYPE_STM32F205_SOC);
-    qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3"));
+    qdev_prop_set_string(dev, "cpu-type", machine->cpu_type);
     object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
 
     armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
                        FLASH_SIZE);
 }
 
+const char *netduino_valid_cpus[] = {
+                                    ARM_CPU_TYPE_NAME("cortex-m3"),
+                                    ARM_CPU_TYPE_NAME("cortex-m4"),
+                                    NULL
+                                    };
+
 static void netduino2_machine_init(MachineClass *mc)
 {
     mc->desc = "Netduino 2 Machine";
     mc->init = netduino2_init;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
+    mc->valid_cpu_types = netduino_valid_cpus;
 }
 
 DEFINE_MACHINE("netduino2", netduino2_machine_init)
Signature · 1 line
2.11.0
#3 lore raw

PATCH v2 2/5 bcm2836: Use the Cortex-A7 instead of Cortex-A15

In reply to Alistair Francis

The BCM2836 uses a Cortex-A7 not a Cortex-A15. Update the device to use the correct CPU.
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf

---
V2:
- Fix the BCM2836 CPU

 hw/arm/bcm2836.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/bcm2836.c +1 -1
index 8c43291112..931795a878 100644
@@ -30,7 +30,7 @@ static void bcm2836_init(Object *obj)
 
     for (n = 0; n < BCM2836_NCPUS; n++) {
         object_initialize(&s->cpus[n], sizeof(s->cpus[n]),
-                          "cortex-a15-" TYPE_ARM_CPU);
+                          "cortex-a7-" TYPE_ARM_CPU);
         object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]),
                                   &error_abort);
     }
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 3/5 raspi: Specify the valid CPUs

In reply to Alistair Francis

List all possible valid CPU options.

---
V2:
- Fix the indentation

 hw/arm/raspi.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/arm/raspi.c +7 -0
index 5941c9f751..2a7e6a40bb 100644
@@ -158,6 +158,11 @@ static void raspi2_init(MachineState *machine)
     setup_boot(machine, 2, machine->ram_size - vcram_size);
 }
 
+const char *raspi2_valid_cpus[] = {
+                                    ARM_CPU_TYPE_NAME("cortex-a7"),
+                                    NULL
+                                  };
+
 static void raspi2_machine_init(MachineClass *mc)
 {
     mc->desc = "Raspberry Pi 2";
@@ -169,5 +174,7 @@ static void raspi2_machine_init(MachineClass *mc)
     mc->max_cpus = BCM2836_NCPUS;
     mc->default_ram_size = 1024 * 1024 * 1024;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
+    mc->valid_cpu_types = raspi2_valid_cpus;
 };
 DEFINE_MACHINE("raspi2", raspi2_machine_init)
Signature · 1 line
2.11.0
#6 lore raw

PATCH v2 4/5 xlnx-zcu102: Specify the valid CPUs

In reply to Alistair Francis

List all possible valid CPU options.

---

An implementation for single CPU machines is still being discussed. A solution proposed by Eduardo is this:

1) Change the default on TYPE_MACHINE to:

     mc->valid_cpu_types = { TYPE_CPU, NULL };

This will keep the existing behavior for all boards.

2) mc->valid_cpu_types=NULL be interpreted as "no CPU model except the default is accepted" or "-cpu is not accepted" in machine_run_board_init() (I prefer the former, but both options would be correct)

3) Boards like xlnx_zynqmp could then just do this:

   static void xxx_class_init(...) {
       mc->default_cpu_type = MY_CPU_TYPE;
       /* Reason: XXX_init() is hardcoded to MY_CPU_TYPE */
       mc->valid_cpu_types = NULL;
   }

V2:
- Don't use the users -cpu
- Fixup allignment

 hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/arm/xlnx-zcu102.c +17 -0
index 519a16ed98..c6df776d89 100644
@@ -160,6 +160,11 @@ static void xlnx_zynqmp_init(XlnxZCU102 *s, MachineState *machine)
     arm_load_kernel(s->soc.boot_cpu_ptr, &xlnx_zcu102_binfo);
 }
 
+const char *xlnx_zynqmp_valid_cpus[] = {
+                                        ARM_CPU_TYPE_NAME("cortex-a53"),
+                                        NULL
+                                       };
+
 static void xlnx_ep108_init(MachineState *machine)
 {
     XlnxZCU102 *s = EP108_MACHINE(machine);
@@ -185,6 +190,12 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_IDE;
     mc->units_per_default_bus = 1;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
+    /* The ZynqMP SoC is always a Cortex-A53. We add this here to give
+     * users a sane error if they specify a different CPU, but we never
+     * use their CPU choice.
+     */
+    mc->valid_cpu_types = xlnx_zynqmp_valid_cpus;
 }
 
 static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
@@ -240,6 +251,12 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_IDE;
     mc->units_per_default_bus = 1;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
+    /* The ZynqMP SoC is always a Cortex-A53. We add this here to give
+     * users a sane error if they specify a different CPU, but we never
+     * use their CPU choice.
+     */
+    mc->valid_cpu_types = xlnx_zynqmp_valid_cpus;
 }
 
 static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
Signature · 1 line
2.11.0
#7 lore raw

PATCH v2 5/5 xilinx_zynq: : Specify the valid CPUs

In reply to Alistair Francis

List all possible valid CPU options.

---
V2:
- Fixup alignment

 hw/arm/xilinx_zynq.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/arm/xilinx_zynq.c +6 -0
index 1836a4ed45..e169bf0a86 100644
@@ -313,6 +313,11 @@ static void zynq_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), &zynq_binfo);
 }
 
+const char *xlnx_zynq_7000_valid_cpus[] = {
+                                            ARM_CPU_TYPE_NAME("cortex-a9"),
+                                            NULL
+                                          };
+
 static void zynq_machine_init(MachineClass *mc)
 {
     mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9";
@@ -321,6 +326,7 @@ static void zynq_machine_init(MachineClass *mc)
     mc->no_sdcard = 1;
     mc->ignore_memory_transaction_failures = true;
     mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
+    mc->valid_cpu_types = xlnx_zynq_7000_valid_cpus;
 }
 
 DEFINE_MACHINE("xilinx-zynq-a9", zynq_machine_init)
Signature · 1 line
2.11.0
#8 lore raw
In reply to Alistair Francis
Quoted 8 lines · On Thu, 12 Oct 2017 17:07:23 -0700 Alistair Francis…

There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.

I have added the valid_cpu_types for some ARM machines only at the moment.

do you plan to complete work for other boards as well so that new interface would replace current opencoded checks across the tree?

Quoted 46 lines

Here is what specifying the CPUs looks like now:

$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m3" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) info cpus
* CPU #0: thread_id=24175
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m4" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m5" -S
qemu-system-aarch64: unable to find CPU model 'cortex-m5'
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-a9" -S
qemu-system-aarch64: Invalid CPU type: cortex-a9-arm-cpu
The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpu

V2:
- Rebase
- Reorder patches
- Add a Raspberry Pi 2 CPU fix
V1:
- Small fixes to prepare a series instead of RFC
- Add commit messages for the commits
- Expand the machine support to ARM machines
RFC v2:
- Rebase on Igor's work
- Use more QEMUisms inside the code
- List the supported machines in a NULL terminated array

Alistair Francis (5):
netduino2: Specify the valid CPUs
bcm2836: Use the Cortex-A7 instead of Cortex-A15
raspi: Specify the valid CPUs
xlnx-zcu102: Specify the valid CPUs
xilinx_zynq: : Specify the valid CPUs

 hw/arm/bcm2836.c     |  2 +-
 hw/arm/netduino2.c   | 10 +++++++++-
 hw/arm/raspi.c       |  7 +++++++
 hw/arm/xilinx_zynq.c |  6 ++++++
 hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)
#4 lore raw

Re: [Qemu-devel] [PATCH v2 2/5] bcm2836: Use the Cortex-A7 instead of Cortex-A15

In reply to Alistair Francis
Quoted 17 lines · On Thu, 12 Oct 2017 17:07:28 -0700 Alistair Francis…

The BCM2836 uses a Cortex-A7 not a Cortex-A15. Update the device to use the correct CPU.
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/QA7_rev3.4.pdf

---
V2:
- Fix the BCM2836 CPU

 hw/arm/bcm2836.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/bcm2836.c +0 -0
index 8c43291112..931795a878 100644

hw/arm/bcm2836.c static void bcm2836_init(Object *obj) · line 33

Quoted 5 lines
hw/arm/bcm2836.c +1 -1
@@ -30,7 +30,7 @@ static void bcm2836_init(Object *obj)
 
     for (n = 0; n < BCM2836_NCPUS; n++) {
         object_initialize(&s->cpus[n], sizeof(s->cpus[n]),
-                          "cortex-a15-" TYPE_ARM_CPU);
+                          "cortex-a7-" TYPE_ARM_CPU);

ARM_CPU_TYPE_NAME("cortex-a7")

Quoted 3 lines
hw/arm/bcm2836.c +0 -0
         object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]),
                                   &error_abort);
     }
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/5] netduino2: Specify the valid CPUs

In reply to Alistair Francis
Quoted 28 lines · On Thu, 12 Oct 2017 17:07:25 -0700 Alistair Francis…

List all possible valid CPU options.

Although the board only ever has a Cortex-M3 we mark the Cortex-M4 as supported because the Netduino2 Plus supports the Cortex-M4 and the Netduino2 Plus is similar to the Netduino2.

---

V2:
- Fixup allignment
RFC v2:
- Use a NULL terminated list
- Add the Cortex-M4 for testing

 hw/arm/netduino2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/arm/netduino2.c +0 -0
index f936017d4a..6427552a72 100644
@@ -34,18 +34,26 @@ static void netduino2_init(MachineState *machine)
     DeviceState *dev;
 

hw/arm/netduino2.c static void netduino2_init(MachineState *machine) · line 44

Quoted 10 lines
hw/arm/netduino2.c +2 -1
     dev = qdev_create(NULL, TYPE_STM32F205_SOC);
-    qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3"));
+    qdev_prop_set_string(dev, "cpu-type", machine->cpu_type);
     object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
 
     armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
                        FLASH_SIZE);
 }
 
+const char *netduino_valid_cpus[] = {

may be add 'static' here and ditto in other patches

Quoted 15 lines
hw/arm/netduino2.c +7 -0
+                                    ARM_CPU_TYPE_NAME("cortex-m3"),
+                                    ARM_CPU_TYPE_NAME("cortex-m4"),
+                                    NULL
+                                    };
+
 static void netduino2_machine_init(MachineClass *mc)
 {
     mc->desc = "Netduino 2 Machine";
     mc->init = netduino2_init;
     mc->ignore_memory_transaction_failures = true;
+    mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
+    mc->valid_cpu_types = netduino_valid_cpus;
 }
 
 DEFINE_MACHINE("netduino2", netduino2_machine_init)
#9 lore raw
In reply to Igor Mammedov
Quoted 9 lines · Igor Mammedov
Quoted 6 lines · On Thu, 12 Oct 2017 17:07:23 -0700 Alistair Francis…

There are numorous QEMU machines that only have a single or a handful of valid CPU options. To simplyfy the management of specificying which CPU is/isn't valid let's create a property that can be set in the machine init. We can then check to see if the user supplied CPU is in that list or not.

Quoted 5 lines
Quoted 2 lines

I have added the valid_cpu_types for some ARM machines only at the moment.

do you plan to complete work for other boards as well so that new interface would replace current opencoded checks across the tree?

Ideally yes, it's just a matter of finding time to dig through the other architectures.

Thanks,
Alistair

Quoted 49 lines
Quoted 48 lines

Here is what specifying the CPUs looks like now:

$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m3" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) info cpus
* CPU #0: thread_id=24175
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m4" -S
QEMU 2.10.50 monitor - type 'help' for more information
(qemu) q
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-m5" -S
qemu-system-aarch64: unable to find CPU model 'cortex-m5'
$ aarch64-softmmu/qemu-system-aarch64 -M netduino2 -kernel ./u-boot.elf -nographic -cpu "cortex-a9" -S
qemu-system-aarch64: Invalid CPU type: cortex-a9-arm-cpu
The valid types are: cortex-m3-arm-cpu, cortex-m4-arm-cpu

V2:
- Rebase
- Reorder patches
- Add a Raspberry Pi 2 CPU fix
V1:
- Small fixes to prepare a series instead of RFC
- Add commit messages for the commits
- Expand the machine support to ARM machines
RFC v2:
- Rebase on Igor's work
- Use more QEMUisms inside the code
- List the supported machines in a NULL terminated array

Alistair Francis (5):
netduino2: Specify the valid CPUs
bcm2836: Use the Cortex-A7 instead of Cortex-A15
raspi: Specify the valid CPUs
xlnx-zcu102: Specify the valid CPUs
xilinx_zynq: : Specify the valid CPUs

 hw/arm/bcm2836.c     |  2 +-
 hw/arm/netduino2.c   | 10 +++++++++-
 hw/arm/raspi.c       |  7 +++++++
 hw/arm/xilinx_zynq.c |  6 ++++++
 hw/arm/xlnx-zcu102.c | 17 +++++++++++++++++
 5 files changed, 40 insertions(+), 2 deletions(-)