xref: /openbmc/qemu/include/hw/vfio/vfio-platform.h (revision 38559979)
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"
21*38559979SEric Auger #include "qemu/event_notifier.h"
22*38559979SEric Auger #include "qemu/queue.h"
23*38559979SEric Auger #include "hw/irq.h"
240ea2730bSEric Auger 
250ea2730bSEric Auger #define TYPE_VFIO_PLATFORM "vfio-platform"
260ea2730bSEric Auger 
27*38559979SEric Auger enum {
28*38559979SEric Auger     VFIO_IRQ_INACTIVE = 0,
29*38559979SEric Auger     VFIO_IRQ_PENDING = 1,
30*38559979SEric Auger     VFIO_IRQ_ACTIVE = 2,
31*38559979SEric Auger     /* VFIO_IRQ_ACTIVE_AND_PENDING cannot happen with VFIO */
32*38559979SEric Auger };
33*38559979SEric Auger 
34*38559979SEric Auger typedef struct VFIOINTp {
35*38559979SEric Auger     QLIST_ENTRY(VFIOINTp) next; /* entry for IRQ list */
36*38559979SEric Auger     QSIMPLEQ_ENTRY(VFIOINTp) pqnext; /* entry for pending IRQ queue */
37*38559979SEric Auger     EventNotifier interrupt; /* eventfd triggered on interrupt */
38*38559979SEric Auger     EventNotifier unmask; /* eventfd for unmask on QEMU bypass */
39*38559979SEric Auger     qemu_irq qemuirq;
40*38559979SEric Auger     struct VFIOPlatformDevice *vdev; /* back pointer to device */
41*38559979SEric Auger     int state; /* inactive, pending, active */
42*38559979SEric Auger     uint8_t pin; /* index */
43*38559979SEric Auger     uint32_t flags; /* IRQ info flags */
44*38559979SEric Auger } VFIOINTp;
45*38559979SEric Auger 
46*38559979SEric Auger /* function type for user side eventfd handler */
47*38559979SEric Auger typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
48*38559979SEric Auger 
490ea2730bSEric Auger typedef struct VFIOPlatformDevice {
500ea2730bSEric Auger     SysBusDevice sbdev;
510ea2730bSEric Auger     VFIODevice vbasedev; /* not a QOM object */
520ea2730bSEric Auger     VFIORegion **regions;
53*38559979SEric Auger     QLIST_HEAD(, VFIOINTp) intp_list; /* list of IRQs */
54*38559979SEric Auger     /* queue of pending IRQs */
55*38559979SEric Auger     QSIMPLEQ_HEAD(pending_intp_queue, VFIOINTp) pending_intp_queue;
560ea2730bSEric Auger     char *compat; /* compatibility string */
57*38559979SEric Auger     uint32_t mmap_timeout; /* delay to re-enable mmaps after interrupt */
58*38559979SEric Auger     QEMUTimer *mmap_timer; /* allows fast-path resume after IRQ hit */
59*38559979SEric Auger     QemuMutex intp_mutex; /* protect the intp_list IRQ state */
600ea2730bSEric Auger } VFIOPlatformDevice;
610ea2730bSEric Auger 
620ea2730bSEric Auger typedef struct VFIOPlatformDeviceClass {
630ea2730bSEric Auger     /*< private >*/
640ea2730bSEric Auger     SysBusDeviceClass parent_class;
650ea2730bSEric Auger     /*< public >*/
660ea2730bSEric Auger } VFIOPlatformDeviceClass;
670ea2730bSEric Auger 
680ea2730bSEric Auger #define VFIO_PLATFORM_DEVICE(obj) \
690ea2730bSEric Auger      OBJECT_CHECK(VFIOPlatformDevice, (obj), TYPE_VFIO_PLATFORM)
700ea2730bSEric Auger #define VFIO_PLATFORM_DEVICE_CLASS(klass) \
710ea2730bSEric Auger      OBJECT_CLASS_CHECK(VFIOPlatformDeviceClass, (klass), TYPE_VFIO_PLATFORM)
720ea2730bSEric Auger #define VFIO_PLATFORM_DEVICE_GET_CLASS(obj) \
730ea2730bSEric Auger      OBJECT_GET_CLASS(VFIOPlatformDeviceClass, (obj), TYPE_VFIO_PLATFORM)
740ea2730bSEric Auger 
750ea2730bSEric Auger #endif /*HW_VFIO_VFIO_PLATFORM_H*/
76