现有内核驱动程序应如何初始化为 PCI 内存映射?

How existing kernel driver should be initialized as PCI memory-mapped?

现有的内核驱动程序(如 xilinx)有特定的注册方式(作为 tty 设备),如果它们直接映射到 cpu 内存映射,就像这里使用设备树所做的那样: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842249/Uartlite+Driver

但在其他情况下,有一个 PCIe 设备(如具有 xilinx uart IP 的 FPGA)连接到 cpu。

使用PCIe设备时如何让uart注册成功?

我尝试注册到 PCIe 的设备树是 uartlite 驱动程序: https://github.com/Xilinx/linux-xlnx/blob/master/drivers/tty/serial/uartlite.c

我认为我可能需要做的是:

  1. 编写自定义 pci 驱动程序。

  2. 需要准备platform_device结构,然后从pci驱动调用uart探测例程:

    ulite_probe(结构platform_device *pdev)

我已经看到其他人在连接多个设备的情况下使用 FPGA 的相关问题,但似乎没有描述如何执行此操作的文档或教程。

欢迎任何评论、示例或文档。

像 ARM CPU 这样的东西通过 PCIe 连接到 Artix FPGA 对吗?

是的,您需要自定义 PCIe 驱动程序。必须映射 PCIe 配置和数据 spaces。查看 pci_resource_{start, len} 和 pci_remap_bar 函数。然后,您可以使用 pci_get_device 获取指向结构设备的指针并检索 PCIe 配置的虚拟地址 space。然后,UART 驱动程序可以使用结构设备指针,并且它的寄存器映射应该根据您的设计与 PCIe 配置的虚拟地址 space 有一定的偏移量。您可以在自己的驱动中调用UARTlite IP驱动的probe call。

"Existing kernel drivers such as xilinx have specific way to be registered (as tty device), if they are mapped directly to cpu memory map as done here with device tree"。请注意,如果我们只谈论 tty 设备,这是正确的。 GPIO 外设 IP 不会公开为 tty,而是在 /sys/class/gpio.