Commit dee8d3a7 authored by Yu Liao's avatar Yu Liao Committed by yanhaitao
Browse files

cpuinspect: add ATF inspector

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: default avatarYu Liao <liaoyu15@huawei.com>
parent 069486b6
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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
+81 −0
Original line number Diff line number Diff line
// 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);