hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM
[qemu/ar7.git] / hw / block / nvme-subsys.h
blob7d7ef5f7f12b2809cc9c42d210157fa720cbe0cb
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 #ifndef NVME_SUBSYS_H
10 #define NVME_SUBSYS_H
12 #define TYPE_NVME_SUBSYS "nvme-subsys"
13 #define NVME_SUBSYS(obj) \
14 OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)
16 #define NVME_SUBSYS_MAX_CTRLS 32
17 #define NVME_MAX_NAMESPACES 256
19 typedef struct NvmeCtrl NvmeCtrl;
20 typedef struct NvmeNamespace NvmeNamespace;
21 typedef struct NvmeSubsystem {
22 DeviceState parent_obj;
23 uint8_t subnqn[256];
25 NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS];
26 /* Allocated namespaces for this subsystem */
27 NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1];
29 struct {
30 char *nqn;
31 } params;
32 } NvmeSubsystem;
34 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp);
36 static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys,
37 uint32_t cntlid)
39 if (!subsys || cntlid >= NVME_SUBSYS_MAX_CTRLS) {
40 return NULL;
43 return subsys->ctrls[cntlid];
47 * Return allocated namespace of the specified nsid in the subsystem.
49 static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys,
50 uint32_t nsid)
52 if (!subsys || !nsid || nsid > NVME_MAX_NAMESPACES) {
53 return NULL;
56 return subsys->namespaces[nsid];
59 #endif /* NVME_SUBSYS_H */