xref: /qemu/include/hw/pci/shpc.h (revision fc524567087c2537b5103cdfc1d41e4f442892b6)
11dc324d2SMichael S. Tsirkin #ifndef SHPC_H
21dc324d2SMichael S. Tsirkin #define SHPC_H
31dc324d2SMichael S. Tsirkin 
4*8be545baSRichard Henderson #include "system/memory.h"
55d268704SIgor Mammedov #include "hw/hotplug.h"
6edf5ca5dSMarkus Armbruster #include "hw/pci/pci_device.h"
7d6454270SMarkus Armbruster #include "migration/vmstate.h"
81dc324d2SMichael S. Tsirkin 
91dc324d2SMichael S. Tsirkin struct SHPCDevice {
101dc324d2SMichael S. Tsirkin     /* Capability offset in device's config space */
111dc324d2SMichael S. Tsirkin     int cap;
121dc324d2SMichael S. Tsirkin 
131dc324d2SMichael S. Tsirkin     /* # of hot-pluggable slots */
141dc324d2SMichael S. Tsirkin     int nslots;
151dc324d2SMichael S. Tsirkin 
161dc324d2SMichael S. Tsirkin     /* SHPC WRS: working register set */
171dc324d2SMichael S. Tsirkin     uint8_t *config;
181dc324d2SMichael S. Tsirkin 
191dc324d2SMichael S. Tsirkin     /* Used to enable checks on load. Note that writable bits are
201dc324d2SMichael S. Tsirkin      * never checked even if set in cmask. */
211dc324d2SMichael S. Tsirkin     uint8_t *cmask;
221dc324d2SMichael S. Tsirkin 
231dc324d2SMichael S. Tsirkin     /* Used to implement R/W bytes */
241dc324d2SMichael S. Tsirkin     uint8_t *wmask;
251dc324d2SMichael S. Tsirkin 
261dc324d2SMichael S. Tsirkin     /* Used to implement RW1C(Write 1 to Clear) bytes */
271dc324d2SMichael S. Tsirkin     uint8_t *w1cmask;
281dc324d2SMichael S. Tsirkin 
291dc324d2SMichael S. Tsirkin     /* MMIO for the SHPC BAR */
301dc324d2SMichael S. Tsirkin     MemoryRegion mmio;
311dc324d2SMichael S. Tsirkin 
321dc324d2SMichael S. Tsirkin     /* Bus controlled by this SHPC */
331dc324d2SMichael S. Tsirkin     PCIBus *sec_bus;
341dc324d2SMichael S. Tsirkin 
351dc324d2SMichael S. Tsirkin     /* MSI already requested for this event */
361dc324d2SMichael S. Tsirkin     int msi_requested;
371dc324d2SMichael S. Tsirkin };
381dc324d2SMichael S. Tsirkin 
391dc324d2SMichael S. Tsirkin void shpc_reset(PCIDevice *d);
401dc324d2SMichael S. Tsirkin int shpc_bar_size(PCIDevice *dev);
41344475e7SMao Zhongyi int shpc_init(PCIDevice *dev, PCIBus *sec_bus, MemoryRegion *bar,
42344475e7SMao Zhongyi               unsigned off, Error **errp);
431dc324d2SMichael S. Tsirkin void shpc_cleanup(PCIDevice *dev, MemoryRegion *bar);
445cd5e701SPaolo Bonzini void shpc_free(PCIDevice *dev);
451dc324d2SMichael S. Tsirkin void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int len);
461dc324d2SMichael S. Tsirkin 
475d268704SIgor Mammedov 
48851fedfbSDavid Hildenbrand void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
495d268704SIgor Mammedov                          Error **errp);
508f560cdcSDavid Hildenbrand void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
518f560cdcSDavid Hildenbrand                            Error **errp);
52851fedfbSDavid Hildenbrand void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
5314d5a28fSIgor Mammedov                                    DeviceState *dev, Error **errp);
545d268704SIgor Mammedov 
558e5e0890SRichard Henderson extern const VMStateInfo shpc_vmstate_info;
560034e562SLaszlo Ersek #define SHPC_VMSTATE(_field, _type,  _test) \
570034e562SLaszlo Ersek     VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _type, _test, 0, \
580034e562SLaszlo Ersek                                     shpc_vmstate_info, 0)
591dc324d2SMichael S. Tsirkin 
shpc_present(const PCIDevice * dev)6023ab143dSLaszlo Ersek static inline bool shpc_present(const PCIDevice *dev)
6123ab143dSLaszlo Ersek {
6223ab143dSLaszlo Ersek     return dev->cap_present & QEMU_PCI_CAP_SHPC;
6323ab143dSLaszlo Ersek }
6423ab143dSLaszlo Ersek 
651dc324d2SMichael S. Tsirkin #endif
66