summaryrefslogtreecommitdiff
path: root/Kernel/Bus
diff options
context:
space:
mode:
authorEvan Smal <evan.smal@hotmail.com>2022-12-28 17:55:04 -0500
committerJelle Raaijmakers <jelle@gmta.nl>2023-01-05 01:44:19 +0100
commit288a73ea0e21ab1f98dba68e6b71d37da87b5591 (patch)
tree5d0d6e511155b5e23face6f3440a1a8aaec75f19 /Kernel/Bus
parent6a5be5f1c555fa880822d988e52058b50a3eea84 (diff)
downloadserenity-288a73ea0e21ab1f98dba68e6b71d37da87b5591.zip
Kernel: Add dmesgln_pci logging for Kernel::PCI
A virtual method named device_name() was added to Kernel::PCI to support logging the PCI::Device name and address using dmesgln_pci. Previously, PCI::Device did not store the device name. All devices inheriting from PCI::Device now use dmesgln_pci where they previously used dmesgln.
Diffstat (limited to 'Kernel/Bus')
-rw-r--r--Kernel/Bus/PCI/Device.h17
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIController.cpp6
-rw-r--r--Kernel/Bus/USB/UHCI/UHCIController.h1
-rw-r--r--Kernel/Bus/VirtIO/Console.h1
-rw-r--r--Kernel/Bus/VirtIO/RNG.h1
5 files changed, 23 insertions, 3 deletions
diff --git a/Kernel/Bus/PCI/Device.h b/Kernel/Bus/PCI/Device.h
index f167e192e1..9c1d1fa92e 100644
--- a/Kernel/Bus/PCI/Device.h
+++ b/Kernel/Bus/PCI/Device.h
@@ -6,6 +6,8 @@
#pragma once
+#include <AK/Format.h>
+#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <Kernel/Bus/PCI/Definitions.h>
@@ -16,6 +18,9 @@ public:
Address pci_address() const { return m_pci_address; };
virtual ~Device() = default;
+
+ virtual StringView device_name() const = 0;
+
void enable_pin_based_interrupts() const;
void disable_pin_based_interrupts() const;
@@ -35,4 +40,16 @@ private:
Address m_pci_address;
};
+template<typename... Parameters>
+void dmesgln_pci(Device const& device, AK::CheckedFormatString<Parameters...>&& fmt, Parameters const&... parameters)
+{
+ AK::StringBuilder builder;
+ if (builder.try_append("{}: {}: "sv).is_error())
+ return;
+ if (builder.try_append(fmt.view()).is_error())
+ return;
+ AK::VariadicFormatParams variadic_format_params { device.device_name(), device.pci_address(), parameters... };
+ vdmesgln(builder.string_view(), variadic_format_params);
+}
+
}
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp
index d9867968de..78e62ca29d 100644
--- a/Kernel/Bus/USB/UHCI/UHCIController.cpp
+++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp
@@ -75,9 +75,9 @@ ErrorOr<NonnullLockRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI
ErrorOr<void> UHCIController::initialize()
{
- dmesgln("UHCI: Controller found {} @ {}", PCI::get_hardware_id(pci_address()), pci_address());
- dmesgln("UHCI: I/O base {}", m_registers_io_window);
- dmesgln("UHCI: Interrupt line: {}", interrupt_number());
+ dmesgln_pci(*this, "Controller found {} @ {}", PCI::get_hardware_id(pci_address()), pci_address());
+ dmesgln_pci(*this, "I/O base {}", m_registers_io_window);
+ dmesgln_pci(*this, "Interrupt line: {}", interrupt_number());
TRY(spawn_async_poll_process());
TRY(spawn_port_process());
diff --git a/Kernel/Bus/USB/UHCI/UHCIController.h b/Kernel/Bus/USB/UHCI/UHCIController.h
index 1b45461cd5..4041da4be4 100644
--- a/Kernel/Bus/USB/UHCI/UHCIController.h
+++ b/Kernel/Bus/USB/UHCI/UHCIController.h
@@ -38,6 +38,7 @@ public:
virtual ~UHCIController() override;
virtual StringView purpose() const override { return "UHCI"sv; }
+ virtual StringView device_name() const override { return purpose(); }
virtual ErrorOr<void> initialize() override;
virtual ErrorOr<void> reset() override;
diff --git a/Kernel/Bus/VirtIO/Console.h b/Kernel/Bus/VirtIO/Console.h
index 9694fa0a3c..3b8e58d302 100644
--- a/Kernel/Bus/VirtIO/Console.h
+++ b/Kernel/Bus/VirtIO/Console.h
@@ -22,6 +22,7 @@ public:
virtual ~Console() override = default;
virtual StringView purpose() const override { return class_name(); }
+ virtual StringView device_name() const override { return class_name(); }
unsigned device_id() const
{
diff --git a/Kernel/Bus/VirtIO/RNG.h b/Kernel/Bus/VirtIO/RNG.h
index f7ddef9b83..5f7f8a1ee8 100644
--- a/Kernel/Bus/VirtIO/RNG.h
+++ b/Kernel/Bus/VirtIO/RNG.h
@@ -21,6 +21,7 @@ class RNG final
public:
static NonnullLockRefPtr<RNG> must_create(PCI::DeviceIdentifier const&);
virtual StringView purpose() const override { return class_name(); }
+ virtual StringView device_name() const override { return class_name(); }
virtual ~RNG() override = default;
virtual void initialize() override;