mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
Kernel/PCI: Propagate usage of DeviceIdentifier everywhere
This allows us to remove a bunch of PCI API functions, and instead to leverage the cached data from DeviceIdentifier object in many places.
This commit is contained in:
parent
da327746a2
commit
057f5a12c2
40 changed files with 150 additions and 186 deletions
|
@ -71,11 +71,11 @@ struct [[gnu::packed]] BochsDisplayMMIORegisters {
|
|||
ExtensionRegisters extension_regs;
|
||||
};
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::Address address)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
PCI::HardwareID id = PCI::get_hardware_id(address);
|
||||
PCI::HardwareID id = pci_device_identifier.hardware_id();
|
||||
VERIFY((id.vendor_id == PCI::VendorID::QEMUOld && id.device_id == 0x1111) || (id.vendor_id == PCI::VendorID::VirtualBox && id.device_id == 0xbeef));
|
||||
return adopt_ref(*new BochsGraphicsAdapter(address));
|
||||
return adopt_ref(*new BochsGraphicsAdapter(pci_device_identifier));
|
||||
}
|
||||
|
||||
void BochsGraphicsAdapter::set_framebuffer_to_big_endian_format()
|
||||
|
@ -100,21 +100,23 @@ void BochsGraphicsAdapter::set_framebuffer_to_little_endian_format()
|
|||
full_memory_barrier();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::Address pci_address)
|
||||
: PCI::Device(pci_address)
|
||||
, m_mmio_registers(PCI::get_BAR2(pci_address) & 0xfffffff0)
|
||||
UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
: PCI::Device(pci_device_identifier.address())
|
||||
, m_mmio_registers(PCI::get_BAR2(pci_device_identifier.address()) & 0xfffffff0)
|
||||
, m_registers(Memory::map_typed_writable<BochsDisplayMMIORegisters volatile>(m_mmio_registers))
|
||||
{
|
||||
// We assume safe resolutio is 1024x768x32
|
||||
m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(PhysicalAddress(PCI::get_BAR0(pci_address) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32));
|
||||
m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(PhysicalAddress(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32));
|
||||
// FIXME: This is a very wrong way to do this...
|
||||
GraphicsManagement::the().m_console = m_framebuffer_console;
|
||||
|
||||
// Note: If we use VirtualBox graphics adapter (which is based on Bochs one), we need to use IO ports
|
||||
auto id = PCI::get_hardware_id(pci_address);
|
||||
if (id.vendor_id == 0x80ee && id.device_id == 0xbeef)
|
||||
if (pci_device_identifier.hardware_id().vendor_id == 0x80ee && pci_device_identifier.hardware_id().device_id == 0xbeef)
|
||||
m_io_required = true;
|
||||
|
||||
if (pci_device_identifier.class_code().value() == 0x3 && pci_device_identifier.subclass_code().value() == 0x0)
|
||||
m_is_vga_capable = true;
|
||||
|
||||
// Note: According to Gerd Hoffmann - "The linux driver simply does
|
||||
// the unblank unconditionally. With bochs-display this is not needed but
|
||||
// it also has no bad side effect".
|
||||
|
@ -132,7 +134,7 @@ UNMAP_AFTER_INIT void BochsGraphicsAdapter::initialize_framebuffer_devices()
|
|||
|
||||
GraphicsDevice::Type BochsGraphicsAdapter::type() const
|
||||
{
|
||||
if (PCI::get_class(pci_address()) == 0x3 && PCI::get_subclass(pci_address()) == 0x0)
|
||||
if (m_is_vga_capable)
|
||||
return Type::VGACompatible;
|
||||
return Type::Bochs;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ private:
|
|||
TYPEDEF_DISTINCT_ORDERED_ID(u16, IndexID);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<BochsGraphicsAdapter> initialize(PCI::Address);
|
||||
static NonnullRefPtr<BochsGraphicsAdapter> initialize(PCI::DeviceIdentifier const&);
|
||||
virtual ~BochsGraphicsAdapter() = default;
|
||||
virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); }
|
||||
|
||||
|
@ -47,7 +47,7 @@ private:
|
|||
virtual void enable_consoles() override;
|
||||
virtual void disable_consoles() override;
|
||||
|
||||
explicit BochsGraphicsAdapter(PCI::Address);
|
||||
explicit BochsGraphicsAdapter(PCI::DeviceIdentifier const&);
|
||||
|
||||
IndexID index_id() const;
|
||||
|
||||
|
@ -71,5 +71,6 @@ private:
|
|||
Spinlock m_console_mode_switch_lock;
|
||||
bool m_console_enabled { false };
|
||||
bool m_io_required { false };
|
||||
bool m_is_vga_capable { false };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -50,23 +50,23 @@ void GraphicsManagement::activate_graphical_mode()
|
|||
}
|
||||
}
|
||||
|
||||
static inline bool is_vga_compatible_pci_device(PCI::Address address)
|
||||
static inline bool is_vga_compatible_pci_device(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
// Note: Check for Display Controller, VGA Compatible Controller or
|
||||
// Unclassified, VGA-Compatible Unclassified Device
|
||||
auto is_display_controller_vga_compatible = PCI::get_class(address) == 0x3 && PCI::get_subclass(address) == 0x0;
|
||||
auto is_general_pci_vga_compatible = PCI::get_class(address) == 0x0 && PCI::get_subclass(address) == 0x1;
|
||||
auto is_display_controller_vga_compatible = device_identifier.class_code().value() == 0x3 && device_identifier.subclass_code().value() == 0x0;
|
||||
auto is_general_pci_vga_compatible = device_identifier.class_code().value() == 0x0 && device_identifier.subclass_code().value() == 0x1;
|
||||
return is_display_controller_vga_compatible || is_general_pci_vga_compatible;
|
||||
}
|
||||
|
||||
static inline bool is_display_controller_pci_device(PCI::Address address)
|
||||
static inline bool is_display_controller_pci_device(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
return PCI::get_class(address) == 0x3;
|
||||
return device_identifier.class_code().value() == 0x3;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_device(const PCI::Address& address, PCI::HardwareID id)
|
||||
UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_device(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
VERIFY(is_vga_compatible_pci_device(address) || is_display_controller_pci_device(address));
|
||||
VERIFY(is_vga_compatible_pci_device(device_identifier) || is_display_controller_pci_device(device_identifier));
|
||||
auto add_and_configure_adapter = [&](GraphicsDevice& graphics_device) {
|
||||
m_graphics_devices.append(graphics_device);
|
||||
if (!m_framebuffer_devices_allowed) {
|
||||
|
@ -77,24 +77,24 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi
|
|||
};
|
||||
|
||||
RefPtr<GraphicsDevice> adapter;
|
||||
switch (id.vendor_id) {
|
||||
switch (device_identifier.hardware_id().vendor_id) {
|
||||
case PCI::VendorID::QEMUOld:
|
||||
if (id.device_id == 0x1111)
|
||||
adapter = BochsGraphicsAdapter::initialize(address);
|
||||
if (device_identifier.hardware_id().device_id == 0x1111)
|
||||
adapter = BochsGraphicsAdapter::initialize(device_identifier);
|
||||
break;
|
||||
case PCI::VendorID::VirtualBox:
|
||||
if (id.device_id == 0xbeef)
|
||||
adapter = BochsGraphicsAdapter::initialize(address);
|
||||
if (device_identifier.hardware_id().device_id == 0xbeef)
|
||||
adapter = BochsGraphicsAdapter::initialize(device_identifier);
|
||||
break;
|
||||
case PCI::VendorID::Intel:
|
||||
adapter = IntelNativeGraphicsAdapter::initialize(address);
|
||||
adapter = IntelNativeGraphicsAdapter::initialize(device_identifier);
|
||||
break;
|
||||
case PCI::VendorID::VirtIO:
|
||||
dmesgln("Graphics: Using VirtIO console");
|
||||
adapter = Graphics::VirtIOGPU::GraphicsAdapter::initialize(address);
|
||||
adapter = Graphics::VirtIOGPU::GraphicsAdapter::initialize(device_identifier);
|
||||
break;
|
||||
default:
|
||||
if (!is_vga_compatible_pci_device(address))
|
||||
if (!is_vga_compatible_pci_device(device_identifier))
|
||||
break;
|
||||
// Note: Although technically possible that a system has a
|
||||
// non-compatible VGA graphics device that was initialized by the
|
||||
|
@ -108,10 +108,10 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi
|
|||
// utilize VESA BIOS extensions (that we don't currently) of these cards
|
||||
// support, so we want to utilize the provided framebuffer of these
|
||||
// devices, if possible.
|
||||
if (!m_vga_adapter && PCI::is_io_space_enabled(address)) {
|
||||
if (!m_vga_adapter && PCI::is_io_space_enabled(device_identifier.address())) {
|
||||
if (multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) {
|
||||
dmesgln("Graphics: Using a preset resolution from the bootloader");
|
||||
adapter = VGACompatibleAdapter::initialize_with_preset_resolution(address,
|
||||
adapter = VGACompatibleAdapter::initialize_with_preset_resolution(device_identifier,
|
||||
multiboot_framebuffer_addr,
|
||||
multiboot_framebuffer_width,
|
||||
multiboot_framebuffer_height,
|
||||
|
@ -119,7 +119,7 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi
|
|||
}
|
||||
} else {
|
||||
dmesgln("Graphics: Using a VGA compatible generic adapter");
|
||||
adapter = VGACompatibleAdapter::initialize(address);
|
||||
adapter = VGACompatibleAdapter::initialize(device_identifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ UNMAP_AFTER_INIT bool GraphicsManagement::determine_and_initialize_graphics_devi
|
|||
|
||||
// Note: If IO space is enabled, this VGA adapter is operating in VGA mode.
|
||||
// Note: If no other VGA adapter is attached as m_vga_adapter, we should attach it then.
|
||||
if (!m_vga_adapter && PCI::is_io_space_enabled(address) && adapter->type() == GraphicsDevice::Type::VGACompatible) {
|
||||
dbgln("Graphics adapter @ {} is operating in VGA mode", address);
|
||||
if (!m_vga_adapter && PCI::is_io_space_enabled(device_identifier.address()) && adapter->type() == GraphicsDevice::Type::VGACompatible) {
|
||||
dbgln("Graphics adapter @ {} is operating in VGA mode", device_identifier.address());
|
||||
m_vga_adapter = static_ptr_cast<VGACompatibleAdapter>(adapter);
|
||||
}
|
||||
return true;
|
||||
|
@ -179,13 +179,13 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize()
|
|||
dbgln("Forcing no initialization of framebuffer devices");
|
||||
}
|
||||
|
||||
PCI::enumerate([&](const PCI::Address& address, PCI::DeviceIdentifier const& device_identifier) {
|
||||
PCI::enumerate([&](const PCI::Address&, PCI::DeviceIdentifier const& device_identifier) {
|
||||
// Note: Each graphics controller will try to set its native screen resolution
|
||||
// upon creation. Later on, if we don't want to have framebuffer devices, a
|
||||
// framebuffer console will take the control instead.
|
||||
if (!is_vga_compatible_pci_device(address) && !is_display_controller_pci_device(address))
|
||||
if (!is_vga_compatible_pci_device(device_identifier) && !is_display_controller_pci_device(device_identifier))
|
||||
return;
|
||||
determine_and_initialize_graphics_device(address, device_identifier.hardware_id());
|
||||
determine_and_initialize_graphics_device(device_identifier);
|
||||
});
|
||||
|
||||
if (m_graphics_devices.is_empty()) {
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void activate_graphical_mode();
|
||||
|
||||
private:
|
||||
bool determine_and_initialize_graphics_device(const PCI::Address& address, PCI::HardwareID id);
|
||||
bool determine_and_initialize_graphics_device(PCI::DeviceIdentifier const&);
|
||||
NonnullRefPtrVector<GraphicsDevice> m_graphics_devices;
|
||||
RefPtr<Graphics::Console> m_console;
|
||||
|
||||
|
|
|
@ -41,13 +41,12 @@ static bool is_supported_model(u16 device_id)
|
|||
|
||||
#define DDC2_I2C_ADDRESS 0x50
|
||||
|
||||
RefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::Address address)
|
||||
RefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
auto id = PCI::get_hardware_id(address);
|
||||
VERIFY(id.vendor_id == 0x8086);
|
||||
if (!is_supported_model(id.device_id))
|
||||
VERIFY(pci_device_identifier.hardware_id().vendor_id == 0x8086);
|
||||
if (!is_supported_model(pci_device_identifier.hardware_id().device_id))
|
||||
return {};
|
||||
return adopt_ref(*new IntelNativeGraphicsAdapter(address));
|
||||
return adopt_ref(*new IntelNativeGraphicsAdapter(pci_device_identifier.address()));
|
||||
}
|
||||
|
||||
static size_t compute_dac_multiplier(size_t pixel_clock_in_khz)
|
||||
|
|
|
@ -105,7 +105,7 @@ private:
|
|||
};
|
||||
|
||||
public:
|
||||
static RefPtr<IntelNativeGraphicsAdapter> initialize(PCI::Address);
|
||||
static RefPtr<IntelNativeGraphicsAdapter> initialize(PCI::DeviceIdentifier const&);
|
||||
|
||||
private:
|
||||
explicit IntelNativeGraphicsAdapter(PCI::Address);
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize_with_preset_resolution(PCI::Address address, PhysicalAddress m_framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::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)
|
||||
{
|
||||
return adopt_ref(*new VGACompatibleAdapter(address, m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch));
|
||||
return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address(), m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch));
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize(PCI::Address address)
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
return adopt_ref(*new VGACompatibleAdapter(address));
|
||||
return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address()));
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices()
|
||||
|
|
|
@ -20,8 +20,8 @@ class VGACompatibleAdapter : public GraphicsDevice
|
|||
, public PCI::Device {
|
||||
AK_MAKE_ETERNAL
|
||||
public:
|
||||
static NonnullRefPtr<VGACompatibleAdapter> initialize_with_preset_resolution(PCI::Address, PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch);
|
||||
static NonnullRefPtr<VGACompatibleAdapter> initialize(PCI::Address);
|
||||
static NonnullRefPtr<VGACompatibleAdapter> initialize_with_preset_resolution(PCI::DeviceIdentifier const&, PhysicalAddress, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch);
|
||||
static NonnullRefPtr<VGACompatibleAdapter> initialize(PCI::DeviceIdentifier const&);
|
||||
|
||||
virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); }
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ void GPU::initialize()
|
|||
}
|
||||
}
|
||||
|
||||
GPU::GPU(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
GPU::GPU(PCI::DeviceIdentifier const& device_identifier)
|
||||
: VirtIO::Device(device_identifier)
|
||||
{
|
||||
auto region_or_error = MM.allocate_contiguous_kernel_region(32 * PAGE_SIZE, "VirtGPU Scratch Space", Memory::Region::Access::ReadWrite);
|
||||
if (region_or_error.is_error())
|
||||
|
|
|
@ -40,7 +40,7 @@ class GPU final
|
|||
friend class FrameBufferDevice;
|
||||
|
||||
public:
|
||||
GPU(PCI::Address);
|
||||
GPU(PCI::DeviceIdentifier const&);
|
||||
virtual ~GPU() override;
|
||||
|
||||
void create_framebuffer_devices();
|
||||
|
|
|
@ -13,16 +13,16 @@
|
|||
|
||||
namespace Kernel::Graphics::VirtIOGPU {
|
||||
|
||||
NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::Address base_address)
|
||||
NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
VERIFY(PCI::get_hardware_id(base_address).vendor_id == PCI::VendorID::VirtIO);
|
||||
return adopt_ref(*new GraphicsAdapter(base_address));
|
||||
VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO);
|
||||
return adopt_ref(*new GraphicsAdapter(device_identifier));
|
||||
}
|
||||
|
||||
GraphicsAdapter::GraphicsAdapter(PCI::Address base_address)
|
||||
: PCI::Device(base_address)
|
||||
GraphicsAdapter::GraphicsAdapter(PCI::DeviceIdentifier const& device_identifier)
|
||||
: PCI::Device(device_identifier.address())
|
||||
{
|
||||
m_gpu_device = adopt_ref(*new GPU(base_address)).leak_ref();
|
||||
m_gpu_device = adopt_ref(*new GPU(device_identifier)).leak_ref();
|
||||
m_gpu_device->initialize();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ class GraphicsAdapter final
|
|||
AK_MAKE_ETERNAL
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<GraphicsAdapter> initialize(PCI::Address);
|
||||
static NonnullRefPtr<GraphicsAdapter> initialize(PCI::DeviceIdentifier const&);
|
||||
|
||||
virtual bool framebuffer_devices_initialized() const override { return m_created_framebuffer_devices; }
|
||||
|
||||
private:
|
||||
explicit GraphicsAdapter(PCI::Address base_address);
|
||||
explicit GraphicsAdapter(PCI::DeviceIdentifier const&);
|
||||
|
||||
virtual void initialize_framebuffer_devices() override;
|
||||
virtual Type type() const override { return Type::Raw; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue