mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 20:35:07 +00:00

This ensures we safely handle interrupts (which can call virtual functions), so they don't happen in the constructor - this pattern can lead to a crash, if we are still in the constructor context because not all methods are available for usage (some are pure virtual, so it's possible to call __cxa_pure_virtual). Also, under some conditions like adding a PCI device via PCI-passthrough mechanism in QEMU, it became exposed to the eye that the code asserts on RNG::handle_device_config_change(). That device has no configuration but if the hypervisor still misbehaves and tries to configure it, we should simply return false to indicate nothing happened.
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Bus/PCI/IDs.h>
|
|
#include <Kernel/Graphics/Console/GenericFramebufferConsole.h>
|
|
#include <Kernel/Graphics/GraphicsManagement.h>
|
|
#include <Kernel/Graphics/VirtIOGPU/GPU.h>
|
|
#include <Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h>
|
|
|
|
namespace Kernel::Graphics::VirtIOGPU {
|
|
|
|
NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::Address base_address)
|
|
{
|
|
VERIFY(PCI::get_id(base_address).vendor_id == PCI::VendorID::VirtIO);
|
|
return adopt_ref(*new GraphicsAdapter(base_address));
|
|
}
|
|
|
|
GraphicsAdapter::GraphicsAdapter(PCI::Address base_address)
|
|
: PCI::Device(base_address)
|
|
{
|
|
m_gpu_device = adopt_ref(*new GPU(base_address)).leak_ref();
|
|
m_gpu_device->initialize();
|
|
}
|
|
|
|
void GraphicsAdapter::initialize_framebuffer_devices()
|
|
{
|
|
dbgln_if(VIRTIO_DEBUG, "GPU: Initializing framebuffer devices");
|
|
VERIFY(!m_created_framebuffer_devices);
|
|
m_gpu_device->create_framebuffer_devices();
|
|
m_created_framebuffer_devices = true;
|
|
|
|
// FIXME: This is a very wrong way to do this...
|
|
GraphicsManagement::the().m_console = m_gpu_device->default_console();
|
|
}
|
|
|
|
void GraphicsAdapter::enable_consoles()
|
|
{
|
|
dbgln_if(VIRTIO_DEBUG, "GPU: Enabling consoles");
|
|
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
|
|
framebuffer.deactivate_writes();
|
|
console.enable();
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
|
|
void GraphicsAdapter::disable_consoles()
|
|
{
|
|
dbgln_if(VIRTIO_DEBUG, "GPU: Disabling consoles");
|
|
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
|
|
console.disable();
|
|
framebuffer.activate_writes();
|
|
return IterationDecision::Continue;
|
|
});
|
|
}
|
|
|
|
}
|