GitHub - Zain-Naqvi-tech/linux-pci-dma-driver
Platform: QEMU EDU virtual PCI device (1234:11e8), x86-64 guest, Linux 6.8
Toolchain: Kbuild out-of-tree module, gcc for userspace, WSL2 host running a QEMU guest
Language: C, kernel space and userspace
An out-of-tree Linux kernel PCI driver written from scratch against QEMU’s EDU device. It enumerates the device, maps its registers, exposes it to userspace as a character device, handles MSI interrupts, and runs DMA transfers into and out of the device’s internal buffer. On top of that sits a benchmark that compares programmed I/O against DMA across eleven transfer sizes.
The reason I picked this instead of another bare-metal board project: kernel space is a different set of rules. Nothing I had written before had to worry about which context a function runs in, whether a pointer is safe to dereference, or what a device is allowed to do to system memory without asking. I wanted to find out what actually changes when the code you write is the thing standing between userspace and the hardware.
Everything runs inside a VM. When the driver takes down the kernel, and it did, the recovery is a five second reboot instead of a wrecked laptop.
ioremap./dev/edu with read, write, and ioctl.open, read, write,
ioctl, timing, CSV output.