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);
35 fprintf(stderr, "ERROR: could not allocate memory for response\n");
38 (*resp)->data_len = sizeof(struct palacios_host_dev_host_request_response) + datasize;
41 // Fill out the fields of the response - notice that there are six kinds of things to response to:
42 // - read/write device port
43 // - read/write device mem
44 // - read/write device configuration space
49 int main(int argc, char *argv[])
62 mode = argv[3][0]=='s';
64 fprintf(stderr,"Attempting to rendezvous with host device %s on vm %s\n", url, vm);
66 if ((devfd = v3_user_host_dev_rendezvous(vm,url))<0) {
67 perror("failed to rendezvous");
71 fprintf(stderr,"Rendezvous succeeded, I will now operate in %s mode\n", mode==0 ? "busywait" : "select");
76 struct palacios_host_dev_host_request_response *req;
77 struct palacios_host_dev_host_request_response *resp;
81 while (!(v3_user_host_dev_have_request(devfd))) {
83 v3_user_host_dev_pull_request(devfd, &req);
87 v3_user_host_dev_push_response(devfd, resp);
94 struct palacios_host_dev_host_request_response *req;
95 struct palacios_host_dev_host_request_response *resp;
100 // select-based operation so that you can wait for multiple things
104 FD_SET(devfd,&readset);
106 rc = select(devfd+1, &readset, 0, 0, 0); // pick whatever you want to select on, just include devfd
109 if (FD_ISSET(devfd,&readset)) {
110 // a request is read for us!
111 v3_user_host_dev_pull_request(devfd, &req);
115 v3_user_host_dev_push_response(devfd, resp);
124 v3_user_host_dev_depart(devfd);