committed by
Norman Feske
parent
dd15d65800
commit
9c7df24e20
104
include/regulator/component.h
Normal file
104
include/regulator/component.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* \brief Regulator-session component
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _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:
|
||||
|
||||
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)) { }
|
||||
|
||||
~Session_component()
|
||||
{
|
||||
_driver.state(_id, false);
|
||||
_driver_factory.destroy(_driver);
|
||||
}
|
||||
|
||||
|
||||
/***********************************
|
||||
** Regulator session interface **
|
||||
***********************************/
|
||||
|
||||
void level(unsigned long level) override { _driver.level(_id, level); }
|
||||
unsigned long level() override { return _driver.level(_id); }
|
||||
void state(bool enable) override { _driver.state(_id, enable); }
|
||||
bool state() override { return _driver.state(_id); }
|
||||
};
|
||||
|
||||
|
||||
class Regulator::Root :
|
||||
public Genode::Root_component<Regulator::Session_component>
|
||||
{
|
||||
private:
|
||||
|
||||
Regulator::Driver_factory & _driver_factory;
|
||||
|
||||
protected:
|
||||
|
||||
Session_component *_create_session(const char *args) override
|
||||
{
|
||||
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 Insufficient_ram_quota();
|
||||
|
||||
if (!strlen(reg_name))
|
||||
throw Service_denied();
|
||||
|
||||
return new (md_alloc())
|
||||
Session_component(regulator_id_by_name(reg_name),
|
||||
_driver_factory);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Root(Genode::Env & env,
|
||||
Genode::Allocator & md_alloc,
|
||||
Regulator::Driver_factory & driver_factory)
|
||||
: Genode::Root_component<Regulator::Session_component>(env.ep(),
|
||||
md_alloc),
|
||||
_driver_factory(driver_factory) { }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR__COMPONENT_H_ */
|
||||
54
include/regulator/driver.h
Normal file
54
include/regulator/driver.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* \brief Regulator-driver interface
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _INCLUDE__REGULATOR__DRIVER_H_
|
||||
#define _INCLUDE__REGULATOR__DRIVER_H_
|
||||
|
||||
#include <regulator/consts.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
struct Driver;
|
||||
struct Driver_factory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Interface to be implemented by the device-specific driver code
|
||||
*/
|
||||
struct Regulator::Driver : Genode::Interface
|
||||
{
|
||||
virtual void level(Regulator_id id, unsigned long level) = 0;
|
||||
virtual unsigned long level(Regulator_id id) = 0;
|
||||
virtual void state(Regulator_id id, bool enable) = 0;
|
||||
virtual bool state(Regulator_id id) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Interface for constructing the driver object
|
||||
*/
|
||||
struct Regulator::Driver_factory : Genode::Interface
|
||||
{
|
||||
/**
|
||||
* Construct new driver
|
||||
*/
|
||||
virtual Driver &create(Regulator_id regulator) = 0;
|
||||
|
||||
/**
|
||||
* Destroy driver
|
||||
*/
|
||||
virtual void destroy(Driver &driver) = 0;
|
||||
};
|
||||
|
||||
#endif /* _REGULATOR__DRIVER_H_ */
|
||||
22
include/regulator_session/capability.h
Normal file
22
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-2017 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 _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_ */
|
||||
44
include/regulator_session/client.h
Normal file
44
include/regulator_session/client.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* \brief Client-side regulator session interface
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _INCLUDE__REGULATOR_SESSION__CLIENT_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__CLIENT_H_
|
||||
|
||||
#include <base/rpc_client.h>
|
||||
#include <regulator_session/capability.h>
|
||||
|
||||
namespace Regulator { struct Session_client; }
|
||||
|
||||
|
||||
struct Regulator::Session_client : public Genode::Rpc_client<Session>
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param session session capability
|
||||
*/
|
||||
Session_client(Session_capability session)
|
||||
: Genode::Rpc_client<Session>(session) { }
|
||||
|
||||
|
||||
/*********************************
|
||||
** Regulator session interface **
|
||||
*********************************/
|
||||
|
||||
void level(unsigned long level) override { call<Rpc_set_level>(level); }
|
||||
unsigned long level() override { return call<Rpc_level>(); }
|
||||
void state(bool enable) override { call<Rpc_set_state>(enable); }
|
||||
bool state() override { return call<Rpc_state>(); }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__CLIENT_H_ */
|
||||
42
include/regulator_session/connection.h
Normal file
42
include/regulator_session/connection.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* \brief Connection to regulator service
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _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; }
|
||||
|
||||
|
||||
struct Regulator::Connection : Genode::Connection<Session>, Session_client
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param regulator identifier for the specific regulator
|
||||
* \param label string identifier of the client
|
||||
*/
|
||||
Connection(Genode::Env &env, Regulator_id regulator, const char * label = "")
|
||||
:
|
||||
Genode::Connection<Session>(env,
|
||||
session(env.parent(),
|
||||
"ram_quota=8K, cap_quota=%ld, regulator=\"%s\", label=\"%s\"",
|
||||
CAP_QUOTA, regulator_name_by_id(regulator), label)),
|
||||
Session_client(cap())
|
||||
{ }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__REGULATOR_SESSION__CONNECTION_H_ */
|
||||
65
include/regulator_session/regulator_session.h
Normal file
65
include/regulator_session/regulator_session.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* \brief Abstract regulator session interface.
|
||||
* \author Stefan Kalkowski
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _INCLUDE__REGULATOR_SESSION__REGULATOR_SESSION_H_
|
||||
#define _INCLUDE__REGULATOR_SESSION__REGULATOR_SESSION_H_
|
||||
|
||||
#include <session/session.h>
|
||||
|
||||
namespace Regulator { struct Session; }
|
||||
|
||||
|
||||
struct Regulator::Session : public Genode::Session
|
||||
{
|
||||
/**
|
||||
* \noapi
|
||||
*/
|
||||
static const char *service_name() { return "Regulator"; }
|
||||
|
||||
enum { CAP_QUOTA = 2 };
|
||||
|
||||
virtual ~Session() { }
|
||||
|
||||
/**
|
||||
* Set regulator specific level
|
||||
*/
|
||||
virtual void level(unsigned long level) = 0;
|
||||
|
||||
/**
|
||||
* Returns current regulator level
|
||||
*/
|
||||
virtual unsigned long level() = 0;
|
||||
|
||||
/**
|
||||
* Enable/disable regulator
|
||||
*/
|
||||
virtual void state(bool enable) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether regulator is enabled or not
|
||||
*/
|
||||
virtual bool state() = 0;
|
||||
|
||||
|
||||
/*******************
|
||||
** RPC interface **
|
||||
*******************/
|
||||
|
||||
GENODE_RPC(Rpc_set_level, void, level, unsigned long);
|
||||
GENODE_RPC(Rpc_level, unsigned long, level);
|
||||
GENODE_RPC(Rpc_set_state, void, 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
include/regulator_session/rpc_object.h
Normal file
40
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-2017 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 _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; }
|
||||
|
||||
|
||||
class Regulator::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_ */
|
||||
86
include/spec/exynos5/regulator/consts.h
Normal file
86
include/spec/exynos5/regulator/consts.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* \brief Regulator definitions for Exynos5
|
||||
* \author Stefan Kalkowski <stefan.kalkowski@genode-labs.com>
|
||||
* \date 2013-06-13
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013-2017 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 _INCLUDE__SPEC__EXYNOS5__REGULATOR__CONSTS_H_
|
||||
#define _INCLUDE__SPEC__EXYNOS5__REGULATOR__CONSTS_H_
|
||||
|
||||
#include <util/string.h>
|
||||
|
||||
namespace Regulator {
|
||||
|
||||
enum Regulator_id {
|
||||
CLK_CPU,
|
||||
CLK_SATA,
|
||||
CLK_USB30,
|
||||
CLK_USB20,
|
||||
CLK_MMC0,
|
||||
CLK_HDMI,
|
||||
PWR_SATA,
|
||||
PWR_USB30,
|
||||
PWR_USB20,
|
||||
PWR_HDMI,
|
||||
MAX,
|
||||
INVALID
|
||||
};
|
||||
|
||||
struct Regulator_name {
|
||||
Regulator_id id;
|
||||
const char * name;
|
||||
};
|
||||
|
||||
static constexpr Regulator_name names[] = {
|
||||
{ CLK_CPU, "clock-cpu" },
|
||||
{ CLK_SATA, "clock-sata" },
|
||||
{ CLK_USB30, "clock-usb3.0" },
|
||||
{ CLK_USB20, "clock-usb2.0" },
|
||||
{ CLK_MMC0, "clock-mmc0" },
|
||||
{ CLK_HDMI, "clock-hdmi" },
|
||||
{ PWR_SATA, "power-sata" },
|
||||
{ PWR_USB30, "power-usb3.0" },
|
||||
{ PWR_USB20, "power-usb2.0" },
|
||||
{ PWR_HDMI, "power-hdmi"},
|
||||
};
|
||||
|
||||
inline Regulator_id regulator_id_by_name(const char * name)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(names)/sizeof(names[0]); i++)
|
||||
if (Genode::strcmp(names[i].name, name) == 0)
|
||||
return names[i].id;
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
inline const char * regulator_name_by_id(Regulator_id id) {
|
||||
return (id < sizeof(names)/sizeof(names[0])) ? names[id].name : 0; }
|
||||
|
||||
|
||||
/***************************************
|
||||
** Device specific level definitions **
|
||||
***************************************/
|
||||
|
||||
enum Cpu_clock_freq {
|
||||
CPU_FREQ_200 = 200000000,
|
||||
CPU_FREQ_400 = 400000000,
|
||||
CPU_FREQ_600 = 600000000,
|
||||
CPU_FREQ_800 = 800000000,
|
||||
CPU_FREQ_1000 = 1000000000,
|
||||
CPU_FREQ_1200 = 1200000000,
|
||||
CPU_FREQ_1400 = 1400000000,
|
||||
CPU_FREQ_1600 = 1600000000,
|
||||
CPU_FREQ_1700 = 1700000000,
|
||||
/* warning: 1700 not recommended by the reference manual
|
||||
we just insert this for performance measurement against
|
||||
Linux, which uses this overclocking */
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__SPEC__EXYNOS5__REGULATOR__CONSTS_H_ */
|
||||
Reference in New Issue
Block a user