[5/5] arm-bsp/linux: setting the FFA_VERSION compatibility checks

Message ID 20211129124002.18352-6-abdellatif.elkhlifi@arm.com
State New
Headers show
Series Corstone1000: FF-A in u-boot , enabling secure partitions in Optee | expand

Commit Message

Abdellatif El Khlifi Nov. 29, 2021, 12:40 p.m. UTC
From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>

This commit introduces a new kernel patch that aligns the FF-A
versions checks according to the FF-A specification v1.0.

Without this fix, the FF-A bus fails to initialize when the FF-A
framework is version 1.1 (comes with the latest TF-A).

The bus driver which is v1.0 rejects the framework v1.1 despite
the fact they are compatible according to the specification.

This kernel patch changes the logic of the version checking based on
the specification.

Change-Id: If9d7b6c0d5e24e73d4f42c6532cd56ff2d05fcec
Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
---
 ...A_VERSION-compatibility-checks.patch.patch | 101 ++++++++++++++++++
 .../linux/linux-arm-platforms.inc             |   1 +
 2 files changed, 102 insertions(+)
 create mode 100644 meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0037-firmware-arm_ffa-setting-the-FFA_VERSION-compatibility-checks.patch.patch

Patch

diff --git a/meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0037-firmware-arm_ffa-setting-the-FFA_VERSION-compatibility-checks.patch.patch b/meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0037-firmware-arm_ffa-setting-the-FFA_VERSION-compatibility-checks.patch.patch
new file mode 100644
index 0000000..f5e5b81
--- /dev/null
+++ b/meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0037-firmware-arm_ffa-setting-the-FFA_VERSION-compatibility-checks.patch.patch
@@ -0,0 +1,101 @@ 
+Upstream-Status: Pending [Not submitted to upstream yet]
+Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
+
+From 045c5da54595303c8bfec54fa5bbae10fdf9f5f5 Mon Sep 17 00:00:00 2001
+From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
+Date: Wed, 25 Aug 2021 11:24:35 +0100
+Subject: [PATCH 1/3] firmware: arm_ffa: setting the FFA_VERSION compatibility
+ checks
+
+This commit aligns the FF-A versions checks according to the
+FF-A specification v1.0.
+
+The compatibility of the version number (x.y) of the caller with
+the version number (a.b) of the callee can be defined as:
+
+    If x == a and y <= b, then the versions are compatible.
+    Otherwise, versions are incompatible.
+
+Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
+---
+ drivers/firmware/arm_ffa/driver.c | 41 ++++++++++++++++++++++---------
+ 1 file changed, 30 insertions(+), 11 deletions(-)
+
+diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c
+index c9fb56afbcb4..0044c928d9f2 100644
+--- a/drivers/firmware/arm_ffa/driver.c
++++ b/drivers/firmware/arm_ffa/driver.c
+@@ -105,13 +105,14 @@
+ 
+ #define MAJOR_VERSION_MASK	GENMASK(30, 16)
+ #define MINOR_VERSION_MASK	GENMASK(15, 0)
+-#define MAJOR_VERSION(x)	((u16)(FIELD_GET(MAJOR_VERSION_MASK, (x))))
+-#define MINOR_VERSION(x)	((u16)(FIELD_GET(MINOR_VERSION_MASK, (x))))
++#define GET_FFA_MAJOR_VERSION(x)	((u16)(FIELD_GET(MAJOR_VERSION_MASK, (x))))
++#define GET_FFA_MINOR_VERSION(x)	((u16)(FIELD_GET(MINOR_VERSION_MASK, (x))))
+ #define PACK_VERSION_INFO(major, minor)			\
+ 	(FIELD_PREP(MAJOR_VERSION_MASK, (major)) |	\
+ 	 FIELD_PREP(MINOR_VERSION_MASK, (minor)))
+-#define FFA_VERSION_1_0		PACK_VERSION_INFO(1, 0)
+-#define FFA_MIN_VERSION		FFA_VERSION_1_0
++#define FFA_MAJOR_VERSION		(1)
++#define FFA_MINOR_VERSION		(0)
++#define FFA_VERSION_1_0		PACK_VERSION_INFO(FFA_MAJOR_VERSION, FFA_MINOR_VERSION)
+ 
+ #define SENDER_ID_MASK		GENMASK(31, 16)
+ #define RECEIVER_ID_MASK	GENMASK(15, 0)
+@@ -170,26 +171,44 @@ static struct ffa_drv_info *drv_info;
+ static int ffa_version_check(u32 *version)
+ {
+ 	ffa_value_t ver;
++	u16 major, minor;
+ 
+ 	invoke_ffa_fn((ffa_value_t){
+ 		      .a0 = FFA_VERSION, .a1 = FFA_DRIVER_VERSION,
+ 		      }, &ver);
+ 
++
+ 	if (ver.a0 == FFA_RET_NOT_SUPPORTED) {
+-		pr_info("FFA_VERSION returned not supported\n");
++		pr_err("A Firmware Framework implementation does not exist\n");
+ 		return -EOPNOTSUPP;
+ 	}
+ 
+-	if (ver.a0 < FFA_MIN_VERSION || ver.a0 > FFA_DRIVER_VERSION) {
+-		pr_err("Incompatible version %d.%d found\n",
+-		       MAJOR_VERSION(ver.a0), MINOR_VERSION(ver.a0));
+-		return -EINVAL;
++	major = GET_FFA_MAJOR_VERSION(ver.a0);
++	minor = GET_FFA_MINOR_VERSION(ver.a0);
++
++	if ((major != FFA_MAJOR_VERSION) || (minor < FFA_MINOR_VERSION)) {
++		pr_err("Versions are incompatible\n"
++		"FF-A driver version: %d.%d\n"
++		"FF-A framework version: %d.%d\n",
++				FFA_MAJOR_VERSION,
++				FFA_MINOR_VERSION,
++				major,
++				minor);
++		return -EPROTONOSUPPORT;
+ 	}
+ 
++	pr_info("Versions are compatible\n"
++	"FF-A driver version: %d.%d\n"
++	"FF-A framework version: %d.%d\n",
++					FFA_MAJOR_VERSION,
++					FFA_MINOR_VERSION,
++					major,
++					minor);
++
+ 	*version = ver.a0;
+-	pr_info("Version %d.%d found\n", MAJOR_VERSION(ver.a0),
+-		MINOR_VERSION(ver.a0));
++
+ 	return 0;
++
+ }
+ 
+ static int ffa_rx_release(void)
+-- 
+2.17.1
+
diff --git a/meta-arm-bsp/recipes-kernel/linux/linux-arm-platforms.inc b/meta-arm-bsp/recipes-kernel/linux/linux-arm-platforms.inc
index f4b5604..49f92ce 100644
--- a/meta-arm-bsp/recipes-kernel/linux/linux-arm-platforms.inc
+++ b/meta-arm-bsp/recipes-kernel/linux/linux-arm-platforms.inc
@@ -128,6 +128,7 @@  SRC_URI:append:corstone1000 = " \
            file://0034-usb-isp1760-write-to-status-and-address-register.patch \
            file://0035-usb-isp1760-use-the-right-irq-status-bit.patch \
            file://0036-usb-isp1760-otg-control-register-access.patch \
+           file://0037-firmware-arm_ffa-setting-the-FFA_VERSION-compatibility-checks.patch.patch \
            file://defconfig  \
         "