2828#include <kernel/error.h>
2929#include <kernel/types.h>
3030
31+ #include <libalgo/linked_list.h>
32+
33+ /**
34+ * Values returned by an interrupt handler.
35+ */
36+ typedef enum interrupt_return {
37+ INTERRUPT_HANDLED , /*!< Interrupt was handled by the handler. */
38+ INTERRUPT_IGNORED , /*!< Interrupt was for another handler. */
39+ } interrupt_return_t ;
40+
3141/**
3242 * @brief Frame passed onto the interrupt handlers when triggering an interrupt
3343 * @note This is a only a forward declaration. The actual definition
3646typedef struct interrupt_frame interrupt_frame ;
3747
3848/** Function pointer to an interrupt handler */
39- typedef u32 (* interrupt_handler_func_t )(void * );
49+ typedef interrupt_return_t (* interrupt_handler_func_t )(void * );
50+
51+ struct interrupt_handler {
52+ interrupt_handler_func_t handler ;
53+ void * data ;
54+ node_t this ; /* used by interrupt_vector->handlers */
55+ };
4056
4157/** A single hardware IRQ vector. */
4258struct interrupt_vector {
43- interrupt_handler_func_t handler ;
44- void * data ;
45- const char * name ;
59+ const char * name ;
60+ llist_t handlers ;
4661};
4762
4863struct interrupt_chip {
@@ -56,24 +71,32 @@ struct interrupt_chip {
5671 * @param handler The handler function called when the interrupt occurs
5772 * @param data Data passed to the interrupt handler
5873 */
59- error_t interrupts_set_handler (unsigned int irq , interrupt_handler_func_t , void * );
74+ error_t
75+ interrupts_install_handler (unsigned int irq , interrupt_handler_func_t , void * );
76+
77+ /** Install a pre-configured interrupt handler.
78+ *
79+ * This function must be used only when configuring an interrupt handler
80+ * at before the virtual memory subsystem is initialized (INIT_BOOTSTRAP).
81+ *
82+ * The interrupt_handler strcuture is initialized and provided by the caller.
83+ */
84+ error_t
85+ interrupts_install_static_handler (unsigned int nr , struct interrupt_handler * );
6086
6187/** Retreive the current handler for a given IRQ
6288 *
6389 * @param irq The interrupt number
6490 * @param[out] pdata If not NULL, the handler's associated data is stored inside
6591 * this pointer (optional)
6692 *
93+ * @note In the case of shared interrupts this function always returns the first
94+ * installed handler.
95+ *
6796 * @return The current handler function fo the IRQ
6897 */
6998interrupt_handler_func_t interrupts_get_handler (unsigned int irq , void * * );
7099
71- /** Return wether a custom interrupt has been installed for the given vector */
72- static inline bool interrupts_has_been_installed (unsigned int irq )
73- {
74- return interrupts_get_handler (irq , NULL ) != NULL ;
75- }
76-
77100error_t interrupt_handle (unsigned int nr );
78101const char * interrupt_name (unsigned int nr );
79102
@@ -85,7 +108,7 @@ const char *interrupt_name(unsigned int nr);
85108 * You must always use this function when defining an interrupt handler.
86109 */
87110#define INTERRUPT_HANDLER_FUNCTION (_interrupt ) \
88- u32 INTERRUPT_HANDLER(_interrupt)(void *data)
111+ interrupt_return_t INTERRUPT_HANDLER(_interrupt)(void *data)
89112
90113/** @brief Disable interrupts on the current CPU. */
91114static inline void interrupts_disable (void )
0 commit comments