hw/block/nvme: factor out device state setup
Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Reviewed-by: Keith Busch <kbusch@kernel.org> Message-Id: <20200609190333.59390-12-its@irrelevant.dk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
54000c66f0
commit
a17f50188b
@ -1399,6 +1399,17 @@ static void nvme_check_constraints(NvmeCtrl *n, Error **errp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void nvme_init_state(NvmeCtrl *n)
|
||||||
|
{
|
||||||
|
n->num_namespaces = 1;
|
||||||
|
/* add one to max_ioqpairs to account for the admin queue pair */
|
||||||
|
n->reg_size = pow2ceil(NVME_REG_SIZE +
|
||||||
|
2 * (n->params.max_ioqpairs + 1) * NVME_DB_SIZE);
|
||||||
|
n->namespaces = g_new0(NvmeNamespace, n->num_namespaces);
|
||||||
|
n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1);
|
||||||
|
n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static void nvme_realize(PCIDevice *pci_dev, Error **errp)
|
static void nvme_realize(PCIDevice *pci_dev, Error **errp)
|
||||||
{
|
{
|
||||||
NvmeCtrl *n = NVME(pci_dev);
|
NvmeCtrl *n = NVME(pci_dev);
|
||||||
@ -1415,6 +1426,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvme_init_state(n);
|
||||||
|
|
||||||
bs_size = blk_getlength(n->conf.blk);
|
bs_size = blk_getlength(n->conf.blk);
|
||||||
if (bs_size < 0) {
|
if (bs_size < 0) {
|
||||||
error_setg(errp, "could not get backing file size");
|
error_setg(errp, "could not get backing file size");
|
||||||
@ -1433,17 +1446,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
|
|||||||
pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS);
|
pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS);
|
||||||
pcie_endpoint_cap_init(pci_dev, 0x80);
|
pcie_endpoint_cap_init(pci_dev, 0x80);
|
||||||
|
|
||||||
n->num_namespaces = 1;
|
|
||||||
|
|
||||||
/* add one to max_ioqpairs to account for the admin queue pair */
|
|
||||||
n->reg_size = pow2ceil(NVME_REG_SIZE +
|
|
||||||
2 * (n->params.max_ioqpairs + 1) * NVME_DB_SIZE);
|
|
||||||
n->ns_size = bs_size / (uint64_t)n->num_namespaces;
|
n->ns_size = bs_size / (uint64_t)n->num_namespaces;
|
||||||
|
|
||||||
n->namespaces = g_new0(NvmeNamespace, n->num_namespaces);
|
|
||||||
n->sq = g_new0(NvmeSQueue *, n->params.max_ioqpairs + 1);
|
|
||||||
n->cq = g_new0(NvmeCQueue *, n->params.max_ioqpairs + 1);
|
|
||||||
|
|
||||||
memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n,
|
memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n,
|
||||||
"nvme", n->reg_size);
|
"nvme", n->reg_size);
|
||||||
pci_register_bar(pci_dev, 0,
|
pci_register_bar(pci_dev, 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user