diff mbox series

[v1,7/9] hw/arm/xlnx-versal: Connect the OSPI flash memory controller model

Message ID 20211117141841.4696-8-francisco.iglesias@xilinx.com (mailing list archive)
State New, archived
Headers show
Series Xilinx Versal's PMC SLCR and OSPI support | expand

Commit Message

Francisco Iglesias Nov. 17, 2021, 2:18 p.m. UTC
Connect the OSPI flash memory controller model (including the source and
destination DMA).

Signed-off-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
---
 hw/arm/xlnx-versal.c         | 89 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/xlnx-versal.h | 18 +++++++++
 2 files changed, 107 insertions(+)

Comments

Edgar E. Iglesias Nov. 19, 2021, 5:14 p.m. UTC | #1
On Wed, Nov 17, 2021 at 02:18:39PM +0000, Francisco Iglesias wrote:
> Connect the OSPI flash memory controller model (including the source and
> destination DMA).
> 
> Signed-off-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
> ---
>  hw/arm/xlnx-versal.c         | 89 ++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/arm/xlnx-versal.h | 18 +++++++++
>  2 files changed, 107 insertions(+)
> 
> diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c
> index 08e250945f..f8e94a50fd 100644
> --- a/hw/arm/xlnx-versal.c
> +++ b/hw/arm/xlnx-versal.c
> @@ -24,6 +24,7 @@
>  
>  #define XLNX_VERSAL_ACPU_TYPE ARM_CPU_TYPE_NAME("cortex-a72")
>  #define GEM_REVISION        0x40070106
> +#define NUM_OSPI_IRQ_LINES 3
>  
>  static void versal_create_apu_cpus(Versal *s)
>  {
> @@ -385,6 +386,93 @@ static void versal_create_pmc_iou_slcr(Versal *s, qemu_irq *pic)
>      sysbus_connect_irq(sbd, 0, pic[VERSAL_PMC_IOU_SLCR_IRQ]);
>  }
>  
> +static void versal_create_ospi(Versal *s, qemu_irq *pic)
> +{
> +    SysBusDevice *sbd;
> +    MemoryRegion *mr_dac;
> +
> +    memory_region_init(&s->pmc.iou.lospi_mr, OBJECT(s),
> +                       "versal-lospi_mr" , MM_PMC_OSPI_DAC_SIZE);
> +
> +    object_initialize_child(OBJECT(s), "versal-ospi", &s->pmc.iou.ospi,
> +                            TYPE_XILINX_VERSAL_OSPI);
> +
> +    mr_dac = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->pmc.iou.ospi), 1);
> +    memory_region_add_subregion(&s->pmc.iou.lospi_mr, 0x0, mr_dac);
> +
> +    /* Create the OSPI destination DMA */
> +    object_initialize_child(OBJECT(s), "versal-ospi-dma-dst",
> +                            &s->pmc.iou.ospi_dma_dst,
> +                            TYPE_XLNX_CSU_DMA);
> +
> +    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_dst),
> +                            "dma", OBJECT(get_system_memory()),
> +                             &error_abort);
> +
> +    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_dst);
> +    sysbus_realize(sbd, &error_fatal);
> +
> +    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DMA_DST,
> +        sysbus_mmio_get_region(sbd, 0));
> +
> +    sysbus_connect_irq(SYS_BUS_DEVICE(sbd), 0, pic[VERSAL_OSPI_IRQ]);
> +
> +    /* Create the OSPI source DMA */
> +    object_initialize_child(OBJECT(s), "versal-ospi-dma-src",
> +                            &s->pmc.iou.ospi_dma_src,
> +                            TYPE_XLNX_CSU_DMA);
> +
> +    object_property_set_bool(OBJECT(&s->pmc.iou.ospi_dma_src), "is-dst",
> +                             false, &error_abort);
> +
> +    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_src),
> +                            "dma", OBJECT(mr_dac), &error_abort);
> +
> +    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_src),
> +                            "stream-connected-dma",
> +                             OBJECT(&s->pmc.iou.ospi_dma_dst),
> +                             &error_abort);
> +
> +    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_src);
> +    sysbus_realize(sbd, &error_fatal);
> +
> +    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DMA_SRC,
> +        sysbus_mmio_get_region(sbd, 0));
> +
> +    /* Create the OSPI */
> +    object_property_set_link(OBJECT(&s->pmc.iou.ospi), "dma-src",
> +                             OBJECT(&s->pmc.iou.ospi_dma_src), &error_abort);
> +
> +    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi);
> +    sysbus_realize(sbd, &error_fatal);
> +
> +    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI,
> +        sysbus_mmio_get_region(sbd, 0));
> +
> +    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DAC,
> +                                &s->pmc.iou.lospi_mr);
> +
> +    /* ospi_mux_sel */
> +    qdev_connect_gpio_out(DEVICE(&s->pmc.iou.slcr), 3,
> +                          qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi), 0));
> +
> +    /* OSPI irq */
> +    object_initialize_child(OBJECT(s), "ospi-irq",
> +                            &s->pmc.iou.ospi_irq, TYPE_OR_IRQ);
> +    object_property_set_int(OBJECT(&s->pmc.iou.ospi_irq),
> +                            "num-lines", NUM_OSPI_IRQ_LINES, &error_fatal);
> +    qdev_realize(DEVICE(&s->pmc.iou.ospi_irq), NULL, &error_fatal);
> +
> +    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi), 0,
> +                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 0));
> +    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_src), 0,
> +                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 1));
> +    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_dst), 0,
> +                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 2));
> +
> +    qdev_connect_gpio_out(DEVICE(&s->pmc.iou.ospi_irq), 0,
> +                          pic[VERSAL_OSPI_IRQ]);
> +}
>  
>  /* This takes the board allocated linear DDR memory and creates aliases
>   * for each split DDR range/aperture on the Versal address map.
> @@ -477,6 +565,7 @@ static void versal_realize(DeviceState *dev, Error **errp)
>      versal_create_bbram(s, pic);
>      versal_create_efuse(s, pic);
>      versal_create_pmc_iou_slcr(s, pic);
> +    versal_create_ospi(s, pic);
>      versal_map_ddr(s);
>      versal_unimp(s);
>  
> diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h
> index 729c093dfc..dae15db352 100644
> --- a/include/hw/arm/xlnx-versal.h
> +++ b/include/hw/arm/xlnx-versal.h
> @@ -26,6 +26,8 @@
>  #include "hw/misc/xlnx-versal-xramc.h"
>  #include "hw/nvram/xlnx-bbram.h"
>  #include "hw/nvram/xlnx-versal-efuse.h"
> +#include "hw/ssi/xlnx-versal-ospi.h"
> +#include "hw/dma/xlnx_csu_dma.h"
>  #include "hw/misc/xlnx-versal-pmc-iou-slcr.h"
>  
>  #define TYPE_XLNX_VERSAL "xlnx-versal"
> @@ -80,6 +82,12 @@ struct Versal {
>          struct {
>              SDHCIState sd[XLNX_VERSAL_NR_SDS];
>              XlnxVersalPmcIouSlcr slcr;
> +
> +            XlnxVersalOspi ospi;
> +            XlnxCSUDMA ospi_dma_src;
> +            XlnxCSUDMA ospi_dma_dst;
> +            MemoryRegion lospi_mr;
> +            qemu_or_irq ospi_irq;


I wonder if we should do something like?

struct {
    XlnxVersalOspi ospi;
    XlnxCSUDMA dma_src;
    XlnxCSUDMA dma_dst;
    MemoryRegion linear_mr;
    qemu_or_irq irq;
} ospi;


But either way is OK with me:

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
diff mbox series

Patch

diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c
index 08e250945f..f8e94a50fd 100644
--- a/hw/arm/xlnx-versal.c
+++ b/hw/arm/xlnx-versal.c
@@ -24,6 +24,7 @@ 
 
 #define XLNX_VERSAL_ACPU_TYPE ARM_CPU_TYPE_NAME("cortex-a72")
 #define GEM_REVISION        0x40070106
+#define NUM_OSPI_IRQ_LINES 3
 
 static void versal_create_apu_cpus(Versal *s)
 {
@@ -385,6 +386,93 @@  static void versal_create_pmc_iou_slcr(Versal *s, qemu_irq *pic)
     sysbus_connect_irq(sbd, 0, pic[VERSAL_PMC_IOU_SLCR_IRQ]);
 }
 
+static void versal_create_ospi(Versal *s, qemu_irq *pic)
+{
+    SysBusDevice *sbd;
+    MemoryRegion *mr_dac;
+
+    memory_region_init(&s->pmc.iou.lospi_mr, OBJECT(s),
+                       "versal-lospi_mr" , MM_PMC_OSPI_DAC_SIZE);
+
+    object_initialize_child(OBJECT(s), "versal-ospi", &s->pmc.iou.ospi,
+                            TYPE_XILINX_VERSAL_OSPI);
+
+    mr_dac = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->pmc.iou.ospi), 1);
+    memory_region_add_subregion(&s->pmc.iou.lospi_mr, 0x0, mr_dac);
+
+    /* Create the OSPI destination DMA */
+    object_initialize_child(OBJECT(s), "versal-ospi-dma-dst",
+                            &s->pmc.iou.ospi_dma_dst,
+                            TYPE_XLNX_CSU_DMA);
+
+    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_dst),
+                            "dma", OBJECT(get_system_memory()),
+                             &error_abort);
+
+    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_dst);
+    sysbus_realize(sbd, &error_fatal);
+
+    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DMA_DST,
+        sysbus_mmio_get_region(sbd, 0));
+
+    sysbus_connect_irq(SYS_BUS_DEVICE(sbd), 0, pic[VERSAL_OSPI_IRQ]);
+
+    /* Create the OSPI source DMA */
+    object_initialize_child(OBJECT(s), "versal-ospi-dma-src",
+                            &s->pmc.iou.ospi_dma_src,
+                            TYPE_XLNX_CSU_DMA);
+
+    object_property_set_bool(OBJECT(&s->pmc.iou.ospi_dma_src), "is-dst",
+                             false, &error_abort);
+
+    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_src),
+                            "dma", OBJECT(mr_dac), &error_abort);
+
+    object_property_set_link(OBJECT(&s->pmc.iou.ospi_dma_src),
+                            "stream-connected-dma",
+                             OBJECT(&s->pmc.iou.ospi_dma_dst),
+                             &error_abort);
+
+    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_src);
+    sysbus_realize(sbd, &error_fatal);
+
+    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DMA_SRC,
+        sysbus_mmio_get_region(sbd, 0));
+
+    /* Create the OSPI */
+    object_property_set_link(OBJECT(&s->pmc.iou.ospi), "dma-src",
+                             OBJECT(&s->pmc.iou.ospi_dma_src), &error_abort);
+
+    sbd = SYS_BUS_DEVICE(&s->pmc.iou.ospi);
+    sysbus_realize(sbd, &error_fatal);
+
+    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI,
+        sysbus_mmio_get_region(sbd, 0));
+
+    memory_region_add_subregion(&s->mr_ps, MM_PMC_OSPI_DAC,
+                                &s->pmc.iou.lospi_mr);
+
+    /* ospi_mux_sel */
+    qdev_connect_gpio_out(DEVICE(&s->pmc.iou.slcr), 3,
+                          qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi), 0));
+
+    /* OSPI irq */
+    object_initialize_child(OBJECT(s), "ospi-irq",
+                            &s->pmc.iou.ospi_irq, TYPE_OR_IRQ);
+    object_property_set_int(OBJECT(&s->pmc.iou.ospi_irq),
+                            "num-lines", NUM_OSPI_IRQ_LINES, &error_fatal);
+    qdev_realize(DEVICE(&s->pmc.iou.ospi_irq), NULL, &error_fatal);
+
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi), 0,
+                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 0));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_src), 0,
+                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 1));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pmc.iou.ospi_dma_dst), 0,
+                       qdev_get_gpio_in(DEVICE(&s->pmc.iou.ospi_irq), 2));
+
+    qdev_connect_gpio_out(DEVICE(&s->pmc.iou.ospi_irq), 0,
+                          pic[VERSAL_OSPI_IRQ]);
+}
 
 /* This takes the board allocated linear DDR memory and creates aliases
  * for each split DDR range/aperture on the Versal address map.
@@ -477,6 +565,7 @@  static void versal_realize(DeviceState *dev, Error **errp)
     versal_create_bbram(s, pic);
     versal_create_efuse(s, pic);
     versal_create_pmc_iou_slcr(s, pic);
+    versal_create_ospi(s, pic);
     versal_map_ddr(s);
     versal_unimp(s);
 
diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h
index 729c093dfc..dae15db352 100644
--- a/include/hw/arm/xlnx-versal.h
+++ b/include/hw/arm/xlnx-versal.h
@@ -26,6 +26,8 @@ 
 #include "hw/misc/xlnx-versal-xramc.h"
 #include "hw/nvram/xlnx-bbram.h"
 #include "hw/nvram/xlnx-versal-efuse.h"
+#include "hw/ssi/xlnx-versal-ospi.h"
+#include "hw/dma/xlnx_csu_dma.h"
 #include "hw/misc/xlnx-versal-pmc-iou-slcr.h"
 
 #define TYPE_XLNX_VERSAL "xlnx-versal"
@@ -80,6 +82,12 @@  struct Versal {
         struct {
             SDHCIState sd[XLNX_VERSAL_NR_SDS];
             XlnxVersalPmcIouSlcr slcr;
+
+            XlnxVersalOspi ospi;
+            XlnxCSUDMA ospi_dma_src;
+            XlnxCSUDMA ospi_dma_dst;
+            MemoryRegion lospi_mr;
+            qemu_or_irq ospi_irq;
         } iou;
 
         XlnxZynqMPRTC rtc;
@@ -116,6 +124,7 @@  struct Versal {
 #define VERSAL_BBRAM_APB_IRQ_0     121
 #define VERSAL_RTC_APB_ERR_IRQ     121
 #define VERSAL_PMC_IOU_SLCR_IRQ    121
+#define VERSAL_OSPI_IRQ            124
 #define VERSAL_SD0_IRQ_0           126
 #define VERSAL_EFUSE_IRQ           139
 #define VERSAL_RTC_ALARM_IRQ       142
@@ -184,6 +193,15 @@  struct Versal {
 #define MM_PMC_PMC_IOU_SLCR         0xf1060000
 #define MM_PMC_PMC_IOU_SLCR_SIZE    0x10000
 
+#define MM_PMC_OSPI                 0xf1010000
+#define MM_PMC_OSPI_SIZE            0x10000
+
+#define MM_PMC_OSPI_DAC             0xc0000000
+#define MM_PMC_OSPI_DAC_SIZE        0x20000000
+
+#define MM_PMC_OSPI_DMA_DST         0xf1011800
+#define MM_PMC_OSPI_DMA_SRC         0xf1011000
+
 #define MM_PMC_SD0                  0xf1040000U
 #define MM_PMC_SD0_SIZE             0x10000
 #define MM_PMC_BBRAM_CTRL           0xf11f0000