125781fd4SRahul Gupta // SPDX-License-Identifier: BSD-2-Clause
225781fd4SRahul Gupta /*
325781fd4SRahul Gupta * Copyright (c) 2019, Broadcom
425781fd4SRahul Gupta */
525781fd4SRahul Gupta
6*e0cfd556SAndrew Mustea #include <config.h>
725781fd4SRahul Gupta #include <drivers/bcm_sotp.h>
825781fd4SRahul Gupta #include <io.h>
925781fd4SRahul Gupta #include <kernel/misc.h>
1025781fd4SRahul Gupta #include <kernel/pseudo_ta.h>
1125781fd4SRahul Gupta
1225781fd4SRahul Gupta #define SOTP_SERVICE_UUID \
1325781fd4SRahul Gupta {0x6272636D, 0x2018, 0x1101, \
1425781fd4SRahul Gupta {0x42, 0x43, 0x4D, 0x5F, 0x53, 0x4F, 0x54, 0x50} }
1525781fd4SRahul Gupta
1625781fd4SRahul Gupta enum pta_bcm_sotp_cmd {
1725781fd4SRahul Gupta PTA_BCM_SOTP_CMD_READ = 0,
1825781fd4SRahul Gupta PTA_BCM_SOTP_CMD_WRITE,
1925781fd4SRahul Gupta };
2025781fd4SRahul Gupta
2125781fd4SRahul Gupta #define SOTP_TA_NAME "pta_bcm_sotp.ta"
2225781fd4SRahul Gupta
23*e0cfd556SAndrew Mustea static bool sotp_access_disabled;
24*e0cfd556SAndrew Mustea
25*e0cfd556SAndrew Mustea /**
26*e0cfd556SAndrew Mustea * close_session() - Print a debug message when closing a session and set the
27*e0cfd556SAndrew Mustea * driver to disallow any more pta sessions to connect.
28*e0cfd556SAndrew Mustea * @pSessionContext Unused.
29*e0cfd556SAndrew Mustea */
close_session(void * pSessionContext __unused)30*e0cfd556SAndrew Mustea static void close_session(void *pSessionContext __unused)
31*e0cfd556SAndrew Mustea {
32*e0cfd556SAndrew Mustea DMSG("close entry point for \"%s\"", SOTP_TA_NAME);
33*e0cfd556SAndrew Mustea if (IS_ENABLED(CFG_BCM_SOTP_SINGLE_SESSION))
34*e0cfd556SAndrew Mustea sotp_access_disabled = true;
35*e0cfd556SAndrew Mustea }
36*e0cfd556SAndrew Mustea
pta_sotp_read(uint32_t param_types,TEE_Param params[TEE_NUM_PARAMS])3725781fd4SRahul Gupta static TEE_Result pta_sotp_read(uint32_t param_types,
3825781fd4SRahul Gupta TEE_Param params[TEE_NUM_PARAMS])
3925781fd4SRahul Gupta {
4025781fd4SRahul Gupta uint64_t sotp_row_value = 0;
4125781fd4SRahul Gupta uint32_t val = 0;
4225781fd4SRahul Gupta uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
4325781fd4SRahul Gupta TEE_PARAM_TYPE_VALUE_OUTPUT,
4425781fd4SRahul Gupta TEE_PARAM_TYPE_NONE,
4525781fd4SRahul Gupta TEE_PARAM_TYPE_NONE);
4625781fd4SRahul Gupta if (exp_param_types != param_types) {
4725781fd4SRahul Gupta EMSG("Invalid Param types");
4825781fd4SRahul Gupta return TEE_ERROR_BAD_PARAMETERS;
4925781fd4SRahul Gupta }
5025781fd4SRahul Gupta
5125781fd4SRahul Gupta val = params[0].value.a;
5225781fd4SRahul Gupta
5348ca91edSVahid Dukandar bcm_iproc_sotp_mem_read(val, true, &sotp_row_value);
5425781fd4SRahul Gupta reg_pair_from_64(sotp_row_value, ¶ms[1].value.a,
5525781fd4SRahul Gupta ¶ms[1].value.b);
5625781fd4SRahul Gupta
5725781fd4SRahul Gupta return TEE_SUCCESS;
5825781fd4SRahul Gupta }
5925781fd4SRahul Gupta
pta_sotp_write(uint32_t param_types __unused,TEE_Param params[TEE_NUM_PARAMS]__unused)6025781fd4SRahul Gupta static TEE_Result pta_sotp_write(uint32_t param_types __unused,
6125781fd4SRahul Gupta TEE_Param params[TEE_NUM_PARAMS] __unused)
6225781fd4SRahul Gupta {
6325781fd4SRahul Gupta /* Nothing as of now */
6425781fd4SRahul Gupta return TEE_ERROR_NOT_IMPLEMENTED;
6525781fd4SRahul Gupta }
6625781fd4SRahul Gupta
invoke_command(void * session_context __unused,uint32_t cmd_id,uint32_t param_types,TEE_Param params[TEE_NUM_PARAMS])6725781fd4SRahul Gupta static TEE_Result invoke_command(void *session_context __unused,
6825781fd4SRahul Gupta uint32_t cmd_id,
6925781fd4SRahul Gupta uint32_t param_types,
7025781fd4SRahul Gupta TEE_Param params[TEE_NUM_PARAMS])
7125781fd4SRahul Gupta {
7225781fd4SRahul Gupta TEE_Result res = TEE_SUCCESS;
7325781fd4SRahul Gupta
7425781fd4SRahul Gupta DMSG("command entry point[%d] for \"%s\"", cmd_id, SOTP_TA_NAME);
7525781fd4SRahul Gupta
76*e0cfd556SAndrew Mustea if (IS_ENABLED(CFG_BCM_SOTP_SINGLE_SESSION) && sotp_access_disabled) {
77*e0cfd556SAndrew Mustea DMSG("bcm sotp pta access disabled");
78*e0cfd556SAndrew Mustea return TEE_ERROR_ACCESS_DENIED;
79*e0cfd556SAndrew Mustea }
80*e0cfd556SAndrew Mustea
8125781fd4SRahul Gupta switch (cmd_id) {
8225781fd4SRahul Gupta case PTA_BCM_SOTP_CMD_READ:
8325781fd4SRahul Gupta res = pta_sotp_read(param_types, params);
8425781fd4SRahul Gupta break;
8525781fd4SRahul Gupta case PTA_BCM_SOTP_CMD_WRITE:
8625781fd4SRahul Gupta res = pta_sotp_write(param_types, params);
8725781fd4SRahul Gupta break;
8825781fd4SRahul Gupta default:
8925781fd4SRahul Gupta EMSG("cmd %d Not supported %s", cmd_id, SOTP_TA_NAME);
9025781fd4SRahul Gupta res = TEE_ERROR_NOT_SUPPORTED;
9125781fd4SRahul Gupta break;
9225781fd4SRahul Gupta }
9325781fd4SRahul Gupta
9425781fd4SRahul Gupta return res;
9525781fd4SRahul Gupta }
9625781fd4SRahul Gupta
9725781fd4SRahul Gupta pseudo_ta_register(.uuid = SOTP_SERVICE_UUID,
9825781fd4SRahul Gupta .name = SOTP_TA_NAME,
9925781fd4SRahul Gupta .flags = PTA_DEFAULT_FLAGS,
100*e0cfd556SAndrew Mustea .close_session_entry_point = close_session,
10125781fd4SRahul Gupta .invoke_command_entry_point = invoke_command);
102