From 753f46dffe17e0311fa660fed6bf1efec41de002 Mon Sep 17 00:00:00 2001 From: zouboan Date: Wed, 7 Dec 2022 11:41:39 +0800 Subject: [PATCH] arch/arm64: add support of systemreset --- arch/arm64/Kconfig | 1 + arch/arm64/src/a64/a64_boot.c | 2 +- arch/arm64/src/common/Make.defs | 2 +- arch/arm64/src/common/arm64_cpu_psci.c | 14 +++++ arch/arm64/src/common/arm64_cpu_psci.h | 1 + arch/arm64/src/common/arm64_systemreset.c | 63 +++++++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/src/common/arm64_systemreset.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 2353830cce1..25dbe31ea86 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -14,6 +14,7 @@ config ARCH_CHIP_A64 bool "Allwinner A64" select ARCH_CORTEX_A53 select ARCH_HAVE_ADDRENV + select ARCH_HAVE_RESET select ARCH_NEED_ADDRENV_MAPPING ---help--- Allwinner A64 SoC diff --git a/arch/arm64/src/a64/a64_boot.c b/arch/arm64/src/a64/a64_boot.c index 862d014dc16..3a52012eeab 100644 --- a/arch/arm64/src/a64/a64_boot.c +++ b/arch/arm64/src/a64/a64_boot.c @@ -84,7 +84,7 @@ void arm64_chip_boot(void) arm64_mmu_init(true); -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP) || defined(CONFIG_ARCH_HAVE_RESET) arm64_psci_init("smc"); #endif diff --git a/arch/arm64/src/common/Make.defs b/arch/arm64/src/common/Make.defs index 1b137b0fb32..79a42ec3096 100644 --- a/arch/arm64/src/common/Make.defs +++ b/arch/arm64/src/common/Make.defs @@ -48,7 +48,7 @@ CMN_CSRCS += arm64_createstack.c arm64_releasestack.c arm64_stackframe.c arm64_u CMN_CSRCS += arm64_task_sched.c arm64_exit.c arm64_vfork.c CMN_CSRCS += arm64_releasepending.c arm64_switchcontext.c CMN_CSRCS += arm64_assert.c arm64_schedulesigaction.c arm64_backtrace.c -CMN_CSRCS += arm64_sigdeliver.c +CMN_CSRCS += arm64_sigdeliver.c arm64_systemreset.c # Common C source files ( hardware BSP ) CMN_CSRCS += arm64_mmu.c arm64_arch_timer.c arm64_cache.c diff --git a/arch/arm64/src/common/arm64_cpu_psci.c b/arch/arm64/src/common/arm64_cpu_psci.c index 15970887618..25ff69746ae 100644 --- a/arch/arm64/src/common/arm64_cpu_psci.c +++ b/arch/arm64/src/common/arm64_cpu_psci.c @@ -164,6 +164,20 @@ int pcsi_cpu_off(void) return psci_to_dev_err(ret); } +int pcsi_cpu_reset(void) +{ + int ret; + + if (psci_data.conduit == SMCCC_CONDUIT_NONE) + { + return -EINVAL; + } + + ret = psci_data.invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); + + return psci_to_dev_err(ret); +} + int pcsi_cpu_on(unsigned long cpuid, uintptr_t entry_point) { int ret; diff --git a/arch/arm64/src/common/arm64_cpu_psci.h b/arch/arm64/src/common/arm64_cpu_psci.h index d078360ca89..eeb3801bd53 100644 --- a/arch/arm64/src/common/arm64_cpu_psci.h +++ b/arch/arm64/src/common/arm64_cpu_psci.h @@ -99,6 +99,7 @@ struct psci_interface uint32_t psci_version(void); int pcsi_cpu_off(void); +int pcsi_cpu_reset(void); int pcsi_cpu_on(unsigned long cpuid, uintptr_t entry_point); #endif /* __ARCH_ARM64_SRC_COMMON_ARM64_CPU_PSCI_H */ diff --git a/arch/arm64/src/common/arm64_systemreset.c b/arch/arm64/src/common/arm64_systemreset.c new file mode 100644 index 00000000000..1076d99c18b --- /dev/null +++ b/arch/arm64/src/common/arm64_systemreset.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_systemreset.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "arm64_internal.h" +#include "arm64_cpu_psci.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_systemreset + * + * Description: + * Internal, arm64 reset logic. + * + ****************************************************************************/ + +void up_systemreset(void) +{ + int ret; + + /* Set up for the system reset */ + + ret = pcsi_cpu_reset(); + if (ret) + { + sinfo("Failed to reset CPU, error code: %d\n", ret); + } + + /* Wait for the reset */ + + for (; ; ); +}