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