diff --git a/README.adoc b/README.adoc index e9a522b..a32e63b 100644 --- a/README.adoc +++ b/README.adoc @@ -4858,6 +4858,48 @@ But in part because it is dying, I didn't spend much effort to integrate it into Maybe some brave soul will send a pull request one day. +=== UIO + +UIO is a kernel subsystem that allows to do certain types of driver operations from userland. + +This would be awesome to improve debugability and safety of kernel modules. + +VFIO looks like a newer and better UIO replacement, but there do not exist any examples of how to use it: https://stackoverflow.com/questions/49309162/interfacing-with-qemu-edu-device-via-userspace-i-o-uio-linux-driver + +TODO get something interesting working. I currently don't understand the behaviour very well. + +TODO how to ACK interrupts? How to ensure that every interrupt gets handled separately? + +TODO how to write to registers. Currently using `/dev/mem` and `lspci`. + +This example should handle interrupts from userland and print a message to stdout: + +.... +/uio_read.sh +.... + +TODO: what is the expected behaviour? I should have documented this when I wrote this stuff, and I'm that lazy right now that I'm in the middle of a refactor :-) + +Sources: + +* link:kernel_module/user/uio_read.c[] +* link:rootfs_overlay/uio_read.sh[] + +Bibliography: + +* https://stackoverflow.com/questions/15286772/userspace-vs-kernel-space-driver +* https://01.org/linuxgraphics/gfx-docs/drm/driver-api/uio-howto.html +* https://stackoverflow.com/questions/7986260/linux-interrupt-handling-in-user-space +* https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt/ +* https://github.com/bmartini/zynq-axis/blob/65a3a448fda1f0ea4977adfba899eb487201853d/dev/axis.c +* https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt/ +* http://nairobi-embedded.org/uio_example.html that website has QEMU examples for everything as usual. The example has a kernel-side which creates the memory mappings and is used by the user. +* https://stackoverflow.com/questions/49309162/interfacing-with-qemu-edu-device-via-userspace-i-o-uio-linux-driver +* userland driver stability questions: +** https://stackoverflow.com/questions/8030758/getting-kernel-version-from-linux-kernel-module-at-runtime/45430233#45430233 +** https://stackoverflow.com/questions/37098482/how-to-build-a-linux-kernel-module-so-that-it-is-compatible-with-all-kernel-rele/45429681#45429681 +** https://liquidat.wordpress.com/2007/07/21/linux-kernel-2623-to-have-stable-userspace-driver-api/ + === Linux kernel interactive stuff [[fbcon]] diff --git a/kernel_module/user/uio_read.c b/kernel_module/user/uio_read.c index cb70f80..299a0fb 100644 --- a/kernel_module/user/uio_read.c +++ b/kernel_module/user/uio_read.c @@ -1,32 +1,4 @@ -/* -TODO get working. Currently I don't understand the behaviour. - -TODO how to ACK interrupts? How to ensure that every interrupt gets handled separately? - -TODO write to registers. Currently using /dev/mem and lspci. - -Handle interrupts from userland and print a message to stdout. - -- Userland driver -- https://stackoverflow.com/questions/15286772/userspace-vs-kernel-space-driver -- https://01.org/linuxgraphics/gfx-docs/drm/driver-api/uio-howto.html -- https://stackoverflow.com/questions/7986260/linux-interrupt-handling-in-user-space -- https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt/ -- https://github.com/bmartini/zynq-axis/blob/65a3a448fda1f0ea4977adfba899eb487201853d/dev/axis.c -- https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt/ -- http://nairobi-embedded.org/uio_example.html that website has QEMU examples for everything as usual. The example has a kernel-side which creates the memory mappings and is used by the user. -- https://stackoverflow.com/questions/49309162/interfacing-with-qemu-edu-device-via-userspace-i-o-uio-linux-driver - -Userland driver stability questions: - -- https://stackoverflow.com/questions/8030758/getting-kernel-version-from-linux-kernel-module-at-runtime/45430233#45430233 -- https://stackoverflow.com/questions/37098482/how-to-build-a-linux-kernel-module-so-that-it-is-compatible-with-all-kernel-rele/45429681#45429681 -- https://liquidat.wordpress.com/2007/07/21/linux-kernel-2623-to-have-stable-userspace-driver-api/ - -VFIO looks like the newer UIO replacement, but there are no examples out there anywhere: - -- https://stackoverflow.com/questions/49309162/interfacing-with-qemu-edu-device-via-userspace-i-o-uio-linux-driver -*/ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#uio */ #if 1 diff --git a/rootfs_overlay/uio_read.sh b/rootfs_overlay/uio_read.sh index 935f697..459cdca 100755 --- a/rootfs_overlay/uio_read.sh +++ b/rootfs_overlay/uio_read.sh @@ -1,5 +1,6 @@ #!/bin/sh -set -ex +# https://github.com/cirosantilli/linux-kernel-module-cheat#uio +set -e modprobe uio_pci_generic # pci_min device echo '1234 11e9' > /sys/bus/pci/drivers/uio_pci_generic/new_id @@ -13,3 +14,4 @@ devmem "0x${base}" w 0x12345678 devmem "0x$(($base + 4))" w 0x12345678 devmem "0x${base}" w 0x12345678 devmem "0x$(($base + 4))" w 0x12345678 +modprobe -r uio_pci_generic