summaryrefslogtreecommitdiff
path: root/Kernel/Graphics/VMWare
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-09-23 11:50:04 +0300
committerLinus Groh <mail@linusgroh.de>2022-09-23 17:22:15 +0100
commit05ba0340006e57aaa62d0b962238fa7686df8e06 (patch)
tree35a5c43b16811873d8e69c437e01aa481b0a9455 /Kernel/Graphics/VMWare
parent6bafbd64e23c51933a37c170dcba649df3fa3760 (diff)
downloadserenity-05ba0340006e57aaa62d0b962238fa7686df8e06.zip
Kernel: Introduce the IOWindow class
This class is intended to replace all IOAddress usages in the Kernel codebase altogether. The idea is to ensure IO can be done in arch-specific manner that is determined mostly in compile-time, but to still be able to use most of the Kernel code in non-x86 builds. Specific devices that rely on x86-specific IO instructions are already placed in the Arch/x86 directory and are omitted for non-x86 builds. The reason this works so well is the fact that x86 IO space acts in a similar fashion to the traditional memory space being available in most CPU architectures - the x86 IO space is essentially just an array of bytes like the physical memory address space, but requires x86 IO instructions to load and store data. Therefore, many devices allow host software to interact with the hardware registers in both ways, with a noticeable trend even in the modern x86 hardware to move away from the old x86 IO space to exclusively using memory-mapped IO. Therefore, the IOWindow class encapsulates both methods for x86 builds. The idea is to allow PCI devices to be used in either way in x86 builds, so when trying to map an IOWindow on a PCI BAR, the Kernel will try to find the proper method being declared with the PCI BAR flags. For old PCI hardware on non-x86 builds this might turn into a problem as we can't use port mapped IO, so the Kernel will gracefully fail with ENOTSUP error code if that's the case, as there's really nothing we can do within such case. For general IO, the read{8,16,32} and write{8,16,32} methods are available as a convenient API for other places in the Kernel. There are simply no direct 64-bit IO API methods yet, as it's not needed right now and is not considered to be Arch-agnostic too - the x86 IO space doesn't support generating 64 bit cycle on IO bus and instead requires two 2 32-bit accesses. If for whatever reason it appears to be necessary to do IO in such manner, it could probably be added with some neat tricks to do so. It is recommended to use Memory::TypedMapping struct if direct 64 bit IO is actually needed.
Diffstat (limited to 'Kernel/Graphics/VMWare')
-rw-r--r--Kernel/Graphics/VMWare/GraphicsAdapter.cpp18
-rw-r--r--Kernel/Graphics/VMWare/GraphicsAdapter.h6
2 files changed, 13 insertions, 11 deletions
diff --git a/Kernel/Graphics/VMWare/GraphicsAdapter.cpp b/Kernel/Graphics/VMWare/GraphicsAdapter.cpp
index a7a7b19646..ceddafb8ef 100644
--- a/Kernel/Graphics/VMWare/GraphicsAdapter.cpp
+++ b/Kernel/Graphics/VMWare/GraphicsAdapter.cpp
@@ -15,6 +15,7 @@
#include <Kernel/Graphics/VMWare/Definitions.h>
#include <Kernel/Graphics/VMWare/DisplayConnector.h>
#include <Kernel/Graphics/VMWare/GraphicsAdapter.h>
+#include <Kernel/IOWindow.h>
#include <Kernel/Memory/TypedMapping.h>
#include <Kernel/Sections.h>
@@ -27,29 +28,30 @@ UNMAP_AFTER_INIT LockRefPtr<VMWareGraphicsAdapter> VMWareGraphicsAdapter::try_in
// Note: We only support VMWare SVGA II adapter
if (id.device_id != 0x0405)
return {};
- auto adapter = MUST(adopt_nonnull_lock_ref_or_enomem(new (nothrow) VMWareGraphicsAdapter(pci_device_identifier)));
+ auto registers_io_window = MUST(IOWindow::create_for_pci_device_bar(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0));
+ auto adapter = MUST(adopt_nonnull_lock_ref_or_enomem(new (nothrow) VMWareGraphicsAdapter(pci_device_identifier, move(registers_io_window))));
MUST(adapter->initialize_adapter());
return adapter;
}
-UNMAP_AFTER_INIT VMWareGraphicsAdapter::VMWareGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier)
+UNMAP_AFTER_INIT VMWareGraphicsAdapter::VMWareGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier, NonnullOwnPtr<IOWindow> registers_io_window)
: PCI::Device(pci_device_identifier.address())
- , m_io_registers_base(PCI::get_BAR0(pci_device_identifier.address()) & 0xfffffff0)
+ , m_registers_io_window(move(registers_io_window))
{
- dbgln("VMWare SVGA @ {}, {}", pci_device_identifier.address(), m_io_registers_base);
+ dbgln("VMWare SVGA @ {}, {}", pci_device_identifier.address(), m_registers_io_window);
}
u32 VMWareGraphicsAdapter::read_io_register(VMWareDisplayRegistersOffset register_offset) const
{
SpinlockLocker locker(m_io_access_lock);
- m_io_registers_base.out<u32>(to_underlying(register_offset));
- return m_io_registers_base.offset(1).in<u32>();
+ m_registers_io_window->write32(0, to_underlying(register_offset));
+ return m_registers_io_window->read32_unaligned(1);
}
void VMWareGraphicsAdapter::write_io_register(VMWareDisplayRegistersOffset register_offset, u32 value)
{
SpinlockLocker locker(m_io_access_lock);
- m_io_registers_base.out<u32>(to_underlying(register_offset));
- m_io_registers_base.offset(1).out<u32>(value);
+ m_registers_io_window->write32(0, to_underlying(register_offset));
+ m_registers_io_window->write32_unaligned(1, value);
}
UNMAP_AFTER_INIT ErrorOr<void> VMWareGraphicsAdapter::negotiate_device_version()
diff --git a/Kernel/Graphics/VMWare/GraphicsAdapter.h b/Kernel/Graphics/VMWare/GraphicsAdapter.h
index 8872e992a9..ae27a30d25 100644
--- a/Kernel/Graphics/VMWare/GraphicsAdapter.h
+++ b/Kernel/Graphics/VMWare/GraphicsAdapter.h
@@ -7,10 +7,10 @@
#pragma once
#include <AK/Types.h>
-#include <Kernel/Arch/x86/IO.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Graphics/GenericGraphicsAdapter.h>
#include <Kernel/Graphics/VMWare/Definitions.h>
+#include <Kernel/IOWindow.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Memory/TypedMapping.h>
#include <Kernel/PhysicalAddress.h>
@@ -46,11 +46,11 @@ private:
void print_svga_capabilities() const;
void modeset_primary_screen_resolution(size_t width, size_t height);
- explicit VMWareGraphicsAdapter(PCI::DeviceIdentifier const&);
+ VMWareGraphicsAdapter(PCI::DeviceIdentifier const&, NonnullOwnPtr<IOWindow> registers_io_window);
Memory::TypedMapping<volatile VMWareDisplayFIFORegisters> m_fifo_registers;
LockRefPtr<VMWareDisplayConnector> m_display_connector;
- const IOAddress m_io_registers_base;
+ mutable NonnullOwnPtr<IOWindow> m_registers_io_window;
mutable Spinlock m_io_access_lock { LockRank::None };
mutable RecursiveSpinlock m_operation_lock { LockRank::None };
};