RTEMS 6.1-rc4
Loading...
Searching...
No Matches
genirq.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* General Shared Interrupt handling function interface
4 *
5 * The functions does not manipulate the IRQ controller or the
6 * interrupt level of the CPU. It simply helps the caller with
7 * managing shared interrupts where multiple interrupt routines
8 * share on interrupt vector/number.
9 *
10 * COPYRIGHT (c) 2008.
11 * Cobham Gaisler AB.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef __GENIRQ_H__
36#define __GENIRQ_H__
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42typedef void (*genirq_handler)(void *arg);
43typedef void* genirq_t;
44
46 unsigned int irq_cnt;
47};
48
49/* Initialize the genirq interface. Must be the first function
50 * called.
51 *
52 * Returns zero on success, otherwise failure.
53 */
54extern genirq_t genirq_init(int number_of_irqs);
55
56/* Free the dynamically allocated memory that the genirq interface has
57 * allocated. Also the handlers will be freed.
58 *
59 * Returns zero on success, otherwise failure.
60 */
61extern void genirq_destroy(genirq_t d);
62
63/* Check IRQ number validity
64 *
65 * Returns zero for valid IRQ numbers, -1 of invalid IRQ numbers.
66 */
67extern int genirq_check(genirq_t d, int irq);
68
69/* Allocate one ISR handler and initialize it. Input to genirq_register().
70 *
71 * \param isr The interrupt service routine called upon IRQ
72 * \param arg The argument given to isr() when called.
73 *
74 * Returns a pointer on success, on failure NULL is returned.
75 */
76extern void *genirq_alloc_handler(genirq_handler isr, void *arg);
77
78/* Free handler memory */
79#define genirq_free_handler(handler) free(handler)
80
81/* Register shared interrupt handler previously initialized with
82 * genirq_alloc_handler().
83 *
84 * NOTE: internal list structures are accessed and needs to be protected by
85 * spin-locks/IRQ disable by the user to guarantee a correct behaviour.
86 *
87 * \param irq The interrupt number to register ISR on
88 * \param handler Install the pre- allocated and initialized handler.
89 *
90 * Return Values
91 * -1 = Failed
92 * 0 = Handler registered Successfully, first handler on this IRQ
93 * 1 = Handler registered Successfully, _not_ first handler on this IRQ
94 */
95extern int genirq_register(genirq_t d, int irq, void *handler);
96
97/* Unregister an previous registered interrupt handler. It is the user's
98 * responsibility to free the handler returned by genirq_unregister().
99 *
100 * NOTE: internal list structures are accessed and needs to be protected by
101 * spin-locks/IRQ disable by the user to guarantee a correct behaviour.
102 *
103 * Return Values
104 * NULL = ISR not registered before or unable to unregister enabled ISR
105 * Pointer = ISR sucessfully unregistered. Returned is the handler pointer
106 * previously allocated with genirq_alloc_handler().
107 */
108extern void *genirq_unregister(genirq_t d, int irq,
109 genirq_handler isr, void *arg);
110
111/* Enables IRQ only for this isr[arg] combination. Records if this
112 * is the first interrupt enable, only then must interrupts be enabled
113 * on the interrupt controller.
114 *
115 * NOTE: internal list structures are accessed and needs to be protected by
116 * spin-locks/IRQ disable by the user to guarantee a correct behaviour.
117 *
118 * Return values
119 * -1 = Failure, for example isr[arg] not registered on this irq
120 * 0 = IRQ must be enabled, it is the first IRQ handler to be enabled
121 * 1 = IRQ has already been enabled, either by isr[arg] or by another handler
122 */
123extern int genirq_enable(genirq_t d, int irq, genirq_handler isr, void *arg);
124
125/* Disables IRQ only for this isr[arg] combination. Records if this
126 * is the only interrupt handler that is enabled on this IRQ, only then
127 * must interrupts be disabled on the interrupt controller.
128 *
129 * NOTE: internal list structures are accessed and needs to be protected by
130 * spin-locks/IRQ disable by the user to guarantee a correct behaviour.
131 *
132 * Return values
133 * -1 = Failure, for example isr[arg] not registered on this irq
134 * 0 = IRQ must be disabled, no ISR are enabled for this IRQ
135 * 1 = ISR has already been disabled, or other ISRs are still enabled
136 */
137extern int genirq_disable(genirq_t d, int irq, genirq_handler isr, void *arg);
138
139/* Must be called by user when an IRQ has fired, the argument 'irq'
140 * is the IRQ number of the IRQ which was fired.
141 *
142 * NOTE: internal list structures are accessed and needs to be protected by
143 * spin-locks/IRQ disable by the user to guarantee a correct behaviour.
144 */
145extern void genirq_doirq(genirq_t d, int irq);
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif
Definition: genirq.h:45