[PATCH 2/5] hw/pcmcia/microdrive: Register machine reset handler
The abstract PCMCIA_CARD is a bus-less TYPE_DEVICE, so devices implementing it are not reset automatically. Register a reset handler so children get reset on machine reset. Note, the DSCM-1 device (TYPE_DSCM1) which inherits TYPE_MICRODRIVE and PCMCIA_CARD reset itself when a disk is attached or detached, but was not resetting itself on machine reset. It doesn't seem to be an issue because it is that way since the device QDev'ifycation 8 years ago, in commit d1f2c96a81a ("pcmcia: QOM'ify PCMCIACardState and MicroDriveState"). Still, correct to have a proper API usage. Signed-off-by: Philippe Mathieu-Daudé --- hw/pcmcia/pcmcia.c | 25 + 1 file changed, 25 insertions(+) diff --git a/hw/pcmcia/pcmcia.c b/hw/pcmcia/pcmcia.c index 03d13e7d670..73656257227 100644 --- a/hw/pcmcia/pcmcia.c +++ b/hw/pcmcia/pcmcia.c @@ -6,14 +6,39 @@ #include "qemu/osdep.h" #include "qemu/module.h" +#include "sysemu/reset.h" #include "hw/pcmcia.h" +static void pcmcia_card_reset_handler(void *dev) +{ +device_legacy_reset(DEVICE(dev)); +} + +static void pcmcia_card_realize(DeviceState *dev, Error **errp) +{ +qemu_register_reset(pcmcia_card_reset_handler, dev); +} + +static void pcmcia_card_unrealize(DeviceState *dev) +{ +qemu_unregister_reset(pcmcia_card_reset_handler, dev); +} + +static void pcmcia_card_class_init(ObjectClass *klass, void *data) +{ +DeviceClass *dc = DEVICE_CLASS(klass); + +dc->realize = pcmcia_card_realize; +dc->unrealize = pcmcia_card_unrealize; +} + static const TypeInfo pcmcia_card_type_info = { .name = TYPE_PCMCIA_CARD, .parent = TYPE_DEVICE, .instance_size = sizeof(PCMCIACardState), .abstract = true, .class_size = sizeof(PCMCIACardClass), +.class_init = pcmcia_card_class_init, }; static void pcmcia_register_types(void) -- 2.26.3
Re: [PATCH 2/5] hw/pcmcia/microdrive: Register machine reset handler
On Sat, 24 Apr 2021 at 17:22, Philippe Mathieu-Daudé wrote: > > The abstract PCMCIA_CARD is a bus-less TYPE_DEVICE, so devices > implementing it are not reset automatically. > Register a reset handler so children get reset on machine reset. > > Note, the DSCM-1 device (TYPE_DSCM1) which inherits > TYPE_MICRODRIVE and PCMCIA_CARD reset itself when a disk is > attached or detached, but was not resetting itself on machine > reset. > > It doesn't seem to be an issue because it is that way since the > device QDev'ifycation 8 years ago, in commit d1f2c96a81a > ("pcmcia: QOM'ify PCMCIACardState and MicroDriveState"). > Still, correct to have a proper API usage. > > Signed-off-by: Philippe Mathieu-Daudé > --- > hw/pcmcia/pcmcia.c | 25 + > 1 file changed, 25 insertions(+) > > diff --git a/hw/pcmcia/pcmcia.c b/hw/pcmcia/pcmcia.c > index 03d13e7d670..73656257227 100644 > --- a/hw/pcmcia/pcmcia.c > +++ b/hw/pcmcia/pcmcia.c > @@ -6,14 +6,39 @@ > > #include "qemu/osdep.h" > #include "qemu/module.h" > +#include "sysemu/reset.h" > #include "hw/pcmcia.h" > > +static void pcmcia_card_reset_handler(void *dev) > +{ > +device_legacy_reset(DEVICE(dev)); > +} > + > +static void pcmcia_card_realize(DeviceState *dev, Error **errp) > +{ > +qemu_register_reset(pcmcia_card_reset_handler, dev); > +} > + > +static void pcmcia_card_unrealize(DeviceState *dev) > +{ > +qemu_unregister_reset(pcmcia_card_reset_handler, dev); > +} Why isn't a pcmcia card something that plugs into a bus ? -- PMM
Re: [PATCH 2/5] hw/pcmcia/microdrive: Register machine reset handler
On 4/25/21 8:36 PM, Peter Maydell wrote: > On Sat, 24 Apr 2021 at 17:22, Philippe Mathieu-Daudé wrote: >> >> The abstract PCMCIA_CARD is a bus-less TYPE_DEVICE, so devices >> implementing it are not reset automatically. >> Register a reset handler so children get reset on machine reset. >> >> Note, the DSCM-1 device (TYPE_DSCM1) which inherits >> TYPE_MICRODRIVE and PCMCIA_CARD reset itself when a disk is >> attached or detached, but was not resetting itself on machine >> reset. >> >> It doesn't seem to be an issue because it is that way since the >> device QDev'ifycation 8 years ago, in commit d1f2c96a81a >> ("pcmcia: QOM'ify PCMCIACardState and MicroDriveState"). >> Still, correct to have a proper API usage. >> >> Signed-off-by: Philippe Mathieu-Daudé >> --- >> hw/pcmcia/pcmcia.c | 25 + >> 1 file changed, 25 insertions(+) >> >> diff --git a/hw/pcmcia/pcmcia.c b/hw/pcmcia/pcmcia.c >> index 03d13e7d670..73656257227 100644 >> --- a/hw/pcmcia/pcmcia.c >> +++ b/hw/pcmcia/pcmcia.c >> @@ -6,14 +6,39 @@ >> >> #include "qemu/osdep.h" >> #include "qemu/module.h" >> +#include "sysemu/reset.h" >> #include "hw/pcmcia.h" >> >> +static void pcmcia_card_reset_handler(void *dev) >> +{ >> +device_legacy_reset(DEVICE(dev)); >> +} >> + >> +static void pcmcia_card_realize(DeviceState *dev, Error **errp) >> +{ >> +qemu_register_reset(pcmcia_card_reset_handler, dev); >> +} >> + >> +static void pcmcia_card_unrealize(DeviceState *dev) >> +{ >> +qemu_unregister_reset(pcmcia_card_reset_handler, dev); >> +} > > Why isn't a pcmcia card something that plugs into a bus ? No clue, looks like a very old device with unfinished qdev-ification? See pxa2xx_pcmcia_attach(): /* Insert a new card into a slot */ int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card) { PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque; PCMCIACardClass *pcc; ... s->card = card; pcc = PCMCIA_CARD_GET_CLASS(s->card); ... s->card->slot = &s->slot; pcc->attach(s->card); ... }