Skip to contentSkip to conversation

hw/ssi: Convert SPI controllers to Resettable interface

PATCH New Oscar Alejandro Sánchez Lucero 1 participant 12 messages Dec 2

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover hw/ssi: Convert SPI controllers to Resettable interface

Convert all remaining SPI controller device models in hw/ssi away from the deprecated device_class_set_legacy_reset() wrapper to the ResettableClass interface (hold phase), moving towards removing the legacy_reset callback from DeviceClass once all callers are migrated (as noted in include/hw/core/qdev.h).

---
Oscar Alejandro Sánchez Lucero (11):
hw/ssi/bcm2835_spi: Convert to Resettable interface hw/ssi/ibex_spi_host: Convert to Resettable interface hw/ssi/imx_spi: Convert to Resettable interface hw/ssi/mss-spi: Convert to Resettable interface hw/ssi/pl022: Convert to Resettable interface hw/ssi/pnv_spi: Convert to Resettable interface hw/ssi/sifive_spi: Convert to Resettable interface hw/ssi/stm32f2xx_spi: Convert to Resettable interface hw/ssi/xilinx_spi: Convert to Resettable interface hw/ssi/xlnx-versal-ospi: Convert to Resettable interface hw/ssi/xilinx_spips: Convert to Resettable interface

 hw/ssi/bcm2835_spi.c          |  7 ++++---
 hw/ssi/ibex_spi_host.c        | 10 ++++++----
 hw/ssi/imx_spi.c              |  7 ++++---
 hw/ssi/mss-spi.c              |  9 +++++----
 hw/ssi/pl022.c                |  7 ++++---
 hw/ssi/pnv_spi.c              |  8 +++++---
 hw/ssi/sifive_spi.c           |  7 ++++---
 hw/ssi/stm32f2xx_spi.c        |  7 ++++---
 hw/ssi/xilinx_spi.c           |  7 ++++---
 hw/ssi/xilinx_spips.c         | 21 ++++++++++++++-------
 hw/ssi/xlnx-versal-ospi.c     |  7 ++++---
 include/hw/ssi/xilinx_spips.h |  1 +
 12 files changed, 59 insertions(+), 39 deletions(-)

---
base-commit: bbece0805c03c25f51a8cd89c39142f4f76a6567
change-id: 20261202-ssi-resettable-d15f725acffa

Best regards,

Signature · 1 line
Oscar Alejandro Sánchez Lucero <[email protected]>
#1 lore raw

PATCH 1/11 hw/ssi/bcm2835_spi: Convert to Resettable interface

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in bcm2835_spi_reset_hold().

---
 hw/ssi/bcm2835_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/bcm2835_spi.c +4 -3
index 01763c4..f7a6ccc 100644
@@ -233,9 +233,9 @@ static void bcm2835_spi_realize(DeviceState *dev, Error **errp)
     fifo8_create(&s->tx_fifo, FIFO_SIZE);
     fifo8_create(&s->rx_fifo, FIFO_SIZE);
 }
-static void bcm2835_spi_reset(DeviceState *dev)
+static void bcm2835_spi_reset_hold(Object *obj, ResetType type)
 {
-    BCM2835SPIState *s = BCM2835_SPI(dev);
+    BCM2835SPIState *s = BCM2835_SPI(obj);
 
     fifo8_reset(&s->tx_fifo);
     fifo8_reset(&s->rx_fifo);
@@ -267,8 +267,9 @@ static const VMStateDescription vmstate_bcm2835_spi = {
 static void bcm2835_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, bcm2835_spi_reset);
+    rc->phases.hold = bcm2835_spi_reset_hold;
     dc->realize = bcm2835_spi_realize;
     dc->vmsd = &vmstate_bcm2835_spi;
 }
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/11 hw/ssi/ibex_spi_host: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in ibex_spi_host_reset_hold().

---
 hw/ssi/ibex_spi_host.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/ssi/ibex_spi_host.c +6 -4
index 1e574c3..e84ea65 100644
@@ -127,9 +127,9 @@ static void ibex_spi_txfifo_reset(IbexSPIHostState *s)
     s->regs[IBEX_SPI_HOST_STATUS] = data;
 }
 
