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.


add raw packet interface
[palacios.git] / palacios / src / palacios / vmm_host_events.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_muxer.h>
24
25 int v3_init_host_events(struct v3_vm_info * vm) {
26     struct v3_host_events * host_evts = &(vm->host_event_hooks);
27
28     INIT_LIST_HEAD(&(host_evts->keyboard_events));
29     INIT_LIST_HEAD(&(host_evts->mouse_events));
30     INIT_LIST_HEAD(&(host_evts->timer_events));
31     INIT_LIST_HEAD(&(host_evts->serial_events));
32     INIT_LIST_HEAD(&(host_evts->console_events));
33     INIT_LIST_HEAD(&(host_evts->packet_events));
34
35     return 0;
36 }
37
38
39 int v3_hook_host_event(struct v3_vm_info * vm, 
40                        v3_host_evt_type_t event_type, 
41                        union v3_host_event_handler cb, 
42                        void * private_data) {
43   
44     struct v3_host_events * host_evts = &(vm->host_event_hooks);
45     struct v3_host_event_hook * hook = NULL;
46
47     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
48     if (hook == NULL) {
49         PrintError("Could not allocate event hook\n");
50         return -1;
51     }
52
53     hook->cb = cb;
54     hook->private_data = private_data;
55
56     switch (event_type)  {
57         case HOST_KEYBOARD_EVT:
58             list_add(&(hook->link), &(host_evts->keyboard_events));
59             break;
60         case HOST_MOUSE_EVT:
61             list_add(&(hook->link), &(host_evts->mouse_events));
62             break;
63         case HOST_TIMER_EVT:
64             list_add(&(hook->link), &(host_evts->timer_events));
65             break;
66         case HOST_SERIAL_EVT:
67             list_add(&(hook->link), &(host_evts->serial_events));
68             break;
69         case HOST_CONSOLE_EVT:
70             list_add(&(hook->link), &(host_evts->console_events));
71             break;
72         case HOST_PACKET_EVT:
73             list_add(&(hook->link), &(host_evts->packet_events));
74             break;
75     }
76
77     return 0;
78 }
79
80
81 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
82                               struct v3_keyboard_event * evt) {
83     struct v3_host_events * host_evts = NULL;
84     struct v3_host_event_hook * hook = NULL;
85
86     if (vm == NULL) {
87         vm = v3_get_foreground_vm();
88     }
89
90     host_evts = &(vm->host_event_hooks);
91
92     if (vm->run_state != VM_RUNNING) {
93         return -1;
94     }
95
96     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
97         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
98             return -1;
99         }
100     }
101
102     return 0;
103 }
104
105
106 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
107                            struct v3_mouse_event * evt) {
108     struct v3_host_events * host_evts = NULL;
109     struct v3_host_event_hook * hook = NULL;
110
111     if (vm == NULL) {
112         vm = v3_get_foreground_vm();
113     }
114
115     host_evts = &(vm->host_event_hooks);
116
117     if (vm->run_state != VM_RUNNING) {
118         return -1;
119     }
120
121     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
122         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
123             return -1;
124         }
125     }
126
127     return 0;
128 }
129
130
131 int v3_deliver_timer_event(struct v3_vm_info * vm, 
132                            struct v3_timer_event * evt) {
133     struct v3_host_events * host_evts = NULL;
134     struct v3_host_event_hook * hook = NULL;
135
136     if (vm == NULL) {
137         vm = v3_get_foreground_vm();
138     }
139
140     host_evts = &(vm->host_event_hooks);
141
142     if (vm->run_state != VM_RUNNING) {
143         return -1;
144     }
145
146     list_for_each_entry(hook, &(host_evts->timer_events), link) {
147         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
148             return -1;
149         }
150     }
151
152     return 0;
153 }
154
155 int v3_deliver_serial_event(struct v3_vm_info * vm, 
156                             struct v3_serial_event * evt) {
157     struct v3_host_events * host_evts = NULL;
158     struct v3_host_event_hook * hook = NULL;
159
160     if (vm == NULL) {
161         vm = v3_get_foreground_vm();
162     }
163
164     host_evts = &(vm->host_event_hooks);
165
166     if (vm->run_state != VM_RUNNING) {
167         return -1;
168     }
169
170     list_for_each_entry(hook, &(host_evts->serial_events), link) {
171         if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
172             return -1;
173         }
174     }
175
176     return 0;
177 }
178
179
180
181 int v3_deliver_console_event(struct v3_vm_info * vm, 
182                              struct v3_console_event * evt) {
183     struct v3_host_events * host_evts = NULL;
184     struct v3_host_event_hook * hook = NULL;
185
186     if (vm == NULL) {
187         vm = v3_get_foreground_vm();
188     }
189
190     host_evts = &(vm->host_event_hooks);
191
192     if (vm->run_state != VM_RUNNING) {
193         return -1;
194     }
195
196     list_for_each_entry(hook, &(host_evts->console_events), link) {
197         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
198             return -1;
199         }
200     }
201
202     return 0;
203 }
204
205
206 int v3_deliver_packet_event(struct v3_vm_info * vm, 
207                              struct v3_packet_event * evt) {
208     struct v3_host_events * host_evts = NULL;
209     struct v3_host_event_hook * hook = NULL;
210
211     if (vm == NULL) {
212         vm = v3_get_foreground_vm();
213     }
214
215     host_evts = &(vm->host_event_hooks);
216
217     if (vm->run_state != VM_RUNNING) {
218         return -1;
219     }
220
221     list_for_each_entry(hook, &(host_evts->packet_events), link) {
222         if (hook->cb.packet_handler(vm, evt, hook->private_data) == -1) {
223             return -1;
224         }
225     }
226
227     return 0;
228 }
229
230
231