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 | 81 ++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 drivers/cpuinspect/inspector-atf.c
diff --git a/drivers/cpuinspect/Kconfig b/drivers/cpuinspect/Kconfig index 548412ba3578..4f4144288d64 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 64dcaf3e4e44..8429e9751ae4 100644 --- a/drivers/cpuinspect/Makefile +++ b/drivers/cpuinspect/Makefile @@ -3,4 +3,5 @@ # Makefile for cpuinspect. # 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..00adaff5a19a --- /dev/null +++ b/drivers/cpuinspect/inspector-atf.c @@ -0,0 +1,81 @@ +// 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 +#define CPUINSPECT_NOT_SUPPORTED -1 + +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) +{ + unsigned long ret; + + ret = atf_get_group_num(); + if (ret == CPUINSPECT_NOT_SUPPORTED) { + pr_info("BIOS does not support CPU inspect.\nFailed to register inspector %s\n", + atf_inspector.name); + return -EOPNOTSUPP; + } + + atf_inspector.group_num = ret; + + 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);