cosmetic changes
This commit is contained in:
parent
7797a38423
commit
6bbc2b2245
|
@ -158,6 +158,15 @@ kerneltrap()
|
||||||
w_sstatus(sstatus);
|
w_sstatus(sstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clockintr()
|
||||||
|
{
|
||||||
|
acquire(&tickslock);
|
||||||
|
ticks++;
|
||||||
|
wakeup(&ticks);
|
||||||
|
release(&tickslock);
|
||||||
|
}
|
||||||
|
|
||||||
// check if it's an external interrupt or software interrupt,
|
// check if it's an external interrupt or software interrupt,
|
||||||
// and handle it.
|
// and handle it.
|
||||||
// returns 2 if timer interrupt,
|
// returns 2 if timer interrupt,
|
||||||
|
@ -182,16 +191,15 @@ devintr()
|
||||||
plic_complete(irq);
|
plic_complete(irq);
|
||||||
return 1;
|
return 1;
|
||||||
} else if(scause == 0x8000000000000001){
|
} else if(scause == 0x8000000000000001){
|
||||||
// software interrupt from a machine-mode timer interrupt.
|
// software interrupt from a machine-mode timer interrupt,
|
||||||
|
// forwarded by machinevec in kernelvec.S.
|
||||||
|
|
||||||
if(cpuid() == 0){
|
if(cpuid() == 0){
|
||||||
acquire(&tickslock);
|
clockintr();
|
||||||
ticks++;
|
|
||||||
wakeup(&ticks);
|
|
||||||
release(&tickslock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// acknowledge.
|
// acknowledge the software interrupt by clearing
|
||||||
|
// the SSIP bit in sip.
|
||||||
w_sip(r_sip() & ~2);
|
w_sip(r_sip() & ~2);
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
// the address of virtio mmio register r.
|
// the address of virtio mmio register r.
|
||||||
#define R(r) ((volatile uint32 *)(VIRTIO0 + (r)))
|
#define R(r) ((volatile uint32 *)(VIRTIO0 + (r)))
|
||||||
|
|
||||||
struct spinlock virtio_disk_lock;
|
struct spinlock vdisk_lock;
|
||||||
|
|
||||||
// memory for virtio descriptors &c for queue 0.
|
// memory for virtio descriptors &c for queue 0.
|
||||||
// this is a global instead of allocated because it has
|
// this is a global instead of allocated because it has
|
||||||
|
@ -49,7 +49,7 @@ virtio_disk_init(void)
|
||||||
{
|
{
|
||||||
uint32 status = 0;
|
uint32 status = 0;
|
||||||
|
|
||||||
initlock(&virtio_disk_lock, "virtio_disk");
|
initlock(&vdisk_lock, "virtio_disk");
|
||||||
|
|
||||||
if(*R(VIRTIO_MMIO_MAGIC_VALUE) != 0x74726976 ||
|
if(*R(VIRTIO_MMIO_MAGIC_VALUE) != 0x74726976 ||
|
||||||
*R(VIRTIO_MMIO_VERSION) != 1 ||
|
*R(VIRTIO_MMIO_VERSION) != 1 ||
|
||||||
|
@ -168,7 +168,7 @@ virtio_disk_rw(struct buf *b)
|
||||||
{
|
{
|
||||||
uint64 sector = b->blockno * (BSIZE / 512);
|
uint64 sector = b->blockno * (BSIZE / 512);
|
||||||
|
|
||||||
acquire(&virtio_disk_lock);
|
acquire(&vdisk_lock);
|
||||||
|
|
||||||
// the spec says that legacy block operations use three
|
// the spec says that legacy block operations use three
|
||||||
// descriptors: one for type/reserved/sector, one for
|
// descriptors: one for type/reserved/sector, one for
|
||||||
|
@ -180,7 +180,7 @@ virtio_disk_rw(struct buf *b)
|
||||||
if(alloc3_desc(idx) == 0) {
|
if(alloc3_desc(idx) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sleep(&free[0], &virtio_disk_lock);
|
sleep(&free[0], &vdisk_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
// format the three descriptors.
|
// format the three descriptors.
|
||||||
|
@ -234,16 +234,16 @@ virtio_disk_rw(struct buf *b)
|
||||||
|
|
||||||
// Wait for virtio_disk_intr() to say request has finished.
|
// Wait for virtio_disk_intr() to say request has finished.
|
||||||
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
|
while((b->flags & (B_VALID|B_DIRTY)) != B_VALID){
|
||||||
sleep(b, &virtio_disk_lock);
|
sleep(b, &vdisk_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
release(&virtio_disk_lock);
|
release(&vdisk_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
virtio_disk_intr()
|
virtio_disk_intr()
|
||||||
{
|
{
|
||||||
acquire(&virtio_disk_lock);
|
acquire(&vdisk_lock);
|
||||||
|
|
||||||
while((used_idx % NUM) != (used->id % NUM)){
|
while((used_idx % NUM) != (used->id % NUM)){
|
||||||
int id = used->elems[used_idx].id;
|
int id = used->elems[used_idx].id;
|
||||||
|
@ -262,5 +262,5 @@ virtio_disk_intr()
|
||||||
used_idx = (used_idx + 1) % NUM;
|
used_idx = (used_idx + 1) % NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
release(&virtio_disk_lock);
|
release(&vdisk_lock);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue