[PATCH v2 15/24] hw/arm/mps2-tz: Allow boards to have different PPCInfo data

Peter Maydell posted 24 patches 4 years, 11 months ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>
[PATCH v2 15/24] hw/arm/mps2-tz: Allow boards to have different PPCInfo data
Posted by Peter Maydell 4 years, 11 months ago
The AN505 and AN521 have the same device layout, but the AN524 is
somewhat different.  Allow for more than one PPCInfo array, which can
be selected based on the board type.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
We can't just put the arrays at file-scope and set up pointers
to them in the MPS2TZMachineClass struct, because the array
members include entries like "&mms->uart[0]" which is only valid
inside the mps2tz_common_init() function.
---
 hw/arm/mps2-tz.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
index f1a9c5f65a5..a79966a7187 100644
--- a/hw/arm/mps2-tz.c
+++ b/hw/arm/mps2-tz.c
@@ -423,6 +423,8 @@ static void mps2tz_common_init(MachineState *machine)
     MemoryRegion *system_memory = get_system_memory();
     DeviceState *iotkitdev;
     DeviceState *dev_splitter;
+    const PPCInfo *ppcs;
+    int num_ppcs;
     int i;
 
     if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
@@ -544,7 +546,7 @@ static void mps2tz_common_init(MachineState *machine)
      *  + wire up the PPC's control lines to the IoTKit object
      */
 
-    const PPCInfo ppcs[] = { {
+    const PPCInfo an505_ppcs[] = { {
             .name = "apb_ppcexp0",
             .ports = {
                 { "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },
@@ -598,7 +600,17 @@ static void mps2tz_common_init(MachineState *machine)
         },
     };
 
-    for (i = 0; i < ARRAY_SIZE(ppcs); i++) {
+    switch (mmc->fpga_type) {
+    case FPGA_AN505:
+    case FPGA_AN521:
+        ppcs = an505_ppcs;
+        num_ppcs = ARRAY_SIZE(an505_ppcs);
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    for (i = 0; i < num_ppcs; i++) {
         const PPCInfo *ppcinfo = &ppcs[i];
         TZPPC *ppc = &mms->ppc[i];
         DeviceState *ppcdev;
-- 
2.20.1


Re: [PATCH v2 15/24] hw/arm/mps2-tz: Allow boards to have different PPCInfo data
Posted by Richard Henderson 4 years, 11 months ago
On 2/15/21 3:51 AM, Peter Maydell wrote:
> @@ -544,7 +546,7 @@ static void mps2tz_common_init(MachineState *machine)
>        *  + wire up the PPC's control lines to the IoTKit object
>        */
>   
> -    const PPCInfo ppcs[] = { {
> +    const PPCInfo an505_ppcs[] = { {
>               .name = "apb_ppcexp0",
>               .ports = {
>                   { "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },

Existing nit, but about to be exacerbated by another array.  I'm not a fan of 
large, initialized, on-stack arrays.  Do you really need the pointer into the 
runtime variable mms?  Perhaps arrange for it to be an offsetof?  Then the 
whole thing can be static const.

That said, the change in this patch is ok.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~