Skip to contentSkip to conversation

Add Axiado SoC AX3000 and EVK board

PATCH Superseded Kuan-Jui Chiu 2 participants 14 messages Jun 2 – Jun 16

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add Axiado SoC AX3000 and EVK board

This patchset introduces Axiado SoC AX3000 and a EVK SCM3003 for emulation The model for Axiado SoC AX3000 supports
4 Cortex-A53 CPUs
Arm Generic Interrupt Controller v3
4 Cadence UARTs
1 SDHCI controller with PHY
8 Cadence GPIOs

Verified the machine "axiado-scm3003" with following command

qemu-system-aarch64 \
    -m 4G \
    -machine axiado-scm3003 \
    -device loader,file=u-boot.bin,addr=0x3C000000,cpu-num=0 \
    -nographic \
    -serial null \
    -serial null \
    -serial null \
    -serial mon:stdio \
    -drive if=sd,file=obmc-phosphor-image-evk-axiado-qemu.wic,format=raw

Refer Axiado website for more product information
https://axiado.com/products/

Changes in v3:
1. Add a new patch for Axiado SD host controller
2. Fill in valid/impl parameters of MemoryRegionOps in ax3000-soc/cadence_gpio/axiado_sdhci
3. Follow C99 standard to declare variable in for-loop
4. Remove comment "TBD" from empty function
5. Define marco for bit definition in axiado_sdhci
6. Move object_initialize_child() to instance_init() from realize() in axiado_sdhci
7. Remove callback of get_default_cpu_type() from ax3000-soc and set type of CPU to A53
8. Update the command to run "axiado-scm3003" in QEMU

Changes in v2:
1. Move axiado-* to ax3000-* in hw/arm and include/hw/arm
2. Add axiado_sdhci to support AXIADO_SDHCI
3. Move implementation for eMMC PHY device to axiado_sdhci
4. Use UNIMP to create dummy device "timerctrl"
5. Add cadence_gpio to support CADENCE_GPIO
6. Enable Cadence GPIO controllers on AX3000 SoC

Kuan-Jui Chiu (6):
hw/arm: Add Axiado SoC AX3000
hw/sd: Add Axiado SD host controller with eMMC PHY hw/arm: ax3000-soc: Enable Axiado SD host controller hw/arm: Add Axiado EVK SCM3003
hw/gpio: Add Cadence GPIO controller hw/arm: ax3000-soc: Enable Cadence GPIO controllers

 MAINTAINERS                    |   9 +
 hw/arm/Kconfig                 |  14 ++
 hw/arm/ax3000-boards.c         |  47 +++++
 hw/arm/ax3000-evk.c            |  27 +++
 hw/arm/ax3000-soc.c            | 267 ++++++++++++++++++++++++++++
 hw/arm/meson.build             |   6 +
 hw/gpio/Kconfig                |   3 +
 hw/gpio/cadence_gpio.c         | 307 +++++++++++++++++++++++++++++++++
 hw/gpio/meson.build            |   1 +
 hw/gpio/trace-events           |   5 +
 hw/sd/Kconfig                  |   4 +
 hw/sd/axiado_sdhci.c           | 115 ++++++++++++
 hw/sd/meson.build              |   1 +
 include/hw/arm/ax3000-boards.h |  28 +++
 include/hw/arm/ax3000-soc.h    |  99 +++++++++++
 include/hw/gpio/cadence_gpio.h |  55 ++++++
 include/hw/sd/axiado_sdhci.h   |  21 +++
 17 files changed, 1009 insertions(+)
 create mode 100644 hw/arm/ax3000-boards.c
 create mode 100644 hw/arm/ax3000-evk.c
 create mode 100644 hw/arm/ax3000-soc.c
 create mode 100644 hw/gpio/cadence_gpio.c
 create mode 100644 hw/sd/axiado_sdhci.c
 create mode 100644 include/hw/arm/ax3000-boards.h
 create mode 100644 include/hw/arm/ax3000-soc.h
 create mode 100644 include/hw/gpio/cadence_gpio.h
 create mode 100644 include/hw/sd/axiado_sdhci.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/6 hw/arm: Add Axiado SoC AX3000

This patch adds new model for Axiado SoC AX3000 which supports
4 Cortex-A53 ARM64 CPUs
Arm Generic Interrupt Controller v3
4 Cadence UARTs

---
 MAINTAINERS                 |   7 ++
 hw/arm/Kconfig              |   7 ++
 hw/arm/ax3000-soc.c         | 218 ++++++++++++++++++++++++++++++++++++
 hw/arm/meson.build          |   3 +
 include/hw/arm/ax3000-soc.h |  71 ++++++++++++
 5 files changed, 306 insertions(+)
 create mode 100644 hw/arm/ax3000-soc.c
 create mode 100644 include/hw/arm/ax3000-soc.h
MAINTAINERS +7 -0
index cd5c4831e27..3782c83738a 100644
@@ -1298,6 +1298,13 @@ M: Manos Pitsidianakis <[email protected]>
 S: Maintained
 F: rust/hw/char/pl011/
 
+Axiado SoCs and EVKs
+M: Kuan-Jui Chiu <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/arm/ax3000*.c
+F: include/hw/arm/ax3000*.h
+
 AVR Machines
 -------------
 
