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.


updated module cleanup and added user space tools
[palacios.git] / linux_usr / v3_mem.c
1 /* 
2  * V3 Control utility
3  * (c) Jack lange, 2010
4  */
5
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h> 
10 #include <sys/ioctl.h> 
11 #include <sys/stat.h> 
12 #include <sys/types.h> 
13 #include <unistd.h> 
14 #include <string.h>
15  
16 #include "v3_ctrl.h"
17
18
19 int main(int argc, char* argv[]) {
20     unsigned long long base_addr = atoll(argv[1]);
21     unsigned long long num_bytes = atoll(argv[2]);
22     int v3_fd = 0;
23     struct v3_mem_region mem;
24
25     if (argc <= 2) {
26         printf("Usage: ./v3_mem <base_addr> <num_bytes>\n");
27         return -1;
28     }
29
30     printf("Giving Palacios %dMB of memory: \n", num_bytes / (1024 * 1024));
31
32     mem.base_addr = base_addr;
33     mem.num_pages = num_bytes / 4096;
34
35     v3_fd = open(v3_dev, O_RDONLY);
36
37     if (v3_fd == -1) {
38         printf("Error opening V3Vee control device\n");
39         return -1;
40     }
41
42     ioctl(v3_fd, V3_ADD_MEMORY, &mem); 
43
44
45
46     /* Close the file descriptor.  */ 
47     close(v3_fd); 
48  
49
50
51     return 0; 
52
53
54
55
56 int read_file(int fd, int size, unsigned char * buf) {
57     int left_to_read = size;
58     int have_read = 0;
59
60     while (left_to_read != 0) {
61         int bytes_read = read(fd, buf + have_read, left_to_read);
62
63         if (bytes_read <= 0) {
64             break;
65         }
66
67         have_read += bytes_read;
68         left_to_read -= bytes_read;
69     }
70
71     if (left_to_read != 0) {
72         printf("Error could not finish reading file\n");
73         return -1;
74     }
75     
76     return 0;
77 }