poll_wait adds your device (represented by a "structure file") to the list of those that may wake up the process.
The idea is that a process can use polling (either select or epoll, etc.) to add a bunch of file descriptors to the list it wants to wait on. A record is requested for each driver. Everyone adds himself (through poll_wait) to the list of waiters.
Then the main core blocks the process in one place. Thus, any of the devices can wake up the process. If you return non-zero bits of the mask, it means that those “ready-made” attributes (readable / writable / etc) are now applied.
So, in pseudo code, it is something like this:
foreach fd: find device corresponding to fd call device poll function to setup wait queues (with poll_wait) and to collect its "ready-now" mask while time remaining in timeout and no devices are ready: sleep return from system call (either due to timeout or to ready devices)
Gil hamilton
source share