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 to the device framework.
[palacios.git] / palacios / src / devices / ram_hd.c
index 3bce4fc..49bf510 100644 (file)
@@ -81,51 +81,62 @@ static struct v3_ide_hd_ops hd_ops = {
 };
 
 
-static int hd_init(struct vm_device * dev) {
-    struct hd_state * hd = (struct hd_state *)(dev->private_data);
-
-    if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-RAM-HD", &hd_ops, dev) == -1) {
-       return -1;
-    }
-    
-    return 0;
-}
 
 
-static int hd_deinit(struct vm_device * dev) {
+static int hd_free(struct vm_device * dev) {
     return 0;
 }
 
-static struct vm_device_ops dev_ops = {
-    .init = hd_init, 
-    .deinit = hd_deinit,
+static struct v3_device_ops dev_ops = {
+    .free = hd_free,
     .reset = NULL,
     .start = NULL,
     .stop = NULL,
 };
 
-struct vm_device * v3_create_ram_hd(struct vm_device * ide, 
-                                   uint_t bus, uint_t drive, 
-                                   addr_t ramdisk, uint32_t size) {
+
+
+
+static int hd_init(struct guest_info * vm, void * cfg_data) {
     struct hd_state * hd = NULL;
+    struct ram_hd_cfg * cfg = (struct ram_hd_cfg *)cfg_data;
 
-    if (size % IDE_SECTOR_SIZE) {
+    if (cfg->size % IDE_SECTOR_SIZE) {
        PrintError("HD image must be an integral of sector size (IDE_SECTOR_SIZE=%d)\n", IDE_SECTOR_SIZE);
-       return NULL;
+       return -1;
     }
 
     hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state));
 
     PrintDebug("Registering Ram HDD at %p (size=%d)\n", (void *)ramdisk, size);
 
-    hd->disk_image = ramdisk;
-    hd->capacity = size;
+    hd->disk_image = cfg->ramdisk;
+    hd->capacity = cfg->size;
+
+    hd->ide = v3_find_dev(vm, cfg->ide);
+
+    if (hd->ide == 0) {
+       PrintError("Could not find backend %s\n", cfg->ide);
+       return -1;
+    }
 
-    hd->ide = ide;
-    hd->bus = bus;
-    hd->drive = drive;
+    hd->bus = cfg->bus;
+    hd->drive = cfg->drive;
        
-    struct vm_device * hd_dev = v3_create_device("RAM-HD", &dev_ops, hd);
+    struct vm_device * dev = v3_allocate_device("RAM-HD", &dev_ops, hd);
+
+    if (v3_attach_device(vm, dev) == -1) {
+       PrintError("Could not attach device %s\n", "RAM-HD");
+       return -1;
+    }
+
 
-    return hd_dev;
+    if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "RAM-HD", &hd_ops, dev) == -1) {
+       return -1;
+    }
+    
+    return 0;
 }
+
+
+device_register("RAM-HD", hd_init)