hw/intc/arm_gicv3_its: Drop TableDesc and CmdQDesc valid fields
[qemu.git] / hw / nvme / subsys.c
blobfb58d639504e9fc80f45e3e40b6c936585f24423
1 /*
2 * QEMU NVM Express Subsystem: nvme-subsys
4 * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com>
6 * This code is licensed under the GNU GPL v2. Refer COPYING.
7 */
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
12 #include "nvme.h"
14 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
16 NvmeSubsystem *subsys = n->subsys;
17 int cntlid, nsid;
19 for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) {
20 if (!subsys->ctrls[cntlid]) {
21 break;
25 if (cntlid == ARRAY_SIZE(subsys->ctrls)) {
26 error_setg(errp, "no more free controller id");
27 return -1;
30 subsys->ctrls[cntlid] = n;
32 for (nsid = 1; nsid < ARRAY_SIZE(subsys->namespaces); nsid++) {
33 NvmeNamespace *ns = subsys->namespaces[nsid];
34 if (ns && ns->params.shared && !ns->params.detached) {
35 nvme_attach_ns(n, ns);
39 return cntlid;
42 void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n)
44 subsys->ctrls[n->cntlid] = NULL;
45 n->cntlid = -1;
48 static void nvme_subsys_setup(NvmeSubsystem *subsys)
50 const char *nqn = subsys->params.nqn ?
51 subsys->params.nqn : subsys->parent_obj.id;
53 snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn),
54 "nqn.2019-08.org.qemu:%s", nqn);
57 static void nvme_subsys_realize(DeviceState *dev, Error **errp)
59 NvmeSubsystem *subsys = NVME_SUBSYS(dev);
61 qbus_init(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);
63 nvme_subsys_setup(subsys);
66 static Property nvme_subsystem_props[] = {
67 DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn),
68 DEFINE_PROP_END_OF_LIST(),
71 static void nvme_subsys_class_init(ObjectClass *oc, void *data)
73 DeviceClass *dc = DEVICE_CLASS(oc);
75 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
77 dc->realize = nvme_subsys_realize;
78 dc->desc = "Virtual NVMe subsystem";
79 dc->hotpluggable = false;
81 device_class_set_props(dc, nvme_subsystem_props);
84 static const TypeInfo nvme_subsys_info = {
85 .name = TYPE_NVME_SUBSYS,
86 .parent = TYPE_DEVICE,
87 .class_init = nvme_subsys_class_init,
88 .instance_size = sizeof(NvmeSubsystem),
91 static void nvme_subsys_register_types(void)
93 type_register_static(&nvme_subsys_info);
96 type_init(nvme_subsys_register_types)