4e0dcd858a07ce5f6c98942a1ac8d72d50f5309b
[k3conf/k3conf.git] / common / socinfo.c
1 /*
2  * K3 SoC detection and helper apis
3  *
4  * Copyright (C) 2019 Texas Instruments Incorporated - https://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/am65x/am65x_processors_info.h>
43 #include <soc/am65x/am65x_devices_info.h>
44 #include <soc/am65x/am65x_clocks_info.h>
45 #include <soc/am65x/am65x_rm_info.h>
46 #include <soc/am65x_sr2/am65x_sr2_host_info.h>
47 #include <soc/am65x_sr2/am65x_sr2_sec_proxy_info.h>
48 #include <soc/am65x_sr2/am65x_sr2_processors_info.h>
49 #include <soc/am65x_sr2/am65x_sr2_devices_info.h>
50 #include <soc/am65x_sr2/am65x_sr2_clocks_info.h>
51 #include <soc/am65x_sr2/am65x_sr2_rm_info.h>
52 #include <soc/j721e/j721e_host_info.h>
53 #include <soc/j721e/j721e_sec_proxy_info.h>
54 #include <soc/j721e/j721e_processors_info.h>
55 #include <soc/j721e/j721e_devices_info.h>
56 #include <soc/j721e/j721e_clocks_info.h>
57 #include <soc/j721e/j721e_rm_info.h>
58 #include <soc/j7200/j7200_host_info.h>
59 #include <soc/j7200/j7200_sec_proxy_info.h>
60 #include <soc/j7200/j7200_processors_info.h>
61 #include <soc/j7200/j7200_devices_info.h>
62 #include <soc/j7200/j7200_clocks_info.h>
63 #include <soc/j7200/j7200_rm_info.h>
64 #include <soc/am64x/am64x_host_info.h>
65 #include <soc/am64x/am64x_sec_proxy_info.h>
66 #include <soc/am64x/am64x_processors_info.h>
67 #include <soc/am64x/am64x_devices_info.h>
68 #include <soc/am64x/am64x_clocks_info.h>
69 #include <soc/am64x/am64x_rm_info.h>
70 #include <soc/am62x/am62x_devices_info.h>
71 #include <soc/am62x/am62x_clocks_info.h>
72 #include <soc/am62x/am62x_host_info.h>
73 #include <soc/am62x/am62x_processors_info.h>
74 #include <soc/am62x/am62x_rm_info.h>
76 /* Assuming these addresses and definitions stay common across K3 devices */
77 #define CTRLMMR_WKUP_JTAG_DEVICE_ID     0x43000018
78 #define DEVICE_ID_FAMILY_SHIFT  26
79 #define DEVICE_ID_FAMILY_MASK   (0x3f << 26)
80 #define DEVICE_ID_BASE_SHIFT    11
81 #define DEVICE_ID_BASE_MASK     (0x1fff << 11)
82 #define DEVICE_ID_SPEED_SHIFT   6
83 #define DEVICE_ID_SPEED_MASK    (0x1f << 6)
84 #define DEVICE_ID_TEMP_SHIFT    3
85 #define DEVICE_ID_TEMP_MASK     (0x7 << 3)
87 #define CTRLMMR_WKUP_JTAG_ID            0x43000014
88 #define JTAG_ID_VARIANT_SHIFT   28
89 #define JTAG_ID_VARIANT_MASK    (0xf << 28)
90 #define JTAG_ID_PARTNO_SHIFT    12
91 #define JTAG_ID_PARTNO_MASK     (0xffff << 12)
93 #define CTRLMMR_WKUP_DIE_ID0    0x43000020
94 #define CTRLMMR_WKUP_DIE_ID1    0x43000024
95 #define CTRLMMR_WKUP_DIE_ID2    0x43000028
96 #define CTRLMMR_WKUP_DIE_ID3    0x4300002c
97 #define CTRLMMR_WKUP_DEVSTAT    0x43000030
98 #define CTRLMMR_WKUP_BOOTCFG    0x43000034
100 struct k3conf_soc_info soc_info;
102 static const char soc_revision[REV_PG_MAX + 1][SOC_REVISION_MAX_LENGTH] = {
103         [REV_SR1_0] = "1.0",
104         [REV_SR2_0] = "2.0",
105         [REV_PG_MAX] = "NULL"
106 };
108 static void am654_init(void)
110         struct ti_sci_info *sci_info = &soc_info.sci_info;
112         sci_info->host_info = am65x_host_info;
113         sci_info->num_hosts = AM65X_MAX_HOST_IDS;
114         sci_info->sp_info[MAIN_SEC_PROXY] = am65x_main_sp_info;
115         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM65X_MAIN_SEC_PROXY_THREADS;
116         sci_info->sp_info[MCU_SEC_PROXY] = am65x_mcu_sp_info;
117         sci_info->num_sp_threads[MCU_SEC_PROXY] = AM65X_MCU_SEC_PROXY_THREADS;
118         sci_info->processors_info = am65x_processors_info;
119         sci_info->num_processors = AM65X_MAX_PROCESSORS_IDS;
120         sci_info->devices_info = am65x_devices_info;
121         sci_info->num_devices = AM65X_MAX_DEVICES;
122         sci_info->clocks_info = am65x_clocks_info;
123         sci_info->num_clocks = AM65X_MAX_CLOCKS;
124         sci_info->rm_info = am65x_rm_info;
125         sci_info->num_res = AM65X_MAX_RES;
126         soc_info.host_id = DEFAULT_HOST_ID;
127         soc_info.sec_proxy = &k3_generic_sec_proxy_base;
130 static void am654_sr2_init(void)
132         struct ti_sci_info *sci_info = &soc_info.sci_info;
134         sci_info->host_info = am65x_sr2_host_info;
135         sci_info->num_hosts = AM65X_SR2_MAX_HOST_IDS;
136         sci_info->sp_info[MAIN_SEC_PROXY] = am65x_sr2_main_sp_info;
137         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM65X_SR2_MAIN_SEC_PROXY_THREADS;
138         sci_info->sp_info[MCU_SEC_PROXY] = am65x_sr2_mcu_sp_info;
139         sci_info->num_sp_threads[MCU_SEC_PROXY] = AM65X_SR2_MCU_SEC_PROXY_THREADS;
140         sci_info->processors_info = am65x_sr2_processors_info;
141         sci_info->num_processors = AM65X_SR2_MAX_PROCESSORS_IDS;
142         sci_info->devices_info = am65x_sr2_devices_info;
143         sci_info->num_devices = AM65X_SR2_MAX_DEVICES;
144         sci_info->clocks_info = am65x_sr2_clocks_info;
145         sci_info->num_clocks = AM65X_SR2_MAX_CLOCKS;
146         sci_info->rm_info = am65x_sr2_rm_info;
147         sci_info->num_res = AM65X_SR2_MAX_RES;
148         soc_info.host_id = DEFAULT_HOST_ID;
149         soc_info.sec_proxy = &k3_generic_sec_proxy_base;
152 static void j721e_init(void)
154         struct ti_sci_info *sci_info = &soc_info.sci_info;
156         sci_info->host_info = j721e_host_info;
157         sci_info->num_hosts = J721E_MAX_HOST_IDS;
158         sci_info->sp_info[MAIN_SEC_PROXY] = j721e_main_sp_info;
159         sci_info->num_sp_threads[MAIN_SEC_PROXY] = J721E_MAIN_SEC_PROXY_THREADS;
160         sci_info->sp_info[MCU_SEC_PROXY] = j721e_mcu_sp_info;
161         sci_info->num_sp_threads[MCU_SEC_PROXY] = J721E_MCU_SEC_PROXY_THREADS;
162         sci_info->processors_info = j721e_processors_info;
163         sci_info->num_processors = J721E_MAX_PROCESSORS_IDS;
164         sci_info->devices_info = j721e_devices_info;
165         sci_info->num_devices = J721E_MAX_DEVICES;
166         sci_info->clocks_info = j721e_clocks_info;
167         sci_info->num_clocks = J721E_MAX_CLOCKS;
168         sci_info->rm_info = j721e_rm_info;
169         sci_info->num_res = J721E_MAX_RES;
170         soc_info.host_id = DEFAULT_HOST_ID;
171         soc_info.sec_proxy = &k3_generic_sec_proxy_base;
174 static void j7200_init(void)
176         struct ti_sci_info *sci_info = &soc_info.sci_info;
178         sci_info->host_info = j7200_host_info;
179         sci_info->num_hosts = J7200_MAX_HOST_IDS;
180         sci_info->sp_info[MAIN_SEC_PROXY] = j7200_main_sp_info;
181         sci_info->num_sp_threads[MAIN_SEC_PROXY] = J7200_MAIN_SEC_PROXY_THREADS;
182         sci_info->sp_info[MCU_SEC_PROXY] = j7200_mcu_sp_info;
183         sci_info->num_sp_threads[MCU_SEC_PROXY] = J7200_MCU_SEC_PROXY_THREADS;
184         sci_info->processors_info = j7200_processors_info;
185         sci_info->num_processors = J7200_MAX_PROCESSORS_IDS;
186         sci_info->devices_info = j7200_devices_info;
187         sci_info->num_devices = J7200_MAX_DEVICES;
188         sci_info->clocks_info = j7200_clocks_info;
189         sci_info->num_clocks = J7200_MAX_CLOCKS;
190         sci_info->rm_info = j7200_rm_info;
191         sci_info->num_res = J7200_MAX_RES;
192         soc_info.host_id = DEFAULT_HOST_ID;
193         soc_info.sec_proxy = &k3_generic_sec_proxy_base;
196 static void am64x_init(void)
198         struct ti_sci_info *sci_info = &soc_info.sci_info;
200         sci_info->host_info = am64x_host_info;
201         sci_info->num_hosts = AM64X_MAX_HOST_IDS;
202         sci_info->sp_info[MAIN_SEC_PROXY] = am64x_main_sp_info;
203         sci_info->num_sp_threads[MAIN_SEC_PROXY] = AM64X_MAIN_SEC_PROXY_THREADS;
204         sci_info->sp_info[MCU_SEC_PROXY] = NULL;
205         sci_info->num_sp_threads[MCU_SEC_PROXY] = 0;
206         sci_info->processors_info = am64x_processors_info;
207         sci_info->num_processors = AM64X_MAX_PROCESSORS_IDS;
208         sci_info->devices_info = am64x_devices_info;
209         sci_info->num_devices = AM64X_MAX_DEVICES;
210         sci_info->clocks_info = am64x_clocks_info;
211         sci_info->num_clocks = AM64X_MAX_CLOCKS;
212         sci_info->rm_info = am64x_rm_info;
213         sci_info->num_res = AM64X_MAX_RES;
214         soc_info.host_id = 13;
215         soc_info.sec_proxy = &k3_lite_sec_proxy_base;
218 static void am62x_init(void)
220         struct ti_sci_info *sci_info = &soc_info.sci_info;
222         sci_info->rm_info = am62x_rm_info;
223         sci_info->num_res = AM62X_MAX_RES;
224         sci_info->processors_info = am62x_processors_info;
225         sci_info->num_processors = AM62X_MAX_PROCESSORS_IDS;
226         sci_info->host_info = am62x_host_info;
227         sci_info->num_hosts = AM62X_MAX_HOST_IDS;
228         sci_info->devices_info = am62x_devices_info;
229         sci_info->num_devices = AM62X_MAX_DEVICES;
230         sci_info->clocks_info = am62x_clocks_info;
231         sci_info->num_clocks = AM62X_MAX_CLOCKS;
232         soc_info.host_id = 13;
233         soc_info.sec_proxy = &k3_lite_sec_proxy_base;
236 int soc_init(uint32_t host_id)
238         char *name;
240         memset(&soc_info, 0, sizeof(soc_info));
242         soc_info.soc = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
243                         JTAG_ID_PARTNO_MASK) >> JTAG_ID_PARTNO_SHIFT;
244         soc_info.rev = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
245                         JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
247         switch (soc_info.soc) {
248         case AM65X:
249                 name = "AM65x";
250                 break;
251         case J721E:
252                 name = "J721E";
253                 break;
254         case J7200:
255                 name = "J7200";
256                 break;
257         case AM64X:
258                 name = "AM64x";
259                 break;
260         case AM62X:
261                 name = "AM62X";
262                 break;
263         default:
264                 fprintf(stderr, "Unknown Silicon %d\n", soc_info.soc);
265                 return -1;
266         };
268         if (soc_info.rev > REV_PG_MAX) {
269                 fprintf(stderr, "Unknown Silicon revision %d for SoC %s\n",
270                         soc_info.rev, name);
271                 return -1;
272         }
274         strncpy(soc_info.soc_full_name, "", sizeof(soc_info.soc_full_name));
275         strcat(soc_info.soc_full_name, name);
276         strcat(soc_info.soc_full_name, " SR");
277         strcat(soc_info.soc_full_name, soc_revision[soc_info.rev]);
279         if (soc_info.soc == AM65X && soc_info.rev == REV_SR1_0)
280                 am654_init();
281         else if (soc_info.soc == AM65X && soc_info.rev == REV_SR2_0)
282                 am654_sr2_init();
283         else if (soc_info.soc == J721E)
284                 j721e_init();
285         else if (soc_info.soc == J7200)
286                 j7200_init();
287         else if (soc_info.soc == AM64X)
288                 am64x_init();
289         else if (soc_info.soc == AM62X)
290                 am62x_init();
292         if (host_id != INVALID_HOST_ID)
293                 soc_info.host_id = host_id;
295         /* ToDo: Add error if sec_proxy_init/sci_init is failed */
296         if(!k3_sec_proxy_init())
297                 if (!ti_sci_init())
298                         soc_info.ti_sci_enabled = 1;
300         return 0;
303 int soc_is_j721e(void)
305         return soc_info.soc == J721E;
308 int soc_is_am654(void)
310         return soc_info.soc == AM65X;