From 66647b58d403466136d8fbc9f7977377092de8cb Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Mon, 11 Sep 2023 16:01:01 +0200 Subject: [PATCH] Kernel: Make PCI [Sub]ClassCode comparable to the corresponding ID enums --- Kernel/Bus/PCI/Definitions.h | 7 +++++++ Kernel/Devices/Audio/AC97/AC97.cpp | 4 ++-- Kernel/Devices/Audio/IntelHDA/Controller.cpp | 4 ++-- Kernel/Devices/Audio/Management.cpp | 2 +- Kernel/Devices/Storage/StorageManagement.cpp | 6 +++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Kernel/Bus/PCI/Definitions.h b/Kernel/Bus/PCI/Definitions.h index 65c4d4b3717..9a1d81689da 100644 --- a/Kernel/Bus/PCI/Definitions.h +++ b/Kernel/Bus/PCI/Definitions.h @@ -260,7 +260,14 @@ private: }; 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, MassStorage::SubclassID); +AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Multimedia::SubclassID); +AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Bridge::SubclassID); +AK_MAKE_DISTINCT_NUMERIC_COMPARABLE_TO_ENUM(SubclassCode, Base::SubclassID); + AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, ProgrammingInterface); AK_TYPEDEF_DISTINCT_ORDERED_ID(u8, RevisionID); AK_TYPEDEF_DISTINCT_ORDERED_ID(u16, SubsystemID); diff --git a/Kernel/Devices/Audio/AC97/AC97.cpp b/Kernel/Devices/Audio/AC97/AC97.cpp index d70799e2a60..00f365e70fc 100644 --- a/Kernel/Devices/Audio/AC97/AC97.cpp +++ b/Kernel/Devices/Audio/AC97/AC97.cpp @@ -34,8 +34,8 @@ UNMAP_AFTER_INIT ErrorOr> AC97::create(PCI::Devic UNMAP_AFTER_INIT ErrorOr AC97::probe(PCI::DeviceIdentifier const& device_identifier) { - VERIFY(device_identifier.class_code().value() == to_underlying(PCI::ClassID::Multimedia)); - return device_identifier.subclass_code().value() == to_underlying(PCI::Multimedia::SubclassID::AudioController); + VERIFY(device_identifier.class_code() == PCI::ClassID::Multimedia); + return device_identifier.subclass_code() == PCI::Multimedia::SubclassID::AudioController; } UNMAP_AFTER_INIT AC97::AC97(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr pcm_out_channel, NonnullOwnPtr mixer_io_window, NonnullOwnPtr bus_io_window) diff --git a/Kernel/Devices/Audio/IntelHDA/Controller.cpp b/Kernel/Devices/Audio/IntelHDA/Controller.cpp index 2c82f20a95b..1e8d3ce3679 100644 --- a/Kernel/Devices/Audio/IntelHDA/Controller.cpp +++ b/Kernel/Devices/Audio/IntelHDA/Controller.cpp @@ -19,8 +19,8 @@ namespace Kernel::Audio::IntelHDA { UNMAP_AFTER_INIT ErrorOr Controller::probe(PCI::DeviceIdentifier const& device_identifier) { - VERIFY(device_identifier.class_code().value() == to_underlying(PCI::ClassID::Multimedia)); - return device_identifier.subclass_code().value() == to_underlying(PCI::Multimedia::SubclassID::HDACompatibleController); + VERIFY(device_identifier.class_code() == PCI::ClassID::Multimedia); + return device_identifier.subclass_code() == PCI::Multimedia::SubclassID::HDACompatibleController; } UNMAP_AFTER_INIT ErrorOr> Controller::create(PCI::DeviceIdentifier const& pci_device_identifier) diff --git a/Kernel/Devices/Audio/Management.cpp b/Kernel/Devices/Audio/Management.cpp index 187b8b37776..a7f109de8ef 100644 --- a/Kernel/Devices/Audio/Management.cpp +++ b/Kernel/Devices/Audio/Management.cpp @@ -71,7 +71,7 @@ UNMAP_AFTER_INIT void AudioManagement::enumerate_hardware_controllers() return; MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) { // Only consider PCI multimedia devices - if (device_identifier.class_code().value() != to_underlying(PCI::ClassID::Multimedia)) + if (device_identifier.class_code() != PCI::ClassID::Multimedia) return; auto result = determine_audio_device(device_identifier); diff --git a/Kernel/Devices/Storage/StorageManagement.cpp b/Kernel/Devices/Storage/StorageManagement.cpp index b535137baef..e534fb9548f 100644 --- a/Kernel/Devices/Storage/StorageManagement.cpp +++ b/Kernel/Devices/Storage/StorageManagement.cpp @@ -152,10 +152,10 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_pci_controllers(bool force_pi }; MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) -> void { - auto class_code = device_identifier.class_code().value(); - if (class_code == to_underlying(PCI::ClassID::MassStorage)) { + auto class_code = device_identifier.class_code(); + if (class_code == PCI::ClassID::MassStorage) { handle_mass_storage_device(device_identifier); - } else if (class_code == to_underlying(PCI::ClassID::Base)) { + } else if (class_code == PCI::ClassID::Base) { handle_base_device(device_identifier); } }));