mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-11 11:51:46 +00:00
platform_drv: don't restrict ownership to session
This is a prerequisite for letting the platform driver acquire control devices. genodelabs/genode#4761
This commit is contained in:
parent
3520492f09
commit
f98466430f
@ -15,12 +15,12 @@
|
|||||||
|
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <pci.h>
|
#include <pci.h>
|
||||||
|
#include <device_owner.h>
|
||||||
#include <device_component.h>
|
#include <device_component.h>
|
||||||
#include <session_component.h>
|
|
||||||
|
|
||||||
|
|
||||||
Driver::Device::Owner::Owner(Session_component & session)
|
Driver::Device::Owner::Owner(Device_owner & owner)
|
||||||
: obj_id(reinterpret_cast<void*>(&session)) {}
|
: obj_id(reinterpret_cast<void*>(&owner)) {}
|
||||||
|
|
||||||
|
|
||||||
Driver::Device::Name Driver::Device::name() const { return _name; }
|
Driver::Device::Name Driver::Device::name() const { return _name; }
|
||||||
@ -32,9 +32,9 @@ Driver::Device::Type Driver::Device::type() const { return _type; }
|
|||||||
Driver::Device::Owner Driver::Device::owner() const { return _owner; }
|
Driver::Device::Owner Driver::Device::owner() const { return _owner; }
|
||||||
|
|
||||||
|
|
||||||
void Driver::Device::acquire(Session_component & sc)
|
void Driver::Device::acquire(Device_owner & owner)
|
||||||
{
|
{
|
||||||
if (!_owner.valid()) _owner = sc;
|
if (!_owner.valid()) _owner = owner;
|
||||||
|
|
||||||
_power_domain_list.for_each([&] (Power_domain & p) {
|
_power_domain_list.for_each([&] (Power_domain & p) {
|
||||||
|
|
||||||
@ -81,19 +81,20 @@ void Driver::Device::acquire(Session_component & sc)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pci_enable(_env, sc.device_pd(), *this);
|
owner.enable_device(*this);
|
||||||
sc.update_devices_rom();
|
owner.update_devices_rom();
|
||||||
|
|
||||||
_model.device_status_changed();
|
_model.device_status_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Driver::Device::release(Session_component & sc)
|
void Driver::Device::release(Device_owner & owner)
|
||||||
{
|
{
|
||||||
if (!(_owner == sc))
|
if (!(_owner == owner))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_leave_operational) {
|
if (!_leave_operational) {
|
||||||
pci_disable(_env, *this);
|
owner.disable_device(*this);
|
||||||
|
|
||||||
_reset_domain_list.for_each([&] (Reset_domain & r)
|
_reset_domain_list.for_each([&] (Reset_domain & r)
|
||||||
{
|
{
|
||||||
@ -115,7 +116,7 @@ void Driver::Device::release(Session_component & sc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_owner = Owner();
|
_owner = Owner();
|
||||||
sc.update_devices_rom();
|
owner.update_devices_rom();
|
||||||
_model.device_status_changed();
|
_model.device_status_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <clock.h>
|
#include <clock.h>
|
||||||
#include <reset.h>
|
#include <reset.h>
|
||||||
#include <power.h>
|
#include <power.h>
|
||||||
|
#include <device_owner.h>
|
||||||
|
|
||||||
namespace Driver {
|
namespace Driver {
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ namespace Driver {
|
|||||||
class Device;
|
class Device;
|
||||||
struct Device_reporter;
|
struct Device_reporter;
|
||||||
struct Device_model;
|
struct Device_model;
|
||||||
class Session_component;
|
struct Device_owner;
|
||||||
struct Irq_update_policy;
|
struct Irq_update_policy;
|
||||||
struct Io_mem_update_policy;
|
struct Io_mem_update_policy;
|
||||||
struct Io_port_update_policy;
|
struct Io_port_update_policy;
|
||||||
@ -70,7 +71,7 @@ class Driver::Device : private List_model<Device>::Element
|
|||||||
void * obj_id;
|
void * obj_id;
|
||||||
|
|
||||||
Owner() : obj_id(nullptr) {}
|
Owner() : obj_id(nullptr) {}
|
||||||
Owner(Session_component & session);
|
Owner(Device_owner & owner);
|
||||||
|
|
||||||
bool operator == (Owner const & o) const {
|
bool operator == (Owner const & o) const {
|
||||||
return obj_id == o.obj_id; }
|
return obj_id == o.obj_id; }
|
||||||
@ -218,8 +219,8 @@ class Driver::Device : private List_model<Device>::Element
|
|||||||
Type type() const;
|
Type type() const;
|
||||||
Owner owner() const;
|
Owner owner() const;
|
||||||
|
|
||||||
virtual void acquire(Session_component &);
|
virtual void acquire(Device_owner &);
|
||||||
virtual void release(Session_component &);
|
virtual void release(Device_owner &);
|
||||||
|
|
||||||
template <typename FN> void for_each_irq(FN const & fn) const
|
template <typename FN> void for_each_irq(FN const & fn) const
|
||||||
{
|
{
|
||||||
|
32
repos/os/src/drivers/platform/device_owner.h
Normal file
32
repos/os/src/drivers/platform/device_owner.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* \brief Platform driver - Device owner abstraction
|
||||||
|
* \author Johannes Schlatow
|
||||||
|
* \date 2023-01-20
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SRC__DRIVERS__PLATFORM__DEVICE_OWNER_H_
|
||||||
|
#define _SRC__DRIVERS__PLATFORM__DEVICE_OWNER_H_
|
||||||
|
|
||||||
|
namespace Driver
|
||||||
|
{
|
||||||
|
struct Device;
|
||||||
|
struct Device_owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Driver::Device_owner
|
||||||
|
{
|
||||||
|
virtual void enable_device(Device const &) {};
|
||||||
|
virtual void disable_device(Device const &) {};
|
||||||
|
virtual void update_devices_rom() {};
|
||||||
|
virtual ~Device_owner() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _SRC__DRIVERS__PLATFORM__DEVICE_OWNER_H_ */
|
@ -125,6 +125,18 @@ void Session_component::update_devices_rom()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Session_component::enable_device(Device const & device)
|
||||||
|
{
|
||||||
|
pci_enable(_env, device_pd(), device);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Session_component::disable_device(Device const & device)
|
||||||
|
{
|
||||||
|
pci_disable(_env, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Genode::Rom_session_capability Session_component::devices_rom() {
|
Genode::Rom_session_capability Session_component::devices_rom() {
|
||||||
return _rom_session.cap(); }
|
return _rom_session.cap(); }
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <device_component.h>
|
#include <device_component.h>
|
||||||
#include <device_pd.h>
|
#include <device_pd.h>
|
||||||
|
#include <device_owner.h>
|
||||||
|
|
||||||
namespace Driver {
|
namespace Driver {
|
||||||
class Session_component;
|
class Session_component;
|
||||||
@ -36,6 +37,7 @@ namespace Driver {
|
|||||||
class Driver::Session_component
|
class Driver::Session_component
|
||||||
:
|
:
|
||||||
public Session_object<Platform::Session>,
|
public Session_object<Platform::Session>,
|
||||||
|
public Device_owner,
|
||||||
private Registry<Driver::Session_component>::Element,
|
private Registry<Driver::Session_component>::Element,
|
||||||
private Dynamic_rom_session::Xml_producer
|
private Dynamic_rom_session::Xml_producer
|
||||||
{
|
{
|
||||||
@ -61,13 +63,19 @@ class Driver::Session_component
|
|||||||
Device_pd & device_pd();
|
Device_pd & device_pd();
|
||||||
|
|
||||||
bool matches(Device const &) const;
|
bool matches(Device const &) const;
|
||||||
void update_devices_rom();
|
|
||||||
|
|
||||||
Ram_quota_guard & ram_quota_guard() { return _ram_quota_guard(); }
|
Ram_quota_guard & ram_quota_guard() { return _ram_quota_guard(); }
|
||||||
Cap_quota_guard & cap_quota_guard() { return _cap_quota_guard(); }
|
Cap_quota_guard & cap_quota_guard() { return _cap_quota_guard(); }
|
||||||
|
|
||||||
void update_policy(bool info, Policy_version version);
|
void update_policy(bool info, Policy_version version);
|
||||||
|
|
||||||
|
/**************************
|
||||||
|
** Device Owner methods **
|
||||||
|
**************************/
|
||||||
|
|
||||||
|
void enable_device(Device const &) override;
|
||||||
|
void disable_device(Device const &) override;
|
||||||
|
void update_devices_rom() override;
|
||||||
|
|
||||||
/**************************
|
/**************************
|
||||||
** Platform Session API **
|
** Platform Session API **
|
||||||
|
Loading…
x
Reference in New Issue
Block a user