2014-04-28 21:31:57 +02:00
|
|
|
/*
|
|
|
|
* \brief hw-specific implementation of core-local RM session
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2014-02-26
|
|
|
|
*
|
|
|
|
* Taken from OKL4-specific imlementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-04-28 21:31:57 +02: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.
|
2014-04-28 21:31:57 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <platform.h>
|
2016-04-15 15:19:22 +02:00
|
|
|
#include <core_region_map.h>
|
2014-04-28 21:31:57 +02:00
|
|
|
#include <map_local.h>
|
|
|
|
#include <util.h>
|
|
|
|
#include <base/heap.h>
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2016-04-15 15:19:22 +02:00
|
|
|
Region_map::Local_addr
|
|
|
|
Core_region_map::attach(Dataspace_capability ds_cap, size_t size,
|
2014-04-28 21:31:57 +02:00
|
|
|
off_t offset, bool use_local_addr,
|
2018-05-08 11:21:10 +02:00
|
|
|
Region_map::Local_addr, bool, bool writeable)
|
2014-04-28 21:31:57 +02:00
|
|
|
{
|
2015-08-10 13:34:16 +02:00
|
|
|
auto lambda = [&] (Dataspace_component *ds) -> Local_addr {
|
|
|
|
if (!ds)
|
|
|
|
throw Invalid_dataspace();
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
if (size == 0)
|
|
|
|
size = ds->size();
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
size_t page_rounded_size = (size + get_page_size() - 1) & get_page_mask();
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
if (use_local_addr) {
|
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("Parameter 'use_local_addr' not supported within core");
|
2015-08-10 13:34:16 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
if (offset) {
|
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("Parameter 'offset' not supported within core");
|
2015-08-10 13:34:16 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
/* allocate range in core's virtual address space */
|
|
|
|
void *virt_addr;
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
if (!platform().region_alloc().alloc_aligned(page_rounded_size, &virt_addr,
|
|
|
|
get_page_size_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("could not allocate virtual address range in core of size ",
|
|
|
|
page_rounded_size);
|
2015-08-10 13:34:16 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
using namespace Hw;
|
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
/* map the dataspace's physical pages to corresponding virtual addresses */
|
|
|
|
unsigned num_pages = page_rounded_size >> get_page_size_log2();
|
2018-05-08 11:21:10 +02:00
|
|
|
Page_flags const flags { (writeable && ds->writable()) ? RW : RO,
|
|
|
|
NO_EXEC, KERN, GLOBAL,
|
|
|
|
ds->io_mem() ? DEVICE : RAM,
|
2016-11-07 18:00:24 +01:00
|
|
|
ds->cacheability() };
|
2015-08-10 13:34:16 +02:00
|
|
|
if (!map_local(ds->phys_addr(), (addr_t)virt_addr, num_pages, flags))
|
|
|
|
return nullptr;
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
return virt_addr;
|
|
|
|
};
|
2016-04-20 21:12:57 +02:00
|
|
|
return _ep.apply(ds_cap, lambda);
|
2014-04-28 21:31:57 +02:00
|
|
|
}
|
2016-04-20 21:12:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Core_region_map::detach(Local_addr) { }
|