Skip to content

Commit 9c2378f

Browse files
chejianjjren1
authored andcommitted
dm/VBS-U: expand data structures to support virtio 1.0
Struct virtio_base and struct virtio_vq_info are expanded to support virtio 1.0 framework. The BAR layouts of virtio legacy/transitional/ modern are introduced as well. Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com> Reviewed-by: Hao Li <hao.l.li@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 5e613ef commit 9c2378f

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

devicemodel/hw/pci/virtio/virtio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ virtio_reset_dev(struct virtio_base *base)
9696
vq->save_used = 0;
9797
vq->pfn = 0;
9898
vq->msix_idx = VIRTIO_MSI_NO_VECTOR;
99+
vq->gpa_desc[0] = 0;
100+
vq->gpa_desc[1] = 0;
101+
vq->gpa_avail[0] = 0;
102+
vq->gpa_avail[1] = 0;
103+
vq->gpa_used[0] = 0;
104+
vq->gpa_used[1] = 0;
105+
vq->enabled = 0;
99106
}
100107
base->negotiated_caps = 0;
101108
base->curq = 0;
@@ -104,6 +111,9 @@ virtio_reset_dev(struct virtio_base *base)
104111
pci_lintr_deassert(base->dev);
105112
base->isr = 0;
106113
base->msix_cfg_idx = VIRTIO_MSI_NO_VECTOR;
114+
base->device_feature_select = 0;
115+
base->driver_feature_select = 0;
116+
base->config_generation = 0;
107117
}
108118

109119
/*

devicemodel/include/virtio.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,43 @@ struct virtio_vq_info;
378378
#define VIRTIO_EVENT_IDX 0x02 /* use the event-index values */
379379
#define VIRTIO_BROKED 0x08 /* ??? */
380380

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+
381418
/* Common configuration */
382419
#define VIRTIO_PCI_CAP_COMMON_CFG 1
383420
/* Notifications */
@@ -467,12 +504,18 @@ struct virtio_base {
467504
int flags; /**< VIRTIO_* flags from above */
468505
pthread_mutex_t *mtx; /**< POSIX mutex, if any */
469506
struct pci_vdev *dev; /**< PCI device instance */
470-
uint32_t negotiated_caps; /**< negotiated capabilities */
507+
uint64_t negotiated_caps; /**< negotiated capabilities */
471508
struct virtio_vq_info *queues; /**< one per nvq */
472509
int curq; /**< current queue */
473510
uint8_t status; /**< value from last status write */
474511
uint8_t isr; /**< ISR flags, if not MSI-X */
475512
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 */
476519
};
477520

478521
#define VIRTIO_BASE_LOCK(vb) \
@@ -553,6 +596,10 @@ struct virtio_vq_info {
553596
volatile struct vring_used *used;
554597
/**< the "used" ring */
555598

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 */
556603
};
557604

558605
/* as noted above, these are sort of backwards, name-wise */

0 commit comments

Comments
 (0)