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_inject_guest_irq(int devfd, uint8_t irq);
30 // determine datasize - # bytes to include in response
32 // now built a response
33 *resp = malloc(sizeof(struct palacios_host_dev_host_request_response) + datasize);
34 (*resp)->data_len = sizeof(struct palacios_host_dev_host_request_response) + datasize;
37 // Fill out the fields of the response - notice that there are six kinds of things to response to:
38 // - read/write device port
39 // - read/write device mem
40 // - read/write device configuration space
45 int main(int argc, char *argv[])
58 mode = argv[3][0]=='s';
60 fprintf(stderr,"Attempting to rendezvous with host device %s on vm %s\n", url, vm);
62 if ((devfd = v3_user_host_dev_rendezvous(vm,url))<0) {
63 perror("failed to rendezvous");
67 fprintf(stderr,"Rendezvous succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
72 struct palacios_host_dev_host_request_response *req;
73 struct palacios_host_dev_host_request_response *resp;
77 while (!(v3_user_host_dev_have_request(devfd))) {
79 v3_user_host_dev_pull_request(devfd, &req);
83 v3_user_host_dev_push_response(devfd, resp);
90 struct palacios_host_dev_host_request_response *req;
91 struct palacios_host_dev_host_request_response *resp;
96 // select-based operation so that you can wait for multiple things
100 FD_SET(devfd,&readset);
102 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
105 if (FD_ISSET(devfd,&readset)) {
106 // a request is read for us!
107 v3_user_host_dev_pull_request(devfd, &req);
111 v3_user_host_dev_push_response(devfd, resp);
120 v3_user_host_dev_depart(devfd);