mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
Kernel: Finish base implementation of VirtQueues
This commit includes a lot of small changes and additions needed to finalize the base implementation of VirtIOQueues and VirtDevices: * The device specific driver implementation now has to handle setting up the queues it needs before letting the base device class know it finised initialization * Supplying buffers to VirtQueues is now done via ScatterGatherLists instead of arbitary buffer pointers - this ensures the pointers are physical and allows us to follow the specification in regards to the requirement that individual descriptors must point to physically contiguous buffers. This can be further improved in the future by implementating support for the Indirect-Descriptors feature (as defined by the specification) to reduce descriptor usage for very fragmented buffers. * When supplying buffers to a VirtQueue the driver must supply a (temporarily-)unique token (usually the supplied buffer's virtual address) to ensure the driver can discern which buffer has finished processing by the device in the case in which the device does not offer the F_IN_ORDER feature. * Device drivers now handle queue updates (supplied buffers being returned from the device) by implementing a single pure virtual method instead of setting a seperate callback for each queue * Two new VirtQueue methods were added to allow the device driver to either discard or get used/returned buffers from the device by cleanly removing them off the descriptor chain (This also allows the VirtQueue implementation to reuse those freed descriptors) This also includes the necessary changes to the VirtIOConsole implementation to match these interface changes. Co-authored-by: Sahan <sahan.h.fernando@gmail.com>
This commit is contained in:
parent
acdd1424bc
commit
d1f7a2f9a5
7 changed files with 154 additions and 85 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -29,9 +29,13 @@
|
|||
#include <AK/Badge.h>
|
||||
#include <Kernel/SpinLock.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <Kernel/VM/ScatterGatherList.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
#define VIRTQ_DESC_F_NEXT 1
|
||||
#define VIRTQ_DESC_F_INDIRECT 4
|
||||
|
||||
enum class BufferType {
|
||||
DeviceReadable = 0,
|
||||
DeviceWritable = 2
|
||||
|
@ -44,7 +48,7 @@ public:
|
|||
VirtIOQueue(u16 queue_size, u16 notify_offset);
|
||||
~VirtIOQueue();
|
||||
|
||||
bool is_null() const { return !m_region; }
|
||||
bool is_null() const { return !m_queue_region; }
|
||||
u16 notify_offset() const { return m_notify_offset; }
|
||||
|
||||
void enable_interrupts();
|
||||
|
@ -54,17 +58,18 @@ public:
|
|||
PhysicalAddress driver_area() const { return to_physical(m_driver.ptr()); }
|
||||
PhysicalAddress device_area() const { return to_physical(m_device.ptr()); }
|
||||
|
||||
bool supply_buffer(Badge<VirtIODevice>, const u8* buffer, u32 length, BufferType);
|
||||
bool supply_buffer(Badge<VirtIODevice>, const ScatterGatherList&, BufferType, void* token);
|
||||
bool new_data_available() const;
|
||||
|
||||
bool handle_interrupt();
|
||||
Function<void()> on_data_available;
|
||||
void* get_buffer(size_t*);
|
||||
void discard_used_buffers();
|
||||
|
||||
private:
|
||||
void pop_buffer(u16 descriptor_index);
|
||||
|
||||
PhysicalAddress to_physical(const void* ptr) const
|
||||
{
|
||||
auto offset = FlatPtr(ptr) - m_region->vaddr().get();
|
||||
return m_region->physical_page(0)->paddr().offset(offset);
|
||||
auto offset = FlatPtr(ptr) - m_queue_region->vaddr().get();
|
||||
return m_queue_region->physical_page(0)->paddr().offset(offset);
|
||||
}
|
||||
struct [[gnu::packed]] VirtIOQueueDescriptor {
|
||||
u64 address;
|
||||
|
@ -100,7 +105,8 @@ private:
|
|||
OwnPtr<VirtIOQueueDescriptor> m_descriptors { nullptr };
|
||||
OwnPtr<VirtIOQueueDriver> m_driver { nullptr };
|
||||
OwnPtr<VirtIOQueueDevice> m_device { nullptr };
|
||||
OwnPtr<Region> m_region;
|
||||
Vector<void*> m_tokens;
|
||||
OwnPtr<Region> m_queue_region;
|
||||
SpinLock<u8> m_lock;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue