xref: /kvmtool/include/kvm/virtio-pci.h (revision eb34a8c274ba8c4e42f35252c80b57723c35e2ad)
136f5dc91SSasha Levin #ifndef KVM__VIRTIO_PCI_H
236f5dc91SSasha Levin #define KVM__VIRTIO_PCI_H
336f5dc91SSasha Levin 
421ff329dSWill Deacon #include "kvm/devices.h"
536f5dc91SSasha Levin #include "kvm/pci.h"
636f5dc91SSasha Levin 
736f5dc91SSasha Levin #include <linux/types.h>
836f5dc91SSasha Levin 
945d3b59eSSasha Levin #define VIRTIO_PCI_MAX_VQ	32
1014bba8a0SAsias He #define VIRTIO_PCI_MAX_CONFIG	1
1136f5dc91SSasha Levin 
1236f5dc91SSasha Levin struct kvm;
1336f5dc91SSasha Levin 
141599d724SSasha Levin struct virtio_pci_ioevent_param {
1502eca50cSAsias He 	struct virtio_device	*vdev;
161599d724SSasha Levin 	u32			vq;
171599d724SSasha Levin };
181599d724SSasha Levin 
1943c81c74SSasha Levin #define VIRTIO_PCI_F_SIGNAL_MSI (1 << 0)
2043c81c74SSasha Levin 
2136f5dc91SSasha Levin struct virtio_pci {
2236f5dc91SSasha Levin 	struct pci_device_header pci_hdr;
2321ff329dSWill Deacon 	struct device_header	dev_hdr;
2436f5dc91SSasha Levin 	void			*dev;
25a463650cSWill Deacon 	struct kvm		*kvm;
2636f5dc91SSasha Levin 
27a463650cSWill Deacon 	u16			port_addr;
28a463650cSWill Deacon 	u32			mmio_addr;
2936f5dc91SSasha Levin 	u8			status;
3036f5dc91SSasha Levin 	u8			isr;
3143c81c74SSasha Levin 	u32			features;
3236f5dc91SSasha Levin 
33e9922aafSAndre Przywara 	/*
34e9922aafSAndre Przywara 	 * We cannot rely on the INTERRUPT_LINE byte in the config space once
35e9922aafSAndre Przywara 	 * we have run guest code, as the OS is allowed to use that field
36e9922aafSAndre Przywara 	 * as a scratch pad to communicate between driver and PCI layer.
37e9922aafSAndre Przywara 	 * So store our legacy interrupt line number in here for internal use.
38e9922aafSAndre Przywara 	 */
39e9922aafSAndre Przywara 	u8			legacy_irq_line;
40e9922aafSAndre Przywara 
4136f5dc91SSasha Levin 	/* MSI-X */
4236f5dc91SSasha Levin 	u16			config_vector;
4336f5dc91SSasha Levin 	u32			config_gsi;
4436f5dc91SSasha Levin 	u32			vq_vector[VIRTIO_PCI_MAX_VQ];
4536f5dc91SSasha Levin 	u32			gsis[VIRTIO_PCI_MAX_VQ];
4636f5dc91SSasha Levin 	u32			msix_io_block;
4706f48103SSasha Levin 	u64			msix_pba;
4814bba8a0SAsias He 	struct msix_table	msix_table[VIRTIO_PCI_MAX_VQ + VIRTIO_PCI_MAX_CONFIG];
4936f5dc91SSasha Levin 
5036f5dc91SSasha Levin 	/* virtio queue */
5136f5dc91SSasha Levin 	u16			queue_selector;
521599d724SSasha Levin 	struct virtio_pci_ioevent_param ioeventfds[VIRTIO_PCI_MAX_VQ];
5336f5dc91SSasha Levin };
5436f5dc91SSasha Levin 
5502eca50cSAsias He int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq);
5602eca50cSAsias He int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev);
5702eca50cSAsias He int virtio_pci__exit(struct kvm *kvm, struct virtio_device *vdev);
58*eb34a8c2SJean-Philippe Brucker int virtio_pci__reset(struct kvm *kvm, struct virtio_device *vdev);
5902eca50cSAsias He int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
60507e02d8SAsias He 		     int device_id, int subsys_id, int class);
6136f5dc91SSasha Levin 
6236f5dc91SSasha Levin #endif
63