@@ -378,6 +378,43 @@ struct virtio_vq_info;
378
378
#define VIRTIO_EVENT_IDX 0x02 /* use the event-index values */
379
379
#define VIRTIO_BROKED 0x08 /* ??? */
380
380
381
+ /*
382
+ * virtio pci device bar layout
383
+ * 0 : legacy PIO bar
384
+ * 1 : MSIX bar
385
+ * 2 : modern PIO bar, used as notify
386
+ * 4+5 : modern 64-bit MMIO bar
387
+ *
388
+ * pci bar layout for legacy/modern/transitional devices
389
+ * legacy : (0) + (1)
390
+ * modern (no pio notify) : (1) + (4+5)
391
+ * modern (with pio notify) : (1) + (2) + (4+5)
392
+ * transitional (no pio notify) : (0) + (1) + (4+5)
393
+ * transitional (with pio notify) : (0) + (1) + (2) + (4+5)
394
+ */
395
+ #define VIRTIO_LEGACY_PIO_BAR_IDX 0
396
+ #define VIRTIO_MODERN_PIO_BAR_IDX 2
397
+ #define VIRTIO_MODERN_MMIO_BAR_IDX 4
398
+
399
+ /*
400
+ * region layout in modern mmio bar
401
+ * one 4KB region for one capability
402
+ */
403
+ #define VIRTIO_CAP_COMMON_OFFSET 0x0000
404
+ #define VIRTIO_CAP_COMMON_SIZE 0x1000
405
+ #define VIRTIO_CAP_ISR_OFFSET 0x1000
406
+ #define VIRTIO_CAP_ISR_SIZE 0x1000
407
+ #define VIRTIO_CAP_DEVICE_OFFSET 0x2000
408
+ #define VIRTIO_CAP_DEVICE_SIZE 0x1000
409
+ #define VIRTIO_CAP_NOTIFY_OFFSET 0x3000
410
+ #define VIRTIO_CAP_NOTIFY_SIZE 0x1000
411
+
412
+ #define VIRTIO_MODERN_MEM_BAR_SIZE (VIRTIO_CAP_NOTIFY_OFFSET + \
413
+ VIRTIO_CAP_NOTIFY_SIZE)
414
+
415
+ /* 4-byte notify register for one virtqueue */
416
+ #define VIRTIO_MODERN_NOTIFY_OFF_MULT 4
417
+
381
418
/* Common configuration */
382
419
#define VIRTIO_PCI_CAP_COMMON_CFG 1
383
420
/* Notifications */
@@ -467,12 +504,18 @@ struct virtio_base {
467
504
int flags ; /**< VIRTIO_* flags from above */
468
505
pthread_mutex_t * mtx ; /**< POSIX mutex, if any */
469
506
struct pci_vdev * dev ; /**< PCI device instance */
470
- uint32_t negotiated_caps ; /**< negotiated capabilities */
507
+ uint64_t negotiated_caps ; /**< negotiated capabilities */
471
508
struct virtio_vq_info * queues ; /**< one per nvq */
472
509
int curq ; /**< current queue */
473
510
uint8_t status ; /**< value from last status write */
474
511
uint8_t isr ; /**< ISR flags, if not MSI-X */
475
512
uint16_t msix_cfg_idx ; /**< MSI-X vector for config event */
513
+ uint32_t legacy_pio_bar_idx ; /**< index of legacy pio bar */
514
+ uint32_t modern_pio_bar_idx ; /**< index of modern pio bar */
515
+ uint32_t modern_mmio_bar_idx ; /**< index of modern mmio bar */
516
+ uint8_t config_generation ; /**< configuration generation */
517
+ uint32_t device_feature_select ; /**< current selected device feature */
518
+ uint32_t driver_feature_select ; /**< current selected guest feature */
476
519
};
477
520
478
521
#define VIRTIO_BASE_LOCK (vb ) \
@@ -553,6 +596,10 @@ struct virtio_vq_info {
553
596
volatile struct vring_used * used ;
554
597
/**< the "used" ring */
555
598
599
+ uint32_t gpa_desc [2 ]; /**< gpa of descriptors */
600
+ uint32_t gpa_avail [2 ]; /**< gpa of avail_ring */
601
+ uint32_t gpa_used [2 ]; /**< gpa of used_ring */
602
+ bool enabled ; /**< whether the virtqueue is enabled */
556
603
};
557
604
558
605
/* as noted above, these are sort of backwards, name-wise */
0 commit comments