blob: 35e5016ae625ae3050739737ed1173158c377fc0 [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001/*
Jordan Crouse7249f792008-03-20 00:11:05 +00002 *
3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Jordan Crouse7249f792008-03-20 00:11:05 +000013 */
14
15#include "coreinfo.h"
16
Uwe Hermann29413c72008-05-21 13:49:03 +000017#define KEY_ESC 27
18
Jordan Crouse7249f792008-03-20 00:11:05 +000019extern struct coreinfo_module cpuinfo_module;
20extern struct coreinfo_module pci_module;
21extern struct coreinfo_module coreboot_module;
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000022extern struct coreinfo_module multiboot_module;
Uwe Hermannab5b3e02008-03-31 20:30:18 +000023extern struct coreinfo_module nvram_module;
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000024extern struct coreinfo_module bootlog_module;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000025extern struct coreinfo_module ramdump_module;
Uwe Hermann941c1fd2009-07-07 15:10:13 +000026extern struct coreinfo_module cbfs_module;
Antonello Dettori4b1668f2016-07-08 11:14:40 +020027extern struct coreinfo_module timestamps_module;
Jordan Crouse7249f792008-03-20 00:11:05 +000028
Jordan Crousede7fc552008-05-06 22:03:16 +000029struct coreinfo_module *system_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080030#if CONFIG(MODULE_CPUINFO)
Jordan Crouse7249f792008-03-20 00:11:05 +000031 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000032#endif
Julius Wernereab2a292019-03-05 16:55:15 -080033#if CONFIG(MODULE_PCI)
Jordan Crouse7249f792008-03-20 00:11:05 +000034 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000035#endif
Julius Wernereab2a292019-03-05 16:55:15 -080036#if CONFIG(MODULE_NVRAM)
Jordan Crouse7ce26662008-05-06 22:00:55 +000037 &nvram_module,
38#endif
Julius Wernereab2a292019-03-05 16:55:15 -080039#if CONFIG(MODULE_RAMDUMP)
Uwe Hermann2fbbb292008-07-08 16:18:38 +000040 &ramdump_module,
41#endif
Jordan Crousede7fc552008-05-06 22:03:16 +000042};
43
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000044struct coreinfo_module *firmware_modules[] = {
Julius Wernereab2a292019-03-05 16:55:15 -080045#if CONFIG(MODULE_COREBOOT)
Jordan Crousede7fc552008-05-06 22:03:16 +000046 &coreboot_module,
47#endif
Julius Wernereab2a292019-03-05 16:55:15 -080048#if CONFIG(MODULE_MULTIBOOT)
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000049 &multiboot_module,
50#endif
Julius Wernereab2a292019-03-05 16:55:15 -080051#if CONFIG(MODULE_BOOTLOG)
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000052 &bootlog_module,
53#endif
Julius Wernereab2a292019-03-05 16:55:15 -080054#if CONFIG(MODULE_CBFS)
Uwe Hermann941c1fd2009-07-07 15:10:13 +000055 &cbfs_module,
Jordan Crouseaa6e3782008-05-07 20:43:15 +000056#endif
Julius Wernereab2a292019-03-05 16:55:15 -080057#if CONFIG(MODULE_TIMESTAMPS)
Antonello Dettori4b1668f2016-07-08 11:14:40 +020058 &timestamps_module,
59#endif
Jordan Crouse7249f792008-03-20 00:11:05 +000060};
61
Jordan Crousede7fc552008-05-06 22:03:16 +000062struct coreinfo_cat {
63 char name[15];
64 int cur;
65 int count;
66 struct coreinfo_module **modules;
67} categories[] = {
68 {
69 .name = "System",
70 .modules = system_modules,
71 .count = ARRAY_SIZE(system_modules),
72 },
73 {
Jordan Crouse5cb4d9d2008-11-11 19:53:42 +000074 .name = "Firmware",
75 .modules = firmware_modules,
76 .count = ARRAY_SIZE(firmware_modules),
Jordan Crousede7fc552008-05-06 22:03:16 +000077 }
78};
79
Uwe Hermann695cff32008-08-07 14:35:39 +000080static WINDOW *modwin, *menuwin;
Jordan Crouse7249f792008-03-20 00:11:05 +000081static int curwin;
82
83void print_module_title(WINDOW *win, const char *title)
84{
85 int i;
86
87 wattrset(win, COLOR_PAIR(2));
88 mvwprintw(win, 0, 1, title);
89
90 wmove(win, 1, 1);
Uwe Hermann3a406fe2008-03-20 01:11:28 +000091 for (i = 0; i < 78; i++)
Ulf Jordand133d9a2008-08-11 20:35:32 +000092 waddch(win, ACS_HLINE);
Jordan Crouse7249f792008-03-20 00:11:05 +000093}
94
Jordan Crousede7fc552008-05-06 22:03:16 +000095static void print_submenu(struct coreinfo_cat *cat)
96{
97 int i, j;
98 char menu[80];
99 char *ptr = menu;
100
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000101 wmove(menuwin, 0, 0);
Jordan Crousede7fc552008-05-06 22:03:16 +0000102
103 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000104 waddch(menuwin, ' ');
Jordan Crousede7fc552008-05-06 22:03:16 +0000105
106 if (!cat->count)
107 return;
108
109 for (i = 0; i < cat->count; i++)
Uwe Hermann695cff32008-08-07 14:35:39 +0000110 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i,
111 cat->modules[i]->name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000112
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000113 mvwprintw(menuwin, 0, 0, menu);
Jordan Crousede7fc552008-05-06 22:03:16 +0000114}
115
Julius Wernereab2a292019-03-05 16:55:15 -0800116#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000117static void print_time_and_date(void)
118{
119 struct tm tm;
120
Uwe Hermann941aaee2008-07-18 14:08:18 +0000121 while (nvram_updating())
Jordan Crouse19337862008-05-06 22:15:31 +0000122 mdelay(10);
123
124 rtc_read_clock(&tm);
125
Jonathan Neuschäfer2bf7a2c2016-04-04 19:44:30 +0200126 mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
Yasha Cherikovskyae16c402015-11-14 19:16:58 +0200127 tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour,
Uwe Hermann941aaee2008-07-18 14:08:18 +0000128 tm.tm_min, tm.tm_sec);
Jordan Crouse19337862008-05-06 22:15:31 +0000129}
130#endif
131
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000132static void print_menu(void)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000133{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600134 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000135 char menu[80];
136 char *ptr = menu;
Jordan Crouse7249f792008-03-20 00:11:05 +0000137
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000138 wmove(menuwin, 1, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000139 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000140 waddch(menuwin, ' ');
Jordan Crouse7249f792008-03-20 00:11:05 +0000141
Jacob Garbera711e9c2019-06-28 10:58:56 -0600142 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Jordan Crousede7fc552008-05-06 22:03:16 +0000143 if (categories[i].count == 0)
144 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000145
Jacob Garbera711e9c2019-06-28 10:58:56 -0600146 ptr += sprintf(ptr, "F%zu: %s ", i + 1, categories[i].name);
Jordan Crousede7fc552008-05-06 22:03:16 +0000147 }
148
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000149 mvwprintw(menuwin, 1, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000150
Julius Wernereab2a292019-03-05 16:55:15 -0800151#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000152 print_time_and_date();
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000153#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000154}
155
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000156static void center(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000157{
Uwe Hermann695cff32008-08-07 14:35:39 +0000158 int j, len = strlen(str);
Jordan Crouse7249f792008-03-20 00:11:05 +0000159
160 wmove(stdscr, row, 0);
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000161 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000162 waddch(stdscr, ' ');
163
164 mvprintw(row, (SCREEN_X - len) / 2, str);
165}
166
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000167/* FIXME: Currently unused. */
168#if 0
169static void header(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000170{
171 char buf[SCREEN_X];
172 char *ptr = buf;
173 int i;
174 int len = strlen(str) + 4;
175
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000176 for (i = 0; i < (SCREEN_X - len) / 2; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000177 ptr += sprintf(ptr, "=");
178
179 ptr += sprintf(ptr, "[ %s ]", str);
180
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000181 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000182 ptr += sprintf(ptr, "=");
183
184 mvprintw(row, 0, buf);
185}
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000186#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000187
Jordan Crousede7fc552008-05-06 22:03:16 +0000188static void redraw_module(struct coreinfo_cat *cat)
Jordan Crouse7249f792008-03-20 00:11:05 +0000189{
Jordan Crousede7fc552008-05-06 22:03:16 +0000190 if (cat->count == 0)
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000191 return;
192
Jordan Crouse7249f792008-03-20 00:11:05 +0000193 wclear(modwin);
Jordan Crousede7fc552008-05-06 22:03:16 +0000194 cat->modules[cat->cur]->redraw(modwin);
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000195 wrefresh(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000196}
197
Jordan Crousede7fc552008-05-06 22:03:16 +0000198static void handle_category_key(struct coreinfo_cat *cat, int key)
199{
Himanshu Sahdevd3d38c92019-09-23 15:08:18 +0530200 if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) {
201 int index;
202 if (key >= 'A' && key <= 'Z') {
203 index = key - 'A';
204 } else {
205 index = key - 'a';
206 }
Jordan Crousede7fc552008-05-06 22:03:16 +0000207 if (index < cat->count) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000208 cat->cur = index;
Jordan Crousede7fc552008-05-06 22:03:16 +0000209 redraw_module(cat);
210 return;
211 }
212 }
213
214 if (cat->count && cat->modules[cat->cur]->handle) {
215 if (cat->modules[cat->cur]->handle(key))
216 redraw_module(cat);
217 }
218}
219
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100220static void print_no_modules_selected(void)
221{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600222 int height = getmaxy(stdscr);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100223
Jacob Garbera711e9c2019-06-28 10:58:56 -0600224 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100225 if (categories[i].count > 0)
226 return;
227
228 color_set(2, NULL); // White on black
229 center(height / 2, "No modules selected");
230}
231
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100232static int first_nonempty_category(void)
233{
Jacob Garbera711e9c2019-06-28 10:58:56 -0600234 for (size_t i = 0; i < ARRAY_SIZE(categories); i++)
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100235 if (categories[i].count > 0)
236 return i;
237 return 0;
238}
239
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000240static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000241{
242 int key;
243
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000244 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
Jonathan Neuschäfer8a61a2f2016-03-10 04:56:31 +0100245 print_no_modules_selected();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000246 refresh();
Jordan Crouse7249f792008-03-20 00:11:05 +0000247
Jonathan Neuschäferff099522016-03-10 06:33:00 +0100248 curwin = first_nonempty_category();
Jordan Crouse7249f792008-03-20 00:11:05 +0000249 print_menu();
Jordan Crousede7fc552008-05-06 22:03:16 +0000250 print_submenu(&categories[curwin]);
251 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000252
Jordan Crouse19337862008-05-06 22:15:31 +0000253 halfdelay(10);
254
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000255 while (1) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800256 int ch = -1;
257
Julius Wernereab2a292019-03-05 16:55:15 -0800258#if CONFIG(SHOW_DATE_TIME)
Jordan Crouse19337862008-05-06 22:15:31 +0000259 print_time_and_date();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000260 wrefresh(menuwin);
Jordan Crouse19337862008-05-06 22:15:31 +0000261#endif
262
Jordan Crouse7249f792008-03-20 00:11:05 +0000263 key = getch();
264
265 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000266 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000267
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800268 if (key >= KEY_F(1) && key <= KEY_F(9))
269 ch = key - KEY_F(1);
270 if (key >= '1' && key <= '9')
271 ch = key - '1';
Jordan Crouse7249f792008-03-20 00:11:05 +0000272
Jacob Garbera711e9c2019-06-28 10:58:56 -0600273 if (ch >= 0 && (unsigned int)ch <= ARRAY_SIZE(categories)) {
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800274 if (ch == ARRAY_SIZE(categories))
Jordan Crouse7249f792008-03-20 00:11:05 +0000275 continue;
Stefan Reinauerc2b50ac2016-03-11 23:17:28 -0800276 if (categories[ch].count == 0)
277 continue;
278
279 curwin = ch;
280 print_submenu(&categories[curwin]);
281 redraw_module(&categories[curwin]);
282 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000283 }
284
Uwe Hermann29413c72008-05-21 13:49:03 +0000285 if (key == KEY_ESC)
Jordan Crouse98cc0562008-05-20 20:16:34 +0000286 return;
Jordan Crousede7fc552008-05-06 22:03:16 +0000287
288 handle_category_key(&categories[curwin], key);
Jordan Crouse7249f792008-03-20 00:11:05 +0000289 }
290}
291
Jacob Garberbd624722019-10-02 14:44:28 -0600292int main(int argc, char **argv)
Jordan Crouse7249f792008-03-20 00:11:05 +0000293{
Jacob Garberbd624722019-10-02 14:44:28 -0600294 (void)argc;
295 (void)argv;
296
Jacob Garbera711e9c2019-06-28 10:58:56 -0600297 int j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000298
Julius Wernereab2a292019-03-05 16:55:15 -0800299 if (CONFIG(LP_USB))
Nicola Corna71693ba2017-03-14 10:26:58 +0100300 usb_initialize();
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700301
Jordan Crouse7249f792008-03-20 00:11:05 +0000302 initscr();
303
Dave Frodin1b0c3522012-12-05 17:26:03 -0700304 start_color();
Jordan Crouse7249f792008-03-20 00:11:05 +0000305 init_pair(1, COLOR_WHITE, COLOR_GREEN);
Dave Frodin1b0c3522012-12-05 17:26:03 -0700306 init_pair(2, COLOR_WHITE, COLOR_BLACK);
307 init_pair(3, COLOR_BLACK, COLOR_WHITE);
Jordan Crouse7249f792008-03-20 00:11:05 +0000308
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000309 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
310 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000311
312 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
313 wattrset(modwin, COLOR_PAIR(2));
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000314 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
Jordan Crouse7249f792008-03-20 00:11:05 +0000315
Ulf Jordan22d5ddc2008-09-24 14:21:02 +0000316 werase(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000317
Jacob Garbera711e9c2019-06-28 10:58:56 -0600318 for (size_t i = 0; i < ARRAY_SIZE(categories); i++) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000319 for (j = 0; j < categories[i].count; j++)
Jordan Crousede7fc552008-05-06 22:03:16 +0000320 categories[i].modules[j]->init();
Jordan Crousede7fc552008-05-06 22:03:16 +0000321 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000322
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700323 noecho(); /* don't let curses echo keyboard chars */
324 keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */
Yasha Cherikovsky619fc952015-11-14 19:16:58 +0200325 curs_set(0); /* Hide blinking cursor */
Dave Frodin15a2c8f2012-12-05 17:22:47 -0700326
Jordan Crouse7249f792008-03-20 00:11:05 +0000327 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000328
Maxime de Roucy81900782015-09-27 15:53:40 +0200329 /* reboot */
330 outb(0x6, 0xcf9);
331 halt();
Uwe Hermann35845a22008-03-20 20:05:22 +0000332 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000333}
Jordan Crouse50838112008-05-27 20:07:47 +0000334
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000335PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
336PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
337PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);