Some devices and machines need to handle the reset before a vmsave snapshot is loaded differently -- the main user is the handling of RNG seed information, which does not want to put a new RNG seed into a ROM blob when we are doing a snapshot load.
Currently this kind of reset handling is supported only for: * TYPE_MACHINE reset methods, which take a ShutdownCause argument * reset functions registered with qemu_register_reset_nosnapshotload Adding a new ResetType that indicates the pre-snapshot-load reset allows code that implements reset via Resettable to also do this. As an immediate consequence, that means we can clean up the ugly global variable in reset.c that we use to implement the qemu_register_reset_nosnapshotload() callbacks. Slightly longer term, I'm looking at making TYPE_MACHINE a subtype of TYPE_DEVICE, and converting the non-standard reset method of MachineClass into a Resettable as a result, so we'll need this ResetType there too. Adding a new reset type makes plain an awkwardness in our current Resettable API: we only pass the ResetType in to the 'enter' phase method, not 'hold' and 'exit', even though we have it available in the calling code. To avoid annoying workarounds like implementing an 'enter' method that stashes the ResetType for the later 'hold' or 'exit' method to use, we change the signatures of the 'hold' and 'exit' methods to also pass the ResetType. Patch 3 is a Coccinelle script which implements the transformation of the code, and patch 4 is the result of running that script, with no manual tweaks. This is really the biggest part of this patchset. Patch 6 is the actual addition of the new ResetType, which isn't very complicated. There is a TODO comment in resettable.h that claims that "ResettableState structure has to be expanded" to add more ResetTypes, but I can't see any reason why this should be, and I didn't find any discussion in the mailing list archives about it, so I have gone ahead anyway... thanks -- PMM Peter Maydell (6): hw/misc: Don't special case RESET_TYPE_COLD in npcm7xx_clk, gcr allwinner-i2c, adm1272: Use device_cold_reset() for software-triggered reset scripts/coccinelle: New script to add ResetType to hold and exit phases hw, target: Add ResetType argument to hold and exit phase methods docs/devel/reset: Update to new API for hold and exit phase methods reset: Add RESET_TYPE_SNAPSHOT_LOAD docs/devel/reset.rst | 25 ++++-- scripts/coccinelle/reset-type.cocci | 133 ++++++++++++++++++++++++++++ include/hw/resettable.h | 5 +- hw/adc/npcm7xx_adc.c | 2 +- hw/arm/pxa2xx_pic.c | 2 +- hw/arm/smmu-common.c | 2 +- hw/arm/smmuv3.c | 4 +- hw/arm/stellaris.c | 10 +-- hw/audio/asc.c | 2 +- hw/char/cadence_uart.c | 2 +- hw/char/sifive_uart.c | 2 +- hw/core/cpu-common.c | 2 +- hw/core/qdev.c | 4 +- hw/core/reset.c | 17 ++-- hw/core/resettable.c | 8 +- hw/display/virtio-vga.c | 4 +- hw/gpio/npcm7xx_gpio.c | 2 +- hw/gpio/pl061.c | 2 +- hw/gpio/stm32l4x5_gpio.c | 2 +- hw/hyperv/vmbus.c | 2 +- hw/i2c/allwinner-i2c.c | 5 +- hw/i2c/npcm7xx_smbus.c | 2 +- hw/input/adb.c | 2 +- hw/input/ps2.c | 12 +-- hw/intc/arm_gic_common.c | 2 +- hw/intc/arm_gic_kvm.c | 4 +- hw/intc/arm_gicv3_common.c | 2 +- hw/intc/arm_gicv3_its.c | 4 +- hw/intc/arm_gicv3_its_common.c | 2 +- hw/intc/arm_gicv3_its_kvm.c | 4 +- hw/intc/arm_gicv3_kvm.c | 4 +- hw/intc/xics.c | 2 +- hw/m68k/q800-glue.c | 2 +- hw/misc/djmemc.c | 2 +- hw/misc/iosb.c | 2 +- hw/misc/mac_via.c | 8 +- hw/misc/macio/cuda.c | 4 +- hw/misc/macio/pmu.c | 4 +- hw/misc/mos6522.c | 2 +- hw/misc/npcm7xx_clk.c | 13 +-- hw/misc/npcm7xx_gcr.c | 12 +-- hw/misc/npcm7xx_mft.c | 2 +- hw/misc/npcm7xx_pwm.c | 2 +- hw/misc/stm32l4x5_exti.c | 2 +- hw/misc/stm32l4x5_rcc.c | 10 +-- hw/misc/stm32l4x5_syscfg.c | 2 +- hw/misc/xlnx-versal-cframe-reg.c | 2 +- hw/misc/xlnx-versal-crl.c | 2 +- hw/misc/xlnx-versal-pmc-iou-slcr.c | 2 +- hw/misc/xlnx-versal-trng.c | 2 +- hw/misc/xlnx-versal-xramc.c | 2 +- hw/misc/xlnx-zynqmp-apu-ctrl.c | 2 +- hw/misc/xlnx-zynqmp-crf.c | 2 +- hw/misc/zynq_slcr.c | 4 +- hw/net/can/xlnx-zynqmp-can.c | 2 +- hw/net/e1000.c | 2 +- hw/net/e1000e.c | 2 +- hw/net/igb.c | 2 +- hw/net/igbvf.c | 2 +- hw/nvram/xlnx-bbram.c | 2 +- hw/nvram/xlnx-versal-efuse-ctrl.c | 2 +- hw/nvram/xlnx-zynqmp-efuse.c | 2 +- hw/pci-bridge/cxl_root_port.c | 4 +- hw/pci-bridge/pcie_root_port.c | 2 +- hw/pci-host/bonito.c | 2 +- hw/pci-host/pnv_phb.c | 4 +- hw/pci-host/pnv_phb3_msi.c | 4 +- hw/pci/pci.c | 4 +- hw/rtc/mc146818rtc.c | 2 +- hw/s390x/css-bridge.c | 2 +- hw/sensor/adm1266.c | 2 +- hw/sensor/adm1272.c | 4 +- hw/sensor/isl_pmbus_vr.c | 10 +-- hw/sensor/max31785.c | 2 +- hw/sensor/max34451.c | 2 +- hw/ssi/npcm7xx_fiu.c | 2 +- hw/timer/etraxfs_timer.c | 2 +- hw/timer/npcm7xx_timer.c | 2 +- hw/usb/hcd-dwc2.c | 8 +- hw/usb/xlnx-versal-usb2-ctrl-regs.c | 2 +- hw/virtio/virtio-pci.c | 2 +- target/arm/cpu.c | 4 +- target/avr/cpu.c | 4 +- target/cris/cpu.c | 4 +- target/hexagon/cpu.c | 4 +- target/i386/cpu.c | 4 +- target/loongarch/cpu.c | 4 +- target/m68k/cpu.c | 4 +- target/microblaze/cpu.c | 4 +- target/mips/cpu.c | 4 +- target/nios2/cpu.c | 4 +- target/openrisc/cpu.c | 4 +- target/ppc/cpu_init.c | 4 +- target/riscv/cpu.c | 4 +- target/rx/cpu.c | 4 +- target/sh4/cpu.c | 4 +- target/sparc/cpu.c | 4 +- target/tricore/cpu.c | 4 +- target/xtensa/cpu.c | 4 +- 99 files changed, 317 insertions(+), 195 deletions(-) create mode 100644 scripts/coccinelle/reset-type.cocci -- 2.34.1