xref: /openbmc/qemu/tests/qtest/libqos/virtio-pci.h (revision 8e49197c)
11cf4323eSThomas Huth /*
21cf4323eSThomas Huth  * libqos virtio PCI definitions
31cf4323eSThomas Huth  *
41cf4323eSThomas Huth  * Copyright (c) 2014 Marc Marí
51cf4323eSThomas Huth  *
61cf4323eSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
71cf4323eSThomas Huth  * See the COPYING file in the top-level directory.
81cf4323eSThomas Huth  */
91cf4323eSThomas Huth 
101cf4323eSThomas Huth #ifndef LIBQOS_VIRTIO_PCI_H
111cf4323eSThomas Huth #define LIBQOS_VIRTIO_PCI_H
121cf4323eSThomas Huth 
13*a2ce7dbdSPaolo Bonzini #include "virtio.h"
14*a2ce7dbdSPaolo Bonzini #include "pci.h"
15*a2ce7dbdSPaolo Bonzini #include "qgraph.h"
161cf4323eSThomas Huth 
171cf4323eSThomas Huth typedef struct QVirtioPCIMSIXOps QVirtioPCIMSIXOps;
181cf4323eSThomas Huth 
191cf4323eSThomas Huth typedef struct QVirtioPCIDevice {
201cf4323eSThomas Huth     QOSGraphObject obj;
211cf4323eSThomas Huth     QVirtioDevice vdev;
221cf4323eSThomas Huth     QPCIDevice *pdev;
231cf4323eSThomas Huth     QPCIBar bar;
241cf4323eSThomas Huth     const QVirtioPCIMSIXOps *msix_ops;
251cf4323eSThomas Huth     uint16_t config_msix_entry;
261cf4323eSThomas Huth     uint64_t config_msix_addr;
271cf4323eSThomas Huth     uint32_t config_msix_data;
281cf4323eSThomas Huth 
291cf4323eSThomas Huth     int bar_idx;
301cf4323eSThomas Huth 
311cf4323eSThomas Huth     /* VIRTIO 1.0 */
321cf4323eSThomas Huth     uint32_t common_cfg_offset;
331cf4323eSThomas Huth     uint32_t notify_cfg_offset;
341cf4323eSThomas Huth     uint32_t notify_off_multiplier;
351cf4323eSThomas Huth     uint32_t isr_cfg_offset;
361cf4323eSThomas Huth     uint32_t device_cfg_offset;
371cf4323eSThomas Huth } QVirtioPCIDevice;
381cf4323eSThomas Huth 
391cf4323eSThomas Huth struct QVirtioPCIMSIXOps {
401cf4323eSThomas Huth     /* Set the Configuration Vector for MSI-X */
411cf4323eSThomas Huth     void (*set_config_vector)(QVirtioPCIDevice *d, uint16_t entry);
421cf4323eSThomas Huth 
431cf4323eSThomas Huth     /* Set the Queue Vector for MSI-X */
441cf4323eSThomas Huth     void (*set_queue_vector)(QVirtioPCIDevice *d, uint16_t vq_idx,
451cf4323eSThomas Huth                              uint16_t entry);
461cf4323eSThomas Huth };
471cf4323eSThomas Huth 
481cf4323eSThomas Huth typedef struct QVirtQueuePCI {
491cf4323eSThomas Huth     QVirtQueue vq;
501cf4323eSThomas Huth     uint16_t msix_entry;
511cf4323eSThomas Huth     uint64_t msix_addr;
521cf4323eSThomas Huth     uint32_t msix_data;
531cf4323eSThomas Huth 
541cf4323eSThomas Huth     /* VIRTIO 1.0 */
551cf4323eSThomas Huth     uint64_t notify_offset;
561cf4323eSThomas Huth } QVirtQueuePCI;
571cf4323eSThomas Huth 
581cf4323eSThomas Huth void virtio_pci_init(QVirtioPCIDevice *dev, QPCIBus *bus, QPCIAddress * addr);
591cf4323eSThomas Huth QVirtioPCIDevice *virtio_pci_new(QPCIBus *bus, QPCIAddress * addr);
601cf4323eSThomas Huth 
611cf4323eSThomas Huth /* virtio-pci object functions available for subclasses that
621cf4323eSThomas Huth  * override the original start_hw and destroy
631cf4323eSThomas Huth  * function. All virtio-xxx-pci subclass that override must
641cf4323eSThomas Huth  * take care of calling these two functions in the respective
651cf4323eSThomas Huth  * places
661cf4323eSThomas Huth  */
671cf4323eSThomas Huth void qvirtio_pci_destructor(QOSGraphObject *obj);
681cf4323eSThomas Huth void qvirtio_pci_start_hw(QOSGraphObject *obj);
691cf4323eSThomas Huth 
701cf4323eSThomas Huth 
711cf4323eSThomas Huth void qvirtio_pci_device_enable(QVirtioPCIDevice *d);
721cf4323eSThomas Huth void qvirtio_pci_device_disable(QVirtioPCIDevice *d);
731cf4323eSThomas Huth 
741cf4323eSThomas Huth void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,
751cf4323eSThomas Huth                                         QGuestAllocator *alloc, uint16_t entry);
761cf4323eSThomas Huth void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci,
771cf4323eSThomas Huth                                         QGuestAllocator *alloc, uint16_t entry);
781cf4323eSThomas Huth 
791cf4323eSThomas Huth /* Used by Legacy and Modern virtio-pci code */
801cf4323eSThomas Huth QVirtQueue *qvirtio_pci_virtqueue_setup_common(QVirtioDevice *d,
811cf4323eSThomas Huth                                                QGuestAllocator *alloc,
821cf4323eSThomas Huth                                                uint16_t index);
831cf4323eSThomas Huth void qvirtio_pci_virtqueue_cleanup_common(QVirtQueue *vq,
841cf4323eSThomas Huth                                           QGuestAllocator *alloc);
851cf4323eSThomas Huth 
861cf4323eSThomas Huth #endif
87