From ad62e15d984ae766b110ad0b73fd352cdbd73001 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 25 Nov 2020 16:25:12 +0100 Subject: [PATCH] tools/litex_server: move PCIe specific bar renaming/enable to comm_pcie. --- litex/tools/litex_server.py | 8 -------- litex/tools/remote/comm_pcie.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) 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