Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/57015 )
Change subject: dev: Factor out the majority of read|writeConfig.
......................................................................
dev: Factor out the majority of read|writeConfig.
Most of what these two methods are doing in the GenericPciHost are
essentially required for any PCI host. They must be able to get the
device associated with a BDF, and then ask it to either read or write to
its config space. The DPRINTF is also non-trivial and generic.
This also uses structured binding to tidy up the moved code slightly.
Change-Id: I79187bbd2a56e4f40ebeda0e7c228e30c72f1d7d
---
M src/dev/pci/host.cc
M src/dev/pci/host.hh
2 files changed, 65 insertions(+), 35 deletions(-)
diff --git a/src/dev/pci/host.cc b/src/dev/pci/host.cc
index e7dea6c..ce86967 100644
--- a/src/dev/pci/host.cc
+++ b/src/dev/pci/host.cc
@@ -86,6 +86,48 @@
return device != devices.end() ? device->second : nullptr;
}
+Tick
+PciHost::writeConfig(const PciBusAddr &bdf, Addr offset, PacketPtr pkt)
+{
+ const Addr size = pkt->getSize();
+ const auto &[bus, dev, func] = bdf;
+ pkt->makeAtomicResponse();
+ DPRINTF(PciHost, "%02x:%02x.%i: write: offset=0x%x, size=0x%x\n",
+ bus, dev, func, offset, size);
+
+ PciDevice *const pci_dev = getDevice(bdf);
+ panic_if(!pci_dev,
+ "%02x:%02x.%i: Write to config space on non-existent PCI
device",
+ bus, dev, func);
+
+ // @todo Remove this after testing
+ pkt->headerDelay = pkt->payloadDelay = 0;
+
+ return pci_dev->writeConfig(pkt);
+}
+
+Tick
+PciHost::readConfig(const PciBusAddr &bdf, Addr offset, PacketPtr pkt)
+{
+ const auto &[bus, dev, func] = bdf;
+ const Addr size = pkt->getSize();
+ uint8_t *pkt_data = pkt->getPtr<uint8_t>();
+ pkt->makeAtomicResponse();
+
+ DPRINTF(PciHost, "%02x:%02x.%i: read: offset=0x%x, size=0x%x\n",
+ bus, dev, func, offset, size);
+
+ PciDevice *const pci_dev = getDevice(bdf);
+ if (pci_dev) {
+ // @todo Remove this after testing
+ pkt->headerDelay = pkt->payloadDelay = 0;
+ return pci_dev->readConfig(pkt);
+ } else {
+ std::fill(pkt_data, pkt_data + size, 0xFF);
+ return 0;
+ }
+}
+
PciHost::DeviceInterface::DeviceInterface(
PciHost &_host,
PciBusAddr &bus_addr, PciIntPin interrupt_pin)
@@ -136,46 +178,15 @@
Tick
GenericPciHost::read(PacketPtr pkt)
{
- const auto dev_addr(decodeAddress(pkt->getAddr() - confBase));
- const Addr size(pkt->getSize());
-
- DPRINTF(PciHost, "%02x:%02x.%i: read: offset=0x%x, size=0x%x\n",
- dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func,
- dev_addr.second,
- size);
-
- PciDevice *const pci_dev(getDevice(dev_addr.first));
- if (pci_dev) {
- // @todo Remove this after testing
- pkt->headerDelay = pkt->payloadDelay = 0;
- return pci_dev->readConfig(pkt);
- } else {
- uint8_t *pkt_data(pkt->getPtr<uint8_t>());
- std::fill(pkt_data, pkt_data + size, 0xFF);
- pkt->makeAtomicResponse();
- return 0;
- }
+ const auto &[bdf, offset] = decodeAddress(pkt->getAddr() - confBase);
+ return readConfig(bdf, offset, pkt);
}
Tick
GenericPciHost::write(PacketPtr pkt)
{
- const auto dev_addr(decodeAddress(pkt->getAddr() - confBase));
-
- DPRINTF(PciHost, "%02x:%02x.%i: write: offset=0x%x, size=0x%x\n",
- dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func,
- dev_addr.second,
- pkt->getSize());
-
- PciDevice *const pci_dev(getDevice(dev_addr.first));
- panic_if(!pci_dev,
- "%02x:%02x.%i: Write to config space on non-existent PCI
device\n",
- dev_addr.first.bus, dev_addr.first.dev, dev_addr.first.func);
-
- // @todo Remove this after testing
- pkt->headerDelay = pkt->payloadDelay = 0;
-
- return pci_dev->writeConfig(pkt);
+ const auto &[bdf, offset] = decodeAddress(pkt->getAddr() - confBase);
+ return writeConfig(bdf, offset, pkt);
}
AddrRangeList
diff --git a/src/dev/pci/host.hh b/src/dev/pci/host.hh
index 04302f5..f7bd459 100644
--- a/src/dev/pci/host.hh
+++ b/src/dev/pci/host.hh
@@ -240,6 +240,9 @@
*/
const PciDevice *getDevice(const PciBusAddr &addr) const;
+ Tick writeConfig(const PciBusAddr &bdf, Addr offset, PacketPtr pkt);
+ Tick readConfig(const PciBusAddr &bdf, Addr offset, PacketPtr pkt);
+
private:
/** Currently registered PCI devices */
std::map<PciBusAddr, PciDevice *> devices;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/57015
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I79187bbd2a56e4f40ebeda0e7c228e30c72f1d7d
Gerrit-Change-Number: 57015
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s