Can hardware be accessed directly from user space?

Yes, but it is rarely useful. On 32-bit x86 systems, you can use the ioperm(2) system call to set up the current process to allow it to perform port I/O directly. I believe this does not work on 64-bit systems. You can also do lseek/read/write combinations against /dev/port and I think this likewise is not very portable. See http://tldp.org/HOWTO/IO-Port-Programming-2.html for some more details. Both of these approaches are much slower and less flexible than writing a device driver of course (/dev/port slowest of all). None of tese userspace mechanisms allow you to handle interrupts or anything like that, of course. If performance is an issue you're going to end up writing a device driver.


Your guess is correct. The kernel is the only software that can send hardware requests. That does not only hold true for Linux. Virtually no operating system newer than DOS lets you access hardware directly, because, as you also suspect, it's quite quite dangerous.

However, there is no problem in writing your own driver and plenty of documentation is available. For example, this tutorial at xatlantis seems a recent (that's important!) and good source.