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 ed00282..3d52f4e 100644 (file)
@@ -98,8 +98,6 @@
 #define MOUSE               1
 
 
-// The currently targetted keyboard
-static struct vm_device * thekeyboard = NULL;
 
 //#define QUEUE_SIZE          32
 
@@ -325,57 +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(uint_t irq, struct vm_device * dev) {
+int keyboard_interrupt(struct vm_device * dev, uint_t irq) {
   PrintDebug("keyboard: interrupt 0x%x\n", irq);
 
-  dev->vm->vm_ops.raise_irq(dev->vm, irq);
+  v3_raise_irq(dev->vm, irq);
 
   return 0;
 
 }
 
-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;
   
@@ -385,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;
 }
 
 
@@ -1167,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
@@ -1208,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;
 }