aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Jensen <k.jensen@samsung.com>2020-06-09 21:03:17 +0200
committerKevin Wolf <kwolf@redhat.com>2020-06-17 14:53:40 +0200
commitb4529c5c3af69189b65b22906a35b09a7fe17960 (patch)
tree6ecda42aebaef4635592ff20ebf7732b46d92fe8
parent3e829fd438033cdf8646ec22bcc869555b100212 (diff)
downloadqemu-b4529c5c3af69189b65b22906a35b09a7fe17960.zip
qemu-b4529c5c3af69189b65b22906a35b09a7fe17960.tar.gz
qemu-b4529c5c3af69189b65b22906a35b09a7fe17960.tar.bz2
hw/block/nvme: refactor nvme_addr_read
Pull the controller memory buffer check to its own function. The check will be used on its own in later patches. 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-7-its@irrelevant.dk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--hw/block/nvme.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 2a26b88..d6fcf07 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -65,14 +65,22 @@
static void nvme_process_sq(void *opaque);
+static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
+{
+ hwaddr low = n->ctrl_mem.addr;
+ hwaddr hi = n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size);
+
+ return addr >= low && addr < hi;
+}
+
static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size)
{
- if (n->cmbsz && addr >= n->ctrl_mem.addr &&
- addr < (n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size))) {
+ if (n->cmbsz && nvme_addr_is_cmb(n, addr)) {
memcpy(buf, (void *)&n->cmbuf[addr - n->ctrl_mem.addr], size);
- } else {
- pci_dma_read(&n->parent_obj, addr, buf, size);
+ return;
}
+
+ pci_dma_read(&n->parent_obj, addr, buf, size);
}
static int nvme_check_sqid(NvmeCtrl *n, uint16_t sqid)