All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision
@ 2020-02-06  1:17 Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
                   ` (29 more replies)
  0 siblings, 30 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

Hi,

These patches simplify adding the raspi0/raspi1/raspi4 boards.

Igor has been working in his "refactor main RAM allocation to use
hostmem backend" series, and now v4 [1] is almost reviewed.

His raspi patch [2] clashes with my work, Since it is easier for
him to apply his on top of mine, I am sending these patches first.

Only the 4 first patches matter regarding Igor's refactor, to
include "Extract the RAM size from the board revision" which
should solve the problem he has to fix in [2].

I finally finished the SoC code, so can add the raspi0/1.
Avocado tests also include to demostrate the boards work.
I will probably move the raspi tests out of boot_linux_console.py,
but that is another series.

Latest patches NOTFORMERGE are mostly to justify this refactor,
like the raspi0 and 1, it is easy to add a new soc/board.
However other bcm peripherals patches need to get merged first
(on the list but old so I need to rebase/repost them).

Please review, at least up to patch 21 (before the tests).

Phil.

[1] https://www.mail-archive.com/qemu-devel@nongnu.org/msg675738.html
[2] https://www.mail-archive.com/qemu-devel@nongnu.org/msg675752.html
Supersedes: <20200203082619.7426-1-f4bug@amsat.org>
https://www.mail-archive.com/qemu-devel@nongnu.org/msg676154.html

Philippe Mathieu-Daudé (30):
  hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
  hw/arm/raspi: Correct the board descriptions
  hw/arm/raspi: Extract the version from the board revision
  hw/arm/raspi: Extract the RAM size from the board revision
  hw/arm/raspi: Extract the processor type from the board revision
  hw/arm/raspi: Trivial code movement
  hw/arm/raspi: Make machines children of abstract RaspiMachineClass
  hw/arm/raspi: Make board_rev a field of RaspiMachineClass
  hw/arm/raspi: Let class_init() directly call raspi_machine_init()
  hw/arm/raspi: Set default RAM size to size encoded in board revision
  hw/arm/raspi: Extract the board model from the board revision
  hw/arm/raspi: Use a unique raspi_machine_class_init() method
  hw/arm/raspi: Extract the cores count from the board revision
  hw/arm/bcm2836: Restrict BCM283XClass declaration to C source
  hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
  hw/arm/bcm2836: Introduce BCM283XClass::core_count
  hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
  hw/arm/bcm2836: Split out common realize() code
  hw/arm/bcm2836: Introduce the BCM2835 SoC
  hw/arm/raspi: Add the Raspberry Pi Zero machine
  hw/arm/raspi: Add the Raspberry Pi B+ machine
  tests/acceptance/boot_linux_console: Use raspi console model as key
  tests/acceptance/boot_linux_console: Add raspi version=2 parameter
  tests/acceptance/boot_linux_console: Test the raspi1 console
  tests/acceptance/boot_linux_console: Test the raspi0 console
  python/qemu/machine: Allow to use other serial consoles than default
  tests/acceptance/boot_linux_console: Test the raspi1 AUX console
  tests/acceptance: Count Raspberry Pi logos displayed on framebuffer
  hw/arm/bcm2836: Add the ARMv8 BCM2838
  hw/arm/raspi: Add the Raspberry Pi 4

 include/hw/arm/bcm2836.h               |  16 +-
 hw/arm/bcm2836.c                       | 396 +++++++++++++++++++++----
 hw/arm/raspi.c                         | 204 ++++++++++---
 python/qemu/machine.py                 |  10 +-
 tests/acceptance/boot_linux_console.py | 154 +++++++++-
 5 files changed, 645 insertions(+), 135 deletions(-)

-- 
2.21.1



^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06 12:21   ` BALATON Zoltan
  2020-02-06  1:17 ` [PATCH v2 02/30] hw/arm/raspi: Correct the board descriptions Philippe Mathieu-Daudé
                   ` (28 subsequent siblings)
  29 siblings, 1 reply; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Stephen Warren, Zoltán Baldaszti,
	Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm, Alistair Francis,
	Michael Chan, Philippe Mathieu-Daudé,
	Pekka Enberg, Kshitij Soni

When booting without device tree, the Linux kernels uses the $R1
register to determine the machine type. The list of values is
registered at [1].

There are two entries for the Raspberry Pi:

- https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
  name: MACH_TYPE_BCM2708
  value: 0xc42 (3138)
  status: Active, not mainlined
  date: 15 Oct 2010

- https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
  name: MACH_TYPE_BCM2835
  value: 4828
  status: Active, mainlined
  date: 6 Dec 2013

QEMU always used the non-mainlined type MACH_TYPE_BCM2708.
The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and
0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).

The Raspberry Pi foundation bootloader only sets the BCM2708 machine
type, see [2] or [3]:

 133 9:
 134     mov r0, #0
 135     ldr r1, =3138       @ BCM2708 machine id
 136     ldr r2, atags       @ ATAGS
 137     bx  r4

U-Boot only uses MACH_TYPE_BCM2708 (see [4]):

 25 /*
 26  * 2835 is a SKU in a series for which the 2708 is the first or primary SoC,
 27  * so 2708 has historically been used rather than a dedicated 2835 ID.
 28  *
 29  * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation
 30  * chose to use someone else's previously registered machine ID (3139, MX51_GGC)
 31  * rather than obtaining a valid ID:-/
 32  *
 33  * For the bcm2837, hopefully a machine type is not needed, since everything
 34  * is DT.
 35  */

While the definition MACH_BCM2709 with value 0xc43 was introduced in
a commit described "Add 2709 platform for Raspberry Pi 2" out of the
mainline Linux kernel, it does not seem used, and the platform is
introduced with Device Tree support anyway (see [5] and [6]).

Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef
"raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4
"raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708.

[1] https://www.arm.linux.org.uk/developer/machines/
[2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135
[3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64
[4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18
[5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
[6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html

Cc: Zoltán Baldaszti <bztemail@gmail.com>
Cc: Pekka Enberg <penberg@iki.fi>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Kshitij Soni <kshitij.soni@broadcom.com>
Cc: Michael Chan <michael.chan@broadcom.com>
Cc: Andrew Baumann <Andrew.Baumann@microsoft.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 3996f6c63a..ef76a27f33 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -29,8 +29,7 @@
 #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};
+#define MACH_TYPE_BCM2708   3138 /* Linux board IDs */
 
 typedef struct RasPiState {
     BCM283XState soc;
@@ -116,7 +115,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 = MACH_TYPE_BCM2708;
     binfo.ram_size = ram_size;
     binfo.nb_cpus = machine->smp.cpus;
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 02/30] hw/arm/raspi: Correct the board descriptions
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 03/30] hw/arm/raspi: Extract the version from the board revision Philippe Mathieu-Daudé
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

We hardcode the board revision as 0xa21041 for the raspi2, and
0xa02082 for the raspi3:

  166 static void raspi_init(MachineState *machine, int version)
  167 {
  ...
  194     int board_rev = version == 3 ? 0xa02082 : 0xa21041;

These revision codes are for the 2B and 3B models, see:
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md

Correct the board description.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index ef76a27f33..3b892bb509 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -220,7 +220,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;
@@ -242,7 +242,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.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 03/30] hw/arm/raspi: Extract the version from the board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 02/30] hw/arm/raspi: Correct the board descriptions Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size " Philippe Mathieu-Daudé
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Alistair Francis,
	Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The board revision encode the board version. Add a helper
to extract the version, and use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Cc: Alistair Francis <alistair@alistair23.me>

 hw/arm/raspi.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 3b892bb509..13d41dfce6 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -16,6 +16,7 @@
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/arm/bcm2836.h"
+#include "hw/registerfields.h"
 #include "qemu/error-report.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
@@ -36,6 +37,28 @@ typedef struct RasPiState {
     MemoryRegion ram;
 } RasPiState;
 
+/*
+ * Board revision codes:
+ * www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/
+ */
+FIELD(REV_CODE, REVISION,           0, 4);
+FIELD(REV_CODE, TYPE,               4, 8);
+FIELD(REV_CODE, PROCESSOR,         12, 4);
+FIELD(REV_CODE, MANUFACTURER,      16, 4);
+FIELD(REV_CODE, MEMORY_SIZE,       20, 3);
+FIELD(REV_CODE, STYLE,             23, 1);
+
+static int board_processor_id(uint32_t board_rev)
+{
+    assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
+    return FIELD_EX32(board_rev, REV_CODE, PROCESSOR);
+}
+
+static int board_version(uint32_t board_rev)
+{
+    return board_processor_id(board_rev) + 1;
+}
+
 static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info)
 {
     static const uint32_t smpboot[] = {
@@ -163,9 +186,10 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
     arm_load_kernel(ARM_CPU(first_cpu), machine, &binfo);
 }
 
-static void raspi_init(MachineState *machine, int version)
+static void raspi_init(MachineState *machine, uint32_t board_rev)
 {
     RasPiState *s = g_new0(RasPiState, 1);
+    int version = board_version(board_rev);
     uint32_t vcram_size;
     DriveInfo *di;
     BlockBackend *blk;
@@ -191,7 +215,6 @@ static void raspi_init(MachineState *machine, int version)
     /* Setup the SOC */
     object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram),
                                    &error_abort);
-    int board_rev = version == 3 ? 0xa02082 : 0xa21041;
     object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev",
                             &error_abort);
     object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort);
@@ -215,7 +238,7 @@ static void raspi_init(MachineState *machine, int version)
 
 static void raspi2_init(MachineState *machine)
 {
-    raspi_init(machine, 2);
+    raspi_init(machine, 0xa21041);
 }
 
 static void raspi2_machine_init(MachineClass *mc)
@@ -237,7 +260,7 @@ DEFINE_MACHINE("raspi2", raspi2_machine_init)
 #ifdef TARGET_AARCH64
 static void raspi3_init(MachineState *machine)
 {
-    raspi_init(machine, 3);
+    raspi_init(machine, 0xa02082);
 }
 
 static void raspi3_machine_init(MachineClass *mc)
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size from the board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 03/30] hw/arm/raspi: Extract the version from the board revision Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06 12:24   ` BALATON Zoltan
  2020-02-06  1:17 ` [PATCH v2 05/30] hw/arm/raspi: Extract the processor type " Philippe Mathieu-Daudé
                   ` (25 subsequent siblings)
  29 siblings, 1 reply; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Alistair Francis,
	Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm, Igor Mammedov,
	Philippe Mathieu-Daudé

The board revision encode the amount of RAM. Add a helper
to extract the RAM size, and use it.
Since the amount of RAM is fixed (it is impossible to physically
modify to have more or less RAM), do not allow sizes different
than the one anounced by the manufacturer.

Acked-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Cc: Alistair Francis <alistair@alistair23.me>

 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 13d41dfce6..2f5cd32c5e 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"
@@ -48,6 +49,12 @@ FIELD(REV_CODE, MANUFACTURER,      16, 4);
 FIELD(REV_CODE, MEMORY_SIZE,       20, 3);
 FIELD(REV_CODE, STYLE,             23, 1);
 
+static uint64_t board_ram_size(uint32_t board_rev)
+{
+    assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
+    return 256 * MiB << FIELD_EX32(board_rev, REV_CODE, MEMORY_SIZE);
+}
+
 static int board_processor_id(uint32_t board_rev)
 {
     assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
@@ -190,15 +197,17 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
 {
     RasPiState *s = g_new0(RasPiState, 1);
     int version = board_version(board_rev);
+    uint64_t ram_size = board_ram_size(board_rev);
     uint32_t vcram_size;
     DriveInfo *di;
     BlockBackend *blk;
     BusState *bus;
     DeviceState *carddev;
 
-    if (machine->ram_size > 1 * GiB) {
-        error_report("Requested ram size is too large for this machine: "
-                     "maximum is 1GB");
+    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);
     }
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 05/30] hw/arm/raspi: Extract the processor type from the board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size " Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 06/30] hw/arm/raspi: Trivial code movement Philippe Mathieu-Daudé
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The board revision encode the processor type. Add a helper
to extract the type, and use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 2f5cd32c5e..20195227eb 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -66,6 +66,21 @@ static int board_version(uint32_t board_rev)
     return board_processor_id(board_rev) + 1;
 }
 
+static const char *board_soc_type(uint32_t board_rev)
+{
+    static const char *soc_types[] = {
+        NULL, TYPE_BCM2836, TYPE_BCM2837,
+    };
+    int proc_id = board_processor_id(board_rev);
+
+    if (proc_id >= ARRAY_SIZE(soc_types) || !soc_types[proc_id]) {
+        error_report("Unsupported processor id '%d' (board revision: 0x%x)",
+                     proc_id, board_rev);
+        exit(1);
+    }
+    return soc_types[proc_id];
+}
+
 static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info)
 {
     static const uint32_t smpboot[] = {
@@ -212,8 +227,7 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
     }
 
     object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
-                            version == 3 ? TYPE_BCM2837 : TYPE_BCM2836,
-                            &error_abort, NULL);
+                            board_soc_type(board_rev), &error_abort, NULL);
 
     /* Allocate and map RAM */
     memory_region_allocate_system_memory(&s->ram, OBJECT(machine), "ram",
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 06/30] hw/arm/raspi: Trivial code movement
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 05/30] hw/arm/raspi: Extract the processor type " Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass Philippe Mathieu-Daudé
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, open list:Trivial patches, Joaquin de Andres,
	Michael Tokarev, Philippe Mathieu-Daudé,
	Andrew Baumann, Laurent Vivier, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

There is no point in creating the SoC object before allocating the RAM.
Move the call to keep all the SoC-related calls together.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 20195227eb..fab361939c 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -226,9 +226,6 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
         exit(1);
     }
 
-    object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
-                            board_soc_type(board_rev), &error_abort, NULL);
-
     /* Allocate and map RAM */
     memory_region_allocate_system_memory(&s->ram, OBJECT(machine), "ram",
                                          machine->ram_size);
@@ -236,6 +233,8 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
     memory_region_add_subregion_overlap(get_system_memory(), 0, &s->ram, 0);
 
     /* Setup the SOC */
+    object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
+                            board_soc_type(board_rev), &error_abort, NULL);
     object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram),
                                    &error_abort);
     object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev",
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 06/30] hw/arm/raspi: Trivial code movement Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06 12:24   ` BALATON Zoltan
  2020-02-06  1:17 ` [PATCH v2 08/30] hw/arm/raspi: Make board_rev a field of RaspiMachineClass Philippe Mathieu-Daudé
                   ` (22 subsequent siblings)
  29 siblings, 1 reply; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm, Igor Mammedov,
	Philippe Mathieu-Daudé

