RE: How to notify a user process from within a driver

Richard B. Johnson (root@chaos.analogic.com)
Fri, 2 May 2003 07:53:51 -0400 (EDT)


On Thu, 1 May 2003, Lee, Shuyu wrote:

> Richard and Alan,
>
> Thank you for the info. Given the prototype for poll() is
> "int poll(struct pollfd *ufds, unsigned int nfds, int timeout);", and pollfd
> is struct pollfd {int fd; short events; short revents};, how do I
> communicate complex info to the driver?
>
> For example, assuming there are 8 input lines on my hardware, and the user
> wants to be notified in the following three cases:
> 1) input on Line 1 only,
> 2) input on either Line 2 or Line 3,
> 3) input on both Line 4 and Line 5,
> how do I pass that info to the driver? Also, other than POLLERR and POLLHUP,
> can I pass back to the user more descriptive error messages?
>
> Thanks,
> Shuyu
>

poll() tells you something happened, ioctl() tells you what. Poll
has some bits (POLLIN, POLLOUT, etc.) that can be used to tell
the user-mode task what information to actually request in the
ioctl() call. Your ioctl() can receive and send anything if you
use the third variable as a pointer to your stuff.

struct info {
int a;
int b;
...
...
} info;
int fd;
struct pollfd pfd;
fd = open("/dev/device", O_RDWR);

pfd.fd = fd;
pfd.events = POLLIN;
pfd.revents = 0;
if(poll(&pfd, 1, 0) <= 0)
handle_problem();
else if (pfd.revents & POLLIN)
ret = ioctl(fd, GET_MY_INFORMATION, &foo);
else if (pfd.revents & POLLOUT)
ret = ioctl(fd, CHANGE_CONFIGURATION, &how);

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/