soc: j721e: Add sec proxy info
[k3conf/k3conf.git] / common / socinfo.c
1 /*
2  * K3 SoC detection and helper apis
3  *
4  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
5  *      Lokesh Vutla <lokeshvutla@ti.com>
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
36 #include <socinfo.h>
37 #include <mmio.h>
38 #include <string.h>
39 #include <sec_proxy.h>
40 #include <soc/am65x/am65x_host_info.h>
41 #include <soc/am65x/am65x_sec_proxy_info.h>
42 #include <soc/j721e/j721e_host_info.h>
43 #include <soc/j721e/j721e_sec_proxy_info.h>
45 /* Assuming these addresses and definitions stay common across K3 devices */
46 #define CTRLMMR_WKUP_JTAG_DEVICE_ID     0x43000018
47 #define DEVICE_ID_FAMILY_SHIFT  26
48 #define DEVICE_ID_FAMILY_MASK   (0x3f << 26)
49 #define DEVICE_ID_BASE_SHIFT    11
50 #define DEVICE_ID_BASE_MASK     (0x1fff << 11)
51 #define DEVICE_ID_SPEED_SHIFT   6
52 #define DEVICE_ID_SPEED_MASK    (0x1f << 6)
53 #define DEVICE_ID_TEMP_SHIFT    3
54 #define DEVICE_ID_TEMP_MASK     (0x7 << 3)
56 #define CTRLMMR_WKUP_JTAG_ID            0x43000014
57 #define JTAG_ID_VARIANT_SHIFT   28
58 #define JTAG_ID_VARIANT_MASK    (0xf << 28)
59 #define JTAG_ID_PARTNO_SHIFT    12
60 #define JTAG_ID_PARTNO_MASK     (0x7ff << 1)
62 #define CTRLMMR_WKUP_DIE_ID0    0x43000020
63 #define CTRLMMR_WKUP_DIE_ID1    0x43000024
64 #define CTRLMMR_WKUP_DIE_ID2    0x43000028
65 #define CTRLMMR_WKUP_DIE_ID3    0x4300002c
66 #define CTRLMMR_WKUP_DEVSTAT    0x43000030
67 #define CTRLMMR_WKUP_BOOTCFG    0x43000034
69 struct k3conf_soc_info soc_info;
71 static const char soc_name[K3_MAX + 1][SOC_NAME_MAX_LENGTH] = {
72         [AM654] = "AM654",
73         [J721E] = "J721E",
74         [K3_MAX] = "UNKNOWN"
75 };
77 static const char soc_revision[REV_PG_MAX + 1][SOC_REVISION_MAX_LENGTH] = {
78         [REV_PG1_0] = "1.0",
79         [REV_PG2_0] = "2.0",
80         [REV_PG_MAX] = "NULL"
81 };
83 static void am654_init(void)
84 {
85         struct ti_sci_info *sci_info = &soc_info.sci_info;
87         sci_info->host_info = am65x_host_info;
88         sci_info->num_hosts = AM65X_MAX_HOST_IDS;
89         sci_info->sp_info[MAIN_SEC_PROXY] = am65x_main_sp_info;
90         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM65X_MAIN_SEC_PROXY_THREADS;
91         sci_info->sp_info[MCU_SEC_PROXY] = am65x_mcu_sp_info;
92         sci_info->num_sp_threads[MCU_SEC_PROXY] = AM65X_MCU_SEC_PROXY_THREADS;
93 }
95 static void j721e_init(void)
96 {
97         struct ti_sci_info *sci_info = &soc_info.sci_info;
99         sci_info->host_info = j721e_host_info;
100         sci_info->num_hosts = J721E_MAX_HOST_IDS;
101         sci_info->sp_info[MAIN_SEC_PROXY] = j721e_main_sp_info;
102         sci_info->num_sp_threads[MAIN_SEC_PROXY] = J721E_MAIN_SEC_PROXY_THREADS;
103         sci_info->sp_info[MCU_SEC_PROXY] = j721e_mcu_sp_info;
104         sci_info->num_sp_threads[MCU_SEC_PROXY] = J721E_MCU_SEC_PROXY_THREADS;
107 int soc_init(void)
109         memset(&soc_info, 0, sizeof(soc_info));
111         soc_info.soc = (mmio_read_32(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
112                         DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
113         soc_info.rev = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
114                         JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
116         if (soc_info.soc > K3_MAX || !soc_name[soc_info.soc]) {
117                 fprintf(stderr, "Unknown Silicon %d\n", soc_info.soc);
118                 return -1;
119         }
120         if (soc_info.rev > REV_PG_MAX) {
121                 fprintf(stderr, "Unknown Silicon revision %d for SoC %s\n",
122                         soc_info.rev, soc_name[soc_info.soc]);
123                 return -1;
124         }
126         strncpy(soc_info.soc_full_name, "", sizeof(soc_info.soc_full_name));
127         strcat(soc_info.soc_full_name, soc_name[soc_info.soc]);
128         strcat(soc_info.soc_full_name, " PG");
129         strcat(soc_info.soc_full_name, soc_revision[soc_info.rev]);
131         soc_info.host_id = DEFAULT_HOST_ID;
133         if (soc_info.soc == AM654)
134                 am654_init();
135         else if (soc_info.soc == J721E)
136                 j721e_init();
138         /* ToDo: Add error if sec_proxy_init/sci_init is failed */
139         if(!k3_sec_proxy_init())
140                 if (!ti_sci_init())
141                         soc_info.ti_sci_enabled = 1;
143         return 0;
146 int soc_is_j721e(void)
148         return soc_info.soc == J721E;
151 int soc_is_am654(void)
153         return soc_info.soc == AM654;