From: Nikhil Devshatwar <nikhil...@ti.com>

Number of peers available on a platform is different.
Ideally, any peer should be able to communicate with
any other peer. By default, all demos send interrupt to
the next peer in a ring fashion.

Add support for passing a command line parameter to specify
exact peer to send interrupt to. Furthermore, avoid using a
hard-coded max-peers value for the default target selection.

Signed-off-by: Nikhil Devshatwar <nikhil...@ti.com>
[Jan: fix register access, print max-peers, massage commit log]
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
---
 tools/ivshmem-demo.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/tools/ivshmem-demo.c b/tools/ivshmem-demo.c
index 163653e1..4110e898 100644
--- a/tools/ivshmem-demo.c
+++ b/tools/ivshmem-demo.c
@@ -19,6 +19,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <sys/fcntl.h>
@@ -33,7 +34,6 @@ struct ivshm_regs {
 };
 
 static volatile uint32_t *state, *rw, *in, *out;
-static uint32_t id, int_count;
 
 static inline uint32_t mmio_read32(void *address)
 {
@@ -81,20 +81,32 @@ int main(int argc, char *argv[])
 {
        char sysfs_path[64];
        struct ivshm_regs *regs;
-       uint32_t int_no, target = 0;
+       uint32_t int_no, target = INT_MAX;
        struct signalfd_siginfo siginfo;
        struct pollfd fds[2];
        sigset_t sigset;
-       char *path;
-       int has_msix;
+       char *path = "/dev/uio0";
+       int has_msix, i;
        int ret, size, offset, pgsize;
+       uint32_t id, max_peers, int_count;
 
        pgsize = getpagesize();
 
-       if (argc < 2)
-               path = strdup("/dev/uio0");
-       else
-               path = strdup(argv[1]);
+       for (i = 1; i < argc; i++) {
+               if (!strcmp("-t", argv[i]) || !strcmp("--target", argv[i])) {
+                       i++;
+                       target = atoi(argv[i]);
+                       continue;
+               } else if (!strcmp("-d", argv[i]) || !strcmp("--device", 
argv[i])) {
+                       i++;
+                       path = argv[i];
+                       continue;
+               } else {
+                       printf("Invalid argument '%s'\n", argv[i]);
+                       error(1, EINVAL, "Usage: ivshmem-demo [-d DEV] [-t 
TARGET]");
+               }
+       }
+
        fds[0].fd = open(path, O_RDWR);
        if (fds[0].fd < 0)
                error(1, errno, "open(%s)", path);
@@ -114,6 +126,14 @@ int main(int argc, char *argv[])
        id = mmio_read32(&regs->id);
        printf("ID = %d\n", id);
 
+       max_peers = mmio_read32(&regs->max_peers);
+       printf("Maximum peers = %d\n", max_peers);
+
+       if (target == INT_MAX)
+               target = (id + 1) % max_peers;
+       if (target >= max_peers || target == id)
+               error(1, EINVAL, "invalid peer number");
+
        offset += pgsize;
        size = uio_read_mem_size(path, 1);
        state = mmap(NULL, size, PROT_READ, MAP_SHARED, fds[0].fd, offset);
@@ -180,7 +200,6 @@ int main(int argc, char *argv[])
                                error(1, errno, "read(sigfd)");
 
                        int_no = has_msix ? (id + 1) : 0;
-                       target = (id + 1) % 3;
                        printf("\nSending interrupt %d to peer %d\n",
                               int_no, target);
                        mmio_write32(&regs->doorbell, int_no | (target << 16));
-- 
2.26.2

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/4c91b041-b062-a35f-15cc-06b63c640707%40siemens.com.

Reply via email to