poll/select implementation in tty Linux driver


Results 1 to 11 of 11

Thread: poll/select implementation in tty Linux driver

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    4

    poll/select implementation in tty Linux driver

    Hi,

    I need to implement poll function in my tty Linux driver , user space application should call poll/select functions in user space. The problem is tty_operations does not support poll() function, like file_operations.

    How can I implement it?

    Thank you

  2. #2
    Join Date
    Dec 2003
    Location
    Phoenix, AZ
    Posts
    647
    Quote Originally Posted by mudak777
    Hi,

    I need to implement poll function in my tty Linux driver , user space application should call poll/select functions in user space. The problem is tty_operations does not support poll() function, like file_operations.

    How can I implement it?

    Thank you

    Sure they do! Because each tty has a set of file descriptors (stdin,stdout,stderr) that go along with them. That what is what you want to poll or select on. For example you could select on STDIN_FILENO (defined in unistd.h) to poll for input on the stdin of your tty. You can throw STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO into your fdset to poll anything that crosses the tty.

    AFAIK your process will have only have access to it's tty/pty/pts. It won't be able to access the pty's owned by other processes from user space. Check out the ttysnoop source for a little simple lesson on how to access anyone's tty from kernel space.
    "There's a big difference between "copy" and "use". It's exatcly the same
    issue whether it's music or code. You can't re-distribute other peoples
    music (becuase it's _their_ copyright), but they shouldn't put limits on
    how you personally _use_ it (because it's _your_ life)."

    --Linus Torvalds

  3. #3
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Um, I think he's writing a TTY driver, not a userspace program.

    If I'm right, and you're doing a kernel-mode driver, the poll() implementation for TTYs is (at least in 2.6.18) held in the line discipline structure, not the tty_struct. The tty_struct has an "ldisc" member, which is a tty_ldisc. That ldisc's "poll" member should point to your poll routine.

    The TTY file_operations structure has a poll member that points at drivers/char/tty_io.c's tty_poll function. See that function (and functions in the rest of the file) to find out how it gets the function that does the real polling. I'm sure there's a sample TTY driver implementation somewhere in the kernel, but I don't know where it would be.

  4. #4
    Join Date
    Nov 2006
    Posts
    4

    Kernel-mode driver

    Hi,

    Thank you for your respond.

    Yes, I'm doing a kernel mode driver. The problem is, that customer wants
    to use in his user space application select function. That means I need to
    implement in my driver poll() function. Unfortunately I did not find any example
    in Linux serial drivers. I used last Linux kernel, but have no idea how to use line discipline with tty_struct, since I use open,close, write, ioctl etc in tty_struct. I know tty_io.c has tty_poll() function, I need maybe somhow to call it from my driver.

    Quote Originally Posted by bwkaz
    Um, I think he's writing a TTY driver, not a userspace program.

    If I'm right, and you're doing a kernel-mode driver, the poll() implementation for TTYs is (at least in 2.6.18) held in the line discipline structure, not the tty_struct. The tty_struct has an "ldisc" member, which is a tty_ldisc. That ldisc's "poll" member should point to your poll routine.

    The TTY file_operations structure has a poll member that points at drivers/char/tty_io.c's tty_poll function. See that function (and functions in the rest of the file) to find out how it gets the function that does the real polling. I'm sure there's a sample TTY driver implementation somewhere in the kernel, but I don't know where it would be.

  5. #5
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    No, you don't call tty_poll from your driver. tty_poll is the TTY device's poll() handler, and it calls into your driver through the line discipline struct. Your driver is still what does the poll() implementation, it just doesn't do it directly in the file_operations struct (because it doesn't have one). It does it by setting up tty->ldisc (where "tty" is your driver's tty_struct) and then sets tty->ldisc->poll to your poll() handler function.

    I still haven't found a sample tty_struct handler that uses an ldisc (or that doesn't, for that matter). I'd really like to know where one is hiding; that whole interface wouldn't exist unless it needed to...

  6. #6
    Join Date
    Nov 2006
    Posts
    4
    I added struct tty_ldisc as a second srtucture to my driver (it had before tty_operations), and after calling select() function in application (user level),
    I'm able to awake poll function inside my tty driver. But it's strange to use both structures tty_ldisc and tty_operations in one driver.

    Have you any idea?

  7. #7
    Join Date
    Dec 2003
    Location
    Phoenix, AZ
    Posts
    647
    Ah, he wrote:

    Quote Originally Posted by mudak777

    poll function in my tty Linux driver , user space application

    And I read:

    Quote Originally Posted by mudak777
    poll function in my tty Linux user space application
    And I was wondering to myself why he specified user space application.
    "There's a big difference between "copy" and "use". It's exatcly the same
    issue whether it's music or code. You can't re-distribute other peoples
    music (becuase it's _their_ copyright), but they shouldn't put limits on
    how you personally _use_ it (because it's _your_ life)."

    --Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •