ide.c: make names more regular
This commit is contained in:
parent
7b644318dd
commit
c47bc4fd54
1 changed files with 26 additions and 23 deletions
49
ide.c
49
ide.c
|
@ -18,14 +18,14 @@
|
||||||
#define IDE_CMD_READ 0x20
|
#define IDE_CMD_READ 0x20
|
||||||
#define IDE_CMD_WRITE 0x30
|
#define IDE_CMD_WRITE 0x30
|
||||||
|
|
||||||
// ide_queue points to the buf now being read/written to the disk.
|
// idequeue points to the buf now being read/written to the disk.
|
||||||
// ide_queue->qnext points to the next buf to be processed.
|
// idequeue->qnext points to the next buf to be processed.
|
||||||
// You must hold ide_lock while manipulating queue.
|
// You must hold idelock while manipulating queue.
|
||||||
|
|
||||||
static struct spinlock ide_lock;
|
static struct spinlock idelock;
|
||||||
static struct buf *ide_queue;
|
static struct buf *idequeue;
|
||||||
|
|
||||||
static int disk_1_present;
|
static int havedisk1;
|
||||||
static void idestart(struct buf*);
|
static void idestart(struct buf*);
|
||||||
|
|
||||||
// Wait for IDE disk to become ready.
|
// Wait for IDE disk to become ready.
|
||||||
|
@ -34,7 +34,7 @@ idewait(int check_error)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
while(((r = inb(0x1f7)) & IDE_BSY) || !(r & IDE_DRDY))
|
while(((r = inb(0x1f7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
|
||||||
;
|
;
|
||||||
if(check_error && (r & (IDE_DF|IDE_ERR)) != 0)
|
if(check_error && (r & (IDE_DF|IDE_ERR)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -46,7 +46,7 @@ ideinit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
initlock(&ide_lock, "ide");
|
initlock(&idelock, "ide");
|
||||||
picenable(IRQ_IDE);
|
picenable(IRQ_IDE);
|
||||||
ioapicenable(IRQ_IDE, ncpu - 1);
|
ioapicenable(IRQ_IDE, ncpu - 1);
|
||||||
idewait(0);
|
idewait(0);
|
||||||
|
@ -55,7 +55,7 @@ ideinit(void)
|
||||||
outb(0x1f6, 0xe0 | (1<<4));
|
outb(0x1f6, 0xe0 | (1<<4));
|
||||||
for(i=0; i<1000; i++){
|
for(i=0; i<1000; i++){
|
||||||
if(inb(0x1f7) != 0){
|
if(inb(0x1f7) != 0){
|
||||||
disk_1_present = 1;
|
havedisk1 = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ ideinit(void)
|
||||||
outb(0x1f6, 0xe0 | (0<<4));
|
outb(0x1f6, 0xe0 | (0<<4));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the request for b. Caller must hold ide_lock.
|
// Start the request for b. Caller must hold idelock.
|
||||||
static void
|
static void
|
||||||
idestart(struct buf *b)
|
idestart(struct buf *b)
|
||||||
{
|
{
|
||||||
|
@ -92,11 +92,14 @@ ideintr(void)
|
||||||
{
|
{
|
||||||
struct buf *b;
|
struct buf *b;
|
||||||
|
|
||||||
acquire(&ide_lock);
|
// Take first buffer off queue.
|
||||||
if((b = ide_queue) == 0){
|
acquire(&idelock);
|
||||||
release(&ide_lock);
|
if((b = idequeue) == 0){
|
||||||
|
release(&idelock);
|
||||||
|
cprintf("Spurious IDE interrupt.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
idequeue = b->qnext;
|
||||||
|
|
||||||
// Read data if needed.
|
// Read data if needed.
|
||||||
if(!(b->flags & B_DIRTY) && idewait(1) >= 0)
|
if(!(b->flags & B_DIRTY) && idewait(1) >= 0)
|
||||||
|
@ -108,10 +111,10 @@ ideintr(void)
|
||||||
wakeup(b);
|
wakeup(b);
|
||||||
|
|
||||||
// Start disk on next buf in queue.
|
// Start disk on next buf in queue.
|
||||||
if((ide_queue = b->qnext) != 0)
|
if(idequeue != 0)
|
||||||
idestart(ide_queue);
|
idestart(idequeue);
|
||||||
|
|
||||||
release(&ide_lock);
|
release(&idelock);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PAGEBREAK!
|
//PAGEBREAK!
|
||||||
|
@ -127,25 +130,25 @@ iderw(struct buf *b)
|
||||||
panic("iderw: buf not busy");
|
panic("iderw: buf not busy");
|
||||||
if((b->flags & (B_VALID|B_DIRTY)) == B_VALID)
|
if((b->flags & (B_VALID|B_DIRTY)) == B_VALID)
|
||||||
panic("iderw: nothing to do");
|
panic("iderw: nothing to do");
|
||||||
if(b->dev != 0 && !disk_1_present)
|
if(b->dev != 0 && !havedisk1)
|
||||||
panic("idrw: ide disk 1 not present");
|
panic("idrw: ide disk 1 not present");
|
||||||
|
|
||||||
acquire(&ide_lock);
|
acquire(&idelock);
|
||||||
|
|
||||||
// Append b to ide_queue.
|
// Append b to idequeue.
|
||||||
b->qnext = 0;
|
b->qnext = 0;
|
||||||
for(pp=&ide_queue; *pp; pp=&(*pp)->qnext)
|
for(pp=&idequeue; *pp; pp=&(*pp)->qnext)
|
||||||
;
|
;
|
||||||
*pp = b;
|
*pp = b;
|
||||||
|
|
||||||
// Start disk if necessary.
|
// Start disk if necessary.
|
||||||
if(ide_queue == b)
|
if(idequeue == b)
|
||||||
idestart(b);
|
idestart(b);
|
||||||
|
|
||||||
// Wait for request to finish.
|
// Wait for request to finish.
|
||||||
// Assuming will not sleep too long: ignore cp->killed.
|
// Assuming will not sleep too long: ignore cp->killed.
|
||||||
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID)
|
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID)
|
||||||
sleep(b, &ide_lock);
|
sleep(b, &idelock);
|
||||||
|
|
||||||
release(&ide_lock);
|
release(&idelock);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue