• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: interrupt
15  *
16  * Create: 2021-12-16
17  */
18 
19 #include <los_hwi.h>
20 #include <hal_hwi.h>
21 #include <linux/interrupt.h>
22 #include "soc_osal.h"
23 #include "osal_errno.h"
24 #include "osal_inner.h"
25 
26 #define OSAL_IRQ_FLAG_PRI1    1
27 #define OSAL_IRQ_FLAG_PRI2    2
28 #define OSAL_IRQ_FLAG_PRI3    3
29 #define OSAL_IRQ_FLAG_PRI4    4
30 #define OSAL_IRQ_FLAG_PRI5    5
31 #define OSAL_IRQ_FLAG_PRI6    6
32 #define OSAL_IRQ_FLAG_PRI7    7
33 #define OSAL_IRQ_FLAG_PRI_MASK  0x7
34 #define OSAL_IRQ_FLAG_NOT_IN_FLASH 0x10
35 
36 #define OSAL_IRQ_FLAG_DEFAULT    OSAL_IRQ_FLAG_NOT_IN_FLASH
37 
38 #define MAX_IRQ_NAME_LEN 32
39 
40 #ifndef NULL
41 #define NULL ((void *)0)
42 #endif
43 
osal_irq_get_private_dev(void * param_dev)44 void *osal_irq_get_private_dev(void *param_dev)
45 {
46     if (param_dev == NULL) {
47         osal_log("param_dev is NULL!\n");
48         return NULL;
49     }
50     return ((HWI_IRQ_PARAM_S *)param_dev)->pDevId;
51 }
52 
osal_irq_request(unsigned int irq,osal_irq_handler handler,osal_irq_handler thread_fn,const char * name,void * dev)53 int osal_irq_request(unsigned int irq, osal_irq_handler handler, osal_irq_handler thread_fn,
54     const char *name, void *dev)
55 {
56     if (handler == NULL) {
57         osal_log("handler is NULL !\n");
58         return OSAL_FAILURE;
59     }
60 
61     HWI_IRQ_PARAM_S param = {
62         .pDevId = dev,
63         .pName = name,
64         .swIrq = irq,
65     };
66     int ret = LOS_HwiCreate(irq, OS_HWI_PRIO_IGNORE, 0, (HWI_PROC_FUNC)handler, &param);
67     if (ret != LOS_OK) {
68         osal_log("LOS_HwiCreate failed! irq[%u] ret = %#x.\n", irq, ret);
69         return OSAL_FAILURE;
70     }
71 
72     return OSAL_SUCCESS;
73 }
74 
osal_irq_free(unsigned int irq,void * dev)75 void osal_irq_free(unsigned int irq, void *dev)
76 {
77     osal_unused(dev);
78     int ret = LOS_HwiDelete(irq, 0);
79     if (ret != LOS_OK) {
80         osal_log("LOS_HwiDelete failed! ret = %#x.\n", ret);
81     }
82 }
83 
osal_irq_set_affinity(unsigned int irq,const char * name,int cpu_mask)84 int osal_irq_set_affinity(unsigned int irq, const char *name, int cpu_mask)
85 {
86     return 0;
87 }
88 
osal_in_interrupt(void)89 int osal_in_interrupt(void)
90 {
91     return (OS_INT_ACTIVE);
92 }
93 
osal_irq_enable(unsigned int irq)94 void osal_irq_enable(unsigned int irq)
95 {
96     unsigned int ret = LOS_HwiEnable(irq);
97     if (ret != LOS_OK) {
98         if (ret == OS_ERRNO_HWI_HWINUM_UNCREATE) {
99             osal_log("OS_ERRNO_HWI_HWINUM_UNCREATE!\n");
100         } else {
101             osal_log("LOS_HwiDelete failed! ret = %#x.\n", ret);
102         }
103     }
104     dsb();
105 }
106 
107 /**
108  * @par Description:
109  * Disable the corresponding interrupt mask of the interrupt controller,
110  * so that the interrupt source can be sent to the CPU.
111  *
112  * @attention
113  * This function depends on the hardware implementation of the interrupt controller.
114  */
osal_irq_disable(unsigned int irq)115 void osal_irq_disable(unsigned int irq)
116 {
117     LOS_HwiDisable(irq);
118     dsb();
119 }
120 
osal_irq_lock(void)121 unsigned int osal_irq_lock(void)
122 {
123     unsigned int ret = LOS_IntLock();
124 #ifdef OSAL_IRQ_RECORD_DEBUG
125     osal_irq_record(IRQ_LOCK, (td_u32)__builtin_return_address(0), ret);
126 #endif
127     dsb();
128     return ret;
129 }
130 
osal_irq_unlock(void)131 unsigned int osal_irq_unlock(void)
132 {
133 #ifdef OSAL_IRQ_RECORD_DEBUG
134     osal_irq_record(IRQ_UNLOCK, (td_u32)__builtin_return_address(0), 0);
135 #endif
136     unsigned int  ret = LOS_IntUnLock();
137     dsb();
138     return ret;
139 }
140 
osal_irq_restore(unsigned int irq_status)141 void osal_irq_restore(unsigned int irq_status)
142 {
143 #ifdef OSAL_IRQ_RECORD_DEBUG
144     osal_irq_record(IRQ_RESTORE, (td_u32)__builtin_return_address(0), irq_status);
145 #endif
146     LOS_IntRestore(irq_status);
147     dsb();
148 }
149 
osal_irq_set_priority(unsigned int irq,unsigned short priority)150 int osal_irq_set_priority(unsigned int irq, unsigned short priority)
151 {
152     unsigned int ret = LOS_HwiSetPriority(irq, priority);
153     if (ret != LOS_OK) {
154         return OSAL_FAILURE;
155     }
156     return OSAL_SUCCESS;
157 }
158 
osal_irq_clear(unsigned int vector)159 unsigned int osal_irq_clear(unsigned int vector)
160 {
161     unsigned int ret = LOS_HwiClear(vector);
162     if (ret != LOS_OK) {
163         return OSAL_FAILURE;
164     }
165     dsb();
166     return OSAL_SUCCESS;
167 }
168 
169 /* tasklet is running only on one CPU simultaneously */
osal_tasklet_init(osal_tasklet * tasklet)170 int osal_tasklet_init(osal_tasklet *tasklet)
171 {
172     osal_unused(tasklet);
173     osal_log("not supported.\n");
174     return 0;
175 }
176 
177 /*
178  * tasklet update should be called after tasklet init
179  **/
osal_tasklet_update(osal_tasklet * tasklet)180 int osal_tasklet_update(osal_tasklet *tasklet)
181 {
182     osal_unused(tasklet);
183     return 0;
184 }
185 
186 /*
187  * add tasklet to tasklet_osal_vec and start tasklet
188  **/
osal_tasklet_schedule(osal_tasklet * tasklet)189 int osal_tasklet_schedule(osal_tasklet *tasklet)
190 {
191     osal_unused(tasklet);
192     return 0;
193 }
194 
195 /* kill tasklet */
osal_tasklet_kill(osal_tasklet * tasklet)196 int osal_tasklet_kill(osal_tasklet *tasklet)
197 {
198     osal_unused(tasklet);
199     osal_log("not supported.\n");
200     return 0;
201 }
202