Device Drivers: The Tempo Operating System
Device Drivers: The Tempo Operating System
Part 8
System Call Implementation
Low-Level Input/Output Subsystem
1
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.
Memory
Video Adapter
System Bus
PPI: Programmable
Peripheral Interface
Controller
Controller
IDE Disk
IDE Disk
Serial Port
Keyboard (with
8042 chip)
Serial Device
(e.g. a modem)
The controller in this
drive is inactive.
5
Bridges
Host Adapters
Device Classes
10
12
rdc: pseudocode
13
14
15
16
18
19
20
void _vsetcur(void)
{
unsigned int offset;
21
22
Questions
Three arguments:
Purpose:
25
/*
/*
/*
/*
/*
/*
struct IOreq *next; /*
26
read=DSK_READ, write=DSK_WRITE */
disk block address (CHS) */
buffer address */
buffer header addr for asynch I/O */
request process (DISK_BLOCKED) */
or zero, for asynchronous I/O */
ptr to next request to process */
};
struct bufhd {
unsigned int blockno;
/* which block is represented? */
unsigned int status;
/* see sysparm.h */
char data[512];
/* the data */
struct bufhd *prev, *next; /* free list pointers */
};
Common interfaces:
ATA/IDE: frequently used in PCs
SCSI: more common in enterprise class machines
27
ATA/IDE Interface
28
Controller Registers
0x1f0
0x1f1
0x1f2
0x1f3
0x1f4
0x1f6
0x1f7
30
if (IOhead->op == DSK_WRITE) {
for(;;) {
/* for real drives, we'll need a timeout */
iostat = inb(DSK_BASE + DSK_STATUS) & DSK_DRQ;
if (iostat == DSK_DRQ) break;
}
_port_write(DSK_BASE + DSK_DATA, IOhead->buffer, 512);
}
}
31
32
33
34
35
36