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
97 lines
2.3 KiB
C++
97 lines
2.3 KiB
C++
/*
|
|
* \brief Backend for IRQ sessions served by core
|
|
* \author Martin Stein
|
|
* \author Reto Buerki
|
|
* \date 2012-02-12
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU Affero General Public License version 3.
|
|
*/
|
|
|
|
/* base-hw includes */
|
|
#include <kernel/core_interface.h>
|
|
|
|
/* core includes */
|
|
#include <kernel/irq.h>
|
|
#include <irq_root.h>
|
|
#include <irq_args.h>
|
|
#include <core_env.h>
|
|
|
|
/* base-internal includes */
|
|
#include <base/internal/capability_space.h>
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
unsigned Irq_session_component::_find_irq_number(const char * const args)
|
|
{
|
|
return Arg_string::find_arg(args, "irq_number").long_value(-1);
|
|
}
|
|
|
|
|
|
void Irq_session_component::ack_irq()
|
|
{
|
|
using Kernel::User_irq;
|
|
if (!_sig_cap.valid()) { return; }
|
|
User_irq * const kirq = reinterpret_cast<User_irq*>(&_kernel_object);
|
|
Kernel::ack_irq(kirq);
|
|
}
|
|
|
|
|
|
void Irq_session_component::sigh(Signal_context_capability cap)
|
|
{
|
|
if (_sig_cap.valid()) {
|
|
warning("signal handler already registered for IRQ ", _irq_number);
|
|
return;
|
|
}
|
|
|
|
_sig_cap = cap;
|
|
|
|
if (Kernel::new_irq((addr_t)&_kernel_object, _irq_number,
|
|
Capability_space::capid(_sig_cap)))
|
|
warning("invalid signal handler for IRQ ", _irq_number);
|
|
}
|
|
|
|
|
|
Irq_session_component::~Irq_session_component()
|
|
{
|
|
using namespace Kernel;
|
|
|
|
User_irq * kirq = reinterpret_cast<User_irq*>(&_kernel_object);
|
|
_irq_alloc.free((void *)(addr_t)_irq_number);
|
|
if (_sig_cap.valid())
|
|
Kernel::delete_irq(kirq);
|
|
}
|
|
|
|
|
|
Irq_session_component::Irq_session_component(Range_allocator &irq_alloc,
|
|
const char * const args)
|
|
:
|
|
_irq_number(Platform::irq(_find_irq_number(args))), _irq_alloc(irq_alloc),
|
|
_is_msi(false), _address(0), _value(0)
|
|
{
|
|
const long mmconf =
|
|
Arg_string::find_arg(args, "device_config_phys").long_value(0);
|
|
|
|
if (mmconf) {
|
|
_is_msi =
|
|
Platform::get_msi_params(mmconf, _address, _value, _irq_number);
|
|
if (!_is_msi)
|
|
throw Service_denied();
|
|
}
|
|
|
|
/* allocate interrupt */
|
|
if (_irq_alloc.alloc_addr(1, _irq_number).error()) {
|
|
error("unavailable interrupt ", _irq_number, " requested");
|
|
throw Service_denied();
|
|
}
|
|
|
|
Irq_args const irq_args(args);
|
|
|
|
Platform::setup_irq_mode(_irq_number, irq_args.trigger(), irq_args.polarity());
|
|
}
|