1 /*
2 * K3CONF Command Show
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 <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_processors_info(void)
225 {
226 struct ti_sci_processors_info *p = soc_info.sci_info.processors_info;
227 char table[TABLE_MAX_ROW][TABLE_MAX_COL][TABLE_MAX_ELT_LEN];
228 uint32_t row = 0;
230 autoadjust_table_init(table);
231 strncpy(table[row][0], "Device ID", TABLE_MAX_ELT_LEN);
232 strncpy(table[row][1], "Processor ID", TABLE_MAX_ELT_LEN);
233 strncpy(table[row][2], "Processor Name", TABLE_MAX_ELT_LEN);
235 for (row = 0; row < soc_info.sci_info.num_processors; row++) {
236 snprintf(table[row + 1][0], TABLE_MAX_ELT_LEN, "%5d",
237 p[row].dev_id);
238 snprintf(table[row + 1][1], TABLE_MAX_ELT_LEN, "%7d",
239 p[row].processor_id);
240 strncpy(table[row + 1][2], p[row].name, TABLE_MAX_ELT_LEN);
241 }
243 return autoadjust_table_print(table, row + 1, 3);
244 }
246 int process_show_command(int argc, char *argv[])
247 {
248 int ret;
250 if (argc < 1) {
251 help(HELP_SHOW);
252 return -1;
253 }
255 if (!strncmp(argv[0], "host", 4)) {
256 ret = show_hosts_info();
257 if (ret)
258 help(HELP_SHOW_HOST);
259 } else if (!strncmp(argv[0], "thread", 6)) {
260 ret = show_sp_threads_info();
261 if (ret)
262 help(HELP_SHOW_SEC_PROXY);
263 } else if (!strncmp(argv[0], "device", 6)) {
264 argc--;
265 argv++;
266 ret = show_devices_info(argc, argv);
267 if (ret) {
268 fprintf(stderr, "Invalid device arguments\n");
269 help(HELP_SHOW_DEVICE);
270 }
271 } else if (!strncmp(argv[0], "clock", 5)) {
272 argc--;
273 argv++;
274 ret = show_clocks_info(argc, argv);
275 if (ret) {
276 fprintf(stderr, "Invalid clock arguments\n");
277 help(HELP_SHOW_CLOCK);
278 }
279 } else if(!strncmp(argv[0], "processor", 9)) {
280 ret = show_processors_info();
281 if (ret)
282 help(HELP_SHOW_PROCESSOR);
283 } else if (!strcmp(argv[0], "--help")) {
284 help(HELP_SHOW);
285 return 0;
286 } else {
287 fprintf(stderr, "Invalid argument %s\n", argv[1]);
288 help(HELP_SHOW);
289 return -1;
290 }
291 return ret;
292 }