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 * Maximum number of supported hardware devices that generate hardware interrupts. 115 * The maximum number of hardware devices that generate hardware interrupts supported by hi3518ev200 is 32. 116 */ 117 #define OS_HWI_MAX_NUM OS_RISCV_VECTOR_CNT 118 119 /** 120 * Maximum interrupt number. 121 */ 122 #define OS_HWI_MAX ((OS_HWI_MAX_NUM) - 1) 123 124 /** 125 * Minimum interrupt number. 126 */ 127 #define OS_HWI_MIN 0 128 129 /** 130 * Maximum usable interrupt number. 131 */ 132 #define OS_USER_HWI_MAX OS_HWI_MAX 133 134 /** 135 * Minimum usable interrupt number. 136 */ 137 #define OS_USER_HWI_MIN OS_HWI_MIN 138 139 extern HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM]; 140 141 extern VOID HalHwiInit(VOID); 142 extern UINT32 HalGetHwiFormCnt(HWI_HANDLE_T hwiNum); 143 extern HWI_HANDLE_FORM_S *HalGetHwiForm(VOID); 144 extern VOID HalHwiInterruptDone(HWI_HANDLE_T hwiNum); 145 146 /** 147 * @ingroup los_arch_interrupt 148 * Hardware interrupt error code: Invalid interrupt number. 149 * 150 * Value: 0x02000900 151 * 152 * Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable 153 * for a risc-v platform is [0, OS_RISCV_VECTOR_CNT]. 154 */ 155 #define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) 156 157 /** 158 * @ingroup los_arch_interrupt 159 * Hardware interrupt error code: Null hardware interrupt handling function. 160 * 161 * Value: 0x02000901 162 * 163 * Solution: Pass in a valid non-null hardware interrupt handling function. 164 */ 165 #define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) 166 167 /** 168 * @ingroup los_arch_interrupt 169 * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. 170 * 171 * Value: 0x02000902 172 * 173 * Solution: Increase the configured maximum number of supported hardware interrupts. 174 */ 175 #define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) 176 177 /** 178 * @ingroup los_arch_interrupt 179 * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. 180 * 181 * Value: 0x02000903 182 * 183 * Solution: Expand the configured memory. 184 */ 185 #define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) 186 187 /** 188 * @ingroup los_arch_interrupt 189 * Hardware interrupt error code: The interrupt has already been created. 190 * 191 * Value: 0x02000904 192 * 193 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 194 */ 195 #define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) 196 197 /** 198 * @ingroup los_arch_interrupt 199 * Hardware interrupt error code: Invalid interrupt priority. 200 * 201 * Value: 0x02000905 202 * 203 * Solution: Ensure that the interrupt priority is valid. 204 */ 205 #define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) 206 207 /** 208 * @ingroup los_arch_interrupt 209 * Hardware interrupt error code: Incorrect interrupt creation mode. 210 * 211 * Value: 0x02000906 212 * 213 * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the 214 * value can be 0 or 1. 215 */ 216 #define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) 217 218 /** 219 * @ingroup los_arch_interrupt 220 * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. 221 * 222 * Value: 0x02000907 223 * 224 * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. 225 */ 226 #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) 227 228 /** 229 * @ingroup los_arch_interrupt 230 * Hardware interrupt error code: The API is called during an interrupt, which is forbidden. 231 * 232 * Value: 0x02000908 233 * 234 * * Solution: Do not call the API during an interrupt. 235 */ 236 #define OS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) 237 238 /** 239 * @ingroup los_arch_interrupt 240 * Hardware interrupt error code:the hwi support SHARED error. 241 * 242 * Value: 0x02000909 243 * 244 * * Solution:check the input params hwiMode and irqParam of ArchHwiCreate or ArchHwiDelete whether adapt the current 245 * hwi. 246 */ 247 #define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09) 248 249 /** 250 * @ingroup los_arch_interrupt 251 * Hardware interrupt error code:Invalid interrupt Arg when interrupt mode is IRQF_SHARED. 252 * 253 * Value: 0x0200090a 254 * 255 * * Solution:check the interrupt Arg, Arg should not be NULL and pDevId should not be NULL. 256 */ 257 #define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a) 258 259 /** 260 * @ingroup los_arch_interrupt 261 * Hardware interrupt error code:The interrupt corresponded to the hwi number or devid has not been created. 262 * 263 * Value: 0x0200090b 264 * 265 * * Solution:check the hwi number or devid, make sure the hwi number or devid need to delete. 266 */ 267 #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) 268 269 /* * 270 * @ingroup los_arch_interrupt 271 * Hardware interrupt error code: Invalid interrupt operation function. 272 * 273 * Value: 0x0200090c 274 * 275 * Solution: Set a valid interrupt operation function 276 */ 277 #define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) 278 279 extern UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp); 280 281 #ifdef __cplusplus 282 #if __cplusplus 283 } 284 #endif /* __cplusplus */ 285 #endif /* __cplusplus */ 286 287 #endif /* _LOS_ARCH_INTERRUPT_H */ 288