X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_blk.c;h=f44d616731da62101a676abb47007349c36b5fb7;hb=37c18b2c2335a41c68c2f0b779fd2b7d51ab216d;hp=4e0c14c58bda09f341abd5135ccc3be434f5280a;hpb=0160025157d9bc39687eb0c5df6cb3d965d20e07;p=palacios.git diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index 4e0c14c..f44d616 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -51,11 +51,49 @@ static int virtio_pci_read(uint16_t port, void * dst, uint_t length, struct vm_d return -1; } -static int virtio_init(struct vm_device * dev) { - struct blk_state * virtio = (struct blk_state *)(dev->private_data); + + +static int virtio_free(struct vm_device * dev) { + return -1; +} + + + +static struct v3_device_ops dev_ops = { + .free = virtio_free, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + + + + + +static int virtio_init(struct guest_info * vm, void * cfg_data) { + struct blk_state * virtio = NULL; + struct vm_device * pci_bus = (struct vm_device *)cfg_data; + PrintDebug("Initializing VIRTIO Block device\n"); + if (pci_bus == NULL) { + PrintError("VirtIO requires a PCI bus\n"); + return -1; + } + + virtio = (struct blk_state *)V3_Malloc(sizeof(struct blk_state)); + + virtio->pci_bus = pci_bus; + + struct vm_device * dev = v3_allocate_device("VIRTIO_BLK", &dev_ops, virtio); + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", "LNX_VIRTIO_BLK"); + return -1; + } + + + if (virtio->pci_bus != NULL) { struct v3_pci_bar bars[6]; struct pci_device * pci_dev = NULL; @@ -115,36 +153,5 @@ static int virtio_init(struct vm_device * dev) { return -1; } -static int virtio_deinit(struct vm_device * dev) { - return -1; -} - - - -static struct vm_device_ops dev_ops = { - .init = virtio_init, - .deinit = virtio_deinit, - .reset = NULL, - .start = NULL, - .stop = NULL, -}; - - -struct vm_device * v3_create_virtio(struct vm_device * pci_bus) { - struct blk_state * virtio = NULL; - - PrintDebug("Creating VirtIO Block device\n"); - - if (pci_bus == NULL) { - PrintError("VirtIO requires a PCI bus\n"); - return NULL; - } - - - virtio = (struct blk_state *)V3_Malloc(sizeof(struct blk_state)); - - virtio->pci_bus = pci_bus; - - return v3_create_device("VIRTIO_BLK", &dev_ops, virtio); -} +device_register("LNX_VIRTIO_BLK", virtio_init)