diff --git a/repos/os/src/drivers/platform/device_component.cc b/repos/os/src/drivers/platform/device_component.cc index 94690cdca3..182e124fcf 100644 --- a/repos/os/src/drivers/platform/device_component.cc +++ b/repos/os/src/drivers/platform/device_component.cc @@ -245,17 +245,19 @@ Device_component::Device_component(Registry & registry, }); }; + auto default_domain_fn = [&] () { + session.domain_registry().with_default_domain(add_range_fn); }; + /* attach reserved memory ranges to IOMMU domains */ device.for_each_io_mmu( /* non-empty list fn */ [&] (Driver::Device::Io_mmu const &io_mmu) { session.domain_registry().with_domain(io_mmu.name, add_range_fn, - [&] () { }); }, + default_domain_fn); }, /* empty list fn */ - [&] () { - session.domain_registry().with_default_domain(add_range_fn); } + default_domain_fn ); } catch(...) { diff --git a/repos/os/src/drivers/platform/pci.cc b/repos/os/src/drivers/platform/pci.cc index 572cc4fdfb..738b500ce9 100644 --- a/repos/os/src/drivers/platform/pci.cc +++ b/repos/os/src/drivers/platform/pci.cc @@ -60,23 +60,8 @@ struct Config_helper Driver::Device::Pci_config const & cfg) : _env(env), _dev(dev), _cfg(cfg) { _config.scan(); } - void enable(Driver::Io_mmu_domain_registry & domain_registry) + void enable() { - auto enable_fn = [&] (Driver::Io_mmu::Domain & domain) { - domain.enable_pci_device(_io_mem.cap(), - { _cfg.bus_num, _cfg.dev_num, _cfg.func_num }); - }; - - _dev.for_each_io_mmu( - /* non-empty list fn */ - [&] (Driver::Device::Io_mmu const &io_mmu) { - domain_registry.with_domain(io_mmu.name, enable_fn, [&] () {}); }, - - /* empty list fn */ - [&] () { - domain_registry.with_default_domain(enable_fn); } - ); - _config.power_on(delayer(_env)); Config::Command::access_t cmd = @@ -107,7 +92,7 @@ struct Config_helper _config.write(cmd); } - void disable(Driver::Io_mmu_domain_registry & domain_registry) + void disable() { Config::Command::access_t cmd = _config.read(); @@ -118,21 +103,6 @@ struct Config_helper _config.write(cmd); _config.power_off(); - - auto disable_fn = [&] (Driver::Io_mmu::Domain & domain) { - domain.disable_pci_device(_io_mem.cap(), - { _cfg.bus_num, _cfg.dev_num, _cfg.func_num }); - }; - - _dev.for_each_io_mmu( - /* non-empty list fn */ - [&] (Driver::Device::Io_mmu const &io_mmu) { - domain_registry.with_domain(io_mmu.name, disable_fn, [&] () {}); }, - - /* empty list fn */ - [&] () { - domain_registry.with_default_domain(disable_fn); } - ); } void apply_quirks() @@ -165,20 +135,18 @@ struct Config_helper void Driver::pci_enable(Env & env, - Driver::Io_mmu_domain_registry & domain_registry, Device const & dev) { dev.for_pci_config([&] (Device::Pci_config const & pc) { - Config_helper(env, dev, pc).enable(domain_registry); }); + Config_helper(env, dev, pc).enable(); }); } void Driver::pci_disable(Env & env, - Driver::Io_mmu_domain_registry & domain_registry, Device const & dev) { dev.for_pci_config([&] (Device::Pci_config const & pc) { - Config_helper(env, dev, pc).disable(domain_registry); }); + Config_helper(env, dev, pc).disable(); }); } diff --git a/repos/os/src/drivers/platform/pci.h b/repos/os/src/drivers/platform/pci.h index 328804296f..b4395a8856 100644 --- a/repos/os/src/drivers/platform/pci.h +++ b/repos/os/src/drivers/platform/pci.h @@ -28,10 +28,8 @@ namespace Driver { class Device_pd; void pci_enable(Genode::Env & env, - Io_mmu_domain_registry & domain_registry, Device const & dev); void pci_disable(Genode::Env & env, - Io_mmu_domain_registry & domain_registry, Device const & dev); void pci_apply_quirks(Genode::Env & env, Device const & dev); void pci_msi_enable(Genode::Env & env, Device_component & dc, diff --git a/repos/os/src/drivers/platform/session_component.cc b/repos/os/src/drivers/platform/session_component.cc index 44be7d96fa..40cdd0accc 100644 --- a/repos/os/src/drivers/platform/session_component.cc +++ b/repos/os/src/drivers/platform/session_component.cc @@ -12,6 +12,7 @@ */ #include +#include #include #include @@ -231,40 +232,51 @@ void Session_component::update_devices_rom() void Session_component::enable_device(Device const & device) { - pci_enable(_env, domain_registry(), device); - auto fn = [&] (Driver::Io_mmu::Domain & domain) { + device.for_pci_config([&] (Device::Pci_config const & cfg) { + Attached_io_mem_dataspace io_mem { _env, cfg.addr, 0x1000 }; + domain.enable_pci_device(io_mem.cap(), + {cfg.bus_num, cfg.dev_num, cfg.func_num}); + }); domain.enable_device(); }; + auto default_domain_fn = [&] () { _domain_registry.with_default_domain(fn); }; + device.for_each_io_mmu( /* non-empty list fn */ [&] (Device::Io_mmu const & io_mmu) { - _domain_registry.with_domain(io_mmu.name, fn, [&] () { }); }, + _domain_registry.with_domain(io_mmu.name, fn, default_domain_fn); + }, /* empty list fn */ - [&] () { - _domain_registry.with_default_domain(fn); } + default_domain_fn ); + + pci_enable(_env, device); } void Session_component::disable_device(Device const & device) { - pci_disable(_env, domain_registry(), device); + pci_disable(_env, device); auto fn = [&] (Driver::Io_mmu::Domain & domain) { + device.for_pci_config([&] (Device::Pci_config const & cfg) { + domain.disable_pci_device({cfg.bus_num, cfg.dev_num, cfg.func_num}); + }); domain.disable_device(); }; + auto default_domain_fn = [&] () { _domain_registry.with_default_domain(fn); }; + device.for_each_io_mmu( /* non-empty list fn */ [&] (Device::Io_mmu const & io_mmu) { - _domain_registry.with_domain(io_mmu.name, fn, [&] () { }); }, + _domain_registry.with_domain(io_mmu.name, fn, default_domain_fn); }, /* empty list fn */ - [&] () { - _domain_registry.with_default_domain(fn); } + default_domain_fn ); }