QOM'ify RaspiMachineState. Now machines inherite of RaspiMachineClass.

Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 56 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 49 insertions(+), 7 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index fab361939c..edf3e1c0d5 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -33,10 +33,28 @@
 
 #define MACH_TYPE_BCM2708   3138 /* Linux board IDs */
 
-typedef struct RasPiState {
+typedef struct RaspiMachineState {
+    /*< private >*/
+    MachineState parent_obj;
+    /*< public >*/
     BCM283XState soc;
     MemoryRegion ram;
-} RasPiState;
+} RaspiMachineState;
+
+typedef struct RaspiMachineClass {
+    /*< private >*/
+    MachineClass parent_obj;
+    /*< public >*/
+} RaspiMachineClass;
+
+#define TYPE_RASPI_MACHINE       MACHINE_TYPE_NAME("raspi-common")
+#define RASPI_MACHINE(obj) \
+    OBJECT_CHECK(RaspiMachineState, (obj), TYPE_RASPI_MACHINE)
+
+#define RASPI_MACHINE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(RaspiMachineClass, (klass), TYPE_RASPI_MACHINE)
+#define RASPI_MACHINE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(RaspiMachineClass, (obj), TYPE_RASPI_MACHINE)
 
 /*
  * Board revision codes:
@@ -210,7 +228,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
 
 static void raspi_init(MachineState *machine, uint32_t board_rev)
 {
-    RasPiState *s = g_new0(RasPiState, 1);
+    RaspiMachineState *s = RASPI_MACHINE(machine);
     int version = board_version(board_rev);
     uint64_t ram_size = board_ram_size(board_rev);
     uint32_t vcram_size;
@@ -263,8 +281,10 @@ static void raspi2_init(MachineState *machine)
     raspi_init(machine, 0xa21041);
 }
 
-static void raspi2_machine_init(MachineClass *mc)
+static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
     mc->desc = "Raspberry Pi 2B";
     mc->init = raspi2_init;
     mc->block_default_type = IF_SD;
@@ -277,7 +297,6 @@ static void raspi2_machine_init(MachineClass *mc)
     mc->default_ram_size = 1 * GiB;
     mc->ignore_memory_transaction_failures = true;
 };
-DEFINE_MACHINE("raspi2", raspi2_machine_init)
 
 #ifdef TARGET_AARCH64
 static void raspi3_init(MachineState *machine)
@@ -285,8 +304,10 @@ static void raspi3_init(MachineState *machine)
     raspi_init(machine, 0xa02082);
 }
 
-static void raspi3_machine_init(MachineClass *mc)
+static void raspi3_machine_class_init(ObjectClass *oc, void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
+
     mc->desc = "Raspberry Pi 3B";
     mc->init = raspi3_init;
     mc->block_default_type = IF_SD;
@@ -298,5 +319,26 @@ static void raspi3_machine_init(MachineClass *mc)
     mc->default_cpus = BCM283X_NCPUS;
     mc->default_ram_size = 1 * GiB;
 }
-DEFINE_MACHINE("raspi3", raspi3_machine_init)
 #endif
+
+static const TypeInfo raspi_machine_types[] = {
+    {
+        .name           = MACHINE_TYPE_NAME("raspi2"),
+        .parent         = TYPE_RASPI_MACHINE,
+        .class_init     = raspi2_machine_class_init,
+#ifdef TARGET_AARCH64
+    }, {
+        .name           = MACHINE_TYPE_NAME("raspi3"),
+        .parent         = TYPE_RASPI_MACHINE,
+        .class_init     = raspi3_machine_class_init,
+#endif
+    }, {
+        .name           = TYPE_RASPI_MACHINE,
+        .parent         = TYPE_MACHINE,
+        .instance_size  = sizeof(RaspiMachineState),
+        .class_size     = sizeof(RaspiMachineClass),
+        .abstract       = true,
+    }
+};
+
+DEFINE_TYPES(raspi_machine_types)
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 08/30] hw/arm/raspi: Make board_rev a field of RaspiMachineClass
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 09/30] hw/arm/raspi: Let class_init() directly call raspi_machine_init() Philippe Mathieu-Daudé
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

We want to have a common class_init(). The only value that
matters (and changes) is the board revision.
Pass the board_rev as class_data to class_init().

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index edf3e1c0d5..885abced57 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -45,6 +45,7 @@ typedef struct RaspiMachineClass {
     /*< private >*/
     MachineClass parent_obj;
     /*< public >*/
+    uint32_t board_rev;
 } RaspiMachineClass;
 
 #define TYPE_RASPI_MACHINE       MACHINE_TYPE_NAME("raspi-common")
@@ -226,9 +227,11 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
     arm_load_kernel(ARM_CPU(first_cpu), machine, &binfo);
 }
 
-static void raspi_init(MachineState *machine, uint32_t board_rev)
+static void raspi_init(MachineState *machine)
 {
+    RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine);
     RaspiMachineState *s = RASPI_MACHINE(machine);
+    uint32_t board_rev = mc->board_rev;
     int version = board_version(board_rev);
     uint64_t ram_size = board_ram_size(board_rev);
     uint32_t vcram_size;
@@ -278,13 +281,16 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
 
 static void raspi2_init(MachineState *machine)
 {
-    raspi_init(machine, 0xa21041);
+    raspi_init(machine);
 }
 
 static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
+    uint32_t board_rev = (uint32_t)(uintptr_t)data;
 
+    rmc->board_rev = board_rev;
     mc->desc = "Raspberry Pi 2B";
     mc->init = raspi2_init;
     mc->block_default_type = IF_SD;
@@ -301,13 +307,16 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 #ifdef TARGET_AARCH64
 static void raspi3_init(MachineState *machine)
 {
-    raspi_init(machine, 0xa02082);
+    raspi_init(machine);
 }
 
 static void raspi3_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
+    uint32_t board_rev = (uint32_t)(uintptr_t)data;
 
+    rmc->board_rev = board_rev;
     mc->desc = "Raspberry Pi 3B";
     mc->init = raspi3_init;
     mc->block_default_type = IF_SD;
@@ -326,11 +335,13 @@ static const TypeInfo raspi_machine_types[] = {
         .name           = MACHINE_TYPE_NAME("raspi2"),
         .parent         = TYPE_RASPI_MACHINE,
         .class_init     = raspi2_machine_class_init,
+        .class_data     = (void *)0xa21041,
 #ifdef TARGET_AARCH64
     }, {
         .name           = MACHINE_TYPE_NAME("raspi3"),
         .parent         = TYPE_RASPI_MACHINE,
         .class_init     = raspi3_machine_class_init,
+        .class_data     = (void *)0xa02082,
 #endif
     }, {
         .name           = TYPE_RASPI_MACHINE,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 09/30] hw/arm/raspi: Let class_init() directly call raspi_machine_init()
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 08/30] hw/arm/raspi: Make board_rev a field of RaspiMachineClass Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 10/30] hw/arm/raspi: Set default RAM size to size encoded in board revision Philippe Mathieu-Daudé
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

raspi_machine_init() access to board_rev via RaspiMachineClass.
raspi2_init() and raspi3_init() do nothing. Call raspi_machine_init
directly.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Squash with previous?
---
 hw/arm/raspi.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 885abced57..651585ebfb 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -227,7 +227,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
     arm_load_kernel(ARM_CPU(first_cpu), machine, &binfo);
 }
 
-static void raspi_init(MachineState *machine)
+static void raspi_machine_init(MachineState *machine)
 {
     RaspiMachineClass *mc = RASPI_MACHINE_GET_CLASS(machine);
     RaspiMachineState *s = RASPI_MACHINE(machine);
@@ -279,11 +279,6 @@ static void raspi_init(MachineState *machine)
     setup_boot(machine, version, machine->ram_size - vcram_size);
 }
 
-static void raspi2_init(MachineState *machine)
-{
-    raspi_init(machine);
-}
-
 static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -292,7 +287,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 
     rmc->board_rev = board_rev;
     mc->desc = "Raspberry Pi 2B";
-    mc->init = raspi2_init;
+    mc->init = raspi_machine_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
     mc->no_floppy = 1;
@@ -305,11 +300,6 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
 };
 
 #ifdef TARGET_AARCH64
-static void raspi3_init(MachineState *machine)
-{
-    raspi_init(machine);
-}
-
 static void raspi3_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -318,7 +308,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data)
 
     rmc->board_rev = board_rev;
     mc->desc = "Raspberry Pi 3B";
-    mc->init = raspi3_init;
+    mc->init = raspi_machine_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
     mc->no_floppy = 1;
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 10/30] hw/arm/raspi: Set default RAM size to size encoded in board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 09/30] hw/arm/raspi: Let class_init() directly call raspi_machine_init() Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 11/30] hw/arm/raspi: Extract the board model from the " Philippe Mathieu-Daudé
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

We added a helper to extract the RAM size from the board
revision, and made board_rev a field of RaspiMachineClass.
The class_init() can now use the helper to extract from the
board revision the board-specific amount of RAM.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 651585ebfb..43f8b1d677 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -295,7 +295,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = BCM283X_NCPUS;
     mc->min_cpus = BCM283X_NCPUS;
     mc->default_cpus = BCM283X_NCPUS;
-    mc->default_ram_size = 1 * GiB;
+    mc->default_ram_size = board_ram_size(board_rev);
     mc->ignore_memory_transaction_failures = true;
 };
 
@@ -316,7 +316,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data)
     mc->max_cpus = BCM283X_NCPUS;
     mc->min_cpus = BCM283X_NCPUS;
     mc->default_cpus = BCM283X_NCPUS;
-    mc->default_ram_size = 1 * GiB;
+    mc->default_ram_size = board_ram_size(board_rev);
 }
 #endif
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 11/30] hw/arm/raspi: Extract the board model from the board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 10/30] hw/arm/raspi: Set default RAM size to size encoded in board revision Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 12/30] hw/arm/raspi: Use a unique raspi_machine_class_init() method Philippe Mathieu-Daudé
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The board revision encode the model type. Add a helper
to extract the model, and use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 43f8b1d677..a104393cb2 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -100,6 +100,20 @@ static const char *board_soc_type(uint32_t board_rev)
     return soc_types[proc_id];
 }
 
+static const char *board_type(uint32_t board_rev)
+{
+    static const char *types[] = {
+        "A", "B", "A+", "B+", "2B", "Alpha", "CM1", NULL, "3B", "Zero",
+        "CM3", NULL, "Zero W", "3B+", "3A+", NULL, "CM3+", "4B",
+    };
+    assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
+    int bt = FIELD_EX32(board_rev, REV_CODE, TYPE);
+    if (bt >= ARRAY_SIZE(types) || !types[bt]) {
+        return "Unknown";
+    }
+    return types[bt];
+}
+
 static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info)
 {
     static const uint32_t smpboot[] = {
@@ -286,7 +300,7 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
     uint32_t board_rev = (uint32_t)(uintptr_t)data;
 
     rmc->board_rev = board_rev;
-    mc->desc = "Raspberry Pi 2B";
+    mc->desc = g_strdup_printf("Raspberry Pi %s", board_type(board_rev));
     mc->init = raspi_machine_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
@@ -307,7 +321,7 @@ static void raspi3_machine_class_init(ObjectClass *oc, void *data)
     uint32_t board_rev = (uint32_t)(uintptr_t)data;
 
     rmc->board_rev = board_rev;
-    mc->desc = "Raspberry Pi 3B";
+    mc->desc = g_strdup_printf("Raspberry Pi %s", board_type(board_rev));
     mc->init = raspi_machine_init;
     mc->block_default_type = IF_SD;
     mc->no_parallel = 1;
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 12/30] hw/arm/raspi: Use a unique raspi_machine_class_init() method
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 11/30] hw/arm/raspi: Extract the board model from the " Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 13/30] hw/arm/raspi: Extract the cores count from the board revision Philippe Mathieu-Daudé
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

With the exception of the ignore_memory_transaction_failures
flag set for the raspi2, both machine_class_init() methods
are now identical. Merge them to keep a unique method.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/arm/raspi.c | 31 ++++++-------------------------
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index a104393cb2..8fe07db47a 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -293,7 +293,7 @@ static void raspi_machine_init(MachineState *machine)
     setup_boot(machine, version, machine->ram_size - vcram_size);
 }
 
-static void raspi2_machine_class_init(ObjectClass *oc, void *data)
+static void raspi_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
@@ -310,41 +310,22 @@ static void raspi2_machine_class_init(ObjectClass *oc, void *data)
     mc->min_cpus = BCM283X_NCPUS;
     mc->default_cpus = BCM283X_NCPUS;
     mc->default_ram_size = board_ram_size(board_rev);
-    mc->ignore_memory_transaction_failures = true;
+    if (board_version(board_rev) == 2) {
+        mc->ignore_memory_transaction_failures = true;
+    }
 };
 
-#ifdef TARGET_AARCH64
-static void raspi3_machine_class_init(ObjectClass *oc, void *data)
-{
-    MachineClass *mc = MACHINE_CLASS(oc);
-    RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
-    uint32_t board_rev = (uint32_t)(uintptr_t)data;
-
-    rmc->board_rev = board_rev;
-    mc->desc = g_strdup_printf("Raspberry Pi %s", board_type(board_rev));
-    mc->init = raspi_machine_init;
-    mc->block_default_type = IF_SD;
-    mc->no_parallel = 1;
-    mc->no_floppy = 1;
-    mc->no_cdrom = 1;
-    mc->max_cpus = BCM283X_NCPUS;
-    mc->min_cpus = BCM283X_NCPUS;
-    mc->default_cpus = BCM283X_NCPUS;
-    mc->default_ram_size = board_ram_size(board_rev);
-}
-#endif
-
 static const TypeInfo raspi_machine_types[] = {
     {
         .name           = MACHINE_TYPE_NAME("raspi2"),
         .parent         = TYPE_RASPI_MACHINE,
-        .class_init     = raspi2_machine_class_init,
+        .class_init     = raspi_machine_class_init,
         .class_data     = (void *)0xa21041,
 #ifdef TARGET_AARCH64
     }, {
         .name           = MACHINE_TYPE_NAME("raspi3"),
         .parent         = TYPE_RASPI_MACHINE,
-        .class_init     = raspi3_machine_class_init,
+        .class_init     = raspi_machine_class_init,
         .class_data     = (void *)0xa02082,
 #endif
     }, {
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 13/30] hw/arm/raspi: Extract the cores count from the board revision
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (11 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 12/30] hw/arm/raspi: Use a unique raspi_machine_class_init() method Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 14/30] hw/arm/bcm2836: Restrict BCM283XClass declaration to C source Philippe Mathieu-Daudé
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The board revision encode the count of ARM cores. Add a helper
to extract the number of cores, and use it. This will be helpful
when we add the Raspi0/1 that have a single core.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 8fe07db47a..4f7e5ecfab 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -100,6 +100,21 @@ static const char *board_soc_type(uint32_t board_rev)
     return soc_types[proc_id];
 }
 
+static int cores_count(uint32_t board_rev)
+{
+    static const int soc_cores_count[] = {
+        0, BCM283X_NCPUS, BCM283X_NCPUS,
+    };
+    int proc_id = board_processor_id(board_rev);
+
+    if (proc_id >= ARRAY_SIZE(soc_cores_count) || !soc_cores_count[proc_id]) {
+        error_report("Unsupported processor id '%d' (board revision: 0x%x)",
+                     proc_id, board_rev);
+        exit(1);
+    }
+    return soc_cores_count[proc_id];
+}
+
 static const char *board_type(uint32_t board_rev)
 {
     static const char *types[] = {
@@ -306,9 +321,7 @@ static void raspi_machine_class_init(ObjectClass *oc, void *data)
     mc->no_parallel = 1;
     mc->no_floppy = 1;
     mc->no_cdrom = 1;
-    mc->max_cpus = BCM283X_NCPUS;
-    mc->min_cpus = BCM283X_NCPUS;
-    mc->default_cpus = BCM283X_NCPUS;
+    mc->default_cpus = mc->min_cpus = mc->max_cpus = cores_count(board_rev);
     mc->default_ram_size = board_ram_size(board_rev);
     if (board_version(board_rev) == 2) {
         mc->ignore_memory_transaction_failures = true;
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 14/30] hw/arm/bcm2836: Restrict BCM283XClass declaration to C source
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (12 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 13/30] hw/arm/raspi: Extract the cores count from the board revision Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 15/30] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type Philippe Mathieu-Daudé
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

No code out of bcm2836.c uses (or requires) this declarations.
Move it locally to the C source file.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/arm/bcm2836.h | 12 ------------
 hw/arm/bcm2836.c         | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
index 92a6544816..acc75bf553 100644
--- a/include/hw/arm/bcm2836.h
+++ b/include/hw/arm/bcm2836.h
@@ -42,16 +42,4 @@ typedef struct BCM283XState {
     BCM2835PeripheralState peripherals;
 } BCM283XState;
 
-typedef struct BCM283XInfo BCM283XInfo;
-
-typedef struct BCM283XClass {
-    DeviceClass parent_class;
-    const BCM283XInfo *info;
-} BCM283XClass;
-
-#define BCM283X_CLASS(klass) \
-    OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
-#define BCM283X_GET_CLASS(obj) \
-    OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
-
 #endif /* BCM2836_H */
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 38e2941bab..24109fef1d 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -16,6 +16,15 @@
 #include "hw/arm/raspi_platform.h"
 #include "hw/sysbus.h"
 
+typedef struct BCM283XInfo BCM283XInfo;
+
+typedef struct BCM283XClass {
+    /*< private >*/
+    DeviceClass parent_class;
+    /*< public >*/
+    const BCM283XInfo *info;
+} BCM283XClass;
+
 struct BCM283XInfo {
     const char *name;
     const char *cpu_type;
@@ -24,6 +33,11 @@ struct BCM283XInfo {
     int clusterid;
 };
 
+#define BCM283X_CLASS(klass) \
+    OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
+#define BCM283X_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
+
 static const BCM283XInfo bcm283x_socs[] = {
     {
         .name = TYPE_BCM2836,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 15/30] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (13 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 14/30] hw/arm/bcm2836: Restrict BCM283XClass declaration to C source Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 16/30] hw/arm/bcm2836: Introduce BCM283XClass::core_count Philippe Mathieu-Daudé
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm, Igor Mammedov,
	Philippe Mathieu-Daudé

Remove usage of TypeInfo::class_data. Instead fill the fields in
the corresponding class_init().

Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 109 ++++++++++++++++++++++-------------------------
 1 file changed, 51 insertions(+), 58 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 24109fef1d..683d04d6ea 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -16,57 +16,30 @@
 #include "hw/arm/raspi_platform.h"
 #include "hw/sysbus.h"
 
-typedef struct BCM283XInfo BCM283XInfo;
-
 typedef struct BCM283XClass {
     /*< private >*/
     DeviceClass parent_class;
     /*< public >*/
-    const BCM283XInfo *info;
-} BCM283XClass;
-
-struct BCM283XInfo {
-    const char *name;
     const char *cpu_type;
     hwaddr peri_base; /* Peripheral base address seen by the CPU */
     hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
     int clusterid;
-};
+} BCM283XClass;
 
 #define BCM283X_CLASS(klass) \
     OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
 #define BCM283X_GET_CLASS(obj) \
     OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
 
-static const BCM283XInfo bcm283x_socs[] = {
-    {
-        .name = TYPE_BCM2836,
-        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
-        .peri_base = 0x3f000000,
-        .ctrl_base = 0x40000000,
-        .clusterid = 0xf,
-    },
-#ifdef TARGET_AARCH64
-    {
-        .name = TYPE_BCM2837,
-        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
-        .peri_base = 0x3f000000,
-        .ctrl_base = 0x40000000,
-        .clusterid = 0x0,
-    },
-#endif
-};
-
 static void bcm2836_init(Object *obj)
 {
     BCM283XState *s = BCM283X(obj);
     BCM283XClass *bc = BCM283X_GET_CLASS(obj);
-    const BCM283XInfo *info = bc->info;
     int n;
 
     for (n = 0; n < BCM283X_NCPUS; n++) {
         object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
-                                sizeof(s->cpu[n].core), info->cpu_type,
+                                sizeof(s->cpu[n].core), bc->cpu_type,
                                 &error_abort, NULL);
     }
 
@@ -85,7 +58,6 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 {
     BCM283XState *s = BCM283X(dev);
     BCM283XClass *bc = BCM283X_GET_CLASS(dev);
-    const BCM283XInfo *info = bc->info;
     Object *obj;
     Error *err = NULL;
     int n;
@@ -119,7 +91,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
     }
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
-                            info->peri_base, 1);
+                            bc->peri_base, 1);
 
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
@@ -128,7 +100,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
 
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
         qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
@@ -137,11 +109,11 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 
     for (n = 0; n < BCM283X_NCPUS; n++) {
         /* TODO: this should be converted to a property of ARM_CPU */
-        s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n;
+        s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
 
         /* set periphbase/CBAR value for CPU-local registers */
         object_property_set_int(OBJECT(&s->cpu[n].core),
-                                info->peri_base,
+                                bc->peri_base,
                                 "reset-cbar", &err);
         if (err) {
             error_propagate(errp, err);
@@ -190,38 +162,59 @@ static Property bcm2836_props[] = {
 static void bcm283x_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
-    BCM283XClass *bc = BCM283X_CLASS(oc);
 
-    bc->info = data;
-    dc->realize = bcm2836_realize;
-    device_class_set_props(dc, bcm2836_props);
     /* Reason: Must be wired up in code (see raspi_init() function) */
     dc->user_creatable = false;
 }
 
-static const TypeInfo bcm283x_type_info = {
-    .name = TYPE_BCM283X,
-    .parent = TYPE_DEVICE,
-    .instance_size = sizeof(BCM283XState),
-    .instance_init = bcm2836_init,
-    .class_size = sizeof(BCM283XClass),
-    .abstract = true,
+static void bcm2836_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
+
+    bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
+    bc->peri_base = 0x3f000000;
+    bc->ctrl_base = 0x40000000;
+    bc->clusterid = 0xf;
+    dc->realize = bcm2836_realize;
+    device_class_set_props(dc, bcm2836_props);
 };
 
-static void bcm2836_register_types(void)
+#ifdef TARGET_AARCH64
+static void bcm2837_class_init(ObjectClass *oc, void *data)
 {
-    int i;
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
 
-    type_register_static(&bcm283x_type_info);
-    for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) {
-        TypeInfo ti = {
-            .name = bcm283x_socs[i].name,
-            .parent = TYPE_BCM283X,
-            .class_init = bcm283x_class_init,
-            .class_data = (void *) &bcm283x_socs[i],
-        };
-        type_register(&ti);
+    bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
+    bc->peri_base = 0x3f000000;
+    bc->ctrl_base = 0x40000000;
+    bc->clusterid = 0x0;
+    dc->realize = bcm2836_realize;
+    device_class_set_props(dc, bcm2836_props);
+};
+#endif
+
+static const TypeInfo bcm283x_types[] = {
+    {
+        .name           = TYPE_BCM2836,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2836_class_init,
+#ifdef TARGET_AARCH64
+    }, {
+        .name           = TYPE_BCM2837,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2837_class_init,
+#endif
+    }, {
+        .name           = TYPE_BCM283X,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(BCM283XState),
+        .instance_init  = bcm2836_init,
+        .class_size     = sizeof(BCM283XClass),
+        .class_init     = bcm283x_class_init,
+        .abstract       = true,
     }
-}
+};
 
-type_init(bcm2836_register_types)
+DEFINE_TYPES(bcm283x_types)
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 16/30] hw/arm/bcm2836: Introduce BCM283XClass::core_count
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (14 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 15/30] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 17/30] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Philippe Mathieu-Daudé
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The BCM2835 has only one core. Introduce the core_count field to
be able to use values different than BCM283X_NCPUS (4).

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 683d04d6ea..3b95ad11e9 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -21,6 +21,7 @@ typedef struct BCM283XClass {
     DeviceClass parent_class;
     /*< public >*/
     const char *cpu_type;
+    int core_count;
     hwaddr peri_base; /* Peripheral base address seen by the CPU */
     hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
     int clusterid;
@@ -37,7 +38,7 @@ static void bcm2836_init(Object *obj)
     BCM283XClass *bc = BCM283X_GET_CLASS(obj);
     int n;
 
-    for (n = 0; n < BCM283X_NCPUS; n++) {
+    for (n = 0; n < bc->core_count; n++) {
         object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
                                 sizeof(s->cpu[n].core), bc->cpu_type,
                                 &error_abort, NULL);
@@ -107,7 +108,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1,
         qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0));
 
