From: Nikhil Devshatwar <[email protected]>

Number of peers available on a platform is different.
Do not hard code the target peer_id used for interrupt.
Parse this from the command line argument.

This de-couples the dependency between number of peers.
ivshmem-demo can be run to communicate with desired target

Signed-off-by: Nikhil Devshatwar <[email protected]>
---
 tools/ivshmem-demo.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/ivshmem-demo.c b/tools/ivshmem-demo.c
index 163653e1..98d24111 100644
--- a/tools/ivshmem-demo.c
+++ b/tools/ivshmem-demo.c
@@ -91,10 +91,11 @@ int main(int argc, char *argv[])
 
        pgsize = getpagesize();
 
-       if (argc < 2)
-               path = strdup("/dev/uio0");
-       else
-               path = strdup(argv[1]);
+       if (argc !=  3)
+               error(1, EINVAL, "Usage: ivshmem-demo </dev/uioX> <peer_id>");
+       path = strdup(argv[1]);
+       target = atoi(argv[2]);
+
        fds[0].fd = open(path, O_RDWR);
        if (fds[0].fd < 0)
                error(1, errno, "open(%s)", path);
@@ -113,6 +114,8 @@ int main(int argc, char *argv[])
 
        id = mmio_read32(&regs->id);
        printf("ID = %d\n", id);
+       if (target >= regs->max_peers || target == id)
+               error(1, EINVAL, "invalid peer number");
 
        offset += pgsize;
        size = uio_read_mem_size(path, 1);
@@ -180,7 +183,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.17.1

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20200527123225.31726-5-nikhil.nd%40ti.com.

Reply via email to