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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22 #include <palacios/vm_guest.h>
24 int v3_init_host_events(struct v3_vm_info * vm) {
25 struct v3_host_events * host_evts = &(vm->host_event_hooks);
27 INIT_LIST_HEAD(&(host_evts->keyboard_events));
28 INIT_LIST_HEAD(&(host_evts->mouse_events));
29 INIT_LIST_HEAD(&(host_evts->timer_events));
30 INIT_LIST_HEAD(&(host_evts->serial_events));
31 INIT_LIST_HEAD(&(host_evts->console_events));
32 INIT_LIST_HEAD(&(host_evts->packet_events));
37 int v3_deinit_host_events(struct v3_vm_info * vm) {
38 struct v3_host_events * host_evts = &(vm->host_event_hooks);
39 struct v3_host_event_hook * hook = NULL;
40 struct v3_host_event_hook * tmp = NULL;
42 list_for_each_entry_safe(hook, tmp, &(host_evts->keyboard_events), link) {
43 list_del(&(hook->link));
47 list_for_each_entry_safe(hook, tmp, &(host_evts->mouse_events), link) {
48 list_del(&(hook->link));
53 list_for_each_entry_safe(hook, tmp, &(host_evts->timer_events), link) {
54 list_del(&(hook->link));
59 list_for_each_entry_safe(hook, tmp, &(host_evts->serial_events), link) {
60 list_del(&(hook->link));
65 list_for_each_entry_safe(hook, tmp, &(host_evts->console_events), link) {
66 list_del(&(hook->link));
71 list_for_each_entry_safe(hook, tmp, &(host_evts->packet_events), link) {
72 list_del(&(hook->link));
80 int v3_hook_host_event(struct v3_vm_info * vm,
81 v3_host_evt_type_t event_type,
82 union v3_host_event_handler cb,
83 void * private_data) {
85 struct v3_host_events * host_evts = &(vm->host_event_hooks);
86 struct v3_host_event_hook * hook = NULL;
88 hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
90 PrintError("Could not allocate event hook\n");
95 hook->private_data = private_data;
98 case HOST_KEYBOARD_EVT:
99 list_add(&(hook->link), &(host_evts->keyboard_events));
102 list_add(&(hook->link), &(host_evts->mouse_events));
105 list_add(&(hook->link), &(host_evts->timer_events));
107 case HOST_SERIAL_EVT:
108 list_add(&(hook->link), &(host_evts->serial_events));
110 case HOST_CONSOLE_EVT:
111 list_add(&(hook->link), &(host_evts->console_events));
113 case HOST_PACKET_EVT:
114 list_add(&(hook->link), &(host_evts->packet_events));
122 int v3_deliver_keyboard_event(struct v3_vm_info * vm,
123 struct v3_keyboard_event * evt) {
124 struct v3_host_events * host_evts = NULL;
125 struct v3_host_event_hook * hook = NULL;
128 host_evts = &(vm->host_event_hooks);
130 if (vm->run_state != VM_RUNNING) {
134 list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
135 if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
144 int v3_deliver_mouse_event(struct v3_vm_info * vm,
145 struct v3_mouse_event * evt) {
146 struct v3_host_events * host_evts = NULL;
147 struct v3_host_event_hook * hook = NULL;
150 host_evts = &(vm->host_event_hooks);
152 if (vm->run_state != VM_RUNNING) {
156 list_for_each_entry(hook, &(host_evts->mouse_events), link) {
157 if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
166 int v3_deliver_timer_event(struct v3_vm_info * vm,
167 struct v3_timer_event * evt) {
168 struct v3_host_events * host_evts = NULL;
169 struct v3_host_event_hook * hook = NULL;
172 host_evts = &(vm->host_event_hooks);
174 if (vm->run_state != VM_RUNNING) {
178 list_for_each_entry(hook, &(host_evts->timer_events), link) {
179 if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
187 int v3_deliver_serial_event(struct v3_vm_info * vm,
188 struct v3_serial_event * evt) {
189 struct v3_host_events * host_evts = NULL;
190 struct v3_host_event_hook * hook = NULL;
193 host_evts = &(vm->host_event_hooks);
195 if (vm->run_state != VM_RUNNING) {
199 list_for_each_entry(hook, &(host_evts->serial_events), link) {
200 if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
210 int v3_deliver_console_event(struct v3_vm_info * vm,
211 struct v3_console_event * evt) {
212 struct v3_host_events * host_evts = NULL;
213 struct v3_host_event_hook * hook = NULL;
216 host_evts = &(vm->host_event_hooks);
218 if (vm->run_state != VM_RUNNING) {
222 list_for_each_entry(hook, &(host_evts->console_events), link) {
223 if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
232 int v3_deliver_packet_event(struct v3_vm_info * vm,
233 struct v3_packet_event * evt) {
234 struct v3_host_events * host_evts = NULL;
235 struct v3_host_event_hook * hook = NULL;
238 host_evts = &(vm->host_event_hooks);
240 if (vm->run_state != VM_RUNNING) {
244 list_for_each_entry(hook, &(host_evts->packet_events), link) {
245 if (hook->cb.packet_handler(vm, evt, hook->private_data) == -1) {