Hi everybody,
I want to passthrough the two SPI controller of the RPI 4 each to a QEMU/KVM client. If this is possible at all and if so can you give me some advice how to pull this of.
I know that the RPI 4 doesnt support IOMMU groupings, but maybe there is some way around this.
If your CPU does not have an IOMMU, you cannot use PCI passthrough.
You might be able to forward the SPI by creating a virtual SPI device and connecting it on the host. I’m not entirely sure though.
Thank you for the advice!
When typing lspci into the console the SPI controller dont get listed, so I think that they are not connected via PCIe.
I will try to go the virtual SPI device route, but I never have created virtual devices before. Sounds like an adventure 
lsusb? I’m not sure how they’re connected either.
SPI slave devices need no IOMMU because they don’t have an address range mapped to the host. SPI master devices can be abstracted by using the spidev character device API (via /dev/spidev character devices) simply mapped to the slave devices (https://www.kernel.org/doc/Documentation/spi/spidev).
As far as I can tell, QEMU has no support for it, but it seems it would be possible even without support by QEMU, by creating a cuse (cuse.c « fuse « fs - kernel/git/stable/linux.git - Linux kernel stable tree) device which forwards the spidev read/write/ioctl syscalls to the host (over a pipe or socket).
Surprisingly, I can’t find any hits on Google about such a thing but I can’t think of any reason why it wouldn’t work…
Thank you very much!
So if I understand correctly, I have to create a virtual spidev device on the client and try to forward those syscalls to the host. Is this correct?
Nether they seem to be connected via usb. lsusb list the USB 3.0 and 2.0 controller and my keyboard and mouse.
I think this is the right idea. Don’t virtualize SPI, instead write a utility to expose a higher level service over a socket.
…
btw, what’s the device you’re connecting to from the VM?
I‘am connecting two Dragino LoRa/GPS shields to the RPI.
There is now just one question remaining. Right now I am using the Semtec UDP Package Forwarder for forwarding UDP packages to the LoRa shield. The question now is, how to tell the forwarder to connect to the socket and not to /dev/spidev.