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.


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