1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "osal_irq.h"
32 #include "los_hwi.h"
33 #include "hdf_log.h"
34
35 #define OSAL_LOG_TAG osal_irq
36
OsalRegisterIrq(uint32_t irqId,uint32_t config,OsalIRQHandle handle,const char * name,void * dev)37 int32_t OsalRegisterIrq(uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char *name, void *dev)
38 {
39 uint32_t ret;
40 HwiIrqParam irqParam;
41
42 if (irqId >= OS_HWI_MAX_NUM) {
43 HDF_LOGE("invalid irq number %d\n", irqId);
44 return HDF_ERR_INVALID_PARAM;
45 }
46
47 irqParam.swIrq = (INT32)irqId;
48 irqParam.pDevId = dev;
49 irqParam.pName = name;
50 ret = LOS_HwiCreate(irqId, 0, (HWI_MODE_T)config, (HWI_PROC_FUNC)handle, &irqParam);
51 if (ret != LOS_OK) {
52 HDF_LOGE("%s %d register fail 0x%x", __func__, irqId, ret);
53 return HDF_FAILURE;
54 }
55 HalIrqUnmask(irqId);
56
57 return HDF_SUCCESS;
58 }
59
OsalUnregisterIrq(uint32_t irqId,void * dev)60 int32_t OsalUnregisterIrq(uint32_t irqId, void *dev)
61 {
62 uint32_t ret;
63 HwiIrqParam irqParam;
64
65 if (irqId >= OS_HWI_MAX_NUM) {
66 HDF_LOGE("invalid irq number %d\n", irqId);
67 return HDF_ERR_INVALID_PARAM;
68 }
69
70 irqParam.swIrq = (INT32)irqId;
71 irqParam.pDevId = dev;
72 ret = LOS_HwiDelete(irqId, &irqParam);
73 if (ret != LOS_OK) {
74 HDF_LOGE("irq %d unregister fail %d\n", irqId, ret);
75 return HDF_FAILURE;
76 }
77
78 return HDF_SUCCESS;
79 }
80
OsalEnableIrq(uint32_t irqId)81 int32_t OsalEnableIrq(uint32_t irqId)
82 {
83 if (irqId >= OS_HWI_MAX_NUM) {
84 HDF_LOGE("invalid irq number %d\n", irqId);
85 return HDF_ERR_INVALID_PARAM;
86 }
87
88 HalIrqUnmask(irqId);
89
90 return HDF_SUCCESS;
91 }
92
OsalDisableIrq(uint32_t irqId)93 int32_t OsalDisableIrq(uint32_t irqId)
94 {
95 if (irqId >= OS_HWI_MAX_NUM) {
96 HDF_LOGE("invalid irq number %d\n", irqId);
97 return HDF_ERR_INVALID_PARAM;
98 }
99
100 HalIrqMask(irqId);
101
102 return HDF_SUCCESS;
103 }
104
105