-    for (n = 0; n < BCM283X_NCPUS; n++) {
+    for (n = 0; n < bc->core_count; n++) {
         /* TODO: this should be converted to a property of ARM_CPU */
         s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
 
@@ -173,6 +174,7 @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
     BCM283XClass *bc = BCM283X_CLASS(oc);
 
     bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
+    bc->core_count = BCM283X_NCPUS;
     bc->peri_base = 0x3f000000;
     bc->ctrl_base = 0x40000000;
     bc->clusterid = 0xf;
@@ -187,6 +189,7 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
     BCM283XClass *bc = BCM283X_CLASS(oc);
 
     bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
+    bc->core_count = BCM283X_NCPUS;
     bc->peri_base = 0x3f000000;
     bc->ctrl_base = 0x40000000;
     bc->clusterid = 0x0;
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 17/30] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (15 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 16/30] hw/arm/bcm2836: Introduce BCM283XClass::core_count Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 18/30] hw/arm/bcm2836: Split out common realize() code Philippe Mathieu-Daudé
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

It makes no sense to set enabled-cpus=0 on single core SoCs.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 3b95ad11e9..caaa4b625e 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -32,6 +32,9 @@ typedef struct BCM283XClass {
 #define BCM283X_GET_CLASS(obj) \
     OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
 
+static Property bcm2836_enabled_cores_property =
+    DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0);
+
 static void bcm2836_init(Object *obj)
 {
     BCM283XState *s = BCM283X(obj);
@@ -43,6 +46,10 @@ static void bcm2836_init(Object *obj)
                                 sizeof(s->cpu[n].core), bc->cpu_type,
                                 &error_abort, NULL);
     }
+    if (bc->core_count) {
+        qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property);
+        qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
+    }
 
     sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
                           TYPE_BCM2836_CONTROL);
@@ -154,12 +161,6 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
     }
 }
 
-static Property bcm2836_props[] = {
-    DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus,
-                       BCM283X_NCPUS),
-    DEFINE_PROP_END_OF_LIST()
-};
-
 static void bcm283x_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
@@ -179,7 +180,6 @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
     bc->ctrl_base = 0x40000000;
     bc->clusterid = 0xf;
     dc->realize = bcm2836_realize;
-    device_class_set_props(dc, bcm2836_props);
 };
 
 #ifdef TARGET_AARCH64
@@ -194,7 +194,6 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
     bc->ctrl_base = 0x40000000;
     bc->clusterid = 0x0;
     dc->realize = bcm2836_realize;
-    device_class_set_props(dc, bcm2836_props);
 };
 #endif
 
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 18/30] hw/arm/bcm2836: Split out common realize() code
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (16 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 17/30] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 19/30] hw/arm/bcm2836: Introduce the BCM2835 SoC Philippe Mathieu-Daudé
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

The realize() function is clearly composed of two parts,
each described by a comment:

  void realize()
  {
     /* common peripherals from bcm2835 */
     ...
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     ...
   }

Split the two part, so we can reuse the common part with other
SoCs from this family.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index caaa4b625e..2b6fe31139 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -51,8 +51,10 @@ static void bcm2836_init(Object *obj)
         qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
     }
 
-    sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
-                          TYPE_BCM2836_CONTROL);
+    if (bc->ctrl_base) {
+        sysbus_init_child_obj(obj, "control", &s->control,
+                              sizeof(s->control), TYPE_BCM2836_CONTROL);
+    }
 
     sysbus_init_child_obj(obj, "peripherals", &s->peripherals,
                           sizeof(s->peripherals), TYPE_BCM2835_PERIPHERALS);
@@ -62,13 +64,12 @@ static void bcm2836_init(Object *obj)
                               "vcram-size", &error_abort);
 }
 
-static void bcm2836_realize(DeviceState *dev, Error **errp)
+static void bcm283x_common_realize(DeviceState *dev, Error **errp)
 {
     BCM283XState *s = BCM283X(dev);
     BCM283XClass *bc = BCM283X_GET_CLASS(dev);
     Object *obj;
     Error *err = NULL;
-    int n;
 
     /* common peripherals from bcm2835 */
 
@@ -100,6 +101,20 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
                             bc->peri_base, 1);
+}
+
+static void bcm2836_realize(DeviceState *dev, Error **errp)
+{
+    BCM283XState *s = BCM283X(dev);
+    BCM283XClass *bc = BCM283X_GET_CLASS(dev);
+    Error *err = NULL;
+    int n;
+
+    bcm283x_common_realize(dev, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
 
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 19/30] hw/arm/bcm2836: Introduce the BCM2835 SoC
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (17 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 18/30] hw/arm/bcm2836: Split out common realize() code Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 20/30] hw/arm/raspi: Add the Raspberry Pi Zero machine Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/arm/bcm2836.h |  1 +
 hw/arm/bcm2836.c         | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
index acc75bf553..3d46469a73 100644
--- a/include/hw/arm/bcm2836.h
+++ b/include/hw/arm/bcm2836.h
@@ -24,6 +24,7 @@
  * them, code using these devices should always handle them via the
  * BCM283x base class, so they have no BCM2836(obj) etc macros.
  */
+#define TYPE_BCM2835 "bcm2835"
 #define TYPE_BCM2836 "bcm2836"
 #define TYPE_BCM2837 "bcm2837"
 
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 2b6fe31139..bce5f8a866 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -103,6 +103,31 @@ static void bcm283x_common_realize(DeviceState *dev, Error **errp)
                             bc->peri_base, 1);
 }
 
+static void bcm2835_realize(DeviceState *dev, Error **errp)
+{
+    BCM283XState *s = BCM283X(dev);
+    Error *err = NULL;
+
+    bcm283x_common_realize(dev, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_bool(OBJECT(&s->cpu[0].core), true,
+                             "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    /* Connect irq/fiq outputs from the interrupt controller. */
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
+            qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1,
+            qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ));
+}
+
 static void bcm2836_realize(DeviceState *dev, Error **errp)
 {
     BCM283XState *s = BCM283X(dev);
@@ -184,6 +209,17 @@ static void bcm283x_class_init(ObjectClass *oc, void *data)
     dc->user_creatable = false;
 }
 
+static void bcm2835_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
+
+    bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176");
+    bc->core_count = 1;
+    bc->peri_base = 0x20000000;
+    dc->realize = bcm2835_realize;
+};
+
 static void bcm2836_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
@@ -214,6 +250,10 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo bcm283x_types[] = {
     {
+        .name           = TYPE_BCM2835,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2835_class_init,
+    }, {
         .name           = TYPE_BCM2836,
         .parent         = TYPE_BCM283X,
         .class_init     = bcm2836_class_init,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 20/30] hw/arm/raspi: Add the Raspberry Pi Zero machine
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (18 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 19/30] hw/arm/bcm2836: Introduce the BCM2835 SoC Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 21/30] hw/arm/raspi: Add the Raspberry Pi B+ machine Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

