11dc324d2SMichael S. Tsirkin #ifndef SHPC_H 21dc324d2SMichael S. Tsirkin #define SHPC_H 31dc324d2SMichael S. Tsirkin 41dc324d2SMichael S. Tsirkin #include "qemu-common.h" 5022c62cbSPaolo Bonzini #include "exec/memory.h" 6caf71f86SPaolo Bonzini #include "migration/vmstate.h" 75d268704SIgor Mammedov #include "qapi/error.h" 85d268704SIgor Mammedov #include "hw/hotplug.h" 9*23ab143dSLaszlo Ersek #include "hw/pci/pci.h" 101dc324d2SMichael S. Tsirkin 111dc324d2SMichael S. Tsirkin struct SHPCDevice { 121dc324d2SMichael S. Tsirkin /* Capability offset in device's config space */ 131dc324d2SMichael S. Tsirkin int cap; 141dc324d2SMichael S. Tsirkin 151dc324d2SMichael S. Tsirkin /* # of hot-pluggable slots */ 161dc324d2SMichael S. Tsirkin int nslots; 171dc324d2SMichael S. Tsirkin 181dc324d2SMichael S. Tsirkin /* SHPC WRS: working register set */ 191dc324d2SMichael S. Tsirkin uint8_t *config; 201dc324d2SMichael S. Tsirkin 211dc324d2SMichael S. Tsirkin /* Used to enable checks on load. Note that writable bits are 221dc324d2SMichael S. Tsirkin * never checked even if set in cmask. */ 231dc324d2SMichael S. Tsirkin uint8_t *cmask; 241dc324d2SMichael S. Tsirkin 251dc324d2SMichael S. Tsirkin /* Used to implement R/W bytes */ 261dc324d2SMichael S. Tsirkin uint8_t *wmask; 271dc324d2SMichael S. Tsirkin 281dc324d2SMichael S. Tsirkin /* Used to implement RW1C(Write 1 to Clear) bytes */ 291dc324d2SMichael S. Tsirkin uint8_t *w1cmask; 301dc324d2SMichael S. Tsirkin 311dc324d2SMichael S. Tsirkin /* MMIO for the SHPC BAR */ 321dc324d2SMichael S. Tsirkin MemoryRegion mmio; 331dc324d2SMichael S. Tsirkin 341dc324d2SMichael S. Tsirkin /* Bus controlled by this SHPC */ 351dc324d2SMichael S. Tsirkin PCIBus *sec_bus; 361dc324d2SMichael S. Tsirkin 371dc324d2SMichael S. Tsirkin /* MSI already requested for this event */ 381dc324d2SMichael S. Tsirkin int msi_requested; 391dc324d2SMichael S. Tsirkin }; 401dc324d2SMichael S. Tsirkin 411dc324d2SMichael S. Tsirkin void shpc_reset(PCIDevice *d); 421dc324d2SMichael S. Tsirkin int shpc_bar_size(PCIDevice *dev); 431dc324d2SMichael S. Tsirkin int shpc_init(PCIDevice *dev, PCIBus *sec_bus, MemoryRegion *bar, unsigned off); 441dc324d2SMichael S. Tsirkin void shpc_cleanup(PCIDevice *dev, MemoryRegion *bar); 455cd5e701SPaolo Bonzini void shpc_free(PCIDevice *dev); 461dc324d2SMichael S. Tsirkin void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len); 471dc324d2SMichael S. Tsirkin 485d268704SIgor Mammedov 495d268704SIgor Mammedov void shpc_device_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, 505d268704SIgor Mammedov Error **errp); 5114d5a28fSIgor Mammedov void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, 5214d5a28fSIgor Mammedov DeviceState *dev, Error **errp); 535d268704SIgor Mammedov 541dc324d2SMichael S. Tsirkin extern VMStateInfo shpc_vmstate_info; 550034e562SLaszlo Ersek #define SHPC_VMSTATE(_field, _type, _test) \ 560034e562SLaszlo Ersek VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _type, _test, 0, \ 570034e562SLaszlo Ersek shpc_vmstate_info, 0) 581dc324d2SMichael S. Tsirkin 59*23ab143dSLaszlo Ersek static inline bool shpc_present(const PCIDevice *dev) 60*23ab143dSLaszlo Ersek { 61*23ab143dSLaszlo Ersek return dev->cap_present & QEMU_PCI_CAP_SHPC; 62*23ab143dSLaszlo Ersek } 63*23ab143dSLaszlo Ersek 641dc324d2SMichael S. Tsirkin #endif 65