2021-06-12 10:07:44 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-21 04:08:28 -03:00
|
|
|
#include <AK/BinaryBufferWriter.h>
|
Kernel/PCI: Simplify the entire subsystem
A couple of things were changed:
1. Semantic changes - PCI segments are now called PCI domains, to better
match what they are really. It's also the name that Linux gave, and it
seems that Wikipedia also uses this name.
We also remove PCI::ChangeableAddress, because it was used in the past
but now it's no longer being used.
2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as
they made a bunch of unnecessary complexity. Instead, Windowed access is
removed entirely (this was tested, but never was benchmarked), so we are
left with IO access and memory access options. The memory access option
is essentially mapping the PCI bus (from the chosen PCI domain), to
virtual memory as-is. This means that unless needed, at any time, there
is only one PCI bus being mapped, and this is changed if access to
another PCI bus in the same PCI domain is needed. For now, we don't
support mapping of different PCI buses from different PCI domains at the
same time, because basically it's still a non-issue for most machines
out there.
2. OOM-safety is increased, especially when constructing the Access
object. It means that we pre-allocating any needed resources, and we try
to find PCI domains (if requested to initialize memory access) after we
attempt to construct the Access object, so it's possible to fail at this
point "gracefully".
3. All PCI API functions are now separated into a different header file,
which means only "clients" of the PCI subsystem API will need to include
that header file.
4. Functional changes - we only allow now to enumerate the bus after
a hardware scan. This means that the old method "enumerate_hardware"
is removed, so, when initializing an Access object, the initializing
function must call rescan on it to force it to find devices. This makes
it possible to fail rescan, and also to defer it after construction from
both OOM-safety terms and hotplug capabilities.
2021-09-07 06:08:38 -03:00
|
|
|
#include <Kernel/Bus/PCI/API.h>
|
2021-07-02 23:11:29 -03:00
|
|
|
#include <Kernel/Bus/PCI/IDs.h>
|
2022-02-13 02:45:30 -03:00
|
|
|
#include <Kernel/Devices/DeviceManagement.h>
|
2021-06-12 10:07:44 -03:00
|
|
|
#include <Kernel/Graphics/Console/GenericFramebufferConsole.h>
|
|
|
|
|
#include <Kernel/Graphics/GraphicsManagement.h>
|
2021-09-21 04:08:28 -03:00
|
|
|
#include <Kernel/Graphics/VirtIOGPU/Console.h>
|
2022-04-30 07:56:29 -03:00
|
|
|
#include <Kernel/Graphics/VirtIOGPU/DisplayConnector.h>
|
2022-02-13 02:45:30 -03:00
|
|
|
#include <Kernel/Graphics/VirtIOGPU/GPU3DDevice.h>
|
2021-07-07 10:51:33 -03:00
|
|
|
#include <Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h>
|
2021-06-12 10:07:44 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
namespace Kernel {
|
2021-06-12 10:07:44 -03:00
|
|
|
|
2021-09-21 04:08:28 -03:00
|
|
|
#define DEVICE_EVENTS_READ 0x0
|
|
|
|
|
#define DEVICE_EVENTS_CLEAR 0x4
|
|
|
|
|
#define DEVICE_NUM_SCANOUTS 0x8
|
|
|
|
|
|
2022-08-19 15:53:40 -03:00
|
|
|
NonnullLockRefPtr<VirtIOGraphicsAdapter> VirtIOGraphicsAdapter::initialize(PCI::DeviceIdentifier const& device_identifier)
|
2021-06-12 10:07:44 -03:00
|
|
|
{
|
2021-09-23 04:20:54 -03:00
|
|
|
VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO);
|
2022-04-30 07:56:29 -03:00
|
|
|
// Setup memory transfer region
|
|
|
|
|
auto scratch_space_region = MUST(MM.allocate_contiguous_kernel_region(
|
|
|
|
|
32 * PAGE_SIZE,
|
2022-07-11 14:32:29 -03:00
|
|
|
"VirtGPU Scratch Space"sv,
|
2022-04-30 07:56:29 -03:00
|
|
|
Memory::Region::Access::ReadWrite));
|
|
|
|
|
|
2022-08-19 15:53:40 -03:00
|
|
|
auto adapter = adopt_lock_ref(*new (nothrow) VirtIOGraphicsAdapter(device_identifier, move(scratch_space_region)));
|
2021-09-21 04:08:28 -03:00
|
|
|
adapter->initialize();
|
2022-04-30 07:56:29 -03:00
|
|
|
MUST(adapter->initialize_adapter());
|
2021-09-21 04:08:28 -03:00
|
|
|
return adapter;
|
2021-06-12 10:07:44 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
ErrorOr<void> VirtIOGraphicsAdapter::initialize_adapter()
|
2021-06-12 10:07:44 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(m_num_scanouts <= VIRTIO_GPU_MAX_SCANOUTS);
|
|
|
|
|
for (size_t index = 0; index < m_num_scanouts; index++) {
|
|
|
|
|
auto display_connector = VirtIODisplayConnector::must_create(*this, index);
|
|
|
|
|
m_scanouts[index].display_connector = display_connector;
|
|
|
|
|
MUST(query_and_set_edid(index, *display_connector));
|
|
|
|
|
display_connector->set_safe_mode_setting_after_initialization({});
|
|
|
|
|
}
|
|
|
|
|
return {};
|
2021-06-12 10:07:44 -03:00
|
|
|
}
|
|
|
|
|
|
2022-05-12 21:23:13 -03:00
|
|
|
ErrorOr<void> VirtIOGraphicsAdapter::mode_set_resolution(Badge<VirtIODisplayConnector>, VirtIODisplayConnector& connector, size_t width, size_t height)
|
|
|
|
|
{
|
|
|
|
|
SpinlockLocker locker(m_operation_lock);
|
|
|
|
|
VERIFY(connector.scanout_id() < VIRTIO_GPU_MAX_SCANOUTS);
|
|
|
|
|
auto rounded_buffer_size = TRY(calculate_framebuffer_size(width, height));
|
|
|
|
|
TRY(attach_physical_range_to_framebuffer(connector, true, 0, rounded_buffer_size));
|
|
|
|
|
TRY(attach_physical_range_to_framebuffer(connector, false, rounded_buffer_size, rounded_buffer_size));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VirtIOGraphicsAdapter::set_dirty_displayed_rect(Badge<VirtIODisplayConnector>, VirtIODisplayConnector& connector, Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect, bool main_buffer)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
VERIFY(connector.scanout_id() < VIRTIO_GPU_MAX_SCANOUTS);
|
|
|
|
|
Scanout::PhysicalBuffer& buffer = main_buffer ? m_scanouts[connector.scanout_id().value()].main_buffer : m_scanouts[connector.scanout_id().value()].back_buffer;
|
|
|
|
|
if (buffer.dirty_rect.width == 0 || buffer.dirty_rect.height == 0) {
|
|
|
|
|
buffer.dirty_rect = dirty_rect;
|
|
|
|
|
} else {
|
|
|
|
|
auto current_dirty_right = buffer.dirty_rect.x + buffer.dirty_rect.width;
|
|
|
|
|
auto current_dirty_bottom = buffer.dirty_rect.y + buffer.dirty_rect.height;
|
|
|
|
|
buffer.dirty_rect.x = min(buffer.dirty_rect.x, dirty_rect.x);
|
|
|
|
|
buffer.dirty_rect.y = min(buffer.dirty_rect.y, dirty_rect.y);
|
|
|
|
|
buffer.dirty_rect.width = max(current_dirty_right, dirty_rect.x + dirty_rect.width) - buffer.dirty_rect.x;
|
|
|
|
|
buffer.dirty_rect.height = max(current_dirty_bottom, dirty_rect.y + dirty_rect.height) - buffer.dirty_rect.y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VirtIOGraphicsAdapter::flush_displayed_image(Badge<VirtIODisplayConnector>, VirtIODisplayConnector& connector, Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect, bool main_buffer)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
VERIFY(connector.scanout_id() < VIRTIO_GPU_MAX_SCANOUTS);
|
|
|
|
|
Scanout::PhysicalBuffer& buffer = main_buffer ? m_scanouts[connector.scanout_id().value()].main_buffer : m_scanouts[connector.scanout_id().value()].back_buffer;
|
|
|
|
|
flush_displayed_image(buffer.resource_id, dirty_rect);
|
|
|
|
|
buffer.dirty_rect = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VirtIOGraphicsAdapter::transfer_framebuffer_data_to_host(Badge<VirtIODisplayConnector>, VirtIODisplayConnector& connector, Graphics::VirtIOGPU::Protocol::Rect const& rect, bool main_buffer)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
VERIFY(connector.scanout_id() < VIRTIO_GPU_MAX_SCANOUTS);
|
|
|
|
|
Scanout::PhysicalBuffer& buffer = main_buffer ? m_scanouts[connector.scanout_id().value()].main_buffer : m_scanouts[connector.scanout_id().value()].back_buffer;
|
|
|
|
|
transfer_framebuffer_data_to_host(connector.scanout_id(), buffer.resource_id, rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorOr<void> VirtIOGraphicsAdapter::attach_physical_range_to_framebuffer(VirtIODisplayConnector& connector, bool main_buffer, size_t framebuffer_offset, size_t framebuffer_size)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
Scanout::PhysicalBuffer& buffer = main_buffer ? m_scanouts[connector.scanout_id().value()].main_buffer : m_scanouts[connector.scanout_id().value()].back_buffer;
|
|
|
|
|
buffer.framebuffer_offset = framebuffer_offset;
|
|
|
|
|
|
|
|
|
|
// 1. Create BUFFER using VIRTIO_GPU_CMD_RESOURCE_CREATE_2D
|
|
|
|
|
if (buffer.resource_id.value() != 0)
|
|
|
|
|
delete_resource(buffer.resource_id);
|
|
|
|
|
auto display_info = connector.display_information({});
|
|
|
|
|
buffer.resource_id = create_2d_resource(display_info.rect);
|
|
|
|
|
|
|
|
|
|
// 2. Attach backing storage using VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING
|
|
|
|
|
ensure_backing_storage(buffer.resource_id, connector.framebuffer_region(), buffer.framebuffer_offset, framebuffer_size);
|
|
|
|
|
// 3. Use VIRTIO_GPU_CMD_SET_SCANOUT to link the framebuffer to a display scanout.
|
|
|
|
|
set_scanout_resource(connector.scanout_id(), buffer.resource_id, display_info.rect);
|
|
|
|
|
// 4. Render our test pattern
|
|
|
|
|
connector.draw_ntsc_test_pattern({});
|
|
|
|
|
// 5. Use VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D to update the host resource from guest memory.
|
|
|
|
|
transfer_framebuffer_data_to_host(connector.scanout_id(), buffer.resource_id, display_info.rect);
|
|
|
|
|
// 6. Use VIRTIO_GPU_CMD_RESOURCE_FLUSH to flush the updated resource to the display.
|
|
|
|
|
flush_displayed_image(buffer.resource_id, display_info.rect);
|
|
|
|
|
|
|
|
|
|
// Make sure we constrain the existing dirty rect (if any)
|
|
|
|
|
if (buffer.dirty_rect.width != 0 || buffer.dirty_rect.height != 0) {
|
|
|
|
|
auto dirty_right = buffer.dirty_rect.x + buffer.dirty_rect.width;
|
|
|
|
|
auto dirty_bottom = buffer.dirty_rect.y + buffer.dirty_rect.height;
|
|
|
|
|
buffer.dirty_rect.width = min(dirty_right, display_info.rect.x + display_info.rect.width) - buffer.dirty_rect.x;
|
|
|
|
|
buffer.dirty_rect.height = min(dirty_bottom, display_info.rect.y + display_info.rect.height) - buffer.dirty_rect.y;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VirtIOGraphicsAdapter::VirtIOGraphicsAdapter(PCI::DeviceIdentifier const& device_identifier, NonnullOwnPtr<Memory::Region> scratch_space_region)
|
|
|
|
|
: VirtIO::Device(device_identifier)
|
|
|
|
|
, m_scratch_space(move(scratch_space_region))
|
2021-06-12 10:07:44 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::initialize()
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
VirtIO::Device::initialize();
|
2021-09-21 04:08:28 -03:00
|
|
|
if (auto* config = get_config(VirtIO::ConfigurationType::Device)) {
|
|
|
|
|
m_device_configuration = config;
|
|
|
|
|
bool success = negotiate_features([&](u64 supported_features) {
|
|
|
|
|
u64 negotiated = 0;
|
2022-02-13 02:45:30 -03:00
|
|
|
if (is_feature_set(supported_features, VIRTIO_GPU_F_VIRGL)) {
|
|
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: VirGL is available, enabling");
|
|
|
|
|
negotiated |= VIRTIO_GPU_F_VIRGL;
|
|
|
|
|
m_has_virgl_support = true;
|
|
|
|
|
}
|
2021-09-21 04:08:28 -03:00
|
|
|
if (is_feature_set(supported_features, VIRTIO_GPU_F_EDID))
|
2022-01-01 02:02:55 -03:00
|
|
|
negotiated |= VIRTIO_GPU_F_EDID;
|
2021-09-21 04:08:28 -03:00
|
|
|
return negotiated;
|
|
|
|
|
});
|
|
|
|
|
if (success) {
|
|
|
|
|
read_config_atomic([&]() {
|
|
|
|
|
m_num_scanouts = config_read32(*config, DEVICE_NUM_SCANOUTS);
|
|
|
|
|
});
|
|
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: num_scanouts: {}", m_num_scanouts);
|
|
|
|
|
success = setup_queues(2); // CONTROLQ + CURSORQ
|
|
|
|
|
}
|
|
|
|
|
VERIFY(success);
|
|
|
|
|
finish_init();
|
|
|
|
|
} else {
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ResourceID VirtIOGraphicsAdapter::allocate_resource_id(Badge<VirtIODisplayConnector>)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
return m_resource_id_counter++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Graphics::VirtIOGPU::ContextID VirtIOGraphicsAdapter::allocate_context_id(Badge<VirtIODisplayConnector>)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: This should really be tracked using a bitmap, instead of an atomic counter
|
|
|
|
|
return m_context_id_counter++;
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
bool VirtIOGraphicsAdapter::handle_device_config_change()
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
auto events = get_pending_events();
|
|
|
|
|
if (events & VIRTIO_GPU_EVENT_DISPLAY) {
|
|
|
|
|
// The host window was resized, in SerenityOS we completely ignore this event
|
|
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Ignoring virtio gpu display resize event");
|
|
|
|
|
clear_pending_events(VIRTIO_GPU_EVENT_DISPLAY);
|
|
|
|
|
}
|
|
|
|
|
if (events & ~VIRTIO_GPU_EVENT_DISPLAY) {
|
|
|
|
|
dbgln("VirtIO::GraphicsAdapter: Got unknown device config change event: {:#x}", events);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::handle_queue_update(u16 queue_index)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Handle queue update");
|
|
|
|
|
VERIFY(queue_index == CONTROLQ);
|
|
|
|
|
|
|
|
|
|
auto& queue = get_queue(CONTROLQ);
|
|
|
|
|
SpinlockLocker queue_lock(queue.lock());
|
|
|
|
|
queue.discard_used_buffers();
|
|
|
|
|
m_outstanding_request.wake_all();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
u32 VirtIOGraphicsAdapter::get_pending_events()
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
return config_read32(*m_device_configuration, DEVICE_EVENTS_READ);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::clear_pending_events(u32 event_bitmask)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
config_write32(*m_device_configuration, DEVICE_EVENTS_CLEAR, event_bitmask);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
ErrorOr<void> VirtIOGraphicsAdapter::query_and_set_edid(u32 scanout_id, VirtIODisplayConnector& display_connector)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
SpinlockLocker locker(m_operation_lock);
|
2022-01-01 02:02:55 -03:00
|
|
|
if (!is_feature_accepted(VIRTIO_GPU_F_EDID))
|
2022-04-30 07:56:29 -03:00
|
|
|
return Error::from_errno(ENOTSUP);
|
2022-01-01 02:02:55 -03:00
|
|
|
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::GetEDID>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::GetEDIDResponse>();
|
2022-01-01 02:02:55 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_GET_EDID, 0);
|
2022-01-01 02:02:55 -03:00
|
|
|
|
|
|
|
|
request.scanout_id = scanout_id;
|
|
|
|
|
request.padding = 0;
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
if (response.header.type != to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_EDID))
|
2022-01-01 02:02:55 -03:00
|
|
|
return Error::from_string_literal("VirtIO::GraphicsAdapter: Failed to get EDID");
|
|
|
|
|
|
|
|
|
|
if (response.size == 0)
|
|
|
|
|
return Error::from_string_literal("VirtIO::GraphicsAdapter: Failed to get EDID, empty buffer");
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Array<u8, 128> raw_edid;
|
|
|
|
|
memcpy(raw_edid.data(), response.edid, min(sizeof(raw_edid), response.size));
|
|
|
|
|
display_connector.set_edid_bytes({}, raw_edid);
|
|
|
|
|
return {};
|
2022-01-01 02:02:55 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ResourceID VirtIOGraphicsAdapter::create_2d_resource(Graphics::VirtIOGPU::Protocol::Rect rect)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceCreate2D>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_CREATE_2D, 0);
|
2021-09-21 04:08:28 -03:00
|
|
|
|
|
|
|
|
auto resource_id = allocate_resource_id();
|
|
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
request.width = rect.width;
|
|
|
|
|
request.height = rect.height;
|
2022-04-30 07:56:29 -03:00
|
|
|
request.format = to_underlying(Graphics::VirtIOGPU::Protocol::TextureFormat::VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM);
|
2021-09-21 04:08:28 -03:00
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Allocated 2d resource with id {}", resource_id.value());
|
|
|
|
|
return resource_id;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ResourceID VirtIOGraphicsAdapter::create_3d_resource(Graphics::VirtIOGPU::Protocol::Resource3DSpecification const& resource_3d_specification)
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceCreate3D>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2022-02-13 02:45:30 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_CREATE_3D, 0);
|
2022-02-13 02:45:30 -03:00
|
|
|
|
|
|
|
|
auto resource_id = allocate_resource_id();
|
|
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
// TODO: Abstract this out a bit more
|
|
|
|
|
u32* start_of_copied_fields = &request.target;
|
2022-03-14 00:07:31 -03:00
|
|
|
|
|
|
|
|
// Validate that the sub copy from the resource_3d_specification to the offset of the request fits.
|
2022-04-30 07:56:29 -03:00
|
|
|
static_assert((sizeof(request) - offsetof(Graphics::VirtIOGPU::Protocol::ResourceCreate3D, target) == sizeof(resource_3d_specification)));
|
2022-03-14 00:07:31 -03:00
|
|
|
memcpy(start_of_copied_fields, &resource_3d_specification, sizeof(resource_3d_specification));
|
2022-02-13 02:45:30 -03:00
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == static_cast<u32>(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2022-02-13 02:45:30 -03:00
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Allocated 3d resource with id {}", resource_id.value());
|
|
|
|
|
return resource_id;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::ensure_backing_storage(Graphics::VirtIOGPU::ResourceID resource_id, Memory::Region const& region, size_t buffer_offset, size_t buffer_length)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
|
|
|
|
|
VERIFY(buffer_offset % PAGE_SIZE == 0);
|
|
|
|
|
VERIFY(buffer_length % PAGE_SIZE == 0);
|
|
|
|
|
auto first_page_index = buffer_offset / PAGE_SIZE;
|
|
|
|
|
size_t num_mem_regions = buffer_length / PAGE_SIZE;
|
|
|
|
|
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceAttachBacking>();
|
|
|
|
|
const size_t header_block_size = sizeof(request) + num_mem_regions * sizeof(Graphics::VirtIOGPU::Protocol::MemoryEntry);
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING, 0);
|
2021-09-21 04:08:28 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
request.num_entries = num_mem_regions;
|
|
|
|
|
for (size_t i = 0; i < num_mem_regions; ++i) {
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& memory_entry = writer.append_structure<Graphics::VirtIOGPU::Protocol::MemoryEntry>();
|
2021-09-21 04:08:28 -03:00
|
|
|
memory_entry.address = region.physical_page(first_page_index + i)->paddr().get();
|
|
|
|
|
memory_entry.length = PAGE_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), header_block_size, sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Allocated backing storage");
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::detach_backing_storage(Graphics::VirtIOGPU::ResourceID resource_id)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceDetachBacking>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING, 0);
|
2021-09-21 04:08:28 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Detached backing storage");
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::set_scanout_resource(Graphics::VirtIOGPU::ScanoutID scanout, Graphics::VirtIOGPU::ResourceID resource_id, Graphics::VirtIOGPU::Protocol::Rect rect)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
2022-01-01 02:02:55 -03:00
|
|
|
{
|
|
|
|
|
// We need to scope the request/response here so that we can query display information later on
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::SetScanOut>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_SET_SCANOUT, 0);
|
2022-01-01 02:02:55 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
request.scanout_id = scanout.value();
|
|
|
|
|
request.rect = rect;
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-01-01 02:02:55 -03:00
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2022-01-01 02:02:55 -03:00
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Set backing scanout");
|
|
|
|
|
}
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::transfer_framebuffer_data_to_host(Graphics::VirtIOGPU::ScanoutID scanout, Graphics::VirtIOGPU::ResourceID resource_id, Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::TransferToHost2D>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D, 0);
|
|
|
|
|
request.offset = (dirty_rect.x + (dirty_rect.y * m_scanouts[scanout.value()].display_connector->display_information({}).rect.width)) * sizeof(u32);
|
2021-09-21 04:08:28 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
request.rect = dirty_rect;
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::flush_displayed_image(Graphics::VirtIOGPU::ResourceID resource_id, Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceFlush>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_FLUSH, 0);
|
2021-09-21 04:08:28 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
request.rect = dirty_rect;
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::synchronous_virtio_gpu_command(PhysicalAddress buffer_start, size_t request_size, size_t response_size)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
VERIFY(m_outstanding_request.is_empty());
|
|
|
|
|
auto& queue = get_queue(CONTROLQ);
|
|
|
|
|
{
|
|
|
|
|
SpinlockLocker lock(queue.lock());
|
|
|
|
|
VirtIO::QueueChain chain { queue };
|
|
|
|
|
chain.add_buffer_to_chain(buffer_start, request_size, VirtIO::BufferType::DeviceReadable);
|
|
|
|
|
chain.add_buffer_to_chain(buffer_start.offset(request_size), response_size, VirtIO::BufferType::DeviceWritable);
|
|
|
|
|
supply_chain_and_notify(CONTROLQ, chain);
|
|
|
|
|
full_memory_barrier();
|
|
|
|
|
}
|
|
|
|
|
m_outstanding_request.wait_forever();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::populate_virtio_gpu_request_header(Graphics::VirtIOGPU::Protocol::ControlHeader& header, Graphics::VirtIOGPU::Protocol::CommandType ctrl_type, u32 flags)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-03-05 21:31:40 -03:00
|
|
|
header.type = to_underlying(ctrl_type);
|
2021-09-21 04:08:28 -03:00
|
|
|
header.flags = flags;
|
|
|
|
|
header.fence_id = 0;
|
|
|
|
|
header.context_id = 0;
|
|
|
|
|
header.padding = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::flush_dirty_rectangle(Graphics::VirtIOGPU::ScanoutID scanout_id, Graphics::VirtIOGPU::ResourceID resource_id, Graphics::VirtIOGPU::Protocol::Rect const& dirty_rect)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(m_operation_lock.is_locked());
|
2021-09-21 04:56:32 -03:00
|
|
|
transfer_framebuffer_data_to_host(scanout_id, resource_id, dirty_rect);
|
|
|
|
|
flush_displayed_image(resource_id, dirty_rect);
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ResourceID VirtIOGraphicsAdapter::allocate_resource_id()
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
2022-04-30 07:56:29 -03:00
|
|
|
return m_resource_id_counter++;
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ContextID VirtIOGraphicsAdapter::allocate_context_id()
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
// FIXME: This should really be tracked using a bitmap, instead of an atomic counter
|
2022-04-30 07:56:29 -03:00
|
|
|
return m_context_id_counter++;
|
2022-02-13 02:45:30 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::delete_resource(Graphics::VirtIOGPU::ResourceID resource_id)
|
2021-09-21 04:08:28 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ResourceUnref>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2021-09-21 04:08:28 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_RESOURCE_UNREF, 0);
|
2021-09-21 04:08:28 -03:00
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2021-09-21 04:08:28 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::initialize_3d_device()
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
if (m_has_virgl_support) {
|
2022-04-30 07:56:29 -03:00
|
|
|
SpinlockLocker locker(m_operation_lock);
|
|
|
|
|
m_3d_device = VirtIOGPU3DDevice::must_create(*this);
|
2022-02-13 02:45:30 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
Graphics::VirtIOGPU::ContextID VirtIOGraphicsAdapter::create_context()
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto ctx_id = allocate_context_id();
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ContextCreate>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2022-02-13 02:45:30 -03:00
|
|
|
|
|
|
|
|
constexpr char const* region_name = "Serenity VirGL3D Context";
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_CTX_CREATE, 0);
|
2022-02-13 02:45:30 -03:00
|
|
|
request.header.context_id = ctx_id.value();
|
|
|
|
|
request.name_length = strlen(region_name);
|
|
|
|
|
memset(request.debug_name.data(), 0, 64);
|
|
|
|
|
VERIFY(request.name_length <= 64);
|
|
|
|
|
memcpy(request.debug_name.data(), region_name, request.name_length);
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2022-02-13 02:45:30 -03:00
|
|
|
return ctx_id;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::submit_command_buffer(Graphics::VirtIOGPU::ContextID context_id, Function<size_t(Bytes)> buffer_writer)
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::CommandSubmit>();
|
2022-02-13 02:45:30 -03:00
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_SUBMIT_3D, 0);
|
2022-02-13 02:45:30 -03:00
|
|
|
request.header.context_id = context_id.value();
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
auto max_command_buffer_length = m_scratch_space->size() - sizeof(request) - sizeof(Graphics::VirtIOGPU::Protocol::ControlHeader);
|
2022-02-13 02:45:30 -03:00
|
|
|
// Truncate to nearest multiple of alignment, to ensure padding loop doesn't exhaust allocated space
|
2022-04-30 07:56:29 -03:00
|
|
|
max_command_buffer_length -= max_command_buffer_length % alignof(Graphics::VirtIOGPU::Protocol::ControlHeader);
|
2022-02-13 02:45:30 -03:00
|
|
|
Bytes command_buffer_buffer(m_scratch_space->vaddr().offset(sizeof(request)).as_ptr(), max_command_buffer_length);
|
|
|
|
|
request.size = buffer_writer(command_buffer_buffer);
|
|
|
|
|
writer.skip_bytes(request.size);
|
|
|
|
|
// The alignment of a ControlHeader may be a few words larger than the length of a command buffer, so
|
|
|
|
|
// we pad with no-ops until we reach the correct alignment
|
2022-04-30 07:56:29 -03:00
|
|
|
while (writer.current_offset() % alignof(Graphics::VirtIOGPU::Protocol::ControlHeader) != 0) {
|
|
|
|
|
VERIFY((writer.current_offset() % alignof(Graphics::VirtIOGPU::Protocol::ControlHeader)) % sizeof(u32) == 0);
|
|
|
|
|
writer.append_structure<u32>() = to_underlying(Graphics::VirtIOGPU::VirGLCommand::NOP);
|
2022-02-13 02:45:30 -03:00
|
|
|
request.size += 4;
|
|
|
|
|
}
|
|
|
|
|
dbgln_if(VIRTIO_DEBUG, "VirtIO::GraphicsAdapter: Sending command buffer of length {}", request.size);
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
2022-02-13 02:45:30 -03:00
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request) + request.size, sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2022-02-13 02:45:30 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
void VirtIOGraphicsAdapter::attach_resource_to_context(Graphics::VirtIOGPU::ResourceID resource_id, Graphics::VirtIOGPU::ContextID context_id)
|
2022-02-13 02:45:30 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(m_operation_lock.is_locked());
|
|
|
|
|
auto writer = create_scratchspace_writer();
|
2022-04-30 07:56:29 -03:00
|
|
|
auto& request = writer.append_structure<Graphics::VirtIOGPU::Protocol::ContextAttachResource>();
|
|
|
|
|
auto& response = writer.append_structure<Graphics::VirtIOGPU::Protocol::ControlHeader>();
|
|
|
|
|
populate_virtio_gpu_request_header(request.header, Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, 0);
|
2022-02-13 02:45:30 -03:00
|
|
|
request.header.context_id = context_id.value();
|
|
|
|
|
request.resource_id = resource_id.value();
|
|
|
|
|
|
|
|
|
|
synchronous_virtio_gpu_command(start_of_scratch_space(), sizeof(request), sizeof(response));
|
|
|
|
|
|
2022-04-30 07:56:29 -03:00
|
|
|
VERIFY(response.type == to_underlying(Graphics::VirtIOGPU::Protocol::CommandType::VIRTIO_GPU_RESP_OK_NODATA));
|
2022-02-13 02:45:30 -03:00
|
|
|
}
|
|
|
|
|
|
2021-06-12 10:07:44 -03:00
|
|
|
}
|