summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorStefan Fritsch <sf@cvs.openbsd.org>2019-03-24 18:17:25 +0000
committerStefan Fritsch <sf@cvs.openbsd.org>2019-03-24 18:17:25 +0000
commitc372793d0df7d5ba3134e978e10ef5eb40f81925 (patch)
treed8bb31c3da1db9a228da1454c0191ed9230ff30e /sys/dev
parentf477606d599d447fc34dc9aa847f6cb9944e7d2b (diff)
virtio: adjust virtio_setup_queue prototype for 1.0
Make it take an address instead of a PFN. Pass the virtqueue pointer. In virtio 1.0, more information has to be configured in the device. Also call virtio_setup_queue() after the information has been filled in. ok mlarkin@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/fdt/virtio_mmio.c13
-rw-r--r--sys/dev/pci/virtio_pci.c13
-rw-r--r--sys/dev/pv/virtio.c13
-rw-r--r--sys/dev/pv/virtiovar.h4
4 files changed, 22 insertions, 21 deletions
diff --git a/sys/dev/fdt/virtio_mmio.c b/sys/dev/fdt/virtio_mmio.c
index 847519c3280..e72138e480b 100644
--- a/sys/dev/fdt/virtio_mmio.c
+++ b/sys/dev/fdt/virtio_mmio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtio_mmio.c,v 1.5 2019/01/19 16:23:46 sf Exp $ */
+/* $OpenBSD: virtio_mmio.c,v 1.6 2019/03/24 18:17:24 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@@ -89,7 +89,7 @@ void virtio_mmio_write_device_config_2(struct virtio_softc *, int, uint16_t);
void virtio_mmio_write_device_config_4(struct virtio_softc *, int, uint32_t);
void virtio_mmio_write_device_config_8(struct virtio_softc *, int, uint64_t);
uint16_t virtio_mmio_read_queue_size(struct virtio_softc *, uint16_t);
-void virtio_mmio_setup_queue(struct virtio_softc *, uint16_t, uint32_t);
+void virtio_mmio_setup_queue(struct virtio_softc *, struct virtqueue *, uint64_t);
void virtio_mmio_set_status(struct virtio_softc *, int);
uint32_t virtio_mmio_negotiate_features(struct virtio_softc *, uint32_t,
const struct virtio_feature_name *);
@@ -151,15 +151,18 @@ virtio_mmio_read_queue_size(struct virtio_softc *vsc, uint16_t idx)
}
void
-virtio_mmio_setup_queue(struct virtio_softc *vsc, uint16_t idx, uint32_t addr)
+virtio_mmio_setup_queue(struct virtio_softc *vsc, struct virtqueue *vq,
+ uint64_t addr)
{
struct virtio_mmio_softc *sc = (struct virtio_mmio_softc *)vsc;
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_SEL, idx);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_SEL,
+ vq->vq_index);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_NUM,
bus_space_read_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_NUM_MAX));
bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_ALIGN,
PAGE_SIZE);
- bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_PFN, addr);
+ bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_MMIO_QUEUE_PFN,
+ addr / VIRTIO_PAGE_SIZE);
}
void
diff --git a/sys/dev/pci/virtio_pci.c b/sys/dev/pci/virtio_pci.c
index 06d3a5ca23e..b16b7ff1efd 100644
--- a/sys/dev/pci/virtio_pci.c
+++ b/sys/dev/pci/virtio_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtio_pci.c,v 1.21 2019/01/19 16:23:46 sf Exp $ */
+/* $OpenBSD: virtio_pci.c,v 1.22 2019/03/24 18:17:24 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@@ -64,7 +64,7 @@ void virtio_pci_write_device_config_2(struct virtio_softc *, int, uint16_t);
void virtio_pci_write_device_config_4(struct virtio_softc *, int, uint32_t);
void virtio_pci_write_device_config_8(struct virtio_softc *, int, uint64_t);
uint16_t virtio_pci_read_queue_size(struct virtio_softc *, uint16_t);
-void virtio_pci_setup_queue(struct virtio_softc *, uint16_t, uint32_t);
+void virtio_pci_setup_queue(struct virtio_softc *, struct virtqueue *, uint64_t);
void virtio_pci_set_status(struct virtio_softc *, int);
uint32_t virtio_pci_negotiate_features(struct virtio_softc *, uint32_t,
const struct virtio_feature_name *);
@@ -134,13 +134,14 @@ virtio_pci_read_queue_size(struct virtio_softc *vsc, uint16_t idx)
}
void
-virtio_pci_setup_queue(struct virtio_softc *vsc, uint16_t idx, uint32_t addr)
+virtio_pci_setup_queue(struct virtio_softc *vsc, struct virtqueue *vq,
+ uint64_t addr)
{
struct virtio_pci_softc *sc = (struct virtio_pci_softc *)vsc;
bus_space_write_2(sc->sc_iot, sc->sc_ioh, VIRTIO_CONFIG_QUEUE_SELECT,
- idx);
+ vq->vq_index);
bus_space_write_4(sc->sc_iot, sc->sc_ioh, VIRTIO_CONFIG_QUEUE_ADDRESS,
- addr);
+ addr / VIRTIO_PAGE_SIZE);
/*
* This path is only executed if this function is called after
@@ -150,7 +151,7 @@ virtio_pci_setup_queue(struct virtio_softc *vsc, uint16_t idx, uint32_t addr)
if (sc->sc_irq_type != IRQ_NO_MSIX) {
int vec = 1;
if (sc->sc_irq_type == IRQ_MSIX_PER_VQ)
- vec += idx;
+ vec += vq->vq_index;
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
VIRTIO_MSI_QUEUE_VECTOR, vec);
}
diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c
index e6cd1ace5aa..242789d0c70 100644
--- a/sys/dev/pv/virtio.c
+++ b/sys/dev/pv/virtio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtio.c,v 1.13 2019/01/10 18:06:56 sf Exp $ */
+/* $OpenBSD: virtio.c,v 1.14 2019/03/24 18:17:24 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@@ -154,8 +154,7 @@ virtio_reinit_start(struct virtio_softc *sc)
sc->sc_dev.dv_xname, vq->vq_index);
}
virtio_init_vq(sc, vq, 1);
- virtio_setup_queue(sc, vq->vq_index,
- vq->vq_dmamap->dm_segs[0].ds_addr / VIRTIO_PAGE_SIZE);
+ virtio_setup_queue(sc, vq, vq->vq_dmamap->dm_segs[0].ds_addr);
}
}
@@ -345,9 +344,6 @@ virtio_alloc_vq(struct virtio_softc *sc, struct virtqueue *vq, int index,
goto err;
}
- virtio_setup_queue(sc, index,
- vq->vq_dmamap->dm_segs[0].ds_addr / VIRTIO_PAGE_SIZE);
-
/* remember addresses and offsets for later use */
vq->vq_owner = sc;
vq->vq_num = vq_size;
@@ -367,6 +363,7 @@ virtio_alloc_vq(struct virtio_softc *sc, struct virtqueue *vq, int index,
}
vq->vq_bytesize = allocsize;
vq->vq_maxnsegs = maxnsegs;
+ virtio_setup_queue(sc, vq, vq->vq_dmamap->dm_segs[0].ds_addr);
/* free slot management */
vq->vq_entries = mallocarray(vq_size, sizeof(struct vq_entry),
@@ -388,7 +385,7 @@ virtio_alloc_vq(struct virtio_softc *sc, struct virtqueue *vq, int index,
return 0;
err:
- virtio_setup_queue(sc, index, 0);
+ virtio_setup_queue(sc, vq, 0);
if (vq->vq_dmamap)
bus_dmamap_destroy(sc->sc_dmat, vq->vq_dmamap);
if (vq->vq_vaddr)
@@ -418,7 +415,7 @@ virtio_free_vq(struct virtio_softc *sc, struct virtqueue *vq)
}
/* tell device that there's no virtqueue any longer */
- virtio_setup_queue(sc, vq->vq_index, 0);
+ virtio_setup_queue(sc, vq, 0);
free(vq->vq_entries, M_DEVBUF, 0);
bus_dmamap_unload(sc->sc_dmat, vq->vq_dmamap);
diff --git a/sys/dev/pv/virtiovar.h b/sys/dev/pv/virtiovar.h
index 87f7bcfa627..da1351b6ac3 100644
--- a/sys/dev/pv/virtiovar.h
+++ b/sys/dev/pv/virtiovar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtiovar.h,v 1.10 2019/01/19 16:23:46 sf Exp $ */
+/* $OpenBSD: virtiovar.h,v 1.11 2019/03/24 18:17:24 sf Exp $ */
/* $NetBSD: virtiovar.h,v 1.1 2011/10/30 12:12:21 hannken Exp $ */
/*
@@ -149,7 +149,7 @@ struct virtio_ops {
void (*write_dev_cfg_4)(struct virtio_softc *, int, uint32_t);
void (*write_dev_cfg_8)(struct virtio_softc *, int, uint64_t);
uint16_t (*read_queue_size)(struct virtio_softc *, uint16_t);
- void (*setup_queue)(struct virtio_softc *, uint16_t, uint32_t);
+ void (*setup_queue)(struct virtio_softc *, struct virtqueue *, uint64_t);
void (*set_status)(struct virtio_softc *, int);
uint32_t (*neg_features)(struct virtio_softc *, uint32_t, const struct virtio_feature_name *);
int (*poll_intr)(void *);