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.


code restructuring
[palacios.git] / palacios / src / palacios / vmm_io.c
1 #include <palacios/vmm_io.h>
2 #include <palacios/vmm_string.h>
3 #include <palacios/vmm.h>
4
5 extern struct vmm_os_hooks * os_hooks;
6
7 void init_vmm_io_map(vmm_io_map_t * io_map) {
8   io_map->num_ports = 0;
9   io_map->head = NULL;
10 }
11
12
13
14 void add_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) {
15   vmm_io_hook_t * tmp_hook = io_map->head;
16
17   if (!tmp_hook) {
18     io_map->head = io_hook;
19     io_map->num_ports = 1;
20     return;
21   } else {
22     while ((tmp_hook->next)  && 
23            (tmp_hook->next->port <= io_hook->port)) {
24       tmp_hook = tmp_hook->next;
25     }
26     
27     if (tmp_hook->port == io_hook->port) {
28       tmp_hook->read = io_hook->read;
29       tmp_hook->write = io_hook->write;
30       
31       VMMFree(io_hook);
32       return;
33     } else if (!tmp_hook->next) {
34       tmp_hook->next = io_hook;
35       io_hook->prev = tmp_hook;
36       io_map->num_ports++;
37       
38       return;
39     } else {
40       io_hook->next = tmp_hook->next;
41       io_hook->prev = tmp_hook;
42       
43       tmp_hook->next = io_hook;
44       if (io_hook->next) {
45         io_hook->next->prev = io_hook;
46       }
47       
48       io_map->num_ports++;
49       return;
50     }
51   }
52 }
53
54 void hook_io_port(vmm_io_map_t * io_map, uint_t port, 
55                   int (*read)(ushort_t port, void * dst, uint_t length),
56                   int (*write)(ushort_t port, void * src, uint_t length)) {
57   vmm_io_hook_t * io_hook = os_hooks->malloc(sizeof(vmm_io_hook_t));
58
59   io_hook->port = port;
60   io_hook->read = read;
61   io_hook->write = write;
62   io_hook->next = NULL;
63   io_hook->prev = NULL;
64
65   add_io_hook(io_map, io_hook);
66
67   return;
68 }
69
70
71 vmm_io_hook_t * get_io_hook(vmm_io_map_t * io_map, uint_t port) {
72   vmm_io_hook_t * tmp_hook;
73   FOREACH_IO_HOOK(*io_map, tmp_hook) {
74     if (tmp_hook->port == port) {
75       return tmp_hook;
76     }
77   }
78   return NULL;
79 }
80
81
82
83 void PrintDebugIOMap(vmm_io_map_t * io_map) {
84   vmm_io_hook_t * iter = io_map->head;
85
86   PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports);
87
88   while (iter) {
89     PrintDebug("IO Port: %hu (Read=%x) (Write=%x)\n", iter->port, iter->read, iter->write);
90   }
91 }