• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LOS_ARCH_INTERRUPT_H
33 #define _LOS_ARCH_INTERRUPT_H
34 
35 #include "los_common_interrupt.h"
36 
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 #endif /* __cplusplus */
42 
43 /* *
44  * @ingroup los_arch_interrupt
45  * Highest priority of a hardware interrupt.
46  */
47 #ifndef OS_HWI_PRIO_HIGHEST
48 #define OS_HWI_PRIO_HIGHEST                   0
49 #endif
50 
51 /* *
52  * @ingroup los_arch_interrupt
53  * Lowest priority of a hardware interrupt.
54  */
55 #ifndef OS_HWI_PRIO_LOWEST
56 #define OS_HWI_PRIO_LOWEST                    3
57 #endif
58 
59 /* *
60  * @ingroup  los_arch_interrupt
61  * Check the interrupt priority.
62  */
63 #define HWI_PRI_VALID(pri)              (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
64 
65 /* *
66  * @ingroup los_arch_interrupt
67  * Count of C-sky system interrupt vector.
68  */
69 #define OS_SYS_VECTOR_CNT                     32
70 
71 /* *
72  * @ingroup los_arch_interrupt
73  * Count of C-sky interrupt vector.
74  */
75 #define OS_VECTOR_CNT                         (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
76 
77 #define OS_USER_HWI_MIN                 0
78 #define OS_USER_HWI_MAX                 (LOSCFG_PLATFORM_HWI_LIMIT - 1)
79 
80 #define HWI_ALIGNSIZE                   0x400
81 
82 #define PSR_VEC_OFFSET                         16U
83 #define VIC_REG_BASE                           0xE000E100UL
84 
85 typedef struct {
86     UINT32 ISER[4U];
87     UINT32 RESERVED0[12U];
88     UINT32 IWER[4U];
89     UINT32 RESERVED1[12U];
90     UINT32 ICER[4U];
91     UINT32 RESERVED2[12U];
92     UINT32 IWDR[4U];
93     UINT32 RESERVED3[12U];
94     UINT32 ISPR[4U];
95     UINT32 RESERVED4[12U];
96     UINT32 ISSR[4U];
97     UINT32 RESERVED5[12U];
98     UINT32 ICPR[4U];
99     UINT32 RESERVED6[12U];
100     UINT32 ICSR[4U];
101     UINT32 RESERVED7[12U];
102     UINT32 IABR[4U];
103     UINT32 RESERVED8[60U];
104     UINT32 IPR[32U];
105     UINT32 RESERVED9[480U];
106     UINT32 ISR;
107     UINT32 IPTR;
108     UINT32 TSPEND;
109     UINT32 TSABR;
110     UINT32 TSPR;
111 } VIC_TYPE;
112 
113 extern VIC_TYPE *VIC_REG;
114 /* *
115  * @ingroup los_arch_interrupt
116  * Hardware interrupt error code: Invalid interrupt number.
117  *
118  * Value: 0x02000900
119  *
120  * Solution: Ensure that the interrupt number is valid.
121  */
122 #define OS_ERRNO_HWI_NUM_INVALID              LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
123 
124 /* *
125  * @ingroup los_arch_interrupt
126  * Hardware interrupt error code: Null hardware interrupt handling function.
127  *
128  * Value: 0x02000901
129  *
130  * Solution: Pass in a valid non-null hardware interrupt handling function.
131  */
132 #define OS_ERRNO_HWI_PROC_FUNC_NULL           LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
133 
134 /* *
135  * @ingroup los_arch_interrupt
136  * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
137  *
138  * Value: 0x02000902
139  *
140  * Solution: Increase the configured maximum number of supported hardware interrupts.
141  */
142 #define OS_ERRNO_HWI_CB_UNAVAILABLE           LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
143 
144 /* *
145  * @ingroup los_arch_interrupt
146  * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
147  *
148  * Value: 0x02000903
149  *
150  * Solution: Expand the configured memory.
151  */
152 #define OS_ERRNO_HWI_NO_MEMORY                LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
153 
154 /* *
155  * @ingroup los_arch_interrupt
156  * Hardware interrupt error code: The interrupt has already been created.
157  *
158  * Value: 0x02000904
159  *
160  * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
161  */
162 #define OS_ERRNO_HWI_ALREADY_CREATED          LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
163 
164 /* *
165  * @ingroup los_arch_interrupt
166  * Hardware interrupt error code: Invalid interrupt priority.
167  *
168  * Value: 0x02000905
169  *
170  * Solution: Ensure that the interrupt priority is valid.
171  */
172 #define OS_ERRNO_HWI_PRIO_INVALID             LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
173 
174 /* *
175  * @ingroup los_arch_interrupt
176  * Hardware interrupt error code: Incorrect interrupt creation mode.
177  *
178  * Value: 0x02000906
179  *
180  * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST.
181  */
182 #define OS_ERRNO_HWI_MODE_INVALID             LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
183 
184 /* *
185  * @ingroup los_arch_interrupt
186  * Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
187  *
188  * Value: 0x02000907
189  *
190  * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
191  */
192 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
193 
194 /* *
195  * @ingroup los_arch_interrupt
196  * Hardware interrupt error code: Invalid interrupt operation function.
197  *
198  * Value: 0x0200090c
199  *
200  * Solution: Set a valid interrupt operation function
201  */
202 #define OS_ERRNO_HWI_OPS_FUNC_NULL            LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c)
203 
204 /* *
205  * @ingroup los_arch_interrupt
206  * Hardware interrupt error code: Invalid interrupt number.
207  *
208  * Value: 0x02000900
209  *
210  * Solution: Ensure that the interrupt number is valid.
211  */
212 #define LOS_ERRNO_HWI_NUM_INVALID             OS_ERRNO_HWI_NUM_INVALID
213 
214 /* *
215  * @ingroup  los_arch_interrupt
216  * @brief: Hardware interrupt entry function.
217  *
218  * @par Description:
219  * This API is used as all hardware interrupt handling function entry.
220  *
221  * @attention:
222  * <ul><li>None.</li></ul>
223  *
224  * @param:None.
225  *
226  * @retval:None.
227  * @par Dependency:
228  * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
229  * @see None.
230  */
231 extern VOID HalInterrupt(VOID);
232 
233 #define OS_VIC_INT_ENABLE_SIZE             0x4
234 #define OS_VIC_INT_WAKER_SIZE              0x4
235 #define OS_VIC_INT_ICER_SIZE               0x4
236 #define OS_VIC_INT_ISPR_SIZE               0x4
237 #define OS_VIC_INT_IABR_SIZE               0x4
238 #define OS_VIC_INT_IPR_SIZE                0x4
239 #define OS_VIC_INT_ISR_SIZE                0x4
240 #define OS_VIC_INT_IPTR_SIZE               0x4
241 
242 /**
243  * @ingroup los_exc
244  * the struct of register files
245  *
246  * description: the register files that saved when exception triggered
247  *
248  * notes:the following register with prefix 'uw'  correspond to the registers in the cpu  data sheet.
249  */
250 typedef struct TagExcContext {
251     UINT32 R0;
252     UINT32 R1;
253     UINT32 R2;
254     UINT32 R3;
255     UINT32 R4;
256     UINT32 R5;
257     UINT32 R6;
258     UINT32 R7;
259     UINT32 R8;
260     UINT32 R9;
261     UINT32 R10;
262     UINT32 R11;
263     UINT32 R12;
264     UINT32 R13;
265     UINT32 R14;
266     UINT32 R15;
267     UINT32 EPSR;
268     UINT32 EPC;
269 } EXC_CONTEXT_S;
270 
271 /* *
272  * @ingroup  los_arch_interrupt
273  * @brief: Exception handler function.
274  *
275  * @par Description:
276  * This API is used to handle Exception.
277  *
278  * @attention:
279  * <ul><li>None.</li></ul>
280  *
281  * @param  excBufAddr     [IN] The address of stack pointer at which the error occurred.
282  * @param  faultAddr      [IN] The address at which the error occurred.
283  *
284  * @retval:None.
285  * @par Dependency:
286  * <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
287  * @see None.
288  */
289 LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr);
290 
291 VOID IrqEntry(VOID);
292 
293 VOID HandleEntry(VOID);
294 
295 VOID HalHwiInit(VOID);
296 
297 /**
298  * @ingroup los_exc
299  * Exception information structure
300  *
301  * Description: Exception information saved when an exception is triggered on the Csky platform.
302  *
303  */
304 typedef struct TagExcInfo {
305     UINT16 phase;
306     UINT16 type;
307     UINT32 faultAddr;
308     UINT32 thrdPid;
309     UINT16 nestCnt;
310     UINT16 reserved;
311     EXC_CONTEXT_S *context;
312 } ExcInfo;
313 
314 extern ExcInfo g_excInfo;
315 
316 #define MAX_INT_INFO_SIZE       (8 + 0x164)
317 
318 #ifdef __cplusplus
319 #if __cplusplus
320 }
321 #endif /* __cplusplus */
322 #endif /* __cplusplus */
323 
324 #endif /* _LOS_ARCH_INTERRUPT_H */
325