diff --git a/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_pci_vsock.h b/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_pci_vsock.h index 8021965a2..3d2f4551e 100644 --- a/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_pci_vsock.h +++ b/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_pci_vsock.h @@ -5,14 +5,24 @@ */ #pragma once -typedef void (*vsock_inject_irq_fn_t)(void *cookie); +typedef struct virtio_emul virtio_emul_t; + typedef void (*vsock_tx_forward_fn_t)(int cid, void *buffer, unsigned int len); -struct vsock_passthrough { +typedef struct virtio_vsock_callbacks { + void (*rx_complete)(virtio_emul_t *emul, char *buf, unsigned int len); +} virtio_vsock_callbacks_t; + +typedef struct virtio_vsock_passthrough { int guest_cid; - vsock_inject_irq_fn_t injectIRQ; + void (*injectIRQ)(void *cookie); vsock_tx_forward_fn_t forward; void *vsock_data; +} virtio_vsock_passthrough_t; + +struct virtio_vsock_driver { + virtio_vsock_passthrough_t backend_fn; + virtio_vsock_callbacks_t emul_cb; }; -typedef int (*vsock_driver_init)(struct vsock_passthrough *driver, ps_io_ops_t io_ops, void *config); +typedef int (*vsock_driver_init)(struct virtio_vsock_driver *driver, ps_io_ops_t io_ops, void *config); diff --git a/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_vsock.h b/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_vsock.h index 81c471f10..a57cdb416 100644 --- a/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_vsock.h +++ b/libsel4vmmplatsupport/include/sel4vmmplatsupport/drivers/virtio_vsock.h @@ -14,7 +14,8 @@ typedef struct virtio_vsock { unsigned int iobase; virtio_emul_t *emul; - struct vsock_passthrough emul_driver_funcs; + struct virtio_vsock_driver *emul_driver; + struct virtio_vsock_passthrough emul_driver_funcs; ps_io_ops_t ioops; } virtio_vsock_t; @@ -25,4 +26,4 @@ virtio_vsock_t *common_make_virtio_vsock(vm_t *vm, ioport_type_t port_type, unsigned int interrupt_pin, unsigned int interrupt_line, - struct vsock_passthrough backend); + struct virtio_vsock_passthrough backend); diff --git a/libsel4vmmplatsupport/src/drivers/virtio_vsock.c b/libsel4vmmplatsupport/src/drivers/virtio_vsock.c index 0a0a5ce42..ac46c239d 100644 --- a/libsel4vmmplatsupport/src/drivers/virtio_vsock.c +++ b/libsel4vmmplatsupport/src/drivers/virtio_vsock.c @@ -44,10 +44,11 @@ static int virtio_vsock_io_out(void *cookie, unsigned int port_no, unsigned int } -static int emul_vsock_driver_init(struct vsock_passthrough *driver, ps_io_ops_t io_ops, void *config) +static int emul_vsock_driver_init(struct virtio_vsock_driver *driver, ps_io_ops_t io_ops, void *config) { virtio_vsock_t *vsock = (virtio_vsock_t *) config; - *driver = vsock->emul_driver_funcs; + driver->backend_fn = vsock->emul_driver_funcs; + vsock->emul_driver = driver; return 0; } @@ -91,7 +92,7 @@ static vmm_pci_entry_t vmm_virtio_vsock_pci_bar(unsigned int iobase, size_t ioba virtio_vsock_t *common_make_virtio_vsock(vm_t *vm, vmm_pci_space_t *pci, vmm_io_port_list_t *ioport, ioport_range_t ioport_range, ioport_type_t port_type, unsigned int interrupt_pin, unsigned int interrupt_line, - struct vsock_passthrough backend) + struct virtio_vsock_passthrough backend) { int err = ps_new_stdlib_malloc_ops(&ops.malloc_ops); ZF_LOGF_IF(err, "Failed to get malloc ops"); diff --git a/libsel4vmmplatsupport/src/drivers/virtio_vsock_emul.c b/libsel4vmmplatsupport/src/drivers/virtio_vsock_emul.c index a5c2fd694..e8ed3c33a 100644 --- a/libsel4vmmplatsupport/src/drivers/virtio_vsock_emul.c +++ b/libsel4vmmplatsupport/src/drivers/virtio_vsock_emul.c @@ -11,7 +11,7 @@ static char buf[VIRTIO_VSOCK_CAMKES_MTU]; typedef struct vsock_internal { - struct vsock_passthrough driver; + struct virtio_vsock_driver driver; /* what queue did data come through? */ int queue_num; } vsock_internal_t; @@ -66,7 +66,7 @@ static void emul_vsock_rx_complete(virtio_emul_t *emul, char *buf, unsigned int /* record that we've used this descriptor chain now */ virtq->last_idx[RX_QUEUE]++; /* notify the guest that there is something in its used ring */ - vsock->driver.injectIRQ(vsock->driver.vsock_data); + vsock->driver.backend_fn.injectIRQ(vsock->driver.backend_fn.vsock_data); } } @@ -75,6 +75,10 @@ void vsock_rx_complete(virtio_emul_t *emul, char *buf, unsigned int len) emul_vsock_rx_complete(emul, buf, len); } +static virtio_vsock_callbacks_t emul_callbacks = { + .rx_complete = vsock_rx_complete +}; + static void vsock_handle_packet(virtio_emul_t *emul, void *buffer, unsigned int len) { vsock_internal_t *vsock = emul->internal; @@ -86,7 +90,7 @@ static void vsock_handle_packet(virtio_emul_t *emul, void *buffer, unsigned int packet->hdr.len = VIRTIO_VSOCK_CAMKES_MTU - sizeof(struct virtio_vsock_hdr); } - vsock->driver.forward(cid, buffer, len); + vsock->driver.backend_fn.forward(cid, buffer, len); } static void emul_vsock_notify_tx(virtio_emul_t *emul) @@ -126,7 +130,7 @@ static void emul_vsock_notify_tx(virtio_emul_t *emul) idx++; struct vring_used_elem used_elem = {desc_head, 0}; ring_used_add(emul, &virtq->vring[vsock->queue_num], used_elem); - vsock->driver.injectIRQ(vsock->driver.vsock_data); + vsock->driver.backend_fn.injectIRQ(vsock->driver.backend_fn.vsock_data); } /* update which parts of the ring we have processed */ virtq->last_idx[vsock->queue_num] = idx; @@ -151,7 +155,7 @@ static bool vsock_device_emul_io_in(struct virtio_emul *emul, unsigned int offse /* Set VIRTIO_VSOCK_CFG_GUEST_CID in little-endian */ if (offset == VIRTIO_VSOCK_CFG_GUEST_CID) { - *result = vsock->driver.guest_cid; + *result = vsock->driver.backend_fn.guest_cid; } else { *result = 0; } @@ -204,6 +208,7 @@ void *vsock_virtio_emul_init(virtio_emul_t *emul, ps_io_ops_t io_ops, vsock_driv emul->notify = emul_vsock_notify_tx; emul->device_io_in = vsock_device_emul_io_in; emul->device_io_out = vsock_device_emul_io_out; + internal->driver.emul_cb = emul_callbacks; int err = driver(&internal->driver, io_ops, config); if (err) {