From d52af2ac94fa2cf370fb64516da2810a21d2a88d Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 17 Apr 2024 11:52:16 +0200 Subject: [PATCH] os: avoid state names in system ROM for ahci/gpu/nvme. Instead conclude from empty and non empty system state to resume or stop driver. Issue #5180 --- repos/os/src/drivers/ahci/main.cc | 15 +++++++++++---- repos/os/src/drivers/gpu/intel/main.cc | 13 +++++++++++-- repos/os/src/drivers/nvme/main.cc | 12 ++++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/repos/os/src/drivers/ahci/main.cc b/repos/os/src/drivers/ahci/main.cc index 476726b3e1..ede3581e5a 100644 --- a/repos/os/src/drivers/ahci/main.cc +++ b/repos/os/src/drivers/ahci/main.cc @@ -129,7 +129,10 @@ class Ahci::Driver : Noncopyable auto state = _system_rom->xml().attribute_value("state", String<32>("")); - if (state == "driver_stop") { + bool const resume_driver = _schedule_stop && state == ""; + bool const stop_driver = !_schedule_stop && state != ""; + + if (stop_driver) { _schedule_stop = true; for_each_port([&](auto &port, auto, auto) { @@ -138,14 +141,16 @@ class Ahci::Driver : Noncopyable device_release_if_stopped_and_idle(); + log("driver halted"); + return; } - if (state == "driver_reinit") { - _resources.acquire_device(); - + if (resume_driver) { _schedule_stop = false; + _resources.acquire_device(); + /* re-start request handling of client sessions */ for_each_port([&](auto &port, auto const index, auto) { port.stop_processing = false; @@ -153,6 +158,8 @@ class Ahci::Driver : Noncopyable _dispatch.session(index); }); + log("driver resumed"); + return; } } diff --git a/repos/os/src/drivers/gpu/intel/main.cc b/repos/os/src/drivers/gpu/intel/main.cc index 50d035ffdd..171bac8e53 100644 --- a/repos/os/src/drivers/gpu/intel/main.cc +++ b/repos/os/src/drivers/gpu/intel/main.cc @@ -1204,13 +1204,19 @@ struct Igd::Device void handle_system_update(String<32> const & state) { - if (state == "driver_stop") { + bool const resume_driver = _schedule_stop && state == ""; + bool const stop_driver = !_schedule_stop && state != ""; + + if (stop_driver) { _schedule_stop = true; device_release_if_stopped_and_idle(); + + log("driver halted"); + return; } - if (state == "driver_reinit") { + if (resume_driver) { _resources.acquire_device(); _resources.with_mmio([&](auto &mmio) { @@ -1231,6 +1237,9 @@ struct Igd::Device } else warning("setup_ring_vram failed"); }); + + log("driver resumed"); + }, []() { error("reinit - failed"); }); diff --git a/repos/os/src/drivers/nvme/main.cc b/repos/os/src/drivers/nvme/main.cc index 76091f54b5..34f09ab654 100644 --- a/repos/os/src/drivers/nvme/main.cc +++ b/repos/os/src/drivers/nvme/main.cc @@ -1952,18 +1952,26 @@ class Nvme::Driver : Genode::Noncopyable auto state = _system_rom->xml().attribute_value("state", String<32>("")); - if (state == "driver_stop") { + bool const resume_driver = _stop_processing && state == ""; + bool const stop_driver = !_stop_processing && state != ""; + + if (stop_driver) { _stop_processing = true; device_release_if_stopped_and_idle(); + + log("driver halted"); + return; } - if (state == "driver_reinit") { + if (resume_driver) { _stop_processing = false; _nvme_ctrlr.construct(_env, _platform, _delayer, _irq_sigh); reinit(*_nvme_ctrlr); + log("driver resumed"); + /* restart block session handling */ Signal_transmitter(_restart_sigh).submit();