diff options
-rw-r--r-- | include/libvfio-user.h | 16 | ||||
-rw-r--r-- | lib/irq.c | 22 | ||||
-rw-r--r-- | samples/client.c | 59 | ||||
-rw-r--r-- | samples/server.c | 10 |
4 files changed, 17 insertions, 90 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h index 4c9ac6f..06013d4 100644 --- a/include/libvfio-user.h +++ b/include/libvfio-user.h @@ -508,22 +508,6 @@ int vfu_irq_trigger(vfu_ctx_t *vfu_ctx, uint32_t subindex); /** - * Sends message to client to trigger an interrupt. - * - * libvfio-user takes care of using the IRQ type (INTx, MSI/X), the caller only - * needs to specify the sub-index. - * This api can be used to trigger interrupt by sending message to client. - * - * @vfu_ctx: the libvfio-user context to trigger interrupt - * @subindex: vector subindex to trigger interrupt on - * - * @returns 0 on success, or -1 on failure. Sets errno. - */ - -int -vfu_irq_message(vfu_ctx_t *vfu_ctx, uint32_t subindex); - -/** * Takes a guest physical address and returns a list of scatter/gather entries * than can be individually mapped in the program's virtual memory. A single * linear guest physical address span may need to be split into multiple @@ -419,26 +419,4 @@ vfu_irq_trigger(vfu_ctx_t *vfu_ctx, uint32_t subindex) return eventfd_write(vfu_ctx->irqs->efds[subindex], val); } -int -vfu_irq_message(vfu_ctx_t *vfu_ctx, uint32_t subindex) -{ - int ret, msg_id = 1; - struct vfio_user_irq_info irq_info; - - if (!validate_irq_subindex(vfu_ctx, subindex)) { - return ERROR_INT(EINVAL); - } - - irq_info.subindex = subindex; - ret = vfu_ctx->tran->send_msg(vfu_ctx, msg_id, - VFIO_USER_VM_INTERRUPT, - &irq_info, sizeof(irq_info), - NULL, NULL, 0); - if (ret < 0) { - return ERROR_INT(-ret); - } - - return 0; -} - /* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/samples/client.c b/samples/client.c index 3fda9d3..309c193 100644 --- a/samples/client.c +++ b/samples/client.c @@ -516,47 +516,7 @@ access_region(int sock, int region, bool is_write, uint64_t offset, } static void -wait_for_irqs(int sock, int irq_fd) -{ - int ret; - uint64_t val; - size_t size; - struct vfio_user_irq_info vfio_user_irq_info; - struct vfio_user_header hdr; - uint16_t msg_id = 0xbabe; - - if (read(irq_fd, &val, sizeof(val)) == -1) { - err(EXIT_FAILURE, "failed to read from irqfd"); - } - printf("INTx triggered!\n"); - - size = sizeof(vfio_user_irq_info); - ret = tran_sock_recv(sock, &hdr, false, &msg_id, - &vfio_user_irq_info, &size); - if (ret < 0) { - errx(EXIT_FAILURE, "failed to receive IRQ message: %s", - strerror(-ret)); - } - - if (hdr.cmd != VFIO_USER_VM_INTERRUPT) { - errx(EXIT_FAILURE, "unexpected cmd %d\n", hdr.cmd); - } - - if (vfio_user_irq_info.subindex >= 1) { - errx(EXIT_FAILURE, "bad IRQ %d, max=1\n", vfio_user_irq_info.subindex); - } - - // Is a NULL iovec like this OK? - ret = tran_sock_send(sock, msg_id, true, hdr.cmd, NULL, 0); - if (ret < 0) { - errx(EXIT_FAILURE, - "failed to send reply for VFIO_USER_VM_INTERRUPT: %s", - strerror(-ret)); - } -} - -static void -access_bar0(int sock, int irq_fd, time_t *t) +access_bar0(int sock, time_t *t) { int ret; @@ -575,8 +535,17 @@ access_bar0(int sock, int irq_fd, time_t *t) } printf("read from BAR0: %ld\n", *t); +} - wait_for_irqs(sock, irq_fd); +static void +wait_for_irq(int irq_fd) +{ + uint64_t val; + + if (read(irq_fd, &val, sizeof(val)) == -1) { + err(EXIT_FAILURE, "failed to read from irqfd"); + } + printf("INTx triggered!\n"); } static void @@ -1249,7 +1218,9 @@ int main(int argc, char *argv[]) * via explicit messages. */ t = time(NULL) + 1; - access_bar0(sock, irq_fd, &t); + access_bar0(sock, &t); + + wait_for_irq(irq_fd); /* FIXME check that above took at least 1s */ @@ -1340,7 +1311,7 @@ int main(int argc, char *argv[]) } irq_fd = ret; - wait_for_irqs(sock, irq_fd); + wait_for_irq(irq_fd); handle_dma_io(sock, dma_regions + server_max_fds, nr_dma_regions - server_max_fds, diff --git a/samples/server.c b/samples/server.c index 4391bca..cb966f5 100644 --- a/samples/server.c +++ b/samples/server.c @@ -580,15 +580,9 @@ int main(int argc, char *argv[]) if (ret == -1 && errno == EINTR) { if (irq_triggered) { irq_triggered = false; - vfu_irq_trigger(vfu_ctx, 0); - /* - * Apart from triggering an IRQ via the eventfd, we also - * trigger an IRQ via a message, simply for demonstrating how - * it's done. The client expects this behavior from the server. - */ - ret = vfu_irq_message(vfu_ctx, 0); + ret = vfu_irq_trigger(vfu_ctx, 0); if (ret < 0) { - err(EXIT_FAILURE, "vfu_irq_message() failed"); + err(EXIT_FAILURE, "vfu_irq_trigger() failed"); } /* |