hw/sd: Convert SD/MMC devices to Resettable interface
Subsystems (3)
PATCH 3/8 hw/sd/cadence_sdhci: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in cadence_sdhci_reset_hold().
Extract the reset logic into cadence_sdhci_do_reset() so the MMIO software reset path does not invoke the Resettable phase handler directly.
--- hw/sd/cadence_sdhci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
hw/sd/cadence_sdhci.c +9 -5
@@ -56,16 +56,19 @@ static void cadence_sdhci_instance_init(Object *obj) &s->sdhci, TYPE_SYSBUS_SDHCI); } -static void cadence_sdhci_reset (DeviceState *dev) +static void cadence_sdhci_do_reset (CadenceSDHCIState *s) { -CadenceSDHCIState *s =CADENCE_SDHCI (dev); -memset (s->regs,0 ,CADENCE_SDHCI_REG_SIZE ); s->regs[TO_REG (CADENCE_SDHCI_HRS00 )] =CADENCE_SDHCI_HRS00_POR_VAL ;device_cold_reset (DEVICE (&s->sdhci)); } +static void cadence_sdhci_reset_hold (Object *obj,ResetType type) +{ +cadence_sdhci_do_reset (CADENCE_SDHCI (obj)); +} +static uint64_t cadence_sdhci_read (void *opaque,hwaddr addr,unsigned int size) {CadenceSDHCIState *s = opaque;
@@ -89,7 +92,7 @@ static void cadence_sdhci_write(void *opaque, hwaddr addr, uint64_t val,* clears to zero, so essentially this register remains unchanged. */ if (val32 &CADENCE_SDHCI_HRS00_SWR ) { -cadence_sdhci_reset (DEVICE (s)); +cadence_sdhci_do_reset (s); }break ;
@@ -168,10 +171,11 @@ static const VMStateDescription vmstate_cadence_sdhci = {static void cadence_sdhci_class_init (ObjectClass *classp,const void *data) {DeviceClass *dc =DEVICE_CLASS (classp); +ResettableClass *rc =RESETTABLE_CLASS (classp); dc->desc ="Cadence SD/SDIO/eMMC Host Controller (SD4HC)" ; dc->realize = cadence_sdhci_realize; -device_class_set_legacy_reset (dc, cadence_sdhci_reset); + rc->phases.hold = cadence_sdhci_reset_hold; dc->vmsd = &vmstate_cadence_sdhci; }
Signature · 1 line
2.53.0
cover hw/sd: Convert SD/MMC devices to Resettable interface
Convert all remaining SD/MMC host controllers and card devices in hw/sd/ from the deprecated device_class_set_legacy_reset() interface to the Resettable interface (hold phase).
Where internal paths (MMIO soft-reset, card insertion, or CMD0) trigger a device reset, extract a helper routine so the Resettable phase method is not called directly, per docs/devel/reset.rst.
---
Oscar Alejandro Sánchez Lucero (8):
hw/sd/allwinner-sdhost: Convert to Resettable interface hw/sd/bcm2835_sdhost: Convert to Resettable interface hw/sd/cadence_sdhci: Convert to Resettable interface hw/sd/npcm7xx_sdhci: Convert to Resettable interface hw/sd/pl181: Convert to Resettable interface hw/sd/sd: Convert to Resettable interface hw/sd/sdhci: Convert to Resettable interface hw/sd/ssi-sd: Convert to Resettable interface
hw/sd/allwinner-sdhost.c | 7 ++++--- hw/sd/bcm2835_sdhost.c | 7 ++++--- hw/sd/cadence_sdhci.c | 14 +++++++++----- hw/sd/npcm7xx_sdhci.c | 7 ++++--- hw/sd/pl181.c | 7 ++++--- hw/sd/sd.c | 14 +++++++++----- hw/sd/sdhci.c | 7 ++++--- hw/sd/ssi-sd.c | 7 ++++--- 8 files changed, 42 insertions(+), 28 deletions(-)
---
base-commit: 9751c62358073580cbf330a4df22077a7c6a407c
change-id: 20261130-sd-resettable-d2911a1f5039
Best regards,
Signature · 1 line
Oscar Alejandro Sánchez Lucero <[email protected]>
PATCH 7/8 hw/sd/sdhci: Convert to Resettable interface
Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in sdhci_poweron_reset_hold().
--- hw/sd/sdhci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/sdhci.c +4 -3
@@ -332,14 +332,14 @@ static void sdhci_reset(SDHCIState *s) } } -static void sdhci_poweron_reset (DeviceState *dev) +static void sdhci_poweron_reset_hold (Object *obj,ResetType type) {/* * QOM (ie power-on) reset. This is identical to reset * commanded via device register apart from handling of the * 'pending insert on powerup' quirk. */ -SDHCIState *s = (SDHCIState *)dev; +SDHCIState *s =SYSBUS_SDHCI (obj);sdhci_reset (s);
@@ -1696,10 +1696,11 @@ const VMStateDescription sdhci_vmstate = {void sdhci_common_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass);set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); dc->vmsd = &sdhci_vmstate; -device_class_set_legacy_reset (dc, sdhci_poweron_reset); + rc->phases.hold = sdhci_poweron_reset_hold; }/* --- qdev SysBus --- */
Signature · 1 line
2.53.0
PATCH 8/8 hw/sd/ssi-sd: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in ssi_sd_reset_hold().
--- hw/sd/ssi-sd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/ssi-sd.c +4 -3
@@ -300,9 +300,9 @@ static void ssi_sd_realize(SSIPeripheral *d, Error **errp)qbus_init (&s->sdbus,sizeof (s->sdbus),TYPE_SD_BUS ,DEVICE (d),"sd-bus" ); } -static void ssi_sd_reset (DeviceState *dev) +static void ssi_sd_reset_hold (Object *obj,ResetType type) { -ssi_sd_state *s =SSI_SD (dev); +ssi_sd_state *s =SSI_SD (obj); s->mode =SSI_SD_CMD ; s->cmd =0 ;
@@ -320,12 +320,13 @@ static void ssi_sd_class_init(ObjectClass *klass, const void *data) {DeviceClass *dc =DEVICE_CLASS (klass);SSIPeripheralClass *k =SSI_PERIPHERAL_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); k->realize = ssi_sd_realize; k->transfer = ssi_sd_transfer; k->cs_polarity =SSI_CS_LOW ; dc->vmsd = &vmstate_ssi_sd; -device_class_set_legacy_reset (dc, ssi_sd_reset); + rc->phases.hold = ssi_sd_reset_hold;/* Reason: GPIO chip-select line should be wired up */ dc->user_creatable = false; }
Signature · 1 line
2.53.0
PATCH 5/8 hw/sd/pl181: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in pl181_reset_hold().
--- hw/sd/pl181.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/pl181.c +4 -3
@@ -463,9 +463,9 @@ static void pl181_set_inserted(DeviceState *dev, bool level)qemu_set_irq (s->card_inserted, level); } -static void pl181_reset (DeviceState *d) +static void pl181_reset_hold (Object *obj,ResetType type) { -PL181State *s =PL181 (d); +PL181State *s =PL181 (obj); s->power =0 ; s->cmdarg =0 ;
@@ -510,9 +510,10 @@ static void pl181_init(Object *obj)static void pl181_class_init (ObjectClass *klass,const void *data) {DeviceClass *k =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); k->vmsd = &vmstate_pl181; -device_class_set_legacy_reset (k, pl181_reset); + rc->phases.hold = pl181_reset_hold;/* Reason: output IRQs should be wired up */ k->user_creatable = false; }
Signature · 1 line
2.53.0
PATCH 4/8 hw/sd/npcm7xx_sdhci: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in npcm7xx_sdhci_reset_hold().
--- hw/sd/npcm7xx_sdhci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/npcm7xx_sdhci.c +4 -3
@@ -127,9 +127,9 @@ static void npcm7xx_sdhci_realize(DeviceState *dev, Error **errp) s->regs.prstvals[3 ] =NPCM7XX_PRSTVALS_3_RESET ; } -static void npcm7xx_sdhci_reset (DeviceState *dev) +static void npcm7xx_sdhci_reset_hold (Object *obj,ResetType type) { -NPCM7xxSDHCIState *s =NPCM7XX_SDHCI (dev); +NPCM7xxSDHCIState *s =NPCM7XX_SDHCI (obj);device_cold_reset (DEVICE (&s->sdhci)); s->regs.boottoctrl =0 ;
@@ -152,10 +152,11 @@ static const VMStateDescription vmstate_npcm7xx_sdhci = {static void npcm7xx_sdhci_class_init (ObjectClass *classp,const void *data) {DeviceClass *dc =DEVICE_CLASS (classp); +ResettableClass *rc =RESETTABLE_CLASS (classp); dc->desc ="NPCM7xx SD/eMMC Host Controller" ; dc->realize = npcm7xx_sdhci_realize; -device_class_set_legacy_reset (dc, npcm7xx_sdhci_reset); + rc->phases.hold = npcm7xx_sdhci_reset_hold; dc->vmsd = &vmstate_npcm7xx_sdhci; }
Signature · 1 line
2.53.0
PATCH 1/8 hw/sd/allwinner-sdhost: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in allwinner_sdhost_reset_hold().
--- hw/sd/allwinner-sdhost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/allwinner-sdhost.c +4 -3
@@ -835,9 +835,9 @@ static void allwinner_sdhost_realize(DeviceState *dev, Error **errp)address_space_init (&s->dma_as, s->dma_mr,"sdhost-dma" ); } -static void allwinner_sdhost_reset (DeviceState *dev) +static void allwinner_sdhost_reset_hold (Object *obj,ResetType type) { -AwSdHostState *s =AW_SDHOST (dev); +AwSdHostState *s =AW_SDHOST (obj);AwSdHostClass *sc =AW_SDHOST_GET_CLASS (s); s->global_ctl =REG_SD_GCTL_RST ;
@@ -896,8 +896,9 @@ static void allwinner_sdhost_bus_class_init(ObjectClass *klass,static void allwinner_sdhost_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); -device_class_set_legacy_reset (dc, allwinner_sdhost_reset); + rc->phases.hold = allwinner_sdhost_reset_hold; dc->vmsd = &vmstate_allwinner_sdhost; dc->realize = allwinner_sdhost_realize;device_class_set_props (dc, allwinner_sdhost_properties);
Signature · 1 line
2.53.0
PATCH 2/8 hw/sd/bcm2835_sdhost: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in bcm2835_sdhost_reset_hold().
--- hw/sd/bcm2835_sdhost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/sd/bcm2835_sdhost.c +4 -3
@@ -409,9 +409,9 @@ static void bcm2835_sdhost_init(Object *obj)sysbus_init_irq (SYS_BUS_DEVICE (s), &s->irq); } -static void bcm2835_sdhost_reset (DeviceState *dev) +static void bcm2835_sdhost_reset_hold (Object *obj,ResetType type) { -BCM2835SDHostState *s =BCM2835_SDHOST (dev); +BCM2835SDHostState *s =BCM2835_SDHOST (obj); s->cmd =0 ; s->cmdarg =0 ;
@@ -428,8 +428,9 @@ static void bcm2835_sdhost_reset(DeviceState *dev)static void bcm2835_sdhost_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); -device_class_set_legacy_reset (dc, bcm2835_sdhost_reset); + rc->phases.hold = bcm2835_sdhost_reset_hold; dc->vmsd = &vmstate_bcm2835_sdhost; }
Signature · 1 line
2.53.0
PATCH 6/8 hw/sd/sd: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroReplace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in sd_reset_hold().
Move the reset logic into sd_do_reset() so card insertion and CMD0 handlers do not invoke the Resettable phase handler directly.
--- hw/sd/sd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
hw/sd/sd.c +9 -5
@@ -911,9 +911,8 @@ static inline uint64_t sd_addr_to_wpnum(uint64_t addr)return addr >> (HWBLOCK_SHIFT +SECTOR_SHIFT +WPGROUP_SHIFT ); } -static void sd_reset (DeviceState *dev) +static void sd_do_reset (SDState *sd) { -SDState *sd =SDMMC_COMMON (dev);SDCardClass *sc =SDMMC_COMMON_GET_CLASS (sd);uint64_t size;uint64_t sect;
@@ -958,6 +957,11 @@ static void sd_reset(DeviceState *dev) sd->multi_blk_cnt =0 ; } +static void sd_reset_hold (Object *obj,ResetType type) +{ +sd_do_reset (SDMMC_COMMON (obj)); +} +static bool sd_get_inserted (SDState *sd) {return sd->blk &&blk_is_inserted (sd->blk);
@@ -978,7 +982,7 @@ static void sd_cardchange(void *opaque, bool load, Error **errp)if (inserted) {trace_sdcard_inserted (readonly); -sd_reset (dev); +sd_do_reset (sd); }else {trace_sdcard_ejected (); }
@@ -1674,7 +1678,7 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req) }if (sd->state != sd_inactive_state) { sd->state = sd_idle_state; -sd_reset (DEVICE (sd)); +sd_do_reset (sd); }return sd_is_spi (sd) ? sd_r1 : sd_r0;
@@ -3252,7 +3256,7 @@ static void sdmmc_common_class_init(ObjectClass *klass, const void *data)device_class_set_props (dc, sdmmc_common_properties); dc->vmsd = &sd_vmstate; -device_class_set_legacy_reset (dc, sd_reset); +RESETTABLE_CLASS (klass)->phases.hold = sd_reset_hold; dc->bus_type =TYPE_SD_BUS ;set_bit (DEVICE_CATEGORY_STORAGE , dc->categories);
Signature · 1 line
2.53.0
Re: [PATCH 1/8] hw/sd/allwinner-sdhost: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 10 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase inallwinner_sdhost_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/allwinner-sdhost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Re: [PATCH 2/8] hw/sd/bcm2835_sdhost: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 10 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase inbcm2835_sdhost_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/bcm2835_sdhost.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Re: [PATCH 8/8] hw/sd/ssi-sd: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 10 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase inssi_sd_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/ssi-sd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Re: [PATCH 3/8] hw/sd/cadence_sdhci: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 5 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase incadence_sdhci_reset_hold().
Quoted 9 lines
Extract the reset logic into
cadence_sdhci_do_reset()so the MMIO software reset path does not invoke the Resettable phase handler directly.Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/cadence_sdhci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
Re: [PATCH 4/8] hw/sd/npcm7xx_sdhci: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 10 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase innpcm7xx_sdhci_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/npcm7xx_sdhci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Re: [PATCH 7/8] hw/sd/sdhci: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 18 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase insdhci_poweron_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/sdhci.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/sd/sdhci.c +0
-0@@ -332,14 +332,14 @@ static void sdhci_reset(SDHCIState *s) } }
hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 342
Quoted 10 lines
hw/sd/sdhci.c +2
-2-static void sdhci_poweron_reset (DeviceState *dev) +static void sdhci_poweron_reset_hold (Object *obj,ResetType type) {/* * QOM (ie power-on) reset. This is identical to reset * commanded via device register apart from handling of the * 'pending insert on powerup' quirk. */ -SDHCIState *s = (SDHCIState *)dev; +SDHCIState *s =SYSBUS_SDHCI (obj);
This callback is shared by the SysBus and PCI variants through sdhci_common_class_init(). Since sdhci-pci does not derive from generic-sdhci, this cast aborts during startup with the default QOM cast checks enabled.
Quoted 7 lines
hw/sd/sdhci.c +0
-0sdhci_reset (s);@@ -1696,10 +1696,11 @@ const VMStateDescription sdhci_vmstate = {void sdhci_common_class_init (ObjectClass *klass,const void *data) {
hw/sd/sdhci.c const VMStateDescription sdhci_vmstate = { · line 1706
Quoted 10 lines
hw/sd/sdhci.c +2
-1DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass);set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); dc->vmsd = &sdhci_vmstate; -device_class_set_legacy_reset (dc, sdhci_poweron_reset); + rc->phases.hold = sdhci_poweron_reset_hold; }/* --- qdev SysBus --- */
Regards,
Bin
Re: [PATCH 6/8] hw/sd/sd: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 5 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase insd_reset_hold().
Quoted 8 lines
Move the reset logic into
sd_do_reset()so card insertion and CMD0 handlers do not invoke the Resettable phase handler directly.Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/sd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
Re: [PATCH 5/8] hw/sd/pl181: Convert to Resettable interface
In reply to Oscar Alejandro Sánchez LuceroQuoted 10 lines · Oscar Alejandro Sánchez Lucero
Replace the deprecated
device_class_set_legacy_reset()with the Resettable interface by implementing the hold phase inpl181_reset_hold().Signed-off-by Oscar Alejandro Sánchez Lucero <[email protected]>--- hw/sd/pl181.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)