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.


updated devices to use new host event interface
[palacios.git] / palacios / src / devices / keyboard.c
index 39accf5..3d52f4e 100644 (file)
@@ -1,8 +1,23 @@
-/* Northwestern University */
-/* (c) 2008, Peter Dinda <pdinda@cs.northwestern.edu> */
+/* 
+ * 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, Peter Dinda <pdinda@northwestern.edu> 
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Peter Dinda <pdinda@northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
 
 #include <devices/keyboard.h>
-#include <geekos/io.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_types.h>
 
@@ -83,8 +98,6 @@
 #define MOUSE               1
 
 
-// The currently targetted keyboard
-static struct vm_device * thekeyboard = NULL;
 
 //#define QUEUE_SIZE          32
 
@@ -310,49 +323,52 @@ static int PullFromInputQueue(struct vm_device *dev, uchar_t *value)
 
 #endif
 
-static struct vm_device *demultiplex_injected_key(uchar_t status, uchar_t scancode)
-{
-  // this currently does nothing
-  return thekeyboard;
-}
 
-static struct vm_device *demultiplex_injected_mouse(uchar_t mouse_packet[3])
-{
-  // this currently does nothing
-  return thekeyboard;
+
+
+int keyboard_interrupt(struct vm_device * dev, uint_t irq) {
+  PrintDebug("keyboard: interrupt 0x%x\n", irq);
+
+  v3_raise_irq(dev->vm, irq);
+
+  return 0;
+
 }
 
-int keyboard_interrupt(uint_t irq, struct vm_device * dev);
 
-void deliver_key_to_vmm(uchar_t status, uchar_t scancode)
-{
-  struct vm_device *dev = demultiplex_injected_key(status, scancode);
+
+int key_event_handler(struct guest_info * info, 
+                      struct v3_keyboard_event * evt, 
+                      void * private_data) {
+  struct vm_device * dev = (struct vm_device *)private_data;
   struct keyboard_internal *state = (struct keyboard_internal *)(dev->private_data);
 
-  PrintDebug("keyboard: injected status 0x%x, and scancode 0x%x\n", status, scancode);
+  PrintDebug("keyboard: injected status 0x%x, and scancode 0x%x\n", evt->status, evt->scan_code);
   
   if ( (state->status_byte & STATUS_ENABLED)      // onboard is enabled
        && (!(state->cmd_byte & CMD_DISABLE)) )  {   // keyboard is enabled
-
-    PushToOutputQueue(dev, scancode, OVERWRITE, DATA, KEYBOARD);
-
+    
+    PushToOutputQueue(dev, evt->scan_code, OVERWRITE, DATA, KEYBOARD);
+    
     if (state->cmd_byte & CMD_INTR) { 
-      keyboard_interrupt(KEYBOARD_IRQ, dev);
+      keyboard_interrupt(dev, KEYBOARD_IRQ);
     }
-       
   }
+  
+  return 0;
 }
 
 
-void deliver_mouse_to_vmm(uchar_t data[3])
-{
-  struct vm_device * dev = demultiplex_injected_mouse(data);
+int mouse_event_handler(struct guest_info * info, 
+                        struct v3_mouse_event * evt, 
+                        void * private_data) {
+  struct vm_device * dev = (struct vm_device *)private_data;
   struct keyboard_internal * state = (struct keyboard_internal *)(dev->private_data);
 
   PrintDebug("keyboard: injected mouse packet 0x %x %x %x\n",
-            data[0], data[1], data[2]);
+            evt->data[0], evt->data[1], evt->data[2]);
   
-  memcpy(state->mouse_packet, data, 3);
+  memcpy(state->mouse_packet, evt->data, 3);
   
   state->status_byte |= STATUS_MOUSE_BUFFER_FULL;
   
@@ -362,13 +378,15 @@ void deliver_mouse_to_vmm(uchar_t data[3])
   case STREAM2:
   case STREAM3:
     if (!(state->cmd_byte & CMD_MOUSE_DISABLE)) { 
-      keyboard_interrupt(MOUSE_IRQ, dev);
+      keyboard_interrupt(dev, MOUSE_IRQ);
     }
     break;
   default:
+    return -1;
     break;
   }
 
+  return 0;
 }
 
 
@@ -751,7 +769,7 @@ int keyboard_read_delay(ushort_t port,
 {
 
   if (length == 1) { 
-    *((uchar_t*)dest) = In_Byte(port);
+    *((uchar_t*)dest) = v3_inb(port);
 
     PrintDebug("keyboard: read of 0x%x from 80h\n", *((uchar_t*)dest));
 
@@ -1126,15 +1144,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) 
@@ -1152,6 +1162,10 @@ int keyboard_init_device(struct vm_device * dev)
   dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command);
   dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output);
 
+  v3_hook_host_event(dev->vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), dev);
+  v3_hook_host_event(dev->vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), dev);
+
+
 #if KEYBOARD_DEBUG_80H
   dev_hook_io(dev, KEYBOARD_DELAY_80H, &keyboard_read_delay, &keyboard_write_delay);
 #endif
@@ -1193,16 +1207,12 @@ static struct vm_device_ops dev_ops = {
 
 
 struct vm_device *create_keyboard() {
-  
-  if (thekeyboard != NULL) { 
-    PrintDebug("keyboard: creating >1 keyboard device.  This will probably fail!\n");
-  }
-  
-  struct keyboard_internal * keyboard_state = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal));
+  struct keyboard_internal * keyboard_state = NULL;
+
+  keyboard_state = (struct keyboard_internal *)V3_Malloc(sizeof(struct keyboard_internal));
 
   struct vm_device *device = create_device("KEYBOARD", &dev_ops, keyboard_state);
 
-  thekeyboard = device;
-  
+
   return device;
 }