blob: e329d9970091f917a9163daf0520e5afd521570f (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Checked.h>
#include <AK/Singleton.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Debug.h>
#include <Kernel/Graphics/BochsGraphicsAdapter.h>
#include <Kernel/Graphics/GraphicsManagement.h>
#include <Kernel/Graphics/IntelNativeGraphicsAdapter.h>
#include <Kernel/Graphics/VGACompatibleAdapter.h>
#include <Kernel/Multiboot.h>
namespace Kernel {
static AK::Singleton<GraphicsManagement> s_the;
GraphicsManagement& GraphicsManagement::the()
{
return *s_the;
}
bool GraphicsManagement::is_initialized()
{
return s_the.is_initialized();
}
UNMAP_AFTER_INIT GraphicsManagement::GraphicsManagement()
: m_textmode_enabled(kernel_command_line().is_text_mode())
{
}
UNMAP_AFTER_INIT RefPtr<GraphicsDevice> GraphicsManagement::determine_graphics_device(PCI::Address address, PCI::ID id) const
{
if ((id.vendor_id == 0x1234 && id.device_id == 0x1111) || (id.vendor_id == 0x80ee && id.device_id == 0xbeef)) {
return BochsGraphicsAdapter::initialize(address);
}
if (PCI::get_class(address) == 0x3 && PCI::get_subclass(address) == 0x0) {
if (id.vendor_id == 0x8086) {
auto adapter = IntelNativeGraphicsAdapter::initialize(address);
if (!adapter.is_null())
return adapter;
}
VERIFY(multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB || multiboot_info_ptr->framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT);
return VGACompatibleAdapter::initialize_with_preset_resolution(address,
PhysicalAddress((u32)(multiboot_info_ptr->framebuffer_addr)),
multiboot_info_ptr->framebuffer_pitch,
multiboot_info_ptr->framebuffer_width,
multiboot_info_ptr->framebuffer_height);
}
return {};
}
UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
{
if (kernel_command_line().is_text_mode()) {
dbgln("Text mode enabled");
return false;
}
PCI::enumerate([&](const PCI::Address& address, PCI::ID id) {
auto adapter = determine_graphics_device(address, id);
if (!adapter)
return;
adapter->initialize_framebuffer_devices();
m_graphics_devices.append(adapter.release_nonnull());
});
return true;
}
}
|