genode/repos/os/src/drivers/platform/spec/x86/irq.h

189 lines
4.6 KiB
C
Raw Normal View History

/*
* \brief IRQ session interface
* \author Alexander Boettcher
* \date 2015-03-25
*/
/*
* Copyright (C) 2015-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.
*/
#ifndef _X86__IRQ_H_
#define _X86__IRQ_H_
#include <base/rpc_server.h>
#include <base/allocator.h>
#include <util/list.h>
#include <irq_session/connection.h>
/* platform local includes */
#include <irq_proxy.h>
namespace Platform {
class Irq_session_component;
class Irq_override;
class Irq_routing;
}
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
class Platform::Irq_session_component : public Genode::Rpc_object<Genode::Irq_session>,
private Genode::List<Irq_session_component>::Element
{
private:
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
friend class Genode::List<Irq_session_component>;
unsigned _gsi;
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
Platform::Irq_sigh _irq_sigh { };
Genode::Irq_session::Info _msi_info { };
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
Genode::Constructible<Genode::Irq_connection> _irq_conn { };
public:
enum { INVALID_IRQ = 0xffU };
Irq_session_component(unsigned, Genode::addr_t, Genode::Env &,
Genode::Allocator &heap);
~Irq_session_component();
bool msi()
{
return _irq_conn.constructed() &&
_msi_info.type == Genode::Irq_session::Info::Type::MSI;
}
unsigned gsi() { return _gsi; }
unsigned long msi_address() const { return _msi_info.address; }
unsigned long msi_data() const { return _msi_info.value; }
/***************************
** Irq session interface **
***************************/
void ack_irq() override;
void sigh(Genode::Signal_context_capability) override;
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
Info info() override
{
return { .type = Info::Type::INVALID, .address = 0, .value = 0 };
}
};
/**
* List that holds interrupt override information
*/
class Platform::Irq_override : public Genode::List<Platform::Irq_override>::Element
{
private:
unsigned short _irq; /* source IRQ */
unsigned short _gsi; /* target GSI */
Genode::Irq_session::Trigger _trigger; /* interrupt trigger mode */
Genode::Irq_session::Polarity _polarity; /* interrupt polarity */
Genode::Irq_session::Trigger _mode2trigger(unsigned mode)
{
enum { EDGE = 0x4, LEVEL = 0xc };
switch (mode & 0xc) {
case EDGE:
return Genode::Irq_session::TRIGGER_EDGE;
case LEVEL:
return Genode::Irq_session::TRIGGER_LEVEL;
default:
return Genode::Irq_session::TRIGGER_UNCHANGED;
}
}
Genode::Irq_session::Polarity _mode2polarity(unsigned mode)
{
using namespace Genode;
enum { HIGH = 0x1, LOW = 0x3 };
switch (mode & 0x3) {
case HIGH:
return Genode::Irq_session::POLARITY_HIGH;
case LOW:
return Genode::Irq_session::POLARITY_LOW;
default:
return Genode::Irq_session::POLARITY_UNCHANGED;
}
}
public:
Irq_override(unsigned irq, unsigned gsi, unsigned mode)
:
_irq(irq), _gsi(gsi),
_trigger(_mode2trigger(mode)), _polarity(_mode2polarity(mode))
{ }
static Genode::List<Irq_override> *list()
{
static Genode::List<Irq_override> _list;
return &_list;
}
unsigned short irq() const { return _irq; }
unsigned short gsi() const { return _gsi; }
Genode::Irq_session::Trigger trigger() const { return _trigger; }
Genode::Irq_session::Polarity polarity() const { return _polarity; }
static unsigned irq_override (unsigned irq,
Genode::Irq_session::Trigger &trigger,
Genode::Irq_session::Polarity &polarity)
{
for (Irq_override *i = list()->first(); i; i = i->next())
if (i->irq() == irq) {
trigger = i->trigger();
polarity = i->polarity();
return i->gsi();
}
trigger = Genode::Irq_session::TRIGGER_UNCHANGED;
polarity = Genode::Irq_session::POLARITY_UNCHANGED;
return irq;
}
};
/**
* List that holds interrupt rewrite information
*/
class Platform::Irq_routing : public Genode::List<Platform::Irq_routing>::Element
{
private:
unsigned short _gsi;
unsigned short _bridge_bdf;
unsigned short _device;
unsigned char _device_pin;
public:
static Genode::List<Irq_routing> *list()
{
static Genode::List<Irq_routing> _list;
return &_list;
}
Irq_routing(unsigned short gsi, unsigned short bridge_bdf,
unsigned char device, unsigned char device_pin)
:
_gsi(gsi), _bridge_bdf(bridge_bdf), _device(device),
_device_pin(device_pin)
{ }
static unsigned short rewrite(unsigned char bus, unsigned char dev,
unsigned char func, unsigned char pin);
};
#endif /* _X86__IRQ_H_ */