Skip to contentSkip to conversation

Add Aspeed GPIO controller model

PATCH Superseded Rashmica Gupta 4 participants 10 messages Jul 30, 2019 – Aug 14, 2019 Arm/Aspeed machine support

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add Aspeed GPIO controller model

There are a couple of things I'm not confident about here:
- what should be in init vs realize?
- should the irq state be in vmstate?
- is there a better way to do composition of classes (patch 3)?

v3:
- didn't have each gpio set up as an irq
- now can't access set AC on ast2400 (only exists on ast2500)
- added ast2600 implementation (patch 3)
- renamed a couple of variables for clarity

v2: Addressed Andrew's feedback, added debounce regs, renamed get/set to read/write to minimise confusion with a 'set' of registers.

Rashmica Gupta (3):
hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500
aspeed: add a GPIO controller to the SoC
hw/gpio: Add in AST2600 specific implementation

 hw/arm/aspeed_soc.c           |   17 +
 hw/gpio/Makefile.objs         |    1 +
 hw/gpio/aspeed_gpio.c         | 1103 +++++++++++++++++++++++++++++++++
 include/hw/arm/aspeed_soc.h   |    3 +
 include/hw/gpio/aspeed_gpio.h |   91 +++
 5 files changed, 1215 insertions(+)
 create mode 100644 hw/gpio/aspeed_gpio.c
 create mode 100644 include/hw/gpio/aspeed_gpio.h
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/3 hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500

GPIO pins are arranged in groups of 8 pins labeled A,B,..,Y,Z,AA,AB,AC. (Note that the ast2400 controller only goes up to group AB). A set has four groups (except set AC which only has one) and is referred to by the groups it is composed of (eg ABCD,EFGH,...,YZAAAB). Each set is accessed and controlled by a bank of 14 registers.

These registers operate on a per pin level where each bit in the register corresponds to a pin, except for the command source registers. The command source registers operate on a per group level where bits 24, 16, 8 and 0 correspond to each group in the set.

eg. registers for set ABCD:

 |D7...D0|C7...C0|B7...B0|A7...A0| <- GPIOs
 |31...24|23...16|15....8|7.....0| <- bit position

Note that there are a couple of groups that only have 4 pins.

There are two ways that this model deviates from the behaviour of the actual controller:
(1) The only control source driving the GPIO pins in the model is the ARM model (as there currently aren't models for the LPC or Coprocessor).

(2) None of the registers in the model are reset tolerant (needs integration with the watchdog).

---
 hw/gpio/Makefile.objs         |   1 +
 hw/gpio/aspeed_gpio.c         | 923 ++++++++++++++++++++++++++++++++++
 include/hw/gpio/aspeed_gpio.h |  91 ++++
 3 files changed, 1015 insertions(+)
 create mode 100644 hw/gpio/aspeed_gpio.c
 create mode 100644 include/hw/gpio/aspeed_gpio.h
hw/gpio/Makefile.objs +1 -0
index e5da0cb54f..d305b3b24b 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_OMAP) += omap_gpio.o
 obj-$(CONFIG_IMX) += imx_gpio.o
 obj-$(CONFIG_RASPI) += bcm2835_gpio.o
 obj-$(CONFIG_NRF51_SOC) += nrf51_gpio.o
+obj-$(CONFIG_ASPEED_SOC) += aspeed_gpio.o
hw/gpio/aspeed_gpio.c new file +923 -0

923 lines not on this page · raw message

include/hw/gpio/aspeed_gpio.h new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [Qemu-arm] [PATCH v3 1/3] hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500

Quoted 27 lines · Rashmica Gupta

GPIO pins are arranged in groups of 8 pins labeled A,B,..,Y,Z,AA,AB,AC. (Note that the ast2400 controller only goes up to group AB). A set has four groups (except set AC which only has one) and is referred to by the groups it is composed of (eg ABCD,EFGH,...,YZAAAB). Each set is accessed and controlled by a bank of 14 registers.

These registers operate on a per pin level where each bit in the register corresponds to a pin, except for the command source registers. The command source registers operate on a per group level where bits 24, 16, 8 and 0 correspond to each group in the set.

eg. registers for set ABCD:

 |D7...D0|C7...C0|B7...B0|A7...A0| <- GPIOs
 |31...24|23...16|15....8|7.....0| <- bit position

Note that there are a couple of groups that only have 4 pins.

There are two ways that this model deviates from the behaviour of the actual controller:
(1) The only control source driving the GPIO pins in the model is the ARM model (as there currently aren't models for the LPC or Coprocessor).

(2) None of the registers in the model are reset tolerant (needs integration with the watchdog).

include/hw/gpio/aspeed_gpio.h line 44

Quoted 6 lines
include/hw/gpio/aspeed_gpio.h new file +6 -0
+typedef struct AspeedGPIOReg {
+    uint16_t set_idx;
+    uint32_t (*read)(GPIOSets *regs);
+    void (*write)(AspeedGPIOState *s, GPIOSets *regs,
+                const GPIOSetProperties *props, uint32_t val);
+ } AspeedGPIOReg;

Please don't create new abstractions for implementing registers that are only used in one device model. We have a couple of basic approaches that we use already:

* just open coded switch statements in the read and write functions for the device's MMIO regions
* if you'd rather have a data structure defining each register with hook functions where they need to do particular behaviour on reads and writes, have a look at the APIs in include/hw/register.h. Currently these are used just by some of the Xilinx devices, but if you want an API shaped like that you can use it.

thanks
-- PMM

#3 lore raw

Re: [Qemu-arm] [PATCH v3 1/3] hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500

Quoted 42 lines · Peter Maydell
Quoted 33 lines · Rashmica Gupta

GPIO pins are arranged in groups of 8 pins labeled A,B,..,Y,Z,AA,AB,AC.
(Note that the ast2400 controller only goes up to group AB). A set has four groups (except set AC which only has one) and is referred to by the groups it is composed of (eg ABCD,EFGH,...,YZAAAB).
Each set is accessed and controlled by a bank of 14 registers.

These registers operate on a per pin level where each bit in the register
corresponds to a pin, except for the command source registers. The command
source registers operate on a per group level where bits 24, 16, 8 and 0
correspond to each group in the set.

eg. registers for set ABCD:

 |D7...D0|C7...C0|B7...B0|A7...A0| <- GPIOs
 |31...24|23...16|15....8|7.....0| <- bit position

Note that there are a couple of groups that only have 4 pins.

There are two ways that this model deviates from the behaviour of the
actual controller:
(1) The only control source driving the GPIO pins in the model is the ARM
model (as there currently aren't models for the LPC or Coprocessor).

(2) None of the registers in the model are reset tolerant (needs integration with the watchdog).

include/hw/gpio/aspeed_gpio.h line 44

Quoted 6 lines
include/hw/gpio/aspeed_gpio.h new file +6 -0
+typedef struct AspeedGPIOReg {
+    uint16_t set_idx;
+    uint32_t (*read)(GPIOSets *regs);
+    void (*write)(AspeedGPIOState *s, GPIOSets *regs,
+                const GPIOSetProperties *props, uint32_t val);
+ } AspeedGPIOReg;
Quoted 3 lines

Please don't create new abstractions for implementing registers that are only used in one device model. We have a couple of basic approaches that we use already:

That's fair enough :)

Quoted 3 lines

* just open coded switch statements in the read and write functions for the device's MMIO regions

Thoughts on the switch statement approach in v4? I think it's much nicer than two huge switch statements.

Quoted 7 lines

* if you'd rather have a data structure defining each register with hook functions where they need to do particular behaviour on reads and writes, have a look at the APIs in include/hw/register.h. Currently these are used just by some of the Xilinx devices, but if you want an API shaped like that you can use it.

I had a play with the existing register API. I couldn't quite get it to work. When writing to some registers in a set we need to look at other registers in that set, and so we need some kind of structure tells us how to find those registers.

Quoted 2 lines

thanks
-- PMM

#4 lore raw

PATCH v3 2/3 aspeed: add a GPIO controller to the SoC

In reply to Rashmica Gupta
---
 hw/arm/aspeed_soc.c         | 17 +++++++++++++++++
 include/hw/arm/aspeed_soc.h |  3 +++
 2 files changed, 20 insertions(+)
hw/arm/aspeed_soc.c +17 -0
index c6fb3700f2..ff422c8ad1 100644
@@ -124,6 +124,7 @@ static const AspeedSoCInfo aspeed_socs[] = {
         .spis_num     = 1,
         .fmc_typename = "aspeed.smc.fmc",
         .spi_typename = aspeed_soc_ast2400_typenames,
+        .gpio_typename = "aspeed.gpio-ast2400",
         .wdts_num     = 2,
         .irqmap       = aspeed_soc_ast2400_irqmap,
         .memmap       = aspeed_soc_ast2400_memmap,
@@ -136,6 +137,7 @@ static const AspeedSoCInfo aspeed_socs[] = {
         .spis_num     = 1,
         .fmc_typename = "aspeed.smc.fmc",
         .spi_typename = aspeed_soc_ast2400_typenames,
+        .gpio_typename = "aspeed.gpio-ast2400",
         .wdts_num     = 2,
         .irqmap       = aspeed_soc_ast2400_irqmap,
         .memmap       = aspeed_soc_ast2400_memmap,
@@ -148,6 +150,7 @@ static const AspeedSoCInfo aspeed_socs[] = {
         .spis_num     = 1,
         .fmc_typename = "aspeed.smc.fmc",
         .spi_typename = aspeed_soc_ast2400_typenames,
+        .gpio_typename = "aspeed.gpio-ast2400",
         .wdts_num     = 2,
         .irqmap       = aspeed_soc_ast2400_irqmap,
         .memmap       = aspeed_soc_ast2400_memmap,
@@ -160,6 +163,7 @@ static const AspeedSoCInfo aspeed_socs[] = {
         .spis_num     = 2,
         .fmc_typename = "aspeed.smc.ast2500-fmc",
         .spi_typename = aspeed_soc_ast2500_typenames,
+        .gpio_typename = "aspeed.gpio-ast2500",
         .wdts_num     = 3,
         .irqmap       = aspeed_soc_ast2500_irqmap,
         .memmap       = aspeed_soc_ast2500_memmap,
@@ -246,6 +250,9 @@ static void aspeed_soc_init(Object *obj)
 
     sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
                           TYPE_ASPEED_XDMA);
+
+    sysbus_init_child_obj(obj, "gpio", OBJECT(&s->gpio), sizeof(s->gpio),
+                          sc->info->gpio_typename);
 }
 
 static void aspeed_soc_realize(DeviceState *dev, Error **errp)
@@ -425,6 +432,16 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
                     sc->info->memmap[ASPEED_XDMA]);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0,
                        aspeed_soc_get_irq(s, ASPEED_XDMA));
+
+    /* GPIO */
+    object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->info->memmap[ASPEED_GPIO]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0,
+                       aspeed_soc_get_irq(s, ASPEED_GPIO));
 }
 static Property aspeed_soc_properties[] = {
     DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0),
