Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Updated kernel module and user tools to reflect ioctl changes for host devices
[palacios.git] / linux_usr / v3_user_host_dev.c
1 #include <unistd.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <malloc.h>
5 #include <string.h>
6 #include <stdio.h>
7
8 #include "v3_user_host_dev.h"
9
10
11 int v3_user_host_dev_rendezvous(char *vmdev, char *url)
12 {
13     int vmfd;
14     int devfd;
15     char buf[256];
16
17
18     strcpy(buf,url);
19     buf[255]=0;
20
21     if ((vmfd=open(vmdev,O_RDWR))<0) { 
22         return -1;
23     }
24
25     devfd = ioctl(vmfd,V3_VM_HOST_DEV_CONNECT,buf);
26     
27     close(vmfd);
28
29     return devfd;
30
31 }
32 int v3_user_host_dev_depart(int devfd)
33 {
34     return close(devfd);
35 }
36
37
38 int v3_user_host_dev_have_request(int devfd)
39 {
40     uint64_t len;
41
42     int rc=ioctl(devfd,V3_HOST_DEV_HOST_REQUEST_SIZE_IOCTL,&len);
43
44     return rc==1;
45 }
46
47 int v3_user_host_dev_pull_request(int devfd, struct palacios_host_dev_host_request_response **req)
48 {
49     uint64_t len;
50     int rc;
51
52     rc=ioctl(devfd,V3_HOST_DEV_HOST_REQUEST_SIZE_IOCTL,&len);
53
54     if (rc<=0) { 
55         return -1;
56     } else {
57         struct palacios_host_dev_host_request_response *r = malloc(len);
58         
59         rc=ioctl(devfd, V3_HOST_DEV_HOST_REQUEST_PULL_IOCTL,r);
60         
61         if (rc<=0) { 
62             free(r);
63             return -1;
64         } else {
65             *req=r;
66             return 0;
67         }
68     }
69 }
70                 
71
72 int v3_user_host_dev_push_response(int devfd, struct palacios_host_dev_host_request_response *resp)
73 {
74     int rc;
75
76     rc=ioctl(devfd, V3_HOST_DEV_USER_RESPONSE_PUSH_IOCTL,resp);
77         
78     if (rc<=0) { 
79         return -1;
80     } else {
81         return 0;
82     }
83 }
84                 
85
86
87 static uint64_t do_user(int devfd, struct palacios_host_dev_user_op *op)
88 {
89     return ioctl(devfd, V3_HOST_DEV_USER_REQUEST_PUSH_IOCTL,op);
90 }
91
92 uint64_t v3_user_host_dev_read_guest_mem(int devfd, void *gpa, void *dest, uint64_t len)
93 {
94     struct palacios_host_dev_user_op op;
95
96     op.type= PALACIOS_HOST_DEV_USER_REQUEST_READ_GUEST;
97     op.gpa=gpa;
98     op.data=dest;
99     op.len=len;
100     op.irq=0;
101     
102     return do_user(devfd,&op);
103 }
104
105 uint64_t v3_user_host_dev_write_guest_mem(int devfd, void *gpa, void *src, uint64_t len)
106 {
107     struct palacios_host_dev_user_op op;
108
109     op.type= PALACIOS_HOST_DEV_USER_REQUEST_WRITE_GUEST;
110     op.gpa=gpa;
111     op.data=src;
112     op.len=len;
113     op.irq=0;
114     
115     return do_user(devfd,&op);
116 }
117
118 int      v3_user_host_dev_inject_irq(int devfd, uint8_t irq)
119 {
120     struct palacios_host_dev_user_op op;
121
122     op.type= PALACIOS_HOST_DEV_USER_REQUEST_IRQ_GUEST;
123     op.gpa=0;
124     op.data=0;
125     op.len=0;
126     op.irq=irq;
127     
128     return do_user(devfd,&op);
129 }
130
131
132