• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3  * Copyright (c) 2021 Nuclei Limited. 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 #include <stdio.h>
33 #include <stdarg.h>
34 #include "los_arch.h"
35 #include "los_arch_interrupt.h"
36 #include "los_arch_context.h"
37 #include "los_task.h"
38 #include "los_debug.h"
39 #include "nuclei_sdk_hal.h"
40 
HwiUnmask(HWI_HANDLE_T hwiNum)41 STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum)
42 {
43     if (hwiNum >= OS_HWI_MAX_NUM) {
44         return OS_ERRNO_HWI_NUM_INVALID;
45     }
46 
47     ECLIC_EnableIRQ(hwiNum);
48 
49     return LOS_OK;
50 }
51 
HwiMask(HWI_HANDLE_T hwiNum)52 STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum)
53 {
54     if (hwiNum >= OS_HWI_MAX_NUM) {
55         return OS_ERRNO_HWI_NUM_INVALID;
56     }
57 
58     ECLIC_DisableIRQ(hwiNum);
59 
60     return LOS_OK;
61 }
62 
HwiSetPriority(HWI_HANDLE_T hwiNum,UINT8 priority)63 STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority)
64 {
65     if (hwiNum >= OS_HWI_MAX_NUM) {
66         return OS_ERRNO_HWI_NUM_INVALID;
67     }
68 
69     if (priority > OS_HWI_PRIO_HIGHEST || priority < OS_HWI_PRIO_LOWEST) {
70         return OS_ERRNO_HWI_PRIO_INVALID;
71     }
72 
73     ECLIC_SetPriorityIRQ(hwiNum, (hwiPrio & 0xffff));
74 
75     return LOS_OK;
76 }
77 
HalHwiInit(VOID)78 LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
79 {
80     // already setup interrupt vectors
81 }
82 
83 /*****************************************************************************
84  Function    : ArchHwiCreate
85  Description : create hardware interrupt
86  Input       : hwiNum       --- hwi num to create
87                hwiPrio      --- priority of the hwi
88                hwiMode      --- hwi interrupt hwiMode, between vector or non-vector
89                hwiHandler   --- hwi handler
90                irqParam     --- set trig hwiMode of the hwi handler
91                                 Level Triggerred = 0
92                                 Postive/Rising Edge Triggered = 1
93                                 Negtive/Falling Edge Triggered = 3
94  Output      : None
95  Return      : LOS_OK on success or error code on failure
96  *****************************************************************************/
ArchHwiCreate(HWI_HANDLE_T hwiNum,HWI_PRIOR_T hwiPrio,HWI_MODE_T hwiMode,HWI_PROC_FUNC hwiHandler,HwiIrqParam * irqParam)97 UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
98                      HWI_PRIOR_T hwiPrio,
99                      HWI_MODE_T hwiMode,
100                      HWI_PROC_FUNC hwiHandler,
101                      HwiIrqParam *irqParam)
102 {
103     if (hwiNum > SOC_INT_MAX) {
104         return OS_ERRNO_HWI_NUM_INVALID;
105     }
106     if (hwiMode > ECLIC_VECTOR_INTERRUPT) {
107         return OS_ERRNO_HWI_MODE_INVALID;
108     }
109     if ((irqParam == NULL) || (irqParam->pDevId > ECLIC_NEGTIVE_EDGE_TRIGGER)) {
110         return OS_ERRNO_HWI_ARG_INVALID;
111     }
112 
113     /* set interrupt vector hwiMode */
114     ECLIC_SetShvIRQ(hwiNum, hwiMode);
115     /* set interrupt trigger hwiMode and polarity */
116     ECLIC_SetTrigIRQ(hwiNum, irqParam->pDevId);
117     /* set interrupt level */
118     // default to 0
119     ECLIC_SetLevelIRQ(hwiNum, 0);
120     /* set interrupt priority */
121     // high 16 bit for level
122     ECLIC_SetLevelIRQ(hwiNum, (hwiPrio >> 16));
123     /* set interrupt priority */
124     // low 16 bit for priority
125     ECLIC_SetPriorityIRQ(hwiNum, (hwiPrio & 0xffff));
126     if (hwiHandler != NULL) {
127         /* set interrupt handler entry to vector table */
128         ECLIC_SetVector(hwiNum, (rv_csr_t)hwiHandler);
129     }
130     /* enable interrupt */
131     HwiUnmask(hwiNum);
132     return LOS_OK;
133 }
134 
135 /*****************************************************************************
136  Function    : ArchHwiDelete
137  Description : Delete hardware interrupt
138  Input       : hwiNum   --- hwi num to delete
139                irqParam --- param of the hwi handler
140  Return      : LOS_OK on success or error code on failure
141  *****************************************************************************/
ArchHwiDelete(HWI_HANDLE_T hwiNum,HwiIrqParam * irqParam)142 LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
143 {
144     (VOID)irqParam;
145     // change func to default func
146     ECLIC_SetVector(hwiNum, (rv_csr_t)HalHwiDefaultHandler);
147     // disable interrupt
148     HwiMask(hwiNum);
149     return LOS_OK;
150 }
151 
152 /* ****************************************************************************
153  Function    : HalDisplayTaskInfo
154  Description : display the task list
155  Input       : None
156  Output      : None
157  Return      : None
158  **************************************************************************** */
HalDisplayTaskInfo(VOID)159 VOID HalDisplayTaskInfo(VOID)
160 {
161     TSK_INFO_S taskInfo;
162     UINT32 index;
163     UINT32 ret;
164 
165     PRINTK("ID  Pri    Status     name \r\n");
166     PRINTK("--  ---    ---------  ----\r\n");
167 
168     for (index = 0; index < LOSCFG_BASE_CORE_TSK_LIMIT; index++) {
169         ret = LOS_TaskInfoGet(index, &taskInfo);
170         if (ret != LOS_OK) {
171             continue;
172         }
173         PRINTK("%d    %d     %s      %s \r\n",
174                taskInfo.uwTaskID, taskInfo.usTaskPrio, OsConvertTskStatus(taskInfo.usTaskStatus), taskInfo.acName);
175     }
176     return;
177 }
178 
179 /* ****************************************************************************
180  Function    : HalUnalignedAccessFix
181  Description : Unaligned access fixes are not supported by default
182  Input       : None
183  Output      : None
184  Return      : None
185  **************************************************************************** */
HalUnalignedAccessFix(UINTPTR mcause,UINTPTR mepc,UINTPTR mtval,VOID * sp)186 WEAK UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp)
187 {
188     /* Unaligned access fixes are not supported by default */
189     PRINTK("Unaligned access fixes are not support by default!\r\n");
190     return LOS_NOK;
191 }
192 
HalIntEnter(VOID)193 __attribute__((always_inline)) inline VOID HalIntEnter(VOID)
194 {
195     g_intCount += 1;
196 }
197 
HalIntExit(VOID)198 __attribute__((always_inline)) inline VOID HalIntExit(VOID)
199 {
200     g_intCount -= 1;
201 }
202 
203 STATIC HwiControllerOps g_archHwiOps = {
204     .enableIrq      = HwiUnmask,
205     .disableIrq     = HwiMask,
206     .setIrqPriority = HwiSetPriority,
207 };
208 
ArchIntOpsGet(VOID)209 HwiControllerOps *ArchIntOpsGet(VOID)
210 {
211     return &g_archHwiOps;
212 }
213