Linux 启动后查找并启用连接的 PCIe 设备

发布于 2024-10-09 14:04:00 字数 601 浏览 8 评论 0原文

我们正在开发一个通过 PCIe 连接到 Linux PC 主机的嵌入式系统。目前,在实现和调试阶段,我经常需要对设备进行断电和上电,或者尝试不同的板卡。这会导致在 Intel PC 上运行的 Linux(Ubuntu 或 Debian)出现问题。

通常,当我需要插入被测设备时,PC 就会启动。正如预期的那样,Linux 找不到该设备,并且软件应用程序无法与其通信。如果我执行“lspci -v”,那么它不会列出我们的设备。我们的应用程序使用 libpci(使用 -lpci 构建的程序)来访问我们的设备公开的单个 BAR,然后通过执行 page_remap 的内核模块进行“mmap”。我们的解决方法是重新启动 PC,然后设备可见并启用。

我正在寻找一种解决方案,使我不必经常重新启动电脑(一天数十次)。我不能连接设备然后运行一些代码来让 Linux 内核检测并启用我们设备的 BAR 吗?我希望找到一些有关使用 PCI 支持库的文档和示例,但一直未能找到。任何指示表示赞赏。也许我可以在代码中执行诸如 pci_enable_device() 或 pci_find_device() 等调用?但我无法弄清楚。我可以编写内核模块以及用户代码来使其正常工作,即,我对是否具有 root 访问权限没有任何限制。

非常感谢您的建议和指点, 古拉夫

We are developing an embedded system connected to a Linux PC host over PCIe. Right now, in the implementation and debug phase, I often need to power off and power on the device or try different boards. This causes a problem with the Linux (Ubuntu or Debian) running on the Intel PC.

Typically the PC is booted when I need to insert the device under test. As expected, the Linux doesn't find the device and the software app cannot talk to it. If I do "lspci -v" then it does not list our device. Our application uses libpci (programs built with -lpci) to gain access to the single BAR exposed by our device which is then "mmap" via our kernel module that does a page_remap. Our workaround is to reboot the PC after which the device is visible and enabled.

I am looking for a solution where I don't have to reboot the PC so often (tens of times during a day). Can't I connect the device and then run some code to make the Linux kernel detect and enable the BAR of our device? I was hoping to find some documentation on using the PCI Support Library and examples but haven't been able to. Any pointers appreciated. Perhaps there are calls like pci_enable_device() or pci_find_device() etc. that I can execute in my code? I can't figure out though. I can write kernel modules as well as user code to get this working, i.e., I don't have any restrictions on whether I have root access or not.

Thanks a lot for your advice and pointers,
Guraaf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-10-16 14:04:00

您是否尝试通过以下方式重新加载模块(在设备拔下插头时):

rmmod yourmodule
modprobe yourmodule

并重新插入设备。

Did you try to reload your module (while the device is unplugged) with:

rmmod yourmodule
modprobe yourmodule

And re-plug the device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文