2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief RAM session interface
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-05-11
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2006-2017 Genode Labs GmbH
|
2011-12-22 15:19:25 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 15:19:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__RAM_SESSION__RAM_SESSION_H_
|
|
|
|
#define _INCLUDE__RAM_SESSION__RAM_SESSION_H_
|
|
|
|
|
|
|
|
#include <base/stdint.h>
|
2017-05-07 21:49:43 +00:00
|
|
|
#include <base/ram_allocator.h>
|
2011-12-22 15:19:25 +00:00
|
|
|
#include <dataspace/capability.h>
|
|
|
|
#include <ram_session/capability.h>
|
|
|
|
#include <session/session.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
2016-11-06 13:26:34 +00:00
|
|
|
struct Ram_session_client;
|
2015-03-04 20:12:14 +00:00
|
|
|
struct Ram_session;
|
2011-12-22 15:19:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2015-03-20 16:50:41 +00:00
|
|
|
/**
|
|
|
|
* RAM session interface
|
|
|
|
*/
|
2017-05-07 21:49:43 +00:00
|
|
|
struct Genode::Ram_session : Session, Ram_allocator
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
|
|
|
static const char *service_name() { return "RAM"; }
|
|
|
|
|
2017-05-07 20:03:25 +00:00
|
|
|
enum { CAP_QUOTA = 8 };
|
|
|
|
|
2016-11-06 13:26:34 +00:00
|
|
|
typedef Ram_session_client Client;
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2017-05-08 10:33:56 +00:00
|
|
|
/*********************
|
|
|
|
** Exception types **
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
class Invalid_session : public Exception { };
|
|
|
|
class Undefined_ref_account : public Exception { };
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
virtual ~Ram_session() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define reference account for the RAM session
|
|
|
|
*
|
|
|
|
* \param ram_session reference account
|
|
|
|
*
|
2017-05-08 10:33:56 +00:00
|
|
|
* \throw Invalid_session
|
2015-03-04 20:12:14 +00:00
|
|
|
*
|
|
|
|
* Each RAM session requires another RAM session as reference
|
|
|
|
* account to transfer quota to and from. The reference account can
|
|
|
|
* be defined only once.
|
|
|
|
*/
|
2017-05-08 10:33:56 +00:00
|
|
|
virtual void ref_account(Ram_session_capability ram_session) = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer quota to another RAM session
|
|
|
|
*
|
|
|
|
* \param ram_session receiver of quota donation
|
|
|
|
* \param amount amount of quota to donate
|
2017-05-08 10:33:56 +00:00
|
|
|
*
|
|
|
|
* \throw Out_of_ram
|
|
|
|
* \throw Invalid_session
|
|
|
|
* \throw Undefined_ref_account
|
2015-03-04 20:12:14 +00:00
|
|
|
*
|
|
|
|
* Quota can only be transfered if the specified RAM session is
|
|
|
|
* either the reference account for this session or vice versa.
|
|
|
|
*/
|
2017-05-08 10:33:56 +00:00
|
|
|
virtual void transfer_quota(Ram_session_capability ram_session, Ram_quota amount) = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return current quota limit
|
|
|
|
*/
|
2017-05-07 23:33:40 +00:00
|
|
|
virtual Ram_quota ram_quota() const = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return used quota
|
|
|
|
*/
|
2017-05-07 23:33:40 +00:00
|
|
|
virtual Ram_quota used_ram() const = 0;
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return amount of available quota
|
|
|
|
*/
|
2017-05-07 23:33:40 +00:00
|
|
|
Ram_quota avail_ram() const { return { ram_quota().value - used_ram().value }; }
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
** RPC declaration **
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
GENODE_RPC_THROW(Rpc_alloc, Ram_dataspace_capability, alloc,
|
2017-05-08 17:55:54 +00:00
|
|
|
GENODE_TYPE_LIST(Out_of_ram, Out_of_caps, Undefined_ref_account),
|
2015-03-04 20:12:14 +00:00
|
|
|
size_t, Cache_attribute);
|
|
|
|
GENODE_RPC(Rpc_free, void, free, Ram_dataspace_capability);
|
2017-05-08 10:33:56 +00:00
|
|
|
GENODE_RPC(Rpc_ref_account, void, ref_account, Capability<Ram_session>);
|
|
|
|
GENODE_RPC_THROW(Rpc_transfer_ram_quota, void, transfer_quota,
|
|
|
|
GENODE_TYPE_LIST(Out_of_ram, Invalid_session, Undefined_ref_account),
|
|
|
|
Capability<Ram_session>, Ram_quota);
|
2017-05-07 23:33:40 +00:00
|
|
|
GENODE_RPC(Rpc_ram_quota, Ram_quota, ram_quota);
|
|
|
|
GENODE_RPC(Rpc_used_ram, Ram_quota, used_ram);
|
2015-03-04 20:12:14 +00:00
|
|
|
|
|
|
|
GENODE_RPC_INTERFACE(Rpc_alloc, Rpc_free, Rpc_ref_account,
|
2017-05-07 23:33:40 +00:00
|
|
|
Rpc_transfer_ram_quota, Rpc_ram_quota, Rpc_used_ram);
|
2015-03-04 20:12:14 +00:00
|
|
|
};
|
|
|
|
|
2011-12-22 15:19:25 +00:00
|
|
|
#endif /* _INCLUDE__RAM_SESSION__RAM_SESSION_H_ */
|