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.


various changes...
[palacios.git] / palacios / src / devices / ram_cd.c
index fb88e37..4a3baac 100644 (file)
 
 #include <palacios/vmm.h>
 #include <devices/ram_cd.h>
+#include <palacios/vmm_dev_mgr.h>
 #include <devices/ide.h>
 
-#ifndef DEBUG_IDE
+#ifndef CONFIG_DEBUG_IDE
 #undef PrintDebug
 #define PrintDebug(fmt, args...)
 #endif
@@ -61,58 +62,67 @@ static uint32_t cd_get_capacity(void * private_data) {
     return cd->capacity / ATAPI_BLOCK_SIZE;
 }
 
-static struct v3_ide_cd_ops cd_ops = {
+static struct v3_cd_ops cd_ops = {
     .read = cd_read, 
     .get_capacity = cd_get_capacity,
 };
 
 
-static int cd_init(struct vm_device * dev) {
-    struct cd_state * cd = (struct cd_state *)(dev->private_data);
 
-    if (v3_ide_register_cdrom(cd->ide, cd->bus, cd->drive, "RAM-CD", &cd_ops, dev) == -1) {
-       return -1;
-    }
-    
-    return 0;
-}
 
-
-static int cd_deinit(struct vm_device * dev) {
+static int cd_free(struct vm_device * dev) {
     return 0;
 }
 
-static struct vm_device_ops dev_ops = {
-    .init = cd_init, 
-    .deinit = cd_deinit,
+static struct v3_device_ops dev_ops = {
+    .free = cd_free,
     .reset = NULL,
     .start = NULL,
     .stop = NULL,
 };
 
-struct vm_device * v3_create_ram_cd(struct vm_device * ide, 
-                                   uint_t bus, uint_t drive, 
-                                   addr_t ramdisk, uint32_t size) {
+
+static int cd_init(struct guest_info * vm, void * cfg_data) {
     struct cd_state * cd = NULL;
+    struct ram_cd_cfg * cfg = (struct ram_cd_cfg *)cfg_data;
 
-    if (size % ATAPI_BLOCK_SIZE) {
+    if (cfg->size % ATAPI_BLOCK_SIZE) {
        PrintError("CD image must be an integral of block size (ATAPI_BLOCK_SIZE=%d)\n", ATAPI_BLOCK_SIZE);
-       return NULL;
+       return -1;
     }
 
     cd = (struct cd_state *)V3_Malloc(sizeof(struct cd_state));
 
-    PrintDebug("Registering Ram CD at %p (size=%d)\n", (void *)ramdisk, size);
+    PrintDebug("Registering Ram CD at %p (size=%d)\n", (void *)cfg->ramdisk, cfg->size);
 
   
-    cd->disk_image = ramdisk;
-    cd->capacity = size;
+    cd->disk_image = cfg->ramdisk;
+    cd->capacity = cfg->size;
+
+    cd->ide = v3_find_dev(vm, cfg->ide);
+
+    if (cd->ide == 0) {
+       PrintError("Could not find backend %s\n", cfg->ide);
+       return -1;
+    }
 
-    cd->ide = ide;
-    cd->bus = bus;
-    cd->drive = drive;
+    cd->bus = cfg->bus;
+    cd->drive = cfg->drive;
        
-    struct vm_device * cd_dev = v3_create_device("RAM-CD", &dev_ops, cd);
+    struct vm_device * dev = v3_allocate_device("RAM-CD", &dev_ops, cd);
+
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", "RAM-CD");
+       return -1;
+    }
+
 
-    return cd_dev;
+    if (v3_ide_register_cdrom(cd->ide, cd->bus, cd->drive, "RAM-CD", &cd_ops, dev) == -1) {
+       return -1;
+    }
+    
+    return 0;
 }
+
+
+device_register("RAM-CD", cd_init)