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