diff options
40 files changed, 150 insertions, 186 deletions
diff --git a/Kernel/Bus/PCI/API.cpp b/Kernel/Bus/PCI/API.cpp index 0e4cf8f163..11e8ca2fbb 100644 --- a/Kernel/Bus/PCI/API.cpp +++ b/Kernel/Bus/PCI/API.cpp @@ -120,36 +120,6 @@ u32 get_BAR(Address address, u8 bar) } } -u8 get_revision_id(Address address) -{ - return read8(address, PCI_REVISION_ID); -} - -u8 get_subclass(Address address) -{ - return read8(address, PCI_SUBCLASS); -} - -u8 get_class(Address address) -{ - return read8(address, PCI_CLASS); -} - -u8 get_programming_interface(Address address) -{ - return read8(address, PCI_PROG_IF); -} - -u16 get_subsystem_id(Address address) -{ - return read16(address, PCI_SUBSYSTEM_ID); -} - -u16 get_subsystem_vendor_id(Address address) -{ - return read16(address, PCI_SUBSYSTEM_VENDOR_ID); -} - void enable_bus_mastering(Address address) { auto value = read16(address, PCI_COMMAND); diff --git a/Kernel/Bus/PCI/API.h b/Kernel/Bus/PCI/API.h index 5b6abd0fc7..38798c7b23 100644 --- a/Kernel/Bus/PCI/API.h +++ b/Kernel/Bus/PCI/API.h @@ -31,12 +31,6 @@ u32 get_BAR3(Address); u32 get_BAR4(Address); u32 get_BAR5(Address); u32 get_BAR(Address address, u8 bar); -u8 get_revision_id(Address); -u8 get_programming_interface(Address); -u8 get_subclass(Address); -u8 get_class(Address); -u16 get_subsystem_id(Address); -u16 get_subsystem_vendor_id(Address); size_t get_BAR_space_size(Address, u8); void enable_bus_mastering(Address); void disable_bus_mastering(Address); diff --git a/Kernel/Bus/USB/UHCI/UHCIController.cpp b/Kernel/Bus/USB/UHCI/UHCIController.cpp index 31d1ad7e4c..6aec8877ff 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.cpp +++ b/Kernel/Bus/USB/UHCI/UHCIController.cpp @@ -62,10 +62,10 @@ static constexpr u16 UCHI_PORTSC_NON_WRITE_CLEAR_BIT_MASK = 0x1FF5; // This is u static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128; static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024; -KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::Address address) +KResultOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { // NOTE: This assumes that address is pointing to a valid UHCI controller. - auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(address))); + auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier.address()))); TRY(controller->initialize()); return controller; } diff --git a/Kernel/Bus/USB/UHCI/UHCIController.h b/Kernel/Bus/USB/UHCI/UHCIController.h index 6657aa8411..b3ede96c3c 100644 --- a/Kernel/Bus/USB/UHCI/UHCIController.h +++ b/Kernel/Bus/USB/UHCI/UHCIController.h @@ -33,7 +33,7 @@ class UHCIController final public: static constexpr u8 NUMBER_OF_ROOT_PORTS = 2; - static KResultOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::Address address); + static KResultOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier); virtual ~UHCIController() override; virtual StringView purpose() const override { return "UHCI"; } diff --git a/Kernel/Bus/USB/USBManagement.cpp b/Kernel/Bus/USB/USBManagement.cpp index 04eb14aded..144d4c806c 100644 --- a/Kernel/Bus/USB/USBManagement.cpp +++ b/Kernel/Bus/USB/USBManagement.cpp @@ -34,7 +34,7 @@ UNMAP_AFTER_INIT void USBManagement::enumerate_controllers() if (kernel_command_line().disable_uhci_controller()) return; - if (auto uhci_controller_or_error = UHCIController::try_to_initialize(address); !uhci_controller_or_error.is_error()) + if (auto uhci_controller_or_error = UHCIController::try_to_initialize(device_identifier); !uhci_controller_or_error.is_error()) m_controllers.append(uhci_controller_or_error.release_value()); return; diff --git a/Kernel/Bus/VirtIO/Console.cpp b/Kernel/Bus/VirtIO/Console.cpp index a636a3d37c..cced62ff0f 100644 --- a/Kernel/Bus/VirtIO/Console.cpp +++ b/Kernel/Bus/VirtIO/Console.cpp @@ -13,9 +13,9 @@ namespace Kernel::VirtIO { unsigned Console::next_device_id = 0; -UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::Address address) +UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::DeviceIdentifier const& pci_device_identifier) { - return adopt_ref_if_nonnull(new Console(address)).release_nonnull(); + return adopt_ref_if_nonnull(new Console(pci_device_identifier)).release_nonnull(); } UNMAP_AFTER_INIT void Console::initialize() @@ -61,8 +61,8 @@ UNMAP_AFTER_INIT void Console::initialize() } } -UNMAP_AFTER_INIT Console::Console(PCI::Address address) - : VirtIO::Device(address) +UNMAP_AFTER_INIT Console::Console(PCI::DeviceIdentifier const& pci_device_identifier) + : VirtIO::Device(pci_device_identifier) , m_device_id(next_device_id++) { } diff --git a/Kernel/Bus/VirtIO/Console.h b/Kernel/Bus/VirtIO/Console.h index 77d0b1c285..65c2f3770c 100644 --- a/Kernel/Bus/VirtIO/Console.h +++ b/Kernel/Bus/VirtIO/Console.h @@ -18,7 +18,7 @@ class Console friend VirtIO::ConsolePort; public: - static NonnullRefPtr<Console> must_create(PCI::Address address); + static NonnullRefPtr<Console> must_create(PCI::DeviceIdentifier const&); virtual ~Console() override = default; virtual StringView purpose() const override { return class_name(); } @@ -32,7 +32,7 @@ public: private: virtual StringView class_name() const override { return "VirtIOConsole"; } - explicit Console(PCI::Address); + explicit Console(PCI::DeviceIdentifier const&); enum class ControlEvent : u16 { DeviceReady = 0, DeviceAdd = 1, diff --git a/Kernel/Bus/VirtIO/Device.cpp b/Kernel/Bus/VirtIO/Device.cpp index 15733d7525..d9ad50b8a4 100644 --- a/Kernel/Bus/VirtIO/Device.cpp +++ b/Kernel/Bus/VirtIO/Device.cpp @@ -18,20 +18,20 @@ UNMAP_AFTER_INIT void detect() { if (kernel_command_line().disable_virtio()) return; - PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { - if (address.is_null() || device_identifier.hardware_id().is_null()) + PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) { + if (device_identifier.hardware_id().is_null()) return; // TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive if (device_identifier.hardware_id().vendor_id != PCI::VendorID::VirtIO) return; switch (device_identifier.hardware_id().device_id) { case PCI::DeviceID::VirtIOConsole: { - auto& console = Console::must_create(address).leak_ref(); + auto& console = Console::must_create(device_identifier).leak_ref(); console.initialize(); break; } case PCI::DeviceID::VirtIOEntropy: { - auto& rng = RNG::must_create(address).leak_ref(); + auto& rng = RNG::must_create(device_identifier).leak_ref(); rng.initialize(); break; } @@ -46,12 +46,12 @@ UNMAP_AFTER_INIT void detect() }); } -static StringView const determine_device_class(const PCI::Address& address) +static StringView const determine_device_class(PCI::DeviceIdentifier const& device_identifier) { - if (PCI::get_revision_id(address) == 0) { + if (device_identifier.revision_id().value() == 0) { // Note: If the device is a legacy (or transitional) device, therefore, // probe the subsystem ID in the PCI header and figure out the - auto subsystem_device_id = PCI::get_subsystem_id(address); + auto subsystem_device_id = device_identifier.subsystem_id().value(); switch (subsystem_device_id) { case 1: return "VirtIONetAdapter"sv; @@ -67,7 +67,7 @@ static StringView const determine_device_class(const PCI::Address& address) } } - auto id = PCI::get_hardware_id(address); + auto id = device_identifier.hardware_id(); VERIFY(id.vendor_id == PCI::VendorID::VirtIO); switch (id.device_id) { case PCI::DeviceID::VirtIONetAdapter: @@ -150,11 +150,11 @@ UNMAP_AFTER_INIT void Device::initialize() set_status_bit(DEVICE_STATUS_DRIVER); } -UNMAP_AFTER_INIT VirtIO::Device::Device(PCI::Address address) - : PCI::Device(address) - , IRQHandler(PCI::get_interrupt_line(address)) +UNMAP_AFTER_INIT VirtIO::Device::Device(PCI::DeviceIdentifier const& device_identifier) + : PCI::Device(device_identifier.address()) + , IRQHandler(PCI::get_interrupt_line(device_identifier.address())) , m_io_base(IOAddress(PCI::get_BAR0(pci_address()) & ~1)) - , m_class_name(VirtIO::determine_device_class(address)) + , m_class_name(VirtIO::determine_device_class(device_identifier)) { dbgln("{}: Found @ {}", m_class_name, pci_address()); } diff --git a/Kernel/Bus/VirtIO/Device.h b/Kernel/Bus/VirtIO/Device.h index 1ad18e3ba4..79f0368117 100644 --- a/Kernel/Bus/VirtIO/Device.h +++ b/Kernel/Bus/VirtIO/Device.h @@ -93,7 +93,7 @@ public: protected: virtual StringView class_name() const { return "VirtIO::Device"; } - explicit Device(PCI::Address); + explicit Device(PCI::DeviceIdentifier const&); struct MappedMMIO { OwnPtr<Memory::Region> base; size_t size { 0 }; diff --git a/Kernel/Bus/VirtIO/RNG.cpp b/Kernel/Bus/VirtIO/RNG.cpp index c98f472e00..9c482bfc10 100644 --- a/Kernel/Bus/VirtIO/RNG.cpp +++ b/Kernel/Bus/VirtIO/RNG.cpp @@ -9,9 +9,9 @@ namespace Kernel::VirtIO { -UNMAP_AFTER_INIT NonnullRefPtr<RNG> RNG::must_create(PCI::Address address) +UNMAP_AFTER_INIT NonnullRefPtr<RNG> RNG::must_create(PCI::DeviceIdentifier const& device_identifier) { - return adopt_ref_if_nonnull(new RNG(address)).release_nonnull(); + return adopt_ref_if_nonnull(new RNG(device_identifier)).release_nonnull(); } UNMAP_AFTER_INIT void RNG::initialize() @@ -33,8 +33,8 @@ UNMAP_AFTER_INIT void RNG::initialize() } } -UNMAP_AFTER_INIT RNG::RNG(PCI::Address address) - : VirtIO::Device(address) +UNMAP_AFTER_INIT RNG::RNG(PCI::DeviceIdentifier const& device_identifier) + : VirtIO::Device(device_identifier) { } diff --git a/Kernel/Bus/VirtIO/RNG.h b/Kernel/Bus/VirtIO/RNG.h index c1e6d3c440..a77b284a39 100644 --- a/Kernel/Bus/VirtIO/RNG.h +++ b/Kernel/Bus/VirtIO/RNG.h @@ -19,7 +19,7 @@ class RNG final : public RefCounted<RNG> , public VirtIO::Device { public: - static NonnullRefPtr<RNG> must_create(PCI::Address address); + static NonnullRefPtr<RNG> must_create(PCI::DeviceIdentifier const&); virtual StringView purpose() const override { return class_name(); } virtual ~RNG() override = default; @@ -27,7 +27,7 @@ public: private: virtual StringView class_name() const override { return "VirtIOConsole"; } - explicit RNG(PCI::Address); + explicit RNG(PCI::DeviceIdentifier const&); virtual bool handle_device_config_change() override; virtual void handle_queue_update(u16 queue_index) override; void request_entropy_from_host(); diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp index 0a4e2c84e6..1f6157e2fa 100644 --- a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp +++ b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp @@ -71,11 +71,11 @@ struct [[gnu::packed]] BochsDisplayMMIORegisters { ExtensionRegisters extension_regs; }; -UNMAP_AFTER_INIT NonnullRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::Address address) +UNMAP_AFTER_INIT NonnullRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - PCI::HardwareID id = PCI::get_hardware_id(address); + PCI::HardwareID id = pci_device_identifier.hardware_id(); 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)); + return adopt_ref(*new BochsGraphicsAdapter(pci_device_identifier)); } void BochsGraphicsAdapter::set_framebuffer_to_big_endian_format() @@ -100,21 +100,23 @@ void BochsGraphicsAdapter::set_framebuffer_to_little_endian_format() full_memory_barrier(); } -UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::Address pci_address) - : PCI::Device(pci_address) - , m_mmio_registers(PCI::get_BAR2(pci_address) & 0xfffffff0) +UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier) + : PCI::Device(pci_device_identifier.address()) + , m_mmio_registers(PCI::get_BAR2(pci_device_identifier.address()) & 0xfffffff0) , m_registers(Memory::map_typed_writable<BochsDisplayMMIORegisters volatile>(m_mmio_registers)) { // We assume safe resolutio is 1024x768x32 - m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(PhysicalAddress(PCI::get_BAR0(pci_address) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32)); + m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(PhysicalAddress(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32)); // FIXME: This is a very wrong way to do this... GraphicsManagement::the().m_console = m_framebuffer_console; // Note: If we use VirtualBox graphics adapter (which is based on Bochs one), we need to use IO ports - auto id = PCI::get_hardware_id(pci_address); - if (id.vendor_id == 0x80ee && id.device_id == 0xbeef) + if (pci_device_identifier.hardware_id().vendor_id == 0x80ee && pci_device_identifier.hardware_id().device_id == 0xbeef) m_io_required = true; + if (pci_device_identifier.class_code().value() == 0x3 && pci_device_identifier.subclass_code().value() == 0x0) + m_is_vga_capable = true; + // Note: According to Gerd Hoffmann - "The linux driver simply does // the unblank unconditionally. With bochs-display this is not needed but // it also has no bad side effect". @@ -132,7 +134,7 @@ UNMAP_AFTER_INIT void BochsGraphicsAdapter::initialize_framebuffer_devices() GraphicsDevice::Type BochsGraphicsAdapter::type() const { - if (PCI::get_class(pci_address()) == 0x3 && PCI::get_subclass(pci_address()) == 0x0) + if (m_is_vga_capable) return Type::VGACompatible; return Type::Bochs; } diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.h b/Kernel/Graphics/Bochs/GraphicsAdapter.h index 48717df85d..fdbf069dbb 100644 --- a/Kernel/Graphics/Bochs/GraphicsAdapter.h +++ b/Kernel/Graphics/Bochs/GraphicsAdapter.h @@ -29,7 +29,7 @@ private: TYPEDEF_DISTINCT_ORDERED_ID(u16, IndexID); public: - static NonnullRefPtr<BochsGraphicsAdapter> initialize(PCI::Address); + static NonnullRefPtr<BochsGraphicsAdapter> initialize(PCI::DeviceIdentifier const&); virtual ~BochsGraphicsAdapter() = default; virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); } @@ -47,7 +47,7 @@ private: virtual void enable_consoles() override; virtual void disable_consoles() override; - explicit BochsGraphicsAdapter(PCI::Address); + explicit BochsGraphicsAdapter(PCI::DeviceIdentifier const&); IndexID index_id() const; @@ -71,5 +71,6 @@ private: Spinlock m_console_mode_switch_lock; bool m_console_enabled { false }; bool m_io_required { false }; + bool m_is_vga_capable { false }; }; } diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index afc29022d2..e1532a6662 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -50,23 +50,23 @@ void GraphicsManagement::activate_graphical_mode() } } -static inline bool is_vga_compatible_pci_device(PCI::Address address) +static inline bool is_vga_compatible_pci_device(PCI::DeviceIdentifier const& device_identifier) { // Note: Check for Display Controller, VGA Compatible Controller or // Unclassified, VGA-Compatible Unclassified Device - auto is_display_controller_vga_compatible = PCI::get_class(address) == 0x3 && PCI::get_subclass(address) == 0x0; - auto is_general_pci_vga_compatible = PCI::get_class(address) == 0x0 && PCI::get_subclass(address) == 0x1; + 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; return is_display_controller_vga_compatible || is_general_pci_vga_compatible; } -static inline bool is_display_controller_pci_device(PCI::Address address) +static inline bool is_display_controller_pci_device(PCI::DeviceIdentifier const& device_identifier) { - return PCI::get_class(address) == 0x3; + return device_identifier.class_code().value() == 0x3; } -UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_device(const PCI::Address& address, PCI::HardwareID id) +UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_device(PCI::DeviceIdentifier const& device_identifier) { - VERIFY(is_vga_compatible_pci_device(address) || is_display_controller_pci_device(address)); + VERIFY(is_vga_compatible_pci_device(device_identifier) || is_display_controller_pci_device(device_identifier)); auto add_and_configure_adapter = [&](GraphicsDevice& graphics_device) { m_graphics_devices.append(graphics_device); if (!m_framebuffer_devices_allowed) { @@ -77,24 +77,24 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi }; RefPtr<GraphicsDevice> adapter; - switch (id.vendor_id) { + switch (device_identifier.hardware_id().vendor_id) { case PCI::VendorID::QEMUOld: - if (id.device_id == 0x1111) - adapter = BochsGraphicsAdapter::initialize(address); + if (device_identifier.hardware_id().device_id == 0x1111) + adapter = BochsGraphicsAdapter::initialize(device_identifier); break; case PCI::VendorID::VirtualBox: - if (id.device_id == 0xbeef) - adapter = BochsGraphicsAdapter::initialize(address); + if (device_identifier.hardware_id().device_id == 0xbeef) + adapter = BochsGraphicsAdapter::initialize(device_identifier); break; case PCI::VendorID::Intel: - adapter = IntelNativeGraphicsAdapter::initialize(address); + adapter = IntelNativeGraphicsAdapter::initialize(device_identifier); break; case PCI::VendorID::VirtIO: dmesgln("Graphics: Using VirtIO console"); - adapter = Graphics::VirtIOGPU::GraphicsAdapter::initialize(address); + adapter = Graphics::VirtIOGPU::GraphicsAdapter::initialize(device_identifier); break; default: - if (!is_vga_compatible_pci_device(address)) + if (!is_vga_compatible_pci_device(device_identifier)) break; // Note: Although technically possible that a system has a // non-compatible VGA graphics device that was initialized by the @@ -108,10 +108,10 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi // utilize VESA BIOS extensions (that we don't currently) of these cards // support, so we want to utilize the provided framebuffer of these // devices, if possible. - if (!m_vga_adapter && PCI::is_io_space_enabled(address)) { + if (!m_vga_adapter && PCI::is_io_space_enabled(device_identifier.address())) { if (multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { dmesgln("Graphics: Using a preset resolution from the bootloader"); - adapter = VGACompatibleAdapter::initialize_with_preset_resolution(address, + adapter = VGACompatibleAdapter::initialize_with_preset_resolution(device_identifier, multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, @@ -119,7 +119,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi } } else { dmesgln("Graphics: Using a VGA compatible generic adapter"); - adapter = VGACompatibleAdapter::initialize(address); + adapter = VGACompatibleAdapter::initialize(device_identifier); } break; } @@ -129,8 +129,8 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi // Note: If IO space is enabled, this VGA adapter is operating in VGA mode. // Note: If no other VGA adapter is attached as m_vga_adapter, we should attach it then. - if (!m_vga_adapter && PCI::is_io_space_enabled(address) && adapter->type() == GraphicsDevice::Type::VGACompatible) { - dbgln("Graphics adapter @ {} is operating in VGA mode", address); + if (!m_vga_adapter && PCI::is_io_space_enabled(device_identifier.address()) && adapter->type() == GraphicsDevice::Type::VGACompatible) { + dbgln("Graphics adapter @ {} is operating in VGA mode", device_identifier.address()); m_vga_adapter = static_ptr_cast<VGACompatibleAdapter>(adapter); } return true; @@ -179,13 +179,13 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() dbgln("Forcing no initialization of framebuffer devices"); } - PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { + PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) { // Note: Each graphics controller will try to set its native screen resolution // upon creation. Later on, if we don't want to have framebuffer devices, a // framebuffer console will take the control instead. - if (!is_vga_compatible_pci_device(address) && !is_display_controller_pci_device(address)) + if (!is_vga_compatible_pci_device(device_identifier) && !is_display_controller_pci_device(device_identifier)) return; - determine_and_initialize_graphics_device(address, device_identifier.hardware_id()); + determine_and_initialize_graphics_device(device_identifier); }); if (m_graphics_devices.is_empty()) { diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h index 6d6a200416..5c58926d03 100644 --- a/Kernel/Graphics/GraphicsManagement.h +++ b/Kernel/Graphics/GraphicsManagement.h @@ -47,7 +47,7 @@ public: void activate_graphical_mode(); private: - bool determine_and_initialize_graphics_device(const PCI::Address& address, PCI::HardwareID id); + bool determine_and_initialize_graphics_device(PCI::DeviceIdentifier const&); NonnullRefPtrVector<GraphicsDevice> m_graphics_devices; RefPtr<Graphics::Console> m_console; diff --git a/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp b/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp index 0ed5f32eb2..0ebd2f617c 100644 --- a/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp +++ b/Kernel/Graphics/Intel/NativeGraphicsAdapter.cpp @@ -41,13 +41,12 @@ static bool is_supported_model(u16 device_id) #define DDC2_I2C_ADDRESS 0x50 -RefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::Address address) +RefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - auto id = PCI::get_hardware_id(address); - VERIFY(id.vendor_id == 0x8086); - if (!is_supported_model(id.device_id)) + VERIFY(pci_device_identifier.hardware_id().vendor_id == 0x8086); + if (!is_supported_model(pci_device_identifier.hardware_id().device_id)) return {}; - return adopt_ref(*new IntelNativeGraphicsAdapter(address)); + return adopt_ref(*new IntelNativeGraphicsAdapter(pci_device_identifier.address())); } static size_t compute_dac_multiplier(size_t pixel_clock_in_khz) diff --git a/Kernel/Graphics/Intel/NativeGraphicsAdapter.h b/Kernel/Graphics/Intel/NativeGraphicsAdapter.h index 6db51e8005..f71a097bd0 100644 --- a/Kernel/Graphics/Intel/NativeGraphicsAdapter.h +++ b/Kernel/Graphics/Intel/NativeGraphicsAdapter.h @@ -105,7 +105,7 @@ private: }; public: - static RefPtr<IntelNativeGraphicsAdapter> initialize(PCI::Address); + static RefPtr<IntelNativeGraphicsAdapter> initialize(PCI::DeviceIdentifier const&); private: explicit IntelNativeGraphicsAdapter(PCI::Address); diff --git a/Kernel/Graphics/VGACompatibleAdapter.cpp b/Kernel/Graphics/VGACompatibleAdapter.cpp index e899a8af1c..05f4314c11 100644 --- a/Kernel/Graphics/VGACompatibleAdapter.cpp +++ b/Kernel/Graphics/VGACompatibleAdapter.cpp @@ -13,14 +13,14 @@ namespace Kernel { -UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize_with_preset_resolution(PCI::Address address, PhysicalAddress m_framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch) +UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize_with_preset_resolution(PCI::DeviceIdentifier const& pci_device_identifier, PhysicalAddress m_framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch) { - return adopt_ref(*new VGACompatibleAdapter(address, m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch)); + return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address(), m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch)); } -UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize(PCI::Address address) +UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - return adopt_ref(*new VGACompatibleAdapter(address)); + return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address())); } UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices() diff --git a/Kernel/Graphics/VGACompatibleAdapter.h b/Kernel/Graphics/VGACompatibleAdapter.h index cbfbd7e580..523b4eb452 100644 --- a/Kernel/Graphics/VGACompatibleAdapter.h +++ b/Kernel/Graphics/VGACompatibleAdapter.h @@ -20,8 +20,8 @@ class VGACompatibleAdapter : public GraphicsDevice , public PCI::Device { AK_MAKE_ETERNAL public: - static NonnullRefPtr<VGACompatibleAdapter> initialize_with_preset_resolution(PCI::Address, PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch); - static NonnullRefPtr<VGACompatibleAdapter> initialize(PCI::Address); + static NonnullRefPtr<VGACompatibleAdapter> initialize_with_preset_resolution(PCI::DeviceIdentifier const&, PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch); + static NonnullRefPtr<VGACompatibleAdapter> initialize(PCI::DeviceIdentifier const&); virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); } diff --git a/Kernel/Graphics/VirtIOGPU/GPU.cpp b/Kernel/Graphics/VirtIOGPU/GPU.cpp index e5b2140bd8..494c002d21 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU.cpp +++ b/Kernel/Graphics/VirtIOGPU/GPU.cpp @@ -46,8 +46,8 @@ void GPU::initialize() } } -GPU::GPU(PCI::Address address) - : VirtIO::Device(address) +GPU::GPU(PCI::DeviceIdentifier const& device_identifier) + : VirtIO::Device(device_identifier) { auto region_or_error = MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::ReadWrite); if (region_or_error.is_error()) diff --git a/Kernel/Graphics/VirtIOGPU/GPU.h b/Kernel/Graphics/VirtIOGPU/GPU.h index 0427eba006..7405aa9326 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU.h +++ b/Kernel/Graphics/VirtIOGPU/GPU.h @@ -40,7 +40,7 @@ class GPU final friend class FrameBufferDevice; public: - GPU(PCI::Address); + GPU(PCI::DeviceIdentifier const&); virtual ~GPU() override; void create_framebuffer_devices(); diff --git a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp index 6d8ab929ca..507169a4dd 100644 --- a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp +++ b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp @@ -13,16 +13,16 @@ namespace Kernel::Graphics::VirtIOGPU { -NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::Address base_address) +NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::DeviceIdentifier const& device_identifier) { - VERIFY(PCI::get_hardware_id(base_address).vendor_id == PCI::VendorID::VirtIO); - return adopt_ref(*new GraphicsAdapter(base_address)); + VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO); + return adopt_ref(*new GraphicsAdapter(device_identifier)); } -GraphicsAdapter::GraphicsAdapter(PCI::Address base_address) - : PCI::Device(base_address) +GraphicsAdapter::GraphicsAdapter(PCI::DeviceIdentifier const& device_identifier) + : PCI::Device(device_identifier.address()) { - m_gpu_device = adopt_ref(*new GPU(base_address)).leak_ref(); + m_gpu_device = adopt_ref(*new GPU(device_identifier)).leak_ref(); m_gpu_device->initialize(); } diff --git a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h index 56b23d0d27..95dae4632f 100644 --- a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h +++ b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h @@ -18,12 +18,12 @@ class GraphicsAdapter final AK_MAKE_ETERNAL public: - static NonnullRefPtr<GraphicsAdapter> initialize(PCI::Address); + static NonnullRefPtr<GraphicsAdapter> initialize(PCI::DeviceIdentifier const&); virtual bool framebuffer_devices_initialized() const override { return m_created_framebuffer_devices; } private: - explicit GraphicsAdapter(PCI::Address base_address); + explicit GraphicsAdapter(PCI::DeviceIdentifier const&); virtual void initialize_framebuffer_devices() override; virtual Type type() const override { return Type::Raw; } diff --git a/Kernel/Net/E1000ENetworkAdapter.cpp b/Kernel/Net/E1000ENetworkAdapter.cpp index 9f5a43bfdb..1cc610fbca 100644 --- a/Kernel/Net/E1000ENetworkAdapter.cpp +++ b/Kernel/Net/E1000ENetworkAdapter.cpp @@ -180,15 +180,14 @@ static bool is_valid_device_id(u16 device_id) } } -UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::Address address) +UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - auto id = PCI::get_hardware_id(address); - if (id.vendor_id != PCI::VendorID::Intel) + if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel) return {}; - if (!is_valid_device_id(id.device_id)) + if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id)) return {}; - u8 irq = PCI::get_interrupt_line(address); - auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(address, irq)); + u8 irq = PCI::get_interrupt_line(pci_device_identifier.address()); + auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(pci_device_identifier.address(), irq)); if (!adapter) return {}; if (adapter->initialize()) diff --git a/Kernel/Net/E1000ENetworkAdapter.h b/Kernel/Net/E1000ENetworkAdapter.h index 7c0b017ba0..de88a423e3 100644 --- a/Kernel/Net/E1000ENetworkAdapter.h +++ b/Kernel/Net/E1000ENetworkAdapter.h @@ -21,7 +21,7 @@ namespace Kernel { class E1000ENetworkAdapter final : public E1000NetworkAdapter { public: - static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::Address); + static RefPtr<E1000ENetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); virtual bool initialize() override; diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 781faa3aa3..d8f4ac617a 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -158,15 +158,14 @@ UNMAP_AFTER_INIT static bool is_valid_device_id(u16 device_id) } } -UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::Address address) +UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - auto id = PCI::get_hardware_id(address); - if (id.vendor_id != PCI::VendorID::Intel) + if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Intel) return {}; - if (!is_valid_device_id(id.device_id)) + if (!is_valid_device_id(pci_device_identifier.hardware_id().device_id)) return {}; - u8 irq = PCI::get_interrupt_line(address); - auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(address, irq)); + u8 irq = PCI::get_interrupt_line(pci_device_identifier.address()); + auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(pci_device_identifier.address(), irq)); if (!adapter) return {}; if (adapter->initialize()) diff --git a/Kernel/Net/E1000NetworkAdapter.h b/Kernel/Net/E1000NetworkAdapter.h index 97b8ea4804..5a1961ca57 100644 --- a/Kernel/Net/E1000NetworkAdapter.h +++ b/Kernel/Net/E1000NetworkAdapter.h @@ -20,7 +20,7 @@ class E1000NetworkAdapter : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::Address); + static RefPtr<E1000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); virtual bool initialize(); diff --git a/Kernel/Net/NE2000NetworkAdapter.cpp b/Kernel/Net/NE2000NetworkAdapter.cpp index b29ce5b056..1949c71599 100644 --- a/Kernel/Net/NE2000NetworkAdapter.cpp +++ b/Kernel/Net/NE2000NetworkAdapter.cpp @@ -137,7 +137,7 @@ struct [[gnu::packed]] received_packet_header { u16 length; }; -UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::Address address) +UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { constexpr auto ne2k_ids = Array { PCI::HardwareID { 0x10EC, 0x8029 }, // RealTek RTL-8029(AS) @@ -154,11 +154,10 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi PCI::HardwareID { 0x12c3, 0x5598 }, // Holtek HT80229 PCI::HardwareID { 0x8c4a, 0x1980 }, // Winbond W89C940 (misprogrammed) }; - auto id = PCI::get_hardware_id(address); - if (!ne2k_ids.span().contains_slow(id)) + if (!ne2k_ids.span().contains_slow(pci_device_identifier.hardware_id())) return {}; - u8 irq = PCI::get_interrupt_line(address); - return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(address, irq)); + u8 irq = PCI::get_interrupt_line(pci_device_identifier.address()); + return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(pci_device_identifier.address(), irq)); } UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq) diff --git a/Kernel/Net/NE2000NetworkAdapter.h b/Kernel/Net/NE2000NetworkAdapter.h index 1918010ae6..f1b14868fd 100644 --- a/Kernel/Net/NE2000NetworkAdapter.h +++ b/Kernel/Net/NE2000NetworkAdapter.h @@ -20,7 +20,7 @@ class NE2000NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::Address); + static RefPtr<NE2000NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); virtual ~NE2000NetworkAdapter() override; diff --git a/Kernel/Net/NetworkingManagement.cpp b/Kernel/Net/NetworkingManagement.cpp index bb5e52e380..dba129ecec 100644 --- a/Kernel/Net/NetworkingManagement.cpp +++ b/Kernel/Net/NetworkingManagement.cpp @@ -73,17 +73,17 @@ RefPtr<NetworkAdapter> NetworkingManagement::lookup_by_name(const StringView& na return found_adapter; } -UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::Address address) const +UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_device(PCI::DeviceIdentifier const& device_identifier) const { - if (auto candidate = E1000NetworkAdapter::try_to_initialize(address); !candidate.is_null()) + if (auto candidate = E1000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) return candidate; - if (auto candidate = E1000ENetworkAdapter::try_to_initialize(address); !candidate.is_null()) + if (auto candidate = E1000ENetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) return candidate; - if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(address); !candidate.is_null()) + if (auto candidate = RTL8139NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) return candidate; - if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(address); !candidate.is_null()) + if (auto candidate = RTL8168NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) return candidate; - if (auto candidate = NE2000NetworkAdapter::try_to_initialize(address); !candidate.is_null()) + if (auto candidate = NE2000NetworkAdapter::try_to_initialize(device_identifier); !candidate.is_null()) return candidate; return {}; } @@ -91,11 +91,11 @@ UNMAP_AFTER_INIT RefPtr<NetworkAdapter> NetworkingManagement::determine_network_ bool NetworkingManagement::initialize() { if (!kernel_command_line().is_physical_networking_disabled()) { - PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { + PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) { // Note: PCI class 2 is the class of Network devices if (device_identifier.class_code().value() != 0x02) return; - if (auto adapter = determine_network_device(address); !adapter.is_null()) + if (auto adapter = determine_network_device(device_identifier); !adapter.is_null()) m_adapters.append(adapter.release_nonnull()); }); } diff --git a/Kernel/Net/NetworkingManagement.h b/Kernel/Net/NetworkingManagement.h index 6669d54a2a..cab54711ca 100644 --- a/Kernel/Net/NetworkingManagement.h +++ b/Kernel/Net/NetworkingManagement.h @@ -36,7 +36,7 @@ public: NonnullRefPtr<NetworkAdapter> loopback_adapter() const; private: - RefPtr<NetworkAdapter> determine_network_device(PCI::Address address) const; + RefPtr<NetworkAdapter> determine_network_device(PCI::DeviceIdentifier const&) const; NonnullRefPtrVector<NetworkAdapter> m_adapters; RefPtr<NetworkAdapter> m_loopback_adapter; diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp index 00d715f71e..fbf0ab3b64 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.cpp +++ b/Kernel/Net/RTL8139NetworkAdapter.cpp @@ -112,14 +112,13 @@ namespace Kernel { #define RX_BUFFER_SIZE 32768 #define TX_BUFFER_SIZE PACKET_SIZE_MAX -UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::Address address) +UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { constexpr PCI::HardwareID rtl8139_id = { 0x10EC, 0x8139 }; - auto id = PCI::get_hardware_id(address); - if (id != rtl8139_id) + if (pci_device_identifier.hardware_id() != rtl8139_id) return {}; - u8 irq = PCI::get_interrupt_line(address); - return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(address, irq)); + u8 irq = PCI::get_interrupt_line(pci_device_identifier.address()); + return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(pci_device_identifier.address(), irq)); } UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq) diff --git a/Kernel/Net/RTL8139NetworkAdapter.h b/Kernel/Net/RTL8139NetworkAdapter.h index 397cf29d68..af10cc9e70 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.h +++ b/Kernel/Net/RTL8139NetworkAdapter.h @@ -22,7 +22,7 @@ class RTL8139NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::Address); + static RefPtr<RTL8139NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); virtual ~RTL8139NetworkAdapter() override; diff --git a/Kernel/Net/RTL8168NetworkAdapter.cpp b/Kernel/Net/RTL8168NetworkAdapter.cpp index 787ce9472f..3b2459b86d 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.cpp +++ b/Kernel/Net/RTL8168NetworkAdapter.cpp @@ -181,15 +181,14 @@ namespace Kernel { #define TX_BUFFER_SIZE 0x1FF8 #define RX_BUFFER_SIZE 0x1FF8 // FIXME: this should be increased (0x3FFF) -UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::Address address) +UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - auto id = PCI::get_hardware_id(address); - if (id.vendor_id != PCI::VendorID::Realtek) + if (pci_device_identifier.hardware_id().vendor_id != PCI::VendorID::Realtek) return {}; - if (id.device_id != 0x8168) + if (pci_device_identifier.hardware_id().device_id != 0x8168) return {}; - u8 irq = PCI::get_interrupt_line(address); - return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(address, irq)); + u8 irq = PCI::get_interrupt_line(pci_device_identifier.address()); + return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(pci_device_identifier.address(), irq)); } bool RTL8168NetworkAdapter::determine_supported_version() const diff --git a/Kernel/Net/RTL8168NetworkAdapter.h b/Kernel/Net/RTL8168NetworkAdapter.h index 8a10d2db66..4f66139a89 100644 --- a/Kernel/Net/RTL8168NetworkAdapter.h +++ b/Kernel/Net/RTL8168NetworkAdapter.h @@ -22,7 +22,7 @@ class RTL8168NetworkAdapter final : public NetworkAdapter , public PCI::Device , public IRQHandler { public: - static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::Address); + static RefPtr<RTL8168NetworkAdapter> try_to_initialize(PCI::DeviceIdentifier const&); virtual ~RTL8168NetworkAdapter() override; diff --git a/Kernel/Storage/AHCIController.cpp b/Kernel/Storage/AHCIController.cpp index d037639ca1..09b9872ca7 100644 --- a/Kernel/Storage/AHCIController.cpp +++ b/Kernel/Storage/AHCIController.cpp @@ -15,9 +15,9 @@ namespace Kernel { -NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::Address address) +NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::DeviceIdentifier const& pci_device_identifier) { - return adopt_ref(*new AHCIController(address)); + return adopt_ref(*new AHCIController(pci_device_identifier.address())); } bool AHCIController::reset() diff --git a/Kernel/Storage/AHCIController.h b/Kernel/Storage/AHCIController.h index 310203659b..de0d15d28e 100644 --- a/Kernel/Storage/AHCIController.h +++ b/Kernel/Storage/AHCIController.h @@ -25,7 +25,7 @@ class AHCIController final : public StorageController friend class AHCIPort; AK_MAKE_ETERNAL public: - UNMAP_AFTER_INIT static NonnullRefPtr<AHCIController> initialize(PCI::Address address); + UNMAP_AFTER_INIT static NonnullRefPtr<AHCIController> initialize(PCI::DeviceIdentifier const& pci_device_identifier); virtual ~AHCIController() override; virtual RefPtr<StorageDevice> device(u32 index) const override; diff --git a/Kernel/Storage/IDEController.cpp b/Kernel/Storage/IDEController.cpp index 599f619e4e..f28e14461b 100644 --- a/Kernel/Storage/IDEController.cpp +++ b/Kernel/Storage/IDEController.cpp @@ -16,9 +16,9 @@ namespace Kernel { -UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize(PCI::Address address, bool force_pio) +UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize(PCI::DeviceIdentifier const& device_identifier, bool force_pio) { - return adopt_ref(*new IDEController(address, force_pio)); + return adopt_ref(*new IDEController(device_identifier, force_pio)); } bool IDEController::reset() @@ -51,12 +51,13 @@ void IDEController::complete_current_request(AsyncDeviceRequest::RequestResult) VERIFY_NOT_REACHED(); } -UNMAP_AFTER_INIT IDEController::IDEController(PCI::Address address, bool force_pio) +UNMAP_AFTER_INIT IDEController::IDEController(PCI::DeviceIdentifier const& device_identifier, bool force_pio) : StorageController() - , PCI::Device(address) + , PCI::Device(device_identifier.address()) + , m_prog_if(device_identifier.prog_if()) { - PCI::enable_io_space(address); - PCI::enable_memory_space(address); + PCI::enable_io_space(device_identifier.address()); + PCI::enable_memory_space(device_identifier.address()); initialize(force_pio); } @@ -66,22 +67,22 @@ UNMAP_AFTER_INIT IDEController::~IDEController() bool IDEController::is_pci_native_mode_enabled() const { - return (PCI::get_programming_interface(pci_address()) & 0x05) != 0; + return (m_prog_if.value() & 0x05) != 0; } bool IDEController::is_pci_native_mode_enabled_on_primary_channel() const { - return (PCI::get_programming_interface(pci_address()) & 0x1) == 0x1; + return (m_prog_if.value() & 0x1) == 0x1; } bool IDEController::is_pci_native_mode_enabled_on_secondary_channel() const { - return (PCI::get_programming_interface(pci_address()) & 0x4) == 0x4; + return (m_prog_if.value() & 0x4) == 0x4; } bool IDEController::is_bus_master_capable() const { - return PCI::get_programming_interface(pci_address()) & (1 << 7); + return m_prog_if.value() & (1 << 7); } static const char* detect_controller_type(u8 programming_value) @@ -114,7 +115,7 @@ UNMAP_AFTER_INIT void IDEController::initialize(bool force_pio) auto bus_master_base = IOAddress(PCI::get_BAR4(pci_address()) & (~1)); dbgln("IDE controller @ {}: bus master base was set to {}", pci_address(), bus_master_base); dbgln("IDE controller @ {}: interrupt line was set to {}", pci_address(), PCI::get_interrupt_line(pci_address())); - dbgln("IDE controller @ {}: {}", pci_address(), detect_controller_type(PCI::get_programming_interface(pci_address()))); + dbgln("IDE controller @ {}: {}", pci_address(), detect_controller_type(m_prog_if.value())); dbgln("IDE controller @ {}: primary channel DMA capable? {}", pci_address(), ((bus_master_base.offset(2).in<u8>() >> 5) & 0b11)); dbgln("IDE controller @ {}: secondary channel DMA capable? {}", pci_address(), ((bus_master_base.offset(2 + 8).in<u8>() >> 5) & 0b11)); diff --git a/Kernel/Storage/IDEController.h b/Kernel/Storage/IDEController.h index e484bbd667..a73f5e5473 100644 --- a/Kernel/Storage/IDEController.h +++ b/Kernel/Storage/IDEController.h @@ -21,7 +21,7 @@ class IDEController final : public StorageController , public PCI::Device { AK_MAKE_ETERNAL public: - static NonnullRefPtr<IDEController> initialize(PCI::Address address, bool force_pio); + static NonnullRefPtr<IDEController> initialize(PCI::DeviceIdentifier const&, bool force_pio); virtual ~IDEController() override; virtual RefPtr<StorageDevice> device(u32 index) const override; @@ -37,12 +37,14 @@ public: private: bool is_pci_native_mode_enabled_on_primary_channel() const; bool is_pci_native_mode_enabled_on_secondary_channel() const; - IDEController(PCI::Address address, bool force_pio); + IDEController(PCI::DeviceIdentifier const&, bool force_pio); RefPtr<StorageDevice> device_by_channel_and_position(u32 index) const; void initialize(bool force_pio); void detect_disks(); NonnullRefPtrVector<IDEChannel> m_channels; + // FIXME: Find a better way to get the ProgrammingInterface + PCI::ProgrammingInterface m_prog_if; }; } diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index a60a530259..ef75ac8cac 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -44,15 +44,15 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_controllers(bool force_pio) VERIFY(m_controllers.is_empty()); if (!kernel_command_line().disable_physical_storage()) { if (kernel_command_line().is_ide_enabled()) { - PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { + PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) { if (device_identifier.class_code().value() == PCI_MASS_STORAGE_CLASS_ID && device_identifier.subclass_code().value() == PCI_IDE_CTRL_SUBCLASS_ID) { - m_controllers.append(IDEController::initialize(address, force_pio)); + m_controllers.append(IDEController::initialize(device_identifier, force_pio)); } }); } - PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) { + PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) { if (device_identifier.class_code().value() == PCI_MASS_STORAGE_CLASS_ID && device_identifier.subclass_code().value() == PCI_SATA_CTRL_SUBCLASS_ID && device_identifier.prog_if().value() == PCI_AHCI_IF_PROGIF) { - m_controllers.append(AHCIController::initialize(address)); + m_controllers.append(AHCIController::initialize(device_identifier)); } }); } |