include/hw/arm/aspeed_soc.h +3 -0
index cef605ad6b..fa04abddd8 100644
@@ -22,6 +22,7 @@
 #include "hw/ssi/aspeed_smc.h"
 #include "hw/watchdog/wdt_aspeed.h"
 #include "hw/net/ftgmac100.h"
+#include "hw/gpio/aspeed_gpio.h"
 
 #define ASPEED_SPIS_NUM  2
 #define ASPEED_WDTS_NUM  3
@@ -47,6 +48,7 @@ typedef struct AspeedSoCState {
     AspeedSDMCState sdmc;
     AspeedWDTState wdt[ASPEED_WDTS_NUM];
     FTGMAC100State ftgmac100[ASPEED_MACS_NUM];
+    AspeedGPIOState gpio;
 } AspeedSoCState;
 
 #define TYPE_ASPEED_SOC "aspeed-soc"
@@ -60,6 +62,7 @@ typedef struct AspeedSoCInfo {
     int spis_num;
     const char *fmc_typename;
     const char **spi_typename;
+    const char *gpio_typename;
     int wdts_num;
     const int *irqmap;
     const hwaddr *memmap;
Signature · 1 line
2.20.1
#5 lore raw

PATCH v3 3/3 hw/gpio: Add in AST2600 specific implementation

In reply to Rashmica Gupta

The AST2600 has the same sets of 3.6v gpios as the AST2400 plus an addtional two sets of 1.8V gpios.

---
 hw/gpio/aspeed_gpio.c         | 186 +++++++++++++++++++++++++++++++++-
 include/hw/gpio/aspeed_gpio.h |   2 +-
 2 files changed, 184 insertions(+), 4 deletions(-)
hw/gpio/aspeed_gpio.c +183 -3
index 4f1546a900..a94b5f2780 100644
@@ -16,6 +16,7 @@
 #define GPIOS_PER_REG 32
 #define GPIOS_PER_SET GPIOS_PER_REG
 #define GPIO_3_6V_REG_ARRAY_SIZE  (0x1f0 >> 2)
+#define GPIO_1_8V_REG_ARRAY_SIZE  ((0x9d8 - 0x800) >> 2)
 #define GPIO_PIN_GAP_SIZE 4
 #define GPIOS_PER_GROUP 8
 #define GPIO_GROUP_SHIFT 3
@@ -145,6 +146,7 @@
 #define GPIO_YZAAAB_DEBOUNCE_1     (0x190 >> 2)
 #define GPIO_YZAAAB_DEBOUNCE_2     (0x194 >> 2)
 #define GPIO_YZAAAB_INPUT_MASK     (0x198 >> 2)
+/* AST2500 only */
 #define GPIO_AC_COMMAND_SRC_0      (0x1A0 >> 2)
 #define GPIO_AC_COMMAND_SRC_1      (0x1A4 >> 2)
 #define GPIO_AC_INT_ENABLE         (0x1A8 >> 2)
@@ -163,6 +165,47 @@
 #define GPIO_AC_DATA_VALUE         (0x1E8 >> 2)
 #define GPIO_AC_DIRECTION          (0x1EC >> 2)
 
+
+/* AST2600 only - 1.8V gpios */
+/*
+ * The AST2600 has same 3.6V gpios as the AST2400 (memory offsets 0x0-0x198)
+ * and addtional 1.8V gpios (memory offsets 0x800-0x9D4). We create one
+ * GPIOState for the 3.6V gpios mapped at 0x0 and another GPIOState for the
+ * 1.8V gpios mapped at 0x800.
+ */
+#define GPIO_1_8_REG_OFFSET          0x800
+#define GPIO_1_8_ABCD_DATA_VALUE     ((0x800 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DIRECTION      ((0x804 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_ENABLE     ((0x808 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_0     ((0x80C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_1     ((0x810 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_2     ((0x814 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_STATUS     ((0x818 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_RESET_TOLERANT ((0x81C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_VALUE        ((0x820 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DIRECTION         ((0x824 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_ENABLE        ((0x828 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_0        ((0x82C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_1        ((0x830 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_2        ((0x834 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_STATUS        ((0x838 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_RESET_TOLERANT    ((0x83C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_1     ((0x840 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_2     ((0x844 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_1        ((0x848 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_2        ((0x84C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_1     ((0x850 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_2     ((0x854 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_3     ((0x858 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_0  ((0x860 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_1  ((0x864 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_0     ((0x868 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_1     ((0x86C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DATA_READ      ((0x8C0 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_READ         ((0x8C4 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INPUT_MASK     ((0x9D0 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INPUT_MASK        ((0x9D4 - GPIO_1_8_REG_OFFSET) >> 2)
+
 static int aspeed_evaluate_irq(GPIOSets *regs, int gpio_prev_high, int gpio)
 {
     uint32_t falling_edge = 0, rising_edge = 0;
@@ -626,6 +669,39 @@ static const AspeedGPIOReg aspeed_3_6v_gpios[GPIO_3_6V_REG_ARRAY_SIZE] = {
     [GPIO_AC_INPUT_MASK] =         {7, read_input_mask, write_input_mask},
 };
 
+static const AspeedGPIOReg aspeed_1_8v_gpios[GPIO_1_8V_REG_ARRAY_SIZE] = {
+    /* 1.8V Set ABCD */
+    [GPIO_1_8_ABCD_DATA_VALUE] =     {0, read_data_value, write_data_value},
+    [GPIO_1_8_ABCD_DIRECTION] =      {0, read_direction, write_direction},
+    [GPIO_1_8_ABCD_INT_ENABLE] =     {0, read_int_enable, write_int_enable},
+    [GPIO_1_8_ABCD_INT_SENS_0] =     {0, read_int_sens_0, write_int_sens_0},
+    [GPIO_1_8_ABCD_INT_SENS_1] =     {0, read_int_sens_1, write_int_sens_1},
+    [GPIO_1_8_ABCD_INT_SENS_2] =     {0, read_int_sens_2, write_int_sens_2},
+    [GPIO_1_8_ABCD_INT_STATUS] =     {0, read_int_status, write_int_status},
+    [GPIO_1_8_ABCD_RESET_TOLERANT] = {0, read_reset_tol, write_reset_tol},
+    [GPIO_1_8_ABCD_DEBOUNCE_1] =     {0, read_debounce_1, write_debounce_1},
+    [GPIO_1_8_ABCD_DEBOUNCE_2] =     {0, read_debounce_2, write_debounce_2},
+    [GPIO_1_8_ABCD_COMMAND_SRC_0] =  {0, read_cmd_source_0, write_cmd_source_0},
+    [GPIO_1_8_ABCD_COMMAND_SRC_1] =  {0, read_cmd_source_1, write_cmd_source_1},
+    [GPIO_1_8_ABCD_DATA_READ] =      {0, read_data, NULL},
+    [GPIO_1_8_ABCD_INPUT_MASK] =     {0, read_input_mask, write_input_mask},
+    /* 1.8V Set E */
+    [GPIO_1_8_E_DATA_VALUE] =     {1, read_data_value, write_data_value},
+    [GPIO_1_8_E_DIRECTION] =      {1, read_direction, write_direction },
+    [GPIO_1_8_E_INT_ENABLE] =     {1, read_int_enable, write_int_enable},
+    [GPIO_1_8_E_INT_SENS_0] =     {1, read_int_sens_0, write_int_sens_0},
+    [GPIO_1_8_E_INT_SENS_1] =     {1, read_int_sens_1, write_int_sens_1},
+    [GPIO_1_8_E_INT_SENS_2] =     {1, read_int_sens_2, write_int_sens_2},
+    [GPIO_1_8_E_INT_STATUS] =     {1, read_int_status, write_int_status},
+    [GPIO_1_8_E_RESET_TOLERANT] = {1, read_reset_tol,   write_reset_tol},
+    [GPIO_1_8_E_DEBOUNCE_1] =     {1, read_debounce_1,  write_debounce_1},
+    [GPIO_1_8_E_DEBOUNCE_2] =     {1, read_debounce_2,  write_debounce_2},
+    [GPIO_1_8_E_COMMAND_SRC_0] =  {1, read_cmd_source_0,  write_cmd_source_0},
+    [GPIO_1_8_E_COMMAND_SRC_1] =  {1, read_cmd_source_1,  write_cmd_source_1},
+    [GPIO_1_8_E_DATA_READ] =      {1, read_data, NULL},
+    [GPIO_1_8_E_INPUT_MASK] =     {1, read_input_mask,  write_input_mask},
+};
+
 static uint64_t aspeed_gpio_read(void *opaque, hwaddr offset, uint32_t size)
 {
     AspeedGPIOState *s = ASPEED_GPIO(opaque);
@@ -708,9 +784,12 @@ static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name,
     int set_idx, group_idx = 0;
 
     if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
                       __func__, name);
         return;
+        }
     }
     set_idx = get_set_idx(s, group, &group_idx);
     if (set_idx == -1) {
@@ -733,9 +812,12 @@ static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,
 
     visit_type_bool(v, name, &level, &local_err);
     if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
                       __func__, name);
         return;
