2015-02-19 14:50:27 +01:00
|
|
|
/*
|
|
|
|
* \brief VM session component for 'base-hw'
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2015-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-02-19 14:50:27 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-02-19 14:50:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <util/construct_at.h>
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <kernel/core_interface.h>
|
|
|
|
#include <vm_session_component.h>
|
|
|
|
#include <platform.h>
|
|
|
|
#include <core_env.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::exception_handler(Signal_context_capability handler)
|
|
|
|
{
|
|
|
|
Core_mem_allocator * cma =
|
|
|
|
static_cast<Core_mem_allocator*>(platform()->core_mem_alloc());
|
2015-04-01 10:23:38 +02:00
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
if (!create((void*)_ds.core_local_addr(), Capability_space::capid(handler),
|
2015-05-19 14:18:40 +02:00
|
|
|
cma->phys_addr(_table)))
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::warning("Cannot instantiate vm kernel object, invalid signal context?");
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::_attach(addr_t phys_addr, addr_t vm_addr, size_t size)
|
|
|
|
{
|
2016-11-07 18:00:24 +01:00
|
|
|
Page_flags pflags { RW, NO_EXEC, USER, NO_GLOBAL, RAM, CACHED };
|
2015-02-19 14:50:27 +01:00
|
|
|
|
|
|
|
try {
|
2015-06-16 10:59:26 +02:00
|
|
|
_table->insert_translation(vm_addr, phys_addr, size, pflags, _tt_alloc);
|
|
|
|
return;
|
2015-02-19 14:50:27 +01:00
|
|
|
} catch(Allocator::Out_of_memory) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("Translation table needs to much RAM");
|
2015-02-19 14:50:27 +01:00
|
|
|
} catch(...) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::error("Invalid mapping ", Genode::Hex(phys_addr), " -> ",
|
|
|
|
Genode::Hex(vm_addr), " (", size, ")");
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::attach(Dataspace_capability ds_cap, addr_t vm_addr)
|
|
|
|
{
|
|
|
|
/* check dataspace validity */
|
2015-08-10 13:34:16 +02:00
|
|
|
_ds_ep->apply(ds_cap, [&] (Dataspace_component *dsc) {
|
|
|
|
if (!dsc) throw Invalid_dataspace();
|
2015-02-19 14:50:27 +01:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
_attach(dsc->phys_addr(), vm_addr, dsc->size());
|
|
|
|
});
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::attach_pic(addr_t vm_addr)
|
|
|
|
{
|
|
|
|
_attach(Board::IRQ_CONTROLLER_VT_CPU_BASE, vm_addr,
|
|
|
|
Board::IRQ_CONTROLLER_VT_CPU_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Vm_session_component::detach(addr_t vm_addr, size_t size) {
|
2015-06-16 10:59:26 +02:00
|
|
|
_table->remove_translation(vm_addr, size, _tt_alloc); }
|
2015-02-19 14:50:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
Vm_session_component::Vm_session_component(Rpc_entrypoint *ds_ep,
|
|
|
|
size_t ram_quota)
|
2015-04-01 10:23:38 +02:00
|
|
|
: _ds_ep(ds_ep), _ds(_ds_size(), _alloc_ds(ram_quota), UNCACHED, true, 0),
|
2015-02-19 14:50:27 +01:00
|
|
|
_ds_cap(static_cap_cast<Dataspace>(_ds_ep->manage(&_ds)))
|
|
|
|
{
|
|
|
|
_ds.assign_core_local_addr(core_env()->rm_session()->attach(_ds_cap));
|
|
|
|
|
|
|
|
Core_mem_allocator * cma =
|
|
|
|
static_cast<Core_mem_allocator*>(platform()->core_mem_alloc());
|
|
|
|
void *tt;
|
|
|
|
|
|
|
|
/* get some aligned space for the translation table */
|
|
|
|
if (!cma->alloc_aligned(sizeof(Translation_table), (void**)&tt,
|
2016-05-11 18:21:47 +02:00
|
|
|
Translation_table::ALIGNM_LOG2).ok()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
error("failed to allocate kernel object");
|
2015-02-19 14:50:27 +01:00
|
|
|
throw Root::Quota_exceeded();
|
|
|
|
}
|
|
|
|
|
2015-06-16 10:59:26 +02:00
|
|
|
_table = construct_at<Translation_table>(tt);
|
|
|
|
_tt_alloc = (new (cma) Table_allocator(cma))->alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vm_session_component::~Vm_session_component()
|
|
|
|
{
|
|
|
|
/* dissolve VM dataspace from service entry point */
|
|
|
|
_ds_ep->dissolve(&_ds);
|
|
|
|
|
|
|
|
/* free region in allocator */
|
|
|
|
core_env()->rm_session()->detach(_ds.core_local_addr());
|
|
|
|
platform()->ram_alloc()->free((void*)_ds.phys_addr());
|
|
|
|
|
|
|
|
/* free guest-to-host page tables */
|
|
|
|
destroy(platform()->core_mem_alloc(), _table);
|
|
|
|
destroy(platform()->core_mem_alloc(), Table_allocator::base(_tt_alloc));
|
2015-02-19 14:50:27 +01:00
|
|
|
}
|