hw/arm/Kconfig +7 -0
index 5b198402d5e..39f0b652a0f 100644
@@ -716,3 +716,10 @@ config ARMSSE
     select UNIMP
     select SSE_COUNTER
     select SSE_TIMER
+
+config AXIADO_SOC
+    bool
+    depends on ARM
+    select ARM_GIC
+    select CADENCE # UART
+    select UNIMP
hw/arm/ax3000-soc.c new file +218 -0

218 lines not on this page · raw message

hw/arm/meson.build +3 -0
index 80068f70bb9..772ae5211dc 100644
@@ -103,6 +103,9 @@ arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c'))
 arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
 
+arm_common_ss.add(when: ['CONFIG_AXIADO_SOC', 'TARGET_AARCH64'], if_true: files(
+  'ax3000-soc.c'))
+
 arm_common_ss.add(files('boot.c'))
 
 hw_arch += {'arm': arm_ss}
include/hw/arm/ax3000-soc.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/6] hw/arm: Add Axiado SoC AX3000

Quoted 93 lines · Kuan-Jui Chiu

This patch adds new model for Axiado SoC AX3000 which supports
4 Cortex-A53 ARM64 CPUs
Arm Generic Interrupt Controller v3
4 Cadence UARTs

---
 MAINTAINERS                 |   7 ++
 hw/arm/Kconfig              |   7 ++
 hw/arm/ax3000-soc.c         | 218 ++++++++++++++++++++++++++++++++++++
 hw/arm/meson.build          |   3 +
 include/hw/arm/ax3000-soc.h |  71 ++++++++++++
 5 files changed, 306 insertions(+)
 create mode 100644 hw/arm/ax3000-soc.c
 create mode 100644 include/hw/arm/ax3000-soc.h
MAINTAINERS +7 -0
index cd5c4831e27..3782c83738a 100644
@@ -1298,6 +1298,13 @@ M: Manos Pitsidianakis <[email protected]>
 S: Maintained
 F: rust/hw/char/pl011/
 
+Axiado SoCs and EVKs
+M: Kuan-Jui Chiu <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/arm/ax3000*.c
+F: include/hw/arm/ax3000*.h
+
 AVR Machines
 -------------
 
hw/arm/Kconfig +7 -0
index 5b198402d5e..39f0b652a0f 100644
@@ -716,3 +716,10 @@ config ARMSSE
     select UNIMP
     select SSE_COUNTER
     select SSE_TIMER
+
+config AXIADO_SOC
+    bool
+    depends on ARM
+    select ARM_GIC
+    select CADENCE # UART
+    select UNIMP
hw/arm/ax3000-soc.c new file +37 -0
new file mode 100644
index 00000000000..517cc6f52d5
@@ -0,0 +1,218 @@
+/*
+ * Axiado SoC AX3000
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "system/address-spaces.h"
+#include "hw/arm/bsa.h"
+#include "hw/arm/ax3000-soc.h"
+#include "hw/misc/unimp.h"
+#include "system/system.h"
+#include "qobject/qlist.h"
+#include "qom/object.h"
+#include "hw/core/boards.h"
+
+static uint64_t pll_read(void *opaque, hwaddr offset, unsigned size)
+{
+    switch (offset) {
+    case CLKRST_CPU_PLL_POSTDIV_OFFSET:
+        return 0x20891b;
+    case CLKRST_CPU_PLL_STS_OFFSET:
+        return 0x01;
+    default:
+        return 0x00;
+    }
+}
+
+static void pll_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
+{
+}
+
+static const MemoryRegionOps pll_ops = {
+    .read = pll_read,
+    .write = pll_write,

hw/arm/ax3000-soc.c line 47

Quoted 10 lines
hw/arm/ax3000-soc.c new file +10 -0
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    }
+};

This needs to be its own device model. Don't set up and map a MemoryRegionOps directly in this SoC object.

thanks
-- PMM

#3 lore raw

PATCH v3 2/6 hw/sd: Add Axiado SD host controller with eMMC PHY

In reply to Kuan-Jui Chiu

This patch add a new model for Axiado SD host controller which is compatible with SDHCI 3.0 spec

This device model also includes a eMMC PHY which helps to control SD/eMMC

---
 MAINTAINERS                  |   2 +
 hw/sd/Kconfig                |   4 ++
 hw/sd/axiado_sdhci.c         | 115 +++++++++++++++++++++++++++++++++++
 hw/sd/meson.build            |   1 +
 include/hw/sd/axiado_sdhci.h |  21 +++++++
 5 files changed, 143 insertions(+)
 create mode 100644 hw/sd/axiado_sdhci.c
 create mode 100644 include/hw/sd/axiado_sdhci.h
MAINTAINERS +2 -0
index 3782c83738a..0a3b26c5417 100644
@@ -1303,7 +1303,9 @@ M: Kuan-Jui Chiu <[email protected]>
 L: [email protected]
 S: Maintained
 F: hw/arm/ax3000*.c
+F: hw/*/axiado*.c
 F: include/hw/arm/ax3000*.h
+F: include/hw/*/axiado*.h
 
 AVR Machines
 -------------
hw/sd/Kconfig +4 -0
index 633b9afec91..c69bf24f8de 100644
@@ -23,3 +23,7 @@ config SDHCI_PCI
 config CADENCE_SDHCI
     bool
     select SDHCI
+
+config AXIADO_SDHCI
+    bool
+    select SDHCI
hw/sd/axiado_sdhci.c new file +115 -0

115 lines not on this page · raw message

hw/sd/meson.build +1 -0
index b43d45bc564..ebf09e30a48 100644
@@ -10,3 +10,4 @@ system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sdhci.c'))
 system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-sdhost.c'))
 system_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_sdhci.c'))
 system_ss.add(when: 'CONFIG_CADENCE_SDHCI', if_true: files('cadence_sdhci.c'))
+system_ss.add(when: 'CONFIG_AXIADO_SDHCI', if_true: files('axiado_sdhci.c'))
include/hw/sd/axiado_sdhci.h new file +21 -0
new file mode 100644
index 00000000000..85afebad931
@@ -0,0 +1,21 @@
+/*
+ * Axiado SD Host Controller
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "hw/sd/sdhci.h"
+#include "qom/object.h"
+
+#define TYPE_AXIADO_SDHCI "axiado-sdhci"
+OBJECT_DECLARE_SIMPLE_TYPE(AxiadoSDHCIState, AXIADO_SDHCI)
+
+typedef struct AxiadoSDHCIState {
+    SysBusDevice parent;
+
+    SDHCIState sdhci;
+    MemoryRegion emmc_phy;
+    BusState *sd_bus;
+} AxiadoSDHCIState;
Signature · 1 line
2.34.1
Reviewed-by on v3 2/6
#4 lore raw

Re: [PATCH v3 2/6] hw/sd: Add Axiado SD host controller with eMMC PHY

Quoted 12 lines · Kuan-Jui Chiu

This patch add a new model for Axiado SD host controller which is compatible with SDHCI 3.0 spec

This device model also includes a eMMC PHY which helps to control SD/eMMC

hw/sd/axiado_sdhci.c new file +4 -0
+static void axiado_sdhci_realize(DeviceState *dev, Error **errp)
+{
+    AxiadoSDHCIState *s = AXIADO_SDHCI(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);

hw/sd/axiado_sdhci.c line 71

Quoted 10 lines
hw/sd/axiado_sdhci.c new file +10 -0
+    SysBusDevice *sdhci_sbd;
+
+    qdev_prop_set_uint64(DEVICE(&s->sdhci), "capareg", 0x216737eed0b0);
+    qdev_prop_set_uint64(DEVICE(&s->sdhci), "sd-spec-version", 3);
+
+    sdhci_sbd = SYS_BUS_DEVICE(&s->sdhci);
+    sysbus_realize(sdhci_sbd, errp);
+    if (*errp) {
+        return;
+    }

You need an "ERRP_GUARD();" line at the top of this function, because otherwise errp can be NULL here. (There's a long comment in include/qapi/error.h that discusses the various ways of handling Error objects and the standard patterns to use.)

Otherwise

thanks
-- PMM

#5 lore raw

Re: [PATCH v3 2/6] hw/sd: Add Axiado SD host controller with eMMC PHY

Quoted 21 lines · Peter Maydell
Quoted 19 lines · Kuan-Jui Chiu

This patch add a new model for Axiado SD host controller which is compatible with SDHCI 3.0 spec

This device model also includes a eMMC PHY which helps to control SD/eMMC

hw/sd/axiado_sdhci.c new file +11 -0
+static void axiado_sdhci_realize(DeviceState *dev, Error **errp)
+{
+    AxiadoSDHCIState *s = AXIADO_SDHCI(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SysBusDevice *sdhci_sbd;
+
+    qdev_prop_set_uint64(DEVICE(&s->sdhci), "capareg", 0x216737eed0b0);
+    qdev_prop_set_uint64(DEVICE(&s->sdhci), "sd-spec-version", 3);
+
+    sdhci_sbd = SYS_BUS_DEVICE(&s->sdhci);
+    sysbus_realize(sdhci_sbd, errp);
Quoted 8 lines

hw/sd/axiado_sdhci.c line 71

Quoted 3 lines
hw/sd/axiado_sdhci.c new file +3 -0
+    if (*errp) {
+        return;
+    }

You need an "ERRP_GUARD();" line at the top of this function, because otherwise errp can be NULL here. (There's a long comment in include/qapi/error.h that discusses the various ways of handling Error objects and the standard patterns to use.)

Actually, better would be to use the return value of sysbus_realize() instead of looking at errp:

    if (!sysbus_realize(sdhci_sbd, errp)) {
        return;
    }

Then you don't need the ERRP_GUARD.

-- PMM

#6 lore raw

PATCH v3 3/6 hw/arm: ax3000-soc: Enable Axiado SD host controller

In reply to Kuan-Jui Chiu

Enable SD host controller into Axiado AX3000 SoC to load kernel and rootfs from eMMC.

---
 hw/arm/Kconfig              |  1 +
 hw/arm/ax3000-soc.c         | 19 +++++++++++++++++++
 include/hw/arm/ax3000-soc.h |  7 +++++++
 3 files changed, 27 insertions(+)
hw/arm/Kconfig +1 -0
index 39f0b652a0f..5b9cf25dd31 100644
@@ -722,4 +722,5 @@ config AXIADO_SOC
     depends on ARM
     select ARM_GIC
     select CADENCE # UART
+    select AXIADO_SDHCI
     select UNIMP
hw/arm/ax3000-soc.c +19 -0
index 517cc6f52d5..fd8c2f977e7 100644
@@ -63,6 +63,8 @@ static void ax3000_init(Object *obj)
         g_autofree char *name = g_strdup_printf("uart%d", i);
         object_initialize_child(obj, name, &s->uart[i], TYPE_CADENCE_UART);
     }
+
+    object_initialize_child(obj, "sdhci0", &s->sdhci0, TYPE_AXIADO_SDHCI);
 }
 
 static void ax3000_realize(DeviceState *dev, Error **errp)
@@ -193,6 +195,23 @@ static void ax3000_realize(DeviceState *dev, Error **errp)
                           "ax3000.pllctrl", 32);
     memory_region_add_subregion(get_system_memory(), AX3000_PLL_BASE,
                                 &s->pll_ctrl);
+
+    /* SDHCI */
+    sdhci0_sbd = SYS_BUS_DEVICE(&s->sdhci0);
+    if (!sysbus_realize(sdhci0_sbd, errp)) {
+        return;
+    }
+
+    sysbus_mmio_map(sdhci0_sbd, 0, AX3000_SDHCI0_BASE);
+    sysbus_mmio_map(sdhci0_sbd, 1, AX3000_EMMC_PHY_BASE);
+    sysbus_connect_irq(sdhci0_sbd, 0,
+                       qdev_get_gpio_in(gic_dev, AX3000_SDHCI0_IRQ));
+
+    card = qdev_new(TYPE_SD_CARD);
+    qdev_prop_set_drive_err(card, "drive",
+                            blk_by_legacy_dinfo((drive_get(IF_SD, 0, 0))),
+                            &error_fatal);
+    qdev_realize_and_unref(card, s->sdhci0.sd_bus, &error_fatal);
 }
 
 static void ax3000_class_init(ObjectClass *oc, const void *data)
include/hw/arm/ax3000-soc.h +7 -0
index 6e3b5f51d30..763866ce6e2 100644
@@ -12,6 +12,7 @@
 #include "cpu.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/char/cadence_uart.h"
+#include "hw/sd/axiado_sdhci.h"
 #include "hw/core/sysbus.h"
 #include "qemu/units.h"
 
@@ -33,6 +34,9 @@ OBJECT_DECLARE_TYPE(Ax3000SoCState, Ax3000SoCClass, AX3000_SOC)
 #define AX3000_UART2_BASE       0x80620000
 #define AX3000_UART3_BASE       0x80520800
 
+#define AX3000_SDHCI0_BASE      0x86000000
+#define AX3000_EMMC_PHY_BASE    0x80801C00
+
 #define AX3000_TIMER_CTRL       0x8A020000
 #define AX3000_PLL_BASE         0x80000000
 #define CLKRST_CPU_PLL_POSTDIV_OFFSET   0x0C
@@ -53,6 +57,7 @@ typedef struct Ax3000SoCState {
     MemoryRegion        dram[AX3000_NUM_BANKS];
     MemoryRegion        pll_ctrl;
     CadenceUARTState    uart[AX3000_NUM_UARTS];
+    AxiadoSDHCIState    sdhci0;
 } Ax3000SoCState;
 
 typedef struct Ax3000SoCClass {
@@ -66,6 +71,8 @@ enum Ax3000Irqs {
     AX3000_UART1_IRQ    = 113,
     AX3000_UART2_IRQ    = 114,
     AX3000_UART3_IRQ    = 170,
+
+    AX3000_SDHCI0_IRQ   = 123,
 };
 
 #endif /* AXIADO_AX3000_H */
Signature · 1 line
2.34.1
#8 lore raw

PATCH v3 4/6 hw/arm: Add Axiado EVK SCM3003

In reply to Kuan-Jui Chiu

Add EVK axiado-scm3003 built with AX3000 SoC

---
 hw/arm/Kconfig                 |  5 ++++
 hw/arm/ax3000-boards.c         | 47 ++++++++++++++++++++++++++++++++++
 hw/arm/ax3000-evk.c            | 27 +++++++++++++++++++
 hw/arm/meson.build             |  3 +++
 include/hw/arm/ax3000-boards.h | 28 ++++++++++++++++++++
 5 files changed, 110 insertions(+)
 create mode 100644 hw/arm/ax3000-boards.c
 create mode 100644 hw/arm/ax3000-evk.c
 create mode 100644 include/hw/arm/ax3000-boards.h
hw/arm/Kconfig +5 -0
index 5b9cf25dd31..175e6c7985b 100644
@@ -724,3 +724,8 @@ config AXIADO_SOC
     select CADENCE # UART
     select AXIADO_SDHCI
     select UNIMP
+
+config AXIADO_EVK
+    bool
+    default y
+    select AXIADO_SOC
hw/arm/ax3000-boards.c new file +47 -0

47 lines not on this page · raw message

hw/arm/ax3000-evk.c new file +27 -0
new file mode 100644
index 00000000000..a1708488710
@@ -0,0 +1,27 @@
+/*
+ * Axiado Evaluation Kit Emulation
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/arm/ax3000-boards.h"
+
+static void axiado_scm3003_class_init(ObjectClass *oc, const void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->desc = "Axiado SCM3003 EVK Board";
+}
+
+static const TypeInfo ax3000_evk_types[] = {
+    {
+        .name          = MACHINE_TYPE_NAME("axiado-scm3003"),
+        .parent        = TYPE_AX3000_MACHINE,
+        .class_init    = axiado_scm3003_class_init,
+    }
+};
+
+DEFINE_TYPES(ax3000_evk_types)
hw/arm/meson.build +3 -0
index 772ae5211dc..61358dd4c8f 100644
@@ -105,6 +105,9 @@ arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
 
 arm_common_ss.add(when: ['CONFIG_AXIADO_SOC', 'TARGET_AARCH64'], if_true: files(
   'ax3000-soc.c'))
+arm_common_ss.add(when: ['CONFIG_AXIADO_EVK', 'TARGET_AARCH64'], if_true: files(
+  'ax3000-boards.c',
+  'ax3000-evk.c'))
 
 arm_common_ss.add(files('boot.c'))
 
include/hw/arm/ax3000-boards.h new file +28 -0
new file mode 100644
index 00000000000..4a632661e1e
@@ -0,0 +1,28 @@
+/*
+ * Axiado Boards
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef AXIADO_BOARD_H
+#define AXIADO_BOARD_H
+
+#include "hw/core/boards.h"
+#include "hw/arm/ax3000-soc.h"
+
+#define TYPE_AX3000_MACHINE       MACHINE_TYPE_NAME("ax3000")
+OBJECT_DECLARE_TYPE(Ax3000MachineState, Ax3000MachineClass, AX3000_MACHINE)
+
+typedef struct Ax3000MachineState {
+    MachineState parent;
+
+    Ax3000SoCState *soc;
+} Ax3000MachineState;
+
+typedef struct Ax3000MachineClass {
+    MachineClass parent;
+
+} Ax3000MachineClass;
+#endif
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v3 4/6] hw/arm: Add Axiado EVK SCM3003

Quoted 46 lines · Kuan-Jui Chiu

Add EVK axiado-scm3003 built with AX3000 SoC

---
 hw/arm/Kconfig                 |  5 ++++
 hw/arm/ax3000-boards.c         | 47 ++++++++++++++++++++++++++++++++++
 hw/arm/ax3000-evk.c            | 27 +++++++++++++++++++
 hw/arm/meson.build             |  3 +++
 include/hw/arm/ax3000-boards.h | 28 ++++++++++++++++++++
 5 files changed, 110 insertions(+)
 create mode 100644 hw/arm/ax3000-boards.c
 create mode 100644 hw/arm/ax3000-evk.c
 create mode 100644 include/hw/arm/ax3000-boards.h
hw/arm/Kconfig +5 -0
index 5b9cf25dd31..175e6c7985b 100644
@@ -724,3 +724,8 @@ config AXIADO_SOC
     select CADENCE # UART
     select AXIADO_SDHCI
     select UNIMP
+
+config AXIADO_EVK
+    bool
+    default y
+    select AXIADO_SOC
hw/arm/ax3000-boards.c new file +12 -0
new file mode 100644
index 00000000000..ad3dd963656
@@ -0,0 +1,47 @@
+/*
+ * Axiado Boards
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/arm/ax3000-boards.h"
+#include "hw/arm/machines-qom.h"
+#include "qemu/error-report.h"

hw/arm/ax3000-boards.c line 22

Quoted 10 lines
hw/arm/ax3000-boards.c new file +10 -0
+#include "qom/object.h"
+
+static void ax3000_machine_init(MachineState *machine)
+{
+    Ax3000MachineState *ams = AX3000_MACHINE(machine);
+
+    ams->soc = AX3000_SOC(object_new(TYPE_AX3000_SOC));
+    object_property_add_child(OBJECT(machine), "soc", OBJECT(ams->soc));
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(ams->soc), &error_fatal);
+}

You *must* call arm_load_kernel() in your machine init function. This is not an optional step -- that function does work that must be done for things like reset to work correctly, even if the user is not using "-kernel". Also, even if you don't typically want to use "-kernel", other people might. This is standard functionality all boards need to provide.

thanks
-- PMM

#10 lore raw

PATCH v3 5/6 hw/gpio: Add Cadence GPIO controller

In reply to Kuan-Jui Chiu

This patch add a new model for Cadence GPIO controller which supports 32 pins and interrupts for level-triggered/edge-triggered type on input pins.

Also define new trace functions for analysis purpose and new configuration to enable this model.

---
 hw/gpio/Kconfig                |   3 +
 hw/gpio/cadence_gpio.c         | 307 +++++++++++++++++++++++++++++++++
 hw/gpio/meson.build            |   1 +
 hw/gpio/trace-events           |   5 +
 include/hw/gpio/cadence_gpio.h |  55 ++++++
 5 files changed, 371 insertions(+)
 create mode 100644 hw/gpio/cadence_gpio.c
 create mode 100644 include/hw/gpio/cadence_gpio.h
hw/gpio/Kconfig +3 -0
index a209294c20c..fcc7c70bd50 100644
@@ -30,3 +30,6 @@ config PCF8574
 
 config ZAURUS_SCOOP
     bool
+
+config CADENCE_GPIO
+    bool
hw/gpio/cadence_gpio.c new file +307 -0

307 lines not on this page · raw message

hw/gpio/meson.build +1 -0
index 6a67ee958fa..0555f44b6a7 100644
@@ -19,3 +19,4 @@ system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c'))
 system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sgpio.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c'))
 system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c'))
+system_ss.add(when: 'CONFIG_CADENCE_GPIO', if_true: files('cadence_gpio.c'))
hw/gpio/trace-events +5 -0
index cea896b28f6..80ca783a039 100644
@@ -46,3 +46,8 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " "
 stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""
 stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x"
 stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x"
+
+# cadence_gpio.c
+cdns_gpio_read(const char *path, uint64_t offset, uint32_t value) "%s:reg[0x%04" PRIx64 "] -> 0x%" PRIx32
+cdns_gpio_write(const char *path, uint64_t offset, uint64_t value) "%s:reg[0x%04" PRIx64 "] <- 0x%04" PRIx64
+cdns_gpio_set(const char *path, int line, int level) "%s:[%d] <- %d"
include/hw/gpio/cadence_gpio.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH v3 5/6] hw/gpio: Add Cadence GPIO controller

Quoted 48 lines · Kuan-Jui Chiu

This patch add a new model for Cadence GPIO controller which supports 32 pins and interrupts for level-triggered/edge-triggered type on input pins.

Also define new trace functions for analysis purpose and new configuration to enable this model.

---
 hw/gpio/Kconfig                |   3 +
 hw/gpio/cadence_gpio.c         | 307 +++++++++++++++++++++++++++++++++
 hw/gpio/meson.build            |   1 +
 hw/gpio/trace-events           |   5 +
 include/hw/gpio/cadence_gpio.h |  55 ++++++
 5 files changed, 371 insertions(+)
 create mode 100644 hw/gpio/cadence_gpio.c
 create mode 100644 include/hw/gpio/cadence_gpio.h
hw/gpio/Kconfig +3 -0
index a209294c20c..fcc7c70bd50 100644
@@ -30,3 +30,6 @@ config PCF8574
 
 config ZAURUS_SCOOP
     bool
+
+config CADENCE_GPIO
+    bool
hw/gpio/cadence_gpio.c new file +12 -0
new file mode 100644
index 00000000000..08a8cf71968
@@ -0,0 +1,307 @@
+/*
+ * Cadence GPIO emulation.
+ *
+ * Author: Kuan-Jui Chiu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/gpio/cadence_gpio.h"
+#include "hw/core/irq.h"
+#include "migration/vmstate.h"

hw/gpio/cadence_gpio.c line 22

Quoted 10 lines
hw/gpio/cadence_gpio.c new file +10 -0
+#include "qemu/log.h"
+#include "trace.h"
+
+static void cdns_gpio_update_irq(CadenceGPIOState *s)
+{
+    qemu_set_irq(s->irq, s->isr ? 1 : 0);
+}
+
+static void cdns_gpio_update_isr_per_line(CadenceGPIOState *s, int line,
+                                          uint32_t new)

We don't need to do this one line at a time. Because all the registers involved are 32 bits wide and have one bit per GPIO line, we can use logical operations to calculate them all at once, like this:

static void cdns_gpio_write_inpvr(CadenceGPIOState *s, uint32_t new)

{
    /*
     * Update s->inpvr to the specified new value, and recalculate
     * s->isr accordingly.
     * We can calculate the s->isr value for all the GPIO lines
     * at once using bitwise operations.
     */
    uint32_t new_isr = 0;
    uint32_t any_edges, rising_edges, falling_edges, deassert_mask;

    /*
     * If ITR is set, this is level triggered: ISR bit set
     * when IVR matches new invpr value.
     */
    new_isr |= s->itr & ~(s->ivr ^ new);

    /*
     * If ITR is not set, this is edge-triggered. If IOAR bit
     * is set, we trigger on any edge; otherwise we trigger
     * on rising edge if IVR is set, falling if IVR bit is 0.
     */
    any_edges = s->ioar & (s->invpr ^ new);
    rising_edges = s->ivr & ~s->inpvr & new;
    falling_edges = ~s->ivr & s->inpvr & ~new;
    new_isr |= ~s->itr & (any_edges | rising_edges | falling_edges);

    /*
     * In bypass mode or if this isn't an input pin, the ISR
     * bit is forced to zero.
     */
    deassert_mask = s->bmr | ~s->dmr | s->imr;
    new_isr &= ~deassert_mask;

    s->isr = new_isr;
    s->inpvr = new;

    cdns_gpio_update_irq(s);
}

