pci: Fix PCI BAR alignment
Subsystems (2)
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.
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
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
@@ -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
PATCH 2/2 pci: Align PCI addresses on BAR size boundary
In reply to Alexander GordeevPCI 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
@@ -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
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 boundarylib/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