summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-08-27 11:41:27 +0300
committerAndreas Kling <kling@serenityos.org>2021-08-31 16:51:13 +0200
commit9a03c00f45a7e829d9ff851ec9c1a8cbfe697280 (patch)
treefad3fc4875b1fed376edd8bce3cc57d874868c6f /Kernel
parent5a0aa66b7372dc7c9f771a91eaf3468034093ff1 (diff)
downloadserenity-9a03c00f45a7e829d9ff851ec9c1a8cbfe697280.zip
Kernel/VirtIO: Remove the m_class_name member
This class member was used only to determine the device type when printing messages to the debug log. Instead, remove this class member, and add a quick way to find the device type according to how the VirtIO specification says to do that. This simplifies construction of VirtIODevices a bit, because now the constructor doesn't need to ask for a String identified with the device type.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Bus/VirtIO/VirtIO.cpp70
-rw-r--r--Kernel/Bus/VirtIO/VirtIO.h5
-rw-r--r--Kernel/Bus/VirtIO/VirtIOConsole.cpp2
-rw-r--r--Kernel/Bus/VirtIO/VirtIOConsole.h3
-rw-r--r--Kernel/Bus/VirtIO/VirtIORNG.cpp2
-rw-r--r--Kernel/Bus/VirtIO/VirtIORNG.h3
-rw-r--r--Kernel/Graphics/VirtIOGPU/GPU.cpp4
-rw-r--r--Kernel/Graphics/VirtIOGPU/GPU.h2
8 files changed, 56 insertions, 35 deletions
diff --git a/Kernel/Bus/VirtIO/VirtIO.cpp b/Kernel/Bus/VirtIO/VirtIO.cpp
index fa9ac0cc29..6c3e4df2db 100644
--- a/Kernel/Bus/VirtIO/VirtIO.cpp
+++ b/Kernel/Bus/VirtIO/VirtIO.cpp
@@ -43,13 +43,29 @@ UNMAP_AFTER_INIT void VirtIO::detect()
});
}
-UNMAP_AFTER_INIT VirtIODevice::VirtIODevice(PCI::Address address, String class_name)
+StringView VirtIO::determine_device_class(const PCI::Address& address)
+{
+ auto subsystem_device_id = PCI::get_subsystem_id(address);
+ switch (subsystem_device_id) {
+ case 1:
+ return "VirtIONetAdapter";
+ case 2:
+ return "VirtIOBlockDevice";
+ case 3:
+ return "VirtIOConsole";
+ case 4:
+ return "VirtIORNG";
+ }
+ dbgln("VirtIO: Unknown subsystem_device_id {}", subsystem_device_id);
+ VERIFY_NOT_REACHED();
+}
+
+UNMAP_AFTER_INIT VirtIODevice::VirtIODevice(PCI::Address address)
: PCI::Device(address)
, IRQHandler(PCI::get_interrupt_line(address))
- , m_class_name(move(class_name))
, m_io_base(IOAddress(PCI::get_BAR0(pci_address()) & ~1))
{
- dbgln("{}: Found @ {}", m_class_name, pci_address());
+ dbgln("{}: Found @ {}", VirtIO::determine_device_class(address), pci_address());
enable_bus_mastering(pci_address());
PCI::enable_interrupt_line(pci_address());
@@ -62,23 +78,23 @@ UNMAP_AFTER_INIT VirtIODevice::VirtIODevice(PCI::Address address, String class_n
auto cfg = make<Configuration>();
auto raw_config_type = capability.read8(0x3);
if (raw_config_type < static_cast<u8>(ConfigurationType::Common) || raw_config_type > static_cast<u8>(ConfigurationType::PCI)) {
- dbgln("{}: Unknown capability configuration type: {}", m_class_name, raw_config_type);
+ dbgln("{}: Unknown capability configuration type: {}", VirtIO::determine_device_class(address), raw_config_type);
return;
}
cfg->cfg_type = static_cast<ConfigurationType>(raw_config_type);
auto cap_length = capability.read8(0x2);
if (cap_length < 0x10) {
- dbgln("{}: Unexpected capability size: {}", m_class_name, cap_length);
+ dbgln("{}: Unexpected capability size: {}", VirtIO::determine_device_class(address), cap_length);
break;
}
cfg->bar = capability.read8(0x4);
if (cfg->bar > 0x5) {
- dbgln("{}: Unexpected capability bar value: {}", m_class_name, cfg->bar);
+ dbgln("{}: Unexpected capability bar value: {}", VirtIO::determine_device_class(address), cfg->bar);
break;
}
cfg->offset = capability.read32(0x8);
cfg->length = capability.read32(0xc);
- dbgln_if(VIRTIO_DEBUG, "{}: Found configuration {}, bar: {}, offset: {}, length: {}", m_class_name, (u32)cfg->cfg_type, cfg->bar, cfg->offset, cfg->length);
+ dbgln_if(VIRTIO_DEBUG, "{}: Found configuration {}, bar: {}, offset: {}, length: {}", VirtIO::determine_device_class(address), (u32)cfg->cfg_type, cfg->bar, cfg->offset, cfg->length);
if (cfg->cfg_type == ConfigurationType::Common)
m_use_mmio = true;
else if (cfg->cfg_type == ConfigurationType::Notify)
@@ -112,14 +128,14 @@ auto VirtIODevice::mapping_for_bar(u8 bar) -> MappedMMIO&
mapping.size = PCI::get_BAR_space_size(pci_address(), bar);
mapping.base = MM.allocate_kernel_region(PhysicalAddress(page_base_of(PCI::get_BAR(pci_address(), bar))), Memory::page_round_up(mapping.size), "VirtIO MMIO", Memory::Region::Access::ReadWrite, Memory::Region::Cacheable::No);
if (!mapping.base)
- dbgln("{}: Failed to map bar {}", m_class_name, bar);
+ dbgln("{}: Failed to map bar {}", VirtIO::determine_device_class(pci_address()), bar);
}
return mapping;
}
void VirtIODevice::notify_queue(u16 queue_index)
{
- dbgln_if(VIRTIO_DEBUG, "{}: notifying about queue change at idx: {}", m_class_name, queue_index);
+ dbgln_if(VIRTIO_DEBUG, "{}: notifying about queue change at idx: {}", VirtIO::determine_device_class(pci_address()), queue_index);
if (!m_notify_cfg)
out<u16>(REG_QUEUE_NOTIFY, queue_index);
else
@@ -207,7 +223,7 @@ bool VirtIODevice::accept_device_features(u64 device_features, u64 accepted_feat
}
if (is_feature_set(device_features, VIRTIO_F_RING_PACKED)) {
- dbgln_if(VIRTIO_DEBUG, "{}: packed queues not yet supported", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: packed queues not yet supported", VirtIO::determine_device_class(pci_address()));
accepted_features &= ~(VIRTIO_F_RING_PACKED);
}
@@ -220,8 +236,8 @@ bool VirtIODevice::accept_device_features(u64 device_features, u64 accepted_feat
accepted_features |= VIRTIO_F_IN_ORDER;
}
- dbgln_if(VIRTIO_DEBUG, "{}: Device features: {}", m_class_name, device_features);
- dbgln_if(VIRTIO_DEBUG, "{}: Accepted features: {}", m_class_name, accepted_features);
+ dbgln_if(VIRTIO_DEBUG, "{}: Device features: {}", VirtIO::determine_device_class(pci_address()), device_features);
+ dbgln_if(VIRTIO_DEBUG, "{}: Accepted features: {}", VirtIO::determine_device_class(pci_address()), accepted_features);
if (!m_common_cfg) {
out<u32>(REG_GUEST_FEATURES, accepted_features);
@@ -235,18 +251,18 @@ bool VirtIODevice::accept_device_features(u64 device_features, u64 accepted_feat
m_status = read_status_bits();
if (!(m_status & DEVICE_STATUS_FEATURES_OK)) {
set_status_bit(DEVICE_STATUS_FAILED);
- dbgln("{}: Features not accepted by host!", m_class_name);
+ dbgln("{}: Features not accepted by host!", VirtIO::determine_device_class(pci_address()));
return false;
}
m_accepted_features = accepted_features;
- dbgln_if(VIRTIO_DEBUG, "{}: Features accepted by host", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: Features accepted by host", VirtIO::determine_device_class(pci_address()));
return true;
}
void VirtIODevice::reset_device()
{
- dbgln_if(VIRTIO_DEBUG, "{}: Reset device", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: Reset device", VirtIO::determine_device_class(pci_address()));
if (!m_common_cfg) {
mask_status_bits(0);
while (read_status_bits() != 0) {
@@ -268,7 +284,7 @@ bool VirtIODevice::setup_queue(u16 queue_index)
config_write16(*m_common_cfg, COMMON_CFG_QUEUE_SELECT, queue_index);
u16 queue_size = config_read16(*m_common_cfg, COMMON_CFG_QUEUE_SIZE);
if (queue_size == 0) {
- dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] is unavailable!", m_class_name, queue_index);
+ dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] is unavailable!", VirtIO::determine_device_class(pci_address()), queue_index);
return true;
}
@@ -282,7 +298,7 @@ bool VirtIODevice::setup_queue(u16 queue_index)
config_write64(*m_common_cfg, COMMON_CFG_QUEUE_DRIVER, queue->driver_area().get());
config_write64(*m_common_cfg, COMMON_CFG_QUEUE_DEVICE, queue->device_area().get());
- dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] configured with size: {}", m_class_name, queue_index, queue_size);
+ dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] configured with size: {}", VirtIO::determine_device_class(pci_address()), queue_index, queue_size);
m_queues.append(move(queue));
return true;
@@ -296,7 +312,7 @@ bool VirtIODevice::activate_queue(u16 queue_index)
config_write16(*m_common_cfg, COMMON_CFG_QUEUE_SELECT, queue_index);
config_write16(*m_common_cfg, COMMON_CFG_QUEUE_ENABLE, true);
- dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] activated", m_class_name, queue_index);
+ dbgln_if(VIRTIO_DEBUG, "{}: Queue[{}] activated", VirtIO::determine_device_class(pci_address()), queue_index);
return true;
}
@@ -310,17 +326,17 @@ bool VirtIODevice::setup_queues(u16 requested_queue_count)
if (requested_queue_count == 0) {
m_queue_count = maximum_queue_count;
} else if (requested_queue_count > maximum_queue_count) {
- dbgln("{}: {} queues requested but only {} available!", m_class_name, m_queue_count, maximum_queue_count);
+ dbgln("{}: {} queues requested but only {} available!", VirtIO::determine_device_class(pci_address()), m_queue_count, maximum_queue_count);
return false;
} else {
m_queue_count = requested_queue_count;
}
} else {
m_queue_count = requested_queue_count;
- dbgln("{}: device's available queue count could not be determined!", m_class_name);
+ dbgln("{}: device's available queue count could not be determined!", VirtIO::determine_device_class(pci_address()));
}
- dbgln_if(VIRTIO_DEBUG, "{}: Setting up {} queues", m_class_name, m_queue_count);
+ dbgln_if(VIRTIO_DEBUG, "{}: Setting up {} queues", VirtIO::determine_device_class(pci_address()), m_queue_count);
for (u16 i = 0; i < m_queue_count; i++) {
if (!setup_queue(i))
return false;
@@ -339,7 +355,7 @@ void VirtIODevice::finish_init()
VERIFY(!(m_status & DEVICE_STATUS_DRIVER_OK)); // ensure we didn't already finish the initialization
set_status_bit(DEVICE_STATUS_DRIVER_OK);
- dbgln_if(VIRTIO_DEBUG, "{}: Finished initialization", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: Finished initialization", VirtIO::determine_device_class(pci_address()));
}
u8 VirtIODevice::isr_status()
@@ -353,25 +369,25 @@ bool VirtIODevice::handle_irq(const RegisterState&)
{
u8 isr_type = isr_status();
if ((isr_type & (QUEUE_INTERRUPT | DEVICE_CONFIG_INTERRUPT)) == 0) {
- dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", m_class_name, isr_type);
+ dbgln_if(VIRTIO_DEBUG, "{}: Handling interrupt with unknown type: {}", VirtIO::determine_device_class(pci_address()), isr_type);
return false;
}
if (isr_type & DEVICE_CONFIG_INTERRUPT) {
- dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Device config interrupt!", VirtIO::determine_device_class(pci_address()));
if (!handle_device_config_change()) {
set_status_bit(DEVICE_STATUS_FAILED);
- dbgln("{}: Failed to handle device config change!", m_class_name);
+ dbgln("{}: Failed to handle device config change!", VirtIO::determine_device_class(pci_address()));
}
}
if (isr_type & QUEUE_INTERRUPT) {
- dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: VirtIO Queue interrupt!", VirtIO::determine_device_class(pci_address()));
for (size_t i = 0; i < m_queues.size(); i++) {
if (get_queue(i).new_data_available()) {
handle_queue_update(i);
return true;
}
}
- dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "{}: Got queue interrupt but all queues are up to date!", VirtIO::determine_device_class(pci_address()));
}
return true;
}
diff --git a/Kernel/Bus/VirtIO/VirtIO.h b/Kernel/Bus/VirtIO/VirtIO.h
index 7928cffef1..bc07e51874 100644
--- a/Kernel/Bus/VirtIO/VirtIO.h
+++ b/Kernel/Bus/VirtIO/VirtIO.h
@@ -82,6 +82,7 @@ struct Configuration {
class VirtIO {
public:
static void detect();
+ static StringView determine_device_class(const PCI::Address& address);
};
class VirtIODevice
@@ -91,9 +92,9 @@ public:
virtual ~VirtIODevice() override;
protected:
- VirtIODevice(PCI::Address, String);
- const String m_class_name;
+ explicit VirtIODevice(PCI::Address);
+ virtual StringView class_name() const = 0;
struct MappedMMIO {
OwnPtr<Memory::Region> base;
size_t size { 0 };
diff --git a/Kernel/Bus/VirtIO/VirtIOConsole.cpp b/Kernel/Bus/VirtIO/VirtIOConsole.cpp
index 9995d98d39..e8808679a5 100644
--- a/Kernel/Bus/VirtIO/VirtIOConsole.cpp
+++ b/Kernel/Bus/VirtIO/VirtIOConsole.cpp
@@ -13,7 +13,7 @@ namespace Kernel {
unsigned VirtIOConsole::next_device_id = 0;
UNMAP_AFTER_INIT VirtIOConsole::VirtIOConsole(PCI::Address address)
- : VirtIODevice(address, "VirtIOConsole")
+ : VirtIODevice(address)
, m_device_id(next_device_id++)
{
if (auto cfg = get_config(ConfigurationType::Device)) {
diff --git a/Kernel/Bus/VirtIO/VirtIOConsole.h b/Kernel/Bus/VirtIO/VirtIOConsole.h
index f1fb2c15b9..4ebc7eeb79 100644
--- a/Kernel/Bus/VirtIO/VirtIOConsole.h
+++ b/Kernel/Bus/VirtIO/VirtIOConsole.h
@@ -21,7 +21,7 @@ public:
VirtIOConsole(PCI::Address);
virtual ~VirtIOConsole() override = default;
- virtual StringView purpose() const override { return "VirtIOConsole"; }
+ virtual StringView purpose() const override { return class_name(); }
unsigned device_id() const
{
@@ -29,6 +29,7 @@ public:
}
private:
+ virtual StringView class_name() const override { return "VirtIOConsole"; }
enum class ControlEvent : u16 {
DeviceReady = 0,
DeviceAdd = 1,
diff --git a/Kernel/Bus/VirtIO/VirtIORNG.cpp b/Kernel/Bus/VirtIO/VirtIORNG.cpp
index 94fb060ec3..446a83ee85 100644
--- a/Kernel/Bus/VirtIO/VirtIORNG.cpp
+++ b/Kernel/Bus/VirtIO/VirtIORNG.cpp
@@ -10,7 +10,7 @@
namespace Kernel {
UNMAP_AFTER_INIT VirtIORNG::VirtIORNG(PCI::Address address)
- : VirtIODevice(address, "VirtIORNG")
+ : VirtIODevice(address)
{
bool success = negotiate_features([&](auto) {
return 0;
diff --git a/Kernel/Bus/VirtIO/VirtIORNG.h b/Kernel/Bus/VirtIO/VirtIORNG.h
index b43a4267a3..395b507b5c 100644
--- a/Kernel/Bus/VirtIO/VirtIORNG.h
+++ b/Kernel/Bus/VirtIO/VirtIORNG.h
@@ -19,12 +19,13 @@ class VirtIORNG final
: public RefCounted<VirtIORNG>
, public VirtIODevice {
public:
- virtual StringView purpose() const override { return m_class_name; }
+ virtual StringView purpose() const override { return class_name(); }
VirtIORNG(PCI::Address);
virtual ~VirtIORNG() override;
private:
+ virtual StringView class_name() const override { return "VirtIOConsole"; }
virtual bool handle_device_config_change() override;
virtual void handle_queue_update(u16 queue_index) override;
void request_entropy_from_host();
diff --git a/Kernel/Graphics/VirtIOGPU/GPU.cpp b/Kernel/Graphics/VirtIOGPU/GPU.cpp
index 4cce1eda07..5948a4df16 100644
--- a/Kernel/Graphics/VirtIOGPU/GPU.cpp
+++ b/Kernel/Graphics/VirtIOGPU/GPU.cpp
@@ -16,7 +16,7 @@
namespace Kernel::Graphics::VirtIOGPU {
GPU::GPU(PCI::Address address)
- : VirtIODevice(address, "GPU")
+ : VirtIODevice(address)
, m_scratch_space(MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::ReadWrite))
{
VERIFY(!!m_scratch_space);
@@ -65,7 +65,7 @@ bool GPU::handle_device_config_change()
auto events = get_pending_events();
if (events & VIRTIO_GPU_EVENT_DISPLAY) {
// The host window was resized, in SerenityOS we completely ignore this event
- dbgln_if(VIRTIO_DEBUG, "{}: Ignoring virtio gpu display resize event", m_class_name);
+ dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: Ignoring virtio gpu display resize event");
clear_pending_events(VIRTIO_GPU_EVENT_DISPLAY);
}
if (events & ~VIRTIO_GPU_EVENT_DISPLAY) {
diff --git a/Kernel/Graphics/VirtIOGPU/GPU.h b/Kernel/Graphics/VirtIOGPU/GPU.h
index 81d576b804..952e0fea0a 100644
--- a/Kernel/Graphics/VirtIOGPU/GPU.h
+++ b/Kernel/Graphics/VirtIOGPU/GPU.h
@@ -77,6 +77,8 @@ public:
void flush_dirty_rectangle(ScanoutID, Protocol::Rect const& dirty_rect, ResourceID);
private:
+ virtual StringView class_name() const override { return "VirtIOGPU"; }
+
struct Scanout {
RefPtr<FrameBufferDevice> framebuffer;
RefPtr<Console> console;