Newer
Older
#include "types.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
#include "x86.h"
#define IDE_BSY 0x80
#define IDE_DRDY 0x40
#define IDE_DF 0x20
#define IDE_ERR 0x01
#define IDE_CMD_READ 0x20
#define IDE_CMD_WRITE 0x30
// IDE request queue.
// The next request will be stored in request[head],
// and the request currently being served by the disk
// is request[tail].
// Must hold ide_lock while manipulating queue.
static struct ide_request request[NREQUEST];
static int head, tail;
static struct spinlock ide_lock;
while(((r = inb(0x1F7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
initlock(&ide_lock, "ide");
// Probe to see if disk 1 exists (we assume disk 0 exists).
static int
for(x = 0; x < 1000 && (r = inb(0x1F7)) == 0; x++)
// Interrupt handler - wake up the request that just finished.
void
ide_intr(void)
{
acquire(&ide_lock);
ide_start_request (void)
{
struct ide_request *r;
outb(0x3f6, 0); // generate interrupt
outb(0x1F2, r->nsecs);
outb(0x1F3, r->secno & 0xFF);
outb(0x1F4, (r->secno >> 8) & 0xFF);
outb(0x1F5, (r->secno >> 16) & 0xFF);
outb(0x1F6, 0xE0 | ((r->diskno&1)<<4) | ((r->secno>>24)&0x0F));
// Run an entire disk operation.
void
ide_rw(int diskno, uint secno, void *addr, uint nsecs, int read)
if(diskno && !disk_1_present)
panic("ide disk 1 not present");
// Finish request.
if(read){
if(ide_wait_ready(1) >= 0)
insl(0x1F0, addr, 512/4);
// Remove request from queue.
if((head + 1) % NREQUEST == tail)
wakeup(&disk_queue);