<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 28, 2021, 6:12 PM Dhananjay Phadke <<a href="mailto:dphadke@linux.microsoft.com">dphadke@linux.microsoft.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 28 May 2021, Andrew Jeffery wrote:<br>
><br>
> On Thu, 27 May 2021, at 22:53, sainath grandhi wrote:<br>
>> Hello,<br>
>> Our project has an FPGA connected to BMC as a PCIe endpoint. This<br>
>> endpoint provides a set of registers via MMIO and an interrupt for<br>
>> notifying completion of work. This endpoint also implements AER<br>
>> capability.<br>
>><br>
>> We have two options to enable this endpoint.<br>
>> 1) Write a new kernel module with a character device interface for<br>
>> user-space interaction.<br>
>> 2) Use VFIO infrastructure provided by Linux and write an user-space<br>
>> application.<br>
>><br>
>> I am reaching out to the community to check if there is any<br>
>> recommended option, using VFIO vs. implementing a new kernel module,<br>
>> or any previous experiences weighing in one option over the other.<br>
><br>
> I don't have any experience with VFIO, so take this with a grain of salt.<br>
><br>
> Generally you should write an in-kernel driver for it. The reason you<br>
> might not want to do so is if the device's register interface changes<br>
> frequently, as it's more pain to update the kernel than some userspace<br>
> application, which slows iteration. But handling DMAs and interrupts<br>
> make userspace more painful, so unless VFIO helps there (I assume it<br>
> does), then that would push the implementation back towards the kernel.<br>
<br>
VFIO requires IOMMU to protect kernel memory corruption by device DMA,<br>
which is programmed by (untrusted) userspace app. Unless the BMC SoC<br>
implements IOMMU (SMMU) for I/O virtualization (I/O page tables), it<br>
would not be possible/safe to use VFIO for DMA/interrupts.<br>
<br>
See <a href="https://www.kernel.org/doc/Documentation/vfio.txt" rel="noreferrer noreferrer" target="_blank">https://www.kernel.org/doc/Documentation/vfio.txt</a><br><br>Yeah. In our case the endpoint does not have DMA.  And uses INTx for interrupt to avoid memory corruption issues.</blockquote></div></div><div dir="auto"><br></div><div dir="auto"></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Our BMC does not support SMMU, so I am using VFIO with no IOMMU configuration. Linux kernel introduced VFIO without IOMMU for such platforms so that userspace applications can still take advantage of the VFIO facilities.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If you just want to program MMIO registers, you could mmap() PCIe sysfs<br>
resource files that represent MMIO bars and let application write and<br>
read registers, including polling for completion.<br>
<br>
See <a href="https://www.kernel.org/doc/Documentation/PCI/sysfs-pci.rst" rel="noreferrer noreferrer" target="_blank">https://www.kernel.org/doc/Documentation/PCI/sysfs-pci.rst</a><br>
<br>
If none of these options are viable, then a custom kernel driver would<br>
be necessary.<br>
<br>
Regards,<br>
Dhananjay<br>
</blockquote></div></div></div>