From 81c25c6d542a9c3b18c34a565bb479bc80861889 Mon Sep 17 00:00:00 2001 From: zhangdengyu Date: Thu, 15 Jun 2023 15:54:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96csky/xtensa/riscv?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E4=B8=AD=E6=96=AD=E7=AE=A1=E7=90=86=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方案描述: 1、在最外层arch/include/los_interrupt.h中定义数据结构、声明对外接口; 2、在arch/xxx/common实现xxx架构中断通用的接口定义与声明; 3、在arch/xxx/yyy中实现针对xxx架构的差异化实现; 4、修改宏数值,适配整个中断管理框架 BREAKING CHANGE: 优化csky/xtensa/riscv架构中断管理框架对外变更描述: 1、宏OS_ERRNO_HWI_OPS_FUNC_NULL数值改为0x0200090c Close: #I7DRTP Signed-off-by: zhangdengyu Change-Id: Ic7cab8222ceab846b2557ff9047f7c6cd34b2b44 --- arch/arm/arm9/gcc/los_arch_interrupt.h | 4 +- arch/arm/cortex-m3/keil/los_arch_interrupt.h | 4 +- .../cortex-m33/gcc/NTZ/los_arch_interrupt.h | 4 +- .../gcc/TZ/non_secure/los_arch_interrupt.h | 4 +- .../cortex-m33/iar/NTZ/los_arch_interrupt.h | 4 +- .../iar/TZ/non_secure/los_arch_interrupt.h | 4 +- arch/arm/cortex-m4/gcc/los_arch_interrupt.h | 4 +- arch/arm/cortex-m4/iar/los_arch_interrupt.h | 4 +- .../cortex-m55/gcc/NTZ/los_arch_interrupt.h | 4 +- .../gcc/TZ/non_secure/los_arch_interrupt.h | 4 +- .../cortex-m55/iar/NTZ/los_arch_interrupt.h | 4 +- .../iar/TZ/non_secure/los_arch_interrupt.h | 4 +- arch/arm/cortex-m7/gcc/los_arch_interrupt.h | 4 +- arch/arm/cortex-m7/iar/los_arch_interrupt.h | 4 +- arch/csky/BUILD.gn | 7 +- arch/csky/common/BUILD.gn | 39 +++ arch/csky/common/los_common_interrupt.c | 289 ++++++++++++++++++ arch/csky/common/los_common_interrupt.h | 116 +++++++ arch/csky/v2/gcc/los_arch_interrupt.h | 82 ++--- arch/csky/v2/gcc/los_interrupt.c | 218 ++----------- arch/include/los_interrupt.h | 60 ---- arch/risc-v/BUILD.gn | 5 +- arch/risc-v/common/BUILD.gn | 39 +++ arch/risc-v/common/los_common_interrupt.c | 103 +++++++ arch/risc-v/common/los_common_interrupt.h | 60 ++++ arch/risc-v/nuclei/gcc/los_arch_interrupt.h | 24 +- arch/risc-v/nuclei/gcc/los_interrupt.c | 29 +- arch/risc-v/riscv32/gcc/los_arch_interrupt.h | 19 +- arch/risc-v/riscv32/gcc/los_interrupt.c | 22 +- arch/xtensa/BUILD.gn | 7 +- arch/xtensa/common/BUILD.gn | 39 +++ arch/xtensa/common/los_common_interrupt.c | 275 +++++++++++++++++ arch/xtensa/common/los_common_interrupt.h | 97 ++++++ arch/xtensa/lx6/gcc/los_arch_interrupt.h | 47 +-- arch/xtensa/lx6/gcc/los_interrupt.c | 211 ++----------- arch/xtensa/lx6/gcc/los_timer.c | 8 +- 36 files changed, 1204 insertions(+), 648 deletions(-) create mode 100644 arch/csky/common/BUILD.gn create mode 100644 arch/csky/common/los_common_interrupt.c create mode 100644 arch/csky/common/los_common_interrupt.h create mode 100644 arch/risc-v/common/BUILD.gn create mode 100644 arch/risc-v/common/los_common_interrupt.c create mode 100644 arch/risc-v/common/los_common_interrupt.h create mode 100644 arch/xtensa/common/BUILD.gn create mode 100644 arch/xtensa/common/los_common_interrupt.c create mode 100644 arch/xtensa/common/los_common_interrupt.h diff --git a/arch/arm/arm9/gcc/los_arch_interrupt.h b/arch/arm/arm9/gcc/los_arch_interrupt.h index 5c16c386..b0389662 100644 --- a/arch/arm/arm9/gcc/los_arch_interrupt.h +++ b/arch/arm/arm9/gcc/los_arch_interrupt.h @@ -155,11 +155,11 @@ extern "C" { * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m3/keil/los_arch_interrupt.h b/arch/arm/cortex-m3/keil/los_arch_interrupt.h index 951a875d..48db4e62 100644 --- a/arch/arm/cortex-m3/keil/los_arch_interrupt.h +++ b/arch/arm/cortex-m3/keil/los_arch_interrupt.h @@ -169,11 +169,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h index d5139441..a42a8922 100644 --- a/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h +++ b/arch/arm/cortex-m33/gcc/NTZ/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h index d5139441..a42a8922 100644 --- a/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h +++ b/arch/arm/cortex-m33/gcc/TZ/non_secure/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h index 71b61dd0..ac8820e9 100644 --- a/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h +++ b/arch/arm/cortex-m33/iar/NTZ/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h index 71b61dd0..ac8820e9 100644 --- a/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h +++ b/arch/arm/cortex-m33/iar/TZ/non_secure/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m4/gcc/los_arch_interrupt.h b/arch/arm/cortex-m4/gcc/los_arch_interrupt.h index 046f789a..d4685366 100644 --- a/arch/arm/cortex-m4/gcc/los_arch_interrupt.h +++ b/arch/arm/cortex-m4/gcc/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m4/iar/los_arch_interrupt.h b/arch/arm/cortex-m4/iar/los_arch_interrupt.h index 0bb41f38..8b4f9763 100644 --- a/arch/arm/cortex-m4/iar/los_arch_interrupt.h +++ b/arch/arm/cortex-m4/iar/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h index c498aaf4..c2c21ec8 100644 --- a/arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h +++ b/arch/arm/cortex-m55/gcc/NTZ/los_arch_interrupt.h @@ -160,11 +160,11 @@ extern "C" { * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_arch_interrupt.h index 77b3bda4..7471b652 100644 --- a/arch/arm/cortex-m55/gcc/TZ/non_secure/los_arch_interrupt.h +++ b/arch/arm/cortex-m55/gcc/TZ/non_secure/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m55/iar/NTZ/los_arch_interrupt.h b/arch/arm/cortex-m55/iar/NTZ/los_arch_interrupt.h index 70c8754f..1457700a 100644 --- a/arch/arm/cortex-m55/iar/NTZ/los_arch_interrupt.h +++ b/arch/arm/cortex-m55/iar/NTZ/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m55/iar/TZ/non_secure/los_arch_interrupt.h b/arch/arm/cortex-m55/iar/TZ/non_secure/los_arch_interrupt.h index 70c8754f..1457700a 100644 --- a/arch/arm/cortex-m55/iar/TZ/non_secure/los_arch_interrupt.h +++ b/arch/arm/cortex-m55/iar/TZ/non_secure/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m7/gcc/los_arch_interrupt.h b/arch/arm/cortex-m7/gcc/los_arch_interrupt.h index fbe8698b..257bbd0d 100644 --- a/arch/arm/cortex-m7/gcc/los_arch_interrupt.h +++ b/arch/arm/cortex-m7/gcc/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/arm/cortex-m7/iar/los_arch_interrupt.h b/arch/arm/cortex-m7/iar/los_arch_interrupt.h index e0896865..2a7548e0 100644 --- a/arch/arm/cortex-m7/iar/los_arch_interrupt.h +++ b/arch/arm/cortex-m7/iar/los_arch_interrupt.h @@ -167,11 +167,11 @@ extern UINT32 _BootVectors[]; * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt operation function. * - * Value: 0x02000908 + * Value: 0x0200090c * * Solution: Set a valid interrupt operation function */ -#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) /* * * @ingroup los_arch_interrupt diff --git a/arch/csky/BUILD.gn b/arch/csky/BUILD.gn index d0884ff5..0afcae19 100644 --- a/arch/csky/BUILD.gn +++ b/arch/csky/BUILD.gn @@ -1,5 +1,5 @@ # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -30,5 +30,8 @@ import("//kernel/liteos_m/liteos.gni") module_group("csky") { - modules = [ "v2/gcc" ] + modules = [ + "common", + "v2/gcc", + ] } diff --git a/arch/csky/common/BUILD.gn b/arch/csky/common/BUILD.gn new file mode 100644 index 00000000..763b9c9d --- /dev/null +++ b/arch/csky/common/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +module_name = "common" +kernel_module(module_name) { + sources = [ "los_common_interrupt.c" ] + configs += [ "$LITEOSTOPDIR:warn_config" ] +} + +config("public") { + include_dirs = [ "." ] +} diff --git a/arch/csky/common/los_common_interrupt.c b/arch/csky/common/los_common_interrupt.c new file mode 100644 index 00000000..f6a55790 --- /dev/null +++ b/arch/csky/common/los_common_interrupt.c @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_arch_interrupt.h" +#include "los_debug.h" + +/* * + * @ingroup los_hwi + * Hardware interrupt form mapping handling function array. + */ +HWI_PROC_FUNC __attribute__((aligned(HWI_ALIGNSIZE))) g_hwiForm[OS_VECTOR_CNT] = {0}; + +VOID *ArchGetHwiFrom(VOID) +{ + return g_hwiForm; +} + +UINT32 volatile g_intCount = 0; + +/* **************************************************************************** + Function : HalHwiDefaultHandler + Description : default handler of the hardware interrupt + Input : None + Output : None + Return : None + **************************************************************************** */ +LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID) +{ + PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, ArchIntCurIrqNum()); + while (1) {} +} + +WEAK VOID HalPreInterruptHandler(UINT32 arg) +{ + (VOID)arg; + return; +} + +WEAK VOID HalAftInterruptHandler(UINT32 arg) +{ + (VOID)arg; + return; +} + +STATIC UINT32 HwiNumValid(UINT32 num) +{ + return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX); +} + +UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return LOS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->triggerIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->triggerIrq(hwiNum); +} + +UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return LOS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->enableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->enableIrq(hwiNum); +} + +UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return LOS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->disableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->disableIrq(hwiNum); +} + +UINT32 ArchIntClear(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return LOS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->clearIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->clearIrq(hwiNum); +} + +UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority) +{ + if (!HwiNumValid(hwiNum)) { + return LOS_ERRNO_HWI_NUM_INVALID; + } + + if (!HWI_PRI_VALID(priority)) { + return OS_ERRNO_HWI_PRIO_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->setIrqPriority == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->setIrqPriority(hwiNum, priority); +} + +UINT32 ArchIntCurIrqNum(VOID) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + return hwiOps->getCurIrqNum(); +} + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) +typedef struct { + HWI_PROC_FUNC pfnHandler; + VOID *pParm; +} HWI_HANDLER_FUNC; + +/* * + * @ingroup los_hwi + * Hardware interrupt handler form mapping handling function array. + */ +HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }}; + +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)IrqEntry; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg; + ArchIntEnable(num); + } +} +#else +/* * + * @ingroup los_hwi + * Hardware interrupt handler form mapping handling function array. + */ +HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0}; + +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + g_hwiForm[num + OS_SYS_VECTOR_CNT] = IrqEntry; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector; + ArchIntEnable(num); + } +} +#endif + +/* **************************************************************************** + Function : ArchHwiCreate + Description : create hardware interrupt + Input : hwiNum --- hwi num to create + hwiPrio --- priority of the hwi + hwiMode --- unused + hwiHandler --- hwi handler + irqParam --- param of the hwi handler + Output : None + Return : LOS_OK on success or error code on failure + **************************************************************************** */ +LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio, + HWI_MODE_T hwiMode, HWI_PROC_FUNC hwiHandler, + HwiIrqParam *irqParam) +{ + (VOID)hwiMode; + UINT32 intSave; + + if (hwiHandler == NULL) { + return OS_ERRNO_HWI_PROC_FUNC_NULL; + } + if (hwiNum >= OS_HWI_MAX_NUM) { + return OS_ERRNO_HWI_NUM_INVALID; + } + if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) { + return OS_ERRNO_HWI_ALREADY_CREATED; + } + if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) { + return OS_ERRNO_HWI_ALREADY_CREATED; + } + if (hwiPrio > OS_HWI_PRIO_LOWEST) { + return OS_ERRNO_HWI_PRIO_INVALID; + } + intSave = LOS_IntLock(); +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) + if (irqParam != NULL) { + OsSetVector(hwiNum, hwiHandler, irqParam->pDevId); + } else { + OsSetVector(hwiNum, hwiHandler, NULL); + } +#else + (VOID)irqParam; + OsSetVector(hwiNum, hwiHandler); +#endif + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->createIrq == NULL) { + LOS_IntRestore(intSave); + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + hwiOps->createIrq(hwiNum, hwiPrio); + + LOS_IntRestore(intSave); + + return LOS_OK; +} + +/* **************************************************************************** + Function : ArchHwiDelete + Description : Delete hardware interrupt + Input : hwiNum --- hwi num to delete + irqParam --- param of the hwi handler + Output : None + Return : LOS_OK on success or error code on failure + **************************************************************************** */ +LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) +{ + (VOID)irqParam; + UINT32 intSave; + + if (hwiNum >= OS_HWI_MAX_NUM) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + ArchIntDisable((IRQn_Type)hwiNum); + + intSave = LOS_IntLock(); + g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] = 0; + LOS_IntRestore(intSave); + + return LOS_OK; +} + +UINT32 ArchIsIntActive(VOID) +{ + return (g_intCount > 0); +} diff --git a/arch/csky/common/los_common_interrupt.h b/arch/csky/common/los_common_interrupt.h new file mode 100644 index 00000000..6a58a2e7 --- /dev/null +++ b/arch/csky/common/los_common_interrupt.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_COMMON_INTERRUPT_H +#define _LOS_COMMON_INTERRUPT_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_interrupt.h" +#include "los_error.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* * + * @ingroup los_arch_interrupt + * Define the type of a hardware interrupt vector table function. + */ +typedef VOID (**HWI_VECTOR_FUNC)(VOID); + +/* * + * @ingroup los_arch_interrupt + * Count of interrupts. + */ +extern volatile UINT32 g_intCount; + +/* * + * @ingroup los_arch_interrupt + * Maximum number of used hardware interrupts. + */ +#ifndef OS_HWI_MAX_NUM +#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT +#endif + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); +extern HWI_HANDLER_FUNC g_hwiHandlerForm[]; +#else +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); +extern HWI_PROC_FUNC g_hwiHandlerForm[]; +#endif + +#define OS_EXC_IN_INIT 0 +#define OS_EXC_IN_TASK 1 +#define OS_EXC_IN_HWI 2 +#define OS_EXC_FLAG_FAULTADDR_VALID 0x01 +#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB + +/* * + * @ingroup los_arch_interrupt + * @brief: Default vector handling function. + * + * @par Description: + * This API is used to configure interrupt for null function. + * + * @attention: + * + * + * @param:None. + * + * @retval:None. + * @par Dependency: + * + * @see None. + */ +extern VOID HalHwiDefaultHandler(VOID); + +VOID HalPreInterruptHandler(UINT32 arg); +VOID HalAftInterruptHandler(UINT32 arg); +VOID *ArchGetHwiFrom(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_COMMON_INTERRUPT_H */ diff --git a/arch/csky/v2/gcc/los_arch_interrupt.h b/arch/csky/v2/gcc/los_arch_interrupt.h index bcd5728e..53550385 100644 --- a/arch/csky/v2/gcc/los_arch_interrupt.h +++ b/arch/csky/v2/gcc/los_arch_interrupt.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -32,9 +32,7 @@ #ifndef _LOS_ARCH_INTERRUPT_H #define _LOS_ARCH_INTERRUPT_H -#include "los_config.h" -#include "los_compiler.h" -#include "los_interrupt.h" +#include "los_common_interrupt.h" #ifdef __cplusplus #if __cplusplus @@ -42,14 +40,6 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -/* * - * @ingroup los_arch_interrupt - * Maximum number of used hardware interrupts. - */ -#ifndef OS_HWI_MAX_NUM -#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT -#endif - /* * * @ingroup los_arch_interrupt * Highest priority of a hardware interrupt. @@ -72,18 +62,6 @@ extern "C" { */ #define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST)) -/* * - * @ingroup los_arch_interrupt - * Define the type of a hardware interrupt vector table function. - */ -typedef VOID (**HWI_VECTOR_FUNC)(VOID); - -/* * - * @ingroup los_arch_interrupt - * Count of interrupts. - */ -extern volatile UINT32 g_intCount; - /* * * @ingroup los_arch_interrupt * Count of C-sky system interrupt vector. @@ -96,6 +74,11 @@ extern volatile UINT32 g_intCount; */ #define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM) +#define OS_USER_HWI_MIN 0 +#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1) + +#define HWI_ALIGNSIZE 0x400 + #define PSR_VEC_OFFSET 16U #define VIC_REG_BASE 0xE000E100UL @@ -208,6 +191,16 @@ extern VIC_TYPE *VIC_REG; */ #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt operation function. + * + * Value: 0x0200090c + * + * Solution: Set a valid interrupt operation function + */ +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) + /* * * @ingroup los_arch_interrupt * Hardware interrupt error code: Invalid interrupt number. @@ -218,20 +211,6 @@ extern VIC_TYPE *VIC_REG; */ #define LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) -/* * - * @ingroup los_arch_interrupt - * Set interrupt vector table. - */ -extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); -#else -/* * - * @ingroup los_arch_interrupt - * Set interrupt vector table. - */ -extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); -#endif - /* * * @ingroup los_arch_interrupt * @brief: Hardware interrupt entry function. @@ -251,29 +230,6 @@ extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); */ extern VOID HalInterrupt(VOID); -/* * - * @ingroup los_arch_interrupt - * @brief: Default vector handling function. - * - * @par Description: - * This API is used to configure interrupt for null function. - * - * @attention: - * - * - * @param:None. - * - * @retval:None. - * @par Dependency: - * - * @see None. - */ -extern VOID HalHwiDefaultHandler(VOID); - -#define OS_EXC_IN_INIT 0 -#define OS_EXC_IN_TASK 1 -#define OS_EXC_IN_HWI 2 - #define OS_VIC_INT_ENABLE_SIZE 0x4 #define OS_VIC_INT_WAKER_SIZE 0x4 #define OS_VIC_INT_ICER_SIZE 0x4 @@ -283,10 +239,6 @@ extern VOID HalHwiDefaultHandler(VOID); #define OS_VIC_INT_ISR_SIZE 0x4 #define OS_VIC_INT_IPTR_SIZE 0x4 -#define OS_EXC_FLAG_FAULTADDR_VALID 0x01 - -#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB - /** * @ingroup los_exc * the struct of register files diff --git a/arch/csky/v2/gcc/los_interrupt.c b/arch/csky/v2/gcc/los_interrupt.c index 66c0977a..6af1f8a9 100644 --- a/arch/csky/v2/gcc/los_interrupt.c +++ b/arch/csky/v2/gcc/los_interrupt.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -29,7 +29,6 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "los_interrupt.h" #include #include "securec.h" #include "los_context.h" @@ -53,20 +52,10 @@ #define MASK_32_BITS 0xFFFFFFFF #define BYTES_OF_128_INT 4 -#define OS_USER_HWI_MIN 0 -#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1) -#define HWI_ALIGNSIZE 0x400 - -UINT32 volatile g_intCount = 0; CHAR g_trapStackBase[OS_TRAP_STACK_SIZE]; VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE; -UINT32 HwiNumValid(UINT32 num) -{ - return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX); -} - UINT32 HalGetPsr(VOID) { UINT32 intSave; @@ -120,10 +109,6 @@ STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum) { UINT32 intSave; - if (!HwiNumValid(hwiNum)) { - return LOS_ERRNO_HWI_NUM_INVALID; - } - intSave = LOS_IntLock(); VIC_REG->ISER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT)); VIC_REG->ISSR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT)); @@ -136,14 +121,6 @@ STATIC UINT32 HwiSetPriority(HWI_HANDLE_T hwiNum, UINT8 priority) { UINT32 intSave; - if (!HwiNumValid(hwiNum)) { - return LOS_ERRNO_HWI_NUM_INVALID; - } - - if (!HWI_PRI_VALID(priority)) { - return OS_ERRNO_HWI_PRIO_INVALID; - } - intSave = LOS_IntLock(); VIC_REG->IPR[hwiNum / PRI_PER_REG] |= (((priority << PRI_OFF_IN_REG) << (hwiNum % PRI_PER_REG)) * PRI_OFF_PER_INT); LOS_IntRestore(intSave); @@ -155,10 +132,6 @@ STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum) { UINT32 intSave; - if (!HwiNumValid(hwiNum)) { - return LOS_ERRNO_HWI_NUM_INVALID; - } - intSave = LOS_IntLock(); VIC_REG->ICER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT)); LOS_IntRestore(intSave); @@ -170,10 +143,6 @@ STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum) { UINT32 intSave; - if (!HwiNumValid(hwiNum)) { - return LOS_ERRNO_HWI_NUM_INVALID; - } - intSave = LOS_IntLock(); VIC_REG->ISPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT)); LOS_IntRestore(intSave); @@ -183,69 +152,11 @@ STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum) STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum) { - if (!HwiNumValid(hwiNum)) { - return LOS_ERRNO_HWI_NUM_INVALID; - } - VIC_REG->ICPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT)); return LOS_OK; } -/* * - * @ingroup los_hwi - * Hardware interrupt form mapping handling function array. - */ -STATIC HWI_PROC_FUNC __attribute__((aligned(HWI_ALIGNSIZE))) g_hwiForm[OS_VECTOR_CNT] = {0}; - -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) - -typedef struct { - HWI_PROC_FUNC pfnHandler; - VOID *pParm; -} HWI_HANDLER_FUNC; - -/* * - * @ingroup los_hwi - * Hardware interrupt handler form mapping handling function array. - */ -STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }}; - -/* * - * @ingroup los_hwi - * Set interrupt vector table. - */ -VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg) -{ - if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { - g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)IrqEntry; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg; - HwiUnmask(num); - } -} - -#else -/* * - * @ingroup los_hwi - * Hardware interrupt handler form mapping handling function array. - */ -STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0}; - -/* * - * @ingroup los_hwi - * Set interrupt vector table. - */ -VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector) -{ - if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { - g_hwiForm[num + OS_SYS_VECTOR_CNT] = IrqEntry; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector; - HwiUnmask(num); - } -} -#endif - /* **************************************************************************** Function : HwiNumGet Description : Get an interrupt number @@ -258,43 +169,26 @@ STATIC UINT32 HwiNumGet(VOID) return (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS; } -HwiControllerOps g_archHwiOps = { - .triggerIrq = HwiPending, +STATIC UINT32 HwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio) +{ + HwiSetPriority(hwiNum, (UINT8)hwiPrio); + HwiUnmask(hwiNum); + return LOS_OK; +} + +STATIC HwiControllerOps g_archHwiOps = { .enableIrq = HwiUnmask, .disableIrq = HwiMask, .setIrqPriority = HwiSetPriority, .getCurIrqNum = HwiNumGet, + .triggerIrq = HwiPending, .clearIrq = HwiClear, + .createIrq = HwiCreate, }; -inline UINT32 ArchIsIntActive(VOID) +HwiControllerOps *ArchIntOpsGet(VOID) { - return (g_intCount > 0); -} - -/* **************************************************************************** - Function : HalHwiDefaultHandler - Description : default handler of the hardware interrupt - Input : None - Output : None - Return : None - **************************************************************************** */ -LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID) -{ - PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, HwiNumGet()); - while (1) {} -} - -WEAK VOID HalPreInterruptHandler(UINT32 arg) -{ - (VOID)arg; - return; -} - -WEAK VOID HalAftInterruptHandler(UINT32 arg) -{ - (VOID)arg; - return; + return &g_archHwiOps; } /* **************************************************************************** @@ -339,83 +233,6 @@ LITE_OS_SEC_TEXT VOID HalInterrupt(VOID) LOS_IntRestore(intSave); } -/* **************************************************************************** - Function : ArchHwiCreate - Description : create hardware interrupt - Input : hwiNum --- hwi num to create - hwiPrio --- priority of the hwi - hwiMode --- unused - hwiHandler --- hwi handler - irqParam --- param of the hwi handler - Output : None - Return : LOS_OK on success or error code on failure - **************************************************************************** */ -LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, - HWI_PRIOR_T hwiPrio, - HWI_MODE_T hwiMode, - HWI_PROC_FUNC hwiHandler, - HwiIrqParam *irqParam) -{ - (VOID)hwiMode; - UINT32 intSave; - - if (hwiHandler == NULL) { - return OS_ERRNO_HWI_PROC_FUNC_NULL; - } - if (hwiNum >= OS_HWI_MAX_NUM) { - return OS_ERRNO_HWI_NUM_INVALID; - } - if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) { - return OS_ERRNO_HWI_ALREADY_CREATED; - } - if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) { - return OS_ERRNO_HWI_ALREADY_CREATED; - } - if (hwiPrio > OS_HWI_PRIO_LOWEST) { - return OS_ERRNO_HWI_PRIO_INVALID; - } - intSave = LOS_IntLock(); -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) - if (irqParam != NULL) { - OsSetVector(hwiNum, hwiHandler, irqParam->pDevId); - } else { - OsSetVector(hwiNum, hwiHandler, NULL); - } -#else - (VOID)irqParam; - OsSetVector(hwiNum, hwiHandler); -#endif - HwiUnmask(hwiNum); - (VOID)HwiSetPriority(hwiNum, (UINT8)hwiPrio); - LOS_IntRestore(intSave); - - return LOS_OK; -} - -/* **************************************************************************** - Function : ArchHwiDelete - Description : Delete hardware interrupt - Input : hwiNum --- hwi num to delete - irqParam --- param of the hwi handler - Output : None - Return : LOS_OK on success or error code on failure - **************************************************************************** */ -LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) -{ - (VOID)irqParam; - UINT32 intSave; - - if (hwiNum >= OS_HWI_MAX_NUM) { - return OS_ERRNO_HWI_NUM_INVALID; - } - HwiMask(hwiNum); - intSave = LOS_IntLock(); - g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] = 0; - LOS_IntRestore(intSave); - - return LOS_OK; -} - ExcInfo g_excInfo = {0}; #if (LOSCFG_KERNEL_PRINTF != 0) @@ -602,16 +419,17 @@ LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID) { UINT32 i; + HWI_PROC_FUNC *hwiForm = (HWI_PROC_FUNC *)ArchGetHwiFrom(); for (i = 1; i < OS_SYS_VECTOR_CNT; i++) { - g_hwiForm[i] = (HWI_PROC_FUNC)HandleEntry; + hwiForm[i] = (HWI_PROC_FUNC)HandleEntry; } for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) { - g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry; + hwiForm[i] = (HWI_PROC_FUNC)IrqEntry; } - HalHwiHandleReInit((UINT32)&g_hwiForm); + HalHwiHandleReInit((UINT32)hwiForm); - HalSetVbr((UINT32)&g_hwiForm); + HalSetVbr((UINT32)hwiForm); for (i = 0; i < BYTES_OF_128_INT; i++) { VIC_REG->IABR[i] = 0x0; VIC_REG->ICPR[i] = MASK_32_BITS; diff --git a/arch/include/los_interrupt.h b/arch/include/los_interrupt.h index 4e496322..4929def6 100644 --- a/arch/include/los_interrupt.h +++ b/arch/include/los_interrupt.h @@ -147,8 +147,6 @@ UINT32 ArchIsIntActive(VOID); UINT32 ArchIntLock(VOID); UINT32 ArchIntUnLock(VOID); VOID ArchIntRestore(UINT32 intSave); - -#if (LOSCFG_ARCH_ARM == 1) UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum); UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum); UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum); @@ -156,7 +154,6 @@ UINT32 ArchIntClear(HWI_HANDLE_T hwiNum); UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority); UINT32 ArchIntCurIrqNum(VOID); HwiControllerOps *ArchIntOpsGet(VOID); -#endif #define OS_INT_ACTIVE (ArchIsIntActive()) #define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) @@ -173,63 +170,6 @@ HwiControllerOps *ArchIntOpsGet(VOID); #define LOS_HwiCurIrqNum ArchIntCurIrqNum #define LOS_HwiOpsGet ArchIntOpsGet -#if (LOSCFG_ARCH_ARM == 0) -extern HwiControllerOps g_archHwiOps; - -STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum) -{ - if (g_archHwiOps.triggerIrq == NULL) { - return LOS_NOK; - } - return g_archHwiOps.triggerIrq(hwiNum); -} - -STATIC INLINE UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum) -{ - if (g_archHwiOps.enableIrq == NULL) { - return LOS_NOK; - } - return g_archHwiOps.enableIrq(hwiNum); -} - -STATIC INLINE UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum) -{ - if (g_archHwiOps.disableIrq == NULL) { - return LOS_NOK; - } - return g_archHwiOps.disableIrq(hwiNum); -} - -STATIC INLINE UINT32 ArchIntClear(HWI_HANDLE_T hwiNum) -{ - if (g_archHwiOps.clearIrq == NULL) { - return LOS_NOK; - } - return g_archHwiOps.clearIrq(hwiNum); -} - -STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority) -{ - if (g_archHwiOps.setIrqPriority == NULL) { - return LOS_NOK; - } - return g_archHwiOps.setIrqPriority(hwiNum, priority); -} - -STATIC INLINE UINT32 ArchIntCurIrqNum(VOID) -{ - if (g_archHwiOps.getCurIrqNum == NULL) { - return LOS_NOK; - } - return g_archHwiOps.getCurIrqNum(); -} - -STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID) -{ - return &g_archHwiOps; -} -#endif - #ifdef __cplusplus #if __cplusplus } diff --git a/arch/risc-v/BUILD.gn b/arch/risc-v/BUILD.gn index b3f66792..f3821267 100644 --- a/arch/risc-v/BUILD.gn +++ b/arch/risc-v/BUILD.gn @@ -30,5 +30,8 @@ import("//kernel/liteos_m/liteos.gni") module_group("risc-v") { - modules = [ "riscv32/gcc" ] + modules = [ + "common", + "riscv32/gcc", + ] } diff --git a/arch/risc-v/common/BUILD.gn b/arch/risc-v/common/BUILD.gn new file mode 100644 index 00000000..763b9c9d --- /dev/null +++ b/arch/risc-v/common/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +module_name = "common" +kernel_module(module_name) { + sources = [ "los_common_interrupt.c" ] + configs += [ "$LITEOSTOPDIR:warn_config" ] +} + +config("public") { + include_dirs = [ "." ] +} diff --git a/arch/risc-v/common/los_common_interrupt.c b/arch/risc-v/common/los_common_interrupt.c new file mode 100644 index 00000000..a341a69c --- /dev/null +++ b/arch/risc-v/common/los_common_interrupt.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_arch_interrupt.h" +#include "los_debug.h" + +LITE_OS_SEC_BSS UINT32 g_intCount = 0; + +UINT32 ArchIsIntActive(VOID) +{ + return (g_intCount > 0); +} + +LITE_OS_SEC_TEXT_INIT VOID HalHwiDefaultHandler(VOID *arg) +{ + (VOID)arg; + PRINT_ERR("default handler\n"); + while (1) { + } +} + +UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->triggerIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->triggerIrq(hwiNum); +} + +UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->enableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->enableIrq(hwiNum); +} + +UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->disableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->disableIrq(hwiNum); +} + +UINT32 ArchIntClear(HWI_HANDLE_T hwiNum) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->clearIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->clearIrq(hwiNum); +} + +UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->setIrqPriority == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->setIrqPriority(hwiNum, priority); +} + +UINT32 ArchIntCurIrqNum(VOID) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + return hwiOps->getCurIrqNum(); +} diff --git a/arch/risc-v/common/los_common_interrupt.h b/arch/risc-v/common/los_common_interrupt.h new file mode 100644 index 00000000..ac9030cd --- /dev/null +++ b/arch/risc-v/common/los_common_interrupt.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_COMMON_INTERRUPT_H +#define _LOS_COMMON_INTERRUPT_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_interrupt.h" +#include "los_arch_context.h" +#include "los_error.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* * + * @ingroup los_arch_interrupt + * Count of interrupts. + */ +extern UINT32 g_intCount; + +extern VOID HalHwiDefaultHandler(VOID *arg); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_COMMON_INTERRUPT_H */ diff --git a/arch/risc-v/nuclei/gcc/los_arch_interrupt.h b/arch/risc-v/nuclei/gcc/los_arch_interrupt.h index d719550f..5069cf61 100644 --- a/arch/risc-v/nuclei/gcc/los_arch_interrupt.h +++ b/arch/risc-v/nuclei/gcc/los_arch_interrupt.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2020, Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021 Nuclei Limited. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,14 +29,12 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _LOS_HWI_H -#define _LOS_HWI_H +#ifndef _LOS_ARCH_INTERRUPT_H +#define _LOS_ARCH_INTERRUPT_H + +#include "los_common_interrupt.h" #include "nuclei_sdk_soc.h" -#include "los_compiler.h" -#include "los_config.h" -#include "los_interrupt.h" -#include "los_arch_context.h" #ifdef __cplusplus #if __cplusplus @@ -192,6 +190,16 @@ extern VOID HalHwiDefaultHandler(VOID); */ #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt operation function. + * + * Value: 0x0200090c + * + * Solution: Set a valid interrupt operation function + */ +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) + extern UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp); extern VOID DisplayTaskInfo(VOID); @@ -202,4 +210,4 @@ extern VOID DisplayTaskInfo(VOID); #endif /* __cplusplus */ #endif /* __cplusplus */ -#endif /* _LOS_HWI_H */ +#endif /* _LOS_ARCH_INTERRUPT_H */ diff --git a/arch/risc-v/nuclei/gcc/los_interrupt.c b/arch/risc-v/nuclei/gcc/los_interrupt.c index 0ca895fe..4c467d12 100644 --- a/arch/risc-v/nuclei/gcc/los_interrupt.c +++ b/arch/risc-v/nuclei/gcc/los_interrupt.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2021 Nuclei Limited. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -37,8 +38,6 @@ #include "los_debug.h" #include "nuclei_sdk_hal.h" -UINT32 g_intCount = 0; - STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum) { if (hwiNum >= OS_HWI_MAX_NUM) { @@ -150,20 +149,6 @@ LITE_OS_SEC_TEXT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam return LOS_OK; } -/* **************************************************************************** - Function : HalHwiDefaultHandler - Description : default handler of the hardware interrupt - Input : None - Output : None - Return : None - **************************************************************************** */ -LITE_OS_SEC_TEXT_INIT VOID HalHwiDefaultHandler(VOID) -{ - PRINT_ERR("default handler\n"); - while (1) { - } -} - /* **************************************************************************** Function : HalDisplayTaskInfo Description : display the task list @@ -215,13 +200,13 @@ __attribute__((always_inline)) inline VOID HalIntExit(VOID) g_intCount -= 1; } -__attribute__((always_inline)) inline UINT32 ArchIsIntActive(VOID) -{ - return (g_intCount > 0); -} - -const HwiControllerOps g_archHwiOps = { +STATIC HwiControllerOps g_archHwiOps = { .enableIrq = HwiUnmask, .disableIrq = HwiMask, .setIrqPriority = HwiSetPriority, }; + +HwiControllerOps *ArchIntOpsGet(VOID) +{ + return &g_archHwiOps; +} diff --git a/arch/risc-v/riscv32/gcc/los_arch_interrupt.h b/arch/risc-v/riscv32/gcc/los_arch_interrupt.h index fa0f7e51..fe79fd20 100644 --- a/arch/risc-v/riscv32/gcc/los_arch_interrupt.h +++ b/arch/risc-v/riscv32/gcc/los_arch_interrupt.h @@ -31,11 +31,7 @@ #ifndef _LOS_ARCH_INTERRUPT_H #define _LOS_ARCH_INTERRUPT_H -#include "los_compiler.h" -#include "los_config.h" -#include "los_interrupt.h" -#include "los_arch_context.h" -#include "los_error.h" +#include "los_common_interrupt.h" #ifdef __cplusplus #if __cplusplus @@ -146,9 +142,6 @@ extern VOID HalHwiInit(VOID); extern UINT32 HalGetHwiFormCnt(HWI_HANDLE_T hwiNum); extern HWI_HANDLE_FORM_S *HalGetHwiForm(VOID); extern VOID HalHwiInterruptDone(HWI_HANDLE_T hwiNum); -extern VOID HalHwiDefaultHandler(VOID *arg); - -extern UINT32 g_intCount; /** * @ingroup los_arch_interrupt @@ -273,6 +266,16 @@ extern UINT32 g_intCount; */ #define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) +/* * + * @ingroup los_arch_interrupt + * Hardware interrupt error code: Invalid interrupt operation function. + * + * Value: 0x0200090c + * + * Solution: Set a valid interrupt operation function + */ +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) + extern UINT32 HalUnalignedAccessFix(UINTPTR mcause, UINTPTR mepc, UINTPTR mtval, VOID *sp); #ifdef __cplusplus diff --git a/arch/risc-v/riscv32/gcc/los_interrupt.c b/arch/risc-v/riscv32/gcc/los_interrupt.c index 5655cf0f..b080ea27 100644 --- a/arch/risc-v/riscv32/gcc/los_interrupt.c +++ b/arch/risc-v/riscv32/gcc/los_interrupt.c @@ -40,7 +40,6 @@ #include "los_hook.h" #include "riscv_hal.h" - LosExcInfo g_excInfo; #define RISCV_EXC_TYPE_NUM 16 #define RISCV_EXC_LOAD_MISALIGNED 4 @@ -64,7 +63,6 @@ const CHAR g_excInformation[RISCV_EXC_TYPE_NUM][50] = { { "Store/AMO page fault!" }, }; -LITE_OS_SEC_BSS UINT32 g_intCount = 0; LITE_OS_SEC_BSS UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM]; LITE_OS_SEC_DATA_INIT HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM] = { { .pfnHook = NULL, .uwParam = 0 }, // 0 User software interrupt handler @@ -95,14 +93,6 @@ LITE_OS_SEC_DATA_INIT HWI_HANDLE_FORM_S g_hwiForm[OS_HWI_MAX_NUM] = { { .pfnHook = NULL, .uwParam = 0 }, // 25 Reserved }; -LITE_OS_SEC_TEXT_INIT VOID HalHwiDefaultHandler(VOID *arg) -{ - (VOID)arg; - PRINT_ERR("default handler\n"); - while (1) { - } -} - LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID) { UINT32 index; @@ -144,12 +134,6 @@ LITE_OS_SEC_TEXT HWI_HANDLE_FORM_S *HalGetHwiForm(VOID) return g_hwiForm; } - -inline UINT32 ArchIsIntActive(VOID) -{ - return (g_intCount > 0); -} - /***************************************************************************** Function : ArchHwiCreate Description : create hardware interrupt @@ -348,3 +332,9 @@ SYSTEM_DEATH: } } +LITE_OS_SEC_BSS STATIC HwiControllerOps g_archHwiOps; + +HwiControllerOps *ArchIntOpsGet(VOID) +{ + return &g_archHwiOps; +} diff --git a/arch/xtensa/BUILD.gn b/arch/xtensa/BUILD.gn index 761b381e..f42b0cfe 100644 --- a/arch/xtensa/BUILD.gn +++ b/arch/xtensa/BUILD.gn @@ -1,5 +1,5 @@ # Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -30,5 +30,8 @@ import("//kernel/liteos_m/liteos.gni") module_group("xtensa") { - modules = [ "lx6/gcc" ] + modules = [ + "common", + "lx6/gcc", + ] } diff --git a/arch/xtensa/common/BUILD.gn b/arch/xtensa/common/BUILD.gn new file mode 100644 index 00000000..763b9c9d --- /dev/null +++ b/arch/xtensa/common/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +module_name = "common" +kernel_module(module_name) { + sources = [ "los_common_interrupt.c" ] + configs += [ "$LITEOSTOPDIR:warn_config" ] +} + +config("public") { + include_dirs = [ "." ] +} diff --git a/arch/xtensa/common/los_common_interrupt.c b/arch/xtensa/common/los_common_interrupt.c new file mode 100644 index 00000000..9046d611 --- /dev/null +++ b/arch/xtensa/common/los_common_interrupt.c @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_arch_interrupt.h" +#include "los_debug.h" + +UINT32 g_intCount = 0; + +/* * + * @ingroup los_hwi + * Hardware interrupt form mapping handling function array. + */ +HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0}; + +VOID *ArchGetHwiFrom(VOID) +{ + return g_hwiForm; +} + +/* **************************************************************************** + Function : HalHwiDefaultHandler + Description : default handler of the hardware interrupt + Input : None + Output : None + Return : None + **************************************************************************** */ +VOID HalHwiDefaultHandler(VOID) +{ + PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, ArchIntCurIrqNum()); + while (1) {} +} + +WEAK VOID HalPreInterruptHandler(UINT32 arg) +{ + (VOID)arg; + return; +} + +WEAK VOID HalAftInterruptHandler(UINT32 arg) +{ + (VOID)arg; + return; +} + +STATIC UINT32 HwiNumValid(UINT32 num) +{ + return (num >= OS_SYS_VECTOR_CNT) && (num <= OS_VECTOR_CNT); +} + +UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->triggerIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->triggerIrq(hwiNum); +} + +UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->enableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->enableIrq(hwiNum); +} + +UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->disableIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->disableIrq(hwiNum); +} + +UINT32 ArchIntClear(HWI_HANDLE_T hwiNum) +{ + if (!HwiNumValid(hwiNum)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->clearIrq == NULL) { + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + + return hwiOps->clearIrq(hwiNum); +} + +UINT32 ArchIntCurIrqNum(VOID) +{ + HwiControllerOps *hwiOps = ArchIntOpsGet(); + return hwiOps->getCurIrqNum(); +} + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) +typedef struct { + HWI_PROC_FUNC pfnHandler; + VOID *pParm; +} HWI_HANDLER_FUNC; + +/* * + * @ingroup los_hwi + * Hardware interrupt handler form mapping handling function array. + */ +HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }}; + +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg; + } +} + +#else +/* * + * @ingroup los_hwi + * Hardware interrupt handler form mapping handling function array. + */ +HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0}; + +/* * + * @ingroup los_hwi + * Set interrupt vector table. + */ +VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector) +{ + if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { + g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt; + g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector; + } +} +#endif + +/* **************************************************************************** + Function : ArchHwiCreate + Description : create hardware interrupt + Input : hwiNum --- hwi num to create + hwiPrio --- priority of the hwi + hwiMode --- unused + hwiHandler --- hwi handler + irqParam --- param of the hwi handler + Output : None + Return : LOS_OK on success or error code on failure + **************************************************************************** */ +UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, + HWI_PRIOR_T hwiPrio, + HWI_MODE_T hwiMode, + HWI_PROC_FUNC hwiHandler, + HwiIrqParam *irqParam) +{ + (VOID)hwiMode; + UINT32 intSave; + + if (hwiHandler == NULL) { + return OS_ERRNO_HWI_PROC_FUNC_NULL; + } + + if (hwiNum >= OS_HWI_MAX_NUM) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) { + return OS_ERRNO_HWI_ALREADY_CREATED; + } + + if (hwiPrio > OS_HWI_PRIO_LOWEST) { + return OS_ERRNO_HWI_PRIO_INVALID; + } + + intSave = LOS_IntLock(); +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) + if (irqParam != NULL) { + OsSetVector(hwiNum, hwiHandler, irqParam->pDevId); + } else { + OsSetVector(hwiNum, hwiHandler, NULL); + } +#else + (VOID)irqParam; + OsSetVector(hwiNum, hwiHandler); +#endif + + HwiControllerOps *hwiOps = ArchIntOpsGet(); + if (hwiOps->createIrq == NULL) { + LOS_IntRestore(intSave); + return OS_ERRNO_HWI_OPS_FUNC_NULL; + } + hwiOps->createIrq(hwiNum, hwiPrio); + + LOS_IntRestore(intSave); + + return LOS_OK; +} + +/* **************************************************************************** + Function : ArchHwiDelete + Description : Delete hardware interrupt + Input : hwiNum --- hwi num to delete + irqParam --- param of the hwi handler + Output : None + Return : LOS_OK on success or error code on failure + **************************************************************************** */ +LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) +{ + (VOID)irqParam; + UINT32 intSave; + + if (hwiNum >= OS_HWI_MAX_NUM) { + return OS_ERRNO_HWI_NUM_INVALID; + } + + ArchIntDisable(hwiNum); + + intSave = LOS_IntLock(); + + g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler; + + LOS_IntRestore(intSave); + + return LOS_OK; +} + +UINT32 ArchIsIntActive(VOID) +{ + return (g_intCount > 0); +} diff --git a/arch/xtensa/common/los_common_interrupt.h b/arch/xtensa/common/los_common_interrupt.h new file mode 100644 index 00000000..c0a42f12 --- /dev/null +++ b/arch/xtensa/common/los_common_interrupt.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_COMMON_INTERRUPT_H +#define _LOS_COMMON_INTERRUPT_H + +#include "los_config.h" +#include "los_compiler.h" +#include "los_interrupt.h" +#include "los_error.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* * + * @ingroup los_arch_interrupt + * Define the type of a hardware interrupt vector table function. + */ +typedef VOID (**HWI_VECTOR_FUNC)(VOID); + +/* * + * @ingroup los_arch_interrupt + * Count of interrupts. + */ +extern UINT32 g_intCount; + +/* * + * @ingroup los_arch_interrupt + * Maximum number of used hardware interrupts. + */ +#ifndef OS_HWI_MAX_NUM +#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT +#endif + +#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); +extern HWI_HANDLER_FUNC g_hwiHandlerForm[]; +#else +/* * + * @ingroup los_arch_interrupt + * Set interrupt vector table. + */ +extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); +extern HWI_PROC_FUNC g_hwiHandlerForm[]; +#endif + +#define OS_EXC_IN_INIT 0 +#define OS_EXC_IN_TASK 1 +#define OS_EXC_IN_HWI 2 + +extern VOID HalHwiDefaultHandler(VOID); + +VOID HalPreInterruptHandler(UINT32 arg); +VOID HalAftInterruptHandler(UINT32 arg); +VOID *ArchGetHwiFrom(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_COMMON_INTERRUPT_H */ diff --git a/arch/xtensa/lx6/gcc/los_arch_interrupt.h b/arch/xtensa/lx6/gcc/los_arch_interrupt.h index 8f6831e5..039aa2e4 100644 --- a/arch/xtensa/lx6/gcc/los_arch_interrupt.h +++ b/arch/xtensa/lx6/gcc/los_arch_interrupt.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -32,9 +32,7 @@ #ifndef _LOS_ARCH_INTERRUPT_H #define _LOS_ARCH_INTERRUPT_H -#include "los_config.h" -#include "los_compiler.h" -#include "los_interrupt.h" +#include "los_common_interrupt.h" #ifdef __cplusplus #if __cplusplus @@ -67,14 +65,6 @@ typedef struct { extern CHAR *VECTOR_START; #define INIT_VECTOR_START ((UINTPTR)&VECTOR_START) -/* * - * @ingroup los_arch_interrupt - * Maximum number of used hardware interrupts. - */ -#ifndef OS_HWI_MAX_NUM -#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT -#endif - /* * * @ingroup los_arch_interrupt * Highest priority of a hardware interrupt. @@ -91,22 +81,6 @@ extern CHAR *VECTOR_START; #define OS_HWI_PRIO_LOWEST 7 #endif -#define OS_EXC_IN_INIT 0 -#define OS_EXC_IN_TASK 1 -#define OS_EXC_IN_HWI 2 - -/* * - * @ingroup los_arch_interrupt - * Define the type of a hardware interrupt vector table function. - */ -typedef VOID (**HWI_VECTOR_FUNC)(VOID); - -/* * - * @ingroup los_arch_interrupt - * Count of interrupts. - */ -extern UINT32 g_intCount; - /* * * @ingroup los_arch_interrupt * Count of Xtensa system interrupt vector. @@ -199,22 +173,17 @@ extern UINT32 g_intCount; */ #define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) /* * * @ingroup los_arch_interrupt - * Set interrupt vector table. + * Hardware interrupt error code: Invalid interrupt operation function. + * + * Value: 0x0200090c + * + * Solution: Set a valid interrupt operation function */ -extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg); -#else -/* * - * @ingroup los_arch_interrupt - * Set interrupt vector table. - */ -extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector); -#endif +#define OS_ERRNO_HWI_OPS_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0c) VOID HalInterrupt(VOID); -VOID HalHwiDefaultHandler(VOID); VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type); VOID HalHwiInit(VOID); diff --git a/arch/xtensa/lx6/gcc/los_interrupt.c b/arch/xtensa/lx6/gcc/los_interrupt.c index 14d1fcee..aafc37cf 100644 --- a/arch/xtensa/lx6/gcc/los_interrupt.c +++ b/arch/xtensa/lx6/gcc/los_interrupt.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -29,7 +29,6 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "los_interrupt.h" #include #include "securec.h" #include "los_context.h" @@ -42,65 +41,6 @@ #include "los_membox.h" #include "los_arch_regs.h" -UINT32 g_intCount = 0; - -/* * - * @ingroup los_hwi - * Hardware interrupt form mapping handling function array. - */ -STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0}; - -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) - -typedef struct { - HWI_PROC_FUNC pfnHandler; - VOID *pParm; -} HWI_HANDLER_FUNC; - -/* * - * @ingroup los_hwi - * Hardware interrupt handler form mapping handling function array. - */ -STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }}; - -/* * - * @ingroup los_hwi - * Set interrupt vector table. - */ -VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg) -{ - if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { - g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg; - } -} - -#else -/* * - * @ingroup los_hwi - * Hardware interrupt handler form mapping handling function array. - */ -STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0}; - -/* * - * @ingroup los_hwi - * Set interrupt vector table. - */ -VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector) -{ - if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) { - g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt; - g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector; - } -} -#endif - -UINT32 HwiNumValid(UINT32 num) -{ - return (num >= OS_SYS_VECTOR_CNT) && (num <= OS_VECTOR_CNT); -} - /* * * @ingroup los_hwi * Lock all interrupt. @@ -154,37 +94,24 @@ STATIC INLINE UINT32 ArchIntLocked(VOID) */ STATIC UINT32 HwiPending(HWI_HANDLE_T hwiNum) { - if (!HwiNumValid(hwiNum)) { - return OS_ERRNO_HWI_NUM_INVALID; - } - __asm__ __volatile__("wsr %0, intset; rsync" : : "a"(0x1U << hwiNum)); - return LOS_OK; } -UINT32 HwiUnmask(HWI_HANDLE_T hwiNum) +STATIC UINT32 HwiUnmask(HWI_HANDLE_T hwiNum) { UINT32 ier; - if (!HwiNumValid(hwiNum)) { - return OS_ERRNO_HWI_NUM_INVALID; - } - __asm__ __volatile__("rsr %0, intenable" : "=a"(ier) : : "memory"); __asm__ __volatile__("wsr %0, intenable; rsync" : : "a"(ier | ((UINT32)0x1U << hwiNum))); return LOS_OK; } -UINT32 HwiMask(HWI_HANDLE_T hwiNum) +STATIC UINT32 HwiMask(HWI_HANDLE_T hwiNum) { UINT32 ier; - if (!HwiNumValid(hwiNum)) { - return OS_ERRNO_HWI_NUM_INVALID; - } - __asm__ __volatile__("rsr %0, intenable" : "=a"(ier) : : "memory"); __asm__ __volatile__("wsr %0, intenable; rsync" : : "a"(ier & ~((UINT32)0x1U << hwiNum))); @@ -216,53 +143,32 @@ STATIC UINT32 HwiNumGet(VOID) * @ingroup los_hwi * Clear the interrupt */ -STATIC UINT32 HwiClear(HWI_HANDLE_T vector) +STATIC UINT32 HwiClear(HWI_HANDLE_T hwiNum) { - if (!HwiNumValid(vector)) { - return OS_ERRNO_HWI_NUM_INVALID; - } - - __asm__ __volatile__("wsr %0, intclear; rsync" : : "a"(0x1U << vector)); + __asm__ __volatile__("wsr %0, intclear; rsync" : : "a"(0x1U << hwiNum)); return LOS_OK; } -HwiControllerOps g_archHwiOps = { +STATIC UINT32 HwiCreate(HWI_HANDLE_T hwiNum, HWI_PRIOR_T hwiPrio) +{ + (VOID)hwiPrio; + HwiUnmask(hwiNum); + return LOS_OK; +} + +STATIC HwiControllerOps g_archHwiOps = { .triggerIrq = HwiPending, .enableIrq = HwiUnmask, .disableIrq = HwiMask, .getCurIrqNum = HwiNumGet, .clearIrq = HwiClear, + .createIrq = HwiCreate, }; -INLINE UINT32 ArchIsIntActive(VOID) +HwiControllerOps *ArchIntOpsGet(VOID) { - return (g_intCount > 0); -} - -/* **************************************************************************** - Function : HalHwiDefaultHandler - Description : default handler of the hardware interrupt - Input : None - Output : None - Return : None - **************************************************************************** */ -VOID HalHwiDefaultHandler(VOID) -{ - PRINT_ERR("%s irqnum:%u\n", __FUNCTION__, HwiNumGet()); - while (1) {} -} - -WEAK VOID HalPreInterruptHandler(UINT32 arg) -{ - (VOID)arg; - return; -} - -WEAK VOID HalAftInterruptHandler(UINT32 arg) -{ - (VOID)arg; - return; + return &g_archHwiOps; } /* **************************************************************************** @@ -308,88 +214,6 @@ VOID HalInterrupt(VOID) HalIrqEndCheckNeedSched(); } -/* **************************************************************************** - Function : ArchHwiCreate - Description : create hardware interrupt - Input : hwiNum --- hwi num to create - hwiPrio --- priority of the hwi - hwiMode --- unused - hwiHandler --- hwi handler - irqParam --- param of the hwi handler - Output : None - Return : LOS_OK on success or error code on failure - **************************************************************************** */ -UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum, - HWI_PRIOR_T hwiPrio, - HWI_MODE_T hwiMode, - HWI_PROC_FUNC hwiHandler, - HwiIrqParam *irqParam) -{ - (VOID)hwiMode; - UINT32 intSave; - - if (hwiHandler == NULL) { - return OS_ERRNO_HWI_PROC_FUNC_NULL; - } - - if (hwiNum >= OS_HWI_MAX_NUM) { - return OS_ERRNO_HWI_NUM_INVALID; - } - - if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) { - return OS_ERRNO_HWI_ALREADY_CREATED; - } - - if (hwiPrio > OS_HWI_PRIO_LOWEST) { - return OS_ERRNO_HWI_PRIO_INVALID; - } - - intSave = LOS_IntLock(); -#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1) - if (irqParam != NULL) { - OsSetVector(hwiNum, hwiHandler, irqParam->pDevId); - } else { - OsSetVector(hwiNum, hwiHandler, NULL); - } -#else - (VOID)irqParam; - OsSetVector(hwiNum, hwiHandler); -#endif - HwiUnmask(hwiNum); - - LOS_IntRestore(intSave); - - return LOS_OK; -} - -/* **************************************************************************** - Function : ArchHwiDelete - Description : Delete hardware interrupt - Input : hwiNum --- hwi num to delete - irqParam --- param of the hwi handler - Output : None - Return : LOS_OK on success or error code on failure - **************************************************************************** */ -LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) -{ - (VOID)irqParam; - UINT32 intSave; - - if (hwiNum >= OS_HWI_MAX_NUM) { - return OS_ERRNO_HWI_NUM_INVALID; - } - - HwiMask(hwiNum); - - intSave = LOS_IntLock(); - - g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler; - - LOS_IntRestore(intSave); - - return LOS_OK; -} - ExcInfo g_excInfo = {0}; #if (LOSCFG_KERNEL_PRINTF != 0) @@ -559,8 +383,9 @@ WEAK VOID __stack_chk_fail(VOID) VOID HalHwiInit(VOID) { EnableExceptionInterface(); + HWI_PROC_FUNC *hwiForm = (HWI_PROC_FUNC *)ArchGetHwiFrom(); for (UINT32 i = 0; i < OS_HWI_MAX_NUM; i++) { - g_hwiForm[i + OS_SYS_VECTOR_CNT] = HalHwiDefaultHandler; + hwiForm[i + OS_SYS_VECTOR_CNT] = HalHwiDefaultHandler; HwiMask(i); } asm volatile ("wsr %0, vecbase" : : "r"(INIT_VECTOR_START)); diff --git a/arch/xtensa/lx6/gcc/los_timer.c b/arch/xtensa/lx6/gcc/los_timer.c index 0884d252..e60b86d2 100644 --- a/arch/xtensa/lx6/gcc/los_timer.c +++ b/arch/xtensa/lx6/gcc/los_timer.c @@ -1,6 +1,6 @@ /* * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -74,7 +74,7 @@ STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler) __asm__ __volatile__("wsr %0, ccompare1; rsync" : : "a"(0)); __asm__ __volatile__("wsr %0, ccompare2; rsync" : : "a"(0)); - HwiUnmask(tick->irqNum); + LOS_HwiEnable(tick->irqNum); return LOS_OK; } @@ -115,12 +115,12 @@ STATIC UINT64 SysTickCycleGet(UINT32 *period) STATIC VOID SysTickLock(VOID) { - HwiMask(OS_TICK_INT_NUM); + LOS_HwiDisable(OS_TICK_INT_NUM); } STATIC VOID SysTickUnlock(VOID) { - HwiUnmask(OS_TICK_INT_NUM); + LOS_HwiEnable(OS_TICK_INT_NUM); } ArchTickTimer *ArchSysTickTimerGet(VOID)