diff options
author | Sahan Fernando <sahan.h.fernando@gmail.com> | 2021-04-18 18:10:34 +1000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-18 13:04:55 +0200 |
commit | 45f97c109673acc037c66c9bde7ab22b7c2cf4d8 (patch) | |
tree | 2132536c79951c67d0f3e6ad8a6c99c882d251c0 /Kernel/VirtIO | |
parent | 5c924d395f43ee8f16a9ba8c5007a214ba629a79 (diff) | |
download | serenity-45f97c109673acc037c66c9bde7ab22b7c2cf4d8.zip |
Kernel: Make VirtIOConsole block when VirtIOQueue is full
Diffstat (limited to 'Kernel/VirtIO')
-rw-r--r-- | Kernel/VirtIO/VirtIO.h | 6 | ||||
-rw-r--r-- | Kernel/VirtIO/VirtIOConsole.cpp | 2 | ||||
-rw-r--r-- | Kernel/VirtIO/VirtIOQueue.cpp | 5 | ||||
-rw-r--r-- | Kernel/VirtIO/VirtIOQueue.h | 1 |
4 files changed, 13 insertions, 1 deletions
diff --git a/Kernel/VirtIO/VirtIO.h b/Kernel/VirtIO/VirtIO.h index fe22e8cc32..e21f1c0bbe 100644 --- a/Kernel/VirtIO/VirtIO.h +++ b/Kernel/VirtIO/VirtIO.h @@ -192,6 +192,12 @@ protected: return m_queues[queue_index]; } + const VirtIOQueue& get_queue(u16 queue_index) const + { + VERIFY(queue_index < m_queue_count); + return m_queues[queue_index]; + } + template<typename F> bool negotiate_features(F f) { diff --git a/Kernel/VirtIO/VirtIOConsole.cpp b/Kernel/VirtIO/VirtIOConsole.cpp index 83a3fd09d4..1d660aadca 100644 --- a/Kernel/VirtIO/VirtIOConsole.cpp +++ b/Kernel/VirtIO/VirtIOConsole.cpp @@ -110,7 +110,7 @@ KResultOr<size_t> VirtIOConsole::read(FileDescription&, u64, [[maybe_unused]] Us bool VirtIOConsole::can_write(const FileDescription&, size_t) const { - return true; + return get_queue(TRANSMITQ).can_write(); } KResultOr<size_t> VirtIOConsole::write(FileDescription&, u64, const UserOrKernelBuffer& data, size_t size) diff --git a/Kernel/VirtIO/VirtIOQueue.cpp b/Kernel/VirtIO/VirtIOQueue.cpp index b82f2dc5ae..0c62349284 100644 --- a/Kernel/VirtIO/VirtIOQueue.cpp +++ b/Kernel/VirtIO/VirtIOQueue.cpp @@ -145,4 +145,9 @@ void VirtIOQueue::pop_buffer(u16 descriptor_index) m_free_head = descriptor_index; } +bool VirtIOQueue::can_write() const +{ + return m_free_buffers > 0; +} + } diff --git a/Kernel/VirtIO/VirtIOQueue.h b/Kernel/VirtIO/VirtIOQueue.h index 48be3ffc07..16142f3d5e 100644 --- a/Kernel/VirtIO/VirtIOQueue.h +++ b/Kernel/VirtIO/VirtIOQueue.h @@ -60,6 +60,7 @@ public: bool supply_buffer(Badge<VirtIODevice>, const ScatterGatherList&, BufferType, void* token); bool new_data_available() const; + bool can_write() const; void* get_buffer(size_t*); void discard_used_buffers(); |