(Untested, but I believe it to be correct.)

Quoted 35 lines
hw/gpio/cadence_gpio.c new file +35 -0
+{
+    uint32_t old = extract32(s->inpvr, line, 1);
+    uint32_t ivr = extract32(s->ivr, line, 1);
+
+    /* Deassert in bypass mode or not input pin */
+    if (extract32(s->bmr, line, 1) || !extract32(s->dmr, line, 1) ||
+        extract32(s->imr, line, 1)) {
+        s->isr = deposit32(s->isr, line, 1, 0);
+        return;
+    }
+
+    if (extract32(s->itr, line, 1)) {
+        /* Level-triggered */
+        if (ivr && new) {
+            /* High level */
+            s->isr = deposit32(s->isr, line, 1, 1);
+        }
+        if (!ivr && !new) {
+            /* Low level */
+            s->isr = deposit32(s->isr, line, 1, 1);
+        }
+    } else {
+        /* Edge-triggered */
+        if (extract32(s->ioar, line, 1) && (old != new)) {
+            /* On any edge */
+            s->isr = deposit32(s->isr, line, 1, 1);
+        } else {
+            if (ivr && !old && new) {
+                /* Rising edge */
+                s->isr = deposit32(s->isr, line, 1, 1);
+            }
+            if (!ivr && old && !new) {
+                /* Falling edge */
+                s->isr = deposit32(s->isr, line, 1, 1);
+            }

hw/gpio/cadence_gpio.c line 67

Quoted 10 lines
hw/gpio/cadence_gpio.c new file +10 -0
+        }
+    }
+}
+
+static void cdns_gpio_update_isr(CadenceGPIOState *s)
+{
+    for (int i = 0; i < CDNS_GPIO_NUM; i++) {
+        uint32_t level = extract32(s->inpvr, i, 1);
+        cdns_gpio_update_isr_per_line(s, i, level);
+    }

If you use my suggestion above, this function becomes just

    /* Trigger an update of s->isr */
    cdns_gpio_write_inpvr(s, s->invpr);

and since cdns_gpio_write_inpvr() calls cdns_gpio_update_irq() at the end, you don't need to have all this function's callsites do:

        cdns_gpio_update_isr(s);
        cdns_gpio_update_irq(s);

-- they can just call cdns_gpio_update_isr() only.

Quoted 5 lines
hw/gpio/cadence_gpio.c new file +5 -0
+}
+
+static void cdns_gpio_set(void *opaque, int line, int level)
+{
+    CadenceGPIOState *s = CADENCE_GPIO(opaque);

hw/gpio/cadence_gpio.c line 82

Quoted 10 lines
hw/gpio/cadence_gpio.c new file +10 -0
+    uint32_t new = level ? 1 : 0;
+
+    trace_cdns_gpio_set(DEVICE(s)->canonical_path, line, level);
+
+    cdns_gpio_update_isr_per_line(s, line, new);
+
+    /* Sync INPVR with new value */
+    s->inpvr = deposit32(s->inpvr, line, 1, new);
+
+    cdns_gpio_update_irq(s);

Similarly this function becomes something like

      new_invpr = deposit32(s->inpvr, line, 1, new);
      cdns_gpio_write_invpr(s, new_invpr);

hw/gpio/cadence_gpio.c line 91

Quoted 9 lines
hw/gpio/cadence_gpio.c new file +9 -0
+}
+
+static inline void cdns_gpio_update_output_irq(CadenceGPIOState *s)
+{
+    for (int i = 0; i < CDNS_GPIO_NUM; i++) {
+        /* Forward the output value to corresponding irq */
+        if (!extract32(s->bmr, i, 1) && !extract32(s->dmr, i, 1) &&
+            extract32(s->oer, i, 1) && s->output[i]) {
+            qemu_set_irq(s->output[i], extract32(s->ovr, i, 1));

You don't need to check if s->output[i] is NULL -- qemu_set_irq() will handle that correctly (this is the "GPIO is not connected to anything" case, and so it does nothing).

You might as well pre-calculate the outputs outside the loop:

   uint32_t is_output = ~s->bmr & ~s->dmr & s->oer;

so inside the loop you can do if (extract32(is_output, i, 1)) instead of 3 separate extract operations.

hw/gpio/cadence_gpio.c line 39

Quoted 3 lines
hw/gpio/cadence_gpio.c new file +3 -0
+        }
+    }
+}

