Commit b1bfb175 authored by Huifeng Zhang's avatar Huifeng Zhang Committed by Fabio Baltieri
Browse files

tests: arm_smc_call: introduce arm smc call test



Add a simple test case to test the arm SMC call

Signed-off-by: default avatarHuifeng Zhang <Huifeng.Zhang@arm.com>
parent 21c9c0f0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(arm_svc_call)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
target_include_directories(app PRIVATE
  ${ARCH_DIR}/${ARCH}/include
)
+7 −0
Original line number Diff line number Diff line
# Copyright (c) 2022 Arm Limited (or its affiliates). All rights reserved.
# SPDX-License-Identifier: Apache-2.0

config SMC_CALL_USE_HVC
	bool "Set smc call method to hvc"

source "Kconfig.zephyr"
+3 −0
Original line number Diff line number Diff line
CONFIG_TEST_USERSPACE=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 Arm Limited (or its affiliates). All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/ztest.h>

#include "zephyr/arch/arm64/arm-smccc.h"

/* SMC function IDs for Standard Service queries */
#define ARM_STD_SMC_CALL_COUNT		0x8400ff00UL
#define ARM_STD_SMC_VERSION		0x8400ff03UL
#define ARM_STD_SMC_UNKNOWN		0xffffffffUL

#define SMC_UNK				-1

typedef void (*smc_call_method_t)(unsigned long, unsigned long,
				  unsigned long, unsigned long,
				  unsigned long, unsigned long,
				  unsigned long, unsigned long,
				  struct arm_smccc_res *);

#ifdef CONFIG_SMC_CALL_USE_HVC
	smc_call_method_t smc_call = arm_smccc_hvc;
#else
	smc_call_method_t smc_call = arm_smccc_smc;
#endif

ZTEST(arm64_smc_call, test_smc_call_func)
{
	struct arm_smccc_res res;

	smc_call(ARM_STD_SMC_CALL_COUNT, 0, 0, 0, 0, 0, 0, 0, &res);
	zassert_true(res.a0 > 0, "Wrong smc call count");

	smc_call(ARM_STD_SMC_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
	zassert_true((res.a0 >= 0 && res.a1 >= 0),
		"Wrong smc call version");

	smc_call(ARM_STD_SMC_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, &res);
	zassert_true(res.a0 == SMC_UNK, "Wrong return code from smc call");
}

ZTEST_SUITE(arm64_smc_call, NULL, NULL, NULL, NULL, NULL);
+4 −0
Original line number Diff line number Diff line
tests:
  arch.arm64.smc_call.smc:
    platform_allow: fvp_base_revc_2xaemv8a_smp_ns
    tags: arm smc drivers userspace