heikoengel / pyPCIe

Simple Python Module to access PCIe Endpoint BARs
MIT License
16 stars 4 forks source link

How to fix "OSError: [Errno 19] No such device" issue? #2

Open maliang78023367 opened 6 months ago

maliang78023367 commented 6 months ago
import os
from pypcie import Device

# Bind to PCI device at "0000:03:00.0"
d = Device("0000:00:02.0")
# Access BAR 0
bar = d.bar[0]

# write 0xdeadbeef to BAR 0, offset 0x1000
bar.write(0x100, 0xdeadbeef)

# read BAR 0, offset 0x1004
ret = bar.read(0x104)

print(ret)

Issue: root@PC-13:/home/work/script/script/script/pyPCIe-main# python3 test_pcie_bar.py /sys/bus/pci/devices/0000:00:02.0/resource0 /sys/bus/pci/devices/0000:00:02.0/resource2 /sys/bus/pci/devices/0000:00:02.0/resource4 Traceback (most recent call last): File "test_pcie_bar.py", line 6, in d = Device("0000:00:02.0") File "/home/work/script/script/script/pyPCIe-main/pypcie/device.py", line 23, in init self.bar[barnum] = Bar(resfile) File "/home/work/script/script/script/pyPCIe-main/pypcie/bar.py", line 19, in init self.__map = mmap(fd, 0, prot=PROT_READ | PROT_WRITE) OSError: [Errno 19] No such device

root@PC-13:/home//work/script/script/script/pyPCIe-main# ls /sys/bus/pci/devices/0000\:00\:02.0
ari_enabled                device           i2c-3  link            power_state   revision                 subsystem_device
boot_vga                   dma_mask_bits    i2c-4  local_cpulist   remove        rom                      subsystem_vendor
broken_parity_status       driver           i2c-5  local_cpus      rescan        sriov_drivers_autoprobe  uevent
class                      driver_override  i2c-6  max_link_speed  reset         sriov_numvfs             vendor
config                     drm              i2c-7  max_link_width  reset_method  sriov_offset
consistent_dma_mask_bits   enable           i2c-8  modalias        resource      sriov_stride
consumer:pci:0000:00:1f.3  firmware_node    i2c-9  msi_bus         resource0     sriov_totalvfs
current_link_speed         graphics         index  msi_irqs        resource2     sriov_vf_device
current_link_width         i2c-10           irq    numa_node       resource2_wc  sriov_vf_total_msix
d3cold_allowed             i2c-2            label  power           resource4     subsystem
heikoengel commented 5 months ago

I haven't seen this with the devices I tested so far, so I'm just guessing:

bingoc0c0 commented 3 weeks ago

The device ID is incorrect. You should enter the CPU ID instead of the controller ID.