Userspace vs kernel space driver

后端 未结 2 740
Happy的楠姐
Happy的楠姐 2020-12-13 02:28

I am looking to write a PWM driver. I know that there are two ways we can control a hardware driver:

  1. User space driver.
  2. Kernel space driver
  3. <
2条回答
  •  旧时难觅i
    2020-12-13 03:27

    Another consideration: it is far easier to debug user-space drivers. You can use gdb, valgrind, etc. Heck, you don't even have to write your driver in C.

    There's a third option beyond just user space or kernel space drivers: some of both. You can do just the kernel-space-only stuff in a kernel driver and do everything else in user space. You might not even have to write the kernel space driver if you use the Linux UIO driver framework (see https://www.kernel.org/doc/html/latest/driver-api/uio-howto.html).

    I've had luck writing a DMA-capable driver almost completely in user space. UIO provides the infrastructure so you can just read/select/epoll on a file to wait on an interrupt.

    You should be cognizant of the security implications of programming the DMA descriptors from user space: unless you have some protection in the device itself or an IOMMU, the user space driver can cause the device to read from or write to any address in physical memory.

提交回复
热议问题