diff options
author | Klaus Jensen <k.jensen@samsung.com> | 2021-04-14 22:14:30 +0200 |
---|---|---|
committer | Klaus Jensen <k.jensen@samsung.com> | 2021-05-17 09:19:00 +0200 |
commit | 88eea45c536470cd3c43440cbb1cd4d3b9fa519c (patch) | |
tree | b5b4d753aa955348af07777518cd0a60b06e5e56 /hw/nvme/subsys.c | |
parent | 49ad39c55a2086637bbde4616491dfee17a142e7 (diff) | |
download | qemu-88eea45c536470cd3c43440cbb1cd4d3b9fa519c.zip qemu-88eea45c536470cd3c43440cbb1cd4d3b9fa519c.tar.gz qemu-88eea45c536470cd3c43440cbb1cd4d3b9fa519c.tar.bz2 |
hw/nvme: move nvme emulation out of hw/block
With the introduction of the nvme-subsystem device we are really
cluttering up the hw/block directory.
As suggested by Philippe previously, move the nvme emulation to hw/nvme.
Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Diffstat (limited to 'hw/nvme/subsys.c')
-rw-r--r-- | hw/nvme/subsys.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c new file mode 100644 index 0000000..192223d --- /dev/null +++ b/hw/nvme/subsys.c @@ -0,0 +1,80 @@ +/* + * QEMU NVM Express Subsystem: nvme-subsys + * + * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com> + * + * This code is licensed under the GNU GPL v2. Refer COPYING. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" + +#include "nvme.h" + +int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp) +{ + NvmeSubsystem *subsys = n->subsys; + int cntlid; + + for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) { + if (!subsys->ctrls[cntlid]) { + break; + } + } + + if (cntlid == ARRAY_SIZE(subsys->ctrls)) { + error_setg(errp, "no more free controller id"); + return -1; + } + + subsys->ctrls[cntlid] = n; + + return cntlid; +} + +static void nvme_subsys_setup(NvmeSubsystem *subsys) +{ + const char *nqn = subsys->params.nqn ? + subsys->params.nqn : subsys->parent_obj.id; + + snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn), + "nqn.2019-08.org.qemu:%s", nqn); +} + +static void nvme_subsys_realize(DeviceState *dev, Error **errp) +{ + NvmeSubsystem *subsys = NVME_SUBSYS(dev); + + nvme_subsys_setup(subsys); +} + +static Property nvme_subsystem_props[] = { + DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn), + DEFINE_PROP_END_OF_LIST(), +}; + +static void nvme_subsys_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + + dc->realize = nvme_subsys_realize; + dc->desc = "Virtual NVMe subsystem"; + + device_class_set_props(dc, nvme_subsystem_props); +} + +static const TypeInfo nvme_subsys_info = { + .name = TYPE_NVME_SUBSYS, + .parent = TYPE_DEVICE, + .class_init = nvme_subsys_class_init, + .instance_size = sizeof(NvmeSubsystem), +}; + +static void nvme_subsys_register_types(void) +{ + type_register_static(&nvme_subsys_info); +} + +type_init(nvme_subsys_register_types) |