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.


Guest-side test tools, config, and X11 stuff for PARAGRAPH graphics device
[palacios.git] / guest / linux / paragraph / write_paragraph / write_paragraph_sysfs.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <sys/mman.h>
5
6 #define PARAGRAPH_SYSFS_RESOURCE "/sys/devices/pci0000:00/0000:00:02.0/resource0"
7 #define PARAGRAPH_LEN (1024*1024*4)
8
9 int main(int argc, char *argv[]) 
10 {
11   int start;
12   char *res;
13
14   if (argc < 3) {
15     printf("Usage: write_paragraph_sysfs sysfsresource start\nyou probably want to use %s\n",PARAGRAPH_SYSFS_RESOURCE);
16     return 0;
17   }
18   
19   res = argv[1];
20   start = atoi(argv[2]);
21
22   int fd = open(res, O_RDWR | O_SYNC);
23
24   if (fd<0) { 
25     perror("Cannot open sysfs file");
26     printf("sysfs file = %s\n", res);
27     return -1;
28   }
29
30   unsigned char *mem = mmap(NULL, PARAGRAPH_LEN, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
31
32   if (mem == MAP_FAILED) {
33     perror("Can't map memory");
34     return -1;
35   } else { 
36     printf("Mapped to 0x%p (%d bytes)\n", mem, PARAGRAPH_LEN);
37   }
38   
39   int i;
40   for (i = 0; i < PARAGRAPH_LEN; i++) {
41     *(mem+i) = i+start;
42     if (i<16) { printf("0x%p = %d\n", mem+i, *(mem+i)); } 
43   }
44   printf("Wrote %d bytes\n", PARAGRAPH_LEN);
45
46   sleep(99999);
47
48 }