From e187207610b09b132053d60ef2200bb48c4ccbb2 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 29 Nov 2021 16:03:38 +0100 Subject: [PATCH] Kernel: Register Virtio console ports with device management Previously, Virtio console ports would not show up in `/sys/dev/char/`. Also adds support to `SystemServer` to create more than one console port device in `/dev/` in the multiport case. --- Kernel/Bus/VirtIO/Console.cpp | 11 ++++++----- Userland/Services/SystemServer/main.cpp | 9 +-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Kernel/Bus/VirtIO/Console.cpp b/Kernel/Bus/VirtIO/Console.cpp index cced62ff0f..34fa1cc770 100644 --- a/Kernel/Bus/VirtIO/Console.cpp +++ b/Kernel/Bus/VirtIO/Console.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -50,10 +51,10 @@ UNMAP_AFTER_INIT void Console::initialize() if (success) { finish_init(); - if (is_feature_accepted(VIRTIO_CONSOLE_F_MULTIPORT)) + if (is_feature_accepted(VIRTIO_CONSOLE_F_MULTIPORT)) { setup_multiport(); - else { - auto port = make_ref_counted(0u, *this); + } else { + auto port = MUST(DeviceManagement::the().try_create_device(0u, *this)); port->init_receive_buffer({}); m_ports.append(port); } @@ -160,13 +161,13 @@ void Console::process_control_message(ControlMessage message) return; } - m_ports.at(id) = make_ref_counted(id, *this); + m_ports.at(id) = MUST(DeviceManagement::the().try_create_device(id, *this)); + ControlMessage ready_event { .id = static_cast(id), .event = (u16)ControlEvent::PortReady, .value = (u16)ControlMessage::Status::Success }; - write_control_message(ready_event); }); diff --git a/Userland/Services/SystemServer/main.cpp b/Userland/Services/SystemServer/main.cpp index 0fd26ac007..962394865b 100644 --- a/Userland/Services/SystemServer/main.cpp +++ b/Userland/Services/SystemServer/main.cpp @@ -207,14 +207,7 @@ static void populate_devfs_char_devices() break; } case 229: { - switch (minor_number) { - case 0: { - create_devfs_char_device("/dev/hvc0p0", 0666, 229, 0); - break; - } - default: - warnln("Unknown character device {}:{}", major_number, minor_number); - } + create_devfs_char_device(String::formatted("/dev/hvc0p{}", minor_number), 0666, major_number, minor_number); break; } case 10: {