+        }
     }
     set_idx = get_set_idx(s, group, &group_idx);
     if (set_idx == -1) {
@@ -769,6 +851,21 @@ static const GPIOSetProperties ast2500_set_props[] = {
     [7] = {0x000000ff,  0x000000ff,  {"AC"} },
 };
 
+static GPIOSetProperties ast2600_3_6v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
+    [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },
+    [2] = {0xffffffff,  0xffffffff,  {"I", "J", "K", "L"} },
+    [3] = {0xffffffff,  0xffffffff,  {"M", "N", "O", "P"} },
+    [4] = {0xffffffff,  0xffffffff,  {"Q", "R", "S", "T"} },
+    [5] = {0xffffffff,  0x0000ffff,  {"U", "V", "W", "X"} },
+    [6] = {0xffff0000,  0x0fff0000,  {"Y", "Z", "", ""} },
+};
+
+static GPIOSetProperties ast2600_1_8v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"18A", "18B", "18C", "18D"} },
+    [1] = {0x0000000f,  0x0000000f,  {"18E"} },
+};
+
 static const AspeedGPIOController aspeed_gpio_ast2400_controller = {
     .props          = ast2400_set_props,
     .nr_gpio_pins   = 216,
@@ -784,6 +881,21 @@ static const AspeedGPIOController aspeed_gpio_ast2500_controller = {
     .gap            = 220,
     .mem_size       = 0x1f0,
 };
+
+static const AspeedGPIOController aspeed_gpio_ast2600_3_6v_controller = {
+    .props          = ast2600_3_6v_set_props,
+    .nr_gpio_pins   = 208,
+    .nr_gpio_sets   = 7,
+    .mem_size       = 0x1000,
+};
+
+static const AspeedGPIOController aspeed_gpio_ast2600_1_8v_controller = {
+    .props          = ast2600_1_8v_set_props,
+    .nr_gpio_pins   = 36,
+    .nr_gpio_sets   = 2,
+    .mem_size       = 0x1d8,
+};
+
 static const MemoryRegionOps aspeed_gpio_ops = {
     .read = aspeed_gpio_read,
     .write = aspeed_gpio_write,
@@ -815,7 +927,6 @@ static void aspeed_gpio_realize(DeviceState *dev, Error **errp)
             TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
     s->lookup = aspeed_3_6v_gpios;
 
-
     sysbus_init_mmio(sbd, &s->iomem);
 }
 
@@ -841,6 +952,58 @@ static void aspeed_gpio_init(Object *obj)
     }
 }
 
