From: Jack Lange <jarusl@cs.northwestern.edu>
Date: Fri, 6 Feb 2009 06:16:24 +0000 (-0600)
Subject: added APIC device
X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=6c56ead58f57e08c23eab5d67f2a58f95ce712b4;p=palacios.releases.git

added APIC device
---

diff --git a/palacios/build/Makefile b/palacios/build/Makefile
index aabd894..abf8008 100644
--- a/palacios/build/Makefile
+++ b/palacios/build/Makefile
@@ -297,6 +297,7 @@ DEVICES_OBJS := \
 	devices/cdrom.o \
 	devices/bochs_debug.o \
 	devices/os_debug.o \
+	devices/apic.o	\
 
 $(DEVICES_OBJS) :: EXTRA_CFLAGS = \
 	$(JRLDEBUG) \
diff --git a/palacios/include/devices/apic.h b/palacios/include/devices/apic.h
new file mode 100644
index 0000000..2858b24
--- /dev/null
+++ b/palacios/include/devices/apic.h
@@ -0,0 +1,31 @@
+/* 
+ * 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 <jarusl@cs.northwestern.edu> 
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#ifndef __DEVICES_APIC_H__
+#define __DEVICES_APIC_H__
+
+#ifdef __V3VEE__
+
+#include <palacios/vm_dev.h>
+
+struct vm_device * v3_create_apic();
+
+
+#endif // ! __V3VEE__
+#endif
diff --git a/palacios/include/palacios/vmm_msr.h b/palacios/include/palacios/vmm_msr.h
index ed58d9b..5d3d2eb 100644
--- a/palacios/include/palacios/vmm_msr.h
+++ b/palacios/include/palacios/vmm_msr.h
@@ -41,6 +41,9 @@ struct v3_msr {
 } __attribute__((packed));
 
 
+
+typedef struct v3_msr v3_msr_t;
+
 struct v3_msr_hook {
   uint_t msr;
   
diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c
new file mode 100644
index 0000000..8f4b8fe
--- /dev/null
+++ b/palacios/src/devices/apic.c
@@ -0,0 +1,89 @@
+/* 
+ * 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 <jarusl@cs.northwestern.edu> 
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+
+#include <devices/apic.h>
+#include <palacios/vmm.h>
+#include <palacios/vmm_msr.h>
+
+#define BASE_ADDR_MSR 0x0000001B
+
+
+struct apic_state {
+  v3_msr_t base_addr_reg;
+
+};
+
+
+static int read_base_addr(uint_t msr, v3_msr_t * dst, void * priv_data) {
+  struct vm_device * dev = (struct vm_device *)priv_data;
+  struct apic_state * apic = (struct apic_state *)dev->private_data;
+  PrintDebug("READING APIC BASE ADDR: HI=%x LO=%x\n", apic->base_addr_reg.hi, apic->base_addr_reg.lo);
+
+  return -1;
+}
+
+
+static int write_base_addr(uint_t msr, v3_msr_t src, void * priv_data) {
+  //  struct vm_device * dev = (struct vm_device *)priv_data;
+  //  struct apic_state * apic = (struct apic_state *)dev->private_data;
+
+  PrintDebug("WRITING APIC BASE ADDR: HI=%x LO=%x\n", src.hi, src.lo);
+
+  return -1;
+}
+
+
+static int apic_deinit(struct vm_device * dev) {
+  struct guest_info * info = dev->vm;
+
+  v3_unhook_msr(info, BASE_ADDR_MSR);
+
+  return 0;
+}
+
+
+static int apic_init(struct vm_device * dev) {
+  struct guest_info * info = dev->vm;
+
+  v3_hook_msr(info, BASE_ADDR_MSR, read_base_addr, write_base_addr, dev);
+
+  return 0;
+}
+
+
+
+static struct vm_device_ops dev_ops = {
+  .init = apic_init,
+  .deinit = apic_deinit,
+  .reset = NULL,
+  .start = NULL,
+  .stop = NULL,
+};
+
+
+struct vm_device * v3_create_apic() {
+  PrintDebug("Creating APIC\n");
+
+  struct apic_state * apic = (struct apic_state *)V3_Malloc(sizeof(struct apic_state));
+
+  struct vm_device * device = v3_create_device("APIC", &dev_ops, apic);
+  
+  return device;
+}
diff --git a/palacios/src/palacios/vmm_config.c b/palacios/src/palacios/vmm_config.c
index 9362504..9424573 100644
--- a/palacios/src/palacios/vmm_config.c
+++ b/palacios/src/palacios/vmm_config.c
@@ -35,6 +35,7 @@
 #include <devices/cdrom.h>
 #include <devices/bochs_debug.h>
 #include <devices/os_debug.h>
+#include <devices/apic.h>
 
 
 
@@ -196,7 +197,7 @@ static int setup_memory_map(struct guest_info * info, struct v3_vm_config * conf
   v3_add_shadow_mem(info, 0x1000000, 0x8000000, (addr_t)V3_AllocPages(32768));
  
   // test - give linux accesss to PCI space - PAD
-  // v3_add_shadow_mem(info, 0xc0000000,0xffffffff,0xc0000000);
+  //v3_add_shadow_mem(info, 0xc0000000,0xffffffff,0xc0000000);
   
   
   print_shadow_map(info);
@@ -216,6 +217,7 @@ static int setup_devices(struct guest_info * info, struct v3_vm_config * config_
     struct vm_device * pit = v3_create_pit(); 
     struct vm_device * bochs_debug = v3_create_bochs_debug();
     struct vm_device * os_debug = v3_create_os_debug();
+    struct vm_device * apic = v3_create_apic();
 
     //struct vm_device * serial = v3_create_serial();
     struct vm_device * generic = NULL;
@@ -245,6 +247,8 @@ static int setup_devices(struct guest_info * info, struct v3_vm_config * config_
     v3_attach_device(info, bochs_debug);
     v3_attach_device(info, os_debug);
 
+    v3_attach_device(info, apic);
+
     if (use_ramdisk) {
       v3_attach_device(info, ramdisk);
       v3_attach_device(info, cdrom);