thanks
-- PMM

#12 lore raw

PATCH v3 6/6 hw/arm: ax3000-soc: Enable Cadence GPIO controllers

In reply to Kuan-Jui Chiu

Enable 8 Cadence GPIO controllers into Axiado AX3000 SoC

---
 hw/arm/Kconfig              |  1 +
 hw/arm/ax3000-soc.c         | 30 ++++++++++++++++++++++++++++++
 include/hw/arm/ax3000-soc.h | 21 +++++++++++++++++++++
 3 files changed, 52 insertions(+)
hw/arm/Kconfig +1 -0
index 175e6c7985b..1affb1f6228 100644
@@ -722,6 +722,7 @@ config AXIADO_SOC
     depends on ARM
     select ARM_GIC
     select CADENCE # UART
+    select CADENCE_GPIO
     select AXIADO_SDHCI
     select UNIMP
 
hw/arm/ax3000-soc.c +30 -0
index fd8c2f977e7..3f9abc59dff 100644
@@ -65,6 +65,11 @@ static void ax3000_init(Object *obj)
     }
 
     object_initialize_child(obj, "sdhci0", &s->sdhci0, TYPE_AXIADO_SDHCI);
+
+    for (int i = 0; i < AX3000_NUM_GPIOS; i++) {
+        g_autofree char *name = g_strdup_printf("gpio%d", i);
+        object_initialize_child(obj, name, &s->gpio[i], TYPE_CADENCE_GPIO);
+    }
 }
 
 static void ax3000_realize(DeviceState *dev, Error **errp)
