Bladeren bron

Kernel: Use PCI/Definitions.h for PCI-USB controller magic numbers

Hendiadyoin1 1 jaar geleden
bovenliggende
commit
e7012a9245
2 gewijzigde bestanden met toevoegingen van 27 en 12 verwijderingen
  1. 11 0
      Kernel/Bus/PCI/Definitions.h
  2. 16 12
      Kernel/Bus/USB/USBManagement.cpp

+ 11 - 0
Kernel/Bus/PCI/Definitions.h

@@ -199,6 +199,15 @@ enum class SubclassID {
     USB = 0x03,
 };
 
+enum class USBProgIf {
+    UHCI = 0x00,
+    OHCI = 0x10,
+    EHCI = 0x20,
+    xHCI = 0x30,
+    None = 0x80,
+    Device = 0xFE
+};
+
 }
 
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, CapabilityID);
@@ -336,6 +345,8 @@ AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Base::SubclassID);
 AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, SerialBus::SubclassID);
 
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, ProgrammingInterface);
+AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(ProgrammingInterface, SerialBus::USBProgIf);
+
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, RevisionID);
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u16, SubsystemID);
 AK_TYPEDEF_DISTINCT_ORDERED_ID(u16, SubsystemVendorID);

+ 16 - 12
Kernel/Bus/USB/USBManagement.cpp

@@ -8,6 +8,7 @@
 #include <AK/Singleton.h>
 #include <Kernel/Boot/CommandLine.h>
 #include <Kernel/Bus/PCI/API.h>
+#include <Kernel/Bus/PCI/Definitions.h>
 #include <Kernel/Bus/USB/UHCI/UHCIController.h>
 #include <Kernel/Bus/USB/USBManagement.h>
 #include <Kernel/FileSystem/SysFS/Subsystems/Bus/USB/BusDirectory.h>
@@ -29,9 +30,13 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
         return;
 
     MUST(PCI::enumerate([this](PCI::DeviceIdentifier const& device_identifier) {
-        if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3))
+        if (device_identifier.class_code() != PCI::ClassID::SerialBus
+            || device_identifier.subclass_code() != PCI::SerialBus::SubclassID::USB)
             return;
-        if (device_identifier.prog_if().value() == 0x0) {
+        auto progif = static_cast<PCI::SerialBus::USBProgIf>(device_identifier.prog_if().value());
+        using enum PCI::SerialBus::USBProgIf;
+        switch (progif) {
+        case UHCI:
             if (kernel_command_line().disable_uhci_controller())
                 return;
 
@@ -39,23 +44,22 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
                 m_controllers.append(uhci_controller_or_error.release_value());
 
             return;
-        }
-
-        if (device_identifier.prog_if().value() == 0x10) {
+        case OHCI:
             dmesgln("USBManagement: OHCI controller found at {} is not currently supported.", device_identifier.address());
             return;
-        }
-
-        if (device_identifier.prog_if().value() == 0x20) {
+        case EHCI:
             dmesgln("USBManagement: EHCI controller found at {} is not currently supported.", device_identifier.address());
             return;
-        }
-
-        if (device_identifier.prog_if().value() == 0x30) {
+        case xHCI:
             dmesgln("USBManagement: xHCI controller found at {} is not currently supported.", device_identifier.address());
             return;
+        case None:
+            dmesgln("USBManagement: Non interface-able controller found at {} is not currently supported.", device_identifier.address());
+            return;
+        case Device:
+            dmesgln("USBManagement: Direct attached device at {} is not currently supported.", device_identifier.address());
+            return;
         }
-
         dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", device_identifier.address(), device_identifier.prog_if().value());
     }));
 }