xref: /openbmc/qemu/include/hw/vfio/vfio-platform.h (revision f00f57f3)
10ea2730bSEric Auger /*
20ea2730bSEric Auger  * vfio based device assignment support - platform devices
30ea2730bSEric Auger  *
40ea2730bSEric Auger  * Copyright Linaro Limited, 2014
50ea2730bSEric Auger  *
60ea2730bSEric Auger  * Authors:
70ea2730bSEric Auger  *  Kim Phillips <kim.phillips@linaro.org>
80ea2730bSEric Auger  *
90ea2730bSEric Auger  * This work is licensed under the terms of the GNU GPL, version 2.  See
100ea2730bSEric Auger  * the COPYING file in the top-level directory.
110ea2730bSEric Auger  *
120ea2730bSEric Auger  * Based on vfio based PCI device assignment support:
130ea2730bSEric Auger  *  Copyright Red Hat, Inc. 2012
140ea2730bSEric Auger  */
150ea2730bSEric Auger 
160ea2730bSEric Auger #ifndef HW_VFIO_VFIO_PLATFORM_H
170ea2730bSEric Auger #define HW_VFIO_VFIO_PLATFORM_H
180ea2730bSEric Auger 
190ea2730bSEric Auger #include "hw/sysbus.h"
200ea2730bSEric Auger #include "hw/vfio/vfio-common.h"
2138559979SEric Auger #include "qemu/event_notifier.h"
2238559979SEric Auger #include "qemu/queue.h"
23db1015e9SEduardo Habkost #include "qom/object.h"
240ea2730bSEric Auger 
250ea2730bSEric Auger #define TYPE_VFIO_PLATFORM "vfio-platform"
260ea2730bSEric Auger 
2738559979SEric Auger enum {
2838559979SEric Auger     VFIO_IRQ_INACTIVE = 0,
2938559979SEric Auger     VFIO_IRQ_PENDING = 1,
3038559979SEric Auger     VFIO_IRQ_ACTIVE = 2,
3138559979SEric Auger     /* VFIO_IRQ_ACTIVE_AND_PENDING cannot happen with VFIO */
3238559979SEric Auger };
3338559979SEric Auger 
3438559979SEric Auger typedef struct VFIOINTp {
3538559979SEric Auger     QLIST_ENTRY(VFIOINTp) next; /* entry for IRQ list */
3638559979SEric Auger     QSIMPLEQ_ENTRY(VFIOINTp) pqnext; /* entry for pending IRQ queue */
37a22313deSEric Auger     EventNotifier *interrupt; /* eventfd triggered on interrupt */
38a22313deSEric Auger     EventNotifier *unmask; /* eventfd for unmask on QEMU bypass */
3938559979SEric Auger     qemu_irq qemuirq;
4038559979SEric Auger     struct VFIOPlatformDevice *vdev; /* back pointer to device */
4138559979SEric Auger     int state; /* inactive, pending, active */
4238559979SEric Auger     uint8_t pin; /* index */
4338559979SEric Auger     uint32_t flags; /* IRQ info flags */
44fb5f8164SEric Auger     bool kvm_accel; /* set when QEMU bypass through KVM enabled */
4538559979SEric Auger } VFIOINTp;
4638559979SEric Auger 
4738559979SEric Auger /* function type for user side eventfd handler */
4838559979SEric Auger typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
4938559979SEric Auger 
50db1015e9SEduardo Habkost struct VFIOPlatformDevice {
510ea2730bSEric Auger     SysBusDevice sbdev;
520ea2730bSEric Auger     VFIODevice vbasedev; /* not a QOM object */
530ea2730bSEric Auger     VFIORegion **regions;
5438559979SEric Auger     QLIST_HEAD(, VFIOINTp) intp_list; /* list of IRQs */
5538559979SEric Auger     /* queue of pending IRQs */
56b58deb34SPaolo Bonzini     QSIMPLEQ_HEAD(, VFIOINTp) pending_intp_queue;
57a49531ebSEric Auger     char *compat; /* DT compatible values, separated by NUL */
58a49531ebSEric Auger     unsigned int num_compat; /* number of compatible values */
5938559979SEric Auger     uint32_t mmap_timeout; /* delay to re-enable mmaps after interrupt */
6038559979SEric Auger     QEMUTimer *mmap_timer; /* allows fast-path resume after IRQ hit */
6138559979SEric Auger     QemuMutex intp_mutex; /* protect the intp_list IRQ state */
62fb5f8164SEric Auger     bool irqfd_allowed; /* debug option to force irqfd on/off */
63db1015e9SEduardo Habkost };
64db1015e9SEduardo Habkost typedef struct VFIOPlatformDevice VFIOPlatformDevice;
650ea2730bSEric Auger 
66db1015e9SEduardo Habkost struct VFIOPlatformDeviceClass {
670ea2730bSEric Auger     /*< private >*/
680ea2730bSEric Auger     SysBusDeviceClass parent_class;
690ea2730bSEric Auger     /*< public >*/
70db1015e9SEduardo Habkost };
71db1015e9SEduardo Habkost typedef struct VFIOPlatformDeviceClass VFIOPlatformDeviceClass;
720ea2730bSEric Auger 
73*8110fa1dSEduardo Habkost DECLARE_OBJ_CHECKERS(VFIOPlatformDevice, VFIOPlatformDeviceClass,
74*8110fa1dSEduardo Habkost                      VFIO_PLATFORM_DEVICE, TYPE_VFIO_PLATFORM)
750ea2730bSEric Auger 
760ea2730bSEric Auger #endif /* HW_VFIO_VFIO_PLATFORM_H */
77