• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @defgroup interrupt Interrupt mechanism
17  * @ingroup linux
18  */
19 #ifndef _LINUX_INTERRUPT_H
20 #define _LINUX_INTERRUPT_H
21 
22 #include "linux/kernel.h"
23 #include "los_base.h"
24 #include "linux/workqueue.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 
30 #define IRQ_RETVAL(x)    ((x) != IRQ_NONE)
31 
32 /**
33  * These correspond to the IORESOURCE_IRQ_* defines in
34  * linux/ioport.h to select the interrupt line behaviour.
35  */
36 #define IRQF_TRIGGER_LOW      0x00000008
37 #define IRQF_TRIGGER_HIGH     0x00000004
38 #define IRQF_TRIGGER_FALLING  0x00000002
39 #define IRQF_TRIGGER_RISING   0x00000001
40 #define IRQF_TRIGGER_NONE     0x00000000
41 #define IRQF_TRIGGER_MASK     (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
42                                IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
43 #define IRQF_PROBE_SHARED     0x00000100
44 
45 #ifdef LOSCFG_ARCH_RISCV32
46 #define IRQ_DEFAULT_PRIORITY 0x1
47 #else
48 #define IRQ_DEFAULT_PRIORITY 0x0
49 #endif
50 
51 typedef enum irqreturn {
52     IRQ_NONE        = (0U << 0),  /* interrupt was not from this device. */
53     IRQ_HANDLED     = (1U << 0),  /* interrupt was handled by this device. */
54     IRQ_WAKE_THREAD = (1U << 1)   /* handler requests to wake the handler thread. */
55 } irqreturn_t;
56 
57 typedef irqreturn_t (*irq_handler_t)(int, void *);
58 
59 typedef struct irq_args {
60     int         iIrq;
61     void        *pDevId;
62     const char  *pName;
63 } irq_args;
64 
65 /**
66  * @ingroup interrupt
67  * @brief Request an interrupt.
68  *
69  * @par Description:
70  * This API is used to request the interrupt that has a specified interrupt ID and register an interrupt handler.
71  * @attention
72  * <ul>
73  * <li>The maximum number of interrupts supported by the OS Kernel is pre-configured
74  * (for details on how to pre-configure an appropriate upper threshold, see the reference document provided by
75  * the chip supplier). If the maximum number of interrupts is exceeded, the request fails.</li>
76  * <li>The value of registered interrupt handler must not be null.
77  * Devices that share a same interrupt ID must each be assigned a unique value of the dev parameter.</li>
78  * <li>The input parameter dev must be valid, otherwise, the system may be abnormal.</li>
79  * <li>The return value is inconsistent with the Linux standard interface definition.</li>
80  * </ul>
81  *
82  * @param irq     [IN] ID of the interrupt to be requested. [OS_USER_HWI_MIN, OS_USER_HWI_MAX].
83  * @param handler [IN] Interrupt handler to be registered.
84  * @param flags   [IN] Attributes of the interrupt processing, NOT used.
85  * @param name    [IN] Interrupt name.
86  * @param dev     [IN] Input parameter of the interrupt handler.
87  *
88  * @retval #LOS_ERRNO_HWI_PROC_FUNC_NULL    The hardware interrupt processing function is null.
89  * @retval #LOS_ERRNO_HWI_NUM_INVALID       The interrupt ID is invalid.
90  * @retval #LOS_ERRNO_HWI_NO_MEMORY         The memory is insufficient for creating a hardware interrupt.
91  * @retval #LOS_ERRNO_HWI_ALREADY_CREATED   The interrupt being created has already been created.
92  * @retval #LOS_ERRNO_HWI_SHARED_ERROR      The interrupt can not be shared.
93  * @retval #LOS_OK                          The interrupt request is accepted.
94  * @par Dependency:
95  * <ul><li>interrupt.h: the header file that contains the API declaration.</li></ul>
96  * @see free_irq
97  */
98 int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
99                 const char *name, void *dev);
100 
101 /**
102  * @ingroup interrupt
103  * @brief Delete an interrupt.
104  *
105  * @par Description:
106  * This API is used to delete the interrupt handler that has a specified input parameter.
107  * @attention
108  * <ul>
109  * <li>The maximum number of interrupts supported by the OS Kernel is pre-configured
110  * (for details on how to pre-configure an appropriate upper threshold, see the reference document provided by
111  * the chip supplier). If the maximum number of interrupts is exceeded, the interrupt fails to be deleted.</li>
112  * <li>Please make sure that the parameters irq and dev_id is that specified by calling request_irq(),
113  * or else delete an interrupt would be fails.</li>
114  * </ul>
115  *
116  * @param irq   [IN] ID of the interrupt to be deleted. [OS_USER_HWI_MIN, OS_USER_HWI_MAX].
117  * @param dev_id   [IN] Input parameter of the interrupt handler to be deleted.
118  *
119  * @retval None.
120  * @par Dependency:
121  * <ul><li>interrupt.h: the header file that contains the API declaration.</li></ul>
122  * @see request_irq
123  */
124 void free_irq(unsigned int irq, void *dev_id);
125 
126 /**
127  * @ingroup interrupt
128  * @brief Enable an interrupt.
129  *
130  * @par Description:
131  * This API is used to enable the interrupt that has a specified interrupt ID.
132  * @attention
133  * <ul>
134  * <li>The maximum number of interrupts supported by the OS Kernel is pre-configured
135  * (for details on how to pre-configure an appropriate upper threshold, see the reference document provided by
136  * the chip supplier). If the maximum number of interrupts is exceeded, the interrupt fails to be enabled.</li>
137  * <li>Please do make sure the specified irq has corresponding interrupt handler, otherwise,
138  * the system would do nothing  but only respond the specified interrupt if the specified interrupt is pending.</li>
139  * </ul>
140  *
141  * @param irq   [IN] ID of the interrupt to be enabled. [OS_USER_HWI_MIN, OS_USER_HWI_MAX].
142  *
143  * @retval None.
144  * @par Dependency:
145  * <ul><li>interrupt.h: the header file that contains the API declaration.</li></ul>
146  * @see disable_irq
147  */
148 void enable_irq(unsigned int irq);
149 
150 /**
151  * @ingroup interrupt
152  * @brief Disable an interrupt.
153  *
154  * @par Description:
155  * This API is used to disable the interrupt that has a specified interrupt ID.
156  * @attention
157  * <ul>
158  * <li>The maximum number of interrupts supported by the OS Kernel is pre-configured
159  * (for details on how to pre-configure an appropriate upper threshold, see the reference document provided by
160  * the chip supplier). If the maximum number of interrupts is exceeded, the interrupt fails to be disabled.</li>
161  * </ul>
162  *
163  * @param irq   [IN] ID of the interrupt to be disabled. [OS_USER_HWI_MIN, OS_USER_HWI_MAX].
164  *
165  * @retval None.
166  * @par Dependency:
167  * <ul><li>interrupt.h: the header file that contains the API declaration.</li></ul>
168  * @see enable_irq
169  */
170 void disable_irq(unsigned int irq);
171 
172 #ifdef __cplusplus
173 }
174 #endif /* __cplusplus */
175 
176 #endif /* _LINUX_INTERRUPT_H */
177