mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:22:45 +00:00 
			
		
		
		
	Kernel: Move x86 Bochs VBE code to the Arch/x86 directory
To do this, we make the QEMUDisplayConnector class more standalone so it does not need to inherit from the BochsDisplayConnector class.
This commit is contained in:
		
							parent
							
								
									c50a81e93e
								
							
						
					
					
						commit
						8d6da9863f
					
				
					 7 changed files with 86 additions and 13 deletions
				
			
		|  | @ -4,11 +4,12 @@ | ||||||
|  * SPDX-License-Identifier: BSD-2-Clause |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | #include <AK/Platform.h> | ||||||
|  | #include <Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h> | ||||||
| #include <Kernel/Arch/x86/IO.h> | #include <Kernel/Arch/x86/IO.h> | ||||||
| #include <Kernel/Debug.h> | #include <Kernel/Debug.h> | ||||||
| #include <Kernel/Devices/DeviceManagement.h> | #include <Kernel/Devices/DeviceManagement.h> | ||||||
| #include <Kernel/Graphics/Bochs/Definitions.h> | #include <Kernel/Graphics/Bochs/Definitions.h> | ||||||
| #include <Kernel/Graphics/Bochs/DisplayConnector.h> |  | ||||||
| #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h> | #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h> | ||||||
| #include <Kernel/Graphics/GraphicsManagement.h> | #include <Kernel/Graphics/GraphicsManagement.h> | ||||||
| 
 | 
 | ||||||
|  | @ -26,9 +26,9 @@ public: | ||||||
| 
 | 
 | ||||||
|     static NonnullLockRefPtr<BochsDisplayConnector> must_create(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, bool virtual_box_hardware); |     static NonnullLockRefPtr<BochsDisplayConnector> must_create(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, bool virtual_box_hardware); | ||||||
| 
 | 
 | ||||||
|     virtual IndexID index_id() const; | private: | ||||||
|  |     IndexID index_id() const; | ||||||
| 
 | 
 | ||||||
| protected: |  | ||||||
|     ErrorOr<void> create_attached_framebuffer_console(); |     ErrorOr<void> create_attached_framebuffer_console(); | ||||||
| 
 | 
 | ||||||
