# Linux Kernel Module Cheat

##### 23.6.1.1. QEMU edu PCI device

Small upstream educational PCI device:

    ./qemu_edu.sh

This tests a lot of features of the edu device, to understand the results, compare the inputs with the documentation of the hardware: https://github.com/qemu/qemu/blob/v2.12.0/docs/specs/edu.txt

Sources:

- kernel module: kernel_modules/qemu_edu.c

- QEMU device: https://github.com/qemu/qemu/blob/v2.12.0/hw/misc/edu.c

- test script: rootfs_overlay/lkmc/qemu_edu.sh

Works because we add to our default QEMU CLI:

    -device edu

This example uses:

- the QEMU `edu` educational device, which is a minimal educational in-tree PCI example

- the `pci.ko` kernel module, which exercises the `edu` hardware.

  I’ve contacted the awesome original author author of `edu` Jiri Slaby, and he told there is no official kernel module example because this was created for a kernel module university course that he gives, and he didn’t want to give away answers. I don’t agree with that philosophy, so students, cheat away with this repo and go make startups instead.

TODO exercise DMA on the kernel module. The `edu` hardware model has that feature:

- https://stackoverflow.com/questions/17913679/how-to-instantiate-and-use-a-dma-driver-linux-module

- https://stackoverflow.com/questions/32592734/are-there-any-dma-driver-example-pcie-and-fpga/44716747#44716747

- https://stackoverflow.com/questions/62831327/add-memory-device-to-qemu

- https://stackoverflow.com/questions/64539528/qemu-pci-dma-read-and-pci-dma-write-does-not-work

- https://stackoverflow.com/questions/64842929/general-protection-error-while-tring-to-perform-ioctl