mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-20 03:36:33 +00:00
parent
231d92f88a
commit
8fb8cf1c8b
107
os/include/regulator/component.h
Normal file
107
os/include/regulator/component.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* \brief Regulator-session component
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR__COMPONENT_H_
|
||||
#define _INCLUDE__REGULATOR__COMPONENT_H_
|
||||
|
||||
#include <root/component.h>
|
||||
#include <regulator_session/rpc_object.h>
|
||||
#include <regulator/driver.h>
|
||||
|
||||
|
||||
namespace Regulator {
|
||||
class Session_component;
|
||||
class Root;
|
||||
}
|
||||
|
||||
|
||||
class Regulator::Session_component : public Regulator::Session_rpc_object
|
||||
{
|
||||
private:
|
||||
|
||||
Driver_factory &_driver_factory;
|
||||
Driver &_driver;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Session_component(Regulator_id regulator_id,
|
||||
Driver_factory &driver_factory)
|
||||
: Session_rpc_object(regulator_id),
|
||||
_driver_factory(driver_factory),
|
||||
_driver(_driver_factory.create(regulator_id)) { }
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Session_component() { _driver_factory.destroy(_driver); }
|
||||
|
||||
|
||||
/***********************************
|
||||
** Regulator session interface **
|
||||
***********************************/
|
||||
|
||||
void set_level(unsigned long level) { _driver.set_level(_id, level); }
|
||||
unsigned long level() { return _driver.level(_id); }
|
||||
void set_state(bool enable) { _driver.set_state(_id, enable); }
|
||||
bool state() { return _driver.state(_id); }
|
||||
};
|
||||
|
||||
|
||||
class Regulator::Root :
|
||||
public Genode::Root_component<Regulator::Session_component>
|
||||
{
|
||||
private:
|
||||
|
||||
Driver_factory &_driver_factory;
|
||||
Genode::Rpc_entrypoint &_ep;
|
||||
|
||||
protected:
|
||||
|
||||
Session_component *_create_session(const char *args)
|
||||
{
|
||||
using namespace Genode;
|
||||
|
||||
char reg_name[64];
|
||||
Arg_string::find_arg(args, "regulator").string(reg_name,
|
||||
sizeof(reg_name), 0);
|
||||
size_t ram_quota =
|
||||
Arg_string::find_arg(args, "ram_quota").ulong_value(0);
|
||||
|
||||
/* delete ram quota by the memory needed for the session */
|
||||
size_t session_size = max((size_t)4096,
|
||||
sizeof(Session_component));
|
||||
if (ram_quota < session_size)
|
||||
throw Root::Quota_exceeded();
|
||||
|
||||
if (!strlen(reg_name))
|
||||
throw Root::Invalid_args();
|
||||
|
||||
return new (md_alloc())
|
||||
Session_component(regulator_id_by_name(reg_name),
|
||||
_driver_factory);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Root(Genode::Rpc_entrypoint *session_ep,
|
||||
Genode::Allocator *md_alloc,
|
||||
Driver_factory &driver_factory)
|
||||
: Genode::Root_component<Regulator::Session_component>(session_ep,
|
||||
md_alloc),
|
||||
_driver_factory(driver_factory), _ep(*session_ep) { }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR__COMPONENT_H_ */
|
50
os/include/regulator/driver.h
Normal file
50
os/include/regulator/driver.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* \brief Regulator-driver interface
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR__DRIVER_H_
|
||||
#define _INCLUDE__REGULATOR__DRIVER_H_
|
||||
|
||||
#include <regulator/consts.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
/**
|
||||
* Interface to be implemented by the device-specific driver code
|
||||
*/
|
||||
struct Driver
|
||||
{
|
||||
virtual void set_level(Regulator_id id, unsigned long level) = 0;
|
||||
virtual unsigned long level(Regulator_id id) = 0;
|
||||
virtual void set_state(Regulator_id id, bool enable) = 0;
|
||||
virtual bool state(Regulator_id id) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Interface for constructing the driver object
|
||||
*/
|
||||
struct Driver_factory
|
||||
{
|
||||
/**
|
||||
* Construct new driver
|
||||
*/
|
||||
virtual Driver &create(Regulator_id regulator) = 0;
|
||||
|
||||
/**
|
||||
* Destroy driver
|
||||
*/
|
||||
virtual void destroy(Driver &driver) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _REGULATOR__DRIVER_H_ */
|
22
os/include/regulator_session/capability.h
Normal file
22
os/include/regulator_session/capability.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* \brief Regulator session capability type
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR_SESSION__CAPABILITY_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__CAPABILITY_H_
|
||||
|
||||
#include <base/capability.h>
|
||||
#include <regulator_session/regulator_session.h>
|
||||
|
||||
namespace Regulator { typedef Genode::Capability<Session> Session_capability; }
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__CAPABILITY_H_ */
|
46
os/include/regulator_session/client.h
Normal file
46
os/include/regulator_session/client.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* \brief Client-side regulator session interface
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR_SESSION__CLIENT_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__CLIENT_H_
|
||||
|
||||
#include <base/rpc_client.h>
|
||||
#include <regulator_session/capability.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
class Session_client : public Genode::Rpc_client<Session>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param session session capability
|
||||
*/
|
||||
Session_client(Session_capability session)
|
||||
: Genode::Rpc_client<Session>(session) { }
|
||||
|
||||
|
||||
/*********************************
|
||||
** Regulator session interface **
|
||||
*********************************/
|
||||
|
||||
void set_level(unsigned long level) { call<Rpc_set_level>(level); }
|
||||
unsigned long level() { return call<Rpc_level>(); }
|
||||
void set_state(bool enable) { call<Rpc_set_state>(enable); }
|
||||
bool state() { return call<Rpc_state>(); }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__CLIENT_H_ */
|
39
os/include/regulator_session/connection.h
Normal file
39
os/include/regulator_session/connection.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* \brief Connection to regulator service
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR_SESSION__CONNECTION_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__CONNECTION_H_
|
||||
|
||||
#include <regulator_session/client.h>
|
||||
#include <regulator/consts.h>
|
||||
#include <base/connection.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
struct Connection : Genode::Connection<Session>, Session_client
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param regulator identifier for the specific regulator
|
||||
* \param label string identifier of the client
|
||||
*/
|
||||
Connection(Regulator_id regulator, const char * label = "")
|
||||
: Genode::Connection<Session>(
|
||||
session("ram_quota=8K, regulator=\"%s\", label=\"%s\"",
|
||||
regulator_name_by_id(regulator), label)),
|
||||
Session_client(cap()) { }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__CONNECTION_H_ */
|
60
os/include/regulator_session/regulator_session.h
Normal file
60
os/include/regulator_session/regulator_session.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* \brief Abstract regulator session interface.
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR_SESSION__REGULATOR_SESSION_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__REGULATOR_SESSION_H_
|
||||
|
||||
#include <session/session.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
struct Session : public Genode::Session
|
||||
{
|
||||
static const char *service_name() { return "Regulator"; }
|
||||
|
||||
virtual ~Session() { }
|
||||
|
||||
/**
|
||||
* Set regulator specific level
|
||||
*/
|
||||
virtual void set_level(unsigned long level) = 0;
|
||||
|
||||
/**
|
||||
* Returns current regulator level
|
||||
*/
|
||||
virtual unsigned long level() = 0;
|
||||
|
||||
/**
|
||||
* Enable/disable regulator
|
||||
*/
|
||||
virtual void set_state(bool enable) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether regulator is enabled or not
|
||||
*/
|
||||
virtual bool state() = 0;
|
||||
|
||||
|
||||
/*******************
|
||||
** RPC interface **
|
||||
*******************/
|
||||
|
||||
GENODE_RPC(Rpc_set_level, void, set_level, unsigned long);
|
||||
GENODE_RPC(Rpc_level, unsigned long, level);
|
||||
GENODE_RPC(Rpc_set_state, void, set_state, bool);
|
||||
GENODE_RPC(Rpc_state, bool, state);
|
||||
GENODE_RPC_INTERFACE(Rpc_set_level, Rpc_level, Rpc_set_state, Rpc_state);
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__REGULATOR_SESSION_H_ */
|
40
os/include/regulator_session/rpc_object.h
Normal file
40
os/include/regulator_session/rpc_object.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* \brief Server-side block regulator interface
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__REGULATOR_SESSION__SERVER_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__SERVER_H_
|
||||
|
||||
#include <base/rpc_server.h>
|
||||
#include <regulator/consts.h>
|
||||
#include <regulator_session/regulator_session.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
class Session_rpc_object : public Genode::Rpc_object<Session, Session_rpc_object>
|
||||
{
|
||||
protected:
|
||||
|
||||
Regulator_id _id; /* regulator identifier */
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param id identifies the specific regulator
|
||||
*/
|
||||
Session_rpc_object(Regulator_id id) : _id(id) { }
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__SERVER_H_ */
|
Loading…
Reference in New Issue
Block a user