@@ -212,6 +217,31 @@ static void ax3000_realize(DeviceState *dev, Error **errp)
                             blk_by_legacy_dinfo((drive_get(IF_SD, 0, 0))),
                             &error_fatal);
     qdev_realize_and_unref(card, s->sdhci0.sd_bus, &error_fatal);
+
+    /* GPIOs */
+    for (int i = 0; i < AX3000_NUM_GPIOS; i++) {
+        struct {
+            hwaddr addr;
+            unsigned int irq;
+        } gpio_table[] = {
+            { AX3000_GPIO0_BASE, AX3000_GPIO0_IRQ },
+            { AX3000_GPIO1_BASE, AX3000_GPIO1_IRQ },
+            { AX3000_GPIO2_BASE, AX3000_GPIO2_IRQ },
+            { AX3000_GPIO3_BASE, AX3000_GPIO3_IRQ },
+            { AX3000_GPIO4_BASE, AX3000_GPIO4_IRQ },
+            { AX3000_GPIO5_BASE, AX3000_GPIO5_IRQ },
+            { AX3000_GPIO6_BASE, AX3000_GPIO6_IRQ },
+            { AX3000_GPIO7_BASE, AX3000_GPIO7_IRQ }
+        };
+
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), errp)) {
+            return;
+        }
+
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, gpio_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0,
+                           qdev_get_gpio_in(gic_dev, gpio_table[i].irq));
+    }
 }
 
 static void ax3000_class_init(ObjectClass *oc, const void *data)
