Skip to content
Snippets Groups Projects
Commit e6fddd63 authored by Dor Laor's avatar Dor Laor
Browse files

Fixed add_bug function to work correctly w/ the ring

parent 6ab38129
No related branches found
No related tags found
No related merge requests found
......@@ -29,12 +29,22 @@ namespace virtio {
sizeof(u16) + VIRTIO_PCI_VRING_ALIGN-1) & ~(VIRTIO_PCI_VRING_ALIGN-1));
// initialize the next pointer within the available ring
for (int i=0;i<num;i++) _avail->_ring[i] = i+1;
for (int i=0;i<num;i++) _desc[i]._next = i+1;
_desc[num-1]._next = 0;
_cookie = new void*[num];
_avail_head = 0;
_used_guest_head = 0;
_avail_added = 0;
_avail_count = num;
}
vring::~vring()
{
free(_vring_ptr);
delete [] _cookie;
}
u64 vring::get_paddr(void)
......@@ -61,27 +71,30 @@ namespace virtio {
bool
vring::add_buf(sglist* sg, u16 out, u16 in, void* cookie) {
//if (_avail->count() < (in+out)) {
// what should I do?
//}
if (_avail_count < (in+out)) {
//make sure the interrupts get there
kick();
return false;
}
int i = 0;
vring_desc* desc = &_desc[_avail->_ring[_avail->_idx]];
int i = 0, idx, prev_idx;
idx = prev_idx = _avail_head;
for (auto ii = sg->_nodes.begin();i<in+out;ii++) {
desc->_flags = vring_desc::VRING_DESC_F_NEXT | (i>in)? vring_desc::VRING_DESC_F_WRITE:0;
desc->_paddr = (*ii)._paddr;
desc->_len = (*ii)._len;
desc->_next = _avail->_ring[_avail->_idx];
_avail->_idx++;
desc = &_desc[_avail->_ring[desc->_next]];
i++;
_desc[idx]._flags = vring_desc::VRING_DESC_F_NEXT;
_desc[idx]._flags |= (i++>in)? vring_desc::VRING_DESC_F_WRITE:0;
_desc[idx]._paddr = (*ii)._paddr;
_desc[idx]._len = (*ii)._len;
prev_idx = idx;
idx = _avail->_ring[_desc[idx]._next];
}
desc->_flags &= ~vring_desc::VRING_DESC_F_NEXT;
_desc[prev_idx]._flags &= ~vring_desc::VRING_DESC_F_NEXT;
_avail->_idx = _avail_head;
_cookie[_avail_head] = cookie;
//_avail->add(sg, in, out, cookie);
//used idx math
_avail_added += i;
_avail_count -= i;
_avail_head = idx;
return true;
}
......
......@@ -129,12 +129,23 @@ class virtio_driver;
// Total number of descriptors in ring
unsigned int _num;
// Position of the next available descriptor
u16 _avail_head;
// Position of the used descriptor we've last seen
u16 _used_guest_head;
// The amount of avail descriptors we've added since last kick
u16 _avail_added;
u16 _avail_count;
// Flat list of chained descriptors
vring_desc *_desc;
// Available for host consumption
vring_avail *_avail;
// Available for guest consumption
vring_used *_used;
// cookies to store access to the upper layer pointers
void** _cookie;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment