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.


*** empty log message ***
[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 remove_io_hook(vmm_io_map_t * io_map, vmm_io_hook_t * io_hook) {
55   if (io_map->head == io_hook) {
56     io_map->head = io_hook->next;
57   } else if (io_hook->prev) {
58     io_hook->prev->next = io_hook->next;
59   } else {
60     // data corruption failure
61   }
62   
63   if (io_hook->next) {
64     io_hook->next->prev = io_hook->prev;
65   }
66
67   io_map->num_ports--;
68
69   return;
70 }
71
72
73 void hook_io_port(vmm_io_map_t * io_map, uint_t port, 
74                   int (*read)(ushort_t port, void * dst, uint_t length, void * priv_data),
75                   int (*write)(ushort_t port, void * src, uint_t length, void * priv_data), 
76                   void * priv_data) {
77   vmm_io_hook_t * io_hook = os_hooks->malloc(sizeof(vmm_io_hook_t));
78
79   io_hook->port = port;
80   io_hook->read = read;
81   io_hook->write = write;
82   io_hook->next = NULL;
83   io_hook->prev = NULL;
84
85   io_hook->priv_data = priv_data;
86
87   add_io_hook(io_map, io_hook);
88
89   return;
90 }
91
92 int unhook_io_port(vmm_io_map_t * io_map, uint_t port) {
93   vmm_io_hook_t * hook = get_io_hook(io_map, port);
94
95   if (hook == NULL) {
96     return -1;
97   }
98
99   remove_io_hook(io_map, hook);
100   return 0;
101 }
102
103
104 vmm_io_hook_t * get_io_hook(vmm_io_map_t * io_map, uint_t port) {
105   vmm_io_hook_t * tmp_hook;
106   FOREACH_IO_HOOK(*io_map, tmp_hook) {
107     if (tmp_hook->port == port) {
108       return tmp_hook;
109     }
110   }
111   return NULL;
112 }
113
114
115
116 void PrintDebugIOMap(vmm_io_map_t * io_map) {
117   vmm_io_hook_t * iter = io_map->head;
118
119   PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports);
120
121   while (iter) {
122     PrintDebug("IO Port: %hu (Read=%x) (Write=%x)\n", iter->port, iter->read, iter->write);
123   }
124 }