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.


fixed configuration macro checks and a few configuration bugs
[palacios.git] / palacios / src / devices / io_apic.c
index 8eae20a..860cf8d 100644 (file)
  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
  */
 
-#include <devices/io_apic.h>
-#include <palacios/vmm.h>
 
+#include <palacios/vmm.h>
+#include <palacios/vmm_dev_mgr.h>
 #include <devices/apic.h>
 
-/*
-  #ifndef DEBUG_IO_APIC
-  #undef PrintDebug
-  #define PrintDebug(fmt, args...)
-  #endif
-*/
+
+#ifndef CONFIG_DEBUG_IO_APIC
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
+
 
 
 #define IO_APIC_BASE_ADDR 0xfec00000
@@ -182,7 +182,7 @@ static int ioapic_read(addr_t guest_addr, void * dst, uint_t length, void * priv
                break;
            default:
                {
-                   uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) & 0xfffffffe;
+                   uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) >> 1;
                    uint_t hi_val = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) % 1;
 
                    if (redir_index > 0x3f) {
@@ -227,7 +227,7 @@ static int ioapic_write(addr_t guest_addr, void * src, uint_t length, void * pri
                break;
            default:
                {
-                   uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) & 0xfffffffe;
+                   uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) >> 1;
                    uint_t hi_val = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) % 1;
 
 
@@ -273,7 +273,7 @@ static int ioapic_raise_irq(void * private_data, int irq) {
     struct redir_tbl_entry * irq_entry = NULL;
 
     if (irq > 24) {
-       PrintError("IRQ out of range of IO APIC\n");
+       PrintDebug("IRQ out of range of IO APIC\n");
        return -1;
     }
 
@@ -301,30 +301,17 @@ static struct intr_ctrl_ops intr_ops = {
 };
 
 
-static int io_apic_init(struct vm_device * dev) {
-    struct guest_info * info = dev->vm;
-    struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data);
 
-    v3_register_intr_controller(dev->vm, &intr_ops, dev);
-    init_ioapic_state(ioapic);
 
-    v3_hook_full_mem(info, ioapic->base_addr, ioapic->base_addr + PAGE_SIZE_4KB, 
-                    ioapic_read, ioapic_write, dev);
-  
-    return 0;
-}
-
-
-static int io_apic_deinit(struct vm_device * dev) {
+static int io_apic_free(struct vm_device * dev) {
     //  struct guest_info * info = dev->vm;
 
     return 0;
 }
 
 
-static struct vm_device_ops dev_ops = {
-    .init = io_apic_init, 
-    .deinit = io_apic_deinit,
+static struct v3_device_ops dev_ops = {
+    .free = io_apic_free,
     .reset = NULL,
     .start = NULL,
     .stop = NULL,
@@ -332,13 +319,37 @@ static struct vm_device_ops dev_ops = {
 
 
 
-struct vm_device * v3_create_io_apic(struct vm_device * apic) {
+static int ioapic_init(struct guest_info * vm, void * cfg_data) {
+    struct vm_device * apic = v3_find_dev(vm, (char *)cfg_data);
+
+    if (!apic) {
+       PrintError("Could not locate APIC device (%s)\n", (char *)cfg_data);
+       return -1;
+    }
+
     PrintDebug("Creating IO APIC\n");
 
     struct io_apic_state * ioapic = (struct io_apic_state *)V3_Malloc(sizeof(struct io_apic_state));
+
     ioapic->apic = apic;
 
-    struct vm_device * device = v3_create_device("IOAPIC", &dev_ops, ioapic);
+    struct vm_device * dev = v3_allocate_device("IOAPIC", &dev_ops, ioapic);
+
+
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", "IOAPIC");
+       return -1;
+    }
+
 
-    return device;
+    v3_register_intr_controller(vm, &intr_ops, dev);
+    init_ioapic_state(ioapic);
+
+    v3_hook_full_mem(vm, ioapic->base_addr, ioapic->base_addr + PAGE_SIZE_4KB, 
+                    ioapic_read, ioapic_write, dev);
+  
+    return 0;
 }
+
+
+device_register("IOAPIC", ioapic_init)