summaryrefslogtreecommitdiff
path: root/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp
blob: 4043f81156bbe0f9c736d616aa135e3831b16c0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <Kernel/Bus/PCI/API.h>
#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::DeviceIdentifier const& device_identifier)
{
    VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO);
    return adopt_ref(*new GraphicsAdapter(device_identifier));
}

GraphicsAdapter::GraphicsAdapter(PCI::DeviceIdentifier const& device_identifier)
    : PCI::Device(device_identifier.address())
{
    m_gpu_device = adopt_ref(*new GPU(*this, device_identifier)).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;
    });
}

}