mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-27 21:40:49 +00:00
hw/block/nvme: add namespace helpers
Introduce some small helpers to make the next patches easier on the eye. 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-14-its@irrelevant.dk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
90f4511543
commit
3adee1c2d3
@ -1573,8 +1573,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
|
||||
id_ns->dps = 0;
|
||||
id_ns->lbaf[0].ds = BDRV_SECTOR_BITS;
|
||||
id_ns->ncap = id_ns->nuse = id_ns->nsze =
|
||||
cpu_to_le64(n->ns_size >>
|
||||
id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds);
|
||||
cpu_to_le64(nvme_ns_nlbas(n, ns));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,17 @@ typedef struct NvmeNamespace {
|
||||
NvmeIdNs id_ns;
|
||||
} NvmeNamespace;
|
||||
|
||||
static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns)
|
||||
{
|
||||
NvmeIdNs *id_ns = &ns->id_ns;
|
||||
return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
|
||||
}
|
||||
|
||||
static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns)
|
||||
{
|
||||
return nvme_ns_lbaf(ns)->ds;
|
||||
}
|
||||
|
||||
#define TYPE_NVME "nvme"
|
||||
#define NVME(obj) \
|
||||
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
|
||||
@ -97,4 +108,10 @@ typedef struct NvmeCtrl {
|
||||
NvmeIdCtrl id_ctrl;
|
||||
} NvmeCtrl;
|
||||
|
||||
/* calculate the number of LBAs that the namespace can accomodate */
|
||||
static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns)
|
||||
{
|
||||
return n->ns_size >> nvme_ns_lbads(ns);
|
||||
}
|
||||
|
||||
#endif /* HW_NVME_H */
|
||||
|
Loading…
Reference in New Issue
Block a user