Skip to contentSkip to conversation

pci: Fix PCI BAR alignment

PATCH In review Alexander Gordeev 2 participants 4 messages Nov 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover pci: Fix PCI BAR alignment

Andrew Jones reported 'edu' device fails to operate on addresses assigned by PCI memory allocation. This series should fix the issue.

Cc Thomas Huth <[email protected]>
Cc Andrew Jones <[email protected]>

Alexander Gordeev (2):
pci: Remove redundant alignment of BAR size
pci: Align PCI addresses on BAR size boundary

 lib/pci-host-generic.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 pci: Remove redundant alignment of BAR size

Size of a BAR is naturally aligned so there is no need to align it explicitly.

---
 lib/pci-host-generic.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
lib/pci-host-generic.c +1 -4
index 6ac0f15faa90..df66bd4741e6 100644
@@ -169,7 +169,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 mask, bar;
+	u32 bar;
 	u64 size;
 	int type, i;
 
@@ -199,10 +199,7 @@ static bool pci_alloc_resource(pcidevaddr_t dev, int bar_num, u64 *addr)
 		return false;
 	}
 
-	mask = pci_bar_mask(bar);
-	size = ALIGN(size, ~mask + 1);
 	assert(as->allocated + size <= as->size);
-
 	*addr = as->pci_start + as->allocated;
 	as->allocated += size;
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 pci: Align PCI addresses on BAR size boundary

In reply to Alexander Gordeev

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)

---
 lib/pci-host-generic.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/pci-host-generic.c +4 -2
index df66bd4741e6..d57b47ee4c53 100644
@@ -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;
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Alexander Gordeev
Quoted 6 lines · Alexander Gordeev

Andrew Jones reported 'edu' device fails to operate on addresses assigned by PCI memory allocation. This series should fix the issue.

Cc Thomas Huth <[email protected]>
Cc Andrew Jones <[email protected]>
Quoted 7 lines

Alexander Gordeev (2):
pci: Remove redundant alignment of BAR size
pci: Align PCI addresses on BAR size boundary

 lib/pci-host-generic.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Thanks, applied to https://github.com/rhdrjones/kvm-unit-tests arm/next which will be the branch I'll start using for PULL requests.

drew