From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiejun Chen Subject: [RFC][v2][PATCH 12/14] hvmloader/pci: skip reserved ranges Date: Fri, 22 May 2015 17:35:12 +0800 Message-ID: <1432287314-4388-13-git-send-email-tiejun.chen@intel.com> References: <1432287314-4388-1-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1432287314-4388-1-git-send-email-tiejun.chen@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: JBeulich@suse.com, tim@xen.org, konrad.wilk@oracle.com, andrew.cooper3@citrix.com, kevin.tian@intel.com, yang.z.zhang@intel.com, ian.campbell@citrix.com, wei.liu2@citrix.com, Ian.Jackson@eu.citrix.com, stefano.stabellini@citrix.com Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org When allocating mmio address for PCI bars, we need to make sure they don't overlap with reserved regions. Signed-off-by: Tiejun Chen --- tools/firmware/hvmloader/pci.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c index 5ff87a7..98af568 100644 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -59,8 +59,8 @@ void pci_setup(void) uint32_t bar_reg; uint64_t bar_sz; } *bars = (struct bars *)scratch_start; - unsigned int i, nr_bars = 0; - uint64_t mmio_hole_size = 0; + unsigned int i, j, nr_bars = 0; + uint64_t mmio_hole_size = 0, reserved_end, max_bar_sz = 0; const char *s; /* @@ -226,6 +226,8 @@ void pci_setup(void) bars[i].devfn = devfn; bars[i].bar_reg = bar_reg; bars[i].bar_sz = bar_sz; + if ( bar_sz > max_bar_sz ) + max_bar_sz = bar_sz; if ( ((bar_data & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) || @@ -301,6 +303,21 @@ void pci_setup(void) pci_mem_start <<= 1; } + /* Relocate PCI memory that overlaps reserved space, like RDM. */ + for ( j = 0; j < memory_map.nr_map ; j++ ) + { + if ( memory_map.map[j].type != E820_RAM ) + { + reserved_end = memory_map.map[j].addr + memory_map.map[j].size; + if ( check_overlap(pci_mem_start, pci_mem_end, + memory_map.map[j].addr, + memory_map.map[j].size) ) + pci_mem_start -= memory_map.map[j].size >> PAGE_SHIFT; + pci_mem_start = (pci_mem_start + max_bar_sz - 1) & + ~(uint64_t)(max_bar_sz - 1); + } + } + if ( mmio_total > (pci_mem_end - pci_mem_start) ) { printf("Low MMIO hole not large enough for all devices," @@ -407,8 +424,23 @@ void pci_setup(void) } base = (resource->base + bar_sz - 1) & ~(uint64_t)(bar_sz - 1); + reallocate_mmio: bar_data |= (uint32_t)base; bar_data_upper = (uint32_t)(base >> 32); + for ( j = 0; j < memory_map.nr_map ; j++ ) + { + if ( memory_map.map[j].type != E820_RAM ) + { + reserved_end = memory_map.map[j].addr + memory_map.map[j].size; + if ( check_overlap(base, bar_sz, + memory_map.map[j].addr, + memory_map.map[j].size) ) + { + base = (reserved_end + bar_sz - 1) & ~(uint64_t)(bar_sz - 1); + goto reallocate_mmio; + } + } + } base += bar_sz; if ( (base < resource->base) || (base > resource->max) ) -- 1.9.1