X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fram_cd.c;h=4a3baace9aefeded75b98eec7389c6113be8a4e6;hp=fb88e37ebaef290b202678fdc6d7aa7755deceb7;hb=0e097100a26bc43eb8964734fa43130fc4c71429;hpb=1f3ac121a2cb2eff7c71c84a799096c2cd744d1b diff --git a/palacios/src/devices/ram_cd.c b/palacios/src/devices/ram_cd.c index fb88e37..4a3baac 100644 --- a/palacios/src/devices/ram_cd.c +++ b/palacios/src/devices/ram_cd.c @@ -19,9 +19,10 @@ #include #include +#include #include -#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)