diff -r b6eea72ea9dc tools/firmware/hvmloader/hvmloader.c --- a/tools/firmware/hvmloader/hvmloader.c Mon Sep 01 11:29:01 2008 +0100 +++ b/tools/firmware/hvmloader/hvmloader.c Tue Sep 02 08:40:22 2008 +0900 @@ -268,6 +268,7 @@ static void pci_setup(void) /* Assign iomem and ioport resources in descending order of size. */ for ( i = 0; i < nr_bars; i++ ) { + int use_orig_resource = 0; devfn = bars[i].devfn; bar_reg = bars[i].bar_reg; bar_sz = bars[i].bar_sz; @@ -278,7 +279,15 @@ static void pci_setup(void) PCI_BASE_ADDRESS_SPACE_MEMORY ) { resource = &mem_resource; - bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK; + if ((bar_data & PCI_BASE_ADDRESS_MEM_MASK) == 0 || + (PCI_MEMBASE <= (bar_data & PCI_BASE_ADDRESS_MEM_MASK) && + (bar_data & PCI_BASE_ADDRESS_MEM_MASK) < PCI_MEMBASE + + PCI_MEMSIZE)) { + bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK; + } else { + use_orig_resource = 1; + printf("use original BAR value [%04x].\n", bar_data); + } } else { @@ -286,22 +294,24 @@ static void pci_setup(void) bar_data &= ~PCI_BASE_ADDRESS_IO_MASK; } - base = (resource->base + bar_sz - 1) & ~(bar_sz - 1); - bar_data |= base; - base += bar_sz; - - if ( (base < resource->base) || (base > resource->max) ) - { - printf("pci dev %02x:%x bar %02x size %08x: no space for " - "resource!\n", devfn>>3, devfn&7, bar_reg, bar_sz); - continue; - } - - resource->base = base; - - pci_writel(devfn, bar_reg, bar_data); - printf("pci dev %02x:%x bar %02x size %08x: %08x\n", - devfn>>3, devfn&7, bar_reg, bar_sz, bar_data); + if (! use_orig_resource) { + base = (resource->base + bar_sz - 1) & ~(bar_sz - 1); + bar_data |= base; + base += bar_sz; + + if ( (base < resource->base) || (base > resource->max) ) + { + printf("pci dev %02x:%x bar %02x size %08x: no space for " + "resource!\n", devfn>>3, devfn&7, bar_reg, bar_sz); + continue; + } + + resource->base = base; + + pci_writel(devfn, bar_reg, bar_data); + printf("pci dev %02x:%x bar %02x size %08x: %08x\n", + devfn>>3, devfn&7, bar_reg, bar_sz, bar_data); + } /* Now enable the memory or I/O mapping. */ cmd = pci_readw(devfn, PCI_COMMAND);