]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - k3conf/k3conf.git/blobdiff - common/sec_proxy.c
common: cmd_dump: Gracefully handle ti_sci_cmd_get_clk_state() failure
[k3conf/k3conf.git] / common / sec_proxy.c
index 9de3f9331bb1f9c982feb54c569e649913ebf50c..ca43611f90ac1b812f711eccf46baad4c000e796 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * K3 Secure proxy driver
  *
- * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
  *     Lokesh Vutla <lokeshvutla@ti.com>
  *
  *  Redistribution and use in source and binary forms, with or without
 #include <mmio.h>
 #include <error.h>
 #include <socinfo.h>
+#include <string.h>
+
+#ifdef DEBUG
+#define dprintf(format, ...)    printf(format, ## __VA_ARGS__)
+#else
+#define dprintf(format, ...)
+#endif
 
 /* SEC PROXY RT THREAD STATUS */
 #define RT_THREAD_STATUS                       0x0
 #define SEC_PROXY_DATA_START_OFFS              0x4
 #define SEC_PROXY_DATA_END_OFFS                        0x3c
 
-/* Physical address for AM6 NAVSS 256 Main domain */
-#define SEC_PROXY0_CFG_MMRS            0x31140000
-#define SEC_PROXY0_SRC_TARGET_DATA     0x32C00000
-#define SEC_PROXY0_CFG_SCFG            0x32800000
-#define SEC_PROXY0_CFG_RT              0x32400000
+struct k3_sec_proxy_base k3_generic_sec_proxy_base = {
+       .src_target_data = 0x32c00000,
+       .cfg_scfg = 0x32800000,
+       .cfg_rt = 0x32400000,
+};
+
+struct k3_sec_proxy_base k3_lite_sec_proxy_base = {
+       .src_target_data = 0x4d000000,
+       .cfg_scfg = 0x4a400000,
+       .cfg_rt = 0x4a600000,
+};
 
 struct k3_sec_proxy_thread {
        uint32_t id;
@@ -193,25 +206,69 @@ int k3_sec_proxy_recv(struct k3_sec_proxy_msg *msg)
        return 0;
 }
 
+static int get_thread_id(char *host_name, char *function)
+{
+       struct ti_sci_info *sci_info = &soc_info.sci_info;
+       uint32_t i;
+
+       for (i = 0; i < sci_info->num_sp_threads[MAIN_SEC_PROXY]; i++)
+               if (!strcmp(host_name,
+                           sci_info->sp_info[MAIN_SEC_PROXY][i].host) &&
+                   !strcmp(function,
+                           sci_info->sp_info[MAIN_SEC_PROXY][i].host_function))
+                       return sci_info->sp_info[MAIN_SEC_PROXY][i].sp_id;
+
+       return -1;
+
+}
+
+static char* get_host_name(uint32_t host_id)
+{
+       struct ti_sci_info *sci_info = &soc_info.sci_info;
+       uint32_t i;
+
+       for (i = 0; i < sci_info->num_hosts; i++)
+               if (host_id == sci_info->host_info[i].host_id)
+                       return sci_info->host_info[i].host_name;
+
+       return NULL;
+}
+
 int k3_sec_proxy_init(void)
 {
-       uint32_t rx_thread, tx_thread;
+       struct k3_sec_proxy_base *spb = soc_info.sec_proxy;
+       int rx_thread, tx_thread;
+       char *host_name;
+
+       host_name = get_host_name(soc_info.host_id);
+       if (!host_name) {
+               fprintf(stderr, "Invalid host id %d, using default host_id %d\n",
+                       soc_info.host_id, DEFAULT_HOST_ID);
+               soc_info.host_id = DEFAULT_HOST_ID;
+               host_name = get_host_name(soc_info.host_id);
+       }
 
-       if (soc_info.host_id == DEFAULT_HOST_ID) {
-               tx_thread = DEFAULT_SEC_PROXY_TX_THREAD;
-               rx_thread = DEFAULT_SEC_PROXY_RX_THREAD;
+       rx_thread = get_thread_id(host_name, "response");
+       if (rx_thread < 0) {
+               fprintf(stderr, "Invalid host id %d, using default host_id %d\n",
+                       soc_info.host_id, DEFAULT_HOST_ID);
+               soc_info.host_id = DEFAULT_HOST_ID;
+               host_name = get_host_name(soc_info.host_id);
+               rx_thread = get_thread_id(host_name, "response");
        }
+       tx_thread = get_thread_id(host_name, "low_priority");
+       dprintf("host_name = %s, tx_thread = %d, rx_thread = %d\n",
+               host_name, tx_thread, rx_thread);
 
-       /* ToDO: Get thread ids using host_id and soc information */
        spts[SEC_PROXY_TX_THREAD].id = tx_thread;
-       spts[SEC_PROXY_TX_THREAD].data = SEC_PROXY_THREAD(SEC_PROXY0_SRC_TARGET_DATA, tx_thread);
-       spts[SEC_PROXY_TX_THREAD].scfg = SEC_PROXY_THREAD(SEC_PROXY0_CFG_SCFG, tx_thread);
-       spts[SEC_PROXY_TX_THREAD].rt = SEC_PROXY_THREAD(SEC_PROXY0_CFG_RT, tx_thread);
+       spts[SEC_PROXY_TX_THREAD].data = SEC_PROXY_THREAD(spb->src_target_data, tx_thread);
+       spts[SEC_PROXY_TX_THREAD].scfg = SEC_PROXY_THREAD(spb->cfg_scfg, tx_thread);
+       spts[SEC_PROXY_TX_THREAD].rt = SEC_PROXY_THREAD(spb->cfg_rt, tx_thread);
 
        spts[SEC_PROXY_RX_THREAD].id = rx_thread;
-       spts[SEC_PROXY_RX_THREAD].data = SEC_PROXY_THREAD(SEC_PROXY0_SRC_TARGET_DATA, rx_thread);
-       spts[SEC_PROXY_RX_THREAD].scfg = SEC_PROXY_THREAD(SEC_PROXY0_CFG_SCFG, rx_thread);
-       spts[SEC_PROXY_RX_THREAD].rt = SEC_PROXY_THREAD(SEC_PROXY0_CFG_RT, rx_thread);
+       spts[SEC_PROXY_RX_THREAD].data = SEC_PROXY_THREAD(spb->src_target_data, rx_thread);
+       spts[SEC_PROXY_RX_THREAD].scfg = SEC_PROXY_THREAD(spb->cfg_scfg, rx_thread);
+       spts[SEC_PROXY_RX_THREAD].rt = SEC_PROXY_THREAD(spb->cfg_rt, rx_thread);
 
        return 0;
 }