1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

Fixed used index and available index. These are modded by the queue size in the ring only. The index continues to increase until it naturally wraps at the data size

This commit is contained in:
Stephen Marz 2020-04-12 21:37:06 -04:00
parent fb3a9ccdae
commit 4767b6d698
2 changed files with 6 additions and 4 deletions

View File

@ -296,8 +296,8 @@ pub fn block_op(dev: usize, buffer: *mut u8, size: u32, offset: u64, write: bool
flags: virtio::VIRTIO_DESC_F_WRITE, flags: virtio::VIRTIO_DESC_F_WRITE,
next: 0, }; next: 0, };
let _status_idx = fill_next_descriptor(bdev, desc); let _status_idx = fill_next_descriptor(bdev, desc);
(*bdev.queue).avail.ring[(*bdev.queue).avail.idx as usize] = head_idx; (*bdev.queue).avail.ring[(*bdev.queue).avail.idx as usize % virtio::VIRTIO_RING_SIZE] = head_idx;
(*bdev.queue).avail.idx = ((*bdev.queue).avail.idx + 1) % virtio::VIRTIO_RING_SIZE as u16; (*bdev.queue).avail.idx = (*bdev.queue).avail.idx.wrapping_add(1);
// The only queue a block device has is 0, which is the request // The only queue a block device has is 0, which is the request
// queue. // queue.
bdev.dev.add(MmioOffsets::QueueNotify.scale32()).write_volatile(0); bdev.dev.add(MmioOffsets::QueueNotify.scale32()).write_volatile(0);
@ -322,8 +322,8 @@ pub fn pending(bd: &mut BlockDevice) {
unsafe { unsafe {
let ref queue = *bd.queue; let ref queue = *bd.queue;
while bd.ack_used_idx != queue.used.idx { while bd.ack_used_idx != queue.used.idx {
let ref elem = queue.used.ring[bd.ack_used_idx as usize]; let ref elem = queue.used.ring[bd.ack_used_idx as usize % VIRTIO_RING_SIZE];
bd.ack_used_idx = (bd.ack_used_idx + 1) % VIRTIO_RING_SIZE as u16; bd.ack_used_idx = bd.ack_used_idx.wrapping_add(1);
let rq = queue.desc[elem.id as usize].addr as *const Request; let rq = queue.desc[elem.id as usize].addr as *const Request;
kfree(rq as *mut u8); kfree(rq as *mut u8);
// TODO: Awaken the process that will need this I/O. This is // TODO: Awaken the process that will need this I/O. This is

View File

@ -5,7 +5,9 @@
use crate::fs::{Descriptor, FileSystem, Stat, FsError}; use crate::fs::{Descriptor, FileSystem, Stat, FsError};
use crate::block; use crate::block;
use crate::kmem::{kmalloc, kfree};
use alloc::string::String; use alloc::string::String;
use core::mem::size_of;
pub const MAGIC: u16 = 0x4d5a; pub const MAGIC: u16 = 0x4d5a;