X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fram_hd.c;h=c90e5bebb8c8fc3ded37c949d9dbc3208bdd280c;hb=17e0fe3ae80a90f7268462f6109ab68929b25e16;hp=3bce4fcfdb32926b21a54a392aeacb121024f7a0;hpb=326a9425e1dc7a9f7afafe2951b55f35d9ff2422;p=palacios.git diff --git a/palacios/src/devices/ram_hd.c b/palacios/src/devices/ram_hd.c index 3bce4fc..c90e5be 100644 --- a/palacios/src/devices/ram_hd.c +++ b/palacios/src/devices/ram_hd.c @@ -23,7 +23,7 @@ -#ifndef DEBUG_IDE +#ifndef CONFIG_DEBUG_IDE #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -43,8 +43,8 @@ struct hd_state { static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); - int offset = lba * IDE_SECTOR_SIZE; - int length = sector_count * IDE_SECTOR_SIZE; + int offset = lba * HD_SECTOR_SIZE; + int length = sector_count * HD_SECTOR_SIZE; // PrintDebug("Reading RAM HD at (LBA=%d) offset %d (length=%d)\n", (uint32_t)lba, offset, length); @@ -57,8 +57,8 @@ static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * privat static int hd_write(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); - int offset = lba * IDE_SECTOR_SIZE; - int length = sector_count * IDE_SECTOR_SIZE; + int offset = lba * HD_SECTOR_SIZE; + int length = sector_count * HD_SECTOR_SIZE; memcpy((uint8_t *)(hd->disk_image + offset), buf, length); @@ -70,62 +70,73 @@ static uint64_t hd_get_capacity(void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); PrintDebug("Querying RAM HD capacity (bytes=%d) (ret = %d)\n", - hd->capacity, hd->capacity / IDE_SECTOR_SIZE); - return hd->capacity / IDE_SECTOR_SIZE; + hd->capacity, hd->capacity / HD_SECTOR_SIZE); + return hd->capacity / HD_SECTOR_SIZE; } -static struct v3_ide_hd_ops hd_ops = { +static struct v3_hd_ops hd_ops = { .read = hd_read, .write = hd_write, .get_capacity = hd_get_capacity, }; -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) { - PrintError("HD image must be an integral of sector size (IDE_SECTOR_SIZE=%d)\n", IDE_SECTOR_SIZE); - return NULL; + if (cfg->size % HD_SECTOR_SIZE) { + PrintError("HD image must be an integral of sector size (HD_SECTOR_SIZE=%d)\n", HD_SECTOR_SIZE); + return -1; } hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state)); - PrintDebug("Registering Ram HDD at %p (size=%d)\n", (void *)ramdisk, size); + PrintDebug("Registering Ram HDD at %p (size=%d)\n", (void *)cfg->ramdisk, cfg->size); + + hd->disk_image = cfg->ramdisk; + hd->capacity = cfg->size; + + hd->ide = v3_find_dev(vm, cfg->ide); - hd->disk_image = ramdisk; - hd->capacity = size; + 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)