blob: 6219a357a1576dfda96908d20ecf790d07418a8f (
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
|
/*
* 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/VirtIOGraphicsAdapter.h>
namespace Kernel::Graphics {
NonnullRefPtr<VirtIOGraphicsAdapter> VirtIOGraphicsAdapter::initialize(PCI::Address base_address)
{
VERIFY(PCI::get_id(base_address).vendor_id == static_cast<u16>(PCIVendorID::VirtIO));
return adopt_ref(*new VirtIOGraphicsAdapter(base_address));
}
VirtIOGraphicsAdapter::VirtIOGraphicsAdapter(PCI::Address base_address)
: PCI::DeviceController(base_address)
{
m_gpu_device = adopt_ref(*new VirtIOGPU(base_address)).leak_ref();
}
void VirtIOGraphicsAdapter::initialize_framebuffer_devices()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: 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 VirtIOGraphicsAdapter::enable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: Enabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
framebuffer.deactivate_writes();
framebuffer.clear_to_black();
console.enable();
return IterationDecision::Continue;
});
}
void VirtIOGraphicsAdapter::disable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: Disabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
console.disable();
framebuffer.activate_writes();
return IterationDecision::Continue;
});
}
}
|