1*eb2e8974SMinwoo Im /* 2*eb2e8974SMinwoo Im * QEMU NVM Express Subsystem: nvme-subsys 3*eb2e8974SMinwoo Im * 4*eb2e8974SMinwoo Im * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com> 5*eb2e8974SMinwoo Im * 6*eb2e8974SMinwoo Im * This code is licensed under the GNU GPL v2. Refer COPYING. 7*eb2e8974SMinwoo Im */ 8*eb2e8974SMinwoo Im 9*eb2e8974SMinwoo Im #include "qemu/units.h" 10*eb2e8974SMinwoo Im #include "qemu/osdep.h" 11*eb2e8974SMinwoo Im #include "qemu/uuid.h" 12*eb2e8974SMinwoo Im #include "qemu/iov.h" 13*eb2e8974SMinwoo Im #include "qemu/cutils.h" 14*eb2e8974SMinwoo Im #include "qapi/error.h" 15*eb2e8974SMinwoo Im #include "hw/qdev-properties.h" 16*eb2e8974SMinwoo Im #include "hw/qdev-core.h" 17*eb2e8974SMinwoo Im #include "hw/block/block.h" 18*eb2e8974SMinwoo Im #include "block/aio.h" 19*eb2e8974SMinwoo Im #include "block/accounting.h" 20*eb2e8974SMinwoo Im #include "sysemu/sysemu.h" 21*eb2e8974SMinwoo Im #include "hw/pci/pci.h" 22*eb2e8974SMinwoo Im #include "nvme.h" 23*eb2e8974SMinwoo Im #include "nvme-subsys.h" 24*eb2e8974SMinwoo Im 25*eb2e8974SMinwoo Im static void nvme_subsys_setup(NvmeSubsystem *subsys) 26*eb2e8974SMinwoo Im { 27*eb2e8974SMinwoo Im const char *nqn = subsys->params.nqn ? 28*eb2e8974SMinwoo Im subsys->params.nqn : subsys->parent_obj.id; 29*eb2e8974SMinwoo Im 30*eb2e8974SMinwoo Im snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn), 31*eb2e8974SMinwoo Im "nqn.2019-08.org.qemu:%s", nqn); 32*eb2e8974SMinwoo Im } 33*eb2e8974SMinwoo Im 34*eb2e8974SMinwoo Im static void nvme_subsys_realize(DeviceState *dev, Error **errp) 35*eb2e8974SMinwoo Im { 36*eb2e8974SMinwoo Im NvmeSubsystem *subsys = NVME_SUBSYS(dev); 37*eb2e8974SMinwoo Im 38*eb2e8974SMinwoo Im nvme_subsys_setup(subsys); 39*eb2e8974SMinwoo Im } 40*eb2e8974SMinwoo Im 41*eb2e8974SMinwoo Im static Property nvme_subsystem_props[] = { 42*eb2e8974SMinwoo Im DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn), 43*eb2e8974SMinwoo Im DEFINE_PROP_END_OF_LIST(), 44*eb2e8974SMinwoo Im }; 45*eb2e8974SMinwoo Im 46*eb2e8974SMinwoo Im static void nvme_subsys_class_init(ObjectClass *oc, void *data) 47*eb2e8974SMinwoo Im { 48*eb2e8974SMinwoo Im DeviceClass *dc = DEVICE_CLASS(oc); 49*eb2e8974SMinwoo Im 50*eb2e8974SMinwoo Im set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); 51*eb2e8974SMinwoo Im 52*eb2e8974SMinwoo Im dc->realize = nvme_subsys_realize; 53*eb2e8974SMinwoo Im dc->desc = "Virtual NVMe subsystem"; 54*eb2e8974SMinwoo Im 55*eb2e8974SMinwoo Im device_class_set_props(dc, nvme_subsystem_props); 56*eb2e8974SMinwoo Im } 57*eb2e8974SMinwoo Im 58*eb2e8974SMinwoo Im static const TypeInfo nvme_subsys_info = { 59*eb2e8974SMinwoo Im .name = TYPE_NVME_SUBSYS, 60*eb2e8974SMinwoo Im .parent = TYPE_DEVICE, 61*eb2e8974SMinwoo Im .class_init = nvme_subsys_class_init, 62*eb2e8974SMinwoo Im .instance_size = sizeof(NvmeSubsystem), 63*eb2e8974SMinwoo Im }; 64*eb2e8974SMinwoo Im 65*eb2e8974SMinwoo Im static void nvme_subsys_register_types(void) 66*eb2e8974SMinwoo Im { 67*eb2e8974SMinwoo Im type_register_static(&nvme_subsys_info); 68*eb2e8974SMinwoo Im } 69*eb2e8974SMinwoo Im 70*eb2e8974SMinwoo Im type_init(nvme_subsys_register_types) 71