diff --git a/hw/pass-through.c b/hw/pass-through.c index a848164..1afbe5b 100644 --- a/hw/pass-through.c +++ b/hw/pass-through.c @@ -2031,7 +2031,8 @@ static void pt_bar_mapping_one(struct pt_dev *ptdev, int bar, int io_enable, /* check overlapped address */ ret = pt_chk_bar_overlap(dev->bus, dev->devfn, - r_addr, r_size, r->type); + r_addr, r_size, r->type, bar); + if (ret > 0) PT_LOG("Warning: ptdev[%02x:%02x.%x][Region:%d][Address:%08xh]" "[Size:%08xh] is overlapped.\n", pci_bus_num(dev->bus), diff --git a/hw/pci.c b/hw/pci.c index d7c516e..4f2e82c 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -919,13 +919,17 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, return s->bus; } +#define MEMORYSPACE_BAR_MASK 0xFFFFFC00 +#define IOSPACE_BAR_MASK 0xFFFFFFFC +#define EXPANSION_ROM_BAR_MASK 0xFFFFFFFE int pt_chk_bar_overlap(PCIBus *bus, int devfn, uint32_t addr, - uint32_t size, uint8_t type) + uint32_t size, uint8_t type, int index) { PCIDevice *devices = NULL; PCIIORegion *r; int ret = 0; int i, j; + uint32_t mask=0xFFFFFFFF; /* check Overlapped to Base Address */ for (i=0; i<256; i++) @@ -951,7 +955,16 @@ int pt_chk_bar_overlap(PCIBus *bus, int devfn, uint32_t addr, continue; } - if ((addr < (r->addr + r->size)) && ((addr + size) > r->addr)) + if (index == PCI_ROM_SLOT) + mask = EXPANSION_ROM_BAR_MASK; + else if (type == PCI_ADDRESS_SPACE_IO) + mask = IOSPACE_BAR_MASK; + else if (type == PCI_ADDRESS_SPACE_MEM || + type == PCI_ADDRESS_SPACE_MEM_PREFETCH ) + mask = MEMORYSPACE_BAR_MASK; + + if (((addr&mask) < (r->addr + r->size)) && + (((addr&mask) + size) > r->addr)) { printf("Overlapped to device[%02x:%02x.%x][Region:%d]" "[Address:%08xh][Size:%08xh]\n", bus->bus_num, diff --git a/hw/pci.h b/hw/pci.h index d45b80c..e0c101d 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -225,7 +225,7 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num, PCIMapIORegionFunc *map_func); int pt_chk_bar_overlap(PCIBus *bus, int devfn, uint32_t addr, - uint32_t size, uint8_t type); + uint32_t size, uint8_t type, int index); uint32_t pci_default_read_config(PCIDevice *d, uint32_t address, int len);