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.


deallocation of devices
[palacios.git] / palacios / src / devices / keyboard.c
index 43dd816..2aa4bec 100644 (file)
@@ -441,42 +441,8 @@ static int mouse_event_handler(struct v3_vm_info * vm,
 }
 
 
-static int keyboard_reset_device(struct keyboard_internal * kbd) {
-  
-    memset(kbd, 0, sizeof(struct keyboard_internal));
-
-    kbd->state = NORMAL;
-    kbd->mouse_state = STREAM;
 
 
-    // PS2, keyboard+mouse enabled, generic translation    
-    kbd->cmd.val = 0;
-
-    kbd->cmd.irq_en = 1;
-    kbd->cmd.mouse_irq_en = 1;
-    kbd->cmd.self_test_ok = 1;
-    /** **/
-
-
-    // buffers empty, no errors
-    kbd->status.val = 0; 
-
-    kbd->status.self_test_ok = 1; // self-tests passed
-    kbd->status.enabled = 1;// keyboard ready
-    /** **/
-
-    
-    kbd->output_byte = 0;  //  ?
-
-    kbd->input_byte = INPUT_RAM;  // we have some
-    // also display=color, jumper 0, keyboard enabled 
-
-    PrintDebug("keyboard: reset device\n");
-    return 0;
-
-}
-
 
 
 
@@ -991,17 +957,64 @@ static int keyboard_read_input(struct guest_info * core, ushort_t port, void * d
 
 
 
-static int keyboard_free(struct vm_device * dev) {
+static int keyboard_free(struct keyboard_internal * kbd) {
     
+
+    // unhook host events
+
+    V3_Free(kbd);
     return 0;
 }
 
 
 
 
+static int keyboard_reset_device(struct keyboard_internal * kbd) {
+  
+
+    kbd->mouse_queue.start = 0;
+    kbd->mouse_queue.end = 0;
+    kbd->mouse_queue.count = 0;
+
+    kbd->kbd_queue.start = 0;
+    kbd->kbd_queue.end = 0;
+    kbd->kbd_queue.count = 0;
+
+    kbd->mouse_enabled = 0;
+
+    kbd->state = NORMAL;
+    kbd->mouse_state = STREAM;
+
+    // PS2, keyboard+mouse enabled, generic translation    
+    kbd->cmd.val = 0;
+
+    kbd->cmd.irq_en = 1;
+    kbd->cmd.mouse_irq_en = 1;
+    kbd->cmd.self_test_ok = 1;
+    /** **/
+
+
+    // buffers empty, no errors
+    kbd->status.val = 0; 
+
+    kbd->status.self_test_ok = 1; // self-tests passed
+    kbd->status.enabled = 1;// keyboard ready
+    /** **/
+
+    
+    kbd->output_byte = 0;  //  ?
+
+    kbd->input_byte = INPUT_RAM;  // we have some
+    // also display=color, jumper 0, keyboard enabled 
+
+    PrintDebug("keyboard: reset device\n");
+    return 0;
+
+}
 
 static struct v3_device_ops dev_ops = { 
-    .free = keyboard_free,
+    .free = (int (*)(void *))keyboard_free,
 
 };
 
@@ -1011,6 +1024,7 @@ static struct v3_device_ops dev_ops = {
 static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct keyboard_internal * kbd = NULL;
     char * dev_id = v3_cfg_val(cfg, "ID");
+    int ret = 0;
 
     PrintDebug("keyboard: init_device\n");
 
@@ -1020,20 +1034,11 @@ static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
     kbd->vm = vm;
 
-    kbd->mouse_queue.start = 0;
-    kbd->mouse_queue.end = 0;
-    kbd->mouse_queue.count = 0;
-
-    kbd->kbd_queue.start = 0;
-    kbd->kbd_queue.end = 0;
-    kbd->kbd_queue.count = 0;
+    struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, kbd);
 
-    kbd->mouse_enabled = 0;
-
-    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, kbd);
-
-    if (v3_attach_device(vm, dev) == -1) {
+    if (dev == NULL) {
        PrintError("Could not attach device %s\n", dev_id);
+       V3_Free(kbd);
        return -1;
     }
 
@@ -1044,11 +1049,17 @@ static int keyboard_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
 
     // hook ports
-    v3_dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command);
-    v3_dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output);
+    ret |= v3_dev_hook_io(dev, KEYBOARD_64H, &keyboard_read_status, &keyboard_write_command);
+    ret |= v3_dev_hook_io(dev, KEYBOARD_60H, &keyboard_read_input, &keyboard_write_output);
+
+    if (ret != 0) {
+       PrintError("Error hooking keyboard IO ports\n");
+       v3_remove_device(dev);
+       return -1;
+    }
 
-    v3_hook_host_event(vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), dev);
-    v3_hook_host_event(vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), dev);
+    v3_hook_host_event(vm, HOST_KEYBOARD_EVT, V3_HOST_EVENT_HANDLER(key_event_handler), kbd);
+    v3_hook_host_event(vm, HOST_MOUSE_EVT, V3_HOST_EVENT_HANDLER(mouse_event_handler), kbd);
 
 
 #if KEYBOARD_DEBUG_80H