Skip to contentSkip to conversation

drivers: optee: allow op-tee to access devices on the i2c bus

PATCH In review Jorge Ramirez-Ortiz 2 participants 4 messages Aug 14, 2020 – Aug 21, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v9 1/1 drivers: optee: allow op-tee to access devices on the i2c bus

Some secure elements like NXP's SE050 sit on I2C buses. For OP-TEE to control this type of cryptographic devices it needs coordinated access to the bus, so collisions and RUNTIME_PM dont get in the way.

This trampoline driver allow OP-TEE to access them.

---
v9: params return value must be written before optee_msg_to_param is called
v8: review fixes:
fix types and add TEEC_ERROR_NOT_SUPPORTED to GP errors
v7: add support for ten bit i2c slave addressing
v6: compile out if CONFIG_I2C not enabled
v5: alphabetic order of includes
v4: remove unnecessary extra line in optee_msg.h
v3: use from/to msg param to support all types of memory
modify OPTEE_MSG_RPC_CMD_I2C_TRANSFER message id

 drivers/tee/optee/optee_msg.h     | 21 +++++++
 drivers/tee/optee/optee_private.h |  1 +
 drivers/tee/optee/rpc.c           | 95 +++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
drivers/tee/optee/optee_msg.h +21 -0
index 795bc19ae17a..7b2d919da2ac 100644
@@ -419,4 +419,25 @@ struct optee_msg_arg {
  */
 #define OPTEE_MSG_RPC_CMD_SHM_FREE	7
 
+/*
+ * Access a device on an i2c bus
+ *
+ * [in]  param[0].u.value.a		mode: RD(0), WR(1)
+ * [in]  param[0].u.value.b		i2c adapter
+ * [in]  param[0].u.value.c		i2c chip
+ *
+ * [in]  param[1].u.value.a		i2c control flags
+ *
+ * [in/out] memref[2]			buffer to exchange the transfer data
+ *					with the secure world
+ *
+ * [out]  param[3].u.value.a		bytes transferred by the driver
+ */
+#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER 21
+/* I2C master transfer modes */
+#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD 0
+#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR 1
+/* I2C master control flags */
+#define OPTEE_MSG_RPC_CMD_I2C_FLAGS_TEN_BIT  BIT(0)
+
 #endif /* _OPTEE_MSG_H */
drivers/tee/optee/optee_private.h +1 -0
index 8b71839a357e..564116d6cc58 100644
@@ -17,6 +17,7 @@
 /* Some Global Platform error codes used in this driver */
 #define TEEC_SUCCESS			0x00000000
 #define TEEC_ERROR_BAD_PARAMETERS	0xFFFF0006
+#define TEEC_ERROR_NOT_SUPPORTED        0xFFFF000A
 #define TEEC_ERROR_COMMUNICATION	0xFFFF000E
 #define TEEC_ERROR_OUT_OF_MEMORY	0xFFFF000C
 #define TEEC_ERROR_SHORT_BUFFER		0xFFFF0010
drivers/tee/optee/rpc.c +95 -0

113 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw
Quoted 18 lines · Jorge Ramirez-Ortiz

Some secure elements like NXP's SE050 sit on I2C buses. For OP-TEE to control this type of cryptographic devices it needs coordinated access to the bus, so collisions and RUNTIME_PM dont get in the way.

This trampoline driver allow OP-TEE to access them.

---
v9: params return value must be written before optee_msg_to_param is called
v8: review fixes:
fix types and add TEEC_ERROR_NOT_SUPPORTED to GP errors
v7: add support for ten bit i2c slave addressing
v6: compile out if CONFIG_I2C not enabled
v5: alphabetic order of includes
v4: remove unnecessary extra line in optee_msg.h
v3: use from/to msg param to support all types of memory
modify OPTEE_MSG_RPC_CMD_I2C_TRANSFER message id

Quoted 4 lines
 drivers/tee/optee/optee_msg.h     | 21 +++++++
 drivers/tee/optee/optee_private.h |  1 +
 drivers/tee/optee/rpc.c           | 95 +++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)

Looks good. Did you test this with the recently merged
https://github.com/OP-TEE/optee_os/pull/4033 ?

Cheers,
Jens

#2 lore raw
Quoted 19 lines · Jens Wiklander
Quoted 18 lines · Jorge Ramirez-Ortiz

Some secure elements like NXP's SE050 sit on I2C buses. For OP-TEE to control this type of cryptographic devices it needs coordinated access to the bus, so collisions and RUNTIME_PM dont get in the way.

This trampoline driver allow OP-TEE to access them.

---
v9: params return value must be written before optee_msg_to_param is called
v8: review fixes:
fix types and add TEEC_ERROR_NOT_SUPPORTED to GP errors
v7: add support for ten bit i2c slave addressing
v6: compile out if CONFIG_I2C not enabled
v5: alphabetic order of includes
v4: remove unnecessary extra line in optee_msg.h
v3: use from/to msg param to support all types of memory
modify OPTEE_MSG_RPC_CMD_I2C_TRANSFER message id

Quoted 8 lines
Quoted 4 lines
 drivers/tee/optee/optee_msg.h     | 21 +++++++
 drivers/tee/optee/optee_private.h |  1 +
 drivers/tee/optee/rpc.c           | 95 +++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)

Looks good. Did you test this with the recently merged
https://github.com/OP-TEE/optee_os/pull/4033 ?

yes, I did retest and it is good.

thanks!

Quoted 2 lines

Cheers,
Jens

#3 lore raw
Quoted 26 lines · Foundries
Quoted 24 lines · Jens Wiklander
Quoted 22 lines · Jorge Ramirez-Ortiz

Some secure elements like NXP's SE050 sit on I2C buses. For OP-TEE to control this type of cryptographic devices it needs coordinated access to the bus, so collisions and RUNTIME_PM dont get in the way.

This trampoline driver allow OP-TEE to access them.

---
v9: params return value must be written before optee_msg_to_param is called
v8: review fixes:
fix types and add TEEC_ERROR_NOT_SUPPORTED to GP errors
v7: add support for ten bit i2c slave addressing
v6: compile out if CONFIG_I2C not enabled
v5: alphabetic order of includes
v4: remove unnecessary extra line in optee_msg.h
v3: use from/to msg param to support all types of memory
modify OPTEE_MSG_RPC_CMD_I2C_TRANSFER message id

 drivers/tee/optee/optee_msg.h     | 21 +++++++
 drivers/tee/optee/optee_private.h |  1 +
 drivers/tee/optee/rpc.c           | 95 +++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
Quoted 5 lines
Quoted 3 lines

Looks good. Did you test this with the recently merged
https://github.com/OP-TEE/optee_os/pull/4033 ?

yes, I did retest and it is good.

Good. I'm picking this up.

Thanks,
Jens