aboutsummaryrefslogtreecommitdiff
path: root/include/sm.h
diff options
context:
space:
mode:
authorAlexey Romanov2023-09-21 11:13:34 +0300
committerNeil Armstrong2023-10-15 12:23:48 +0200
commitc52cd07407af6467d68f1ed9dd180fb72bbf0313 (patch)
treee5cc8087f0a6a756c05311aa65ef82e230581c0e /include/sm.h
parenta92345610ed3596bc25de08b17cb29c86b508e6c (diff)
drivers: introduce Secure Monitor uclass
At the moment, we don't have a common API for working with SM, only the smc_call() function. This approach is not generic and difficult to configure and maintain. This patch adds UCLASS_SM with the generic API: - sm_call() - sm_call_write() - sm_call_read() These functions operate with struct pt_regs, which describes Secure Monitor arguments. Signed-off-by: Alexey Romanov <avromanov@salutedevices.com> Reviewed-by: Simon Glass <sjg@chromium.org> Link: https://lore.kernel.org/r/20230921081346.22157-2-avromanov@salutedevices.com Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Diffstat (limited to 'include/sm.h')
-rw-r--r--include/sm.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/include/sm.h b/include/sm.h
new file mode 100644
index 00000000000..afa9c89055e
--- /dev/null
+++ b/include/sm.h
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2023 SberDevices, Inc.
+ *
+ * Author: Alexey Romanov <avromanov@salutedevices.ru>
+ */
+
+#ifndef __SM_H__
+#define __SM_H__
+
+/*
+ * NOTE: UCLASS_SM is designed with the idea that
+ * each driver should convert @cmd to some raw
+ * value, which is known only for driver, and set this
+ * value to the first element of the @args->regs array.
+ * Therefore, it is necessary to pass the remaining
+ * arguments starting at index = 1. Anyway, driver
+ * implementation may vary, so, please, check the specific
+ * implementation of the driver you are using.
+ */
+
+#include <asm/types.h>
+#include <asm/ptrace.h>
+
+struct udevice;
+
+/**
+ * sm_call - generic SMC call to the secure-monitor
+ *
+ * @dev: Pointer to UCLASS_SM device
+ * @cmd_index: Index of the SMC function ID
+ * @smc_ret: Returned value from secure world
+ * @args: SMC arguments
+ *
+ * @return: 0 on success, a negative value on error
+ */
+int sm_call(struct udevice *dev, u32 cmd, s32 *ret, struct pt_regs *args);
+
+/**
+ * sm_call_read - retrieve data from secure-monitor
+ *
+ * @dev: Pointer to UCLASS_MESON_SM device
+ * @buffer: Buffer to store the retrieved data
+ * @size: Size of the buffer
+ * @cmd: Index of the SMC function ID
+ * @args: SMC arguments
+ *
+ * @return: size of read data on success, a negative value on error
+ */
+int sm_call_read(struct udevice *dev, void *buffer, size_t size,
+ u32 cmd, struct pt_regs *args);
+
+/**
+ * sm_call_write - send data to secure-monitor
+ *
+ * @dev: Pointer to UCLASS_SM device
+ * @buffer: Buffer containing data to send
+ * @size: Size of the buffer
+ * @cmd: Index of the SMC function ID
+ * @args: SMC arguments
+ *
+ * @return: size of sent data on success, a negative value on error
+ */
+int sm_call_write(struct udevice *dev, void *buffer, size_t size,
+ u32 cmd, struct pt_regs *args);
+
+#endif /* __SM_H__ */