+static void aspeed_2600_gpio_realize(DeviceState *dev, Error **errp)
+{
+    AspeedGPIOState *s = ASPEED_GPIO(dev);
+    AspeedGPIOState *s_1_8, *s_3_6;
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    int pin;
+    void *obj;
+
+    /* Create and setup the 1.8V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_1_8 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-ast2600-1.8v",
+                              obj, &error_abort);
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s_1_8);
+    agc->ctrl = (void *)&aspeed_gpio_ast2600_1_8v_controller;
+    aspeed_gpio_init(obj);
+
+    /* Create and setup the 3.6V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_3_6 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-ast2600-3.6v",
+                              obj, &error_abort);
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc2 = ASPEED_GPIO_GET_CLASS(s_3_6);
+    agc2->ctrl = (void *)&aspeed_gpio_ast2600_3_6v_controller;
+    aspeed_gpio_init(obj);
+
+
+    for (pin = 0; pin < agc->ctrl->nr_gpio_pins; pin++) {
+        sysbus_init_irq(sbd, &s->irq[pin]);
+    }
+
+    memory_region_init_io(&s_3_6->iomem, OBJECT(s_3_6), &aspeed_gpio_ops, s_3_6,
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    s_3_6->lookup = aspeed_3_6v_gpios;
+
+
+    memory_region_init_io(&s_1_8->iomem, OBJECT(s_1_8), &aspeed_gpio_ops, s_1_8,
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    memory_region_add_subregion(&s_3_6->iomem, GPIO_1_8_REG_OFFSET,
+                                &s_1_8->iomem);
+    s_1_8->lookup = aspeed_1_8v_gpios;
+
+    sysbus_init_mmio(sbd, &s_3_6->iomem);
+    sysbus_init_mmio(sbd, &s_1_8->iomem);
+}
+
 static const VMStateDescription vmstate_gpio_regs = {
     .name = TYPE_ASPEED_GPIO"/regs",
     .version_id = 1,
@@ -877,6 +1040,16 @@ static const VMStateDescription vmstate_aspeed_gpio = {
    }
 };
 
+static void aspeed_gpio_ast2600_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = aspeed_2600_gpio_realize;
+    dc->reset = aspeed_gpio_reset;
+    dc->desc = "Aspeed GPIO Controller";
+    dc->vmsd = &vmstate_aspeed_gpio;
+}
+
 static void aspeed_gpio_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -913,11 +1086,18 @@ static const TypeInfo aspeed_gpio_ast2500_info = {
     .class_data = (void *)&aspeed_gpio_ast2500_controller,
 };
 
+static const TypeInfo aspeed_gpio_ast2600_info = {
+    .name =  TYPE_ASPEED_GPIO "-ast2600",
+    .parent = TYPE_ASPEED_GPIO,
+    .class_init = aspeed_gpio_ast2600_class_init,
+};
+
 static void aspeed_gpio_register_types(void)
 {
     type_register_static(&aspeed_gpio_info);
     type_register_static(&aspeed_gpio_ast2400_info);
     type_register_static(&aspeed_gpio_ast2500_info);
+    type_register_static(&aspeed_gpio_ast2600_info);
 }
 
 type_init(aspeed_gpio_register_types);
include/hw/gpio/aspeed_gpio.h +1 -1
index bef1d37c78..cf751c6af2 100644
@@ -25,7 +25,7 @@
 #define ASPEED_GPIO_NR_PINS 228
 #define ASPEED_GROUPS_PER_SET 4
 #define ASPEED_GPIO_NR_DEBOUNCE_REGS 3
-#define ASPEED_CHARS_PER_GROUP_LABEL 3
+#define ASPEED_CHARS_PER_GROUP_LABEL 4
 
 typedef struct GPIOSets GPIOSets;
 typedef struct AspeedGPIOState AspeedGPIOState;
Signature · 1 line
2.20.1
#6 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v3 3/3] hw/gpio: Add in AST2600 specific implementation

Quoted 14 lines · Rashmica Gupta

The AST2600 has the same sets of 3.6v gpios as the AST2400 plus an addtional two sets of 1.8V gpios.

---
  hw/gpio/aspeed_gpio.c         | 186 +++++++++++++++++++++++++++++++++-
  include/hw/gpio/aspeed_gpio.h |   2 +-
  2 files changed, 184 insertions(+), 4 deletions(-)
hw/gpio/aspeed_gpio.c +0 -0
index 4f1546a900..a94b5f2780 100644

hw/gpio/aspeed_gpio.c line 19

Quoted 4 lines
hw/gpio/aspeed_gpio.c +1 -0
@@ -16,6 +16,7 @@
  #define GPIOS_PER_REG 32
  #define GPIOS_PER_SET GPIOS_PER_REG
  #define GPIO_3_6V_REG_ARRAY_SIZE  (0x1f0 >> 2)
+#define GPIO_1_8V_REG_ARRAY_SIZE  ((0x9d8 - 0x800) >> 2)

Is this 0x800 a GPIO_1_8_REG_OFFSET from below? And 0x9d8 - GPIO_1_8_E_INPUT_MASK + sizeof(u32)? Use them here?

Actually the symbol does not seem to be very useful anyway, I'd just do "aspeed_1_8v_gpios[]" but it seem to be a pattern here so never mind...

Quoted 100 lines
hw/gpio/aspeed_gpio.c +75 -0
  #define GPIO_PIN_GAP_SIZE 4
  #define GPIOS_PER_GROUP 8
  #define GPIO_GROUP_SHIFT 3
@@ -145,6 +146,7 @@
  #define GPIO_YZAAAB_DEBOUNCE_1     (0x190 >> 2)
  #define GPIO_YZAAAB_DEBOUNCE_2     (0x194 >> 2)
  #define GPIO_YZAAAB_INPUT_MASK     (0x198 >> 2)
+/* AST2500 only */
  #define GPIO_AC_COMMAND_SRC_0      (0x1A0 >> 2)
  #define GPIO_AC_COMMAND_SRC_1      (0x1A4 >> 2)
  #define GPIO_AC_INT_ENABLE         (0x1A8 >> 2)
@@ -163,6 +165,47 @@
  #define GPIO_AC_DATA_VALUE         (0x1E8 >> 2)
  #define GPIO_AC_DIRECTION          (0x1EC >> 2)
 
+
+/* AST2600 only - 1.8V gpios */
+/*
+ * The AST2600 has same 3.6V gpios as the AST2400 (memory offsets 0x0-0x198)
+ * and addtional 1.8V gpios (memory offsets 0x800-0x9D4). We create one
+ * GPIOState for the 3.6V gpios mapped at 0x0 and another GPIOState for the
+ * 1.8V gpios mapped at 0x800.
+ */
+#define GPIO_1_8_REG_OFFSET          0x800
+#define GPIO_1_8_ABCD_DATA_VALUE     ((0x800 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DIRECTION      ((0x804 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_ENABLE     ((0x808 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_0     ((0x80C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_1     ((0x810 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_2     ((0x814 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_STATUS     ((0x818 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_RESET_TOLERANT ((0x81C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_VALUE        ((0x820 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DIRECTION         ((0x824 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_ENABLE        ((0x828 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_0        ((0x82C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_1        ((0x830 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_2        ((0x834 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_STATUS        ((0x838 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_RESET_TOLERANT    ((0x83C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_1     ((0x840 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_2     ((0x844 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_1        ((0x848 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_2        ((0x84C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_1     ((0x850 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_2     ((0x854 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_3     ((0x858 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_0  ((0x860 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_1  ((0x864 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_0     ((0x868 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_1     ((0x86C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DATA_READ      ((0x8C0 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_READ         ((0x8C4 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INPUT_MASK     ((0x9D0 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INPUT_MASK        ((0x9D4 - GPIO_1_8_REG_OFFSET) >> 2)
+
  static int aspeed_evaluate_irq(GPIOSets *regs, int gpio_prev_high, int gpio)
  {
      uint32_t falling_edge = 0, rising_edge = 0;
@@ -626,6 +669,39 @@ static const AspeedGPIOReg aspeed_3_6v_gpios[GPIO_3_6V_REG_ARRAY_SIZE] = {
      [GPIO_AC_INPUT_MASK] =         {7, read_input_mask, write_input_mask},
  };
 
+static const AspeedGPIOReg aspeed_1_8v_gpios[GPIO_1_8V_REG_ARRAY_SIZE] = {
+    /* 1.8V Set ABCD */
+    [GPIO_1_8_ABCD_DATA_VALUE] =     {0, read_data_value, write_data_value},
+    [GPIO_1_8_ABCD_DIRECTION] =      {0, read_direction, write_direction},
+    [GPIO_1_8_ABCD_INT_ENABLE] =     {0, read_int_enable, write_int_enable},
+    [GPIO_1_8_ABCD_INT_SENS_0] =     {0, read_int_sens_0, write_int_sens_0},
+    [GPIO_1_8_ABCD_INT_SENS_1] =     {0, read_int_sens_1, write_int_sens_1},
+    [GPIO_1_8_ABCD_INT_SENS_2] =     {0, read_int_sens_2, write_int_sens_2},
+    [GPIO_1_8_ABCD_INT_STATUS] =     {0, read_int_status, write_int_status},
+    [GPIO_1_8_ABCD_RESET_TOLERANT] = {0, read_reset_tol, write_reset_tol},
+    [GPIO_1_8_ABCD_DEBOUNCE_1] =     {0, read_debounce_1, write_debounce_1},
+    [GPIO_1_8_ABCD_DEBOUNCE_2] =     {0, read_debounce_2, write_debounce_2},
+    [GPIO_1_8_ABCD_COMMAND_SRC_0] =  {0, read_cmd_source_0, write_cmd_source_0},
+    [GPIO_1_8_ABCD_COMMAND_SRC_1] =  {0, read_cmd_source_1, write_cmd_source_1},
+    [GPIO_1_8_ABCD_DATA_READ] =      {0, read_data, NULL},
+    [GPIO_1_8_ABCD_INPUT_MASK] =     {0, read_input_mask, write_input_mask},
+    /* 1.8V Set E */
+    [GPIO_1_8_E_DATA_VALUE] =     {1, read_data_value, write_data_value},
+    [GPIO_1_8_E_DIRECTION] =      {1, read_direction, write_direction },
+    [GPIO_1_8_E_INT_ENABLE] =     {1, read_int_enable, write_int_enable},
+    [GPIO_1_8_E_INT_SENS_0] =     {1, read_int_sens_0, write_int_sens_0},
+    [GPIO_1_8_E_INT_SENS_1] =     {1, read_int_sens_1, write_int_sens_1},
+    [GPIO_1_8_E_INT_SENS_2] =     {1, read_int_sens_2, write_int_sens_2},
+    [GPIO_1_8_E_INT_STATUS] =     {1, read_int_status, write_int_status},
+    [GPIO_1_8_E_RESET_TOLERANT] = {1, read_reset_tol,   write_reset_tol},
+    [GPIO_1_8_E_DEBOUNCE_1] =     {1, read_debounce_1,  write_debounce_1},
+    [GPIO_1_8_E_DEBOUNCE_2] =     {1, read_debounce_2,  write_debounce_2},
+    [GPIO_1_8_E_COMMAND_SRC_0] =  {1, read_cmd_source_0,  write_cmd_source_0},
+    [GPIO_1_8_E_COMMAND_SRC_1] =  {1, read_cmd_source_1,  write_cmd_source_1},
+    [GPIO_1_8_E_DATA_READ] =      {1, read_data, NULL},
+    [GPIO_1_8_E_INPUT_MASK] =     {1, read_input_mask,  write_input_mask},
+};
+
  static uint64_t aspeed_gpio_read(void *opaque, hwaddr offset, uint32_t size)
  {
      AspeedGPIOState *s = ASPEED_GPIO(opaque);

hw/gpio/aspeed_gpio.c static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name, · line 791

Quoted 9 lines
hw/gpio/aspeed_gpio.c +3 -1
@@ -708,9 +784,12 @@ static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name,
      int set_idx, group_idx = 0;
 
      if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
                        __func__, name);
          return;

The 2 lines above need an indent.

Quoted 5 lines
hw/gpio/aspeed_gpio.c +1 -0
+        }
      }
      set_idx = get_set_idx(s, group, &group_idx);
      if (set_idx == -1) {

hw/gpio/aspeed_gpio.c static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name, · line 819

Quoted 9 lines
hw/gpio/aspeed_gpio.c +3 -1
@@ -733,9 +812,12 @@ static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,
 
      visit_type_bool(v, name, &level, &local_err);
      if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
                        __func__, name);
          return;

