From: Jack Lange Date: Wed, 15 Oct 2008 02:21:36 +0000 (-0500) Subject: added host event hooks interface X-Git-Tag: 1.0^2~51 X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=82cceefa66b1f05d8f9d5bfcb2fb7214755e1904 added host event hooks interface --- diff --git a/palacios/build/Makefile b/palacios/build/Makefile index 7a4c23d..9f05bf9 100644 --- a/palacios/build/Makefile +++ b/palacios/build/Makefile @@ -241,6 +241,7 @@ VMM_C_SRCS := vm_guest.c \ svm_halt.c svm_pause.c svm_wbinvd.c \ vmm_config.c vmm_hashtable.c \ vmm_string.c vmm_emulator.c vmm_queue.c\ + vmm_host_events.c \ $(DECODER_SRCS) # vmx.c vmcs_gen.c vmcs.c diff --git a/palacios/include/palacios/vm_guest.h b/palacios/include/palacios/vm_guest.h index 1bd6a8d..c3a97d8 100644 --- a/palacios/include/palacios/vm_guest.h +++ b/palacios/include/palacios/vm_guest.h @@ -31,6 +31,7 @@ #include #include #include +#include typedef ullong_t v3_reg_t; @@ -143,6 +144,8 @@ struct guest_info { struct vmm_dev_mgr dev_mgr; + struct v3_host_events host_event_hooks; + vm_cpu_mode_t cpu_mode; vm_mem_mode_t mem_mode; diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index ad139e8..ecad47f 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -266,7 +266,7 @@ struct v3_interrupt { void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops); int v3_deliver_irq(struct guest_info * vm, struct v3_interrupt * intr); - +int v3_deliver_keyboard_evt(struct guest_info * vm); #endif diff --git a/palacios/include/palacios/vmm_host_events.h b/palacios/include/palacios/vmm_host_events.h new file mode 100644 index 0000000..7459501 --- /dev/null +++ b/palacios/include/palacios/vmm_host_events.h @@ -0,0 +1,88 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __VMM_HOST_EVENTS_H__ +#define __VMM_HOST_EVENTS_H__ + + +struct v3_keyboard_event { + unsigned char status; + unsigned char scan_code; +}; + +struct v3_mouse_event { + unsigned char data[3]; +}; + + +struct v3_timer_event { + +}; + +#ifdef __V3VEE__ + +#include + + +typedef enum {HOST_KEYBOARD_EVT, + HOST_MOUSE_EVT, + HOST_TIMER_EVT} v3_host_evt_type_t; + + +union v3_host_event_handler { + int (*keyboard_handler)(struct guest_info * info, struct v3_keyboard_event * evt, void * priv_data); + int (*mouse_handler)(struct guest_info * info, struct v3_mouse_event * evt, void * priv_data); + int (*timer_handler)(struct guest_info * info, struct v3_timer_event * evt, void * priv_data); +}; + + +struct v3_host_event_hook { + union v3_host_event_handler cb; + void * private_data; + struct list_head link; +}; + + + +struct v3_host_events { + struct list_head keyboard_events; + struct list_head mouse_events; + struct list_head timer_events; +}; + + + +int v3_init_host_events(struct guest_info * info); + +#define V3_HOST_EVENT_HANDLER(cb) ((union v3_host_event_callback)cb) + +int v3_hook_host_event(struct guest_info * info, + v3_host_evt_type_t event_type, + union v3_host_event_handler cb, + void * private_data); + +#endif // ! __V3VEE__ + +int v3_deliver_keyboard_event(struct guest_info * info, struct v3_keyboard_event * evt); +int v3_deliver_mouse_event(struct guest_info * info, struct v3_mouse_event * evt); +int v3_deliver_timer_event(struct guest_info * info, struct v3_timer_event * evt); + + + +#endif diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index 29485be..ed00282 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -337,7 +337,15 @@ static struct vm_device *demultiplex_injected_mouse(uchar_t mouse_packet[3]) return thekeyboard; } -int keyboard_interrupt(uint_t irq, struct vm_device * dev); + +int keyboard_interrupt(uint_t irq, struct vm_device * dev) { + PrintDebug("keyboard: interrupt 0x%x\n", irq); + + dev->vm->vm_ops.raise_irq(dev->vm, irq); + + return 0; + +} void deliver_key_to_vmm(uchar_t status, uchar_t scancode) { @@ -1141,15 +1149,7 @@ int keyboard_read_input(ushort_t port, } -int keyboard_interrupt(uint_t irq, struct vm_device * dev) -{ - PrintDebug("keyboard: interrupt 0x%x\n", irq); - - dev->vm->vm_ops.raise_irq(dev->vm, irq); - return 0; - -} int keyboard_init_device(struct vm_device * dev) diff --git a/palacios/src/palacios/vmm_dev_mgr.c b/palacios/src/palacios/vmm_dev_mgr.c index bc9a940..258e858 100644 --- a/palacios/src/palacios/vmm_dev_mgr.c +++ b/palacios/src/palacios/vmm_dev_mgr.c @@ -108,7 +108,7 @@ int dev_remove_io_hook(struct vm_device * dev, struct dev_io_hook * hook) { struct dev_io_hook * dev_mgr_find_io_hook(struct vmm_dev_mgr * mgr, ushort_t port) { - struct dev_io_hook * tmp; + struct dev_io_hook * tmp = NULL; list_for_each_entry(tmp, &(mgr->io_hooks), mgr_list) { if (tmp->port == port) { @@ -119,7 +119,7 @@ struct dev_io_hook * dev_mgr_find_io_hook(struct vmm_dev_mgr * mgr, ushort_t por } struct dev_io_hook * dev_find_io_hook(struct vm_device * dev, ushort_t port) { - struct dev_io_hook * tmp; + struct dev_io_hook * tmp = NULL; list_for_each_entry(tmp, &(dev->io_hooks), dev_list) { if (tmp->port == port) { diff --git a/palacios/src/palacios/vmm_host_events.c b/palacios/src/palacios/vmm_host_events.c new file mode 100644 index 0000000..b9d122a --- /dev/null +++ b/palacios/src/palacios/vmm_host_events.c @@ -0,0 +1,110 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include + + +int v3_init_host_events(struct guest_info * info) { + struct v3_host_events * host_evts = &(info->host_event_hooks); + + INIT_LIST_HEAD(&(host_evts->keyboard_events)); + INIT_LIST_HEAD(&(host_evts->mouse_events)); + INIT_LIST_HEAD(&(host_evts->timer_events)); + + return 0; +} + + +int v3_hook_host_event(struct guest_info * info, + v3_host_evt_type_t event_type, + union v3_host_event_handler cb, + void * private_data) { + + struct v3_host_events * host_evts = &(info->host_event_hooks); + struct v3_host_event_hook * hook = NULL; + + hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook)); + if (hook == NULL) { + PrintError("Could not allocate event hook\n"); + return -1; + } + + hook->cb = cb; + hook->private_data = private_data; + + switch (event_type) { + case HOST_KEYBOARD_EVT: + list_add(&(hook->link), &(host_evts->keyboard_events)); + break; + case HOST_MOUSE_EVT: + list_add(&(hook->link), &(host_evts->mouse_events)); + break; + case HOST_TIMER_EVT: + list_add(&(hook->link), &(host_evts->timer_events)); + break; + } + + return 0; +} + + +int v3_deliver_keyboard_event(struct guest_info * info, + struct v3_keyboard_event * evt) { + struct v3_host_events * host_evts = &(info->host_event_hooks); + struct v3_host_event_hook * hook = NULL; + + list_for_each_entry(hook, &(host_evts->keyboard_events), link) { + if (hook->cb.keyboard_handler(info, evt, hook->private_data) == -1) { + return -1; + } + } + + return 0; +} + + +int v3_deliver_mouse_event(struct guest_info * info, + struct v3_mouse_event * evt) { + struct v3_host_events * host_evts = &(info->host_event_hooks); + struct v3_host_event_hook * hook = NULL; + + list_for_each_entry(hook, &(host_evts->mouse_events), link) { + if (hook->cb.mouse_handler(info, evt, hook->private_data) == -1) { + return -1; + } + } + + return 0; +} + + +int v3_deliver_timer_event(struct guest_info * info, + struct v3_timer_event * evt) { + struct v3_host_events * host_evts = &(info->host_event_hooks); + struct v3_host_event_hook * hook = NULL; + + list_for_each_entry(hook, &(host_evts->timer_events), link) { + if (hook->cb.timer_handler(info, evt, hook->private_data) == -1) { + return -1; + } + } + + return 0; +}