blob: 24cdf0ad1acd104670b0dfe2167d461dd93dfd70 [file] [log] [blame]
Andrew Geisslerfc7e7972023-09-11 08:24:07 -04001From 717ff43f0d58e5f5a87893bd0cf3274a1e0164dc Mon Sep 17 00:00:00 2001
Patrick Williamsb542dec2023-06-09 01:26:37 -05002From: Gabor Toth <gabor.toth2@arm.com>
3Date: Fri, 3 Mar 2023 12:25:58 +0100
Andrew Geisslerfc7e7972023-09-11 08:24:07 -04004Subject: [PATCH] ffa_spmc: Add arm_ffa_user driver compatibility check
Patrick Williamsb542dec2023-06-09 01:26:37 -05005
6Check the version of the arm_ffa_user Kernel Driver and fail with a
7meaningful message if incompatible driver is detected.
8
9Upstream-Status: Backport
10
11Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
12Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
13---
14 host/xtest/ffa_spmc_1000.c | 68 ++++++++++++++++++++++++++++++++++----
15 1 file changed, 61 insertions(+), 7 deletions(-)
16
17diff --git a/host/xtest/ffa_spmc_1000.c b/host/xtest/ffa_spmc_1000.c
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040018index 15f4a468a775..1839d03f29be 100644
Patrick Williamsb542dec2023-06-09 01:26:37 -050019--- a/host/xtest/ffa_spmc_1000.c
20+++ b/host/xtest/ffa_spmc_1000.c
21@@ -1,11 +1,12 @@
22 // SPDX-License-Identifier: BSD-3-Clause
23 /*
24- * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
25+ * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved.
26 */
27 #include <fcntl.h>
28 #include <ffa.h>
29 #include <stdio.h>
30 #include <string.h>
31+#include <errno.h>
32 #include <sys/ioctl.h>
33 #include <unistd.h>
34 #include "include/uapi/linux/arm_ffa_user.h"
35@@ -17,6 +18,10 @@
36 #define INCORRECT_ENDPOINT_ID 0xffff
37 #define NORMAL_WORLD_ENDPOINT_ID 0
38
39+#define FFA_USER_REQ_VER_MAJOR 5
40+#define FFA_USER_REQ_VER_MINOR 0
41+#define FFA_USER_REQ_VER_PATCH 1
42+
43 /* Get the 32 least significant bits of a handle.*/
44 #define MEM_SHARE_HANDLE_LOW(x) ((x) & 0xffffffff)
45 /* Get the 32 most significant bits of a handle.*/
46@@ -62,6 +67,50 @@ static struct ffa_ioctl_ep_desc test_endpoint3 = {
47 .uuid_ptr = (uint64_t)test_endpoint3_uuid,
48 };
49
50+static bool check_ffa_user_version(void)
51+{
52+ FILE *f = NULL;
53+ int ver_major = -1;
54+ int ver_minor = -1;
55+ int ver_patch = -1;
56+ int scan_cnt = 0;
57+
58+ f = fopen("/sys/module/arm_ffa_user/version", "r");
59+ if (f) {
60+ scan_cnt = fscanf(f, "%d.%d.%d",
61+ &ver_major, &ver_minor, &ver_patch);
62+ fclose(f);
63+ if (scan_cnt != 3) {
64+ printf("error: failed to parse arm_ffa_user version\n");
65+ return false;
66+ }
67+ } else {
68+ printf("error: failed to read arm_ffa_user module info - %s\n",
69+ strerror(errno));
70+ return false;
71+ }
72+
73+ if (ver_major != FFA_USER_REQ_VER_MAJOR)
74+ goto err;
75+
76+ if (ver_minor < FFA_USER_REQ_VER_MINOR)
77+ goto err;
78+
79+ if (ver_minor == FFA_USER_REQ_VER_MINOR)
80+ if (ver_patch < FFA_USER_REQ_VER_PATCH)
81+ goto err;
82+
83+ return true;
84+
85+err:
86+ printf("error: Incompatible arm_ffa_user driver detected.");
87+ printf("Found v%d.%d.%d wanted >= v%d.%d.%d)\n",
88+ ver_major, ver_minor, ver_patch, FFA_USER_REQ_VER_MAJOR,
89+ FFA_USER_REQ_VER_MINOR, FFA_USER_REQ_VER_PATCH);
90+
91+ return false;
92+}
93+
94 static void close_debugfs(void)
95 {
96 int err = 0;
97@@ -76,6 +125,9 @@ static void close_debugfs(void)
98
99 static bool init_sp_xtest(ADBG_Case_t *c)
100 {
101+ if (!check_ffa_user_version())
102+ return false;
103+
104 if (ffa_fd < 0) {
105 ffa_fd = open(FFA_DRIVER_FS_PATH, O_RDWR);
106 if (ffa_fd < 0) {
107@@ -83,6 +135,7 @@ static bool init_sp_xtest(ADBG_Case_t *c)
108 return false;
109 }
110 }
111+
112 return true;
113 }
114
115@@ -99,7 +152,7 @@ static uint16_t get_endpoint_id(uint64_t endp)
116 struct ffa_ioctl_ep_desc sid = { .uuid_ptr = endp };
117
118 /* Get ID of destination SP based on UUID */
119- if(ioctl(ffa_fd, FFA_IOC_GET_PART_ID, &sid))
120+ if (ioctl(ffa_fd, FFA_IOC_GET_PART_ID, &sid))
121 return INCORRECT_ENDPOINT_ID;
122
123 return sid.id;
124@@ -213,14 +266,15 @@ static int set_up_mem(struct ffa_ioctl_ep_desc *endp,
125 rc = share_mem(endpoint, handle);
126 ADBG_EXPECT_COMPARE_SIGNED(c, rc, ==, 0);
127
128- if (!ADBG_EXPECT_TRUE(c, handle != NULL))
129- return TEEC_ERROR_GENERIC;
130+ if (!ADBG_EXPECT_NOT_NULL(c, handle))
131+ return TEEC_ERROR_GENERIC;
132
133 /* SP will retrieve the memory region. */
134 memset(args, 0, sizeof(*args));
135 args->dst_id = endpoint;
136 args->args[MEM_SHARE_HANDLE_LOW_INDEX] = MEM_SHARE_HANDLE_LOW(*handle);
137- args->args[MEM_SHARE_HANDLE_HIGH_INDEX] = MEM_SHARE_HANDLE_HIGH(*handle);
138+ args->args[MEM_SHARE_HANDLE_HIGH_INDEX] =
139+ MEM_SHARE_HANDLE_HIGH(*handle);
140 args->args[MEM_SHARE_HANDLE_ENDPOINT_INDEX] = NORMAL_WORLD_ENDPOINT_ID;
141
142 rc = start_sp_test(endpoint, EP_RETRIEVE, args);
143@@ -254,7 +308,7 @@ static void xtest_ffa_spmc_test_1002(ADBG_Case_t *c)
144 rc = start_sp_test(endpoint1_id, EP_TEST_SP, &args);
145 ADBG_EXPECT_COMPARE_SIGNED(c, rc, ==, 0);
146 if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, args.args[0], ==, SPMC_TEST_OK))
147- goto out;
148+ goto out;
149
150 /* Set up memory and have the SP retrieve it. */
151 Do_ADBG_BeginSubCase(c, "Test memory set-up");
152@@ -469,7 +523,7 @@ static void xtest_ffa_spmc_test_1005(ADBG_Case_t *c)
153 memset(&args, 0, sizeof(args));
154 args.args[1] = endpoint2;
155 args.args[2] = endpoint3;
156- rc = start_sp_test(endpoint1, EP_SP_MEM_SHARING_MULTI,&args);
157+ rc = start_sp_test(endpoint1, EP_SP_MEM_SHARING_MULTI, &args);
158 ADBG_EXPECT_COMPARE_SIGNED(c, rc, ==, 0);
159 ADBG_EXPECT_COMPARE_UNSIGNED(c, args.args[0], ==, SPMC_TEST_OK);
160