Skip to content

Commit

Permalink
Merge pull request managarm#621 from no92/576
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 authored Feb 17, 2024
2 parents fbe44a9 + 52511fd commit 91224a7
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion core/drm/include/core/drm/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct Configuration {

virtual bool capture(std::vector<Assignment> assignment, std::unique_ptr<AtomicState> &state) = 0;
virtual void dispose() = 0;
virtual void commit(std::unique_ptr<AtomicState> &state) = 0;
virtual void commit(std::unique_ptr<AtomicState> state) = 0;

auto waitForCompletion() {
return _ev.wait();
Expand Down
10 changes: 5 additions & 5 deletions core/drm/src/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ drm_core::File::ioctl(void *object, uint32_t id, helix_ng::RecvInlineResult msg,
auto state = self->_device->atomicState();
auto valid = config->capture(assignments, state);
assert(valid);
config->commit(state);
config->commit(std::move(state));

co_await config->waitForCompletion();

Expand Down Expand Up @@ -530,7 +530,7 @@ drm_core::File::ioctl(void *object, uint32_t id, helix_ng::RecvInlineResult msg,
auto state = self->_device->atomicState();
auto valid = config->capture(assignments, state);
assert(valid);
config->commit(state);
config->commit(std::move(state));

co_await config->waitForCompletion();
self->_retirePageFlip(req->drm_cookie(), crtc->id());
Expand Down Expand Up @@ -621,7 +621,7 @@ drm_core::File::ioctl(void *object, uint32_t id, helix_ng::RecvInlineResult msg,
auto state = self->_device->atomicState();
auto valid = config->capture(assignments, state);
assert(valid);
config->commit(state);
config->commit(std::move(state));

co_await config->waitForCompletion();

Expand Down Expand Up @@ -819,7 +819,7 @@ drm_core::File::ioctl(void *object, uint32_t id, helix_ng::RecvInlineResult msg,
auto valid = config->capture(assignments, state);
assert(valid);

config->commit(state);
config->commit(std::move(state));
co_await config->waitForCompletion();

resp.set_error(managarm::fs::Errors::SUCCESS);
Expand Down Expand Up @@ -1014,7 +1014,7 @@ drm_core::File::ioctl(void *object, uint32_t id, helix_ng::RecvInlineResult msg,
if(!(req->drm_flags() & DRM_MODE_ATOMIC_TEST_ONLY)) {
if(logDrmRequests)
std::cout << "\tCommitting configuration ..." << std::endl;
config->commit(state);
config->commit(std::move(state));
co_await config->waitForCompletion();
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/gfx/bochs/src/bochs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic

bool capture(std::vector<drm_core::Assignment> assignment, std::unique_ptr<drm_core::AtomicState> &state) override;
void dispose() override;
void commit(std::unique_ptr<drm_core::AtomicState> &state) override;
void commit(std::unique_ptr<drm_core::AtomicState> state) override;

private:
async::detached _doCommit(std::unique_ptr<drm_core::AtomicState> &state);
async::detached _doCommit(std::unique_ptr<drm_core::AtomicState> state);

GfxDevice *_device;
};
Expand Down Expand Up @@ -90,7 +90,7 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic
GfxDevice(protocols::hw::Device hw_device,
helix::UniqueDescriptor video_ram, void* frame_buffer);

async::detached initialize();
async::result<std::unique_ptr<drm_core::Configuration>> initialize();
std::unique_ptr<drm_core::Configuration> createConfiguration() override;
std::pair<std::shared_ptr<drm_core::BufferObject>, uint32_t> createDumb(uint32_t width,
uint32_t height, uint32_t bpp) override;
Expand Down
18 changes: 9 additions & 9 deletions drivers/gfx/bochs/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GfxDevice::GfxDevice(protocols::hw::Device hw_device,
_operational = arch::global_io;
}

async::detached GfxDevice::initialize() {
async::result<std::unique_ptr<drm_core::Configuration>> GfxDevice::initialize() {
std::vector<drm_core::Assignment> assignments;

_operational.store(regs::index, (uint16_t)RegisterIndex::id);
Expand Down Expand Up @@ -120,10 +120,9 @@ async::detached GfxDevice::initialize() {
auto config = createConfiguration();
auto state = atomicState();
assert(config->capture(assignments, state));
config->commit(state);
co_await config->waitForCompletion();
config->commit(std::move(state));

co_return;
co_return std::move(config);
}

std::unique_ptr<drm_core::Configuration> GfxDevice::createConfiguration() {
Expand Down Expand Up @@ -240,15 +239,15 @@ void GfxDevice::Configuration::dispose() {

}

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> &state) {
_doCommit(state);

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> state) {
_device->_theCrtc->setDrmState(state->crtc(_device->_theCrtc->id()));
_device->_theConnector->setDrmState(state->connector(_device->_theConnector->id()));
_device->_primaryPlane->setDrmState(state->plane(_device->_primaryPlane->id()));

_doCommit(std::move(state));
}

async::detached GfxDevice::Configuration::_doCommit(std::unique_ptr<drm_core::AtomicState> &state) {
async::detached GfxDevice::Configuration::_doCommit(std::unique_ptr<drm_core::AtomicState> state) {
if(logCommits)
std::cout << "gfx-bochs: Committing configuration" << std::endl;

Expand Down Expand Up @@ -433,7 +432,7 @@ async::detached bindController(mbus::Entity entity) {

auto gfx_device = std::make_shared<GfxDevice>(std::move(pci_device),
std::move(bar), actual_pointer);
gfx_device->initialize();
auto config = co_await gfx_device->initialize();

// Create an mbus object for the device.
auto root = co_await mbus::Instance::global().getRoot();
Expand All @@ -453,6 +452,7 @@ async::detached bindController(mbus::Entity entity) {
co_return std::move(remote_lane);
});

co_await config->waitForCompletion();
co_await root.createObject("gfx_bochs", descriptor, std::move(handler));
}

Expand Down
18 changes: 10 additions & 8 deletions drivers/gfx/plainfb/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ GfxDevice::GfxDevice(protocols::hw::Device hw_device,
}
}

async::detached GfxDevice::initialize() {
async::result<std::unique_ptr<drm_core::Configuration>> GfxDevice::initialize() {
// Setup planes, encoders and CRTCs (i.e. the static entities).
_plane = std::make_shared<Plane>(this, Plane::PlaneType::PRIMARY);
_theCrtc = std::make_shared<Crtc>(this);
Expand Down Expand Up @@ -117,8 +117,9 @@ async::detached GfxDevice::initialize() {
auto config = createConfiguration();
auto state = atomicState();
assert(config->capture(assignments, state));
config->commit(state);
co_await config->waitForCompletion();
config->commit(std::move(state));

co_return config;
}

std::unique_ptr<drm_core::Configuration> GfxDevice::createConfiguration() {
Expand Down Expand Up @@ -197,15 +198,15 @@ void GfxDevice::Configuration::dispose() {

}

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> &state) {
_dispatch(state);

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> state) {
_device->_theCrtc->setDrmState(state->crtc(_device->_theCrtc->id()));
_device->_theConnector->setDrmState(state->connector(_device->_theConnector->id()));
_device->_plane->setDrmState(state->plane(_device->_plane->id()));

_dispatch(std::move(state));
}

async::detached GfxDevice::Configuration::_dispatch(std::unique_ptr<drm_core::AtomicState> &state) {
async::detached GfxDevice::Configuration::_dispatch(std::unique_ptr<drm_core::AtomicState> state) {
auto crtc_state = state->crtc(_device->_theCrtc->id());

if(crtc_state->mode != nullptr) {
Expand Down Expand Up @@ -366,7 +367,7 @@ async::detached bindController(mbus::Entity entity) {
auto gfx_device = std::make_shared<GfxDevice>(std::move(hw_device),
info.width, info.height, info.pitch,
helix::Mapping{fb_memory, 0, info.pitch * info.height});
gfx_device->initialize();
auto config = co_await gfx_device->initialize();

// Create an mbus object for the device.
auto root = co_await mbus::Instance::global().getRoot();
Expand All @@ -386,6 +387,7 @@ async::detached bindController(mbus::Entity entity) {
co_return std::move(remote_lane);
});

co_await config->waitForCompletion();
co_await root.createObject("gfx_plainfb", descriptor, std::move(handler));
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/gfx/plainfb/src/plainfb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic

bool capture(std::vector<drm_core::Assignment> assignment, std::unique_ptr<drm_core::AtomicState> &state) override;
void dispose() override;
void commit(std::unique_ptr<drm_core::AtomicState> &state) override;
void commit(std::unique_ptr<drm_core::AtomicState> state) override;

private:
async::detached _dispatch(std::unique_ptr<drm_core::AtomicState> &state);
async::detached _dispatch(std::unique_ptr<drm_core::AtomicState> state);

GfxDevice *_device;
};
Expand Down Expand Up @@ -91,7 +91,7 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic
unsigned int screen_width, unsigned int screen_height,
size_t screen_pitch, helix::Mapping fb_mapping);

async::detached initialize();
async::result<std::unique_ptr<drm_core::Configuration>> initialize();
std::unique_ptr<drm_core::Configuration> createConfiguration() override;
std::pair<std::shared_ptr<drm_core::BufferObject>, uint32_t> createDumb(uint32_t width,
uint32_t height, uint32_t bpp) override;
Expand Down
18 changes: 10 additions & 8 deletions drivers/gfx/virtio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct AwaitableRequest : virtio_core::Request {
GfxDevice::GfxDevice(std::unique_ptr<virtio_core::Transport> transport)
: _transport{std::move(transport)}, _claimedDevice{false} { }

async::detached GfxDevice::initialize() {
async::result<std::unique_ptr<drm_core::Configuration>> GfxDevice::initialize() {
if(_transport->checkDeviceFeature(VIRTIO_GPU_F_VIRGL)) {
_transport->acknowledgeDriverFeature(VIRTIO_GPU_F_VIRGL);
_virgl3D = true;
Expand Down Expand Up @@ -173,8 +173,9 @@ async::detached GfxDevice::initialize() {
auto config = createConfiguration();
auto state = atomicState();
assert(config->capture(assignments, state));
config->commit(state);
co_await config->waitForCompletion();
config->commit(std::move(state));

co_return config;
}

std::unique_ptr<drm_core::Configuration> GfxDevice::createConfiguration() {
Expand Down Expand Up @@ -257,9 +258,7 @@ void GfxDevice::Configuration::dispose() {

}

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> &state) {
_dispatch(state);

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> state) {
for(auto &[_, cs] : state->crtc_states()) {
cs->crtc().lock()->setDrmState(cs);
}
Expand All @@ -271,9 +270,11 @@ void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> &st
for(auto &[_, cs] : state->connector_states()) {
cs->connector->setDrmState(cs);
}

_dispatch(std::move(state));
}

async::detached GfxDevice::Configuration::_dispatch(std::unique_ptr<drm_core::AtomicState> &state) {
async::detached GfxDevice::Configuration::_dispatch(std::unique_ptr<drm_core::AtomicState> state) {
if(!_device->_claimedDevice) {
co_await _device->_transport->hwDevice().claimDevice();
_device->_claimedDevice = true;
Expand Down Expand Up @@ -455,7 +456,7 @@ async::result<void> doBind(mbus::Entity base_entity) {
virtio_core::DiscoverMode::modernOnly);

auto gfx_device = std::make_shared<GfxDevice>(std::move(transport));
gfx_device->initialize();
auto config = co_await gfx_device->initialize();

// Create an mbus object for the device.
auto root = co_await mbus::Instance::global().getRoot();
Expand All @@ -475,6 +476,7 @@ async::result<void> doBind(mbus::Entity base_entity) {
co_return std::move(remote_lane);
});

co_await config->waitForCompletion();
co_await root.createObject("gfx_virtio", descriptor, std::move(handler));
baseDeviceMap.insert({base_entity.getId(), gfx_device});
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/gfx/virtio/src/virtio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic

bool capture(std::vector<drm_core::Assignment> assignment, std::unique_ptr<drm_core::AtomicState> &state) override;
void dispose() override;
void commit(std::unique_ptr<drm_core::AtomicState> &state) override;
void commit(std::unique_ptr<drm_core::AtomicState> state) override;

private:
async::detached _dispatch(std::unique_ptr<drm_core::AtomicState> &state);
async::detached _dispatch(std::unique_ptr<drm_core::AtomicState> state);

GfxDevice *_device;
};
Expand Down Expand Up @@ -116,7 +116,7 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic

GfxDevice(std::unique_ptr<virtio_core::Transport> transport);

async::detached initialize();
async::result<std::unique_ptr<drm_core::Configuration>> initialize();
std::unique_ptr<drm_core::Configuration> createConfiguration() override;
std::pair<std::shared_ptr<drm_core::BufferObject>, uint32_t> createDumb(uint32_t width,
uint32_t height, uint32_t bpp) override;
Expand Down
19 changes: 11 additions & 8 deletions drivers/gfx/vmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GfxDevice::GfxDevice(protocols::hw::Device hw_dev,
_operational = arch::io_space{io_base};
}

async::detached GfxDevice::initialize() {
async::result<std::unique_ptr<drm_core::Configuration>> GfxDevice::initialize() {
auto pci_info = co_await _hwDev.getPciInfo();

// negotiate version
Expand Down Expand Up @@ -172,8 +172,9 @@ async::detached GfxDevice::initialize() {
auto state = atomicState();
auto valid = config->capture(assignments, state);
assert(valid);
config->commit(state);
co_await config->waitForCompletion();
config->commit(std::move(state));

co_return std::move(config);
}

std::shared_ptr<drm_core::FrameBuffer> GfxDevice::createFrameBuffer(std::shared_ptr<drm_core::BufferObject> base_bo,
Expand Down Expand Up @@ -556,15 +557,15 @@ void GfxDevice::Configuration::dispose() {

}

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> & state) {
commitConfiguration(state);

void GfxDevice::Configuration::commit(std::unique_ptr<drm_core::AtomicState> state) {
_device->_crtc->setDrmState(state->crtc(_device->_crtc->id()));
_device->_primaryPlane->setDrmState(state->plane(_device->_primaryPlane->id()));
_device->_cursorPlane->setDrmState(state->plane(_device->_cursorPlane->id()));

commitConfiguration(std::move(state));
}

async::detached GfxDevice::Configuration::commitConfiguration(std::unique_ptr<drm_core::AtomicState> & state) {
async::detached GfxDevice::Configuration::commitConfiguration(std::unique_ptr<drm_core::AtomicState> state) {
auto primary_plane_state = state->plane(_device->_primaryPlane->id());
auto cursor_plane_state = state->plane(_device->_cursorPlane->id());
auto crtc_state = state->crtc(_device->_crtc->id());
Expand Down Expand Up @@ -741,7 +742,7 @@ async::result<void> setupDevice(mbus::Entity entity) {
helix::Mapping{fifo_bar, 0, fifo_bar_info.length},
std::move(io_bar), io_bar_info.address);

gfx_device->initialize();
auto config = co_await gfx_device->initialize();

auto root = co_await mbus::Instance::global().getRoot();

Expand All @@ -759,6 +760,8 @@ async::result<void> setupDevice(mbus::Entity entity) {

co_return std::move(remote_lane);
});

co_await config->waitForCompletion();
co_await root.createObject("gfx_vmware", descriptor, std::move(handler));
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/gfx/vmware/src/vmware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic

bool capture(std::vector<drm_core::Assignment> assignment, std::unique_ptr<drm_core::AtomicState> & state) override;
void dispose() override;
void commit(std::unique_ptr<drm_core::AtomicState> & state) override;
void commit(std::unique_ptr<drm_core::AtomicState> state) override;

private:
async::detached commitConfiguration(std::unique_ptr<drm_core::AtomicState> & state);
async::detached commitConfiguration(std::unique_ptr<drm_core::AtomicState> state);

GfxDevice *_device;

Expand Down Expand Up @@ -116,7 +116,7 @@ struct GfxDevice final : drm_core::Device, std::enable_shared_from_this<GfxDevic
helix::Mapping fifo,
helix::UniqueDescriptor io_ports, uint16_t io_base);

async::detached initialize();
async::result<std::unique_ptr<drm_core::Configuration>> initialize();
std::unique_ptr<drm_core::Configuration> createConfiguration() override;
std::pair<std::shared_ptr<drm_core::BufferObject>, uint32_t> createDumb(uint32_t width,
uint32_t height, uint32_t bpp) override;
Expand Down

0 comments on commit 91224a7

Please sign in to comment.