2011-12-22 16:19:25 +01:00
|
|
|
/*
|
Fiasco.OC: introduce Cap_index (fixes #149, #112)
This commit introduces a Cap_index class for Fiasco.OC's capabilities.
A Cap_index is a combination of the global capability id, that is used by Genode
to correctly identify a kernel-object, and a corresponding entry in a
protection-domain's (kernel-)capability-space. The cap-indices are non-copyable,
unique objects, that are held in a Cap_map. The Cap_map is used to re-find
capabilities already present in the protection-domain, when a capability is
received via IPC. The retrieval of capabilities effectively fixes issue #112,
meaning the waste of capability-space entries.
Because Cap_index objects are non-copyable (their address indicates the position
in the capability-space of the pd), they are inappropriate to use as
Native_capability. Therefore, Native_capability is implemented as a reference
to Cap_index objects. This design seems to be a good pre-condition to implement
smart-pointers for entries in the capability-space, and thereby closing existing
leaks (please refer to issue #32).
Cap_index, Cap_map, and the allocator for Cap_index objects are designed in a way,
that it should be relatively easy to apply the same concept to NOVA also. By now,
these classes are located in the `base-foc` repository, but they intentionally
contain no Fiasco.OC specific elements.
The previously explained changes had extensive impact on the whole Fiasco.OC
platform implementation, due to various dependencies. The following things had to
be changed:
* The Thread object's startup and destruction routine is re-arranged, to
enable another thread (that calls the Thread destructor) gaining the
capability id of the thread's gate to remove it from the Cap_map, the
thread's UTCB had to be made available to the caller, because there
is the current location of that id. After having the UTCB available
in the Thread object for that reason, the whole thread bootstrapping
could be simplified.
* In the course of changing the Native_capability's semantic, a new Cap_mapping
class was introduced in core, that facilitates the establishment and
destruction of capability mappings between core and it's client's, especially
mappings related to Platform_thread and Platform_task, that are relevant to
task and thread creation and destruction. Thereby, the destruction of
threads had to be reworked, which effectively removed a bug (issue #149)
where some threads weren't destroyed properly.
* In the quick fix for issue #112, something similar to the Cap_map was
introduced available in all processes. Moreover, some kind of a capability
map already existed in core, to handle cap-session request properly. The
introduction of the Cap_map unified both structures, so that the
cap-session component code in core had to be reworked too.
* The platform initialization code had to be changed sligthly due to the
changes in Native_capability
* The vcpu initialization in the L4Linux support library had to be adapted
according to the already mentioned changes in the Thread object's bootstrap
code.
2012-03-15 12:41:24 +01:00
|
|
|
* \brief Fiasco.OC-specific core implementation of IRQ sessions
|
2011-12-22 16:19:25 +01:00
|
|
|
* \author Christian Helmuth
|
Fiasco.OC: introduce Cap_index (fixes #149, #112)
This commit introduces a Cap_index class for Fiasco.OC's capabilities.
A Cap_index is a combination of the global capability id, that is used by Genode
to correctly identify a kernel-object, and a corresponding entry in a
protection-domain's (kernel-)capability-space. The cap-indices are non-copyable,
unique objects, that are held in a Cap_map. The Cap_map is used to re-find
capabilities already present in the protection-domain, when a capability is
received via IPC. The retrieval of capabilities effectively fixes issue #112,
meaning the waste of capability-space entries.
Because Cap_index objects are non-copyable (their address indicates the position
in the capability-space of the pd), they are inappropriate to use as
Native_capability. Therefore, Native_capability is implemented as a reference
to Cap_index objects. This design seems to be a good pre-condition to implement
smart-pointers for entries in the capability-space, and thereby closing existing
leaks (please refer to issue #32).
Cap_index, Cap_map, and the allocator for Cap_index objects are designed in a way,
that it should be relatively easy to apply the same concept to NOVA also. By now,
these classes are located in the `base-foc` repository, but they intentionally
contain no Fiasco.OC specific elements.
The previously explained changes had extensive impact on the whole Fiasco.OC
platform implementation, due to various dependencies. The following things had to
be changed:
* The Thread object's startup and destruction routine is re-arranged, to
enable another thread (that calls the Thread destructor) gaining the
capability id of the thread's gate to remove it from the Cap_map, the
thread's UTCB had to be made available to the caller, because there
is the current location of that id. After having the UTCB available
in the Thread object for that reason, the whole thread bootstrapping
could be simplified.
* In the course of changing the Native_capability's semantic, a new Cap_mapping
class was introduced in core, that facilitates the establishment and
destruction of capability mappings between core and it's client's, especially
mappings related to Platform_thread and Platform_task, that are relevant to
task and thread creation and destruction. Thereby, the destruction of
threads had to be reworked, which effectively removed a bug (issue #149)
where some threads weren't destroyed properly.
* In the quick fix for issue #112, something similar to the Cap_map was
introduced available in all processes. Moreover, some kind of a capability
map already existed in core, to handle cap-session request properly. The
introduction of the Cap_map unified both structures, so that the
cap-session component code in core had to be reworked too.
* The platform initialization code had to be changed sligthly due to the
changes in Native_capability
* The vcpu initialization in the L4Linux support library had to be adapted
according to the already mentioned changes in the Thread object's bootstrap
code.
2012-03-15 12:41:24 +01:00
|
|
|
* \author Stefan Kalkowski
|
2012-10-05 14:46:16 +02:00
|
|
|
* \author Sebastian Sumpf
|
2011-12-22 16:19:25 +01:00
|
|
|
* \date 2007-09-13
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2007-2017 Genode Labs GmbH
|
2011-12-22 16:19:25 +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.
|
2011-12-22 16:19:25 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
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
|
|
|
#include <base/log.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <util/arg_string.h>
|
2015-05-09 21:48:12 +02:00
|
|
|
#include <util/bit_array.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <irq_root.h>
|
2016-07-26 11:34:29 +02:00
|
|
|
#include <irq_args.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <irq_session_component.h>
|
2012-03-16 14:47:41 +01:00
|
|
|
#include <platform.h>
|
2011-12-22 16:19:25 +01:00
|
|
|
#include <util.h>
|
|
|
|
|
|
|
|
/* Fiasco includes */
|
|
|
|
namespace Fiasco {
|
|
|
|
#include <l4/sys/icu.h>
|
|
|
|
#include <l4/sys/irq.h>
|
|
|
|
#include <l4/sys/factory.h>
|
|
|
|
#include <l4/sys/types.h>
|
|
|
|
}
|
|
|
|
|
2012-10-05 14:46:16 +02:00
|
|
|
namespace Genode {
|
|
|
|
class Interrupt_handler;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
2012-10-05 14:46:16 +02:00
|
|
|
/**
|
|
|
|
* Dispatches interrupts from kernel
|
|
|
|
*/
|
2016-05-04 12:27:17 +02:00
|
|
|
class Genode::Interrupt_handler : public Thread_deprecated<2048*sizeof(long)>
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2012-10-05 14:46:16 +02:00
|
|
|
private:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-05-04 12:27:17 +02:00
|
|
|
Interrupt_handler() : Thread_deprecated("irq_handler") { start(); }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2012-10-05 14:46:16 +02:00
|
|
|
public:
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
void entry() override;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2016-01-23 14:42:55 +01:00
|
|
|
static Fiasco::l4_cap_idx_t handler_cap()
|
2012-10-05 14:46:16 +02:00
|
|
|
{
|
|
|
|
static Interrupt_handler handler;
|
2016-06-15 15:04:54 +02:00
|
|
|
return handler._thread_cap.data()->kcap();
|
2012-10-05 14:46:16 +02:00
|
|
|
}
|
2015-05-09 21:48:12 +02:00
|
|
|
|
2012-10-05 14:46:16 +02:00
|
|
|
};
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
enum { MAX_MSIS = 256 };
|
|
|
|
static class Msi_allocator : public Genode::Bit_array<MAX_MSIS>
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-05-09 21:48:12 +02:00
|
|
|
public:
|
2015-04-27 12:17:20 +02:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
Msi_allocator() {
|
|
|
|
using namespace Fiasco;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
l4_icu_info_t info { .features = 0, .nr_irqs = 0, .nr_msis = 0 };
|
2015-05-09 21:48:12 +02:00
|
|
|
l4_msgtag_t res = l4_icu_info(Fiasco::L4_BASE_ICU_CAP, &info);
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
if (l4_error(res) || !(info.features & L4_ICU_FLAG_MSI))
|
|
|
|
set(0, MAX_MSIS);
|
|
|
|
else
|
|
|
|
if (info.nr_msis < MAX_MSIS)
|
|
|
|
set(info.nr_msis, MAX_MSIS - info.nr_msis);
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2015-05-09 21:48:12 +02:00
|
|
|
} msi_alloc;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
bool Genode::Irq_object::associate(unsigned irq, bool msi,
|
|
|
|
Irq_session::Trigger trigger,
|
|
|
|
Irq_session::Polarity polarity)
|
|
|
|
{
|
2015-01-20 10:51:32 +01:00
|
|
|
using namespace Fiasco;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
_irq = irq;
|
|
|
|
_trigger = trigger;
|
|
|
|
_polarity = polarity;
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-01-20 10:51:32 +01:00
|
|
|
if (msi) irq |= L4_ICU_FLAG_MSI;
|
|
|
|
else
|
|
|
|
/* set interrupt mode */
|
|
|
|
Platform::setup_irq_mode(irq, _trigger, _polarity);
|
|
|
|
|
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
|
|
|
if (l4_error(l4_factory_create_irq(L4_BASE_FACTORY_CAP, _capability()))) {
|
|
|
|
error("l4_factory_create_irq failed!");
|
2015-05-09 21:48:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-20 10:51:32 +01:00
|
|
|
if (l4_error(l4_icu_bind(L4_BASE_ICU_CAP, irq, _capability()))) {
|
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("Binding IRQ ", _irq, " to the ICU failed");
|
2015-05-09 21:48:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2018-06-26 11:23:33 +02:00
|
|
|
if (l4_error(l4_rcv_ep_bind_thread(_capability(), Interrupt_handler::handler_cap(),
|
|
|
|
reinterpret_cast<l4_umword_t>(this)))) {
|
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("cannot attach to IRQ ", _irq);
|
2015-05-09 21:48:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-01-20 10:51:32 +01:00
|
|
|
if (msi) {
|
|
|
|
/**
|
|
|
|
* src_id represents bit 64-84 of the Interrupt Remap Table Entry Format
|
|
|
|
* for Remapped Interrupts, reference section 9.10 of the
|
|
|
|
* Intel ® Virtualization Technology for Directed I/O
|
|
|
|
* Architecture Specification
|
|
|
|
*/
|
|
|
|
unsigned src_id = 0x0;
|
|
|
|
Fiasco::l4_icu_msi_info_t info = l4_icu_msi_info_t();
|
|
|
|
if (l4_error(l4_icu_msi_info(L4_BASE_ICU_CAP, irq,
|
|
|
|
src_id, &info))) {
|
|
|
|
error("cannot get MSI info");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_msi_addr = info.msi_addr;
|
|
|
|
_msi_data = info.msi_data;
|
2015-05-09 21:48:12 +02:00
|
|
|
}
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-04-27 12:17:20 +02:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
void Genode::Irq_object::ack_irq()
|
|
|
|
{
|
|
|
|
using namespace Fiasco;
|
2015-04-27 12:17:20 +02:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
int err;
|
|
|
|
l4_msgtag_t tag = l4_irq_unmask(_capability());
|
|
|
|
if ((err = l4_ipc_error(tag, l4_utcb())))
|
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("IRQ unmask: ", err);
|
2015-05-09 21:48:12 +02:00
|
|
|
}
|
2012-10-05 14:46:16 +02:00
|
|
|
|
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
Genode::Irq_object::Irq_object()
|
|
|
|
:
|
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
|
|
|
_cap(cap_map().insert(platform_specific().cap_id_alloc().alloc())),
|
2015-05-09 21:48:12 +02:00
|
|
|
_trigger(Irq_session::TRIGGER_UNCHANGED),
|
|
|
|
_polarity(Irq_session::POLARITY_UNCHANGED),
|
|
|
|
_irq(~0U), _msi_addr(0), _msi_data(0)
|
|
|
|
{ }
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
Genode::Irq_object::~Irq_object()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-05-09 21:48:12 +02:00
|
|
|
if (_irq == ~0U)
|
2015-03-17 15:41:47 +01:00
|
|
|
return;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
using namespace Fiasco;
|
|
|
|
|
2015-01-20 10:51:32 +01:00
|
|
|
unsigned long irq = _irq;
|
|
|
|
if (_msi_addr) irq |= L4_ICU_FLAG_MSI;
|
2015-05-09 21:48:12 +02:00
|
|
|
|
|
|
|
if (l4_error(l4_irq_detach(_capability())))
|
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("cannot detach IRQ");
|
2015-05-09 21:48:12 +02:00
|
|
|
|
2015-01-20 10:51:32 +01:00
|
|
|
if (l4_error(l4_icu_unbind(L4_BASE_ICU_CAP, irq, _capability())))
|
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("cannot unbind IRQ");
|
2015-05-09 21:48:12 +02:00
|
|
|
|
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
|
|
|
cap_map().remove(_cap);
|
2015-03-17 15:41:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
/***************************
|
|
|
|
** IRQ session component **
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
|
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
|
|
|
Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
|
2015-03-17 15:41:47 +01:00
|
|
|
const char *args)
|
2015-01-20 10:51:32 +01:00
|
|
|
: _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)),
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
_irq_alloc(irq_alloc), _irq_object()
|
2015-03-17 15:41:47 +01:00
|
|
|
{
|
2015-05-09 21:48:12 +02:00
|
|
|
long msi = Arg_string::find_arg(args, "device_config_phys").long_value(0);
|
|
|
|
if (msi) {
|
2015-01-20 10:51:32 +01:00
|
|
|
if (msi_alloc.get(_irq_number, 1)) {
|
|
|
|
error("unavailable MSI ", _irq_number, " requested");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-05-09 21:48:12 +02:00
|
|
|
}
|
2015-01-20 10:51:32 +01:00
|
|
|
msi_alloc.set(_irq_number, 1);
|
2015-05-09 21:48:12 +02:00
|
|
|
} else {
|
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 (irq_alloc.alloc_addr(1, _irq_number).error()) {
|
2015-01-20 10:51:32 +01:00
|
|
|
error("unavailable IRQ ", _irq_number, " requested");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-05-09 21:48:12 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
2013-06-26 14:25:45 +02:00
|
|
|
|
2015-01-20 10:51:32 +01:00
|
|
|
Irq_args const irq_args(args);
|
2018-07-20 08:57:59 +02:00
|
|
|
if (_irq_object.associate(_irq_number, msi, irq_args.trigger(),
|
|
|
|
irq_args.polarity()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
if (msi)
|
|
|
|
msi_alloc.clear(_irq_number, 1);
|
|
|
|
else {
|
|
|
|
addr_t const free_irq = _irq_number;
|
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
|
|
|
_irq_alloc.free((void *)free_irq);
|
2018-07-20 08:57:59 +02:00
|
|
|
}
|
|
|
|
throw Service_denied();
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-17 15:41:47 +01:00
|
|
|
Irq_session_component::~Irq_session_component()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
2015-05-09 21:48:12 +02:00
|
|
|
if (_irq_number == ~0U)
|
2015-03-17 15:41:47 +01:00
|
|
|
return;
|
2015-05-09 21:48:12 +02:00
|
|
|
|
|
|
|
if (_irq_object.msi_address()) {
|
|
|
|
msi_alloc.clear(_irq_number, 1);
|
|
|
|
} else {
|
|
|
|
Genode::addr_t free_irq = _irq_number;
|
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
|
|
|
_irq_alloc.free((void *)free_irq);
|
2015-03-17 15:41:47 +01:00
|
|
|
}
|
2015-05-09 21:48:12 +02:00
|
|
|
}
|
2015-03-17 15:41:47 +01:00
|
|
|
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
void Irq_session_component::ack_irq() { _irq_object.ack_irq(); }
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2015-03-17 15:41:47 +01:00
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
void Irq_session_component::sigh(Genode::Signal_context_capability cap)
|
|
|
|
{
|
|
|
|
_irq_object.sigh(cap);
|
2015-03-17 13:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-27 12:17:20 +02:00
|
|
|
Genode::Irq_session::Info Irq_session_component::info()
|
|
|
|
{
|
2015-01-20 10:51:32 +01:00
|
|
|
if (!_irq_object.msi_address())
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
return { .type = Info::Type::INVALID, .address = 0, .value = 0 };
|
2015-04-27 12:17:20 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
.type = Genode::Irq_session::Info::Type::MSI,
|
2015-05-09 21:48:12 +02:00
|
|
|
.address = _irq_object.msi_address(),
|
|
|
|
.value = _irq_object.msi_value()
|
2015-04-27 12:17:20 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-09 21:48:12 +02:00
|
|
|
/**************************************
|
|
|
|
** Interrupt handler implementation **
|
|
|
|
**************************************/
|
2012-10-05 14:46:16 +02:00
|
|
|
|
2014-03-03 19:45:53 +01:00
|
|
|
/* Build with frame pointer to make GDB backtraces work. See issue #1061. */
|
|
|
|
__attribute__((optimize("-fno-omit-frame-pointer")))
|
|
|
|
__attribute__((noinline))
|
2012-10-05 14:46:16 +02:00
|
|
|
void Interrupt_handler::entry()
|
|
|
|
{
|
|
|
|
using namespace Fiasco;
|
|
|
|
|
|
|
|
int err;
|
|
|
|
l4_msgtag_t tag;
|
|
|
|
l4_umword_t label;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
tag = l4_ipc_wait(l4_utcb(), &label, L4_IPC_NEVER);
|
|
|
|
if ((err = l4_ipc_error(tag, l4_utcb())))
|
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("IRQ receive: ", err);
|
2012-10-05 14:46:16 +02:00
|
|
|
else {
|
2015-05-09 21:48:12 +02:00
|
|
|
Irq_object * irq_object = reinterpret_cast<Irq_object *>(label);
|
|
|
|
irq_object->notify();
|
2012-10-05 14:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|