[PATCH 2/4] drivers: implement of_optee_fixup helper function
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Mar 7 01:34:24 PST 2023
This function can be called by board-code after checking whether OP-TEE
was installed or not.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
arch/arm/include/asm/optee.h | 18 ++++++++++++++++
drivers/Makefile | 1 +
drivers/tee/optee/of.c | 42 ++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
create mode 100644 arch/arm/include/asm/optee.h
create mode 100644 drivers/tee/optee/of.c
diff --git a/arch/arm/include/asm/optee.h b/arch/arm/include/asm/optee.h
new file mode 100644
index 000000000000..f8eb7b4a8b0f
--- /dev/null
+++ b/arch/arm/include/asm/optee.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ARM_OPTEE_H__
+#define __ARM_OPTEE_H__
+
+#include <linux/types.h>
+
+struct device_node;
+
+struct of_optee_fixup_data {
+ const char *method;
+ size_t shm_size;
+};
+
+int of_optee_fixup(struct device_node *root, void *fixup_data);
+
+#endif /* __ARM_OPTEE_H__ */
+
diff --git a/drivers/Makefile b/drivers/Makefile
index 10ec145be5e5..be2f736eb188 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -47,3 +47,4 @@ obj-y += ddr/
obj-y += power/
obj-$(CONFIG_SOUND) += sound/
obj-y += virtio/
+obj-$(CONFIG_HAVE_OPTEE) += tee/optee/of.o
diff --git a/drivers/tee/optee/of.c b/drivers/tee/optee/of.c
new file mode 100644
index 000000000000..8295a1751c52
--- /dev/null
+++ b/drivers/tee/optee/of.c
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <of.h>
+#include <linux/ioport.h>
+#include <asm/barebox-arm.h>
+#include <asm/optee.h>
+
+int of_optee_fixup(struct device_node *root, void *_data)
+{
+ struct of_optee_fixup_data *fixup_data = _data;
+ struct resource res = {};
+ struct device_node *node;
+ int ret;
+
+ node = of_create_node(root, "/firmware/optee");
+ if (!node)
+ return -ENOMEM;
+
+ ret = of_property_write_string(node, "compatible", "linaro,optee-tz");
+ if (ret)
+ return ret;
+
+ ret = of_property_write_string(node, "method", fixup_data->method);
+ if (ret)
+ return ret;
+
+ res.start = arm_mem_endmem_get() - OPTEE_SIZE;
+ res.end = arm_mem_endmem_get() - fixup_data->shm_size -1;
+ res.flags = IORESOURCE_BUSY;
+ res.name = "optee_core";
+
+ ret = of_fixup_reserved_memory(root, &res);
+ if (ret)
+ return ret;
+
+ res.start = arm_mem_endmem_get() - fixup_data->shm_size;
+ res.end = arm_mem_endmem_get() - 1;
+ res.flags &= ~IORESOURCE_BUSY;
+ res.name = "optee_shm";
+
+ return of_fixup_reserved_memory(root, &res);
+}
--
2.30.2
More information about the barebox
mailing list