2021-03-05 09:23:08 -03:00
|
|
|
/*
|
2022-01-21 11:15:46 -03:00
|
|
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
2021-03-05 09:23:08 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2021-06-12 09:30:05 -03:00
|
|
|
#include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h>
|
2021-04-16 16:58:51 -03:00
|
|
|
#include <Kernel/Graphics/Console/TextModeConsole.h>
|
|
|
|
|
#include <Kernel/Graphics/GraphicsManagement.h>
|
2022-01-21 11:15:46 -03:00
|
|
|
#include <Kernel/Graphics/VGA/PCIAdapter.h>
|
2021-06-22 12:40:16 -03:00
|
|
|
#include <Kernel/Sections.h>
|
2021-03-05 09:23:08 -03:00
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<PCIVGACompatibleAdapter> PCIVGACompatibleAdapter::initialize_with_preset_resolution(PCI::DeviceIdentifier const& pci_device_identifier, PhysicalAddress m_framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch)
|
2021-03-05 09:23:08 -03:00
|
|
|
{
|
2022-01-21 11:15:46 -03:00
|
|
|
return adopt_ref(*new PCIVGACompatibleAdapter(pci_device_identifier.address(), m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch));
|
2021-03-05 09:23:08 -03:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<PCIVGACompatibleAdapter> PCIVGACompatibleAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
2021-04-16 16:58:51 -03:00
|
|
|
{
|
2022-01-21 11:15:46 -03:00
|
|
|
return adopt_ref(*new PCIVGACompatibleAdapter(pci_device_identifier.address()));
|
2021-04-16 16:58:51 -03:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
UNMAP_AFTER_INIT void PCIVGACompatibleAdapter::initialize_framebuffer_devices()
|
2021-03-05 09:23:08 -03:00
|
|
|
{
|
2021-04-16 16:58:51 -03:00
|
|
|
// We might not have any pre-set framebuffer, so if that's the case - don't try to initialize one.
|
|
|
|
|
if (m_framebuffer_address.is_null())
|
|
|
|
|
return;
|
|
|
|
|
VERIFY(m_framebuffer_width);
|
|
|
|
|
VERIFY(m_framebuffer_width != 0);
|
|
|
|
|
VERIFY(m_framebuffer_height != 0);
|
|
|
|
|
VERIFY(m_framebuffer_pitch != 0);
|
2021-09-22 11:13:12 -03:00
|
|
|
m_framebuffer_device = FramebufferDevice::create(*this, m_framebuffer_address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch);
|
2021-11-07 20:51:39 -03:00
|
|
|
// FIXME: Would be nice to be able to return ErrorOr<void> here.
|
2021-09-22 11:13:12 -03:00
|
|
|
VERIFY(!m_framebuffer_device->try_to_initialize().is_error());
|
2021-03-05 09:23:08 -03:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
UNMAP_AFTER_INIT PCIVGACompatibleAdapter::PCIVGACompatibleAdapter(PCI::Address address)
|
2021-08-21 00:58:43 -03:00
|
|
|
: PCI::Device(address)
|
2021-03-05 09:23:08 -03:00
|
|
|
{
|
2022-02-09 15:53:17 -03:00
|
|
|
m_framebuffer_console = Graphics::TextModeConsole::initialize();
|
2022-01-29 18:08:05 -03:00
|
|
|
GraphicsManagement::the().set_console(*m_framebuffer_console);
|
2021-03-05 09:23:08 -03:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
UNMAP_AFTER_INIT PCIVGACompatibleAdapter::PCIVGACompatibleAdapter(PCI::Address address, PhysicalAddress framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch)
|
2021-08-21 00:58:43 -03:00
|
|
|
: PCI::Device(address)
|
2021-04-16 16:58:51 -03:00
|
|
|
, m_framebuffer_address(framebuffer_address)
|
|
|
|
|
, m_framebuffer_width(framebuffer_width)
|
|
|
|
|
, m_framebuffer_height(framebuffer_height)
|
|
|
|
|
, m_framebuffer_pitch(framebuffer_pitch)
|
|
|
|
|
{
|
2021-06-12 09:30:05 -03:00
|
|
|
m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch);
|
2022-01-29 18:08:05 -03:00
|
|
|
GraphicsManagement::the().set_console(*m_framebuffer_console);
|
2021-04-16 16:58:51 -03:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 11:15:46 -03:00
|
|
|
void PCIVGACompatibleAdapter::enable_consoles()
|
2021-04-16 16:58:51 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_framebuffer_console);
|
|
|
|
|
if (m_framebuffer_device)
|
2021-05-21 00:53:31 -03:00
|
|
|
m_framebuffer_device->deactivate_writes();
|
2021-04-16 16:58:51 -03:00
|
|
|
m_framebuffer_console->enable();
|
|
|
|
|
}
|
2022-01-21 11:15:46 -03:00
|
|
|
void PCIVGACompatibleAdapter::disable_consoles()
|
2021-03-05 09:23:08 -03:00
|
|
|
{
|
2021-04-16 16:58:51 -03:00
|
|
|
VERIFY(m_framebuffer_device);
|
|
|
|
|
VERIFY(m_framebuffer_console);
|
|
|
|
|
m_framebuffer_console->disable();
|
|
|
|
|
m_framebuffer_device->activate_writes();
|
2021-03-05 09:23:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|