|     BochsDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size); |     BochsDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size); | ||||||
|  | @ -66,7 +66,6 @@ set(KERNEL_SOURCES | ||||||
|     Devices/HID/KeyboardDevice.cpp |     Devices/HID/KeyboardDevice.cpp | ||||||
|     Devices/HID/MouseDevice.cpp |     Devices/HID/MouseDevice.cpp | ||||||
|     GlobalProcessExposed.cpp |     GlobalProcessExposed.cpp | ||||||
|     Graphics/Bochs/DisplayConnector.cpp |  | ||||||
|     Graphics/Bochs/GraphicsAdapter.cpp |     Graphics/Bochs/GraphicsAdapter.cpp | ||||||
|     Graphics/Bochs/QEMUDisplayConnector.cpp |     Graphics/Bochs/QEMUDisplayConnector.cpp | ||||||
|     Graphics/Console/BootFramebufferConsole.cpp |     Graphics/Console/BootFramebufferConsole.cpp | ||||||
|  | @ -333,6 +332,7 @@ if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64") | ||||||
|         Arch/x86/common/SmapDisabler.cpp |         Arch/x86/common/SmapDisabler.cpp | ||||||
|         Arch/x86/common/Shutdown.cpp |         Arch/x86/common/Shutdown.cpp | ||||||
| 
 | 
 | ||||||
|  |         Arch/x86/Hypervisor/BochsDisplayConnector.cpp | ||||||
|         Arch/x86/Hypervisor/VMWareBackdoor.cpp |         Arch/x86/Hypervisor/VMWareBackdoor.cpp | ||||||
| 
 | 
 | ||||||
|         Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp |         Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp | ||||||
|  |  | ||||||
|  | @ -7,11 +7,13 @@ | ||||||
| #include <AK/Atomic.h> | #include <AK/Atomic.h> | ||||||
| #include <AK/Checked.h> | #include <AK/Checked.h> | ||||||
| #include <AK/Try.h> | #include <AK/Try.h> | ||||||
|  | #if ARCH(I386) || ARCH(X86_64) | ||||||
|  | #    include <Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h> | ||||||
|  | #endif | ||||||
| #include <Kernel/Bus/PCI/API.h> | #include <Kernel/Bus/PCI/API.h> | ||||||
| #include <Kernel/Bus/PCI/IDs.h> | #include <Kernel/Bus/PCI/IDs.h> | ||||||
| #include <Kernel/Debug.h> | #include <Kernel/Debug.h> | ||||||
| #include <Kernel/Graphics/Bochs/Definitions.h> | #include <Kernel/Graphics/Bochs/Definitions.h> | ||||||
| #include <Kernel/Graphics/Bochs/DisplayConnector.h> |  | ||||||
| #include <Kernel/Graphics/Bochs/GraphicsAdapter.h> | #include <Kernel/Graphics/Bochs/GraphicsAdapter.h> | ||||||
| #include <Kernel/Graphics/Bochs/QEMUDisplayConnector.h> | #include <Kernel/Graphics/Bochs/QEMUDisplayConnector.h> | ||||||
| #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h> | #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h> | ||||||
|  | @ -40,6 +42,10 @@ UNMAP_AFTER_INIT ErrorOr<void> BochsGraphicsAdapter::initialize_adapter(PCI::Dev | ||||||
|     // Note: If we use VirtualBox graphics adapter (which is based on Bochs one), we need to use IO ports
 |     // Note: If we use VirtualBox graphics adapter (which is based on Bochs one), we need to use IO ports
 | ||||||
|     // Note: Bochs (the real bochs graphics adapter in the Bochs emulator) uses revision ID of 0x0
 |     // Note: Bochs (the real bochs graphics adapter in the Bochs emulator) uses revision ID of 0x0
 | ||||||
|     // and doesn't support memory-mapped IO registers.
 |     // and doesn't support memory-mapped IO registers.
 | ||||||
|  | 
 | ||||||
|  |     // Note: In non x86-builds, we should never encounter VirtualBox hardware nor Pure Bochs VBE graphics,
 | ||||||
|  |     // so just assume we can use the QEMU BochsVBE-compatible graphics adapter only.
 | ||||||
|  | #if ARCH(I386) || ARCH(X86_64) | ||||||
|     bool virtual_box_hardware = (pci_device_identifier.hardware_id().vendor_id == 0x80ee && pci_device_identifier.hardware_id().device_id == 0xbeef); |     bool virtual_box_hardware = (pci_device_identifier.hardware_id().vendor_id == 0x80ee && pci_device_identifier.hardware_id().device_id == 0xbeef); | ||||||
|     auto bar0_space_size = PCI::get_BAR_space_size(pci_device_identifier.address(), PCI::HeaderType0BaseRegister::BAR0); |     auto bar0_space_size = PCI::get_BAR_space_size(pci_device_identifier.address(), PCI::HeaderType0BaseRegister::BAR0); | ||||||
|     if (pci_device_identifier.revision_id().value() == 0x0 || virtual_box_hardware) { |     if (pci_device_identifier.revision_id().value() == 0x0 || virtual_box_hardware) { | ||||||
|  | @ -49,6 +55,11 @@ UNMAP_AFTER_INIT ErrorOr<void> BochsGraphicsAdapter::initialize_adapter(PCI::Dev | ||||||
|         VERIFY(registers_mapping.region); |         VERIFY(registers_mapping.region); | ||||||
|         m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0), bar0_space_size, move(registers_mapping)); |         m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0), bar0_space_size, move(registers_mapping)); | ||||||
|     } |     } | ||||||
|  | #else | ||||||
|  |     auto registers_mapping = TRY(Memory::map_typed_writable<BochsDisplayMMIORegisters volatile>(PhysicalAddress(PCI::get_BAR2(pci_device_identifier.address()) & 0xfffffff0))); | ||||||
|  |     VERIFY(registers_mapping.region); | ||||||
|  |     m_display_connector = QEMUDisplayConnector::must_create(PhysicalAddress(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0), bar0_space_size, move(registers_mapping)); | ||||||
|  | #endif | ||||||
| 
 | 
 | ||||||
|     // Note: According to Gerd Hoffmann - "The linux driver simply does
 |     // Note: According to Gerd Hoffmann - "The linux driver simply does
 | ||||||
|     // the unblank unconditionally. With bochs-display this is not needed but
 |     // the unblank unconditionally. With bochs-display this is not needed but
 | ||||||
