From b8d8f9f5ada9568f672f4ce9d68fe0f66cae44f5 Mon Sep 17 00:00:00 2001 From: Martin Cerveny Date: Sun, 31 Mar 2019 09:26:05 +0200 Subject: [PATCH] pci: Merge allocation of prefetchable MEM BAR Fragmented allocation of NON-prefetchable (MMIO) and prefetchable PCI MEM BAR not supported - see "Type 1 Configuration Space Registers (Root Ports)". --- tools/firmware/hvmloader/pci.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c index 0b708bf578..42a3dd5e62 100644 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -97,7 +97,7 @@ void pci_setup(void) uint32_t bar_reg; uint64_t bar_sz; } *bars = (struct bars *)scratch_start; - unsigned int i, nr_bars = 0; + unsigned int i, nr_bars = 0, nr_bars_pref = 0; uint64_t mmio_hole_size = 0; const char *s; @@ -253,9 +253,19 @@ void pci_setup(void) if ( bar_sz == 0 ) continue; - for ( i = 0; i < nr_bars; i++ ) - if ( bars[i].bar_sz < bar_sz ) - break; + if (((bar_data & PCI_BASE_ADDRESS_SPACE) == + PCI_BASE_ADDRESS_SPACE_MEMORY) && + ((bar_data & PCI_BASE_ADDRESS_MEM_PREFETCH) == + PCI_BASE_ADDRESS_MEM_PREFETCH)) { + for ( i = 0; i < nr_bars_pref; i++ ) + if ( bars[i].bar_sz < bar_sz ) + break; + nr_bars_pref++; + } + else + for ( i = nr_bars_pref; i < nr_bars; i++ ) + if ( bars[i].bar_sz < bar_sz ) + break; if ( i != nr_bars ) memmove(&bars[i+1], &bars[i], (nr_bars-i) * sizeof(*bars)); -- 2.20.1