[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/28] pci: remove hard-coded bar size in msix_init_e
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 14/28] pci: remove hard-coded bar size in msix_init_exclusive_bar() |
Date: |
Mon, 11 May 2015 14:47:55 +0200 |
From: Jason Wang <address@hidden>
This patch lets msix_init_exclusive_bar() can calculate the bar and
pba size based on the number of MSI-X vectors other than using a
hard-coded limit 4096. This is needed to allow device to have more
than 128 MSI_X vectors. To keep migration compatibility, keep using
4096 as bar size and 2048 for pba offset.
Notes: We don't care about the case that using vectors > 128 for
legacy machine type. Since we limit the queue max to 64, so vectors >=
65 is meaningless.
Virtio device will be the first user for this.
Cc: Keith Busch <address@hidden>
Cc: Kevin Wolf <address@hidden>
Cc: Stefan Hajnoczi <address@hidden>
Cc: Michael S. Tsirkin <address@hidden>
Signed-off-by: Jason Wang <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
hw/pci/msix.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index 24de260..f8748cf 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -295,29 +295,37 @@ int msix_init_exclusive_bar(PCIDevice *dev, unsigned
short nentries,
{
int ret;
char *name;
+ uint32_t bar_size = 4096;
+ uint32_t bar_pba_offset = bar_size / 2;
+ uint32_t bar_pba_size = (nentries / 8 + 1) * 8;
/*
* Migration compatibility dictates that this remains a 4k
* BAR with the vector table in the lower half and PBA in
- * the upper half. Do not use these elsewhere!
+ * the upper half for nentries which is lower or equal to 128.
+ * No need to care about using more than 65 entries for legacy
+ * machine types who has at most 64 queues.
*/
-#define MSIX_EXCLUSIVE_BAR_SIZE 4096
-#define MSIX_EXCLUSIVE_BAR_TABLE_OFFSET 0
-#define MSIX_EXCLUSIVE_BAR_PBA_OFFSET (MSIX_EXCLUSIVE_BAR_SIZE / 2)
-#define MSIX_EXCLUSIVE_CAP_OFFSET 0
+ if (nentries * PCI_MSIX_ENTRY_SIZE > bar_pba_offset) {
+ bar_pba_offset = nentries * PCI_MSIX_ENTRY_SIZE;
+ }
- if (nentries * PCI_MSIX_ENTRY_SIZE > MSIX_EXCLUSIVE_BAR_PBA_OFFSET) {
- return -EINVAL;
+ if (bar_pba_offset + bar_pba_size > 4096) {
+ bar_size = bar_pba_offset + bar_pba_size;
+ }
+
+ if (bar_size & (bar_size - 1)) {
+ bar_size = 1 << qemu_fls(bar_size);
}
name = g_strdup_printf("%s-msix", dev->name);
- memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev), name,
MSIX_EXCLUSIVE_BAR_SIZE);
+ memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev), name, bar_size);
g_free(name);
ret = msix_init(dev, nentries, &dev->msix_exclusive_bar, bar_nr,
- MSIX_EXCLUSIVE_BAR_TABLE_OFFSET, &dev->msix_exclusive_bar,
- bar_nr, MSIX_EXCLUSIVE_BAR_PBA_OFFSET,
- MSIX_EXCLUSIVE_CAP_OFFSET);
+ 0, &dev->msix_exclusive_bar,
+ bar_nr, bar_pba_offset,
+ 0);
if (ret) {
return ret;
}
--
MST
- [Qemu-devel] [PULL 02/28] hw/i386: Move ACPI header definitions in an arch-independent location, (continued)
- [Qemu-devel] [PULL 02/28] hw/i386: Move ACPI header definitions in an arch-independent location, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 05/28] virtio-net: fix the upper bound when trying to delete queues, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 06/28] pc: add 2.4 machine types, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 07/28] spapr: add machine type specific instance init function, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 08/28] ppc: spapr: add 2.4 machine type, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 09/28] monitor: replace the magic number 255 with MAX_QUEUE_NUM, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 10/28] monitor: check return value of qemu_find_net_clients_except(), Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 11/28] virtio-ccw: using VIRTIO_NO_VECTOR instead of 0 for invalid virtqueue, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 12/28] virtio: introduce vector to virtqueues mapping, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 13/28] virtio-pci: speedup MSI-X masking and unmasking, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 14/28] pci: remove hard-coded bar size in msix_init_exclusive_bar(),
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 16/28] docs: update documentation for memory hot unplug, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 17/28] acpi, mem-hotplug: add acpi_memory_slot_status() to get MemStatus, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 15/28] virtio: coding style tweak, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 18/28] acpi, mem-hotplug: add unplug request cb for memory device, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 19/28] acpi, mem-hotplug: add unplug cb for memory device, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 21/28] acpi: fix "Memory device control fields" register, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 20/28] acpi: extend aml_field() to support UpdateRule, Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 24/28] acpi: add a missing backslash to the \_SB scope., Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 25/28] pci: Merge pci_nic_init() into pci_nic_init_nofail(), Michael S. Tsirkin, 2015/05/11
- [Qemu-devel] [PULL 22/28] acpi: add hardware implementation for memory hot unplug, Michael S. Tsirkin, 2015/05/11