-static void ibex_spi_host_reset(DeviceState *dev)
+static void ibex_spi_host_reset_hold(Object *obj, ResetType type)
 {
-    IbexSPIHostState *s = IBEX_SPI_HOST(dev);
+    IbexSPIHostState *s = IBEX_SPI_HOST(obj);
     trace_ibex_spi_host_reset("Resetting Ibex SPI");
 
     /* SPI Host Register Reset */
@@ -380,7 +380,7 @@ static void ibex_spi_host_write(void *opaque, hwaddr addr,
         s->regs[addr] = val32;
 
         if (val32 & R_CONTROL_SW_RST_MASK)  {
-            ibex_spi_host_reset((DeviceState *)s);
+            device_cold_reset(DEVICE(s));
             /* Clear active if any */
             s->regs[IBEX_SPI_HOST_STATUS] &=  ~R_STATUS_ACTIVE_MASK;
         }
@@ -625,8 +625,10 @@ static void ibex_spi_host_init(Object *obj)
 static void ibex_spi_host_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
     dc->realize = ibex_spi_host_realize;
-    device_class_set_legacy_reset(dc, ibex_spi_host_reset);
+    rc->phases.hold = ibex_spi_host_reset_hold;
     dc->vmsd = &vmstate_ibex;
     device_class_set_props(dc, ibex_spi_properties);
 }
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/11 hw/ssi/imx_spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in imx_spi_reset_hold().

---
 hw/ssi/imx_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/imx_spi.c +4 -3
index 8e014b7..6d2dd84 100644
@@ -269,9 +269,9 @@ static void imx_spi_soft_reset(IMXSPIState *s)
     }
 }
 
-static void imx_spi_reset(DeviceState *dev)
+static void imx_spi_reset_hold(Object *obj, ResetType type)
 {
-    IMXSPIState *s = IMX_SPI(dev);
+    IMXSPIState *s = IMX_SPI(obj);
 
     imx_spi_common_reset(s);
     s->regs[ECSPI_CONREG] = 0;
@@ -478,10 +478,11 @@ static void imx_spi_realize(DeviceState *dev, Error **errp)
 static void imx_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = imx_spi_realize;
     dc->vmsd = &vmstate_imx_spi;
-    device_class_set_legacy_reset(dc, imx_spi_reset);
+    rc->phases.hold = imx_spi_reset_hold;
     dc->desc = "i.MX SPI Controller";
 }
 
Signature · 1 line
2.53.0
#4 lore raw

PATCH 4/11 hw/ssi/mss-spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in mss_spi_reset_hold().

---
 hw/ssi/mss-spi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
hw/ssi/mss-spi.c +5 -4
index 3c118fc..625d0b7 100644
@@ -137,9 +137,9 @@ static void spi_update_irq(MSSSpiState *s)
     qemu_set_irq(s->irq, irq);
 }
 
-static void mss_spi_reset(DeviceState *d)
+static void mss_spi_reset_hold(Object *obj, ResetType type)
 {
-    MSSSpiState *s = MSS_SPI(d);
+    MSSSpiState *s = MSS_SPI(obj);
 
     memset(s->regs, 0, sizeof s->regs);
     s->regs[R_SPI_CONTROL] = 0x80000102;
@@ -301,7 +301,7 @@ static void spi_write(void *opaque, hwaddr addr,
         s->enabled = value & C_ENABLE;
         s->frame_count = (value & FMCOUNT_MASK) >> FMCOUNT_SHIFT;
         if (value & C_RESET) {
-            mss_spi_reset(DEVICE(s));
+            device_cold_reset(DEVICE(s));
         }
         break;
 
@@ -401,9 +401,10 @@ static const VMStateDescription vmstate_mss_spi = {
 static void mss_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = mss_spi_realize;
-    device_class_set_legacy_reset(dc, mss_spi_reset);
+    rc->phases.hold = mss_spi_reset_hold;
     dc->vmsd = &vmstate_mss_spi;
 }
 
Signature · 1 line
2.53.0
#5 lore raw

PATCH 5/11 hw/ssi/pl022: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in pl022_reset_hold().

---
 hw/ssi/pl022.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/pl022.c +4 -3
index 715a2d2..4ac1d34 100644
@@ -214,9 +214,9 @@ static void pl022_write(void *opaque, hwaddr offset,
     }
 }
 
-static void pl022_reset(DeviceState *dev)
+static void pl022_reset_hold(Object *obj, ResetType type)
 {
-    PL022State *s = PL022(dev);
+    PL022State *s = PL022(obj);
 
     s->rx_fifo_len = 0;
     s->tx_fifo_len = 0;
@@ -295,8 +295,9 @@ static void pl022_realize(DeviceState *dev, Error **errp)
 static void pl022_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, pl022_reset);
+    rc->phases.hold = pl022_reset_hold;
     dc->vmsd = &vmstate_pl022;
     dc->realize = pl022_realize;
 }
Signature · 1 line
2.53.0
#6 lore raw

PATCH 6/11 hw/ssi/pnv_spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in pnv_spi_reset_hold().

---
 hw/ssi/pnv_spi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/ssi/pnv_spi.c +5 -3
index f3add8c..380741f 100644
@@ -1010,9 +1010,9 @@ static void operation_sequencer(PnvSpi *s)
  * The SPIC engine reset does not have any affect on the attached devices.
  * Reset handling of any attached devices is beyond the scope of the engine.
  */
