From 064071b5c73d96d626760d0f48aec234eb5da2d6 Mon Sep 17 00:00:00 2001 From: Thanos Makatos Date: Mon, 1 Mar 2021 08:48:10 +0000 Subject: optionally enable DMA controller in GPIO sample (#375) This helps debugging. Signed-off-by: Thanos Makatos Reviewed-by: John Levon --- samples/gpio-pci-idio-16.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'samples/gpio-pci-idio-16.c') diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 62ae031..b52eafb 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -125,11 +125,24 @@ migration_write_data(UNUSED vfu_ctx_t *vfu_ctx, void *buf, __u64 size, return 0; } +static void +map_dma(vfu_ctx_t *vfu_ctx UNUSED, uint64_t iova UNUSED, uint64_t len UNUSED, + uint32_t prot UNUSED) +{ +} + +static int +unmap_dma(vfu_ctx_t *vfu_ctx UNUSED, uint64_t iova UNUSED, uint64_t len UNUSED) +{ + return 0; +} + int main(int argc, char *argv[]) { int ret; bool verbose = false; + bool dma = false; char opt; struct sigaction act = { .sa_handler = _sa_handler }; vfu_ctx_t *vfu_ctx; @@ -146,13 +159,16 @@ main(int argc, char *argv[]) .write_data = &migration_write_data }; - while ((opt = getopt(argc, argv, "v")) != -1) { + while ((opt = getopt(argc, argv, "vd")) != -1) { switch (opt) { case 'v': verbose = true; break; + case 'd': + dma = true; + break; default: /* '?' */ - fprintf(stderr, "Usage: %s [-v] \n", argv[0]); + fprintf(stderr, "Usage: %s [-d] [-v] \n", argv[0]); exit(EXIT_FAILURE); } } @@ -211,6 +227,13 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "failed to setup irq counts"); } + if (dma) { + ret = vfu_setup_device_dma_cb(vfu_ctx, map_dma, unmap_dma); + if (ret < 0) { + err(EXIT_FAILURE, "failed to setup DMA"); + } + } + ret = vfu_realize_ctx(vfu_ctx); if (ret < 0) { err(EXIT_FAILURE, "failed to realize device"); -- cgit v1.1