Device Drivers Device drivers are the primary components of the I O subsystem Each device driver The Tempo Operating System is responsible for managing input output on a single type of device at the lowest level by managing the device s controller is not normally called from user mode usually can t be called from user mode frequently presents a normalized interface to the kernel this depends on the particular OS design Part 8 System Call Implementation Low Level Input Output Subsystem 1 Device Driver Basics 2 Devices and Device Controllers A device driver usually has two parts the top and the bottom The top part is trigger by a call from the OS and manipulates data structures returns results and when necessary triggers the bottom part priming the pump The top part may block The bottom part of the device driver is usually interrupt driven and includes the interrupt handler It handles direct low level interaction with the device and awakens the top part when a request has been completed The bottom part will never block The distinction between devices and their controllers is sometimes blurred A serial port is usually a single chip e g an 8250 or 16550 A modern IDE or SCSI disk has a built in controller A display has a monitor and a video adapter that usually has many components A common practice is to allow one controller to support multiple devices For example multiple old ATA style disks were connected to one controller 3 Controllers and Devices CPU Memory Video Adapter Buses ISA PCI USB AGP Monitor Although simple diagrams as in the previous slide show only one bus with everything connected to it modern systems have many interface buses For example System Bus PPI Programmable Peripheral Interface Controller Controller IDE Disk IDE Disk Serial Port 4 Keyboard with 8042 chip Serial Device e g a modem The controller in this drive is inactive 5 ISA Industry Standard Architecture found in older PCs PCI Peripheral Component Interconnection modern replacement for ISA PCI Express an even more modern version of PCI USB Universal Serial Bus frequently used to connect external devices AGP Accelerated Graphics Port based on enhancement of PCI for video adapters 6 1 Bridges Host Adapters How are all these buses interconnected in a computer system Answer with bridges A bridge is essentially a device chip that maps signals between bus formats synchronization data control etc A common PC architecture has a north bridge between the host bus and the PCI and DRAM memory buses the south bridge connects the PCI bus to the ISA USB IDE and AGP buses But many different organizations are possible So what s a host adapter e g as used with IDE drives A host adapter more completely called a host bus adapter is the hardware that connects a bus from one or more devices to a bus in the computer system For example the cables from IDE drives are a bus which is different from a PCI bus The host adapter is a bridge like device that connects the IDE drive bus to the PCI bus There are even multiple kinds of IDE busses parallel and serial requiring different kinds of host adapters SCSI is also another common disk drive bus type and the SCSI adapter host adapter host bus adapter is used to connect SCSI drives or more properly a SCSI bus to a host bus like the PCI bus 7 Device Classes 8 Normalized Driver Interface 1 Devices are commonly separated into two classes for ease of organization Block devices those which have addressable blocks of data e g disks CDs DVDs device drivers must be given a block number a read write command and a buffer in each request Character devices everything else device drivers transfer only one or a few bytes at a time but must still have a read write command and know where to get put the data In most UNIX implementations each device in each class has two numbers major identifies the controller for all devices of the same type i e all IDE disks will have the same major device number minor identifies an instance of the device i e each individual IDE disk will have a unique minor device number Two arrays of structures bdevsw and cdevsw are indexed by the major device number to locate entry points to device drivers 9 Normalized Driver Interface 2 Block device driver entry points 10 Tempo s Device Drivers Tempo doesn t yet use a normalized device driver format Each device driver is represented by a system call for the most common actions Device specific Tempo system calls d open open a device d close close a device d strategy read or write a block d ioctl I O actions other than read or write Character device driver entry points rdc read next keyboard character conout write character to the display diskio read write a disk block and wait for completion asynchio asynchronous disk I O request queue the requests and continue executing d open open a device d close close a device d read d write read or write a block d ioctl I O actions other than read or write 11 12 2 The keyboard device driver rdc pseudocode The top part of the keyboard device driver is in the rdc system call the bottom half is the interrupt handler rdc s basic data structures include kbdata array one for each console of circular queues each queue has at most NKEYS entries each entry containing one character code frstkey is index of first unused character code keysem array of semaphores one for each console with count equal to number of entries in console s kbdata array Do a down on the console s semaphore keysem con with the specified timeout Return TIMEOUT if the down operation timed out Copy kbdata con frstkey con to result Increment frstkey con modulo NKEYS Return result 13 Keyboard Interrupt Handling 1 14 Keyboard Interrupt Handling 2 Each key press or release generates an interrupt 0x21 IRQ 1 When a keyboard interrupt is handled The PIC is reenabled to allow additional interrupts The keyboard status register is read to clear interrupt request The keyboard data register is read and used as argument to kybdisr the second level interrupt handler When kybdisr returns continue at isr30i normal system call return activity In kybdisr the kbtoa function is called with the key code as an argument It returns NOCHAR if no character code should be returned If the code indicates a virtual console switch should happen do it by calling setvidpg and return If the keyboard buffer is full the character is ignored Add the character code to the circular queue If no processes are awaiting input from the console increment the keysem semaphore s
View Full Document
Unlocking...