blob: 2de10b4fc217707449e7429be2a9fd10c3661ac3 [file] [log] [blame]
Alex Liang1d40d722024-07-23 16:42:16 -05001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arg_struct_def.h>
8#include "constraint.h"
9#include <fuzz_names.h>
10#include <vendor_fuzz_helper.h>
11
12#include <lib/tftf_lib.h>
13#include <runtime_services/ven_el3_svc.h>
14#include <smccc.h>
15#include <uuid_utils.h>
16
17/*
18 * Vendor-Specific EL3 UUID as returned by the implementation in the Trusted
19 * Firmware.
20 */
21static const uuid_t armtf_ven_el3_svc_uuid = {
22 {0xb6, 0x01, 0x1d, 0xca},
23 {0x57, 0xc4},
24 {0x40, 0x7e},
25 0x83, 0xf0,
26 {0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c}
27};
28
29void inputparameters_to_ven_el3_args(struct inputparameters inp, smc_args *args)
30{
31 args->arg1 = inp.x1;
32 args->arg2 = inp.x2;
33 args->arg3 = inp.x3;
34 args->arg4 = inp.x4;
35 args->arg5 = inp.x5;
36 args->arg6 = inp.x6;
37 args->arg7 = inp.x7;
38}
39
40void run_ven_el3_fuzz(int funcid, struct memmod *mmod)
41{
42 if (funcid == ven_el3_svc_uuid_funcid) {
43
44 smc_args ven_el3_svc_args;
45 smc_ret_values ret;
46 uuid_t ven_el3_svc_uuid;
47 char uuid_str[UUID_STR_SIZE];
48
49 /* Standard Service Call UID */
50 ven_el3_svc_args.fid = VEN_EL3_SVC_UID;
51 struct inputparameters inp = generate_args(VEN_EL3_SVC_UUID_CALL, SMC_FUZZ_SANITY_LEVEL);
52
53 inputparameters_to_ven_el3_args(inp, &ven_el3_svc_args);
54
55 ret = tftf_smc(&ven_el3_svc_args);
56
57 make_uuid_from_4words(&ven_el3_svc_uuid,
58 ret.ret0, ret.ret1, ret.ret2, ret.ret3);
59
60 if (!uuid_equal(&ven_el3_svc_uuid, &armtf_ven_el3_svc_uuid)) {
61 tftf_testcase_printf("Wrong UUID: expected %s,\n",
62 uuid_to_str(&armtf_ven_el3_svc_uuid, uuid_str));
63 tftf_testcase_printf(" got %s\n",
64 uuid_to_str(&ven_el3_svc_uuid, uuid_str));
65 } else {
66 #ifdef SMC_FUZZER_DEBUG
67 printf("Correct UUID: got %s,\n",
68 uuid_to_str(&ven_el3_svc_uuid, uuid_str));
69 #endif
70 }
71 } else if (funcid == ven_el3_svc_count_funcid) {
72 smc_args ven_el3_svc_args;
73 smc_ret_values ret;
74
75 ven_el3_svc_args.fid = VEN_EL3_SVC_UID + 1;
76 struct inputparameters inp = generate_args(VEN_EL3_SVC_COUNT_CALL, SMC_FUZZ_SANITY_LEVEL);
77
78 inputparameters_to_ven_el3_args(inp, &ven_el3_svc_args);
79
80 ret = tftf_smc(&ven_el3_svc_args);
81
82 if (ret.ret0 != SMC_UNKNOWN) {
83 tftf_testcase_printf("Querying Vendor-Specific el3 service call count"
84 " which is reserved failed\n");
85 } else {
86 #ifdef SMC_FUZZER_DEBUG
87 printf("Querying Vendor-Specific el3 service call count"
88 " got %ld\n", ret.ret0);
89 #endif
90 }
91 } else if (funcid == ven_el3_svc_version_funcid) {
92 smc_args ven_el3_svc_args;
93 smc_ret_values ret;
94
95 ven_el3_svc_args.fid = VEN_EL3_SVC_VERSION;
96 struct inputparameters inp = generate_args(VEN_EL3_SVC_UUID_CALL, SMC_FUZZ_SANITY_LEVEL);
97
98 inputparameters_to_ven_el3_args(inp, &ven_el3_svc_args);
99
100 ret = tftf_smc(&ven_el3_svc_args);
101
102 if ((ret.ret0 != VEN_EL3_SVC_VERSION_MAJOR) ||
103 (ret.ret1 != VEN_EL3_SVC_VERSION_MINOR)) {
104 tftf_testcase_printf(
105 "Vendor Specific El3 service reported wrong version: expected {%u.%u}, got {%llu.%llu}\n",
106 VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR,
107 (unsigned long long)ret.ret0,
108 (unsigned long long)ret.ret1);
109 }
110 }
111}