diff options
author | Sahan Fernando <sahan.h.fernando@gmail.com> | 2021-07-07 23:51:33 +1000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-18 19:58:17 +0430 |
commit | 1c77f8067620dbc8eea24f8e6e80440eb09e31c5 (patch) | |
tree | c7135d995dc4441ee74f0cbad461bfad1efcc694 /Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp | |
parent | 215f383b126ebacdbaafef2268790016c696090d (diff) | |
download | serenity-1c77f8067620dbc8eea24f8e6e80440eb09e31c5.zip |
Kernel: Put VirtIOGPU related types into a namespace
Diffstat (limited to 'Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp')
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp new file mode 100644 index 0000000000..53471b564d --- /dev/null +++ b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp @@ -0,0 +1,58 @@ +/* + * 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/VirtIOGPU.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::DeviceController(base_address) +{ + m_gpu_device = adopt_ref(*new GPU(base_address)).leak_ref(); +} + +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; + }); +} + +} |