Linux Device Drivers
Sample Implementation scullpipe
The dev scullpipe devices (there are four of them by default) are part of the scull module and are used to show how blocking I O is implemented. Within a driver, a process blocked in a read call is awakened when data arrives usually the hardware issues an interrupt to signal such an event, and the driver awakens waiting processes as part of handling the interrupt. The scull driver works differently, so that it can be run without requiring any particular hardware or an interrupt handler. We...
Poll and select
Applications that use nonblocking I O often use the poll and select system calls as well. poll and select have essentially the same functionality both allow a process to determine whether it can read from or write to one or more open files without blocking. They are thus often used in applications that must use multiple input or output streams without blocking on any one of them. The same functionality is offered by two separate functions because they were implemented in Unix almost at the same...
Using IO Ports
I O ports are the means by which drivers communicate with many devices out there at least part of the time. This section covers the various functions available for making use of I O ports we also touch on some portability issues. Let us start with a quick reminder that I O ports must be allocated before being used by your driver. As we discussed in I O Ports and I O Memory in Chapter 2, the functions used to allocate and free ports are int check_region(unsigned long start, unsigned long len)...
Deeper Look at Wait Queues
The previous discussion is all that most driver writers will need to know to get their job done. Some, however, will want to dig deeper. This section attempts to get the curious started everybody else can skip to the next section without missing much that is important. The wait_queue_head_t type is a fairly simple structure, defined in . It contains only a lock variable and a linked list of sleeping processes. The individual data items in the list are of type wait_queue_t, and the list is the...
Choosing the ioctl Commands
Before writing the code for ioctl, you need to choose the numbers that correspond to commands. Unfortunately, the simple choice of using small numbers starting from 1 and going up doesn't work well. The command numbers should be unique across the system in order to prevent errors caused by issuing the right command to the wrong device. Such a mismatch is not unlikely to happen, and a program might find itself trying to change the baud rate of a non-serial-port input stream, such as a FIFO or an...
Access to User Space in Linux
Memory access was handled differently in the 2.0 kernels. The Linux virtual memory system was less well developed at that time, and memory access was handled a little differently. The new system was the key change that opened 2.1 development, and it brought significant improvements in performance unfortunately, it was accompanied by yet another set of compatibility headaches for driver writers. The functions used to access memory under Linux 2.0 were as follows verify_area(int mode, const void...