mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 18:23:57 -06:00
libqos: Added indirect descriptor support to virtio implementation
Add functions necessary for working with indirect descriptors. Add test using new functions. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
bf3c63d201
commit
f294b029aa
4 changed files with 195 additions and 1 deletions
|
@ -107,6 +107,12 @@ static void qvirtio_pci_set_features(QVirtioDevice *d, uint32_t features)
|
|||
qpci_io_writel(dev->pdev, dev->addr + QVIRTIO_GUEST_FEATURES, features);
|
||||
}
|
||||
|
||||
static uint32_t qvirtio_pci_get_guest_features(QVirtioDevice *d)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
return qpci_io_readl(dev->pdev, dev->addr + QVIRTIO_GUEST_FEATURES);
|
||||
}
|
||||
|
||||
static uint8_t qvirtio_pci_get_status(QVirtioDevice *d)
|
||||
{
|
||||
QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;
|
||||
|
@ -146,10 +152,12 @@ static void qvirtio_pci_set_queue_address(QVirtioDevice *d, uint32_t pfn)
|
|||
static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
|
||||
QGuestAllocator *alloc, uint16_t index)
|
||||
{
|
||||
uint32_t feat;
|
||||
uint64_t addr;
|
||||
QVirtQueue *vq;
|
||||
|
||||
vq = g_malloc0(sizeof(*vq));
|
||||
feat = qvirtio_pci_get_guest_features(d);
|
||||
|
||||
qvirtio_pci_queue_select(d, index);
|
||||
vq->index = index;
|
||||
|
@ -157,6 +165,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
|
|||
vq->free_head = 0;
|
||||
vq->num_free = vq->size;
|
||||
vq->align = QVIRTIO_PCI_ALIGN;
|
||||
vq->indirect = (feat & QVIRTIO_F_RING_INDIRECT_DESC) != 0;
|
||||
|
||||
/* Check different than 0 */
|
||||
g_assert_cmpint(vq->size, !=, 0);
|
||||
|
@ -186,6 +195,7 @@ const QVirtioBus qvirtio_pci = {
|
|||
.config_readq = qvirtio_pci_config_readq,
|
||||
.get_features = qvirtio_pci_get_features,
|
||||
.set_features = qvirtio_pci_set_features,
|
||||
.get_guest_features = qvirtio_pci_get_guest_features,
|
||||
.get_status = qvirtio_pci_get_status,
|
||||
.set_status = qvirtio_pci_set_status,
|
||||
.get_isr_status = qvirtio_pci_get_isr_status,
|
||||
|
|
|
@ -116,6 +116,51 @@ void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)
|
|||
writew(vq->used, 0);
|
||||
}
|
||||
|
||||
QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
|
||||
QGuestAllocator *alloc, uint16_t elem)
|
||||
{
|
||||
int i;
|
||||
QVRingIndirectDesc *indirect = g_malloc(sizeof(*indirect));
|
||||
|
||||
indirect->index = 0;
|
||||
indirect->elem = elem;
|
||||
indirect->desc = guest_alloc(alloc, sizeof(QVRingDesc)*elem);
|
||||
|
||||
for (i = 0; i < elem - 1; ++i) {
|
||||
/* indirect->desc[i].addr */
|
||||
writeq(indirect->desc + (16 * i), 0);
|
||||
/* indirect->desc[i].flags */
|
||||
writew(indirect->desc + (16 * i) + 12, QVRING_DESC_F_NEXT);
|
||||
/* indirect->desc[i].next */
|
||||
writew(indirect->desc + (16 * i) + 14, i + 1);
|
||||
}
|
||||
|
||||
return indirect;
|
||||
}
|
||||
|
||||
void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
|
||||
uint32_t len, bool write)
|
||||
{
|
||||
uint16_t flags;
|
||||
|
||||
g_assert_cmpint(indirect->index, <, indirect->elem);
|
||||
|
||||
flags = readw(indirect->desc + (16 * indirect->index) + 12);
|
||||
|
||||
if (write) {
|
||||
flags |= QVRING_DESC_F_WRITE;
|
||||
}
|
||||
|
||||
/* indirect->desc[indirect->index].addr */
|
||||
writeq(indirect->desc + (16 * indirect->index), data);
|
||||
/* indirect->desc[indirect->index].len */
|
||||
writel(indirect->desc + (16 * indirect->index) + 8, len);
|
||||
/* indirect->desc[indirect->index].flags */
|
||||
writew(indirect->desc + (16 * indirect->index) + 12, flags);
|
||||
|
||||
indirect->index++;
|
||||
}
|
||||
|
||||
uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
|
||||
bool next)
|
||||
{
|
||||
|
@ -140,6 +185,25 @@ uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
|
|||
return vq->free_head++; /* Return and increase, in this order */
|
||||
}
|
||||
|
||||
uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect)
|
||||
{
|
||||
g_assert(vq->indirect);
|
||||
g_assert_cmpint(vq->size, >=, indirect->elem);
|
||||
g_assert_cmpint(indirect->index, ==, indirect->elem);
|
||||
|
||||
vq->num_free--;
|
||||
|
||||
/* vq->desc[vq->free_head].addr */
|
||||
writeq(vq->desc + (16 * vq->free_head), indirect->desc);
|
||||
/* vq->desc[vq->free_head].len */
|
||||
writel(vq->desc + (16 * vq->free_head) + 8,
|
||||
sizeof(QVRingDesc) * indirect->elem);
|
||||
/* vq->desc[vq->free_head].flags */
|
||||
writew(vq->desc + (16 * vq->free_head) + 12, QVRING_DESC_F_INDIRECT);
|
||||
|
||||
return vq->free_head++; /* Return and increase, in this order */
|
||||
}
|
||||
|
||||
void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
|
||||
uint32_t free_head)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#define QVIRTIO_NET_DEVICE_ID 0x1
|
||||
#define QVIRTIO_BLK_DEVICE_ID 0x2
|
||||
|
||||
#define QVIRTIO_F_NOTIFY_ON_EMPTY 0x01000000
|
||||
#define QVIRTIO_F_ANY_LAYOUT 0x08000000
|
||||
#define QVIRTIO_F_RING_INDIRECT_DESC 0x10000000
|
||||
#define QVIRTIO_F_RING_EVENT_IDX 0x20000000
|
||||
|
||||
#define QVRING_DESC_F_NEXT 0x1
|
||||
#define QVRING_DESC_F_WRITE 0x2
|
||||
#define QVRING_DESC_F_INDIRECT 0x4
|
||||
|
@ -74,8 +79,15 @@ typedef struct QVirtQueue {
|
|||
uint32_t free_head;
|
||||
uint32_t num_free;
|
||||
uint32_t align;
|
||||
bool indirect;
|
||||
} QVirtQueue;
|
||||
|
||||
typedef struct QVRingIndirectDesc {
|
||||
uint64_t desc; /* This points to an array fo QVRingDesc */
|
||||
uint16_t index;
|
||||
uint16_t elem;
|
||||
} QVRingIndirectDesc;
|
||||
|
||||
typedef struct QVirtioBus {
|
||||
uint8_t (*config_readb)(QVirtioDevice *d, void *addr);
|
||||
uint16_t (*config_readw)(QVirtioDevice *d, void *addr);
|
||||
|
@ -85,9 +97,12 @@ typedef struct QVirtioBus {
|
|||
/* Get features of the device */
|
||||
uint32_t (*get_features)(QVirtioDevice *d);
|
||||
|
||||
/* Get features of the device */
|
||||
/* Set features of the device */
|
||||
void (*set_features)(QVirtioDevice *d, uint32_t features);
|
||||
|
||||
/* Get features of the guest */
|
||||
uint32_t (*get_guest_features)(QVirtioDevice *d);
|
||||
|
||||
/* Get status of the device */
|
||||
uint8_t (*get_status)(QVirtioDevice *d);
|
||||
|
||||
|
@ -144,8 +159,13 @@ QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
|
|||
QGuestAllocator *alloc, uint16_t index);
|
||||
|
||||
void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr);
|
||||
QVRingIndirectDesc *qvring_indirect_desc_setup(QVirtioDevice *d,
|
||||
QGuestAllocator *alloc, uint16_t elem);
|
||||
void qvring_indirect_desc_add(QVRingIndirectDesc *indirect, uint64_t data,
|
||||
uint32_t len, bool write);
|
||||
uint32_t qvirtqueue_add(QVirtQueue *vq, uint64_t data, uint32_t len, bool write,
|
||||
bool next);
|
||||
uint32_t qvirtqueue_add_indirect(QVirtQueue *vq, QVRingIndirectDesc *indirect);
|
||||
void qvirtqueue_kick(const QVirtioBus *bus, QVirtioDevice *d, QVirtQueue *vq,
|
||||
uint32_t free_head);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue