hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I7ZBQB
----------------------------------
This inspector implements the execution of inspection instructions in BIOS.
Using smc to get group num and execute inspection test cases from arm-trusted-firmware.
Signed-off-by: Yu Liao liaoyu15@huawei.com --- drivers/cpuinspect/Kconfig | 11 +++++ drivers/cpuinspect/Makefile | 1 + drivers/cpuinspect/inspector-atf.c | 70 ++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 drivers/cpuinspect/inspector-atf.c
diff --git a/drivers/cpuinspect/Kconfig b/drivers/cpuinspect/Kconfig index 292dce7ffb6b..c38691304871 100644 --- a/drivers/cpuinspect/Kconfig +++ b/drivers/cpuinspect/Kconfig @@ -10,4 +10,15 @@ config CPU_INSPECT of SDC by proactively executing CPU inspection test cases. It includes modular inspector that can be swapped during runtime.
+if CPU_INSPECT + +config CPU_INSPECTOR_ATF + tristate "ATF CPU inspector" + depends on ARM64 + default n + help + This inspector implements the execution of inspection instructions + in BIOS. + +endif endmenu diff --git a/drivers/cpuinspect/Makefile b/drivers/cpuinspect/Makefile index 287ffedd51fc..51e89ce71822 100644 --- a/drivers/cpuinspect/Makefile +++ b/drivers/cpuinspect/Makefile @@ -4,4 +4,5 @@ # ccflags-y = -DDEBUG obj-$(CONFIG_CPU_INSPECT) += cpu_inspect.o +obj-$(CONFIG_CPU_INSPECTOR_ATF) += inspector-atf.o cpu_inspect-y = cpuinspect.o inspector.o sysfs.o diff --git a/drivers/cpuinspect/inspector-atf.c b/drivers/cpuinspect/inspector-atf.c new file mode 100644 index 000000000000..5b497aea0b70 --- /dev/null +++ b/drivers/cpuinspect/inspector-atf.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * inspector-atf: cpuinspect inspector for EFI-based systems + * + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. + * + * Author: Yu Liao liaoyu15@huawei.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/cpuinspect.h> +#include <linux/arm-smccc.h> + +#define PRIVATE_ARM_SMC_ID_STL_GET_MAX_GROUP 0x83000504 +#define PRIVATE_ARM_SMC_ID_STL_ONLINE_TEST 0x83000505 + +static struct cpu_inspector atf_inspector; + +static int atf_get_group_num(void) +{ + struct arm_smccc_res res; + + arm_smccc_smc(PRIVATE_ARM_SMC_ID_STL_GET_MAX_GROUP, 0, 0, 0, 0, + 0, 0, 0, &res); + + return res.a0; +} + +static int atf_run_chip_test(unsigned int group) +{ + struct arm_smccc_res res; + + arm_smccc_smc(PRIVATE_ARM_SMC_ID_STL_ONLINE_TEST, group, 0, 0, 0, + 0, 0, 0, &res); + + return res.a0; +} + +static struct cpu_inspector atf_inspector = { + .name = "atf", + .start_inspect = atf_run_chip_test, +}; + +/** + * init_atf_inspector - initializes the inspector + */ +static __init int init_atf_inspector(void) +{ + atf_inspector.group_num = atf_get_group_num(); + return cpuinspect_register_inspector(&atf_inspector); +} + +static __exit void exit_atf_inspector(void) +{ + cpuinspect_unregister_inspector(&atf_inspector); +} + +MODULE_LICENSE("GPL"); +module_init(init_atf_inspector); +module_exit(exit_atf_inspector);