[kvm-unit-tests PATCH 2/2] pci: Align PCI addresses on BAR size boundary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PCI I/O and Memory must be allocated to a device in a naturally
aligned way. For example, if a device asks for 0xB0 of PCI I/O
space then it must be aligned on an address that is a multiple
of 0xB0 (http://www.tldp.org/LDP/tlk/dd/pci.html)

Cc: Thomas Huth <thuth@xxxxxxxxxx>
Cc: Andrew Jones <drjones@xxxxxxxxxx>
Reported-by: Andrew Jones <drjones@xxxxxxxxxx>
Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx>
---
 lib/pci-host-generic.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/pci-host-generic.c b/lib/pci-host-generic.c
index df66bd4741e6..d57b47ee4c53 100644
--- a/lib/pci-host-generic.c
+++ b/lib/pci-host-generic.c
@@ -170,7 +170,7 @@ static bool pci_alloc_resource(pcidevaddr_t dev, int bar_num, u64 *addr)
 	struct pci_host_bridge *host = pci_host_bridge;
 	struct pci_addr_space *as = &host->addr_space[0];
 	u32 bar;
-	u64 size;
+	u64 size, pci_addr;
 	int type, i;
 
 	*addr = ~0;
@@ -199,8 +199,10 @@ static bool pci_alloc_resource(pcidevaddr_t dev, int bar_num, u64 *addr)
 		return false;
 	}
 
+	pci_addr = ALIGN(as->pci_start + as->allocated, size);
+	size += pci_addr - (as->pci_start + as->allocated);
 	assert(as->allocated + size <= as->size);
-	*addr = as->pci_start + as->allocated;
+	*addr = pci_addr;
 	as->allocated += size;
 
 	return true;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux