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.


Merge branch 'devel' of newskysaw.cs.northwestern.edu:/home/palacios/palacios into...
[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         if (!r) { 
60             return -1;
61         }
62
63         rc=ioctl(devfd, V3_HOST_DEV_HOST_REQUEST_PULL_IOCTL,r);
64         
65         if (rc<=0) { 
66             free(r);
67             return -1;
68         } else {
69             *req=r;
70             return 0;
71         }
72     }
73 }
74                 
75
76 int v3_user_host_dev_push_response(int devfd, struct palacios_host_dev_host_request_response *resp)
77 {
78     int rc;
79
80     rc=ioctl(devfd, V3_HOST_DEV_USER_RESPONSE_PUSH_IOCTL,resp);
81         
82     if (rc<=0) { 
83         return -1;
84     } else {
85         return 0;
86     }
87 }
88                 
89
90
91 static uint64_t do_user(int devfd, struct palacios_host_dev_user_op *op)
92 {
93     return ioctl(devfd, V3_HOST_DEV_USER_REQUEST_PUSH_IOCTL,op);
94 }
95
96 uint64_t v3_user_host_dev_read_guest_mem(int devfd, void *gpa, void *dest, uint64_t len)
97 {
98     struct palacios_host_dev_user_op op;
99
100     op.type= PALACIOS_HOST_DEV_USER_REQUEST_READ_GUEST;
101     op.gpa=gpa;
102     op.data=dest;
103     op.len=len;
104     op.irq=0;
105     
106     return do_user(devfd,&op);
107 }
108
109 uint64_t v3_user_host_dev_write_guest_mem(int devfd, void *gpa, void *src, uint64_t len)
110 {
111     struct palacios_host_dev_user_op op;
112
113     op.type= PALACIOS_HOST_DEV_USER_REQUEST_WRITE_GUEST;
114     op.gpa=gpa;
115     op.data=src;
116     op.len=len;
117     op.irq=0;
118     
119     return do_user(devfd,&op);
120 }
121
122 int      v3_user_host_dev_inject_irq(int devfd, uint8_t irq)
123 {
124     struct palacios_host_dev_user_op op;
125
126     op.type= PALACIOS_HOST_DEV_USER_REQUEST_IRQ_GUEST;
127     op.gpa=0;
128     op.data=0;
129     op.len=0;
130     op.irq=irq;
131     
132     return do_user(devfd,&op);
133 }
134
135
136