0

Is it possible to write serial driver in userspace, yet, have the device appear as regular serial driver /dev/ttyS0 in the system ?

The full story is that we have a pci express fpga, and there are several devices behind the pci express fpga: serials, canbus, i2c, mdio, etc.

I thought to implement it as uio_pci_generic, yet the serial driver is a bit problematic because we rather that it will appear as regular serial /dev/ttyS0.

If the above is not possible: Is it possible to implement some of the pci devices in kernel (serial) and others in userspace ? Is it problematic in terms of interrupt ?

Thanks for any idea.

ransh
  • 1,589
  • 4
  • 30
  • 56

2 Answers2

2

Yes, you can do this using a pty. The user mode driver opens the master end of the pty and the application that wants to use the serial port opens the slave end. Search for Linux pty.

prl
  • 11,716
  • 2
  • 13
  • 31
  • It won’t be ttyS0, it will be ttypX. I presume that is acceptable. – prl Jan 02 '19 at 10:30
  • It's still different. we can't set baud rate, or use stty for example, right ? – ransh Jan 02 '19 at 14:16
  • 1
    Yes, I think you can. https://stackoverflow.com/questions/21641754/when-pty-pseudo-terminal-slave-fd-settings-are-changed-by-tcsetattr-how-ca – prl Jan 02 '19 at 16:53
  • One last: are you familiar with any example showing pty with real device ? Thanks a lot! – ransh Jan 03 '19 at 08:44
1

Everywhere where you need to use interrupts you need to write code for kernel space not user space. Interrupt handlers need to be serviced in atomic context and user space is not able to provide atomic context. Second thing - if you need to write HAL layer - it also has to be written in kernel space.

user2699113
  • 4,262
  • 3
  • 25
  • 43