1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 10:45:08 +00:00
serenity/Kernel/Bus/PCI/Access.h
Liav A 252c92d565 Kernel/Graphics: Introduce support for QEMU isa-vga device
This device is supposed to be used in microvm and ISA-PC machine types,
and we assume that if we are able to probe for the QEMU BGA version of
0xB0C5, then we have an existing ISA Bochs VGA adapter to utilize.
To ensure we don't instantiate the driver for non isa-vga devices, we
try to ensure that PCI is disabled because hardware IO test probe failed
so we can be sure that we use this special handling code only in the
QEMU microvm and ISA-PC machine types. Unfortunately, this means that if
for some reason the isa-vga device is attached for the i440FX or Q35
machine types, we simply are not able to drive the device in such setups
at all.

To determine the amount of VRAM being available, we read VBE register at
offset 0xA. That register holds the amount of VRAM divided by 64K, so we
need to multiply the value in our code to use the actual VRAM size value
again.

The isa-vga device requires us to hardcode the framebuffer physical
address to 0xE0000000, and that address is not expected to change in the
future as many other projects rely on the isa-vga framebuffer to be
present at that physical memory address.
2022-09-20 19:05:13 +01:00

65 lines
2.1 KiB
C++

/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Bitmap.h>
#include <AK/Try.h>
#include <AK/Vector.h>
#include <Kernel/Bus/PCI/Controller/HostController.h>
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/Locking/Spinlock.h>
namespace Kernel::PCI {
class Access {
public:
static bool initialize_for_multiple_pci_domains(PhysicalAddress mcfg_table);
#if ARCH(I386) || ARCH(X86_64)
static bool initialize_for_one_pci_domain();
#endif
ErrorOr<void> fast_enumerate(Function<void(DeviceIdentifier const&)>&) const;
void rescan_hardware();
static Access& the();
static bool is_initialized();
static bool is_disabled();
static bool is_hardware_disabled();
void write8_field(Address address, u32 field, u8 value);
void write16_field(Address address, u32 field, u16 value);
void write32_field(Address address, u32 field, u32 value);
u8 read8_field(Address address, u32 field);
u16 read16_field(Address address, u32 field);
u32 read32_field(Address address, u32 field);
DeviceIdentifier get_device_identifier(Address address) const;
Spinlock const& scan_lock() const { return m_scan_lock; }
RecursiveSpinlock const& access_lock() const { return m_access_lock; }
ErrorOr<void> add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
private:
u8 read8_field(Address address, RegisterOffset field);
u16 read16_field(Address address, RegisterOffset field);
void add_host_controller(NonnullOwnPtr<HostController>);
bool find_and_register_pci_host_bridges_from_acpi_mcfg_table(PhysicalAddress mcfg);
Access();
Vector<Capability> get_capabilities(Address);
Optional<u8> get_capabilities_pointer(Address address);
mutable RecursiveSpinlock m_access_lock { LockRank::None };
mutable Spinlock m_scan_lock { LockRank::None };
HashMap<u32, NonnullOwnPtr<HostController>> m_host_controllers;
Vector<DeviceIdentifier> m_device_identifiers;
};
}