2012-10-02 09:01:15 +00:00
|
|
|
/*
|
2012-10-23 15:12:09 +00:00
|
|
|
* \brief Connection to VM a service
|
2012-10-02 09:01:15 +00:00
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2012-10-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2012-10-02 09:01:15 +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.
|
2012-10-02 09:01:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VM_SESSION__CONNECTION_H_
|
|
|
|
#define _INCLUDE__VM_SESSION__CONNECTION_H_
|
|
|
|
|
2018-09-26 13:53:18 +00:00
|
|
|
#include <util/retry.h>
|
2012-10-02 09:01:15 +00:00
|
|
|
#include <vm_session/client.h>
|
|
|
|
#include <cpu_session/cpu_session.h>
|
|
|
|
#include <base/connection.h>
|
|
|
|
|
2016-05-10 15:24:51 +00:00
|
|
|
namespace Genode { struct Vm_connection; }
|
|
|
|
|
|
|
|
|
|
|
|
struct Genode::Vm_connection : Connection<Vm_session>, Vm_session_client
|
2012-10-23 15:12:09 +00:00
|
|
|
{
|
2016-05-20 09:00:53 +00:00
|
|
|
/**
|
|
|
|
* Issue session request
|
|
|
|
*
|
|
|
|
* \noapi
|
|
|
|
*/
|
2016-05-10 15:24:51 +00:00
|
|
|
Capability<Vm_session> _session(Parent &parent, char const *label, long priority,
|
|
|
|
unsigned long affinity)
|
|
|
|
{
|
|
|
|
return session(parent,
|
2017-05-07 20:03:25 +00:00
|
|
|
"priority=0x%lx, affinity=0x%lx, ram_quota=16K, cap_quota=10, label=\"%s\"",
|
2016-05-10 15:24:51 +00:00
|
|
|
priority, affinity, label);
|
|
|
|
}
|
|
|
|
|
2012-10-23 15:12:09 +00:00
|
|
|
/**
|
2016-05-10 15:24:51 +00:00
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param label initial session label
|
|
|
|
* \param priority designated priority of the VM
|
|
|
|
* \param affinity which physical CPU the VM should run on top of
|
2012-10-23 15:12:09 +00:00
|
|
|
*/
|
2016-05-10 15:24:51 +00:00
|
|
|
Vm_connection(Env &env, const char *label = "",
|
|
|
|
long priority = Cpu_session::DEFAULT_PRIORITY,
|
|
|
|
unsigned long affinity = 0)
|
|
|
|
:
|
|
|
|
Connection<Vm_session>(env, _session(env.parent(), label, priority, affinity)),
|
|
|
|
Vm_session_client(cap())
|
|
|
|
{ }
|
|
|
|
|
2018-09-26 13:53:18 +00:00
|
|
|
template <typename FUNC>
|
|
|
|
auto with_upgrade(FUNC func) -> decltype(func())
|
|
|
|
{
|
|
|
|
return Genode::retry<Genode::Out_of_ram>(
|
|
|
|
[&] () {
|
|
|
|
return Genode::retry<Genode::Out_of_caps>(
|
|
|
|
[&] () { return func(); },
|
|
|
|
[&] () { this->upgrade_caps(2); });
|
|
|
|
},
|
|
|
|
[&] () { this->upgrade_ram(4096); }
|
|
|
|
);
|
|
|
|
}
|
2016-05-10 15:24:51 +00:00
|
|
|
};
|
2012-10-02 09:01:15 +00:00
|
|
|
|
|
|
|
#endif /* _INCLUDE__VM_SESSION__CONNECTION_H_ */
|