6 #include <sys/select.h>
9 #include "v3_user_host_dev.h"
13 fprintf(stderr,"v3_host_dev_example /dev/v3-vm0 user:mydev busywait|select\n");
17 int do_work(struct palacios_host_dev_host_request_response *req,
18 struct palacios_host_dev_host_request_response **resp)
24 // Process request here, perhaps calling these functions:
26 // uint64_t v3_user_host_dev_read_guest_mem(int devfd, void *gpa, void *dest, uint64_t len);
27 // uint64_t v3_user_host_dev_write_guest_mem(int devfd, void *gpa, void *src, uint64_t len);
28 // int v3_user_host_dev_raise_irq(int devfd, uint8_t irq);
29 // int v3_user_host_dev_lower_irq(int devfd, uint8_t irq);
31 // determine datasize - # bytes to include in response
33 // now built a response
34 *resp = malloc(sizeof(struct palacios_host_dev_host_request_response) + datasize);
36 fprintf(stderr, "ERROR: could not allocate memory for response\n");
39 (*resp)->data_len = sizeof(struct palacios_host_dev_host_request_response) + datasize;
42 // Fill out the fields of the response - notice that there are six kinds of things to response to:
43 // - read/write device port
44 // - read/write device mem
45 // - read/write device configuration space
50 int main(int argc, char *argv[])
63 mode = argv[3][0]=='s';
65 fprintf(stderr,"Attempting to rendezvous with host device %s on vm %s\n", url, vm);
67 if ((devfd = v3_user_host_dev_rendezvous(vm,url))<0) {
68 perror("failed to rendezvous");
72 fprintf(stderr,"Rendezvous succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
77 struct palacios_host_dev_host_request_response *req;
78 struct palacios_host_dev_host_request_response *resp;
82 while (!(v3_user_host_dev_have_request(devfd))) {
84 v3_user_host_dev_pull_request(devfd, &req);
88 v3_user_host_dev_push_response(devfd, resp);
95 struct palacios_host_dev_host_request_response *req;
96 struct palacios_host_dev_host_request_response *resp;
101 // select-based operation so that you can wait for multiple things
105 FD_SET(devfd,&readset);
107 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
110 if (FD_ISSET(devfd,&readset)) {
111 // a request is read for us!
112 v3_user_host_dev_pull_request(devfd, &req);
116 v3_user_host_dev_push_response(devfd, resp);
125 v3_user_host_dev_depart(devfd);