Download Coherent Device Driver Kit

Transcript
40
Example Drivers
These lines wait for the controller to enter a "request state" where it is ready to accept a command
packet.
loopcnt
0;
while ( ( inb ( XT_STAT_REG ) & Oxf ) I = \
( BUSY_STAT I BUS_STAT I REQ_STAT ) )
if ( --loopcnt == 0 )
goto error ;
=
This block of code outputs the command packet to the controller. The code busy-waits until the
command is executed . Given that the controller takes virtually no time to process each byte in the
command packet, busy-waiting the bytes is not significant in terms of time.
for ( i=O ; i < 6 ; i++ ) {
loopcnt = 0 ;
while ( ( inb ( XT_STAT_REG ) & REQ_STAT ) I = REQ_STAT )
if ( --loopcnt
0 )
goto error ;
outb ( XT_DATA_REG, cmdbuf [ i ) ) ;
=a
}
This line enables the DMA controller for this channel. The DMA proceeds at its own rate, paced by
the data going to or coming from the controller.
dmago ( XT_CHAN ) ;
These lines check the controller to see that it has exited the "request state".
if ( inb ( XT_STAT_REG ) & REQ_STAT )
goto error ;
This line sets an internal flag that indicates that we are now busy doing an 1 / 0 operation. This
flag keeps this function from tripping over its own feet.
hd . d_busy
return ;
=
1;
The code that follows the label error shuts down the controller and DMA. The function go to s this
point if an error occurs, as well as flagging the current 1 /0 as bad so the caller will know that the
1/0 failed for some reason. It calls hddoneQ to finish up processing for this block.
'
error 1
outb ( XT_MASK_REG , 0 ) ;
dmaoff ( XT_CHAN ) ;
bp->b_flag I = BFERR ;
hddone ( bp ) ;
}
Function hdintrQ is the hard-disk interrupt handler. It is called when the system receives an
interrupt from the disk controller, as set by the call to setivecQ (see above). No further interrupts
can nest while this interrupt is being processed, so the function need not call sphiQ to disable
interrupts .
COHERENT Driver Kit