diff --git a/devices/common/pci/bandit.cpp b/devices/common/pci/bandit.cpp index 2dad3a5..f8f96da 100644 --- a/devices/common/pci/bandit.cpp +++ b/devices/common/pci/bandit.cpp @@ -200,7 +200,6 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_num, int &fun_num, uint8_t ®_offs, AccessDetails &details, PCIBase *&device) { - device = NULL; details.size = size; details.offset = offset & 3; fun_num = FUN_NUM(); @@ -219,12 +218,11 @@ inline void BanditHost::cfg_setup(uint32_t offset, int size, int &bus_num, for (dev_num = -1, idsel = this->config_addr; idsel; idsel >>= 1, dev_num++) {} LOG_F(ERROR, "%s: config_addr 0x%08x does not contain valid IDSEL", this->name.c_str(), (uint32_t)this->config_addr); + device = NULL; return; } dev_num = WHAT_BIT_SET(idsel); - if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) { - device = this->dev_map[DEV_FUN(dev_num, fun_num)]; - } + device = pci_find_device(dev_num, fun_num); } int BanditHost::device_postinit() diff --git a/devices/common/pci/pcihost.cpp b/devices/common/pci/pcihost.cpp index 009331c..78f12cc 100644 --- a/devices/common/pci/pcihost.cpp +++ b/devices/common/pci/pcihost.cpp @@ -187,14 +187,20 @@ PCIBase *PCIHost::pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_ for (auto& bridge : this->bridge_devs) { if (bridge->secondary_bus <= bus_num) { if (bridge->secondary_bus == bus_num) { - if (bridge->dev_map.count(DEV_FUN(dev_num, fun_num))) { - return bridge->dev_map[DEV_FUN(dev_num, fun_num)]; - } + return bridge->pci_find_device(dev_num, fun_num); } - else if (bridge->subordinate_bus >= bus_num) { + if (bridge->subordinate_bus >= bus_num) { return bridge->pci_find_device(bus_num, dev_num, fun_num); } } } return NULL; } + +PCIBase *PCIHost::pci_find_device(uint8_t dev_num, uint8_t fun_num) +{ + if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) { + return this->dev_map[DEV_FUN(dev_num, fun_num)]; + } + return NULL; +} diff --git a/devices/common/pci/pcihost.h b/devices/common/pci/pcihost.h index 0a354e6..e66d88a 100644 --- a/devices/common/pci/pcihost.h +++ b/devices/common/pci/pcihost.h @@ -76,6 +76,7 @@ public: virtual void pci_io_write_broadcast(uint32_t offset, int size, uint32_t value); virtual PCIBase *pci_find_device(uint8_t bus_num, uint8_t dev_num, uint8_t fun_num); + virtual PCIBase *pci_find_device(uint8_t dev_num, uint8_t fun_num); virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {} diff --git a/devices/memctrl/mpc106.cpp b/devices/memctrl/mpc106.cpp index 70db593..e5b6d62 100644 --- a/devices/memctrl/mpc106.cpp +++ b/devices/memctrl/mpc106.cpp @@ -168,7 +168,6 @@ inline void MPC106::cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_ int &fun_num, uint8_t ®_offs, AccessDetails &details, PCIBase *&device) { - device = NULL; details.size = size; details.offset = offset & 3; @@ -183,9 +182,7 @@ inline void MPC106::cfg_setup(uint32_t offset, int size, int &bus_num, int &dev_ } else { details.flags = PCI_CONFIG_TYPE_0; - if (this->dev_map.count(DEV_FUN(dev_num, fun_num))) { - device = this->dev_map[DEV_FUN(dev_num, fun_num)]; - } + device = pci_find_device(dev_num, fun_num); } }