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