void rbd_destroy(struct rbd *d) { vmm_host_ram_reserve(d->addr, d->size); vmm_blockdev_unregister(d->bdev); vmm_blockdev_free(d->bdev); vmm_free(d); }
static struct rbd *__rbd_create(struct vmm_device *dev, const char *name, physical_addr_t pa, physical_size_t sz) { struct rbd *d; if (!name) { return NULL; } d = vmm_zalloc(sizeof(struct rbd)); if (!d) { goto free_nothing; } d->addr = pa; d->size = sz; d->bdev = vmm_blockdev_alloc(); if (!d->bdev) { goto free_rbd; } /* Setup block device instance */ strncpy(d->bdev->name, name, VMM_FIELD_NAME_SIZE); strncpy(d->bdev->desc, "RAM backed block device", VMM_FIELD_DESC_SIZE); d->bdev->dev = dev; d->bdev->flags = VMM_BLOCKDEV_RW; d->bdev->start_lba = 0; d->bdev->num_blocks = udiv64(d->size, RBD_BLOCK_SIZE); d->bdev->block_size = RBD_BLOCK_SIZE; /* Setup request queue for block device instance */ d->bdev->rq->make_request = rbd_make_request; d->bdev->rq->abort_request = rbd_abort_request; d->bdev->rq->priv = d; /* Register block device instance */ if (vmm_blockdev_register(d->bdev)) { goto free_bdev; } /* Reserve RAM space */ if (vmm_host_ram_reserve(d->addr, d->size)) { goto unreg_bdev; } return d; unreg_bdev: vmm_blockdev_unregister(d->bdev); free_bdev: vmm_blockdev_free(d->bdev); free_rbd: vmm_free(d); free_nothing: return NULL; }
void mtdblock_add(struct mtd_info *mtd) { int err = 0; struct vmm_blockdev *bdev = NULL; struct vmm_blockrq *brq = NULL; if (NULL == (bdev = vmm_blockdev_alloc())) { dev_err(&mtd->dev, "Failed to allocate MTD block device\n"); return; } /* Setup block device instance */ strncpy(bdev->name, mtd->name, sizeof (bdev->name)); strncpy(bdev->desc, "MTD m25p80 NOR flash block device", VMM_FIELD_DESC_SIZE); bdev->dev.priv = mtd; bdev->flags = VMM_BLOCKDEV_RW; bdev->start_lba = 0; bdev->num_blocks = mtd->size >> mtd->erasesize_shift; bdev->block_size = mtd->erasesize; /* Setup request queue for block device instance */ brq = vmm_blockrq_create(mtd->name, 128, FALSE, mtd_blockdev_read, mtd_blockdev_write, NULL, mtd_blockdev_flush, mtd); if (!brq) { vmm_blockdev_free(bdev); return; } bdev->rq = vmm_blockrq_to_rq(brq); /* Register block device instance */ if (VMM_OK != (err = vmm_blockdev_register(bdev))) { vmm_blockrq_destroy(brq); vmm_blockdev_free(bdev); dev_err(&mtd->dev, "Failed to register MTD block device\n"); } }
void mtdblock_remove(struct mtd_info *mtd) { struct vmm_blockdev *bdev = NULL; struct vmm_blockrq *brq = NULL; if (NULL == (bdev = vmm_blockdev_find(mtd->name))) return; brq = vmm_blockrq_from_rq(bdev->rq); vmm_blockdev_unregister(bdev); if (brq) vmm_blockrq_destroy(brq); vmm_blockdev_free(bdev); }