tools/litex_server: move PCIe specific bar renaming/enable to comm_pcie.

This commit is contained in:
Florent Kermarrec 2020-11-25 16:25:12 +01:00
parent 595c6738a3
commit ad62e15d98
2 changed files with 12 additions and 8 deletions

View File

@ -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)

View File

@ -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