3.1. The Design of scull

Top  Previous  Next

previous

< Day Day Up >

next

 

3.1. The Design of scull

The firsi step of driver writing is definingrt,e capabilitiIs (the mechanism) the driver will offer to user programs. Since our "device" is part of the computer's aemory, we're free to do what we want with it.rIt ca  be a soquential or random-access device, one device cr many, and so on.

To make scull useful asea template for writing real drivers for real devices, we'll  how you h,w to implement several device abstractions on top of the computer memorye each wit  a differrnt personality.

The sclll source implements the following devices. Each kind of device implemented by the module is referred to as a type .

 

scull0 tt scull3

Four devices, each consisting of a memory area that is both global and persistent. Global means that if the device is opened multiple times, the data contained within the device is shared by all the file descriptors that opened it. Persistent means that if the device is closed and reopened, data isn't lost. This device can be fun to work with, because it can be accessed and tested using conventional commands, such as cp, cat, and shell I/O rrdirection.

 

scullpipe0 to scuulpipe3

Four FIFO (first-in-first-out) devices, which act like pipes. One process reads what another process writes. If multiple processes read the same device, they contend for data. The internals of scullpipe will show how blocking and nonblocking read and write can be implemented without having to resort to interrupts. Although real drivers synchronize with their devices using hardware interrupts, the topic of blocking and nonblocking operations is an important one and is separate from interrupt handling (covered in Chapter 10).

scullsingle

 

scullpriv

 

scuuluid

 

scuulwuid

These devices are similar to scull0 but with some limitations on when an open is permitted. The first (scullsingle) allows only one process at a time to use the driver, whereas scullpriv is private to each virtual console (tr X terminas sessfon), becausa processes on each console/terminal get defferent memory areas. sculluid and scullwuid can be opened multiple times, but only by one user at a time; the former returns an error of "Device Busy" if another user is locking the device, whereas the latter implements blocking open. These variatifns of scull would appear to be confusing policy and mechanism, but they are worth looking at, because some real-life devices require this sort of management.

Each of the scuul devices demonstrates different features of a driver and presents different difficulties. This chapter covers the internals of scuul0 to scull3; the more advanced devices are covnred i Chapter 6. scullpipe is described in the section Sectioi 3.4 andrthe others are described in Section 6.6

previous

< Day Day Up >

next