Rework aspeed_soc_num_cpus() as a new init_cpus_defaults()
helper to reduce code duplication.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/arm/aspeed.c | 71 +++++++++++++++++++------------------------------
1 file changed, 28 insertions(+), 43 deletions(-)
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index 5b01a4dd28..636a6269aa 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -1141,10 +1141,14 @@ static void aspeed_machine_class_props_init(ObjectClass *oc)
"Change the SPI Flash model");
}
-static int aspeed_soc_num_cpus(const char *soc_name)
+static void aspeed_machine_class_init_cpus_defaults(MachineClass *mc)
{
- AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(soc_name));
- return sc->num_cpus;
+ AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(mc);
+ AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(amc->soc_name));
+
+ mc->default_cpus = mc->min_cpus
+ = mc->max_cpus
+ = sc->num_cpus;
}
static void aspeed_machine_class_init(ObjectClass *oc, void *data)
@@ -1176,8 +1180,7 @@ static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data)
amc->num_cs = 1;
amc->i2c_init = palmetto_bmc_i2c_init;
mc->default_ram_size = 256 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data)
@@ -1193,8 +1196,7 @@ static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data)
amc->num_cs = 1;
amc->i2c_init = quanta_q71l_bmc_i2c_init;
mc->default_ram_size = 128 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
}
static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc,
@@ -1212,8 +1214,7 @@ static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc,
amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON;
amc->i2c_init = palmetto_bmc_i2c_init;
mc->default_ram_size = 256 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
}
static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc,
@@ -1231,8 +1232,7 @@ static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc,
amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON;
amc->i2c_init = palmetto_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
}
static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data)
@@ -1248,8 +1248,7 @@ static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data)
amc->num_cs = 1;
amc->i2c_init = ast2500_evb_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data)
@@ -1266,8 +1265,7 @@ static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data)
amc->num_cs = 2;
amc->i2c_init = yosemitev2_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data)
@@ -1283,8 +1281,7 @@ static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data)
amc->num_cs = 2;
amc->i2c_init = romulus_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data)
@@ -1301,8 +1298,7 @@ static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data)
amc->num_cs = 2;
amc->i2c_init = tiogapass_bmc_i2c_init;
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data)
@@ -1318,8 +1314,7 @@ static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data)
amc->num_cs = 2;
amc->i2c_init = sonorapass_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data)
@@ -1335,8 +1330,7 @@ static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data)
amc->num_cs = 2;
amc->i2c_init = witherspoon_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data)
@@ -1355,8 +1349,7 @@ static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data)
ASPEED_MAC3_ON;
amc->i2c_init = ast2600_evb_i2c_init;
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data)
@@ -1374,8 +1367,7 @@ static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data)
amc->macs_mask = ASPEED_MAC2_ON;
amc->i2c_init = witherspoon_bmc_i2c_init; /* Same board layout */
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data)
@@ -1392,8 +1384,7 @@ static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data)
amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON;
amc->i2c_init = g220a_bmc_i2c_init;
mc->default_ram_size = 1024 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data)
@@ -1410,8 +1401,7 @@ static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data)
amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON;
amc->i2c_init = fp5280g2_bmc_i2c_init;
mc->default_ram_size = 512 * MiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data)
@@ -1429,8 +1419,7 @@ static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data)
amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON;
amc->i2c_init = rainier_bmc_i2c_init;
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
#define FUJI_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB)
@@ -1451,8 +1440,7 @@ static void aspeed_machine_fuji_class_init(ObjectClass *oc, void *data)
amc->i2c_init = fuji_bmc_i2c_init;
amc->uart_default = ASPEED_DEV_UART1;
mc->default_ram_size = FUJI_BMC_RAM_SIZE;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
#define BLETCHLEY_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB)
@@ -1472,8 +1460,7 @@ static void aspeed_machine_bletchley_class_init(ObjectClass *oc, void *data)
amc->macs_mask = ASPEED_MAC2_ON;
amc->i2c_init = bletchley_bmc_i2c_init;
mc->default_ram_size = BLETCHLEY_BMC_RAM_SIZE;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
}
static void fby35_reset(MachineState *state, ShutdownCause reason)
@@ -1515,6 +1502,7 @@ static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data)
amc->i2c_init = fby35_i2c_init;
/* FIXME: Replace this macro with something more general */
mc->default_ram_size = FUJI_BMC_RAM_SIZE;
+ aspeed_machine_class_init_cpus_defaults(mc); //
}
#define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024)
@@ -1592,8 +1580,7 @@ static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc,
amc->spi_model = "sst25vf032b";
amc->num_cs = 2;
amc->macs_mask = 0;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
}
static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc,
@@ -1612,8 +1599,7 @@ static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc,
amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON;
amc->i2c_init = qcom_dc_scm_bmc_i2c_init;
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc,
@@ -1632,8 +1618,7 @@ static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc,
amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON;
amc->i2c_init = qcom_dc_scm_firework_i2c_init;
mc->default_ram_size = 1 * GiB;
- mc->default_cpus = mc->min_cpus = mc->max_cpus =
- aspeed_soc_num_cpus(amc->soc_name);
+ aspeed_machine_class_init_cpus_defaults(mc);
};
static const TypeInfo aspeed_machine_types[] = {
--
2.41.0
Hi Phil, On 1/24/24 08:48, Philippe Mathieu-Daudé wrote: > Rework aspeed_soc_num_cpus() as a new init_cpus_defaults() > helper to reduce code duplication. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/arm/aspeed.c | 71 +++++++++++++++++++------------------------------ > 1 file changed, 28 insertions(+), 43 deletions(-) > One nit needs to be addressed: Reviewed-by: Gavin Shan <gshan@redhat.com> > diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c > index 5b01a4dd28..636a6269aa 100644 > --- a/hw/arm/aspeed.c > +++ b/hw/arm/aspeed.c > @@ -1141,10 +1141,14 @@ static void aspeed_machine_class_props_init(ObjectClass *oc) > "Change the SPI Flash model"); > } > > -static int aspeed_soc_num_cpus(const char *soc_name) > +static void aspeed_machine_class_init_cpus_defaults(MachineClass *mc) > { > - AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(soc_name)); > - return sc->num_cpus; > + AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(mc); > + AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(amc->soc_name)); > + > + mc->default_cpus = mc->min_cpus > + = mc->max_cpus > + = sc->num_cpus; > } > > static void aspeed_machine_class_init(ObjectClass *oc, void *data) > @@ -1176,8 +1180,7 @@ static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 256 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data) > @@ -1193,8 +1196,7 @@ static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = quanta_q71l_bmc_i2c_init; > mc->default_ram_size = 128 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc, > @@ -1212,8 +1214,7 @@ static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 256 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc, > @@ -1231,8 +1232,7 @@ static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data) > @@ -1248,8 +1248,7 @@ static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = ast2500_evb_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data) > @@ -1266,8 +1265,7 @@ static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = yosemitev2_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data) > @@ -1283,8 +1281,7 @@ static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = romulus_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data) > @@ -1301,8 +1298,7 @@ static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = tiogapass_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data) > @@ -1318,8 +1314,7 @@ static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = sonorapass_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data) > @@ -1335,8 +1330,7 @@ static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = witherspoon_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data) > @@ -1355,8 +1349,7 @@ static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data) > ASPEED_MAC3_ON; > amc->i2c_init = ast2600_evb_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data) > @@ -1374,8 +1367,7 @@ static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON; > amc->i2c_init = witherspoon_bmc_i2c_init; /* Same board layout */ > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data) > @@ -1392,8 +1384,7 @@ static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = g220a_bmc_i2c_init; > mc->default_ram_size = 1024 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data) > @@ -1410,8 +1401,7 @@ static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = fp5280g2_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data) > @@ -1429,8 +1419,7 @@ static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = rainier_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > #define FUJI_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) > @@ -1451,8 +1440,7 @@ static void aspeed_machine_fuji_class_init(ObjectClass *oc, void *data) > amc->i2c_init = fuji_bmc_i2c_init; > amc->uart_default = ASPEED_DEV_UART1; > mc->default_ram_size = FUJI_BMC_RAM_SIZE; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > #define BLETCHLEY_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) > @@ -1472,8 +1460,7 @@ static void aspeed_machine_bletchley_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON; > amc->i2c_init = bletchley_bmc_i2c_init; > mc->default_ram_size = BLETCHLEY_BMC_RAM_SIZE; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void fby35_reset(MachineState *state, ShutdownCause reason) > @@ -1515,6 +1502,7 @@ static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data) > amc->i2c_init = fby35_i2c_init; > /* FIXME: Replace this macro with something more general */ > mc->default_ram_size = FUJI_BMC_RAM_SIZE; > + aspeed_machine_class_init_cpus_defaults(mc); // > } > Failure from './scripts/checkpatch.pl --strict' ERROR: do not use C99 // comments #216: FILE: hw/arm/aspeed.c:1505: + aspeed_machine_class_init_cpus_defaults(mc); // > #define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024) > @@ -1592,8 +1580,7 @@ static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc, > amc->spi_model = "sst25vf032b"; > amc->num_cs = 2; > amc->macs_mask = 0; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc, > @@ -1612,8 +1599,7 @@ static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = qcom_dc_scm_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc, > @@ -1632,8 +1618,7 @@ static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = qcom_dc_scm_firework_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static const TypeInfo aspeed_machine_types[] = { Thanks, Gavin
On 25/1/24 03:26, Gavin Shan wrote: > Hi Phil, > > On 1/24/24 08:48, Philippe Mathieu-Daudé wrote: >> Rework aspeed_soc_num_cpus() as a new init_cpus_defaults() >> helper to reduce code duplication. >> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >> --- >> hw/arm/aspeed.c | 71 +++++++++++++++++++------------------------------ >> 1 file changed, 28 insertions(+), 43 deletions(-) >> > > One nit needs to be addressed: > > Reviewed-by: Gavin Shan <gshan@redhat.com> > Failure from './scripts/checkpatch.pl --strict' > > ERROR: do not use C99 // comments > #216: FILE: hw/arm/aspeed.c:1505: > + aspeed_machine_class_init_cpus_defaults(mc); // Oops, forgot to clean that =) Thanks!
On 1/24/24 08:48, Philippe Mathieu-Daudé wrote: > Rework aspeed_soc_num_cpus() as a new init_cpus_defaults() > helper to reduce code duplication. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/arm/aspeed.c | 71 +++++++++++++++++++------------------------------ > 1 file changed, 28 insertions(+), 43 deletions(-) > > diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c > index 5b01a4dd28..636a6269aa 100644 > --- a/hw/arm/aspeed.c > +++ b/hw/arm/aspeed.c > @@ -1141,10 +1141,14 @@ static void aspeed_machine_class_props_init(ObjectClass *oc) > "Change the SPI Flash model"); > } > > -static int aspeed_soc_num_cpus(const char *soc_name) > +static void aspeed_machine_class_init_cpus_defaults(MachineClass *mc) > { > - AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(soc_name)); > - return sc->num_cpus; > + AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(mc); > + AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(amc->soc_name)); > + > + mc->default_cpus = mc->min_cpus > + = mc->max_cpus > + = sc->num_cpus; Not keen on that layout. If you don't want to repeat sc->num_cpus, maybe just pull out int n = sc->num_cpus; at the top. Otherwise, Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
On 1/23/24 23:48, Philippe Mathieu-Daudé wrote: > Rework aspeed_soc_num_cpus() as a new init_cpus_defaults() > helper to reduce code duplication. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/arm/aspeed.c | 71 +++++++++++++++++++------------------------------ > 1 file changed, 28 insertions(+), 43 deletions(-) > > diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c > index 5b01a4dd28..636a6269aa 100644 > --- a/hw/arm/aspeed.c > +++ b/hw/arm/aspeed.c > @@ -1141,10 +1141,14 @@ static void aspeed_machine_class_props_init(ObjectClass *oc) > "Change the SPI Flash model"); > } > > -static int aspeed_soc_num_cpus(const char *soc_name) > +static void aspeed_machine_class_init_cpus_defaults(MachineClass *mc) > > { > - AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(soc_name)); > - return sc->num_cpus; > + AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(mc); > + AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(amc->soc_name)); > + > + mc->default_cpus = mc->min_cpus > + = mc->max_cpus > + = sc->num_cpus; > } > > static void aspeed_machine_class_init(ObjectClass *oc, void *data) > @@ -1176,8 +1180,7 @@ static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 256 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data) > @@ -1193,8 +1196,7 @@ static void aspeed_machine_quanta_q71l_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = quanta_q71l_bmc_i2c_init; > mc->default_ram_size = 128 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc, > @@ -1212,8 +1214,7 @@ static void aspeed_machine_supermicrox11_bmc_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 256 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc, > @@ -1231,8 +1232,7 @@ static void aspeed_machine_supermicro_x11spi_bmc_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = palmetto_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data) > @@ -1248,8 +1248,7 @@ static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data) > amc->num_cs = 1; > amc->i2c_init = ast2500_evb_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data) > @@ -1266,8 +1265,7 @@ static void aspeed_machine_yosemitev2_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = yosemitev2_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data) > @@ -1283,8 +1281,7 @@ static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = romulus_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data) > @@ -1301,8 +1298,7 @@ static void aspeed_machine_tiogapass_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = tiogapass_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data) > @@ -1318,8 +1314,7 @@ static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = sonorapass_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data) > @@ -1335,8 +1330,7 @@ static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data) > amc->num_cs = 2; > amc->i2c_init = witherspoon_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data) > @@ -1355,8 +1349,7 @@ static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data) > ASPEED_MAC3_ON; > amc->i2c_init = ast2600_evb_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data) > @@ -1374,8 +1367,7 @@ static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON; > amc->i2c_init = witherspoon_bmc_i2c_init; /* Same board layout */ > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data) > @@ -1392,8 +1384,7 @@ static void aspeed_machine_g220a_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = g220a_bmc_i2c_init; > mc->default_ram_size = 1024 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data) > @@ -1410,8 +1401,7 @@ static void aspeed_machine_fp5280g2_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC0_ON | ASPEED_MAC1_ON; > amc->i2c_init = fp5280g2_bmc_i2c_init; > mc->default_ram_size = 512 * MiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data) > @@ -1429,8 +1419,7 @@ static void aspeed_machine_rainier_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = rainier_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > #define FUJI_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) > @@ -1451,8 +1440,7 @@ static void aspeed_machine_fuji_class_init(ObjectClass *oc, void *data) > amc->i2c_init = fuji_bmc_i2c_init; > amc->uart_default = ASPEED_DEV_UART1; > mc->default_ram_size = FUJI_BMC_RAM_SIZE; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > #define BLETCHLEY_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) > @@ -1472,8 +1460,7 @@ static void aspeed_machine_bletchley_class_init(ObjectClass *oc, void *data) > amc->macs_mask = ASPEED_MAC2_ON; > amc->i2c_init = bletchley_bmc_i2c_init; > mc->default_ram_size = BLETCHLEY_BMC_RAM_SIZE; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void fby35_reset(MachineState *state, ShutdownCause reason) > @@ -1515,6 +1502,7 @@ static void aspeed_machine_fby35_class_init(ObjectClass *oc, void *data) > amc->i2c_init = fby35_i2c_init; > /* FIXME: Replace this macro with something more general */ > mc->default_ram_size = FUJI_BMC_RAM_SIZE; > + aspeed_machine_class_init_cpus_defaults(mc); // please remove the extra //, with that Reviewed-by: Cédric Le Goater <clg@kaod.org> Thanks, C. > } > > #define AST1030_INTERNAL_FLASH_SIZE (1024 * 1024) > @@ -1592,8 +1580,7 @@ static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc, > amc->spi_model = "sst25vf032b"; > amc->num_cs = 2; > amc->macs_mask = 0; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > } > > static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc, > @@ -1612,8 +1599,7 @@ static void aspeed_machine_qcom_dc_scm_v1_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = qcom_dc_scm_bmc_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc, > @@ -1632,8 +1618,7 @@ static void aspeed_machine_qcom_firework_class_init(ObjectClass *oc, > amc->macs_mask = ASPEED_MAC2_ON | ASPEED_MAC3_ON; > amc->i2c_init = qcom_dc_scm_firework_i2c_init; > mc->default_ram_size = 1 * GiB; > - mc->default_cpus = mc->min_cpus = mc->max_cpus = > - aspeed_soc_num_cpus(amc->soc_name); > + aspeed_machine_class_init_cpus_defaults(mc); > }; > > static const TypeInfo aspeed_machine_types[] = {
© 2016 - 2024 Red Hat, Inc.