2013-08-20 19:24:52 +00:00
|
|
|
/*
|
|
|
|
* \brief Utilities for implementing VMMs on Genode/NOVA
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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__VMM__VCPU_THREAD_H_
|
|
|
|
#define _INCLUDE__VMM__VCPU_THREAD_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/thread.h>
|
|
|
|
#include <cap_session/connection.h>
|
2013-11-14 10:58:28 +00:00
|
|
|
#include <cpu_session/connection.h>
|
|
|
|
#include <pd_session/connection.h>
|
2016-04-15 13:19:22 +00:00
|
|
|
#include <region_map/client.h>
|
2016-04-20 19:12:57 +00:00
|
|
|
#include <nova_native_cpu/client.h>
|
2016-05-10 16:05:38 +00:00
|
|
|
#include <cpu_thread/client.h>
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-03-11 16:32:43 +00:00
|
|
|
/* NOVA includes */
|
|
|
|
#include <nova/native_thread.h>
|
2016-06-15 13:04:54 +00:00
|
|
|
#include <nova/cap_map.h>
|
2016-03-11 16:32:43 +00:00
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
namespace Vmm {
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
class Vcpu_thread;
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vcpu_other_pd;
|
|
|
|
class Vcpu_same_pd;
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vmm::Vcpu_thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual Genode::addr_t exc_base() = 0;
|
|
|
|
virtual void start(Genode::addr_t) = 0;
|
|
|
|
};
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
class Vmm::Vcpu_other_pd : public Vmm::Vcpu_thread
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2014-07-16 19:43:41 +00:00
|
|
|
Genode::Pd_connection _pd_session;
|
|
|
|
Genode::Affinity::Location _location;
|
|
|
|
Genode::Cpu_session *_cpu_session;
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
Genode::addr_t _exc_pt_sel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-07-16 19:43:41 +00:00
|
|
|
Vcpu_other_pd(Cpu_session * cpu_session,
|
|
|
|
Genode::Affinity::Location location)
|
2013-11-14 10:58:28 +00:00
|
|
|
:
|
2014-07-16 19:43:41 +00:00
|
|
|
_pd_session("VM"), _location(location), _cpu_session(cpu_session),
|
2013-11-14 10:58:28 +00:00
|
|
|
_exc_pt_sel(Genode::cap_map()->insert(Nova::NUM_INITIAL_VCPU_PT_LOG2))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void start(Genode::addr_t sel_ec)
|
|
|
|
{
|
|
|
|
using namespace Genode;
|
|
|
|
|
2015-03-27 13:05:55 +00:00
|
|
|
Thread_capability vcpu_vm =
|
2016-05-04 10:27:17 +00:00
|
|
|
_cpu_session->create_thread(_pd_session, "vCPU",
|
|
|
|
_location, Cpu_session::Weight());
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/* tell parent that this will be a vCPU */
|
|
|
|
Thread_state state;
|
|
|
|
state.sel_exc_base = Native_thread::INVALID_INDEX;
|
2016-05-11 16:21:47 +00:00
|
|
|
state.vcpu = true;
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-05-10 16:05:38 +00:00
|
|
|
Cpu_thread_client cpu_thread(vcpu_vm);
|
|
|
|
|
|
|
|
cpu_thread.state(state);
|
2013-11-14 10:58:28 +00:00
|
|
|
|
2016-04-20 19:12:57 +00:00
|
|
|
/* obtain interface to NOVA-specific CPU session operations */
|
|
|
|
Nova_native_cpu_client native_cpu(_cpu_session->native_cpu());
|
|
|
|
|
|
|
|
/* create new pager object and assign it to the new thread */
|
|
|
|
Native_capability pager_cap = native_cpu.pager_cap(vcpu_vm);
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
/*
|
|
|
|
* Delegate parent the vCPU exception portals required during PD
|
|
|
|
* creation.
|
|
|
|
*/
|
|
|
|
delegate_vcpu_portals(pager_cap, exc_base());
|
|
|
|
|
|
|
|
/* start vCPU in separate PD */
|
2016-05-10 16:05:38 +00:00
|
|
|
cpu_thread.start(0, 0);
|
2013-11-14 10:58:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Request native EC thread cap and put it next to the
|
|
|
|
* SM cap - see Vcpu_dispatcher->sel_sm_ec description
|
|
|
|
*/
|
|
|
|
request_native_ec_cap(pager_cap, sel_ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
Genode::addr_t exc_base() { return _exc_pt_sel; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-04 10:27:17 +00:00
|
|
|
class Vmm::Vcpu_same_pd : public Vmm::Vcpu_thread, Genode::Thread
|
2013-11-14 10:58:28 +00:00
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
enum { WEIGHT = Genode::Cpu_session::Weight::DEFAULT_WEIGHT };
|
2015-03-27 13:05:55 +00:00
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
public:
|
|
|
|
|
2014-07-16 19:43:41 +00:00
|
|
|
Vcpu_same_pd(size_t stack_size, Cpu_session * cpu_session,
|
|
|
|
Genode::Affinity::Location location)
|
2013-08-20 19:24:52 +00:00
|
|
|
:
|
2016-05-04 10:27:17 +00:00
|
|
|
Thread(WEIGHT, "vCPU", stack_size, Type::NORMAL, cpu_session, location)
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
/* release pre-allocated selectors of Thread */
|
2016-03-11 16:32:43 +00:00
|
|
|
Genode::cap_map()->remove(native_thread().exc_pt_sel, Nova::NUM_INITIAL_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* allocate correct number of selectors */
|
2016-03-11 16:32:43 +00:00
|
|
|
this->native_thread().exc_pt_sel = cap_map()->insert(Nova::NUM_INITIAL_VCPU_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* tell generic thread code that this becomes a vCPU */
|
2016-05-11 16:21:47 +00:00
|
|
|
this->native_thread().vcpu = true;
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 10:58:28 +00:00
|
|
|
~Vcpu_same_pd()
|
2013-08-20 19:24:52 +00:00
|
|
|
{
|
|
|
|
using namespace Nova;
|
|
|
|
|
2016-03-11 16:32:43 +00:00
|
|
|
revoke(Nova::Obj_crd(this->native_thread().exc_pt_sel, NUM_INITIAL_VCPU_PT_LOG2));
|
|
|
|
cap_map()->remove(this->native_thread().exc_pt_sel, NUM_INITIAL_VCPU_PT_LOG2, false);
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
/* allocate selectors for ~Thread */
|
2016-03-11 16:32:43 +00:00
|
|
|
this->native_thread().exc_pt_sel = cap_map()->insert(Nova::NUM_INITIAL_PT_LOG2);
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 16:32:43 +00:00
|
|
|
addr_t exc_base() { return this->native_thread().exc_pt_sel; }
|
2013-08-20 19:24:52 +00:00
|
|
|
|
|
|
|
void start(Genode::addr_t sel_ec)
|
|
|
|
{
|
2016-05-04 10:27:17 +00:00
|
|
|
this->Thread::start();
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-04-20 19:12:57 +00:00
|
|
|
/* obtain interface to NOVA-specific CPU session operations */
|
|
|
|
Nova_native_cpu_client native_cpu(_cpu_session->native_cpu());
|
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
/*
|
|
|
|
* Request native EC thread cap and put it next to the
|
|
|
|
* SM cap - see Vcpu_dispatcher->sel_sm_ec description
|
|
|
|
*/
|
2016-04-20 19:12:57 +00:00
|
|
|
Native_capability pager_cap = native_cpu.pager_cap(_thread_cap);
|
|
|
|
request_native_ec_cap(pager_cap, sel_ec);
|
2013-08-20 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void entry() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__VMM__VCPU_THREAD_H_ */
|