From d64d03e0d6e0543ca70f422c7fab0aa61c5963b0 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Mon, 11 Sep 2023 18:28:30 +0200 Subject: [PATCH] Kernel: Make Graphics device detection a bit more idomatic --- Kernel/Bus/PCI/Definitions.h | 10 ++++++++++ Kernel/Devices/GPU/Management.cpp | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Kernel/Bus/PCI/Definitions.h b/Kernel/Bus/PCI/Definitions.h index cdbe15a62d..c1a2c025f8 100644 --- a/Kernel/Bus/PCI/Definitions.h +++ b/Kernel/Bus/PCI/Definitions.h @@ -93,6 +93,7 @@ static constexpr u16 msix_control_enable = 0x8000; // Taken from https://pcisig.com/sites/default/files/files/PCI_Code-ID_r_1_11__v24_Jan_2019.pdf enum class ClassID { + Legacy = 0x00, MassStorage = 0x01, Network = 0x02, Display = 0x03, @@ -114,6 +115,14 @@ enum class ClassID { NonEssentialInstrumentation = 0x13, }; +namespace Legacy { + +enum class SubclassID { + Any = 0x00, + VGACompatible = 0x01 +}; + +} namespace MassStorage { enum class SubclassID { @@ -336,6 +345,7 @@ AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, ClassCode); AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(ClassCode, ClassID) AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, SubclassCode); +AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Legacy::SubclassID); AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, MassStorage::SubclassID); AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Network::SubclassID); AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Display::SubclassID); diff --git a/Kernel/Devices/GPU/Management.cpp b/Kernel/Devices/GPU/Management.cpp index 32e24031b0..0f83960522 100644 --- a/Kernel/Devices/GPU/Management.cpp +++ b/Kernel/Devices/GPU/Management.cpp @@ -110,14 +110,14 @@ static inline bool is_vga_compatible_pci_device(PCI::DeviceIdentifier const& dev { // Note: Check for Display Controller, VGA Compatible Controller or // Unclassified, VGA-Compatible Unclassified Device - auto is_display_controller_vga_compatible = device_identifier.class_code().value() == 0x3 && device_identifier.subclass_code().value() == 0x0; - auto is_general_pci_vga_compatible = device_identifier.class_code().value() == 0x0 && device_identifier.subclass_code().value() == 0x1; + auto is_display_controller_vga_compatible = device_identifier.class_code() == PCI::ClassID::Display && device_identifier.subclass_code() == PCI::Display::SubclassID::VGA; + auto is_general_pci_vga_compatible = device_identifier.class_code() == PCI::ClassID::Legacy && device_identifier.subclass_code() == PCI::Legacy::SubclassID::VGACompatible; return is_display_controller_vga_compatible || is_general_pci_vga_compatible; } static inline bool is_display_controller_pci_device(PCI::DeviceIdentifier const& device_identifier) { - return device_identifier.class_code().value() == 0x3; + return device_identifier.class_code() == PCI::ClassID::Display; } struct PCIGraphicsDriverInitializer {