View from user space :
Have special file in /dev associated with it, together with five systems calls:
open: make device availableread: read from devicewrite: write to deviceioctl: Perform operations on device (optional)close: make device unavailable
Kernel Side
Each file may have functions associated with it which are called when corresponding system calls are made linux/fs.h lists all available operations on files. Device driver implements at least functions for open, read, write and close.
Categorising devices
Kernel also keeps track of
- Physical dependencies between devices. Example: devices connected to a USB-hub
- Buses: Channels between processor and one or more devices. Can be either physical (e.g., pci, usb), or logical
- Classes: Sets of devices of the same type, e.g., keyboards, mice
Handling Interrupts in Device Drivers
Normal cycle of interrupt handling for devices :
- Device sends interrupt
- CPU selects appropriate interrupt handler
- Interrupt handler process interrupt. Two important tasks to be done :
- Data to be transferred to/from device
- Waking up process which wait for data transfer to be finished
- Interrupt handler clears interrupt bit of device. Necessary for next interrupt to arrive
Interrupt processing time must be as short as possible. Data transfer fast, rest of processing slow.
Separate interrupt processing in two halves: - Top Half is called directly by interrupt handler. Only transfers data between device and appropriate kernel buffer and schedules software interrupt to start Bottom half.
- Bottom half still runs in interrupt context and does the rest of the processing (e.g., working through the protocol stack, and waking up processes)