diff options
author | Liav A <liavalb@gmail.com> | 2021-07-03 10:24:28 +0300 |
---|---|---|
committer | Gunnar Beutner <gunnar@beutner.name> | 2021-07-03 16:28:49 +0200 |
commit | 3fae7ca113995fae7964d188780671c63e0a2e57 (patch) | |
tree | 457132f99334666efda6fe3a3013e3b91a51175a | |
parent | b4e230a7bbb1147553530bad5b87dce306064c35 (diff) | |
download | serenity-3fae7ca113995fae7964d188780671c63e0a2e57.zip |
Kernel: Clarify and make it easy to not use raw numbers
Let's put the PCI IDs as enums in the PCI namespace so they're free to
pollute that namespace, but it's also more easier to use them.
-rw-r--r-- | Kernel/Bus/PCI/IDs.h | 11 | ||||
-rw-r--r-- | Kernel/Devices/PCISerialDevice.h | 8 | ||||
-rw-r--r-- | Kernel/Graphics/BochsGraphicsAdapter.cpp | 3 | ||||
-rw-r--r-- | Kernel/Graphics/GraphicsManagement.cpp | 8 | ||||
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/E1000ENetworkAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/E1000NetworkAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/RTL8168NetworkAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/VirtIO/VirtIO.cpp | 8 |
9 files changed, 25 insertions, 21 deletions
diff --git a/Kernel/Bus/PCI/IDs.h b/Kernel/Bus/PCI/IDs.h index 8f125f80e4..531e2d7826 100644 --- a/Kernel/Bus/PCI/IDs.h +++ b/Kernel/Bus/PCI/IDs.h @@ -6,19 +6,22 @@ #pragma once -namespace Kernel { +namespace Kernel::PCI { -enum class PCIVendorID { +enum VendorID { VirtIO = 0x1af4, Intel = 0x8086, WCH = 0x1c00, RedHat = 0x1b36, - Realtek = 0x10ec + Realtek = 0x10ec, + QEMUOld = 0x1234, + VirtualBox = 0x80ee }; -enum class PCIDeviceID { +enum DeviceID { VirtIOConsole = 0x1003, VirtIOEntropy = 0x1005, VirtIOGPU = 0x1050, }; + } diff --git a/Kernel/Devices/PCISerialDevice.h b/Kernel/Devices/PCISerialDevice.h index 864941ed70..34beb5942b 100644 --- a/Kernel/Devices/PCISerialDevice.h +++ b/Kernel/Devices/PCISerialDevice.h @@ -32,10 +32,10 @@ private: }; static constexpr BoardDefinition board_definitions[4] = { - { { (u16)PCIVendorID::WCH, 0x3253 }, "WCH CH382 2S", 2, 0, 0xC0, 8, SerialDevice::Baud::Baud115200 }, - { { (u16)PCIVendorID::RedHat, 0x0002 }, "QEMU PCI 16550A", 1, 0, 0, 8, SerialDevice::Baud::Baud115200 }, - { { (u16)PCIVendorID::RedHat, 0x0003 }, "QEMU PCI Dual-port 16550A", 2, 0, 0, 8, SerialDevice::Baud::Baud115200 }, - { { (u16)PCIVendorID::RedHat, 0x0004 }, "QEMU PCI Quad-port 16550A", 4, 0, 0, 8, SerialDevice::Baud::Baud115200 } + { { PCI::VendorID::WCH, 0x3253 }, "WCH CH382 2S", 2, 0, 0xC0, 8, SerialDevice::Baud::Baud115200 }, + { { PCI::VendorID::RedHat, 0x0002 }, "QEMU PCI 16550A", 1, 0, 0, 8, SerialDevice::Baud::Baud115200 }, + { { PCI::VendorID::RedHat, 0x0003 }, "QEMU PCI Dual-port 16550A", 2, 0, 0, 8, SerialDevice::Baud::Baud115200 }, + { { PCI::VendorID::RedHat, 0x0004 }, "QEMU PCI Quad-port 16550A", 4, 0, 0, 8, SerialDevice::Baud::Baud115200 } }; }; diff --git a/Kernel/Graphics/BochsGraphicsAdapter.cpp b/Kernel/Graphics/BochsGraphicsAdapter.cpp index 531412231a..0070bcff98 100644 --- a/Kernel/Graphics/BochsGraphicsAdapter.cpp +++ b/Kernel/Graphics/BochsGraphicsAdapter.cpp @@ -8,6 +8,7 @@ #include <AK/Checked.h> #include <AK/Singleton.h> #include <Kernel/Bus/PCI/Access.h> +#include <Kernel/Bus/PCI/IDs.h> #include <Kernel/Debug.h> #include <Kernel/Graphics/Bochs.h> #include <Kernel/Graphics/BochsGraphicsAdapter.h> @@ -47,7 +48,7 @@ struct [[gnu::packed]] BochsDisplayMMIORegisters { UNMAP_AFTER_INIT NonnullRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::Address address) { PCI::ID id = PCI::get_id(address); - VERIFY((id.vendor_id == 0x1234 && id.device_id == 0x1111) || (id.vendor_id == 0x80ee && id.device_id == 0xbeef)); + VERIFY((id.vendor_id == PCI::VendorID::QEMUOld && id.device_id == 0x1111) || (id.vendor_id == PCI::VendorID::VirtualBox && id.device_id == 0xbeef)); return adopt_ref(*new BochsGraphicsAdapter(address)); } diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index a3a11b4ab1..c9500e7e6f 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -82,18 +82,18 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi RefPtr<GraphicsDevice> adapter; switch (id.vendor_id) { - case 0x1234: + case PCI::VendorID::QEMUOld: if (id.device_id == 0x1111) adapter = BochsGraphicsAdapter::initialize(address); break; - case 0x80ee: + case PCI::VendorID::VirtualBox: if (id.device_id == 0xbeef) adapter = BochsGraphicsAdapter::initialize(address); break; - case 0x8086: + case PCI::VendorID::Intel: adapter = IntelNativeGraphicsAdapter::initialize(address); break; - case static_cast<u16>(PCIVendorID::VirtIO): + case PCI::VendorID::VirtIO: dmesgln("Graphics: Using VirtIO console"); adapter = Graphics::VirtIOGraphicsAdapter::initialize(address); break; diff --git a/Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp b/Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp index 6219a357a1..b41f1f5606 100644 --- a/Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp +++ b/Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp @@ -14,7 +14,7 @@ namespace Kernel::Graphics { NonnullRefPtr<VirtIOGraphicsAdapter> VirtIOGraphicsAdapter::initialize(PCI::Address base_address) { - VERIFY(PCI::get_id(base_address).vendor_id == static_cast<u16>(PCIVendorID::VirtIO)); + VERIFY(PCI::get_id(base_address).vendor_id == PCI::VendorID::VirtIO); return adopt_ref(*new VirtIOGraphicsAdapter(base_address)); } diff --git a/Kernel/Net/E1000ENetworkAdapter.cpp b/Kernel/Net/E1000ENetworkAdapter.cpp index d9cfe06c6f..c4166fab6e 100644 --- a/Kernel/Net/E1000ENetworkAdapter.cpp +++ b/Kernel/Net/E1000ENetworkAdapter.cpp @@ -183,7 +183,7 @@ static bool is_valid_device_id(u16 device_id) UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::Address address) { auto id = PCI::get_id(address); - if (id.vendor_id != (u16)PCIVendorID::Intel) + if (id.vendor_id != PCI::VendorID::Intel) return {}; if (!is_valid_device_id(id.device_id)) return {}; diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 16324e728a..b5c4f6c303 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -160,7 +160,7 @@ UNMAP_AFTER_INIT static bool is_valid_device_id(u16 device_id) UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::Address address) { auto id = PCI::get_id(address); - if (id.vendor_id != (u16)PCIVendorID::Intel) + if (id.vendor_id != PCI::VendorID::Intel) return {}; if (!is_valid_device_id(id.device_id)) return {}; diff --git a/Kernel/Net/RTL8168NetworkAdapter.cpp b/Kernel/Net/RTL8168NetworkAdapter.cpp index 039ab521ac..38aa1aba62 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.cpp +++ b/Kernel/Net/RTL8168NetworkAdapter.cpp @@ -179,7 +179,7 @@ namespace Kernel { UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::Address address) { auto id = PCI::get_id(address); - if (id.vendor_id != (u16)PCIVendorID::Realtek) + if (id.vendor_id != PCI::VendorID::Realtek) return {}; if (id.device_id != 0x8168) return {}; diff --git a/Kernel/VirtIO/VirtIO.cpp b/Kernel/VirtIO/VirtIO.cpp index 0137faf418..d1a20a334a 100644 --- a/Kernel/VirtIO/VirtIO.cpp +++ b/Kernel/VirtIO/VirtIO.cpp @@ -21,18 +21,18 @@ UNMAP_AFTER_INIT void VirtIO::detect() if (address.is_null() || id.is_null()) return; // TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive - if (id.vendor_id != (u16)PCIVendorID::VirtIO) + if (id.vendor_id != PCI::VendorID::VirtIO) return; switch (id.device_id) { - case (u16)PCIDeviceID::VirtIOConsole: { + case PCI::DeviceID::VirtIOConsole: { [[maybe_unused]] auto& unused = adopt_ref(*new VirtIOConsole(address)).leak_ref(); break; } - case (u16)PCIDeviceID::VirtIOEntropy: { + case PCI::DeviceID::VirtIOEntropy: { [[maybe_unused]] auto& unused = adopt_ref(*new VirtIORNG(address)).leak_ref(); break; } - case (u16)PCIDeviceID::VirtIOGPU: { + case PCI::DeviceID::VirtIOGPU: { // This should have been initialized by the graphics subsystem break; } |