include/hw/arm/ax3000-soc.h +21 -0
index 763866ce6e2..aa388f79f0e 100644
@@ -12,6 +12,7 @@
 #include "cpu.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/char/cadence_uart.h"
+#include "hw/gpio/cadence_gpio.h"
 #include "hw/sd/axiado_sdhci.h"
 #include "hw/core/sysbus.h"
 #include "qemu/units.h"
@@ -37,6 +38,15 @@ OBJECT_DECLARE_TYPE(Ax3000SoCState, Ax3000SoCClass, AX3000_SOC)
 #define AX3000_SDHCI0_BASE      0x86000000
 #define AX3000_EMMC_PHY_BASE    0x80801C00
 
+#define AX3000_GPIO0_BASE       0x80500000
+#define AX3000_GPIO1_BASE       0x80580000
+#define AX3000_GPIO2_BASE       0x80600000
+#define AX3000_GPIO3_BASE       0x80680000
+#define AX3000_GPIO4_BASE       0x80700000
+#define AX3000_GPIO5_BASE       0x80780000
+#define AX3000_GPIO6_BASE       0x80800000
+#define AX3000_GPIO7_BASE       0x80880000
+
 #define AX3000_TIMER_CTRL       0x8A020000
 #define AX3000_PLL_BASE         0x80000000
 #define CLKRST_CPU_PLL_POSTDIV_OFFSET   0x0C
@@ -47,6 +57,7 @@ enum Ax3000Configuration {
     AX3000_NUM_IRQS     = 224,
     AX3000_NUM_BANKS    = 2,
     AX3000_NUM_UARTS    = 4,
+    AX3000_NUM_GPIOS    = 8,
 };
 
 typedef struct Ax3000SoCState {
@@ -57,6 +68,7 @@ typedef struct Ax3000SoCState {
     MemoryRegion        dram[AX3000_NUM_BANKS];
     MemoryRegion        pll_ctrl;
     CadenceUARTState    uart[AX3000_NUM_UARTS];
+    CadenceGPIOState    gpio[AX3000_NUM_GPIOS];
     AxiadoSDHCIState    sdhci0;
 } Ax3000SoCState;
 
@@ -73,6 +85,15 @@ enum Ax3000Irqs {
     AX3000_UART3_IRQ    = 170,
 
     AX3000_SDHCI0_IRQ   = 123,
+
+    AX3000_GPIO0_IRQ    = 183,
+    AX3000_GPIO1_IRQ    = 184,
+    AX3000_GPIO2_IRQ    = 185,
+    AX3000_GPIO3_IRQ    = 186,
+    AX3000_GPIO4_IRQ    = 187,
+    AX3000_GPIO5_IRQ    = 188,
+    AX3000_GPIO6_IRQ    = 189,
+    AX3000_GPIO7_IRQ    = 190,
 };
 
 #endif /* AXIADO_AX3000_H */
Signature · 1 line
2.34.1
Reviewed-by on v3 6/6
#13 lore raw

Re: [PATCH v3 6/6] hw/arm: ax3000-soc: Enable Cadence GPIO controllers

Quoted 4 lines · Kuan-Jui Chiu

Enable 8 Cadence GPIO controllers into Axiado AX3000 SoC

I reviewed this patch last time, and it essentially hasn't changed. Please carry across Reviewed-by: tags from previous patchsets as per our process:

https://www.qemu.org/docs/master/devel/submitting-a-patch.html#proper-use-of-reviewed-by-tags-can-aid-review

thanks
-- PMM