-static void do_reset(DeviceState *dev)
+static void pnv_spi_reset_hold(Object *obj, ResetType type)
 {
-    PnvSpi *s = PNV_SPI(dev);
+    PnvSpi *s = PNV_SPI(obj);
     DeviceState *ssi_dev;
 
     trace_pnv_spi_reset();
@@ -1240,9 +1240,11 @@ static void pnv_spi_class_init(ObjectClass *klass, const void *data)
     xscomc->dt_xscom = pnv_spi_dt_xscom;
 
     dc->desc = "PowerNV SPI";
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
     dc->realize = pnv_spi_realize;
     dc->unrealize = pnv_spi_unrealize;
-    device_class_set_legacy_reset(dc, do_reset);
+    rc->phases.hold = pnv_spi_reset_hold;
     dc->vmsd = &pnv_spi_vmstate;
     device_class_set_props(dc, pnv_spi_properties);
 }
Signature · 1 line
2.53.0
#7 lore raw

PATCH 7/11 hw/ssi/sifive_spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in sifive_spi_reset_hold().

---
 hw/ssi/sifive_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/sifive_spi.c +4 -3
index 2ece780..fc2d8ef 100644
@@ -106,9 +106,9 @@ static void sifive_spi_update_irq(SiFiveSPIState *s)
     qemu_set_irq(s->irq, level);
 }
 
-static void sifive_spi_reset(DeviceState *d)
+static void sifive_spi_reset_hold(Object *obj, ResetType type)
 {
-    SiFiveSPIState *s = SIFIVE_SPI(d);
+    SiFiveSPIState *s = SIFIVE_SPI(obj);
 
     memset(s->regs, 0, sizeof(s->regs));
 
@@ -335,9 +335,10 @@ static const Property sifive_spi_properties[] = {
 static void sifive_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     device_class_set_props(dc, sifive_spi_properties);
-    device_class_set_legacy_reset(dc, sifive_spi_reset);
+    rc->phases.hold = sifive_spi_reset_hold;
     dc->realize = sifive_spi_realize;
 }
 
Signature · 1 line
2.53.0
#8 lore raw

PATCH 8/11 hw/ssi/stm32f2xx_spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in stm32f2xx_spi_reset_hold().

---
 hw/ssi/stm32f2xx_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/stm32f2xx_spi.c +4 -3
index da1dbb7..e37edd8 100644
@@ -40,9 +40,9 @@
 
 #define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
 
-static void stm32f2xx_spi_reset(DeviceState *dev)
+static void stm32f2xx_spi_reset_hold(Object *obj, ResetType type)
 {
-    STM32F2XXSPIState *s = STM32F2XX_SPI(dev);
+    STM32F2XXSPIState *s = STM32F2XX_SPI(obj);
 
     s->spi_cr1 = 0x00000000;
     s->spi_cr2 = 0x00000000;
@@ -204,8 +204,9 @@ static void stm32f2xx_spi_init(Object *obj)
 static void stm32f2xx_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, stm32f2xx_spi_reset);
+    rc->phases.hold = stm32f2xx_spi_reset_hold;
     dc->vmsd = &vmstate_stm32f2xx_spi;
 }
 
Signature · 1 line
2.53.0
#9 lore raw

PATCH 9/11 hw/ssi/xilinx_spi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in xlx_spi_reset_hold().

---
 hw/ssi/xilinx_spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/xilinx_spi.c +4 -3
index 79f3e8b..36cb492 100644
@@ -164,9 +164,9 @@ static void xlx_spi_do_reset(XilinxSPI *s)
     xlx_spi_update_cs(s);
 }
 
-static void xlx_spi_reset(DeviceState *d)
+static void xlx_spi_reset_hold(Object *obj, ResetType type)
 {
-    xlx_spi_do_reset(XILINX_SPI(d));
+    xlx_spi_do_reset(XILINX_SPI(obj));
 }
 
 static inline int spi_master_enabled(XilinxSPI *s)
@@ -382,9 +382,10 @@ static const Property xilinx_spi_properties[] = {
 static void xilinx_spi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = xilinx_spi_realize;
-    device_class_set_legacy_reset(dc, xlx_spi_reset);
+    rc->phases.hold = xlx_spi_reset_hold;
     device_class_set_props(dc, xilinx_spi_properties);
     dc->vmsd = &vmstate_xilinx_spi;
 }
Signature · 1 line
2.53.0
#10 lore raw

PATCH 10/11 hw/ssi/xlnx-versal-ospi: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in xlnx_versal_ospi_reset_hold().

---
 hw/ssi/xlnx-versal-ospi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/ssi/xlnx-versal-ospi.c +4 -3
