1 /*
2 * K3CONF Command Show
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 <stdlib.h>
37 #include <string.h>
38 #include <stdio.h>
39 #include <sec_proxy.h>
40 #include <tisci.h>
41 #include <socinfo.h>
42 #include <help.h>
43 #include <autoadjust_table.h>
44 #include <k3conf.h>
46 static int show_hosts_info(void)
47 {
48 struct ti_sci_host_info *hosts = soc_info.sci_info.host_info;
49 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
50 uint32_t row = 0;
52 autoadjust_table_init(table);
53 strncpy(table[row][0], "Host ID", TABLE_MAX_ELT_LEN);
54 strncpy(table[row][1], "Host Name", TABLE_MAX_ELT_LEN);
55 strncpy(table[row][2], "Security Status", TABLE_MAX_ELT_LEN);
56 strncpy(table[row][3], "Description", TABLE_MAX_ELT_LEN);
58 for (row = 0; row < soc_info.sci_info.num_hosts; row++) {
59 snprintf(table[row + 1][0], TABLE_MAX_ELT_LEN, "%d",
60 hosts[row].host_id);
61 strncpy(table[row + 1][1], hosts[row].host_name,
62 TABLE_MAX_ELT_LEN);
63 strncpy(table[row + 1][2], hosts[row].security_status,
64 TABLE_MAX_ELT_LEN);
65 strncpy(table[row + 1][3], hosts[row].description,
66 TABLE_MAX_ELT_LEN);
67 }
69 return autoadjust_table_print(table, row + 1, 4);
70 }
72 static int show_sp_threads_info(void)
73 {
74 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
75 struct ti_sci_sec_proxy_info *sp;
76 uint32_t row = 0, i;
78 autoadjust_table_init(table);
79 strncpy(table[row][0],
80 "Secure Proxy thread allocation for main_sec_proxy0",
81 TABLE_MAX_ELT_LEN);
82 row++;
83 strncpy(table[row][0], "Thread ID", TABLE_MAX_ELT_LEN);
84 strncpy(table[row][1], "Direction", TABLE_MAX_ELT_LEN);
85 strncpy(table[row][2], "No. of msgs", TABLE_MAX_ELT_LEN);
86 strncpy(table[row][3], "Host", TABLE_MAX_ELT_LEN);
87 strncpy(table[row][4], "Host Function", TABLE_MAX_ELT_LEN);
88 row++;
90 sp = soc_info.sci_info.sp_info[MAIN_SEC_PROXY];
91 for (i = 0; i < soc_info.sci_info.num_sp_threads[MAIN_SEC_PROXY];
92 row++, i++) {
93 snprintf(table[row][0], TABLE_MAX_ELT_LEN, "%5d", sp[i].sp_id);
94 strncpy(table[row][1], sp[i].sp_dir, TABLE_MAX_ELT_LEN);
95 snprintf(table[row][2], TABLE_MAX_ELT_LEN, "%7d", sp[i].num_msgs);
96 strncpy(table[row][3], sp[i].host, TABLE_MAX_ELT_LEN);
97 strncpy(table[row][4], sp[i].host_function, TABLE_MAX_ELT_LEN);
98 }
100 autoadjust_table_generic_fprint(stdout, table, row, 5,
101 TABLE_HAS_SUBTITLE | TABLE_HAS_TITLE);
102 row = 0;
103 autoadjust_table_init(table);
104 strncpy(table[row][0],
105 "Secure Proxy thread allocation for mcu_sec_proxy0",
106 TABLE_MAX_ELT_LEN);
107 row++;
108 strncpy(table[row][0], "Thread ID", TABLE_MAX_ELT_LEN);
109 strncpy(table[row][1], "Direction", TABLE_MAX_ELT_LEN);
110 strncpy(table[row][2], "No. of msgs", TABLE_MAX_ELT_LEN);
111 strncpy(table[row][3], "Host", TABLE_MAX_ELT_LEN);
112 strncpy(table[row][4], "Host Function", TABLE_MAX_ELT_LEN);
113 row++;
115 sp = soc_info.sci_info.sp_info[MCU_SEC_PROXY];
116 for (i = 0; i < soc_info.sci_info.num_sp_threads[MCU_SEC_PROXY];
117 row++, i++) {
118 snprintf(table[row][0], TABLE_MAX_ELT_LEN, "%5d", sp[i].sp_id);
119 strncpy(table[row][1], sp[i].sp_dir, TABLE_MAX_ELT_LEN);
120 snprintf(table[row][2], TABLE_MAX_ELT_LEN, "%7d", sp[i].num_msgs);
121 strncpy(table[row][3], sp[i].host, TABLE_MAX_ELT_LEN);
122 strncpy(table[row][4], sp[i].host_function, TABLE_MAX_ELT_LEN);
123 }
125 return autoadjust_table_generic_fprint(stdout, table, row, 5,
126 TABLE_HAS_SUBTITLE | TABLE_HAS_TITLE);
127 }
129 static int show_clocks_info(int argc, char *argv[])
130 {
131 struct ti_sci_clocks_info *c = soc_info.sci_info.clocks_info;
132 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
133 uint32_t row = 0, dev_id;
134 int found = 0, ret;
136 autoadjust_table_init(table);
137 strncpy(table[row][0], "Device ID", TABLE_MAX_ELT_LEN);
138 strncpy(table[row][1], "Clock ID", TABLE_MAX_ELT_LEN);
139 strncpy(table[row][2], "Clock Name", TABLE_MAX_ELT_LEN);
140 strncpy(table[row][3], "Clock Function", TABLE_MAX_ELT_LEN);
142 if (argc)
143 goto print_single_device;
145 for (row = 0; row < soc_info.sci_info.num_clocks; row++) {
146 snprintf(table[row + 1][0], TABLE_MAX_ELT_LEN, "%5d",
147 c[row].dev_id);
148 snprintf(table[row + 1][1], TABLE_MAX_ELT_LEN, "%5d",
149 c[row].clk_id);
150 strncpy(table[row + 1][2], c[row].clk_name, TABLE_MAX_ELT_LEN);
151 strncpy(table[row + 1][3], c[row].clk_function, TABLE_MAX_ELT_LEN);
152 }
154 return autoadjust_table_print(table, row + 1, 4);
156 print_single_device:
157 ret = sscanf(argv[0], "%u", &dev_id);
158 if (ret != 1)
159 return -1;
161 for (row = 0; row < soc_info.sci_info.num_clocks; row++) {
162 if (dev_id == c[row].dev_id) {
163 snprintf(table[found + 1][0], TABLE_MAX_ELT_LEN, "%5d",
164 c[row].dev_id);
165 snprintf(table[found + 1][1], TABLE_MAX_ELT_LEN, "%5d",
166 c[row].clk_id);
167 strncpy(table[found + 1][2], c[row].clk_name,
168 TABLE_MAX_ELT_LEN);
169 strncpy(table[found + 1][3], c[row].clk_function, TABLE_MAX_ELT_LEN);
170 found++;
171 }
172 }
174 if (!found)
175 return -1;
177 return autoadjust_table_print(table, found + 1, 4);
178 }
180 static int show_devices_info(int argc, char *argv[])
181 {
182 struct ti_sci_devices_info *p = soc_info.sci_info.devices_info;
183 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
184 uint32_t row = 0, dev_id;
185 int found = 0, ret;
187 autoadjust_table_init(table);
188 strncpy(table[row][0], "Device ID", TABLE_MAX_ELT_LEN);
189 strncpy(table[row][1], "Device Name", TABLE_MAX_ELT_LEN);
191 if (argc)
192 goto print_single_device;
194 for (row = 0; row < soc_info.sci_info.num_devices; row++) {
195 snprintf(table[row + 1][0], TABLE_MAX_ELT_LEN, "%5d",
196 p[row].dev_id);
197 strncpy(table[row + 1][1], p[row].name, TABLE_MAX_ELT_LEN);
198 }
200 return autoadjust_table_print(table, row + 1, 2);
202 print_single_device:
203 ret = sscanf(argv[0], "%u", &dev_id);
204 if (ret != 1)
205 return -1;
207 for (row = 0; row < soc_info.sci_info.num_devices; row++) {
208 if (dev_id == p[row].dev_id) {
209 snprintf(table[1][0], TABLE_MAX_ELT_LEN, "%5d",
210 p[row].dev_id);
211 strncpy(table[1][1], p[row].name,
212 TABLE_MAX_ELT_LEN);
213 found = 1;
214 break;
215 }
216 }
218 if (!found)
219 return -1;
221 return autoadjust_table_print(table, 2, 2);
222 }
224 static int show_rm_info(int argc, char *argv[])
225 {
226 struct ti_sci_devices_info *d = soc_info.sci_info.devices_info;
227 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
228 struct ti_sci_rm_info *r = soc_info.sci_info.rm_info;
229 uint32_t filter_type = 0, type, subtype, i, j, row;
230 char *subtype_name;
232 if (argc > 1)
233 return -1;
234 if (argc == 1)
235 sscanf(argv[0], "%u", &filter_type);
237 snprintf(table[0][0], TABLE_MAX_ELT_LEN,
238 "Resources managed by System Firmware");
239 snprintf(table[1][0], TABLE_MAX_ELT_LEN, "Unique Type");
240 snprintf(table[1][1], TABLE_MAX_ELT_LEN, "dev_id");
241 snprintf(table[1][2], TABLE_MAX_ELT_LEN, "Device name");
242 snprintf(table[1][3], TABLE_MAX_ELT_LEN, "subtype_id");
243 snprintf(table[1][4], TABLE_MAX_ELT_LEN, "Subtype name");
245 row = 2;
246 for (i = 0; i < soc_info.sci_info.num_res; i++) {
248 type = r[i].utype >> 6;
249 subtype = r[i].utype & 0x3F;
250 subtype_name = r[i].subtype_name;
252 if (filter_type && filter_type != type)
253 continue;
255 for (j = 0; j < soc_info.sci_info.num_devices; j++) {
256 if (type == d[j].dev_id)
257 break;
258 }
260 snprintf(table[row][0], TABLE_MAX_ELT_LEN,
261 "0x%04x", r[i].utype);
262 snprintf(table[row][1], TABLE_MAX_ELT_LEN,
263 "%d", d[j].dev_id);
264 snprintf(table[row][2], TABLE_MAX_ELT_LEN,
265 "%s", d[j].name);
266 snprintf(table[row][3], TABLE_MAX_ELT_LEN,
267 "%d", subtype);
268 snprintf(table[row][4], TABLE_MAX_ELT_LEN,
269 "%s", subtype_name);
270 row++;
271 }
273 if (row == 2) {
274 fprintf(stderr, "Resources for type %d are not managed by SYSFW\n",
275 filter_type);
276 return -1;
277 }
279 return autoadjust_table_generic_fprint(stdout, table, row, 5,
280 TABLE_HAS_SUBTITLE | TABLE_HAS_TITLE);
281 }
283 static int show_processors_info(void)
284 {
285 struct ti_sci_processors_info *p = soc_info.sci_info.processors_info;
286 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
287 uint32_t row = 0;
289 autoadjust_table_init(table);
290 strncpy(table[row][0], "Device ID", TABLE_MAX_ELT_LEN);
291 strncpy(table[row][1], "Processor ID", TABLE_MAX_ELT_LEN);
292 strncpy(table[row][2], "Processor Name", TABLE_MAX_ELT_LEN);
294 for (row = 0; row < soc_info.sci_info.num_processors; row++) {
295 snprintf(table[row + 1][0], TABLE_MAX_ELT_LEN, "%5d",
296 p[row].dev_id);
297 snprintf(table[row + 1][1], TABLE_MAX_ELT_LEN, "%7d",
298 p[row].processor_id);
299 strncpy(table[row + 1][2], p[row].name, TABLE_MAX_ELT_LEN);
300 }
302 return autoadjust_table_print(table, row + 1, 3);
303 }
305 int process_show_command(int argc, char *argv[])
306 {
307 int ret;
309 if (argc < 1) {
310 help(HELP_SHOW);
311 return -1;
312 }
314 if (!strncmp(argv[0], "host", 4)) {
315 ret = show_hosts_info();
316 if (ret)
317 help(HELP_SHOW_HOST);
318 } else if (!strncmp(argv[0], "thread", 6)) {
319 ret = show_sp_threads_info();
320 if (ret)
321 help(HELP_SHOW_SEC_PROXY);
322 } else if (!strncmp(argv[0], "device", 6)) {
323 argc--;
324 argv++;
325 ret = show_devices_info(argc, argv);
326 if (ret) {
327 fprintf(stderr, "Invalid device arguments\n");
328 help(HELP_SHOW_DEVICE);
329 }
330 } else if (!strncmp(argv[0], "clock", 5)) {
331 argc--;
332 argv++;
333 ret = show_clocks_info(argc, argv);
334 if (ret) {
335 fprintf(stderr, "Invalid clock arguments\n");
336 help(HELP_SHOW_CLOCK);
337 }
338 } else if(!strncmp(argv[0], "processor", 9)) {
339 ret = show_processors_info();
340 if (ret)
341 help(HELP_SHOW_PROCESSOR);
342 } else if(!strncmp(argv[0], "rm", 2)) {
343 argc--;
344 argv++;
345 ret = show_rm_info(argc, argv);
346 if (ret) {
347 fprintf(stderr, "Invalid device_id arguments\n");
348 help(HELP_SHOW_RM);
349 }
350 } else if (!strcmp(argv[0], "--help")) {
351 help(HELP_SHOW);
352 return 0;
353 } else {
354 fprintf(stderr, "Invalid argument %s\n", argv[1]);
355 help(HELP_SHOW);
356 return -1;
357 }
358 return ret;
359 }