From: "Cédric Le Goater" <clg@kaod.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
"Joel Stanley" <joel@jms.id.au>,
"Andrew Jeffery" <andrew@aj.id.au>,
"Alistair Francis" <alistair@alistair23.me>,
"Peter Crosthwaite" <crosthwaite.peter@gmail.com>,
"Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH 03/11] hw/arm/aspeed: Add an Aspeed machine class
Date: Fri, 31 Aug 2018 12:38:10 +0200 [thread overview]
Message-ID: <20180831103816.13479-4-clg@kaod.org> (raw)
In-Reply-To: <20180831103816.13479-1-clg@kaod.org>
The code looks better, it removes duplicated lines and it will ease
the introduction of common properties for the Aspeed machines.
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
include/hw/arm/aspeed.h | 46 +++++++++
hw/arm/aspeed.c | 212 +++++++++++++---------------------------
2 files changed, 116 insertions(+), 142 deletions(-)
create mode 100644 include/hw/arm/aspeed.h
diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
new file mode 100644
index 000000000000..2b77f8d2b3c8
--- /dev/null
+++ b/include/hw/arm/aspeed.h
@@ -0,0 +1,46 @@
+/*
+ * Aspeed Machines
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later. See
+ * the COPYING file in the top-level directory.
+ */
+#ifndef _ARM_ASPEED_H
+#define _ARM_ASPEED_H
+
+#include "hw/boards.h"
+
+typedef struct AspeedBoardState AspeedBoardState;
+
+typedef struct AspeedBoardConfig {
+ const char *name;
+ const char *desc;
+ const char *soc_name;
+ uint32_t hw_strap1;
+ const char *fmc_model;
+ const char *spi_model;
+ uint32_t num_cs;
+ void (*i2c_init)(AspeedBoardState *bmc);
+} AspeedBoardConfig;
+
+#define TYPE_ASPEED_MACHINE MACHINE_TYPE_NAME("aspeed")
+#define ASPEED_MACHINE(obj) \
+ OBJECT_CHECK(AspeedMachine, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachine {
+ MachineState parent_obj;
+} AspeedMachine;
+
+#define ASPEED_MACHINE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(AspeedMachineClass, (klass), TYPE_ASPEED_MACHINE)
+#define ASPEED_MACHINE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(AspeedMachineClass, (obj), TYPE_ASPEED_MACHINE)
+
+typedef struct AspeedMachineClass {
+ MachineClass parent_obj;
+ const AspeedBoardConfig *board;
+} AspeedMachineClass;
+
+
+#endif
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index f2d64e45511a..6b33ecd5aa43 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -15,6 +15,7 @@
#include "cpu.h"
#include "exec/address-spaces.h"
#include "hw/arm/arm.h"
+#include "hw/arm/aspeed.h"
#include "hw/arm/aspeed_soc.h"
#include "hw/boards.h"
#include "hw/i2c/smbus.h"
@@ -34,22 +35,6 @@ typedef struct AspeedBoardState {
MemoryRegion max_ram;
} AspeedBoardState;
-typedef struct AspeedBoardConfig {
- const char *soc_name;
- uint32_t hw_strap1;
- const char *fmc_model;
- const char *spi_model;
- uint32_t num_cs;
- void (*i2c_init)(AspeedBoardState *bmc);
-} AspeedBoardConfig;
-
-enum {
- PALMETTO_BMC,
- AST2500_EVB,
- ROMULUS_BMC,
- WITHERSPOON_BMC,
-};
-
/* Palmetto hardware value: 0x120CE416 */
#define PALMETTO_BMC_HW_STRAP1 ( \
SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) | \
@@ -88,46 +73,6 @@ enum {
/* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
#define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
-static void palmetto_bmc_i2c_init(AspeedBoardState *bmc);
-static void ast2500_evb_i2c_init(AspeedBoardState *bmc);
-static void romulus_bmc_i2c_init(AspeedBoardState *bmc);
-static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc);
-
-static const AspeedBoardConfig aspeed_boards[] = {
- [PALMETTO_BMC] = {
- .soc_name = "ast2400-a1",
- .hw_strap1 = PALMETTO_BMC_HW_STRAP1,
- .fmc_model = "n25q256a",
- .spi_model = "mx25l25635e",
- .num_cs = 1,
- .i2c_init = palmetto_bmc_i2c_init,
- },
- [AST2500_EVB] = {
- .soc_name = "ast2500-a1",
- .hw_strap1 = AST2500_EVB_HW_STRAP1,
- .fmc_model = "w25q256",
- .spi_model = "mx25l25635e",
- .num_cs = 1,
- .i2c_init = ast2500_evb_i2c_init,
- },
- [ROMULUS_BMC] = {
- .soc_name = "ast2500-a1",
- .hw_strap1 = ROMULUS_BMC_HW_STRAP1,
- .fmc_model = "n25q256a",
- .spi_model = "mx66l1g45g",
- .num_cs = 2,
- .i2c_init = romulus_bmc_i2c_init,
- },
- [WITHERSPOON_BMC] = {
- .soc_name = "ast2500-a1",
- .hw_strap1 = WITHERSPOON_BMC_HW_STRAP1,
- .fmc_model = "mx25l25635e",
- .spi_model = "mx66l1g45g",
- .num_cs = 2,
- .i2c_init = witherspoon_bmc_i2c_init,
- },
-};
-
/*
* The max ram region is for firmwares that scan the address space
* with load/store to guess how much RAM the SoC has.
@@ -313,30 +258,6 @@ static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
object_property_set_int(OBJECT(dev), 110000, "temperature3", &error_abort);
}
-static void palmetto_bmc_init(MachineState *machine)
-{
- aspeed_board_init(machine, &aspeed_boards[PALMETTO_BMC]);
-}
-
-static void palmetto_bmc_class_init(ObjectClass *oc, void *data)
-{
- MachineClass *mc = MACHINE_CLASS(oc);
-
- mc->desc = "OpenPOWER Palmetto BMC (ARM926EJ-S)";
- mc->init = palmetto_bmc_init;
- mc->max_cpus = 1;
- mc->no_sdcard = 1;
- mc->no_floppy = 1;
- mc->no_cdrom = 1;
- mc->no_parallel = 1;
-}
-
-static const TypeInfo palmetto_bmc_type = {
- .name = MACHINE_TYPE_NAME("palmetto-bmc"),
- .parent = TYPE_MACHINE,
- .class_init = palmetto_bmc_class_init,
-};
-
static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
{
AspeedSoCState *soc = &bmc->soc;
@@ -353,30 +274,6 @@ static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
}
-static void ast2500_evb_init(MachineState *machine)
-{
- aspeed_board_init(machine, &aspeed_boards[AST2500_EVB]);
-}
-
-static void ast2500_evb_class_init(ObjectClass *oc, void *data)
-{
- MachineClass *mc = MACHINE_CLASS(oc);
-
- mc->desc = "Aspeed AST2500 EVB (ARM1176)";
- mc->init = ast2500_evb_init;
- mc->max_cpus = 1;
- mc->no_sdcard = 1;
- mc->no_floppy = 1;
- mc->no_cdrom = 1;
- mc->no_parallel = 1;
-}
-
-static const TypeInfo ast2500_evb_type = {
- .name = MACHINE_TYPE_NAME("ast2500-evb"),
- .parent = TYPE_MACHINE,
- .class_init = ast2500_evb_class_init,
-};
-
static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
{
AspeedSoCState *soc = &bmc->soc;
@@ -386,30 +283,6 @@ static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
}
-static void romulus_bmc_init(MachineState *machine)
-{
- aspeed_board_init(machine, &aspeed_boards[ROMULUS_BMC]);
-}
-
-static void romulus_bmc_class_init(ObjectClass *oc, void *data)
-{
- MachineClass *mc = MACHINE_CLASS(oc);
-
- mc->desc = "OpenPOWER Romulus BMC (ARM1176)";
- mc->init = romulus_bmc_init;
- mc->max_cpus = 1;
- mc->no_sdcard = 1;
- mc->no_floppy = 1;
- mc->no_cdrom = 1;
- mc->no_parallel = 1;
-}
-
-static const TypeInfo romulus_bmc_type = {
- .name = MACHINE_TYPE_NAME("romulus-bmc"),
- .parent = TYPE_MACHINE,
- .class_init = romulus_bmc_class_init,
-};
-
static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc)
{
AspeedSoCState *soc = &bmc->soc;
@@ -433,36 +306,91 @@ static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc)
0x60);
}
-static void witherspoon_bmc_init(MachineState *machine)
+static void aspeed_machine_init(MachineState *machine)
{
- aspeed_board_init(machine, &aspeed_boards[WITHERSPOON_BMC]);
+ AspeedMachineClass *amc = ASPEED_MACHINE_GET_CLASS(machine);
+
+ aspeed_board_init(machine, amc->board);
}
-static void witherspoon_bmc_class_init(ObjectClass *oc, void *data)
+static void aspeed_machine_class_init(ObjectClass *oc, void *data)
{
MachineClass *mc = MACHINE_CLASS(oc);
+ AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
+ const AspeedBoardConfig *board = data;
- mc->desc = "OpenPOWER Witherspoon BMC (ARM1176)";
- mc->init = witherspoon_bmc_init;
+ mc->desc = board->desc;
+ mc->init = aspeed_machine_init;
mc->max_cpus = 1;
mc->no_sdcard = 1;
mc->no_floppy = 1;
mc->no_cdrom = 1;
mc->no_parallel = 1;
+ amc->board = board;
}
-static const TypeInfo witherspoon_bmc_type = {
- .name = MACHINE_TYPE_NAME("witherspoon-bmc"),
+static const TypeInfo aspeed_machine_type = {
+ .name = TYPE_ASPEED_MACHINE,
.parent = TYPE_MACHINE,
- .class_init = witherspoon_bmc_class_init,
+ .instance_size = sizeof(AspeedMachine),
+ .class_size = sizeof(AspeedMachineClass),
+ .abstract = true,
+};
+
+static const AspeedBoardConfig aspeed_boards[] = {
+ {
+ .name = MACHINE_TYPE_NAME("palmetto-bmc"),
+ .desc = "OpenPOWER Palmetto BMC (ARM926EJ-S)",
+ .soc_name = "ast2400-a1",
+ .hw_strap1 = PALMETTO_BMC_HW_STRAP1,
+ .fmc_model = "n25q256a",
+ .spi_model = "mx25l25635e",
+ .num_cs = 1,
+ .i2c_init = palmetto_bmc_i2c_init,
+ }, {
+ .name = MACHINE_TYPE_NAME("ast2500-evb"),
+ .desc = "Aspeed AST2500 EVB (ARM1176)",
+ .soc_name = "ast2500-a1",
+ .hw_strap1 = AST2500_EVB_HW_STRAP1,
+ .fmc_model = "w25q256",
+ .spi_model = "mx25l25635e",
+ .num_cs = 1,
+ .i2c_init = ast2500_evb_i2c_init,
+ }, {
+ .name = MACHINE_TYPE_NAME("romulus-bmc"),
+ .desc = "OpenPOWER Romulus BMC (ARM1176)",
+ .soc_name = "ast2500-a1",
+ .hw_strap1 = ROMULUS_BMC_HW_STRAP1,
+ .fmc_model = "n25q256a",
+ .spi_model = "mx66l1g45g",
+ .num_cs = 2,
+ .i2c_init = romulus_bmc_i2c_init,
+ }, {
+ .name = MACHINE_TYPE_NAME("witherspoon-bmc"),
+ .desc = "OpenPOWER Witherspoon BMC (ARM1176)",
+ .soc_name = "ast2500-a1",
+ .hw_strap1 = WITHERSPOON_BMC_HW_STRAP1,
+ .fmc_model = "mx25l25635e",
+ .spi_model = "mx66l1g45g",
+ .num_cs = 2,
+ .i2c_init = witherspoon_bmc_i2c_init,
+ },
};
-static void aspeed_machine_init(void)
+static void aspeed_machine_types(void)
{
- type_register_static(&palmetto_bmc_type);
- type_register_static(&ast2500_evb_type);
- type_register_static(&romulus_bmc_type);
- type_register_static(&witherspoon_bmc_type);
+ int i;
+
+ type_register_static(&aspeed_machine_type);
+ for (i = 0; i < ARRAY_SIZE(aspeed_boards); ++i) {
+ TypeInfo ti = {
+ .name = aspeed_boards[i].name,
+ .parent = TYPE_ASPEED_MACHINE,
+ .class_init = aspeed_machine_class_init,
+ .class_data = (void *)&aspeed_boards[i],
+ };
+ type_register(&ti);
+ }
}
-type_init(aspeed_machine_init)
+type_init(aspeed_machine_types)
--
2.17.1
next prev parent reply other threads:[~2018-08-31 10:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-31 10:38 [Qemu-devel] [PATCH 00/11] aspeed: misc fixes and enhancements (SMC) Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 01/11] aspeed/timer: fix compile breakage with clang 3.4.2 Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 02/11] hw/arm/aspeed: change the FMC flash model of the AST2500 evb Cédric Le Goater
2018-08-31 10:38 ` Cédric Le Goater [this message]
2018-09-07 23:13 ` [Qemu-devel] [Qemu-arm] [PATCH 03/11] hw/arm/aspeed: Add an Aspeed machine class Philippe Mathieu-Daudé
2018-08-31 10:38 ` [Qemu-devel] [PATCH 04/11] hw/arm/aspeed: add a 'mmio-exec' property to boot from the FMC flash module Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 05/11] aspeed/smc: fix some alignment issues Cédric Le Goater
2018-09-07 18:28 ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-31 10:38 ` [Qemu-devel] [PATCH 06/11] aspeed/smc: fix default read value Cédric Le Goater
2018-09-07 23:06 ` Philippe Mathieu-Daudé
2018-09-10 6:20 ` Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 07/11] aspeed/smc: add a 'sdram_base' and 'max-ram-size' properties Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 08/11] aspeed/smc: add support for DMAs Cédric Le Goater
2018-08-31 10:38 ` [Qemu-devel] [PATCH 09/11] aspeed/smc: add DMA calibration settings Cédric Le Goater
2018-08-31 11:15 ` [Qemu-devel] [PATCH 10/11] aspeed/smc: inject errors in DMA checksum Cédric Le Goater
2018-08-31 11:15 ` [Qemu-devel] [PATCH 11/11] aspeed/smc: Add dummy data register Cédric Le Goater
2018-09-07 23:02 ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2018-08-31 22:16 ` [Qemu-devel] [PATCH 00/11] aspeed: misc fixes and enhancements (SMC) Joel Stanley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180831103816.13479-4-clg@kaod.org \
--to=clg@kaod.org \
--cc=alistair@alistair23.me \
--cc=andrew@aj.id.au \
--cc=crosthwaite.peter@gmail.com \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).