Same here.

Quoted 27 lines
hw/gpio/aspeed_gpio.c +16 -0
+        }
      }
      set_idx = get_set_idx(s, group, &group_idx);
      if (set_idx == -1) {
@@ -769,6 +851,21 @@ static const GPIOSetProperties ast2500_set_props[] = {
      [7] = {0x000000ff,  0x000000ff,  {"AC"} },
  };
 
+static GPIOSetProperties ast2600_3_6v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
+    [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },
+    [2] = {0xffffffff,  0xffffffff,  {"I", "J", "K", "L"} },
+    [3] = {0xffffffff,  0xffffffff,  {"M", "N", "O", "P"} },
+    [4] = {0xffffffff,  0xffffffff,  {"Q", "R", "S", "T"} },
+    [5] = {0xffffffff,  0x0000ffff,  {"U", "V", "W", "X"} },
+    [6] = {0xffff0000,  0x0fff0000,  {"Y", "Z", "", ""} },
+};
+
+static GPIOSetProperties ast2600_1_8v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"18A", "18B", "18C", "18D"} },
+    [1] = {0x0000000f,  0x0000000f,  {"18E"} },
+};
+
  static const AspeedGPIOController aspeed_gpio_ast2400_controller = {
      .props          = ast2400_set_props,
      .nr_gpio_pins   = 216,

hw/gpio/aspeed_gpio.c static const AspeedGPIOController aspeed_gpio_ast2500_controller = { · line 889

Quoted 9 lines
hw/gpio/aspeed_gpio.c +6 -0
@@ -784,6 +881,21 @@ static const AspeedGPIOController aspeed_gpio_ast2500_controller = {
      .gap            = 220,
      .mem_size       = 0x1f0,
  };
+
+static const AspeedGPIOController aspeed_gpio_ast2600_3_6v_controller = {
+    .props          = ast2600_3_6v_set_props,
+    .nr_gpio_pins   = 208,
+    .nr_gpio_sets   = 7,
+    .mem_size       = 0x1000,

magic value?

hw/gpio/aspeed_gpio.c static const AspeedGPIOController aspeed_gpio_ast2500_controller = { · line 896

Quoted 7 lines
hw/gpio/aspeed_gpio.c +7 -0
+};
+
+static const AspeedGPIOController aspeed_gpio_ast2600_1_8v_controller = {
+    .props          = ast2600_1_8v_set_props,
+    .nr_gpio_pins   = 36,
+    .nr_gpio_sets   = 2,
+    .mem_size       = 0x1d8,

s/0x1d8/GPIO_1_8V_REG_ARRAY_SIZE/ ?

hw/gpio/aspeed_gpio.c static void aspeed_gpio_realize(DeviceState *dev, Error **errp) · line 818

Quoted 10 lines
hw/gpio/aspeed_gpio.c +2 -1
+};
+
  static const MemoryRegionOps aspeed_gpio_ops = {
      .read = aspeed_gpio_read,
      .write = aspeed_gpio_write,
@@ -815,7 +927,6 @@ static void aspeed_gpio_realize(DeviceState *dev, Error **errp)
              TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
      s->lookup = aspeed_3_6v_gpios;
 
-

nit: unrelated line removal.

Quoted 10 lines
hw/gpio/aspeed_gpio.c +3 -0
      sysbus_init_mmio(sbd, &s->iomem);
  }
 
@@ -841,6 +952,58 @@ static void aspeed_gpio_init(Object *obj)
      }
  }
 
+static void aspeed_2600_gpio_realize(DeviceState *dev, Error **errp)
+{
+    AspeedGPIOState *s = ASPEED_GPIO(dev);

hw/gpio/aspeed_gpio.c static void aspeed_gpio_init(Object *obj) · line 967

Quoted 10 lines
hw/gpio/aspeed_gpio.c +10 -0
+    AspeedGPIOState *s_1_8, *s_3_6;
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    int pin;
+    void *obj;
+
+    /* Create and setup the 1.8V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_1_8 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-ast2600-1.8v",
+                              obj, &error_abort);

Passing the global @error_abort makes QEMU abort() right away, you probably want to pass @errp here.

hw/gpio/aspeed_gpio.c static void aspeed_gpio_init(Object *obj) · line 971

Quoted 4 lines
hw/gpio/aspeed_gpio.c +4 -0
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s_1_8);

Declarations go before the code, or (some versions of) gcc will warn you.

Quoted 79 lines
hw/gpio/aspeed_gpio.c +52 -0
+    agc->ctrl = (void *)&aspeed_gpio_ast2600_1_8v_controller;
+    aspeed_gpio_init(obj);
+
+    /* Create and setup the 3.6V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_3_6 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-ast2600-3.6v",
+                              obj, &error_abort);
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc2 = ASPEED_GPIO_GET_CLASS(s_3_6);
+    agc2->ctrl = (void *)&aspeed_gpio_ast2600_3_6v_controller;
+    aspeed_gpio_init(obj);
+
+
+    for (pin = 0; pin < agc->ctrl->nr_gpio_pins; pin++) {
+        sysbus_init_irq(sbd, &s->irq[pin]);
+    }
+
+    memory_region_init_io(&s_3_6->iomem, OBJECT(s_3_6), &aspeed_gpio_ops, s_3_6,
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    s_3_6->lookup = aspeed_3_6v_gpios;
+
+
+    memory_region_init_io(&s_1_8->iomem, OBJECT(s_1_8), &aspeed_gpio_ops, s_1_8,
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    memory_region_add_subregion(&s_3_6->iomem, GPIO_1_8_REG_OFFSET,
+                                &s_1_8->iomem);
+    s_1_8->lookup = aspeed_1_8v_gpios;
+
+    sysbus_init_mmio(sbd, &s_3_6->iomem);
+    sysbus_init_mmio(sbd, &s_1_8->iomem);
+}
+
  static const VMStateDescription vmstate_gpio_regs = {
      .name = TYPE_ASPEED_GPIO"/regs",
      .version_id = 1,
@@ -877,6 +1040,16 @@ static const VMStateDescription vmstate_aspeed_gpio = {
     }
  };
 
+static void aspeed_gpio_ast2600_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = aspeed_2600_gpio_realize;
+    dc->reset = aspeed_gpio_reset;
+    dc->desc = "Aspeed GPIO Controller";
+    dc->vmsd = &vmstate_aspeed_gpio;
+}
+
  static void aspeed_gpio_class_init(ObjectClass *klass, void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(klass);
@@ -913,11 +1086,18 @@ static const TypeInfo aspeed_gpio_ast2500_info = {
      .class_data = (void *)&aspeed_gpio_ast2500_controller,
  };
 
+static const TypeInfo aspeed_gpio_ast2600_info = {
+    .name =  TYPE_ASPEED_GPIO "-ast2600",
+    .parent = TYPE_ASPEED_GPIO,
+    .class_init = aspeed_gpio_ast2600_class_init,
+};
+
  static void aspeed_gpio_register_types(void)
  {
      type_register_static(&aspeed_gpio_info);
      type_register_static(&aspeed_gpio_ast2400_info);
      type_register_static(&aspeed_gpio_ast2500_info);
+    type_register_static(&aspeed_gpio_ast2600_info);
  }
 
  type_init(aspeed_gpio_register_types);
include/hw/gpio/aspeed_gpio.h +0 -0
index bef1d37c78..cf751c6af2 100644

include/hw/gpio/aspeed_gpio.h line 28

Quoted 5 lines
include/hw/gpio/aspeed_gpio.h +1 -1
@@ -25,7 +25,7 @@
  #define ASPEED_GPIO_NR_PINS 228
  #define ASPEED_GROUPS_PER_SET 4
  #define ASPEED_GPIO_NR_DEBOUNCE_REGS 3
-#define ASPEED_CHARS_PER_GROUP_LABEL 3
+#define ASPEED_CHARS_PER_GROUP_LABEL 4

This should go to 1/3.

Quoted 4 lines
include/hw/gpio/aspeed_gpio.h +0 -0
  typedef struct GPIOSets GPIOSets;
  typedef struct AspeedGPIOState AspeedGPIOState;
 
Signature · 1 line
Alexey
#7 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH v3 3/3] hw/gpio: Add in AST2600 specific implementation

Thanks for the feedback! I fixed up all the things you mentioned in v4.

Quoted 437 lines · Alexey Kardashevskiy
Quoted 15 lines · Rashmica Gupta

The AST2600 has the same sets of 3.6v gpios as the AST2400 plus an addtional two sets of 1.8V gpios.

---
  hw/gpio/aspeed_gpio.c         | 186
+++++++++++++++++++++++++++++++++-
  include/hw/gpio/aspeed_gpio.h |   2 +-
  2 files changed, 184 insertions(+), 4 deletions(-)
hw/gpio/aspeed_gpio.c +0 -0
index 4f1546a900..a94b5f2780 100644

hw/gpio/aspeed_gpio.c line 19

Quoted 4 lines
hw/gpio/aspeed_gpio.c +1 -0
@@ -16,6 +16,7 @@
  #define GPIOS_PER_REG 32
  #define GPIOS_PER_SET GPIOS_PER_REG
  #define GPIO_3_6V_REG_ARRAY_SIZE  (0x1f0 >> 2)
+#define GPIO_1_8V_REG_ARRAY_SIZE  ((0x9d8 - 0x800) >> 2)

Is this 0x800 a GPIO_1_8_REG_OFFSET from below? And 0x9d8 - GPIO_1_8_E_INPUT_MASK + sizeof(u32)? Use them here?

Actually the symbol does not seem to be very useful anyway, I'd just do
"aspeed_1_8v_gpios[]" but it seem to be a pattern here so never mind...

Quoted 166 lines
hw/gpio/aspeed_gpio.c +6 -0
  #define GPIO_PIN_GAP_SIZE 4
  #define GPIOS_PER_GROUP 8
  #define GPIO_GROUP_SHIFT 3
@@ -145,6 +146,7 @@
  #define GPIO_YZAAAB_DEBOUNCE_1     (0x190 >> 2)
  #define GPIO_YZAAAB_DEBOUNCE_2     (0x194 >> 2)
  #define GPIO_YZAAAB_INPUT_MASK     (0x198 >> 2)
+/* AST2500 only */
  #define GPIO_AC_COMMAND_SRC_0      (0x1A0 >> 2)
  #define GPIO_AC_COMMAND_SRC_1      (0x1A4 >> 2)
  #define GPIO_AC_INT_ENABLE         (0x1A8 >> 2)
@@ -163,6 +165,47 @@
  #define GPIO_AC_DATA_VALUE         (0x1E8 >> 2)
  #define GPIO_AC_DIRECTION          (0x1EC >> 2)
 
+
+/* AST2600 only - 1.8V gpios */
+/*
+ * The AST2600 has same 3.6V gpios as the AST2400 (memory offsets
 0x0-0x198)
+ * and addtional 1.8V gpios (memory offsets 0x800-0x9D4). We

create one
+ * GPIOState for the 3.6V gpios mapped at 0x0 and another GPIOState for the
+ * 1.8V gpios mapped at 0x800.
+ */

hw/gpio/aspeed_gpio.c +2 -0
+#define GPIO_1_8_REG_OFFSET          0x800
+#define GPIO_1_8_ABCD_DATA_VALUE     ((0x800 -

GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DIRECTION ((0x804 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_ENABLE ((0x808 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_0 ((0x80C -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_1 ((0x810 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_SENS_2 ((0x814 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INT_STATUS ((0x818 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_RESET_TOLERANT ((0x81C - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_VALUE ((0x820 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DIRECTION ((0x824 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_ENABLE ((0x828 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_0 ((0x82C -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_1 ((0x830 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_SENS_2 ((0x834 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INT_STATUS ((0x838 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_RESET_TOLERANT ((0x83C -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_1 ((0x840 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DEBOUNCE_2 ((0x844 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_1 ((0x848 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DEBOUNCE_2 ((0x84C -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_1 ((0x850 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_2 ((0x854 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_DEBOUNCE_TIME_3 ((0x858 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_0 ((0x860 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_COMMAND_SRC_1 ((0x864 - GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_0 ((0x868 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_COMMAND_SRC_1 ((0x86C -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_DATA_READ ((0x8C0 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_DATA_READ ((0x8C4 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_ABCD_INPUT_MASK ((0x9D0 -
GPIO_1_8_REG_OFFSET) >> 2)
+#define GPIO_1_8_E_INPUT_MASK ((0x9D4 -
GPIO_1_8_REG_OFFSET) >> 2)
+
static int aspeed_evaluate_irq(GPIOSets *regs, int
gpio_prev_high, int gpio)

  {
      uint32_t falling_edge = 0, rising_edge = 0;
hw/gpio/aspeed_gpio.c +3 -0
@@ -626,6 +669,39 @@ static const AspeedGPIOReg
 aspeed_3_6v_gpios[GPIO_3_6V_REG_ARRAY_SIZE] = {
      [GPIO_AC_INPUT_MASK] =         {7, read_input_mask,
 write_input_mask},
  };
 
+static const AspeedGPIOReg
 aspeed_1_8v_gpios[GPIO_1_8V_REG_ARRAY_SIZE] = {
+    /* 1.8V Set ABCD */
+    [GPIO_1_8_ABCD_DATA_VALUE] =     {0, read_data_value,

write_data_value},
+ [GPIO_1_8_ABCD_DIRECTION] = {0, read_direction,
write_direction},
+ [GPIO_1_8_ABCD_INT_ENABLE] = {0, read_int_enable,
write_int_enable},
+ [GPIO_1_8_ABCD_INT_SENS_0] = {0, read_int_sens_0,
write_int_sens_0},
+ [GPIO_1_8_ABCD_INT_SENS_1] = {0, read_int_sens_1,
write_int_sens_1},
+ [GPIO_1_8_ABCD_INT_SENS_2] = {0, read_int_sens_2,
write_int_sens_2},
+ [GPIO_1_8_ABCD_INT_STATUS] = {0, read_int_status,
write_int_status},
+ [GPIO_1_8_ABCD_RESET_TOLERANT] = {0, read_reset_tol,
write_reset_tol},
+ [GPIO_1_8_ABCD_DEBOUNCE_1] = {0, read_debounce_1,
write_debounce_1},
+ [GPIO_1_8_ABCD_DEBOUNCE_2] = {0, read_debounce_2,
write_debounce_2},
+ [GPIO_1_8_ABCD_COMMAND_SRC_0] = {0, read_cmd_source_0,
write_cmd_source_0},
+ [GPIO_1_8_ABCD_COMMAND_SRC_1] = {0, read_cmd_source_1,
write_cmd_source_1},

hw/gpio/aspeed_gpio.c +2 -0
+    [GPIO_1_8_ABCD_DATA_READ] =      {0, read_data, NULL},
+    [GPIO_1_8_ABCD_INPUT_MASK] =     {0, read_input_mask,

write_input_mask},

hw/gpio/aspeed_gpio.c +2 -0
+    /* 1.8V Set E */
+    [GPIO_1_8_E_DATA_VALUE] =     {1, read_data_value,

write_data_value},
+ [GPIO_1_8_E_DIRECTION] = {1, read_direction,
write_direction },
+ [GPIO_1_8_E_INT_ENABLE] = {1, read_int_enable,
write_int_enable},
+ [GPIO_1_8_E_INT_SENS_0] = {1, read_int_sens_0,
write_int_sens_0},
+ [GPIO_1_8_E_INT_SENS_1] = {1, read_int_sens_1,
write_int_sens_1},
+ [GPIO_1_8_E_INT_SENS_2] = {1, read_int_sens_2,
write_int_sens_2},
+ [GPIO_1_8_E_INT_STATUS] = {1, read_int_status,
write_int_status},
+ [GPIO_1_8_E_RESET_TOLERANT] = {1,
read_reset_tol, write_reset_tol},
+ [GPIO_1_8_E_DEBOUNCE_1] = {1,
read_debounce_1, write_debounce_1},
+ [GPIO_1_8_E_DEBOUNCE_2] = {1,
read_debounce_2, write_debounce_2},
+ [GPIO_1_8_E_COMMAND_SRC_0] = {1,
read_cmd_source_0, write_cmd_source_0},
+ [GPIO_1_8_E_COMMAND_SRC_1] = {1,
read_cmd_source_1, write_cmd_source_1},

hw/gpio/aspeed_gpio.c +2 -0
+    [GPIO_1_8_E_DATA_READ] =      {1, read_data, NULL},
+    [GPIO_1_8_E_INPUT_MASK] =     {1,

read_input_mask, write_input_mask},

hw/gpio/aspeed_gpio.c +2 -0
+};
+
  static uint64_t aspeed_gpio_read(void *opaque, hwaddr offset,

uint32_t size)

  {
      AspeedGPIOState *s = ASPEED_GPIO(opaque);
hw/gpio/aspeed_gpio.c +0 -0
@@ -708,9 +784,12 @@ static void aspeed_gpio_get_pin(Object *obj,
 Visitor *v, const char *name,

hw/gpio/aspeed_gpio.c static void aspeed_gpio_get_pin(Object *obj, · line 793

Quoted 10 lines
hw/gpio/aspeed_gpio.c +3 -1
      int set_idx, group_idx = 0;
 
      if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading
 %s\n",
                        __func__, name);
          return;

The 2 lines above need an indent.

Quoted 6 lines
hw/gpio/aspeed_gpio.c +1 -0
+        }
      }
      set_idx = get_set_idx(s, group, &group_idx);
      if (set_idx == -1) {
hw/gpio/aspeed_gpio.c +0 -0
@@ -733,9 +812,12 @@ static void aspeed_gpio_set_pin(Object *obj,
 Visitor *v, const char *name,

hw/gpio/aspeed_gpio.c static void aspeed_gpio_set_pin(Object *obj, · line 821

Quoted 10 lines
hw/gpio/aspeed_gpio.c +3 -1
 
      visit_type_bool(v, name, &level, &local_err);
      if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
-        qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading %s\n",
+        /* 1.8V gpio */
+        if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
+            qemu_log_mask(LOG_GUEST_ERROR, "%s: error reading
 %s\n",
                        __func__, name);
          return;

Same here.

Quoted 31 lines
hw/gpio/aspeed_gpio.c +1 -0
+        }
      }
      set_idx = get_set_idx(s, group, &group_idx);
      if (set_idx == -1) {
hw/gpio/aspeed_gpio.c +15 -0
@@ -769,6 +851,21 @@ static const GPIOSetProperties
 ast2500_set_props[] = {
      [7] = {0x000000ff,  0x000000ff,  {"AC"} },
  };
 
+static GPIOSetProperties ast2600_3_6v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
+    [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },
+    [2] = {0xffffffff,  0xffffffff,  {"I", "J", "K", "L"} },
+    [3] = {0xffffffff,  0xffffffff,  {"M", "N", "O", "P"} },
+    [4] = {0xffffffff,  0xffffffff,  {"Q", "R", "S", "T"} },
+    [5] = {0xffffffff,  0x0000ffff,  {"U", "V", "W", "X"} },
+    [6] = {0xffff0000,  0x0fff0000,  {"Y", "Z", "", ""} },
+};
+
+static GPIOSetProperties ast2600_1_8v_set_props[] = {
+    [0] = {0xffffffff,  0xffffffff,  {"18A", "18B", "18C", "18D"}
 },
+    [1] = {0x0000000f,  0x0000000f,  {"18E"} },
+};
+
  static const AspeedGPIOController aspeed_gpio_ast2400_controller

= {
.props = ast2400_set_props,
.nr_gpio_pins = 216,

hw/gpio/aspeed_gpio.c +0 -0
@@ -784,6 +881,21 @@ static const AspeedGPIOController
 aspeed_gpio_ast2500_controller = {

hw/gpio/aspeed_gpio.c static const AspeedGPIOController · line 891

Quoted 10 lines
hw/gpio/aspeed_gpio.c +6 -0
      .gap            = 220,
      .mem_size       = 0x1f0,
  };
+
+static const AspeedGPIOController
 aspeed_gpio_ast2600_3_6v_controller = {
+    .props          = ast2600_3_6v_set_props,
+    .nr_gpio_pins   = 208,
+    .nr_gpio_sets   = 7,
+    .mem_size       = 0x1000,

magic value?

hw/gpio/aspeed_gpio.c static const AspeedGPIOController aspeed_gpio_ast2500_controller = { · line 896

Quoted 8 lines
hw/gpio/aspeed_gpio.c +7 -0
+};
+
+static const AspeedGPIOController
 aspeed_gpio_ast2600_1_8v_controller = {
+    .props          = ast2600_1_8v_set_props,
+    .nr_gpio_pins   = 36,
+    .nr_gpio_sets   = 2,
+    .mem_size       = 0x1d8,

s/0x1d8/GPIO_1_8V_REG_ARRAY_SIZE/ ?

hw/gpio/aspeed_gpio.c static void aspeed_gpio_realize(DeviceState · line 819

Quoted 11 lines
hw/gpio/aspeed_gpio.c +2 -0
+};
+
  static const MemoryRegionOps aspeed_gpio_ops = {
      .read = aspeed_gpio_read,
      .write = aspeed_gpio_write,
hw/gpio/aspeed_gpio.c +0 -1
@@ -815,7 +927,6 @@ static void aspeed_gpio_realize(DeviceState
 *dev, Error **errp)
              TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
      s->lookup = aspeed_3_6v_gpios;
 
-

nit: unrelated line removal.

Quoted 12 lines
hw/gpio/aspeed_gpio.c +4 -0
      sysbus_init_mmio(sbd, &s->iomem);
  }
@@ -841,6 +952,58 @@ static void aspeed_gpio_init(Object *obj)
      }
  }
 
+static void aspeed_2600_gpio_realize(DeviceState *dev, Error
 **errp)
+{
+    AspeedGPIOState *s = ASPEED_GPIO(dev);
+    AspeedGPIOState *s_1_8, *s_3_6;

hw/gpio/aspeed_gpio.c static void aspeed_gpio_init(Object *obj) · line 969

Quoted 10 lines
hw/gpio/aspeed_gpio.c +9 -0
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    int pin;
+    void *obj;
+
+    /* Create and setup the 1.8V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_1_8 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-
 ast2600-1.8v",
+                              obj, &error_abort);

Passing the global @error_abort makes QEMU abort() right away, you probably want to pass @errp here.

hw/gpio/aspeed_gpio.c static void aspeed_gpio_init(Object *obj) · line 971

Quoted 4 lines
hw/gpio/aspeed_gpio.c +4 -0
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s_1_8);

Declarations go before the code, or (some versions of) gcc will warn you.

Quoted 88 lines
hw/gpio/aspeed_gpio.c +21 -0
+    agc->ctrl = (void *)&aspeed_gpio_ast2600_1_8v_controller;
+    aspeed_gpio_init(obj);
+
+    /* Create and setup the 3.6V gpio state/class */
+    obj = object_new(TYPE_ASPEED_GPIO "-ast2600");
+    s_3_6 = ASPEED_GPIO(obj);
+    object_property_add_child(OBJECT(dev), TYPE_ASPEED_GPIO "-
 ast2600-3.6v",
+                              obj, &error_abort);
+    if (error_abort) {
+        error_propagate(errp, error_abort);
+    }
+    AspeedGPIOClass *agc2 = ASPEED_GPIO_GET_CLASS(s_3_6);
+    agc2->ctrl = (void *)&aspeed_gpio_ast2600_3_6v_controller;
+    aspeed_gpio_init(obj);
+
+
+    for (pin = 0; pin < agc->ctrl->nr_gpio_pins; pin++) {
+        sysbus_init_irq(sbd, &s->irq[pin]);
+    }
+
+    memory_region_init_io(&s_3_6->iomem, OBJECT(s_3_6),

&aspeed_gpio_ops, s_3_6,

hw/gpio/aspeed_gpio.c +5 -0
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    s_3_6->lookup = aspeed_3_6v_gpios;
+
+
+    memory_region_init_io(&s_1_8->iomem, OBJECT(s_1_8),

&aspeed_gpio_ops, s_1_8,

hw/gpio/aspeed_gpio.c +2 -0
+            TYPE_ASPEED_GPIO, agc->ctrl->mem_size);
+    memory_region_add_subregion(&s_3_6->iomem,

GPIO_1_8_REG_OFFSET,

hw/gpio/aspeed_gpio.c +17 -0
+                                &s_1_8->iomem);
+    s_1_8->lookup = aspeed_1_8v_gpios;
+
+    sysbus_init_mmio(sbd, &s_3_6->iomem);
+    sysbus_init_mmio(sbd, &s_1_8->iomem);
+}
+
  static const VMStateDescription vmstate_gpio_regs = {
      .name = TYPE_ASPEED_GPIO"/regs",
      .version_id = 1,
@@ -877,6 +1040,16 @@ static const VMStateDescription
 vmstate_aspeed_gpio = {
     }
  };
 
+static void aspeed_gpio_ast2600_class_init(ObjectClass *klass,
 void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = aspeed_2600_gpio_realize;
+    dc->reset = aspeed_gpio_reset;
+    dc->desc = "Aspeed GPIO Controller";
+    dc->vmsd = &vmstate_aspeed_gpio;
+}
+
  static void aspeed_gpio_class_init(ObjectClass *klass, void

*data)

  {
      DeviceClass *dc = DEVICE_CLASS(klass);
hw/gpio/aspeed_gpio.c +7 -0
@@ -913,11 +1086,18 @@ static const TypeInfo
 aspeed_gpio_ast2500_info = {
      .class_data = (void *)&aspeed_gpio_ast2500_controller,
  };
 
+static const TypeInfo aspeed_gpio_ast2600_info = {
+    .name =  TYPE_ASPEED_GPIO "-ast2600",
+    .parent = TYPE_ASPEED_GPIO,
+    .class_init = aspeed_gpio_ast2600_class_init,
+};
+
  static void aspeed_gpio_register_types(void)
  {
      type_register_static(&aspeed_gpio_info);
      type_register_static(&aspeed_gpio_ast2400_info);
      type_register_static(&aspeed_gpio_ast2500_info);
+    type_register_static(&aspeed_gpio_ast2600_info);
  }
 
  type_init(aspeed_gpio_register_types);
include/hw/gpio/aspeed_gpio.h +0 -0
index bef1d37c78..cf751c6af2 100644

include/hw/gpio/aspeed_gpio.h line 28

Quoted 5 lines
include/hw/gpio/aspeed_gpio.h +1 -1
@@ -25,7 +25,7 @@
  #define ASPEED_GPIO_NR_PINS 228
  #define ASPEED_GROUPS_PER_SET 4
  #define ASPEED_GPIO_NR_DEBOUNCE_REGS 3
-#define ASPEED_CHARS_PER_GROUP_LABEL 3
+#define ASPEED_CHARS_PER_GROUP_LABEL 4

This should go to 1/3.

Quoted 4 lines
include/hw/gpio/aspeed_gpio.h +0 -0
  typedef struct GPIOSets GPIOSets;
  typedef struct AspeedGPIOState AspeedGPIOState;
 
#8 lore raw
In reply to Rashmica Gupta
Quoted 3 lines · Rashmica Gupta

There are a couple of things I'm not confident about here:
- what should be in init vs realize?

We are not very good at documenting this distinction (and there's some bits of it I'm not sure about either), but:
* init cannot contain anything that might fail
* init cannot contain anything that affects the simulation
* init shouldn't do anything that needs explicit cleanup (eg memory allocation)
* property creation has to happen in init, because properties are set after init but before realize

Thomas did a good blog post on this:
http://people.redhat.com/~thuth/blog/qemu/2018/09/10/instance-init-realize.html

Quoted 1 line

- should the irq state be in vmstate?

I guess you mean the "uint32_t int_status;" field here? If it's state that's in your device then it needs to be in vmstate (this roughly corresponds to 'is there a flipflop in the hardware that holds this state', though that is not a 100% perfect guide). A 'qemu_irq' holds no state of its own, so you cannot query it for the state of the line after migration. So if your device model needs to be able to know that state itself then it has to keep it in a struct field and migrate that struct field. (For some devices the state of the outbound interrupt line is a purely combinatorial result of some other
state: "int_output = int_status & int_mask" is a common one where there's a "raw interrupt status" and a mask bit that suppresses the outbound irq line. In that case the int_output need not be in the device's state struct or migrated, because we can just calculate it when we need it from the int_status and int_mask state.)

Quoted 1 line

- is there a better way to do composition of classes (patch 3)?

No strong opinion. From a quick scan through of patch 3 it didn't look obviously doing something in a suboptimal way.

thanks
-- PMM

#9 lore raw
In reply to Rashmica Gupta
Quoted 4 lines · Rashmica Gupta

There are a couple of things I'm not confident about here:
- what should be in init vs realize?
- should the irq state be in vmstate?
- is there a better way to do composition of classes (patch 3)?

You can not do twice :

     obj = object_new(TYPE_ASPEED_GPIO "-ast2600");

in aspeed_2600_gpio_realize(). This feels wrong.

Let's see if we can instantiate two GPIO devices with different types under the AST2600 SoC instead.

Thanks,

C.

Quoted 25 lines

v3:
- didn't have each gpio set up as an irq
- now can't access set AC on ast2400 (only exists on ast2500)
- added ast2600 implementation (patch 3)
- renamed a couple of variables for clarity

v2: Addressed Andrew's feedback, added debounce regs, renamed get/set to read/write to minimise confusion with a 'set' of registers.

Rashmica Gupta (3):
hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500
aspeed: add a GPIO controller to the SoC
hw/gpio: Add in AST2600 specific implementation

 hw/arm/aspeed_soc.c           |   17 +
 hw/gpio/Makefile.objs         |    1 +
 hw/gpio/aspeed_gpio.c         | 1103 +++++++++++++++++++++++++++++++++
 include/hw/arm/aspeed_soc.h   |    3 +
 include/hw/gpio/aspeed_gpio.h |   91 +++
 5 files changed, 1215 insertions(+)
 create mode 100644 hw/gpio/aspeed_gpio.c
 create mode 100644 include/hw/gpio/aspeed_gpio.h