diff --git a/litex/tools/litex_server.py b/litex/tools/litex_server.py index d19a920b8..6c15c4e57 100755 --- a/litex/tools/litex_server.py +++ b/litex/tools/litex_server.py @@ -217,14 +217,6 @@ def main(): if pcie_bar is None: print("Need to speficy --pcie-bar, exiting.") exit() - if "/sys/bus/pci/devices" not in pcie_bar: - pcie_bar = f"/sys/bus/pci/devices/0000:{args.pcie_bar}/resource0" - # Enable PCIe device is not already enabled. - enable = open(pcie_bar.replace("resource0", "enable"), "r+") - if enable.read(1) == "0": - enable.seek(0) - enable.write("1") - enable.close() print("[CommPCIe] bar: {} / ".format(pcie_bar), end="") comm = CommPCIe(pcie_bar, debug=args.debug) diff --git a/litex/tools/remote/comm_pcie.py b/litex/tools/remote/comm_pcie.py index 371fd765f..437694089 100644 --- a/litex/tools/remote/comm_pcie.py +++ b/litex/tools/remote/comm_pcie.py @@ -15,9 +15,21 @@ from litex.tools.remote.csr_builder import CSRBuilder class CommPCIe(CSRBuilder): def __init__(self, bar, csr_csr=None, debug=False): CSRBuilder.__init__(self, comm=self, csr_csv=csr_csv) + if "/sys/bus/pci/devices" not in bar: + bar = f"/sys/bus/pci/devices/0000:{bar}/resource0" self.bar = bar self.debug = debug + self.enable() + + def enable(self): + # Enable PCIe device is not already enabled. + enable = open(self.bar.replace("resource0", "enable"), "r+") + if enable.read(1) == "0": + enable.seek(0) + enable.write("1") + enable.close() + def open(self): if hasattr(self, "file"): return