From 3bd0106755afdcabfe6d6574c8f3ac49936e7080 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 9 Jul 2022 08:58:57 +0300 Subject: Kernel/Graphics: Remove VGA folder and its content We never supported VGA framebuffers and that folder was a big misleading part of the graphics subsystem. We do support bare-bones VGA text console (80x25), but that only happens to be supported because we can't be 100% sure we can always initialize framebuffer so in the worst scenario we default to plain old VGA console so the user can still use its own machine. Therefore, the only remaining parts of VGA is in the GraphicsManagement code to help driving the VGA text console if needed. --- Kernel/CMakeLists.txt | 3 - Kernel/Graphics/Console/VGAConsole.h | 1 - Kernel/Graphics/GraphicsManagement.cpp | 89 ++++++++-------------------- Kernel/Graphics/GraphicsManagement.h | 8 +-- Kernel/Graphics/VGA/ISAAdapter.cpp | 26 -------- Kernel/Graphics/VGA/ISAAdapter.h | 28 --------- Kernel/Graphics/VGA/PCIAdapter.cpp | 33 ----------- Kernel/Graphics/VGA/PCIAdapter.h | 26 -------- Kernel/Graphics/VGA/VGACompatibleAdapter.cpp | 20 ------- Kernel/Graphics/VGA/VGACompatibleAdapter.h | 29 --------- 10 files changed, 30 insertions(+), 233 deletions(-) delete mode 100644 Kernel/Graphics/VGA/ISAAdapter.cpp delete mode 100644 Kernel/Graphics/VGA/ISAAdapter.h delete mode 100644 Kernel/Graphics/VGA/PCIAdapter.cpp delete mode 100644 Kernel/Graphics/VGA/PCIAdapter.h delete mode 100644 Kernel/Graphics/VGA/VGACompatibleAdapter.cpp delete mode 100644 Kernel/Graphics/VGA/VGACompatibleAdapter.h (limited to 'Kernel') diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 1ad3e1fadf..5e4aaa6dfe 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -85,9 +85,6 @@ set(KERNEL_SOURCES Graphics/GraphicsManagement.cpp Graphics/Intel/NativeDisplayConnector.cpp Graphics/Intel/NativeGraphicsAdapter.cpp - Graphics/VGA/ISAAdapter.cpp - Graphics/VGA/PCIAdapter.cpp - Graphics/VGA/VGACompatibleAdapter.cpp Graphics/VMWare/Console.cpp Graphics/VMWare/GraphicsAdapter.cpp Graphics/VMWare/DisplayConnector.cpp diff --git a/Kernel/Graphics/Console/VGAConsole.h b/Kernel/Graphics/Console/VGAConsole.h index 0b297163e9..5a15e89626 100644 --- a/Kernel/Graphics/Console/VGAConsole.h +++ b/Kernel/Graphics/Console/VGAConsole.h @@ -9,7 +9,6 @@ #include #include #include -#include namespace Kernel::Graphics { class VGAConsole : public Console { diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index e212382ca1..a1e4d230e8 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -13,9 +13,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -126,37 +123,11 @@ static inline bool is_display_controller_pci_device(PCI::DeviceIdentifier const& return device_identifier.class_code().value() == 0x3; } -UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_isa_graphics_device() -{ - dmesgln("Graphics: Using a ISA VGA compatible generic adapter"); - auto adapter = ISAVGAAdapter::initialize(); - m_graphics_devices.append(*adapter); - m_vga_adapter = adapter; - return true; -} - UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_device(PCI::DeviceIdentifier const& device_identifier) { VERIFY(is_vga_compatible_pci_device(device_identifier) || is_display_controller_pci_device(device_identifier)); RefPtr adapter; - auto create_bootloader_framebuffer_device = [&]() { - if (multiboot_framebuffer_addr.is_null()) { - // Prekernel sets the framebuffer address to 0 if MULTIBOOT_INFO_FRAMEBUFFER_INFO - // is not present, as there is likely never a valid framebuffer at this physical address. - dmesgln("Graphics: Bootloader did not set up a framebuffer"); - } else if (multiboot_framebuffer_type != MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { - dmesgln("Graphics: The framebuffer set up by the bootloader is not RGB"); - } else { - dmesgln("Graphics: Using a preset resolution from the bootloader"); - adapter = PCIVGACompatibleAdapter::initialize_with_preset_resolution(device_identifier, - multiboot_framebuffer_addr, - multiboot_framebuffer_width, - multiboot_framebuffer_height, - multiboot_framebuffer_pitch); - } - }; - if (!adapter) { switch (device_identifier.hardware_id().vendor_id) { case PCI::VendorID::QEMUOld: @@ -178,26 +149,6 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi adapter = VMWareGraphicsAdapter::try_initialize(device_identifier); break; default: - 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 - // Multiboot bootloader to provide a framebuffer, in practice we - // probably want to support these devices natively instead of - // initializing them as some sort of a generic GenericGraphicsAdapter. For now, - // the only known example of this sort of device is qxl in QEMU. For VGA - // compatible devices we don't have a special driver for (e.g. ati-vga, - // qxl-vga, cirrus-vga, vmware-svga in QEMU), it's much more likely that - // these devices will be supported by the Multiboot loader that will - // 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(device_identifier.address())) { - create_bootloader_framebuffer_device(); - } else { - dmesgln("Graphics: Using a PCI VGA compatible generic adapter"); - adapter = PCIVGACompatibleAdapter::initialize(device_identifier); - } break; } } @@ -205,16 +156,21 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi if (!adapter) return false; m_graphics_devices.append(*adapter); - - // 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(device_identifier.address()) && adapter->vga_compatible()) { - dbgln("Graphics adapter @ {} is operating in VGA mode", device_identifier.address()); - m_vga_adapter = static_ptr_cast(adapter); - } return true; } +UNMAP_AFTER_INIT void GraphicsManagement::initialize_preset_resolution_generic_display_connector() +{ + VERIFY(!multiboot_framebuffer_addr.is_null()); + VERIFY(multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB); + dmesgln("Graphics: Using a preset resolution from the bootloader, without knowing the PCI device"); + m_preset_resolution_generic_display_connector = GenericDisplayConnector::must_create_with_preset_resolution( + multiboot_framebuffer_addr, + multiboot_framebuffer_width, + multiboot_framebuffer_height, + multiboot_framebuffer_pitch); +} + UNMAP_AFTER_INIT bool GraphicsManagement::initialize() { @@ -272,17 +228,12 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() } if (graphics_subsystem_mode == CommandLine::GraphicsSubsystemMode::Limited && !multiboot_framebuffer_addr.is_null() && multiboot_framebuffer_type != MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { - dmesgln("Graphics: Using a preset resolution from the bootloader, without knowing the PCI device"); - m_preset_resolution_generic_display_connector = GenericDisplayConnector::must_create_with_preset_resolution( - multiboot_framebuffer_addr, - multiboot_framebuffer_width, - multiboot_framebuffer_height, - multiboot_framebuffer_pitch); + initialize_preset_resolution_generic_display_connector(); return true; } if (PCI::Access::is_disabled()) { - determine_and_initialize_isa_graphics_device(); + dmesgln("Graphics: Using an assumed-to-exist ISA VGA compatible generic adapter"); return true; } @@ -295,6 +246,18 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() determine_and_initialize_graphics_device(device_identifier); })); + // Note: If we failed to find any graphics device to be used natively, but the + // bootloader prepared a framebuffer for us to use, then just create a DisplayConnector + // for it so the user can still use the system in graphics mode. + // Prekernel sets the framebuffer address to 0 if MULTIBOOT_INFO_FRAMEBUFFER_INFO + // is not present, as there is likely never a valid framebuffer at this physical address. + // Note: We only support RGB framebuffers. Any other format besides RGBX (and RGBA) or BGRX (and BGRA) is obsolete + // and is not useful for us. + if (m_graphics_devices.is_empty() && !multiboot_framebuffer_addr.is_null() && multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) { + initialize_preset_resolution_generic_display_connector(); + return true; + } + if (!m_console) { // If no graphics driver was instantiated and we had a bootloader provided // framebuffer console we can simply re-use it. diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h index 70937bbc99..d45108f106 100644 --- a/Kernel/Graphics/GraphicsManagement.h +++ b/Kernel/Graphics/GraphicsManagement.h @@ -13,8 +13,8 @@ #include #include #include +#include #include -#include #include #include @@ -47,15 +47,15 @@ private: void enable_vga_text_mode_console_cursor(); bool determine_and_initialize_graphics_device(PCI::DeviceIdentifier const&); - bool determine_and_initialize_isa_graphics_device(); + + void initialize_preset_resolution_generic_display_connector(); + NonnullRefPtrVector m_graphics_devices; RefPtr m_console; // Note: This is only used when booting with kernel commandline that includes "graphics_subsystem_mode=limited" RefPtr m_preset_resolution_generic_display_connector; - // Note: there could be multiple VGA adapters, but only one can operate in VGA mode - RefPtr m_vga_adapter; unsigned m_current_minor_number { 0 }; SpinlockProtected> m_display_connector_nodes; diff --git a/Kernel/Graphics/VGA/ISAAdapter.cpp b/Kernel/Graphics/VGA/ISAAdapter.cpp deleted file mode 100644 index a7345e7fdd..0000000000 --- a/Kernel/Graphics/VGA/ISAAdapter.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include - -namespace Kernel { - -UNMAP_AFTER_INIT NonnullRefPtr ISAVGAAdapter::initialize() -{ - return adopt_ref(*new ISAVGAAdapter()); -} - -UNMAP_AFTER_INIT ISAVGAAdapter::ISAVGAAdapter() -{ - m_framebuffer_console = Graphics::TextModeConsole::initialize(); - GraphicsManagement::the().set_console(*m_framebuffer_console); -} - -} diff --git a/Kernel/Graphics/VGA/ISAAdapter.h b/Kernel/Graphics/VGA/ISAAdapter.h deleted file mode 100644 index 45faf5c0ec..0000000000 --- a/Kernel/Graphics/VGA/ISAAdapter.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace Kernel { - -class ISAVGAAdapter final : public VGACompatibleAdapter { - friend class GraphicsManagement; - -public: - static NonnullRefPtr initialize(); - -private: - ISAVGAAdapter(); - RefPtr m_framebuffer_console; -}; -} diff --git a/Kernel/Graphics/VGA/PCIAdapter.cpp b/Kernel/Graphics/VGA/PCIAdapter.cpp deleted file mode 100644 index 98f53a85e9..0000000000 --- a/Kernel/Graphics/VGA/PCIAdapter.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include - -namespace Kernel { - -UNMAP_AFTER_INIT NonnullRefPtr PCIVGACompatibleAdapter::initialize_with_preset_resolution(PCI::DeviceIdentifier const& pci_device_identifier, PhysicalAddress framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch) -{ - auto adapter = adopt_ref(*new PCIVGACompatibleAdapter(pci_device_identifier.address())); - adapter->initialize_display_connector_with_preset_resolution(framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch); - return adapter; -} - -UNMAP_AFTER_INIT NonnullRefPtr PCIVGACompatibleAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier) -{ - auto adapter = adopt_ref(*new PCIVGACompatibleAdapter(pci_device_identifier.address())); - return adapter; -} - -UNMAP_AFTER_INIT PCIVGACompatibleAdapter::PCIVGACompatibleAdapter(PCI::Address address) - : PCI::Device(address) -{ -} - -} diff --git a/Kernel/Graphics/VGA/PCIAdapter.h b/Kernel/Graphics/VGA/PCIAdapter.h deleted file mode 100644 index fe9d0485bf..0000000000 --- a/Kernel/Graphics/VGA/PCIAdapter.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace Kernel { - -class PCIVGACompatibleAdapter : public VGACompatibleAdapter - , public PCI::Device { -public: - static NonnullRefPtr initialize_with_preset_resolution(PCI::DeviceIdentifier const&, PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch); - static NonnullRefPtr initialize(PCI::DeviceIdentifier const&); - -protected: - explicit PCIVGACompatibleAdapter(PCI::Address); -}; -} diff --git a/Kernel/Graphics/VGA/VGACompatibleAdapter.cpp b/Kernel/Graphics/VGA/VGACompatibleAdapter.cpp deleted file mode 100644 index 2c4e1dccae..0000000000 --- a/Kernel/Graphics/VGA/VGACompatibleAdapter.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include - -namespace Kernel { - -void VGACompatibleAdapter::initialize_display_connector_with_preset_resolution(PhysicalAddress framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch) -{ - m_generic_display_connector = GenericDisplayConnector::must_create_with_preset_resolution(framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch); -} - -} diff --git a/Kernel/Graphics/VGA/VGACompatibleAdapter.h b/Kernel/Graphics/VGA/VGACompatibleAdapter.h deleted file mode 100644 index 8683a32d81..0000000000 --- a/Kernel/Graphics/VGA/VGACompatibleAdapter.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021-2022, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace Kernel { - -class VGACompatibleAdapter : public GenericGraphicsAdapter { -public: - virtual bool vga_compatible() const override final { return true; } - -protected: - void initialize_display_connector_with_preset_resolution(PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch); - - VGACompatibleAdapter() = default; - - RefPtr m_generic_display_connector; -}; -} -- cgit v1.2.3