2013-10-30 13:56:57 +01:00
|
|
|
/*
|
|
|
|
* \brief Kernel back-end and core front-end for user interrupts
|
|
|
|
* \author Martin Stein
|
2015-02-18 14:23:54 +01:00
|
|
|
* \author Stefan Kalkowski
|
2013-10-30 13:56:57 +01:00
|
|
|
* \date 2013-10-28
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 _KERNEL__IRQ_H_
|
|
|
|
#define _KERNEL__IRQ_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <irq_session/irq_session.h>
|
2014-07-09 12:03:17 +02:00
|
|
|
#include <unmanaged_singleton.h>
|
2013-11-14 12:07:07 +01:00
|
|
|
|
2013-10-30 13:56:57 +01:00
|
|
|
/* core includes */
|
|
|
|
#include <kernel/signal_receiver.h>
|
|
|
|
|
|
|
|
namespace Kernel
|
|
|
|
{
|
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Kernel back-end interface of an interrupt
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
|
|
|
class Irq;
|
2015-02-18 14:23:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Kernel back-end of a user interrupt
|
|
|
|
*/
|
|
|
|
class User_irq;
|
2013-10-30 13:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Genode
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Core front-end of a user interrupt
|
|
|
|
*/
|
|
|
|
class Irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
class Kernel::Irq : public Object_pool<Irq>::Item
|
|
|
|
{
|
|
|
|
protected:
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get kernel name of the interrupt
|
|
|
|
*/
|
|
|
|
unsigned _id() const { return Pool::Item::id(); };
|
|
|
|
|
2015-02-18 14:23:54 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
using Pool = Object_pool<Irq>;
|
|
|
|
|
2013-10-30 13:56:57 +01:00
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param irq_id kernel name of the interrupt
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
Irq(unsigned const irq_id)
|
|
|
|
: Pool::Item(irq_id) { }
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param irq_id kernel name of the interrupt
|
|
|
|
* \param pool pool this interrupt shall belong to
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
Irq(unsigned const irq_id, Pool &pool)
|
|
|
|
: Irq(irq_id) { pool.insert(this); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*
|
|
|
|
* By now, there is no use case to destruct interrupts
|
|
|
|
*/
|
|
|
|
virtual ~Irq() { PERR("destruction of interrupts not implemented"); }
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle occurence of the interrupt
|
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
virtual void occurred() { }
|
2015-02-19 14:50:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent interrupt from occurring
|
|
|
|
*/
|
|
|
|
void disable() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow interrupt to occur
|
|
|
|
*/
|
|
|
|
void enable() const;
|
2015-02-18 14:23:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Kernel::User_irq
|
|
|
|
:
|
|
|
|
public Kernel::Irq,
|
|
|
|
public Signal_receiver,
|
|
|
|
public Signal_context,
|
|
|
|
public Signal_ack_handler
|
|
|
|
{
|
|
|
|
private:
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Get map that provides all user interrupts by their kernel names
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
static Irq::Pool * _pool();
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Get kernel name of the interrupt-signal receiver
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
unsigned _receiver_id() const { return Signal_receiver::Object::id(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get kernel name of the interrupt-signal context
|
|
|
|
*/
|
|
|
|
unsigned _context_id() const { return Signal_context::Object::id(); }
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
|
2013-11-14 13:29:47 +01:00
|
|
|
/************************
|
|
|
|
** Signal_ack_handler **
|
|
|
|
************************/
|
2013-10-30 13:56:57 +01:00
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
void _signal_acknowledged() { enable(); }
|
2013-10-30 13:56:57 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param irq_id kernel name of the interrupt
|
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
User_irq(unsigned const irq_id)
|
|
|
|
: Irq(irq_id), Signal_context(this, 0)
|
2013-10-30 13:56:57 +01:00
|
|
|
{
|
|
|
|
_pool()->insert(this);
|
2015-02-19 14:50:27 +01:00
|
|
|
disable();
|
2015-02-18 14:23:54 +01:00
|
|
|
Signal_context::ack_handler(this);
|
2013-10-30 13:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-18 14:23:54 +01:00
|
|
|
* Handle occurence of the interrupt
|
2013-10-30 13:56:57 +01:00
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
void occurred()
|
2013-10-30 13:56:57 +01:00
|
|
|
{
|
2015-02-18 14:23:54 +01:00
|
|
|
Signal_context::submit(1);
|
2015-02-19 14:50:27 +01:00
|
|
|
disable();
|
2013-10-30 13:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get information that enables a user to handle an interrupt
|
|
|
|
*
|
|
|
|
* \param irq_id kernel name of targeted interrupt
|
|
|
|
*/
|
2015-02-18 14:23:54 +01:00
|
|
|
static Genode::Irq_signal signal(unsigned const irq_id)
|
2013-10-30 13:56:57 +01:00
|
|
|
{
|
2015-02-18 14:23:54 +01:00
|
|
|
typedef Genode::Irq_signal Irq_signal;
|
|
|
|
static Irq_signal const invalid = { 0, 0 };
|
|
|
|
User_irq * const irq =
|
|
|
|
dynamic_cast<User_irq*>(_pool()->object(irq_id));
|
|
|
|
if (irq) {
|
|
|
|
Irq_signal s = { irq->_receiver_id(), irq->_context_id() };
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return invalid;
|
2013-10-30 13:56:57 +01:00
|
|
|
}
|
2015-02-18 14:23:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle occurence of an interrupt
|
|
|
|
*
|
|
|
|
* \param irq_id kernel name of targeted interrupt
|
|
|
|
*/
|
|
|
|
static User_irq * object(unsigned const irq_id) {
|
|
|
|
return dynamic_cast<User_irq*>(_pool()->object(irq_id)); }
|
2013-10-30 13:56:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _KERNEL__IRQ_H_ */
|