Add a Raspberry Pi Zero machine.

  $ qemu-system-arm -M raspi0 -serial stdio \
      -kernel raspberrypi/firmware/boot/kernel.img \
      -dtb raspberrypi/firmware/boot/bcm2708-rpi-zero-w.dtb \
      -append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0'
  [    0.000000] Booting Linux on physical CPU 0x0
  [    0.000000] Linux version 4.19.69+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1261 Tue Sep 3 20:21:01 BST 2019
  [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  [    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W
  [    0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
  [    0.000000] bootconsole [pl11] enabled
  [    0.000000] Memory policy: Data cache writeback
  [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  [    0.000000] random: get_random_bytes called from start_kernel+0x8c/0x49c with crng_init=0
  [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  [    0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0 root=/dev/mmcblk0 rootwait
  Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
  Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
  Memory: 434380K/458752K available (6971K kernel code, 635K rwdata, 2080K rodata, 464K init, 797K bss, 16180K reserved, 8192K cma-reserved)
  Virtual kernel memory layout:
      vector  : 0xffff0000 - 0xffff1000   (   4 kB)
      fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
      vmalloc : 0xdc800000 - 0xff800000   ( 560 MB)
      lowmem  : 0xc0000000 - 0xdc000000   ( 448 MB)
      modules : 0xbf000000 - 0xc0000000   (  16 MB)
        .text : 0x(ptrval) - 0x(ptrval)   (6973 kB)
        .init : 0x(ptrval) - 0x(ptrval)   ( 464 kB)
        .data : 0x(ptrval) - 0x(ptrval)   ( 636 kB)
         .bss : 0x(ptrval) - 0x(ptrval)   ( 798 kB)
  SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
  ftrace: allocating 25193 entries in 74 pages
  NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
  sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
  clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
  bcm2835: system timer (irq = 27)
  Console: colour dummy device 80x30
  ...

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
TODO: Add acceptance test
---
 hw/arm/raspi.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 4f7e5ecfab..0d1f15e08c 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -88,7 +88,7 @@ static int board_version(uint32_t board_rev)
 static const char *board_soc_type(uint32_t board_rev)
 {
     static const char *soc_types[] = {
-        NULL, TYPE_BCM2836, TYPE_BCM2837,
+        TYPE_BCM2835, TYPE_BCM2836, TYPE_BCM2837,
     };
     int proc_id = board_processor_id(board_rev);
 
@@ -103,7 +103,7 @@ static const char *board_soc_type(uint32_t board_rev)
 static int cores_count(uint32_t board_rev)
 {
     static const int soc_cores_count[] = {
-        0, BCM283X_NCPUS, BCM283X_NCPUS,
+        1, BCM283X_NCPUS, BCM283X_NCPUS,
     };
     int proc_id = board_processor_id(board_rev);
 
@@ -330,6 +330,11 @@ static void raspi_machine_class_init(ObjectClass *oc, void *data)
 
 static const TypeInfo raspi_machine_types[] = {
     {
+        .name           = MACHINE_TYPE_NAME("raspi0"),
+        .parent         = TYPE_RASPI_MACHINE,
+        .class_init     = raspi_machine_class_init,
+        .class_data     = (void *)0x9000c1,
+    }, {
         .name           = MACHINE_TYPE_NAME("raspi2"),
         .parent         = TYPE_RASPI_MACHINE,
         .class_init     = raspi_machine_class_init,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 21/30] hw/arm/raspi: Add the Raspberry Pi B+ machine
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (19 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 20/30] hw/arm/raspi: Add the Raspberry Pi Zero machine Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 22/30] tests/acceptance/boot_linux_console: Use raspi console model as key Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

  $ qemu-system-arm -M raspi1 -serial stdio \
      -kernel raspberrypi/firmware/boot/kernel.img \
      -dtb raspberrypi/firmware/boot/bcm2708-rpi-b.dtb \
      -append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0'
  [    0.000000] Booting Linux on physical CPU 0x0
  [    0.000000] Linux version 4.19.69+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1261 Tue Sep 3 20:21:01 BST 2019
  [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  [    0.000000] OF: fdt: Machine model: Raspberry Pi Model B
  [    0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
  [    0.000000] bootconsole [pl11] enabled
  [    0.000000] Memory policy: Data cache writeback
  [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  [    0.000000] random: get_random_bytes called from start_kernel+0x8c/0x49c with crng_init=0
  [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  [    0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0
  Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
  Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
  Memory: 434380K/458752K available (6971K kernel code, 635K rwdata, 2080K rodata, 464K init, 797K bss, 16180K reserved, 8192K cma-reserved)
  ...

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 0d1f15e08c..47cc250883 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -334,6 +334,11 @@ static const TypeInfo raspi_machine_types[] = {
         .parent         = TYPE_RASPI_MACHINE,
         .class_init     = raspi_machine_class_init,
         .class_data     = (void *)0x9000c1,
+    }, {
+        .name           = MACHINE_TYPE_NAME("raspi1"),
+        .parent         = TYPE_RASPI_MACHINE,
+        .class_init     = raspi_machine_class_init,
+        .class_data     = (void *)0x900032,
     }, {
         .name           = MACHINE_TYPE_NAME("raspi2"),
         .parent         = TYPE_RASPI_MACHINE,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 22/30] tests/acceptance/boot_linux_console: Use raspi console model as key
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (20 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 21/30] hw/arm/raspi: Add the Raspberry Pi B+ machine Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 23/30] tests/acceptance/boot_linux_console: Add raspi version=2 parameter Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

Python dictionary are not that expensive. Use a key makes the
code easier to review.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index e40b84651b..5fba46a9d1 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -325,14 +325,14 @@ class BootLinuxConsole(Test):
         self.vm.launch()
         self.wait_for_console_pattern('init started: BusyBox')
 
-    def do_test_arm_raspi2(self, uart_id):
+    def do_test_arm_raspi2(self, uart_model):
         """
         The kernel can be rebuilt using the kernel source referenced
         and following the instructions on the on:
         https://www.raspberrypi.org/documentation/linux/kernel/building.md
         """
         serial_kernel_cmdline = {
-            0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
+            'pl011': 'earlycon=pl011,0x3f201000 console=ttyAMA0',
         }
         deb_url = ('http://archive.raspberrypi.org/debian/'
                    'pool/main/r/raspberrypi-firmware/'
@@ -344,7 +344,7 @@ class BootLinuxConsole(Test):
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
-                               serial_kernel_cmdline[uart_id])
+                               serial_kernel_cmdline[uart_model])
         self.vm.add_args('-kernel', kernel_path,
                          '-dtb', dtb_path,
                          '-append', kernel_command_line)
@@ -358,7 +358,7 @@ class BootLinuxConsole(Test):
         :avocado: tags=machine:raspi2
         :avocado: tags=device:pl011
         """
-        self.do_test_arm_raspi2(0)
+        self.do_test_arm_raspi2('pl011')
 
     def test_arm_exynos4210_initrd(self):
         """
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 23/30] tests/acceptance/boot_linux_console: Add raspi version=2 parameter
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (21 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 22/30] tests/acceptance/boot_linux_console: Use raspi console model as key Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 24/30] tests/acceptance/boot_linux_console: Test the raspi1 console Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

We want to tests different Raspberry Pi machines. Refactor to
take the board version as argument.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 5fba46a9d1..56c8d54ca6 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -325,26 +325,34 @@ class BootLinuxConsole(Test):
         self.vm.launch()
         self.wait_for_console_pattern('init started: BusyBox')
 
-    def do_test_arm_raspi2(self, uart_model):
+    def do_test_arm_raspi(self, version, uart_model):
         """
         The kernel can be rebuilt using the kernel source referenced
         and following the instructions on the on:
         https://www.raspberrypi.org/documentation/linux/kernel/building.md
         """
         serial_kernel_cmdline = {
-            'pl011': 'earlycon=pl011,0x3f201000 console=ttyAMA0',
+            'pl011': {
+                2: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
+            },
+        }
+        kernel = {
+            2: '/boot/kernel7.img',
+        }
+        dtb = {
+            2: '/boot/bcm2709-rpi-2-b.dtb',
         }
         deb_url = ('http://archive.raspberrypi.org/debian/'
                    'pool/main/r/raspberrypi-firmware/'
                    'raspberrypi-kernel_1.20190215-1_armhf.deb')
         deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
         deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
-        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
-        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
+        kernel_path = self.extract_from_deb(deb_path, kernel[version])
+        dtb_path = self.extract_from_deb(deb_path, dtb[version])
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
-                               serial_kernel_cmdline[uart_model])
+                               serial_kernel_cmdline[uart_model][version])
         self.vm.add_args('-kernel', kernel_path,
                          '-dtb', dtb_path,
                          '-append', kernel_command_line)
@@ -356,9 +364,10 @@ class BootLinuxConsole(Test):
         """
         :avocado: tags=arch:arm
         :avocado: tags=machine:raspi2
+        :avocado: tags=cpu:cortex-a7
         :avocado: tags=device:pl011
         """
-        self.do_test_arm_raspi2('pl011')
+        self.do_test_arm_raspi(2, 'pl011')
 
     def test_arm_exynos4210_initrd(self):
         """
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 24/30] tests/acceptance/boot_linux_console: Test the raspi1 console
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (22 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 23/30] tests/acceptance/boot_linux_console: Add raspi version=2 parameter Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 25/30] tests/acceptance/boot_linux_console: Test the raspi0 console Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

  $ avocado --show=app,console run -t machine:raspi1 tests/acceptance/
  JOB ID     : c49310d4a21444f03789cd2c443d8c54a29ffd0a
  JOB LOG    : avocado/job-results/job-2020-02-05T23.52-c49310d/job.log
   (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi1_uart0:
  console: [    0.000000] Booting Linux on physical CPU 0x0
  console: [    0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019
  console: [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  console: [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  console: [    0.000000] OF: fdt: Machine model: Raspberry Pi Model B
  console: [    0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
  console: [    0.000000] bootconsole [pl11] enabled
  console: [    0.000000] Memory policy: Data cache writeback
  console: [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  console: [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  console: [    0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0
  PASS (12.93 s)
  RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 13.18 s

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 56c8d54ca6..0371828326 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -333,13 +333,16 @@ class BootLinuxConsole(Test):
         """
         serial_kernel_cmdline = {
             'pl011': {
+                1: 'earlycon=pl011,0x20201000 console=ttyAMA0',
                 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
             },
         }
         kernel = {
+            1: '/boot/kernel.img',
             2: '/boot/kernel7.img',
         }
         dtb = {
+            1: '/boot/bcm2708-rpi-b.dtb',
             2: '/boot/bcm2709-rpi-2-b.dtb',
         }
         deb_url = ('http://archive.raspberrypi.org/debian/'
@@ -360,6 +363,15 @@ class BootLinuxConsole(Test):
         console_pattern = 'Kernel command line: %s' % kernel_command_line
         self.wait_for_console_pattern(console_pattern)
 
+    def test_arm_raspi1_uart0(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi1
+        :avocado: tags=cpu:arm1176
+        :avocado: tags=device:pl011
+        """
+        self.do_test_arm_raspi(1, 'pl011')
+
     def test_arm_raspi2_uart0(self):
         """
         :avocado: tags=arch:arm
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 25/30] tests/acceptance/boot_linux_console: Test the raspi0 console
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (23 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 24/30] tests/acceptance/boot_linux_console: Test the raspi1 console Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 26/30] python/qemu/machine: Allow to use other serial consoles than default Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

  $ avocado --show=app,console run -t machine:raspi0 tests/acceptance/
  JOB ID     : af8e017486290758bff39c986934134199af3556
  JOB LOG    : avocado/job-results/job-2020-02-05T23.53-af8e017/job.log
   (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi0_uart0:
  console: [    0.000000] Booting Linux on physical CPU 0x0
  console: [    0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019
  console: [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  console: [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  console: [    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W
  console: [    0.000000] earlycon: pl11 at MMIO 0x20201000 (options '')
  console: [    0.000000] bootconsole [pl11] enabled
  console: [    0.000000] Memory policy: Data cache writeback
  console: [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  console: [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  console: [    0.000000] Kernel command line: printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0
  PASS (12.59 s)
  RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 12.88 s

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 0371828326..df6600ab2f 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -333,15 +333,18 @@ class BootLinuxConsole(Test):
         """
         serial_kernel_cmdline = {
             'pl011': {
+                0: 'earlycon=pl011,0x20201000 console=ttyAMA0',
                 1: 'earlycon=pl011,0x20201000 console=ttyAMA0',
                 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
             },
         }
         kernel = {
+            0: '/boot/kernel.img',
             1: '/boot/kernel.img',
             2: '/boot/kernel7.img',
         }
         dtb = {
+            0: '/boot/bcm2708-rpi-0-w.dtb',
             1: '/boot/bcm2708-rpi-b.dtb',
             2: '/boot/bcm2709-rpi-2-b.dtb',
         }
@@ -363,6 +366,15 @@ class BootLinuxConsole(Test):
         console_pattern = 'Kernel command line: %s' % kernel_command_line
         self.wait_for_console_pattern(console_pattern)
 
+    def test_arm_raspi0_uart0(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi0
+        :avocado: tags=cpu:arm1176
+        :avocado: tags=device:pl011
+        """
+        self.do_test_arm_raspi(0, 'pl011')
+
     def test_arm_raspi1_uart0(self):
         """
         :avocado: tags=arch:arm
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 26/30] python/qemu/machine: Allow to use other serial consoles than default
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (24 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 25/30] tests/acceptance/boot_linux_console: Test the raspi0 console Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 27/30] tests/acceptance/boot_linux_console: Test the raspi1 AUX console Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Eduardo Habkost, Joaquin de Andres,
	Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Wainer dos Santos Moschetta, Cleber Rosa,
	Philippe Mathieu-Daudé

Currently the QEMU Python module limits the QEMUMachine class to
use the first serial console.

Some machines/guest might use another console than the first one as
the 'boot console'. For example the Raspberry Pi uses the second
(AUX) console.

To be able to use the Nth console as default, we simply need to
connect all the N - 1 consoles to the null chardev.

Add an index argument, so we can use a specific serial console as
default.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Tested-by: Liam Merwick <liam.merwick@oracle.com>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Message-Id: <20200120235159.18510-5-f4bug@amsat.org>
[PMD: zero-initialize _console_index in __init__()]
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 python/qemu/machine.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 734efd8536..183d8f3d38 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -112,6 +112,7 @@ class QEMUMachine(object):
         self._sock_dir = sock_dir
         self._launched = False
         self._machine = None
+        self._console_index = 0
         self._console_set = False
         self._console_device_type = None
         self._console_address = None
@@ -241,6 +242,8 @@ class QEMUMachine(object):
                          'chardev=mon,mode=control'])
         if self._machine is not None:
             args.extend(['-machine', self._machine])
+        for i in range(self._console_index):
+            args.extend(['-serial', 'null'])
         if self._console_set:
             self._console_address = os.path.join(self._sock_dir,
                                                  self._name + "-console.sock")
@@ -527,7 +530,7 @@ class QEMUMachine(object):
         """
         self._machine = machine_type
 
-    def set_console(self, device_type=None):
+    def set_console(self, device_type=None, console_index=0):
         """
         Sets the device type for a console device
 
@@ -548,9 +551,14 @@ class QEMUMachine(object):
                             chardev:console" command line argument will
                             be used instead, resorting to the machine's
                             default device type.
+        @param console_index: the index of the console device to use.
+                              If not zero, the command line will create
+                              'index - 1' consoles and connect them to
+                              the 'null' backing character device.
         """
         self._console_set = True
         self._console_device_type = device_type
+        self._console_index = console_index
 
     @property
     def console_socket(self):
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 27/30] tests/acceptance/boot_linux_console: Test the raspi1 AUX console
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (25 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 26/30] python/qemu/machine: Allow to use other serial consoles than default Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [PATCH v2 28/30] tests/acceptance: Count Raspberry Pi logos displayed on framebuffer Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm

  $ avocado --show=app,console run -t device:bcm2835_aux tests/acceptance/
  JOB ID     : a8846d69d52da701681b1d17f80ef299009fd078
  JOB LOG    : avocado/job-results/job-2020-02-05T23.44-a8846d6/job.log
   (1/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi0_uart1:
  console: [    0.000000] Booting Linux on physical CPU 0x0
  console: [    0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019
  console: [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  console: [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  console: [    0.000000] OF: fdt: Machine model: Raspberry Pi Zero W
  console: [    0.000000] earlycon: uart8250 at MMIO32 0x20215040 (options '')
  console: [    0.000000] bootconsole [uart8250] enabled
  console: [    0.000000] Memory policy: Data cache writeback
  console: [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  console: [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  console: [    0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200
  PASS (13.31 s)
   (2/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi1_uart1:
  console: [    0.000000] Booting Linux on physical CPU 0x0
  console: [    0.000000] Linux version 4.14.98+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 Tue Feb 12 20:11:02 GMT 2019
  console: [    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
  console: [    0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
  console: [    0.000000] OF: fdt: Machine model: Raspberry Pi Model B
  console: [    0.000000] earlycon: uart8250 at MMIO32 0x20215040 (options '')
  console: [    0.000000] bootconsole [uart8250] enabled
  console: [    0.000000] Memory policy: Data cache writeback
  console: [    0.000000] cma: Reserved 8 MiB at 0x1b800000
  console: [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 113680
  console: [    0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200
  PASS (13.39 s)
   (3/3) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi2_uart1:
  console: [    0.000000] Booting Linux on physical CPU 0xf00
  console: [    0.000000] Linux version 4.14.98-v7+ (dom@dom-XPS-13-9370) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1200 SMP Tue Feb 12 20:27:48 GMT 2019
  console: [    0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
  console: [    0.000000] CPU: div instructions available: patching division code
  console: [    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
  console: [    0.000000] OF: fdt: Machine model: Raspberry Pi 2 Model B
  console: [    0.000000] earlycon: uart8250 at MMIO32 0x3f215040 (options '')
  console: [    0.000000] bootconsole [uart8250] enabled
  console: [    0.000000] Memory policy: Data cache writealloc
  console: [    0.000000] cma: Reserved 8 MiB at 0x3b800000
  console: [    0.000000] percpu: Embedded 17 pages/cpu @baf2e000 s38720 r8192 d22720 u69632
  console: [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 243600
  console: [    0.000000] Kernel command line: printk.time=0 earlycon=uart8250,mmio32,0x3f215040 console=ttyS1,115200
  PASS (12.46 s)
  RESULTS    : PASS 3 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 39.60 s

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/acceptance/boot_linux_console.py | 37 +++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index df6600ab2f..7210acd977 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -337,6 +337,14 @@ class BootLinuxConsole(Test):
                 1: 'earlycon=pl011,0x20201000 console=ttyAMA0',
                 2: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
             },
+            'bcm2835_aux': {
+                0: 'earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200',
+                1: 'earlycon=uart8250,mmio32,0x20215040 console=ttyS1,115200',
+                2: 'earlycon=uart8250,mmio32,0x3f215040 console=ttyS1,115200',
+            },
+        }
+        uart_id = {
+            'pl011': 0, 'bcm2835_aux': 1,
         }
         kernel = {
             0: '/boot/kernel.img',
@@ -356,7 +364,7 @@ class BootLinuxConsole(Test):
         kernel_path = self.extract_from_deb(deb_path, kernel[version])
         dtb_path = self.extract_from_deb(deb_path, dtb[version])
 
-        self.vm.set_console()
+        self.vm.set_console(console_index=uart_id[uart_model])
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
                                serial_kernel_cmdline[uart_model][version])
         self.vm.add_args('-kernel', kernel_path,
@@ -375,6 +383,15 @@ class BootLinuxConsole(Test):
         """
         self.do_test_arm_raspi(0, 'pl011')
 
+    def test_arm_raspi0_uart1(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi0
+        :avocado: tags=cpu:arm1176
+        :avocado: tags=device:bcm2835_aux
+        """
+        self.do_test_arm_raspi(0, 'bcm2835_aux')
+
     def test_arm_raspi1_uart0(self):
         """
         :avocado: tags=arch:arm
@@ -384,6 +401,15 @@ class BootLinuxConsole(Test):
         """
         self.do_test_arm_raspi(1, 'pl011')
 
+    def test_arm_raspi1_uart1(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi1
+        :avocado: tags=cpu:arm1176
+        :avocado: tags=device:bcm2835_aux
+        """
+        self.do_test_arm_raspi(1, 'bcm2835_aux')
+
     def test_arm_raspi2_uart0(self):
         """
         :avocado: tags=arch:arm
@@ -393,6 +419,15 @@ class BootLinuxConsole(Test):
         """
         self.do_test_arm_raspi(2, 'pl011')
 
+    def test_arm_raspi2_uart1(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi2
+        :avocado: tags=cpu:cortex-a7
+        :avocado: tags=device:bcm2835_aux
+        """
+        self.do_test_arm_raspi(2, 'bcm2835_aux')
+
     def test_arm_exynos4210_initrd(self):
         """
         :avocado: tags=arch:arm
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 28/30] tests/acceptance: Count Raspberry Pi logos displayed on framebuffer
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (26 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 27/30] tests/acceptance/boot_linux_console: Test the raspi1 AUX console Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 29/30] hw/arm/bcm2836: Add the BCM2838 (ARMv8) Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 30/30] hw/arm/raspi: Add the Raspberry Pi 4 Philippe Mathieu-Daudé
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm, kraxel

Add a test that verifies that each core properly displays the
Raspberry Pi logo on the framebuffer device.

We simply follow the OpenCV "Template Matching with Multiple Objects"
tutorial, replacing Lionel Messi by a raspberrry:
https://docs.opencv.org/4.2.0/d4/dc6/tutorial_py_template_matching.html

When OpenCV and NumPy are installed, this test can be run using:

  $ avocado --show=app,framebuffer run -t device:bcm2835-fb tests/acceptance/
  JOB ID     : 9bbbc54c0a6fa180348d0b5305507f76852b4da2
  JOB LOG    : avocado/job-results/job-2020-01-31T23.48-9bbbc54/job.log
   (1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_raspi2_framebuffer_logo:
  framebuffer: found raspberry at position (x, y) = (0, 0)
  framebuffer: found raspberry at position (x, y) = (71, 0)
  framebuffer: found raspberry at position (x, y) = (142, 0)
  framebuffer: found raspberry at position (x, y) = (213, 0)
  PASS (11.06 s)
  RESULTS    : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
  JOB TIME   : 11.39 s

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
The resulting match can be visualised at https://pasteboard.co/ISzNHtx.png

Cc: kraxel@redhat.com
---
 tests/acceptance/boot_linux_console.py | 62 ++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 7210acd977..33d39d8292 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -12,6 +12,7 @@ import os
 import lzma
 import gzip
 import shutil
+import logging
 
 from avocado import skipUnless
 from avocado_qemu import Test
@@ -21,6 +22,19 @@ from avocado.utils import process
 from avocado.utils import archive
 
 
+NUMPY_AVAILABLE = True
+try:
+    import numpy as np
+except ImportError:
+    NUMPY_AVAILABLE = False
+
+CV2_AVAILABLE = True
+try:
+    import cv2
+except ImportError:
+    CV2_AVAILABLE = False
+
+
 class BootLinuxConsole(Test):
     """
     Boots a Linux kernel and checks that the console is operational and the
@@ -428,6 +442,54 @@ class BootLinuxConsole(Test):
         """
         self.do_test_arm_raspi(2, 'bcm2835_aux')
 
+    @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
+    @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
+    def test_arm_raspi2_framebuffer_logo(self):
+        """
+        :avocado: tags=arch:arm
+        :avocado: tags=machine:raspi2
+        :avocado: tags=device:bcm2835-fb
+        """
+        screendump_path = os.path.join(self.workdir, 'screendump.pbm')
+        rpilogo_url = ('https://github.com/raspberrypi/linux/raw/'
+                       'raspberrypi-kernel_1.20190517-1/'
+                       'drivers/video/logo/logo_linux_clut224.ppm')
+        rpilogo_hash = 'fff3cc20c6030acce0953147f9baac43f44ed6b0'
+        rpilogo_path = self.fetch_asset(rpilogo_url, asset_hash=rpilogo_hash)
+        deb_url = ('http://archive.raspberrypi.org/debian/'
+                   'pool/main/r/raspberrypi-firmware/'
+                   'raspberrypi-kernel_1.20190215-1_armhf.deb')
+        deb_hash = 'cd284220b32128c5084037553db3c482426f3972'
+        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
+        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
+
+        self.vm.set_console()
+        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+                               'earlycon=pl011,0x3f201000 console=ttyAMA0')
+        self.vm.add_args('-kernel', kernel_path,
+                         '-dtb', dtb_path,
+                         '-append', kernel_command_line)
+        self.vm.launch()
+        framebuffer_ready = 'Console: switching to colour frame buffer device'
+        wait_for_console_pattern(self, framebuffer_ready)
+        self.vm.command('human-monitor-command', command_line='stop')
+        self.vm.command('human-monitor-command',
+                        command_line='screendump %s' % screendump_path)
+        logger = logging.getLogger('framebuffer')
+
+        cpu_cores_count = 4
+        match_threshold = 0.95
+        screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
+        rpilogo_bgr = cv2.imread(rpilogo_path, cv2.IMREAD_COLOR)
+        result = cv2.matchTemplate(screendump_bgr, rpilogo_bgr,
+                                   cv2.TM_CCOEFF_NORMED)
+        loc = np.where(result >= match_threshold)
+        rpilogo_count = 0
+        for rpilogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
+            logger.debug('found raspberry at position (x, y) = %s', pt)
+        self.assertGreaterEqual(rpilogo_count, cpu_cores_count)
+
     def test_arm_exynos4210_initrd(self):
         """
         :avocado: tags=arch:arm
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [NOTFORMERGE PATCH v2 29/30] hw/arm/bcm2836: Add the BCM2838 (ARMv8)
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (27 preceding siblings ...)
  2020-02-06  1:17 ` [PATCH v2 28/30] tests/acceptance: Count Raspberry Pi logos displayed on framebuffer Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 30/30] hw/arm/raspi: Add the Raspberry Pi 4 Philippe Mathieu-Daudé
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

Setup the GICv2.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/arm/bcm2836.h |   3 +
 hw/arm/bcm2836.c         | 206 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 209 insertions(+)

diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
index 3d46469a73..7c1f79911c 100644
--- a/include/hw/arm/bcm2836.h
+++ b/include/hw/arm/bcm2836.h
@@ -13,6 +13,7 @@
 
 #include "hw/arm/bcm2835_peripherals.h"
 #include "hw/intc/bcm2836_control.h"
+#include "hw/intc/arm_gic.h"
 #include "target/arm/cpu.h"
 
 #define TYPE_BCM283X "bcm283x"
@@ -27,6 +28,7 @@
 #define TYPE_BCM2835 "bcm2835"
 #define TYPE_BCM2836 "bcm2836"
 #define TYPE_BCM2837 "bcm2837"
+#define TYPE_BCM2838 "bcm2838"
 
 typedef struct BCM283XState {
     /*< private >*/
@@ -39,6 +41,7 @@ typedef struct BCM283XState {
     struct {
         ARMCPU core;
     } cpu[BCM283X_NCPUS];
+    GICState gic;
     BCM2836ControlState control;
     BCM2835PeripheralState peripherals;
 } BCM283XState;
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index bce5f8a866..f09cd25caf 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -24,6 +24,7 @@ typedef struct BCM283XClass {
     int core_count;
     hwaddr peri_base; /* Peripheral base address seen by the CPU */
     hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
+    hwaddr gic_base;
     int clusterid;
 } BCM283XClass;
 
@@ -51,6 +52,11 @@ static void bcm2836_init(Object *obj)
         qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
     }
 
+    if (bc->gic_base) {
+        sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic),
+                              TYPE_ARM_GIC);
+    }
+
     if (bc->ctrl_base) {
         sysbus_init_child_obj(obj, "control", &s->control,
                               sizeof(s->control), TYPE_BCM2836_CONTROL);
@@ -201,6 +207,188 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
     }
 }
 
+#ifdef TARGET_AARCH64
+
+#define GIC400_MAINTAINANCE_IRQ  9
+#define GIC400_TIMER_NS_EL2_IRQ 10
+#define GIC400_TIMER_VIRT_IRQ   11
+#define GIC400_LEGACY_FIQ       12
+#define GIC400_TIMER_S_EL1_IRQ  13
+#define GIC400_TIMER_NS_EL1_IRQ 14
+#define GIC400_LEGACY_IRQ       15
+
+/* Number of external interrupt lines to configure the GIC with */
+#define GIC_NUM_IRQS                128
+
+#define PPI(cpu, irq) (GIC_NUM_IRQS + (cpu) * GIC_INTERNAL + GIC_NR_SGIS + irq)
+
+#define GIC_BASE_OFS                0x0000
+#define GIC_DIST_OFS                0x1000
+#define GIC_CPU_OFS                 0x2000
+#define GIC_VIFACE_THIS_OFS         0x4000
+#define GIC_VIFACE_OTHER_OFS(cpu)  (0x5000 + (cpu) * 0x200)
+#define GIC_VCPU_OFS                0x6000
+
+#define NUM_GICV2M_SPIS       64
+
+#define VIRTUAL_PMU_IRQ 7
+
+static void bcm2838_gic_set_irq(void *opaque, int irq, int level)
+{
+    BCM283XState *s = (BCM283XState *)opaque;
+
+    printf("bcm2838_gic_set_irq irq:%d lvl:%d\n", irq, level);
+    qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
+}
+
+static void bcm2838_realize(DeviceState *dev, Error **errp)
+{
+    BCM283XState *s = BCM283X(dev);
+    BCM283XClass *bc = BCM283X_GET_CLASS(dev);
+    Error *err = NULL;
+    int n;
+
+    bcm283x_common_realize(dev, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
+                            bc->peri_base, 1);
+
+    /* bcm2836 interrupt controller (and mailboxes, etc.) */
+    object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
+
+    /* Create cores */
+    for (n = 0; n < bc->core_count; n++) {
+        /* TODO: this should be converted to a property of ARM_CPU */
+        s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
+
+        /* set periphbase/CBAR value for CPU-local registers */
+        object_property_set_int(OBJECT(&s->cpu[n]),
+                                bc->peri_base,
+                                "reset-cbar", &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;
+        }
+
+        /* start powered off if not enabled */
+        object_property_set_bool(OBJECT(&s->cpu[n]), n >= s->enabled_cpus,
+                                 "start-powered-off", &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;
+        }
+
+        object_property_set_bool(OBJECT(&s->cpu[n]), true, "realized", &err);
+        if (err) {
+            error_propagate(errp, err);
+            return;
+        }
+    }
+
+    object_property_set_uint(OBJECT(&s->gic), 2, "revision", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_uint(OBJECT(&s->gic),
+                             BCM283X_NCPUS, "num-cpu", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_uint(OBJECT(&s->gic),
+                             GIC_NUM_IRQS + GIC_INTERNAL, "num-irq", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_bool(OBJECT(&s->gic),
+                             true, "has-virtualization-extensions", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0,
+                    bc->ctrl_base + bc->gic_base + GIC_DIST_OFS);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1,
+                    bc->ctrl_base + bc->gic_base + GIC_CPU_OFS);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2,
+                    bc->ctrl_base + bc->gic_base + GIC_VIFACE_THIS_OFS);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3,
+                    bc->ctrl_base + bc->gic_base + GIC_VCPU_OFS);
+
+    for (n = 0; n < BCM283X_NCPUS; n++) {
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 4 + n,
+                        bc->ctrl_base + bc->gic_base
+                        + GIC_VIFACE_OTHER_OFS(n));
+    }
+
+    for (n = 0; n < BCM283X_NCPUS; n++) {
+        DeviceState *cpudev = DEVICE(&s->cpu[n]);
+        DeviceState *gicdev = DEVICE(&s->gic);
+
+        /* Connect the GICv2 outputs to the CPU */
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + BCM283X_NCPUS,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 2 * BCM283X_NCPUS,
+                           qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 3 * BCM283X_NCPUS,
+                        qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
+
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), n + 4 * BCM283X_NCPUS,
+                        qdev_get_gpio_in(gicdev,
+                                         PPI(n, GIC400_MAINTAINANCE_IRQ)));
+
+        /* Connect timers from the CPU to the interrupt controller */
+        qdev_connect_gpio_out(cpudev, GTIMER_PHYS,
+              qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_NS_EL1_IRQ)));
+        qdev_connect_gpio_out(cpudev, GTIMER_VIRT,
+              qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_VIRT_IRQ)));
+        qdev_connect_gpio_out(cpudev, GTIMER_HYP,
+              qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_NS_EL2_IRQ)));
+        qdev_connect_gpio_out(cpudev, GTIMER_SEC,
+              qdev_get_gpio_in(gicdev, PPI(n, GIC400_TIMER_S_EL1_IRQ)));
+        /* PMU interrupt */
+        qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0,
+            qdev_get_gpio_in(gicdev, PPI(n, VIRTUAL_PMU_IRQ)));
+    }
+
+    /* Pass through inbound GPIO lines to the GIC */
+    qdev_init_gpio_in(dev, bcm2838_gic_set_irq, GIC_NUM_IRQS);
+
+    /* Pass through outbound IRQ lines from the GIC */
+    qdev_pass_gpios(DEVICE(&s->gic), DEVICE(&s->peripherals), NULL);
+
+    object_property_set_bool(OBJECT(&s->peripherals), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+}
+#endif /* TARGET_AARCH64 */
+
 static void bcm283x_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
@@ -246,6 +434,20 @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
     bc->clusterid = 0x0;
     dc->realize = bcm2836_realize;
 };
+
+static void bcm2838_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
+
+    bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a72");
+    bc->core_count = BCM283X_NCPUS;
+    bc->peri_base = 0xfe000000;
+    bc->ctrl_base = 0xff800000;
+    bc->gic_base = 0x40000;
+    bc->clusterid = 0x0;
+    dc->realize = bcm2838_realize;
+};
 #endif
 
 static const TypeInfo bcm283x_types[] = {
@@ -262,6 +464,10 @@ static const TypeInfo bcm283x_types[] = {
         .name           = TYPE_BCM2837,
         .parent         = TYPE_BCM283X,
         .class_init     = bcm2837_class_init,
+    }, {
+        .name           = TYPE_BCM2838,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2838_class_init,
 #endif
     }, {
         .name           = TYPE_BCM283X,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [NOTFORMERGE PATCH v2 30/30] hw/arm/raspi: Add the Raspberry Pi 4
  2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
                   ` (28 preceding siblings ...)
  2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 29/30] hw/arm/bcm2836: Add the BCM2838 (ARMv8) Philippe Mathieu-Daudé
@ 2020-02-06  1:17 ` Philippe Mathieu-Daudé
  29 siblings, 0 replies; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-06  1:17 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Joaquin de Andres, Philippe Mathieu-Daudé,
	Andrew Baumann, Esteban Bosse, qemu-arm,
	Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/raspi.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
index 47cc250883..8a0309933b 100644
--- a/hw/arm/raspi.c
+++ b/hw/arm/raspi.c
@@ -88,7 +88,7 @@ static int board_version(uint32_t board_rev)
 static const char *board_soc_type(uint32_t board_rev)
 {
     static const char *soc_types[] = {
-        TYPE_BCM2835, TYPE_BCM2836, TYPE_BCM2837,
+        TYPE_BCM2835, TYPE_BCM2836, TYPE_BCM2837, TYPE_BCM2838,
     };
     int proc_id = board_processor_id(board_rev);
 
@@ -103,7 +103,7 @@ static const char *board_soc_type(uint32_t board_rev)
 static int cores_count(uint32_t board_rev)
 {
     static const int soc_cores_count[] = {
-        1, BCM283X_NCPUS, BCM283X_NCPUS,
+        1, BCM283X_NCPUS, BCM283X_NCPUS, BCM283X_NCPUS,
     };
     int proc_id = board_processor_id(board_rev);
 
@@ -350,6 +350,11 @@ static const TypeInfo raspi_machine_types[] = {
         .parent         = TYPE_RASPI_MACHINE,
         .class_init     = raspi_machine_class_init,
         .class_data     = (void *)0xa02082,
+    }, {
+        .name           = MACHINE_TYPE_NAME("raspi4"),
+        .parent         = TYPE_RASPI_MACHINE,
+        .class_init     = raspi_machine_class_init,
+        .class_data     = (void *)0xa03111,
 #endif
     }, {
         .name           = TYPE_RASPI_MACHINE,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
  2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
@ 2020-02-06 12:21   ` BALATON Zoltan
  2020-02-07 14:50     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 36+ messages in thread
From: BALATON Zoltan @ 2020-02-06 12:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-arm, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 4143 bytes --]

On Thu, 6 Feb 2020, Philippe Mathieu-Daudé wrote:
> When booting without device tree, the Linux kernels uses the $R1
> register to determine the machine type. The list of values is
> registered at [1].
>
> There are two entries for the Raspberry Pi:
>
> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
>  name: MACH_TYPE_BCM2708
>  value: 0xc42 (3138)
>  status: Active, not mainlined
>  date: 15 Oct 2010
>
> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
>  name: MACH_TYPE_BCM2835
>  value: 4828
>  status: Active, mainlined
>  date: 6 Dec 2013
>
> QEMU always used the non-mainlined type MACH_TYPE_BCM2708.
> The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and
> 0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).
>
> The Raspberry Pi foundation bootloader only sets the BCM2708 machine
> type, see [2] or [3]:
>
> 133 9:
> 134     mov r0, #0
> 135     ldr r1, =3138       @ BCM2708 machine id
> 136     ldr r2, atags       @ ATAGS
> 137     bx  r4
>
> U-Boot only uses MACH_TYPE_BCM2708 (see [4]):
>
> 25 /*
> 26  * 2835 is a SKU in a series for which the 2708 is the first or primary SoC,
> 27  * so 2708 has historically been used rather than a dedicated 2835 ID.
> 28  *
> 29  * We don't define a machine type for bcm2709/bcm2836 since the RPi Foundation
> 30  * chose to use someone else's previously registered machine ID (3139, MX51_GGC)
> 31  * rather than obtaining a valid ID:-/
> 32  *
> 33  * For the bcm2837, hopefully a machine type is not needed, since everything
> 34  * is DT.
> 35  */
>
> While the definition MACH_BCM2709 with value 0xc43 was introduced in
> a commit described "Add 2709 platform for Raspberry Pi 2" out of the
> mainline Linux kernel, it does not seem used, and the platform is
> introduced with Device Tree support anyway (see [5] and [6]).
>
> Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef
> "raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4
> "raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708.
>
> [1] https://www.arm.linux.org.uk/developer/machines/
> [2] https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135
> [3] https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64
> [4] https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18
> [5] https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526
> [6] http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html
>
> Cc: Zoltán Baldaszti <bztemail@gmail.com>
> Cc: Pekka Enberg <penberg@iki.fi>
> Cc: Stephen Warren <swarren@nvidia.com>
> Cc: Kshitij Soni <kshitij.soni@broadcom.com>
> Cc: Michael Chan <michael.chan@broadcom.com>
> Cc: Andrew Baumann <Andrew.Baumann@microsoft.com>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/arm/raspi.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
> index 3996f6c63a..ef76a27f33 100644
> --- a/hw/arm/raspi.c
> +++ b/hw/arm/raspi.c
> @@ -29,8 +29,7 @@
> #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};

Maybe worth a comment about why using this number (short, one line version 
of commit message).

Regards,
BALATON Zoltan

> +#define MACH_TYPE_BCM2708   3138 /* Linux board IDs */
>
> typedef struct RasPiState {
>     BCM283XState soc;
> @@ -116,7 +115,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 = MACH_TYPE_BCM2708;
>     binfo.ram_size = ram_size;
>     binfo.nb_cpus = machine->smp.cpus;
>
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size from the board revision
  2020-02-06  1:17 ` [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size " Philippe Mathieu-Daudé
@ 2020-02-06 12:24   ` BALATON Zoltan
  0 siblings, 0 replies; 36+ messages in thread
From: BALATON Zoltan @ 2020-02-06 12:24 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-arm, Philippe Mathieu-Daudé, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2447 bytes --]

On Thu, 6 Feb 2020, Philippe Mathieu-Daudé wrote:
> The board revision encode the amount of RAM. Add a helper
> to extract the RAM size, and use it.
> Since the amount of RAM is fixed (it is impossible to physically
> modify to have more or less RAM), do not allow sizes different
> than the one anounced by the manufacturer.
>
> Acked-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> Cc: Alistair Francis <alistair@alistair23.me>
>
> 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 13d41dfce6..2f5cd32c5e 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"
> @@ -48,6 +49,12 @@ FIELD(REV_CODE, MANUFACTURER,      16, 4);
> FIELD(REV_CODE, MEMORY_SIZE,       20, 3);
> FIELD(REV_CODE, STYLE,             23, 1);
>
> +static uint64_t board_ram_size(uint32_t board_rev)
> +{
> +    assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
> +    return 256 * MiB << FIELD_EX32(board_rev, REV_CODE, MEMORY_SIZE);
> +}
> +
> static int board_processor_id(uint32_t board_rev)
> {
>     assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
> @@ -190,15 +197,17 @@ static void raspi_init(MachineState *machine, uint32_t board_rev)
> {
>     RasPiState *s = g_new0(RasPiState, 1);
>     int version = board_version(board_rev);
> +    uint64_t ram_size = board_ram_size(board_rev);
>     uint32_t vcram_size;
>     DriveInfo *di;
>     BlockBackend *blk;
>     BusState *bus;
>     DeviceState *carddev;
>
> -    if (machine->ram_size > 1 * GiB) {
> -        error_report("Requested ram size is too large for this machine: "
> -                     "maximum is 1GB");
> +    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);

Reword error message so it says it has problem with memory as this is not 
clear from the above and user getting it after a command line does not 
have context to tell what the printed number means.

Regards,
BALATON Zoltan


> +        g_free(size_str);
>         exit(1);
>     }
>
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass
  2020-02-06  1:17 ` [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass Philippe Mathieu-Daudé
@ 2020-02-06 12:24   ` BALATON Zoltan
  0 siblings, 0 replies; 36+ messages in thread
From: BALATON Zoltan @ 2020-02-06 12:24 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-arm, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 3997 bytes --]

On Thu, 6 Feb 2020, Philippe Mathieu-Daudé wrote:
> QOM'ify RaspiMachineState. Now machines inherite of RaspiMachineClass.

Typo: inherite -> inherit

Regards,
BALATON Zoltan


>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/arm/raspi.c | 56 +++++++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 49 insertions(+), 7 deletions(-)
>
> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
> index fab361939c..edf3e1c0d5 100644
> --- a/hw/arm/raspi.c
> +++ b/hw/arm/raspi.c
> @@ -33,10 +33,28 @@
>
> #define MACH_TYPE_BCM2708   3138 /* Linux board IDs */
>
> -typedef struct RasPiState {
> +typedef struct RaspiMachineState {
> +    /*< private >*/
> +    MachineState parent_obj;
> +    /*< public >*/
>     BCM283XState soc;
>     MemoryRegion ram;
> -} RasPiState;
> +} RaspiMachineState;
> +
> +typedef struct RaspiMachineClass {
> +    /*< private >*/
> +    MachineClass parent_obj;
> +    /*< public >*/
> +} RaspiMachineClass;
> +
> +#define TYPE_RASPI_MACHINE       MACHINE_TYPE_NAME("raspi-common")
> +#define RASPI_MACHINE(obj) \
> +    OBJECT_CHECK(RaspiMachineState, (obj), TYPE_RASPI_MACHINE)
> +
> +#define RASPI_MACHINE_CLASS(klass) \
> +     OBJECT_CLASS_CHECK(RaspiMachineClass, (klass), TYPE_RASPI_MACHINE)
> +#define RASPI_MACHINE_GET_CLASS(obj) \
> +     OBJECT_GET_CLASS(RaspiMachineClass, (obj), TYPE_RASPI_MACHINE)
>
> /*
>  * Board revision codes:
> @@ -210,7 +228,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)
>
> static void raspi_init(MachineState *machine, uint32_t board_rev)
> {
> -    RasPiState *s = g_new0(RasPiState, 1);
> +    RaspiMachineState *s = RASPI_MACHINE(machine);
>     int version = board_version(board_rev);
>     uint64_t ram_size = board_ram_size(board_rev);
>     uint32_t vcram_size;
> @@ -263,8 +281,10 @@ static void raspi2_init(MachineState *machine)
>     raspi_init(machine, 0xa21041);
> }
>
> -static void raspi2_machine_init(MachineClass *mc)
> +static void raspi2_machine_class_init(ObjectClass *oc, void *data)
> {
> +    MachineClass *mc = MACHINE_CLASS(oc);
> +
>     mc->desc = "Raspberry Pi 2B";
>     mc->init = raspi2_init;
>     mc->block_default_type = IF_SD;
> @@ -277,7 +297,6 @@ static void raspi2_machine_init(MachineClass *mc)
>     mc->default_ram_size = 1 * GiB;
>     mc->ignore_memory_transaction_failures = true;
> };
> -DEFINE_MACHINE("raspi2", raspi2_machine_init)
>
> #ifdef TARGET_AARCH64
> static void raspi3_init(MachineState *machine)
> @@ -285,8 +304,10 @@ static void raspi3_init(MachineState *machine)
>     raspi_init(machine, 0xa02082);
> }
>
> -static void raspi3_machine_init(MachineClass *mc)
> +static void raspi3_machine_class_init(ObjectClass *oc, void *data)
> {
> +    MachineClass *mc = MACHINE_CLASS(oc);
> +
>     mc->desc = "Raspberry Pi 3B";
>     mc->init = raspi3_init;
>     mc->block_default_type = IF_SD;
> @@ -298,5 +319,26 @@ static void raspi3_machine_init(MachineClass *mc)
>     mc->default_cpus = BCM283X_NCPUS;
>     mc->default_ram_size = 1 * GiB;
> }
> -DEFINE_MACHINE("raspi3", raspi3_machine_init)
> #endif
> +
> +static const TypeInfo raspi_machine_types[] = {
> +    {
> +        .name           = MACHINE_TYPE_NAME("raspi2"),
> +        .parent         = TYPE_RASPI_MACHINE,
> +        .class_init     = raspi2_machine_class_init,
> +#ifdef TARGET_AARCH64
> +    }, {
> +        .name           = MACHINE_TYPE_NAME("raspi3"),
> +        .parent         = TYPE_RASPI_MACHINE,
> +        .class_init     = raspi3_machine_class_init,
> +#endif
> +    }, {
> +        .name           = TYPE_RASPI_MACHINE,
> +        .parent         = TYPE_MACHINE,
> +        .instance_size  = sizeof(RaspiMachineState),
> +        .class_size     = sizeof(RaspiMachineClass),
> +        .abstract       = true,
> +    }
> +};
> +
> +DEFINE_TYPES(raspi_machine_types)
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
  2020-02-06 12:21   ` BALATON Zoltan
@ 2020-02-07 14:50     ` Philippe Mathieu-Daudé
  2020-02-07 22:19       ` BALATON Zoltan
  0 siblings, 1 reply; 36+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-07 14:50 UTC (permalink / raw)
  To: BALATON Zoltan, Philippe Mathieu-Daudé; +Cc: qemu-arm, qemu-devel

Hi Zoltan,

On 2/6/20 1:21 PM, BALATON Zoltan wrote:
> On Thu, 6 Feb 2020, Philippe Mathieu-Daudé wrote:
>> When booting without device tree, the Linux kernels uses the $R1
>> register to determine the machine type. The list of values is
>> registered at [1].
>>
>> There are two entries for the Raspberry Pi:
>>
>> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
>>  name: MACH_TYPE_BCM2708
>>  value: 0xc42 (3138)
>>  status: Active, not mainlined
>>  date: 15 Oct 2010
>>
>> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
>>  name: MACH_TYPE_BCM2835
>>  value: 4828
>>  status: Active, mainlined
>>  date: 6 Dec 2013
>>
>> QEMU always used the non-mainlined type MACH_TYPE_BCM2708.
>> The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and
>> 0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).
>>
>> The Raspberry Pi foundation bootloader only sets the BCM2708 machine
>> type, see [2] or [3]:
>>
>> 133 9:
>> 134     mov r0, #0
>> 135     ldr r1, =3138       @ BCM2708 machine id
>> 136     ldr r2, atags       @ ATAGS
>> 137     bx  r4
>>
>> U-Boot only uses MACH_TYPE_BCM2708 (see [4]):
>>
>> 25 /*
>> 26  * 2835 is a SKU in a series for which the 2708 is the first or 
>> primary SoC,
>> 27  * so 2708 has historically been used rather than a dedicated 2835 ID.
>> 28  *
>> 29  * We don't define a machine type for bcm2709/bcm2836 since the RPi 
>> Foundation
>> 30  * chose to use someone else's previously registered machine ID 
>> (3139, MX51_GGC)
>> 31  * rather than obtaining a valid ID:-/
>> 32  *
>> 33  * For the bcm2837, hopefully a machine type is not needed, since 
>> everything
>> 34  * is DT.
>> 35  */
>>
>> While the definition MACH_BCM2709 with value 0xc43 was introduced in
>> a commit described "Add 2709 platform for Raspberry Pi 2" out of the
>> mainline Linux kernel, it does not seem used, and the platform is
>> introduced with Device Tree support anyway (see [5] and [6]).
>>
>> Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef
>> "raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4
>> "raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708.
>>
>> [1] https://www.arm.linux.org.uk/developer/machines/
>> [2] 
>> https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135 
>>
>> [3] 
>> https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64 
>>
>> [4] 
>> https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18 
>>
>> [5] 
>> https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526 
>>
>> [6] 
>> http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html 
>>
>>
>> Cc: Zoltán Baldaszti <bztemail@gmail.com>
>> Cc: Pekka Enberg <penberg@iki.fi>
>> Cc: Stephen Warren <swarren@nvidia.com>
>> Cc: Kshitij Soni <kshitij.soni@broadcom.com>
>> Cc: Michael Chan <michael.chan@broadcom.com>
>> Cc: Andrew Baumann <Andrew.Baumann@microsoft.com>
>> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> hw/arm/raspi.c | 5 ++---
>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
>> index 3996f6c63a..ef76a27f33 100644
>> --- a/hw/arm/raspi.c
>> +++ b/hw/arm/raspi.c
>> @@ -29,8 +29,7 @@
>> #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};
> 
> Maybe worth a comment about why using this number (short, one line 
> version of commit message).

You mean something like:

/* Registered machine type:
  * https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
  */

> 
> Regards,
> BALATON Zoltan
> 
>> +#define MACH_TYPE_BCM2708   3138 /* Linux board IDs */
>>
>> typedef struct RasPiState {
>>     BCM283XState soc;
>> @@ -116,7 +115,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 = MACH_TYPE_BCM2708;
>>     binfo.ram_size = ram_size;
>>     binfo.nb_cpus = machine->smp.cpus;
>>
>>



^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels
  2020-02-07 14:50     ` Philippe Mathieu-Daudé
@ 2020-02-07 22:19       ` BALATON Zoltan
  0 siblings, 0 replies; 36+ messages in thread
From: BALATON Zoltan @ 2020-02-07 22:19 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-arm, Philippe Mathieu-Daudé, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 4692 bytes --]

On Fri, 7 Feb 2020, Philippe Mathieu-Daudé wrote:
> On 2/6/20 1:21 PM, BALATON Zoltan wrote:
>> On Thu, 6 Feb 2020, Philippe Mathieu-Daudé wrote:
>>> When booting without device tree, the Linux kernels uses the $R1
>>> register to determine the machine type. The list of values is
>>> registered at [1].
>>> 
>>> There are two entries for the Raspberry Pi:
>>> 
>>> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
>>>  name: MACH_TYPE_BCM2708
>>>  value: 0xc42 (3138)
>>>  status: Active, not mainlined
>>>  date: 15 Oct 2010
>>> 
>>> - https://www.arm.linux.org.uk/developer/machines/list.php?mid=4828
>>>  name: MACH_TYPE_BCM2835
>>>  value: 4828
>>>  status: Active, mainlined
>>>  date: 6 Dec 2013
>>> 
>>> QEMU always used the non-mainlined type MACH_TYPE_BCM2708.
>>> The value 0xc43 is registered to 'MX51_GGC' (processor i.MX51), and
>>> 0xc44 to 'Western Digital Sharespace NAS' (processor Marvell 88F5182).
>>> 
>>> The Raspberry Pi foundation bootloader only sets the BCM2708 machine
>>> type, see [2] or [3]:
>>> 
>>> 133 9:
>>> 134     mov r0, #0
>>> 135     ldr r1, =3138       @ BCM2708 machine id
>>> 136     ldr r2, atags       @ ATAGS
>>> 137     bx  r4
>>> 
>>> U-Boot only uses MACH_TYPE_BCM2708 (see [4]):
>>> 
>>> 25 /*
>>> 26  * 2835 is a SKU in a series for which the 2708 is the first or primary 
>>> SoC,
>>> 27  * so 2708 has historically been used rather than a dedicated 2835 ID.
>>> 28  *
>>> 29  * We don't define a machine type for bcm2709/bcm2836 since the RPi 
>>> Foundation
>>> 30  * chose to use someone else's previously registered machine ID (3139, 
>>> MX51_GGC)
>>> 31  * rather than obtaining a valid ID:-/
>>> 32  *
>>> 33  * For the bcm2837, hopefully a machine type is not needed, since 
>>> everything
>>> 34  * is DT.
>>> 35  */
>>> 
>>> While the definition MACH_BCM2709 with value 0xc43 was introduced in
>>> a commit described "Add 2709 platform for Raspberry Pi 2" out of the
>>> mainline Linux kernel, it does not seem used, and the platform is
>>> introduced with Device Tree support anyway (see [5] and [6]).
>>> 
>>> Remove the unused values (0xc43 introduced in commit 1df7d1f9303aef
>>> "raspi: add raspberry pi 2 machine" and 0xc44 in commit bade58166f4
>>> "raspi: Raspberry Pi 3 support"), keeping only MACH_TYPE_BCM2708.
>>> 
>>> [1] https://www.arm.linux.org.uk/developer/machines/
>>> [2] 
>>> https://github.com/raspberrypi/tools/blob/920c7ed2e/armstubs/armstub7.S#L135 
>>> [3] 
>>> https://github.com/raspberrypi/tools/blob/49719d554/armstubs/armstub7.S#L64 
>>> [4] 
>>> https://gitlab.denx.de/u-boot/u-boot/blob/v2015.04/include/configs/rpi-common.h#L18 
>>> [5] 
>>> https://github.com/raspberrypi/linux/commit/d9fac63adac#diff-6722037d79570df5b392a49e0e006573R526 
>>> [6] 
>>> http://lists.infradead.org/pipermail/linux-rpi-kernel/2015-February/001268.html 
>>> 
>>> Cc: Zoltán Baldaszti <bztemail@gmail.com>
>>> Cc: Pekka Enberg <penberg@iki.fi>
>>> Cc: Stephen Warren <swarren@nvidia.com>
>>> Cc: Kshitij Soni <kshitij.soni@broadcom.com>
>>> Cc: Michael Chan <michael.chan@broadcom.com>
>>> Cc: Andrew Baumann <Andrew.Baumann@microsoft.com>
>>> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>> ---
>>> hw/arm/raspi.c | 5 ++---
>>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>> 
>>> diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
>>> index 3996f6c63a..ef76a27f33 100644
>>> --- a/hw/arm/raspi.c
>>> +++ b/hw/arm/raspi.c
>>> @@ -29,8 +29,7 @@
>>> #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};
>> 
>> Maybe worth a comment about why using this number (short, one line version 
>> of commit message).
>
> You mean something like:
>
> /* Registered machine type:
> * https://www.arm.linux.org.uk/developer/machines/list.php?mid=3138
> */

I think a link in a comment is not very convenient (and may break if the 
website is ever moved) so maybe just a line to say why this particular 
number was chosen would be better, such as

/* This matches RPi Foundation bootloader and U-Boot */

>> +#define MACH_TYPE_BCM2708   3138 /* Linux board IDs */

The rest of the detailed explanation could be looked up in the commit 
message. Just suggested the comment to warn readers that this is not a 
mistake but a pecularity of the platform.

Regards,
BALATON Zoltan

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2020-02-07 22:21 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
2020-02-06 12:21   ` BALATON Zoltan
2020-02-07 14:50     ` Philippe Mathieu-Daudé
2020-02-07 22:19       ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 02/30] hw/arm/raspi: Correct the board descriptions Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 03/30] hw/arm/raspi: Extract the version from the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size " Philippe Mathieu-Daudé
2020-02-06 12:24   ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 05/30] hw/arm/raspi: Extract the processor type " Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 06/30] hw/arm/raspi: Trivial code movement Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass Philippe Mathieu-Daudé
2020-02-06 12:24   ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 08/30] hw/arm/raspi: Make board_rev a field of RaspiMachineClass Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 09/30] hw/arm/raspi: Let class_init() directly call raspi_machine_init() Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 10/30] hw/arm/raspi: Set default RAM size to size encoded in board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 11/30] hw/arm/raspi: Extract the board model from the " Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 12/30] hw/arm/raspi: Use a unique raspi_machine_class_init() method Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 13/30] hw/arm/raspi: Extract the cores count from the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 14/30] hw/arm/bcm2836: Restrict BCM283XClass declaration to C source Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 15/30] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 16/30] hw/arm/bcm2836: Introduce BCM283XClass::core_count Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 17/30] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 18/30] hw/arm/bcm2836: Split out common realize() code Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 19/30] hw/arm/bcm2836: Introduce the BCM2835 SoC Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 20/30] hw/arm/raspi: Add the Raspberry Pi Zero machine Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 21/30] hw/arm/raspi: Add the Raspberry Pi B+ machine Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 22/30] tests/acceptance/boot_linux_console: Use raspi console model as key Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 23/30] tests/acceptance/boot_linux_console: Add raspi version=2 parameter Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 24/30] tests/acceptance/boot_linux_console: Test the raspi1 console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 25/30] tests/acceptance/boot_linux_console: Test the raspi0 console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 26/30] python/qemu/machine: Allow to use other serial consoles than default Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 27/30] tests/acceptance/boot_linux_console: Test the raspi1 AUX console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 28/30] tests/acceptance: Count Raspberry Pi logos displayed on framebuffer Philippe Mathieu-Daudé
2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 29/30] hw/arm/bcm2836: Add the BCM2838 (ARMv8) Philippe Mathieu-Daudé
2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 30/30] hw/arm/raspi: Add the Raspberry Pi 4 Philippe Mathieu-Daudé

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.