Skip to content

Commit 1901b49

Browse files
committed
hw/block/nvme: move msix table and pba to BAR 0
In the interest of supporting both CMB and PMR to be enabled on the same device, move the MSI-X table and pending bit array out of BAR 4 and into BAR 0. This is a simplified version of the patch contributed by Andrzej Jakowski (see [1]). Leaving the CMB at offset 0 removes the need for changes to CMB address mapping code. [1]: https://lore.kernel.org/qemu-devel/20200729220107.37758-3-andrzej.jakowski@linux.intel.com/ Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com> Tested-by: Minwoo Im <minwoo.im.dev@gmail.com> Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
1 parent c705063 commit 1901b49

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

hw/block/nvme.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4268,6 +4268,8 @@ static void nvme_init_pmr(NvmeCtrl *n, PCIDevice *pci_dev)
42684268
static int nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
42694269
{
42704270
uint8_t *pci_conf = pci_dev->config;
4271+
uint64_t bar_size, msix_table_size, msix_pba_size;
4272+
unsigned msix_table_offset, msix_pba_offset;
42714273
int ret;
42724274

42734275
Error *err = NULL;
@@ -4286,11 +4288,28 @@ static int nvme_init_pci(NvmeCtrl *n, PCIDevice *pci_dev, Error **errp)
42864288
pci_config_set_class(pci_conf, PCI_CLASS_STORAGE_EXPRESS);
42874289
pcie_endpoint_cap_init(pci_dev, 0x80);
42884290

4291+
bar_size = QEMU_ALIGN_UP(n->reg_size, 4 * KiB);
4292+
msix_table_offset = bar_size;
4293+
msix_table_size = PCI_MSIX_ENTRY_SIZE * n->params.msix_qsize;
4294+
4295+
bar_size += msix_table_size;
4296+
bar_size = QEMU_ALIGN_UP(bar_size, 4 * KiB);
4297+
msix_pba_offset = bar_size;
4298+
msix_pba_size = QEMU_ALIGN_UP(n->params.msix_qsize, 64) / 8;
4299+
4300+
bar_size += msix_pba_size;
4301+
bar_size = pow2ceil(bar_size);
4302+
4303+
memory_region_init(&n->bar0, OBJECT(n), "nvme-bar0", bar_size);
42894304
memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme",
42904305
n->reg_size);
4306+
memory_region_add_subregion(&n->bar0, 0, &n->iomem);
4307+
42914308
pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY |
4292-
PCI_BASE_ADDRESS_MEM_TYPE_64, &n->iomem);
4293-
ret = msix_init_exclusive_bar(pci_dev, n->params.msix_qsize, 4, &err);
4309+
PCI_BASE_ADDRESS_MEM_TYPE_64, &n->bar0);
4310+
ret = msix_init(pci_dev, n->params.msix_qsize,
4311+
&n->bar0, 0, msix_table_offset,
4312+
&n->bar0, 0, msix_pba_offset, 0, &err);
42944313
if (ret < 0) {
42954314
if (ret == -ENOTSUP) {
42964315
warn_report_err(err);

hw/block/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct NvmeFeatureVal {
125125

126126
typedef struct NvmeCtrl {
127127
PCIDevice parent_obj;
128+
MemoryRegion bar0;
128129
MemoryRegion iomem;
129130
MemoryRegion ctrl_mem;
130131
NvmeBar bar;

0 commit comments

Comments
 (0)