From 1210ad161b2ed36aec1f1c2ac08538e2ee55da6f Mon Sep 17 00:00:00 2001 From: Swapnil Ingle Date: Wed, 7 Oct 2020 06:36:40 -0400 Subject: client, server changes for lm_irq_message() Signed-off-by: Swapnil Ingle --- samples/client.c | 28 ++++++++++++++++++++++++++-- samples/server.c | 5 +++++ 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'samples') diff --git a/samples/client.c b/samples/client.c index aad15f6..55e9006 100644 --- a/samples/client.c +++ b/samples/client.c @@ -187,9 +187,11 @@ static int get_device_info(int sock, struct vfio_device_info *dev_info) static int configure_irqs(int sock) { - int i; + int i, size; int ret; struct vfio_irq_set irq_set; + struct vfio_user_irq_info irq_info; + struct vfio_user_header hdr; uint16_t msg_id = 1; int irq_fd; uint64_t val; @@ -245,6 +247,28 @@ configure_irqs(int sock) printf("INTx triggered!\n"); + msg_id++; + size = sizeof(irq_info); + ret = recv_vfio_user_msg(sock, &hdr, false, &msg_id, &irq_info, &size); + if (ret < 0) { + fprintf(stderr, "failed to recieve IRQ message: %s\n", strerror(-ret)); + return ret; + } + if (irq_info.subindex >= irq_set.count) { + fprintf(stderr, "bad IRQ %d, max=%d\n", irq_info.subindex, + irq_set.count); + return -ENOENT; + } + + ret = send_vfio_user_msg(sock, msg_id, true, VFIO_USER_VM_INTERRUPT, + NULL, 0, NULL, 0); + if (ret < 0) { + fprintf(stderr, "failed to send reply for VFIO_USER_VM_INTERRUPT: " + "%s\n", strerror(-ret)); + return ret; + } + printf("INTx messaged triggered!\n"); + return 0; } @@ -497,7 +521,7 @@ int main(int argc, char *argv[]) /* * XXX VFIO_USER_DEVICE_GET_IRQ_INFO and VFIO_IRQ_SET_ACTION_TRIGGER * Query interrupts, configure an eventfd to be associated with INTx, and - * finally wait for the server to fire the interrupt. + * finally wait for the server to fire the interrupt. */ ret = configure_irqs(sock); if (ret < 0) { diff --git a/samples/server.c b/samples/server.c index 11f7064..65f80d5 100644 --- a/samples/server.c +++ b/samples/server.c @@ -274,6 +274,11 @@ int main(int argc, char *argv[]) irq_triggered = false; lm_irq_trigger(lm_ctx, 0); + ret = lm_irq_message(lm_ctx, 0); + if (ret < 0) { + fprintf(stderr, "lm_irq_message() failed: %m\n"); + } + ret = do_dma_io(lm_ctx, &server_data); if (ret < 0) { fprintf(stderr, "DMA read/write failed: %m\n"); -- cgit v1.1