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.


Update on the VNET Bridge virtio device
[palacios.git] / palacios / src / devices / nvram.c
index f43cbd0..fb9b319 100644 (file)
  */
 
 
-#include <devices/nvram.h>
+#include <palacios/vmm_dev_mgr.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_types.h>
 
 #include <palacios/vmm_lock.h>
 
 #include <devices/ide.h>
+#include <palacios/vmm_intr.h>
+#include <palacios/vmm_host_events.h>
+#include <palacios/vm_guest.h>
 
-#ifndef DEBUG_NVRAM
+#ifndef CONFIG_DEBUG_NVRAM
 #undef PrintDebug
 #define PrintDebug(fmt, args...)
 #endif
@@ -454,7 +457,7 @@ static void update_time( struct vm_device * dev, uint_t period_us) {
 }
 
 
-static int handle_timer_event(struct guest_info * info, 
+static int handle_timer_event(struct v3_vm_info * vm, 
                              struct v3_timer_event * evt, 
                              void * priv_data) {
 
@@ -589,8 +592,8 @@ static void init_harddrives(struct nvram_internal * nvram) {
     }
 }
 
-static int init_nvram_state(struct vm_device * dev) {
-    struct guest_info * info = dev->vm;
+static int init_nvram_state(struct v3_vm_info * vm, struct vm_device * dev) {
+
     struct nvram_internal * nvram = (struct nvram_internal *)dev->private_data;
   
     memset(nvram->mem_state, 0, NVRAM_REG_MAX);
@@ -669,7 +672,7 @@ static int init_nvram_state(struct vm_device * dev) {
     nvram->us = 0;
     nvram->pus = 0;
 
-    set_memory_size(nvram, info->mem_size);
+    set_memory_size(nvram, vm->mem_size);
     init_harddrives(nvram);
     
     nvram->dev_state = NVRAM_READY;
@@ -704,10 +707,8 @@ static int nvram_stop_device(struct vm_device * dev) {
 
 
 
-static int nvram_write_reg_port(ushort_t port,
-                               void * src, 
-                               uint_t length,
-                               struct vm_device * dev) {
+static int nvram_write_reg_port(struct guest_info * core, ushort_t port,
+                               void * src, uint_t length, struct vm_device * dev) {
 
     struct nvram_internal * data = (struct nvram_internal *)dev->private_data;
     
@@ -717,10 +718,8 @@ static int nvram_write_reg_port(ushort_t port,
     return 1;
 }
 
-static int nvram_read_data_port(ushort_t port,
-                               void * dst, 
-                               uint_t length,
-                               struct vm_device * dev) {
+static int nvram_read_data_port(struct guest_info * core, ushort_t port,
+                               void * dst, uint_t length, struct vm_device * dev) {
 
     struct nvram_internal * data = (struct nvram_internal *)dev->private_data;
 
@@ -747,10 +746,8 @@ static int nvram_read_data_port(ushort_t port,
 }
 
 
-static int nvram_write_data_port(ushort_t port,
-                                void * src, 
-                                uint_t length,
-                                struct vm_device * dev) {
+static int nvram_write_data_port(struct guest_info * core, ushort_t port,
+                                void * src, uint_t length, struct vm_device * dev) {
 
     struct nvram_internal * data = (struct nvram_internal *)dev->private_data;
 
@@ -768,25 +765,11 @@ static int nvram_write_data_port(ushort_t port,
 
 
 
-static int nvram_init_device(struct vm_device * dev) {
-    PrintDebug("nvram: init_device\n");
-
-    init_nvram_state(dev);
-
-    // hook ports
-    v3_dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port);
-    v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port);
-  
-    v3_hook_host_event(dev->vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), dev);
-
-    return 0;
-}
 
-static int nvram_deinit_device(struct vm_device * dev) {
+static int nvram_free(struct vm_device * dev) {
     v3_dev_unhook_io(dev, NVRAM_REG_PORT);
     v3_dev_unhook_io(dev, NVRAM_DATA_PORT);
 
-    nvram_reset_device(dev);
     return 0;
 }
 
@@ -794,9 +777,8 @@ static int nvram_deinit_device(struct vm_device * dev) {
 
 
 
-static struct vm_device_ops dev_ops = { 
-    .init = nvram_init_device, 
-    .deinit = nvram_deinit_device,
+static struct v3_device_ops dev_ops = {  
+    .free = nvram_free,
     .reset = nvram_reset_device,
     .start = nvram_start_device,
     .stop = nvram_stop_device,
@@ -805,16 +787,41 @@ static struct vm_device_ops dev_ops = {
 
 
 
-struct vm_device * v3_create_nvram(struct vm_device * ide) {
+
+static int nvram_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct nvram_internal * nvram_state = NULL;
+    struct vm_device * ide = v3_find_dev(vm, v3_cfg_val(cfg, "storage"));
+    char * name = v3_cfg_val(cfg, "name");
+
+    if (!ide) {
+       PrintError("Could not find IDE device\n");
+       return -1;
+    }
 
+    PrintDebug("nvram: init_device\n");
     nvram_state = (struct nvram_internal *)V3_Malloc(sizeof(struct nvram_internal) + 1000);
 
     PrintDebug("nvram: internal at %p\n", (void *)nvram_state);
 
     nvram_state->ide = ide;
 
-    struct vm_device * device = v3_create_device("NVRAM", &dev_ops, nvram_state);
+    struct vm_device * dev = v3_allocate_device(name, &dev_ops, nvram_state);
+
+
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", name);
+       return -1;
+    }
+
+    init_nvram_state(vm, dev);
 
-    return device;
+    // hook ports
+    v3_dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port);
+    v3_dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port);
+  
+    v3_hook_host_event(vm, HOST_TIMER_EVT, V3_HOST_EVENT_HANDLER(handle_timer_event), dev);
+
+    return 0;
 }
+
+device_register("NVRAM", nvram_init)