mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:07:35 +00:00
Kernel/Graphics: Bring back the mmap interface for DisplayConnectors
The mmap interface was removed when we introduced the DisplayConnector class, as it was quite unsafe to use and didn't handle switching between graphical and text modes safely. By using the SharedFramebufferVMObject, we are able to elegantly coordinate the switch by remapping the attached mmap'ed-Memory::Region(s) with different mappings, therefore, keeping WindowServer to think that the mappings it has are still valid, while they are going to a different physical range until we are back to the graphical mode (after a switch from text mode). Most drivers take advantage of the fact that we know where is the actual framebuffer in physical memory space, the SharedFramebufferVMObject is created with that information. However, the VirtIO driver is different in that aspect, because it relies on DMA transactions to show graphics on the framebuffer, so the SharedFramebufferVMObject is created with that mindset to support the arbitrary framebuffer location in physical memory space.
This commit is contained in:
parent
3d22917548
commit
e2ed6ef741
19 changed files with 309 additions and 341 deletions
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<VMWareDisplayConnector> VMWareDisplayConnector::must_create(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address)
|
||||
NonnullRefPtr<VMWareDisplayConnector> VMWareDisplayConnector::must_create(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address, size_t framebuffer_resource_size)
|
||||
{
|
||||
auto connector = MUST(DeviceManagement::try_create_device<VMWareDisplayConnector>(parent_adapter, framebuffer_address));
|
||||
auto connector = MUST(DeviceManagement::try_create_device<VMWareDisplayConnector>(parent_adapter, framebuffer_address, framebuffer_resource_size));
|
||||
MUST(connector->create_attached_framebuffer_console());
|
||||
MUST(connector->initialize_edid_for_generic_monitor());
|
||||
return connector;
|
||||
|
@ -22,18 +22,13 @@ NonnullRefPtr<VMWareDisplayConnector> VMWareDisplayConnector::must_create(VMWare
|
|||
|
||||
ErrorOr<void> VMWareDisplayConnector::create_attached_framebuffer_console()
|
||||
{
|
||||
auto rounded_size = TRY(Memory::page_round_up(1024 * sizeof(u32) * 768));
|
||||
m_framebuffer_region = TRY(MM.allocate_kernel_region(m_framebuffer_address.page_base(), rounded_size, "Framebuffer"sv, Memory::Region::Access::ReadWrite));
|
||||
[[maybe_unused]] auto result = m_framebuffer_region->set_write_combine(true);
|
||||
m_framebuffer_data = m_framebuffer_region->vaddr().offset(m_framebuffer_address.offset_in_page()).as_ptr();
|
||||
m_framebuffer_console = VMWareFramebufferConsole::initialize(*this);
|
||||
GraphicsManagement::the().set_console(*m_framebuffer_console);
|
||||
return {};
|
||||
}
|
||||
|
||||
VMWareDisplayConnector::VMWareDisplayConnector(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address)
|
||||
: DisplayConnector()
|
||||
, m_framebuffer_address(framebuffer_address)
|
||||
VMWareDisplayConnector::VMWareDisplayConnector(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address, size_t framebuffer_resource_size)
|
||||
: DisplayConnector(framebuffer_address, framebuffer_resource_size, false)
|
||||
, m_parent_adapter(parent_adapter)
|
||||
{
|
||||
}
|
||||
|
@ -63,15 +58,6 @@ ErrorOr<void> VMWareDisplayConnector::unblank()
|
|||
return Error::from_errno(ENOTIMPL);
|
||||
}
|
||||
|
||||
ErrorOr<size_t> VMWareDisplayConnector::write_to_first_surface(u64 offset, UserOrKernelBuffer const& buffer, size_t length)
|
||||
{
|
||||
VERIFY(m_control_lock.is_locked());
|
||||
if (offset + length > m_framebuffer_region->size())
|
||||
return Error::from_errno(EOVERFLOW);
|
||||
TRY(buffer.read(m_framebuffer_data + offset, 0, length));
|
||||
return length;
|
||||
}
|
||||
|
||||
void VMWareDisplayConnector::enable_console()
|
||||
{
|
||||
VERIFY(m_control_lock.is_locked());
|
||||
|
@ -124,10 +110,6 @@ ErrorOr<void> VMWareDisplayConnector::set_mode_setting(ModeSetting const& mode_s
|
|||
|
||||
TRY(m_parent_adapter->modeset_primary_screen_resolution({}, width, height));
|
||||
|
||||
auto rounded_size = TRY(Memory::page_round_up(width * sizeof(u32) * height));
|
||||
m_framebuffer_region = TRY(MM.allocate_kernel_region(m_framebuffer_address.page_base(), rounded_size, "Framebuffer"sv, Memory::Region::Access::ReadWrite));
|
||||
[[maybe_unused]] auto result = m_framebuffer_region->set_write_combine(true);
|
||||
m_framebuffer_data = m_framebuffer_region->vaddr().offset(m_framebuffer_address.offset_in_page()).as_ptr();
|
||||
m_framebuffer_console->set_resolution(width, height, width * sizeof(u32));
|
||||
|
||||
auto pitch = m_parent_adapter->primary_screen_pitch({});
|
||||
|
|
|
@ -23,10 +23,10 @@ class VMWareDisplayConnector : public DisplayConnector {
|
|||
friend class DeviceManagement;
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<VMWareDisplayConnector> must_create(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address);
|
||||
static NonnullRefPtr<VMWareDisplayConnector> must_create(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address, size_t framebuffer_resource_size);
|
||||
|
||||
private:
|
||||
VMWareDisplayConnector(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address);
|
||||
VMWareDisplayConnector(VMWareGraphicsAdapter const& parent_adapter, PhysicalAddress framebuffer_address, size_t framebuffer_resource_size);
|
||||
ErrorOr<void> create_attached_framebuffer_console();
|
||||
|
||||
virtual bool mutable_mode_setting_capable() const override { return true; }
|
||||
|
@ -41,7 +41,6 @@ private:
|
|||
// Note: Paravirtualized hardware doesn't require a defined refresh rate for modesetting.
|
||||
virtual bool refresh_rate_support() const override { return false; }
|
||||
|
||||
virtual ErrorOr<size_t> write_to_first_surface(u64 offset, UserOrKernelBuffer const&, size_t length) override;
|
||||
virtual ErrorOr<void> flush_first_surface() override;
|
||||
virtual ErrorOr<void> flush_rectangle(size_t buffer_index, FBRect const& rect) override;
|
||||
|
||||
|
@ -49,12 +48,7 @@ private:
|
|||
virtual void disable_console() override;
|
||||
|
||||
private:
|
||||
u8* framebuffer_data() { return m_framebuffer_data; }
|
||||
|
||||
const PhysicalAddress m_framebuffer_address;
|
||||
NonnullRefPtr<VMWareGraphicsAdapter> m_parent_adapter;
|
||||
RefPtr<VMWareFramebufferConsole> m_framebuffer_console;
|
||||
OwnPtr<Memory::Region> m_framebuffer_region;
|
||||
u8* m_framebuffer_data {};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -181,7 +181,9 @@ UNMAP_AFTER_INIT ErrorOr<void> VMWareGraphicsAdapter::initialize_adapter()
|
|||
// Note: enable the device by modesetting the primary screen resolution
|
||||
modeset_primary_screen_resolution(640, 480);
|
||||
|
||||
m_display_connector = VMWareDisplayConnector::must_create(*this, PhysicalAddress(PCI::get_BAR1(pci_address()) & 0xfffffff0));
|
||||
auto bar1_space_size = PCI::get_BAR_space_size(pci_address(), 1);
|
||||
|
||||
m_display_connector = VMWareDisplayConnector::must_create(*this, PhysicalAddress(PCI::get_BAR1(pci_address()) & 0xfffffff0), bar1_space_size);
|
||||
TRY(m_display_connector->set_safe_mode_setting());
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue