summaryrefslogtreecommitdiff
path: root/Kernel/VirtIO
diff options
context:
space:
mode:
authorSahan Fernando <sahan.h.fernando@gmail.com>2021-04-18 18:10:34 +1000
committerAndreas Kling <kling@serenityos.org>2021-04-18 13:04:55 +0200
commit45f97c109673acc037c66c9bde7ab22b7c2cf4d8 (patch)
tree2132536c79951c67d0f3e6ad8a6c99c882d251c0 /Kernel/VirtIO
parent5c924d395f43ee8f16a9ba8c5007a214ba629a79 (diff)
downloadserenity-45f97c109673acc037c66c9bde7ab22b7c2cf4d8.zip
Kernel: Make VirtIOConsole block when VirtIOQueue is full
Diffstat (limited to 'Kernel/VirtIO')
-rw-r--r--Kernel/VirtIO/VirtIO.h6
-rw-r--r--Kernel/VirtIO/VirtIOConsole.cpp2
-rw-r--r--Kernel/VirtIO/VirtIOQueue.cpp5
-rw-r--r--Kernel/VirtIO/VirtIOQueue.h1
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();