1 #include <palacios/vmm_io.h>
2 #include <palacios/vmm_string.h>
3 #include <palacios/vmm.h>
5 extern struct vmm_os_hooks * os_hooks;
7 void init_vmm_io_map(vmm_io_map_t * io_map) {
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;
18 io_map->head = io_hook;
19 io_map->num_ports = 1;
22 while ((tmp_hook->next) &&
23 (tmp_hook->next->port <= io_hook->port)) {
24 tmp_hook = tmp_hook->next;
27 if (tmp_hook->port == io_hook->port) {
28 tmp_hook->read = io_hook->read;
29 tmp_hook->write = io_hook->write;
33 } else if (!tmp_hook->next) {
34 tmp_hook->next = io_hook;
35 io_hook->prev = tmp_hook;
40 io_hook->next = tmp_hook->next;
41 io_hook->prev = tmp_hook;
43 tmp_hook->next = io_hook;
45 io_hook->next->prev = io_hook;
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;
60 // data corruption failure
64 io_hook->next->prev = io_hook->prev;
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),
77 vmm_io_hook_t * io_hook = os_hooks->malloc(sizeof(vmm_io_hook_t));
81 io_hook->write = write;
85 io_hook->priv_data = priv_data;
87 add_io_hook(io_map, io_hook);
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);
99 remove_io_hook(io_map, hook);
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) {
116 void PrintDebugIOMap(vmm_io_map_t * io_map) {
117 vmm_io_hook_t * iter = io_map->head;
119 PrintDebug("VMM IO Map (Entries=%d)\n", io_map->num_ports);
122 PrintDebug("IO Port: %hu (Read=%x) (Write=%x)\n", iter->port, iter->read, iter->write);