浏览代码

Kernel: Make Graphics device detection a bit more idomatic

Hendiadyoin1 1 年之前
父节点
当前提交
d64d03e0d6
共有 2 个文件被更改,包括 13 次插入3 次删除
  1. 10 0
      Kernel/Bus/PCI/Definitions.h
  2. 3 3
      Kernel/Devices/GPU/Management.cpp

+ 10 - 0
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
 // Taken from https://pcisig.com/sites/default/files/files/PCI_Code-ID_r_1_11__v24_Jan_2019.pdf
 enum class ClassID {
 enum class ClassID {
+    Legacy = 0x00,
     MassStorage = 0x01,
     MassStorage = 0x01,
     Network = 0x02,
     Network = 0x02,
     Display = 0x03,
     Display = 0x03,
@@ -114,6 +115,14 @@ enum class ClassID {
     NonEssentialInstrumentation = 0x13,
     NonEssentialInstrumentation = 0x13,
 };
 };
 
 
+namespace Legacy {
+
+enum class SubclassID {
+    Any = 0x00,
+    VGACompatible = 0x01
+};
+
+}
 namespace MassStorage {
 namespace MassStorage {
 
 
 enum class SubclassID {
 enum class SubclassID {
@@ -336,6 +345,7 @@ AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, ClassCode);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(ClassCode, ClassID)
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(ClassCode, ClassID)
 
 
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, SubclassCode);
 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, MassStorage::SubclassID);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Network::SubclassID);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Network::SubclassID);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Display::SubclassID);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Display::SubclassID);

+ 3 - 3
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
     // Note: Check for Display Controller, VGA Compatible Controller or
     // Unclassified, VGA-Compatible Unclassified Device
     // 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;
     return is_display_controller_vga_compatible || is_general_pci_vga_compatible;
 }
 }
 
 
 static inline bool is_display_controller_pci_device(PCI::DeviceIdentifier const& device_identifier)
 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 {
 struct PCIGraphicsDriverInitializer {