index e25e4c2..fb42105 100644
@@ -1390,9 +1390,9 @@ static uint64_t dll_obs_upper_reg_post_read(RegisterInfo *reg, uint64_t val)
 }
 
 
-static void xlnx_versal_ospi_reset(DeviceState *dev)
+static void xlnx_versal_ospi_reset_hold(Object *obj, ResetType type)
 {
-    XlnxVersalOspi *s = XILINX_VERSAL_OSPI(dev);
+    XlnxVersalOspi *s = XILINX_VERSAL_OSPI(obj);
     unsigned int i;
 
     for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) {
@@ -1830,8 +1830,9 @@ static const Property xlnx_versal_ospi_properties[] = {
 static void xlnx_versal_ospi_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, xlnx_versal_ospi_reset);
+    rc->phases.hold = xlnx_versal_ospi_reset_hold;
     dc->realize = xlnx_versal_ospi_realize;
     dc->vmsd = &vmstate_xlnx_versal_ospi;
     device_class_set_props(dc, xlnx_versal_ospi_properties);
Signature · 1 line
2.53.0
#11 lore raw

PATCH 11/11 hw/ssi/xilinx_spips: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in xilinx_spips_reset_hold() and xlnx_zynqmp_qspips_reset_hold(), chaining the parent hold phase via resettable_class_set_parent_phases().

---
 hw/ssi/xilinx_spips.c         | 21 ++++++++++++++-------
 include/hw/ssi/xilinx_spips.h |  1 +
 2 files changed, 15 insertions(+), 7 deletions(-)
hw/ssi/xilinx_spips.c +14 -7
index e4fce2c..6c5b526 100644
@@ -366,9 +366,9 @@ static void xlnx_zynqmp_qspips_update_ixr(XlnxZynqMPQSPIPS *s)
     }
 }
 
-static void xilinx_spips_reset(DeviceState *d)
+static void xilinx_spips_reset_hold(Object *obj, ResetType type)
 {
-    XilinxSPIPS *s = XILINX_SPIPS(d);
+    XilinxSPIPS *s = XILINX_SPIPS(obj);
 
     memset(s->regs, 0, sizeof(s->regs));
 
@@ -392,11 +392,14 @@ static void xilinx_spips_reset(DeviceState *d)
     xilinx_spips_update_cs_lines(s);
 }
 
-static void xlnx_zynqmp_qspips_reset(DeviceState *d)
+static void xlnx_zynqmp_qspips_reset_hold(Object *obj, ResetType type)
 {
-    XlnxZynqMPQSPIPS *s = XLNX_ZYNQMP_QSPIPS(d);
+    XlnxZynqMPQSPIPS *s = XLNX_ZYNQMP_QSPIPS(obj);
+    XilinxSPIPSClass *xsc = XILINX_SPIPS_GET_CLASS(obj);
 
-    xilinx_spips_reset(d);
+    if (xsc->parent_phases.hold) {
+        xsc->parent_phases.hold(obj, type);
+    }
 
     memset(s->regs, 0, sizeof(s->regs));
 
@@ -1502,10 +1505,11 @@ static void xilinx_qspips_class_init(ObjectClass *klass, const void *data)
 static void xilinx_spips_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
     XilinxSPIPSClass *xsc = XILINX_SPIPS_CLASS(klass);
 
     dc->realize = xilinx_spips_realize;
-    device_class_set_legacy_reset(dc, xilinx_spips_reset);
+    rc->phases.hold = xilinx_spips_reset_hold;
     device_class_set_props(dc, xilinx_spips_properties);
     dc->vmsd = &vmstate_xilinx_spips;
 
@@ -1518,10 +1522,13 @@ static void xilinx_spips_class_init(ObjectClass *klass, const void *data)
 static void xlnx_zynqmp_qspips_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
     XilinxSPIPSClass *xsc = XILINX_SPIPS_CLASS(klass);
 
     dc->realize = xlnx_zynqmp_qspips_realize;
-    device_class_set_legacy_reset(dc, xlnx_zynqmp_qspips_reset);
+    resettable_class_set_parent_phases(rc, NULL,
+                                       xlnx_zynqmp_qspips_reset_hold,
+                                       NULL, &xsc->parent_phases);
     dc->vmsd = &vmstate_xlnx_zynqmp_qspips;
     device_class_set_props(dc, xilinx_zynqmp_qspips_properties);
     xsc->reg_ops = &xlnx_zynqmp_qspips_ops;
include/hw/ssi/xilinx_spips.h +1 -0
index d1eefa4..f7c1405 100644
@@ -125,6 +125,7 @@ struct XlnxZynqMPQSPIPS {
 
 struct XilinxSPIPSClass {
     SysBusDeviceClass parent_class;
+    ResettablePhases parent_phases;
 
     const MemoryRegionOps *reg_ops;
     uint64_t reg_size;
Signature · 1 line
2.53.0