1 /* 2 * Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 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 #ifndef _LOS_ARCH_INTERRUPT_H 32 #define _LOS_ARCH_INTERRUPT_H 33 34 #include "los_compiler.h" 35 #include "los_config.h" 36 #include "los_interrupt.h" 37 #include "los_arch_context.h" 38 39 #ifdef __cplusplus 40 #if __cplusplus 41 extern "C" { 42 #endif /* __cplusplus */ 43 #endif /* __cplusplus */ 44 45 /** 46 * @ingroup los_arch_interrupt 47 * Define the type of a hardware interrupt vector table function. 48 */ 49 typedef struct tagHwiHandleForm { 50 HWI_PROC_FUNC pfnHook; 51 VOID *uwParam; 52 UINTPTR uwreserved; 53 } HWI_HANDLE_FORM_S; 54 55 typedef struct { 56 UINT32 mcause; 57 UINT32 mtval; 58 UINT32 medeleg; 59 UINT32 gp; 60 TaskContext taskContext; 61 } LosExcContext; 62 63 typedef struct { 64 UINT16 nestCnt; 65 UINT16 type; 66 UINT32 thrID; 67 LosExcContext *context; 68 } LosExcInfo; 69 70 /** 71 * @ingroup los_arch_interrupt 72 * Highest priority of a hardware interrupt. 73 */ 74 #define OS_HWI_PRIO_HIGHEST 7 75 76 /** 77 * @ingroup los_arch_interrupt 78 * Lowest priority of a hardware interrupt. 79 */ 80 #define OS_HWI_PRIO_LOWEST 1 81 82 /** 83 * @ingroup los_arch_interrupt 84 * Count of HimiDeer system interrupt vector. 85 */ 86 #define OS_RISCV_SYS_VECTOR_CNT (RISCV_SYS_MAX_IRQ + 1) 87 88 /** 89 * @ingroup los_arch_interrupt 90 * Count of HimiDeer local interrupt vector 0 - 5, enabled by CSR mie 26 -31 bit. 91 */ 92 #define OS_RISCV_MIE_IRQ_VECTOR_CNT 6 93 94 /** 95 * @ingroup los_arch_interrupt 96 * Count of HimiDeer local interrupt vector 6 - 31, enabled by custom CSR locie0 0 - 25 bit. 97 */ 98 #define OS_RISCV_CUSTOM_IRQ_VECTOR_CNT RISCV_PLIC_VECTOR_CNT 99 100 /** 101 * @ingroup los_arch_interrupt 102 * Count of HimiDeer local IRQ interrupt vector. 103 */ 104 #define OS_RISCV_LOCAL_IRQ_VECTOR_CNT (OS_RISCV_MIE_IRQ_VECTOR_CNT + OS_RISCV_SYS_VECTOR_CNT) 105 106 /** 107 * @ingroup los_arch_interrupt 108 * Count of himideer interrupt vector. 109 */ 110 #define OS_RISCV_VECTOR_CNT (OS_RISCV_SYS_VECTOR_CNT + OS_RISCV_CUSTOM_IRQ_VECTOR_CNT) 111 112 /** 113 * Maximum number of supported hardware devices that generate hardware interrupts. 114 * The maximum number of hardware devices that generate hardware interrupts supported by hi3518ev200 is 32. 115 */ 116 #define OS_HWI_MAX_NUM OS_RISCV_VECTOR_CNT 117 118 /** 119 * Maximum interrupt number. 120 */ 121 #define OS_HWI_MAX ((OS_HWI_MAX_NUM) - 1) 122 123 /** 124 * Minimum interrupt number. 125 */ 126 #define OS_HWI_MIN 0 127 128 /** 129 * Maximum usable interrupt number. 130 */ 131 #define OS_USER_HWI_MAX OS_HWI_MAX 132 133 /** 134 * Minimum usable interrupt number. 135 */ 136 #define OS_USER_HWI_MIN OS_HWI_MIN 137 138 extern HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM]; 139 140 extern VOID HalHwiInit(VOID); 141 extern UINT32 HalGetHwiFormCnt(HWI_HANDLE_T hwiNum); 142 extern HWI_HANDLE_FORM_S *HalGetHwiForm(VOID); 143 extern VOID HalHwiInterruptDone(HWI_HANDLE_T hwiNum); 144 extern VOID HalHwiDefaultHandler(VOID *arg); 145 146 extern UINT32 g_intCount; 147 148 /** 149 * @ingroup los_arch_interrupt 150 * Hardware interrupt error code: Invalid interrupt number. 151 * 152 * Value: 0x02000900 153 * 154 * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable 155 * for a risc-v platform is [0, OS_RISCV_VECTOR_CNT]. 156 */ 157 #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) 158 159 /** 160 * @ingroup los_arch_interrupt 161 * Hardware interrupt error code: Null hardware interrupt handling function. 162 * 163 * Value: 0x02000901 164 * 165 * Solution: Pass in a valid non-null hardware interrupt handling function. 166 */ 167 #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) 168 169 /** 170 * @ingroup los_arch_interrupt 171 * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. 172 * 173 * Value: 0x02000902 174 * 175 * Solution: Increase the configured maximum number of supported hardware interrupts. 176 */ 177 #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) 178 179 /** 180 * @ingroup los_arch_interrupt 181 * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. 182 * 183 * Value: 0x02000903 184 * 185 * Solution: Expand the configured memory. 186 */ 187 #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) 188 189 /** 190 * @ingroup los_arch_interrupt 191 * Hardware interrupt error code: The interrupt has already been created. 192 * 193 * Value: 0x02000904 194 * 195 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 196 */ 197 #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) 198 199 /** 200 * @ingroup los_arch_interrupt 201 * Hardware interrupt error code: Invalid interrupt priority. 202 * 203 * Value: 0x02000905 204 * 205 * Solution: Ensure that the interrupt priority is valid. 206 */ 207 #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) 208 209 /** 210 * @ingroup los_arch_interrupt 211 * Hardware interrupt error code: Incorrect interrupt creation mode. 212 * 213 * Value: 0x02000906 214 * 215 * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the 216 * value can be 0 or 1. 217 */ 218 #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) 219 220 /** 221 * @ingroup los_arch_interrupt 222 * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. 223 * 224 * Value: 0x02000907 225 * 226 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 227 */ 228 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) 229 230 /** 231 * @ingroup los_arch_interrupt 232 * Hardware interrupt error code: The API is called during an interrupt, which is forbidden. 233 * 234 * Value: 0x02000908 235 * 236 * * Solution: Do not call the API during an interrupt. 237 */ 238 #define OS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) 239 240 /** 241 * @ingroup los_arch_interrupt 242 * Hardware interrupt error code:the hwi support SHARED error. 243 * 244 * Value: 0x02000909 245 * 246 * * Solution:check the input params hwiMode and irqParam of ArchHwiCreate or ArchHwiDelete whether adapt the current 247 * hwi. 248 */ 249 #define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09) 250 251 /** 252 * @ingroup los_arch_interrupt 253 * Hardware interrupt error code:Invalid interrupt Arg when interrupt mode is IRQF_SHARED. 254 * 255 * Value: 0x0200090a 256 * 257 * * Solution:check the interrupt Arg, Arg should not be NULL and pDevId should not be NULL. 258 */ 259 #define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a) 260 261 /** 262 * @ingroup los_arch_interrupt 263 * Hardware interrupt error code:The interrupt corresponded to the hwi number or devid has not been created. 264 * 265 * Value: 0x0200090b 266 * 267 * * Solution:check the hwi number or devid, make sure the hwi number or devid need to delete. 268 */ 269 #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) 270 271 extern UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp); 272 273 #ifdef __cplusplus 274 #if __cplusplus 275 } 276 #endif /* __cplusplus */ 277 #endif /* __cplusplus */ 278 279 #endif /* _LOS_ARCH_INTERRUPT_H */ 280