|  |  | ||||||
|  | @ -19,7 +19,6 @@ namespace Kernel { | ||||||
| class GraphicsManagement; | class GraphicsManagement; | ||||||
| struct BochsDisplayMMIORegisters; | struct BochsDisplayMMIORegisters; | ||||||
| 
 | 
 | ||||||
| class BochsDisplayConnector; |  | ||||||
| class BochsGraphicsAdapter final : public GenericGraphicsAdapter | class BochsGraphicsAdapter final : public GenericGraphicsAdapter | ||||||
|     , public PCI::Device { |     , public PCI::Device { | ||||||
|     friend class GraphicsManagement; |     friend class GraphicsManagement; | ||||||
|  | @ -33,6 +32,6 @@ private: | ||||||
| 
 | 
 | ||||||
|     explicit BochsGraphicsAdapter(PCI::DeviceIdentifier const&); |     explicit BochsGraphicsAdapter(PCI::DeviceIdentifier const&); | ||||||
| 
 | 
 | ||||||
|     LockRefPtr<BochsDisplayConnector> m_display_connector; |     LockRefPtr<DisplayConnector> m_display_connector; | ||||||
| }; | }; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ | ||||||
| #include <Kernel/Debug.h> | #include <Kernel/Debug.h> | ||||||
| #include <Kernel/Devices/DeviceManagement.h> | #include <Kernel/Devices/DeviceManagement.h> | ||||||
| #include <Kernel/Graphics/Bochs/QEMUDisplayConnector.h> | #include <Kernel/Graphics/Bochs/QEMUDisplayConnector.h> | ||||||
|  | #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h> | ||||||
| #include <Kernel/Graphics/GraphicsManagement.h> | #include <Kernel/Graphics/GraphicsManagement.h> | ||||||
| #include <LibEDID/Definitions.h> | #include <LibEDID/Definitions.h> | ||||||
| 
 | 
 | ||||||
|  | @ -31,8 +32,54 @@ ErrorOr<void> QEMUDisplayConnector::fetch_and_initialize_edid() | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | ErrorOr<void> QEMUDisplayConnector::create_attached_framebuffer_console() | ||||||
|  | { | ||||||
|  |     // We assume safe resolution is 1024x768x32
 | ||||||
|  |     m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(m_framebuffer_address.value(), 1024, 768, 1024 * sizeof(u32)); | ||||||
|  |     GraphicsManagement::the().set_console(*m_framebuffer_console); | ||||||
|  |     return {}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void QEMUDisplayConnector::enable_console() | ||||||
|  | { | ||||||
|  |     VERIFY(m_control_lock.is_locked()); | ||||||
|  |     VERIFY(m_framebuffer_console); | ||||||
|  |     m_framebuffer_console->enable(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void QEMUDisplayConnector::disable_console() | ||||||
|  | { | ||||||
|  |     VERIFY(m_control_lock.is_locked()); | ||||||
|  |     VERIFY(m_framebuffer_console); | ||||||
|  |     m_framebuffer_console->disable(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> QEMUDisplayConnector::flush_first_surface() | ||||||
|  | { | ||||||
|  |     return Error::from_errno(ENOTSUP); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<void> QEMUDisplayConnector::set_safe_mode_setting() | ||||||
|  | { | ||||||
|  |     DisplayConnector::ModeSetting safe_mode_set { | ||||||
|  |         .horizontal_stride = 1024 * sizeof(u32), | ||||||
|  |         .pixel_clock_in_khz = 0, // Note: There's no pixel clock in paravirtualized hardware
 | ||||||
|  |         .horizontal_active = 1024, | ||||||
|  |         .horizontal_front_porch_pixels = 0, // Note: There's no horizontal_front_porch_pixels in paravirtualized hardware
 | ||||||
|  |         .horizontal_sync_time_pixels = 0,   // Note: There's no horizontal_sync_time_pixels in paravirtualized hardware
 | ||||||
|  |         .horizontal_blank_pixels = 0,       // Note: There's no horizontal_blank_pixels in paravirtualized hardware
 | ||||||
|  |         .vertical_active = 768, | ||||||
|  |         .vertical_front_porch_lines = 0, // Note: There's no vertical_front_porch_lines in paravirtualized hardware
 | ||||||
|  |         .vertical_sync_time_lines = 0,   // Note: There's no vertical_sync_time_lines in paravirtualized hardware
 | ||||||
|  |         .vertical_blank_lines = 0,       // Note: There's no vertical_blank_lines in paravirtualized hardware
 | ||||||
|  |         .horizontal_offset = 0, | ||||||
|  |         .vertical_offset = 0, | ||||||
|  |     }; | ||||||
|  |     return set_mode_setting(safe_mode_set); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| QEMUDisplayConnector::QEMUDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile> registers_mapping) | QEMUDisplayConnector::QEMUDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile> registers_mapping) | ||||||
|     : BochsDisplayConnector(framebuffer_address, framebuffer_resource_size) |     : DisplayConnector(framebuffer_address, framebuffer_resource_size, false) | ||||||
|     , m_registers(move(registers_mapping)) |     , m_registers(move(registers_mapping)) | ||||||
| { | { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,8 +7,9 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <AK/Try.h> | #include <AK/Try.h> | ||||||
| #include <Kernel/Graphics/Bochs/DisplayConnector.h> | #include <Kernel/Graphics/Bochs/Definitions.h> | ||||||
| #include <Kernel/Graphics/Console/GenericFramebufferConsole.h> | #include <Kernel/Graphics/Console/GenericFramebufferConsole.h> | ||||||
|  | #include <Kernel/Graphics/DisplayConnector.h> | ||||||
| #include <Kernel/Library/LockRefPtr.h> | #include <Kernel/Library/LockRefPtr.h> | ||||||
| #include <Kernel/Locking/Spinlock.h> | #include <Kernel/Locking/Spinlock.h> | ||||||
| #include <Kernel/Memory/TypedMapping.h> | #include <Kernel/Memory/TypedMapping.h> | ||||||
|  | @ -17,28 +18,42 @@ namespace Kernel { | ||||||
| 
 | 
 | ||||||
| struct BochsDisplayMMIORegisters; | struct BochsDisplayMMIORegisters; | ||||||
| class QEMUDisplayConnector final | class QEMUDisplayConnector final | ||||||
|     : public BochsDisplayConnector { |     : public DisplayConnector { | ||||||
|     friend class BochsGraphicsAdapter; |     friend class BochsGraphicsAdapter; | ||||||
|     friend class DeviceManagement; |     friend class DeviceManagement; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|  |     AK_TYPEDEF_DISTINCT_ORDERED_ID(u16, IndexID); | ||||||
|  | 
 | ||||||
|     static NonnullLockRefPtr<QEMUDisplayConnector> must_create(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile>); |     static NonnullLockRefPtr<QEMUDisplayConnector> must_create(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile>); | ||||||
| 
 | 
 | ||||||
|     virtual IndexID index_id() const override; |  | ||||||
| 
 |  | ||||||
| private: | private: | ||||||
|  |     IndexID index_id() const; | ||||||
|  | 
 | ||||||
|     ErrorOr<void> fetch_and_initialize_edid(); |     ErrorOr<void> fetch_and_initialize_edid(); | ||||||
|  |     ErrorOr<void> create_attached_framebuffer_console(); | ||||||
|     QEMUDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile>); |     QEMUDisplayConnector(PhysicalAddress framebuffer_address, size_t framebuffer_resource_size, Memory::TypedMapping<BochsDisplayMMIORegisters volatile>); | ||||||
| 
 | 
 | ||||||
|  |     virtual bool mutable_mode_setting_capable() const override final { return true; } | ||||||
|     virtual bool double_framebuffering_capable() const override { return true; } |     virtual bool double_framebuffering_capable() const override { return true; } | ||||||
|     virtual ErrorOr<void> set_mode_setting(ModeSetting const&) override; |     virtual ErrorOr<void> set_mode_setting(ModeSetting const&) override; | ||||||
|     virtual ErrorOr<void> set_y_offset(size_t y) override; |     virtual ErrorOr<void> set_y_offset(size_t y) override; | ||||||
|  |     virtual ErrorOr<void> set_safe_mode_setting() override final; | ||||||
|     virtual ErrorOr<void> unblank() override; |     virtual ErrorOr<void> unblank() override; | ||||||
|  |     virtual bool partial_flush_support() const override final { return false; } | ||||||
|  |     virtual bool flush_support() const override final { return false; } | ||||||
|  |     // Note: Paravirtualized hardware doesn't require a defined refresh rate for modesetting.
 | ||||||
|  |     virtual bool refresh_rate_support() const override final { return false; } | ||||||
|  |     virtual ErrorOr<void> flush_first_surface() override final; | ||||||
| 
 | 
 | ||||||
|     void set_framebuffer_to_big_endian_format(); |     void set_framebuffer_to_big_endian_format(); | ||||||
|     void set_framebuffer_to_little_endian_format(); |     void set_framebuffer_to_little_endian_format(); | ||||||
| 
 | 
 | ||||||
| private: |     virtual void enable_console() override final; | ||||||
|  |     virtual void disable_console() override final; | ||||||
|  | 
 | ||||||
|  |     LockRefPtr<Graphics::GenericFramebufferConsole> m_framebuffer_console; | ||||||
|  | 
 | ||||||
|     Memory::TypedMapping<BochsDisplayMMIORegisters volatile> m_registers; |     Memory::TypedMapping<BochsDisplayMMIORegisters volatile> m_registers; | ||||||
| }; | }; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Liav A
						Liav A