blob: d158b29f8e99709128f2abff506bbd2f2f531b38 [file] [log] [blame]
Jordan Crouse7249f792008-03-20 00:11:05 +00001/*
2 * This file is part of the coreinfo project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "coreinfo.h"
21
Jordan Crouse9b1c7c12008-05-20 20:16:03 +000022#define SCREEN_Y 25
Jordan Crouse7249f792008-03-20 00:11:05 +000023#define SCREEN_X 80
24
Uwe Hermann29413c72008-05-21 13:49:03 +000025#define KEY_ESC 27
26
Jordan Crouse7249f792008-03-20 00:11:05 +000027extern struct coreinfo_module cpuinfo_module;
28extern struct coreinfo_module pci_module;
29extern struct coreinfo_module coreboot_module;
Uwe Hermannab5b3e02008-03-31 20:30:18 +000030extern struct coreinfo_module nvram_module;
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000031extern struct coreinfo_module bootlog_module;
Uwe Hermann2fbbb292008-07-08 16:18:38 +000032extern struct coreinfo_module ramdump_module;
Jordan Crouseaa6e3782008-05-07 20:43:15 +000033extern struct coreinfo_module lar_module;
Jordan Crouse7249f792008-03-20 00:11:05 +000034
Jordan Crousede7fc552008-05-06 22:03:16 +000035struct coreinfo_module *system_modules[] = {
Uwe Hermannab5b3e02008-03-31 20:30:18 +000036#ifdef CONFIG_MODULE_CPUINFO
Jordan Crouse7249f792008-03-20 00:11:05 +000037 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000038#endif
39#ifdef CONFIG_MODULE_PCI
Jordan Crouse7249f792008-03-20 00:11:05 +000040 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000041#endif
Jordan Crouse7ce26662008-05-06 22:00:55 +000042#ifdef CONFIG_MODULE_NVRAM
43 &nvram_module,
44#endif
Uwe Hermann2fbbb292008-07-08 16:18:38 +000045#ifdef CONFIG_MODULE_RAMDUMP
46 &ramdump_module,
47#endif
Jordan Crousede7fc552008-05-06 22:03:16 +000048};
49
50struct coreinfo_module *coreboot_modules[] = {
51#ifdef CONFIG_MODULE_COREBOOT
52 &coreboot_module,
53#endif
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000054#ifdef CONFIG_MODULE_BOOTLOG
55 &bootlog_module,
56#endif
Jordan Crouseaa6e3782008-05-07 20:43:15 +000057#ifdef CONFIG_MODULE_LAR
58 &lar_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 {
74 .name = "Coreboot",
75 .modules = coreboot_modules,
76 .count = ARRAY_SIZE(coreboot_modules),
77 }
78};
79
Jordan Crouse7249f792008-03-20 00:11:05 +000080static WINDOW *modwin;
Jordan Crouse9b1c7c12008-05-20 20:16:03 +000081static WINDOW *menuwin;
82
Jordan Crouse7249f792008-03-20 00:11:05 +000083static int curwin;
84
85void print_module_title(WINDOW *win, const char *title)
86{
87 int i;
88
89 wattrset(win, COLOR_PAIR(2));
90 mvwprintw(win, 0, 1, title);
91
92 wmove(win, 1, 1);
93
Uwe Hermann3a406fe2008-03-20 01:11:28 +000094 for (i = 0; i < 78; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +000095 waddch(win, '\304');
96}
97
Jordan Crousede7fc552008-05-06 22:03:16 +000098static void print_submenu(struct coreinfo_cat *cat)
99{
100 int i, j;
101 char menu[80];
102 char *ptr = menu;
103
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000104 wmove(menuwin, 0, 0);
Jordan Crousede7fc552008-05-06 22:03:16 +0000105
106 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000107 waddch(menuwin, ' ');
Jordan Crousede7fc552008-05-06 22:03:16 +0000108
109 if (!cat->count)
110 return;
111
112 for (i = 0; i < cat->count; i++)
113 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, cat->modules[i]->name);
114
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000115 mvwprintw(menuwin, 0, 0, menu);
Jordan Crousede7fc552008-05-06 22:03:16 +0000116}
117
Jordan Crouse19337862008-05-06 22:15:31 +0000118#ifdef CONFIG_SHOW_DATE_TIME
119static void print_time_and_date(void)
120{
121 struct tm tm;
122
Uwe Hermann941aaee2008-07-18 14:08:18 +0000123 while (nvram_updating())
Jordan Crouse19337862008-05-06 22:15:31 +0000124 mdelay(10);
125
126 rtc_read_clock(&tm);
127
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000128 mvwprintw(menuwin, 0, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
Uwe Hermann941aaee2008-07-18 14:08:18 +0000129 tm.tm_mon, tm.tm_mday, 1900+tm.tm_year, tm.tm_hour,
130 tm.tm_min, tm.tm_sec);
Jordan Crouse19337862008-05-06 22:15:31 +0000131}
132#endif
133
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000134static void print_menu(void)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000135{
Uwe Hermann35845a22008-03-20 20:05:22 +0000136 int i, j;
Jordan Crouse7249f792008-03-20 00:11:05 +0000137 char menu[80];
138 char *ptr = menu;
Jordan Crouse7249f792008-03-20 00:11:05 +0000139
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000140 wmove(menuwin, 1, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000141
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000142 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000143 waddch(menuwin, ' ');
Jordan Crouse7249f792008-03-20 00:11:05 +0000144
Jordan Crousede7fc552008-05-06 22:03:16 +0000145 for (i = 0; i < ARRAY_SIZE(categories); i++) {
146 if (categories[i].count == 0)
147 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000148
Jordan Crousede7fc552008-05-06 22:03:16 +0000149 ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
150 }
151
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000152 mvwprintw(menuwin, 1, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000153
154#ifdef CONFIG_SHOW_DATE_TIME
Jordan Crouse19337862008-05-06 22:15:31 +0000155 print_time_and_date();
Uwe Hermannab5b3e02008-03-31 20:30:18 +0000156#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000157}
158
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000159static void center(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000160{
161 int len = strlen(str);
162 int j;
163
164 wmove(stdscr, row, 0);
165
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000166 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000167 waddch(stdscr, ' ');
168
169 mvprintw(row, (SCREEN_X - len) / 2, str);
170}
171
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000172/* FIXME: Currently unused. */
173#if 0
174static void header(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000175{
176 char buf[SCREEN_X];
177 char *ptr = buf;
178 int i;
179 int len = strlen(str) + 4;
180
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000181 for (i = 0; i < (SCREEN_X - len) / 2; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000182 ptr += sprintf(ptr, "=");
183
184 ptr += sprintf(ptr, "[ %s ]", str);
185
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000186 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000187 ptr += sprintf(ptr, "=");
188
189 mvprintw(row, 0, buf);
190}
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000191#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000192
Jordan Crousede7fc552008-05-06 22:03:16 +0000193static void redraw_module(struct coreinfo_cat *cat)
Jordan Crouse7249f792008-03-20 00:11:05 +0000194{
Jordan Crousede7fc552008-05-06 22:03:16 +0000195 if (cat->count == 0)
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000196 return;
197
Jordan Crouse7249f792008-03-20 00:11:05 +0000198 wclear(modwin);
Jordan Crousede7fc552008-05-06 22:03:16 +0000199 cat->modules[cat->cur]->redraw(modwin);
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000200 wrefresh(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000201}
202
Jordan Crousede7fc552008-05-06 22:03:16 +0000203static void handle_category_key(struct coreinfo_cat *cat, int key)
204{
205 if (key >= 'a' && key <= 'z') {
206 int index = key - 'a';
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
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000220static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000221{
222 int key;
223
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000224 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000225 refresh();
Jordan Crouse7249f792008-03-20 00:11:05 +0000226
227 print_menu();
Jordan Crousede7fc552008-05-06 22:03:16 +0000228 print_submenu(&categories[curwin]);
229 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000230
Jordan Crouse19337862008-05-06 22:15:31 +0000231 halfdelay(10);
232
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000233 while (1) {
Jordan Crouse19337862008-05-06 22:15:31 +0000234#ifdef CONFIG_SHOW_DATE_TIME
235 print_time_and_date();
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000236 wrefresh(menuwin);
Jordan Crouse19337862008-05-06 22:15:31 +0000237#endif
238
Jordan Crouse7249f792008-03-20 00:11:05 +0000239 key = getch();
240
241 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000242 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000243
244 if (key >= KEY_F(1) && key <= KEY_F(9)) {
245 unsigned char ch = key - KEY_F(1);
246
Jordan Crousede7fc552008-05-06 22:03:16 +0000247 if (ch <= ARRAY_SIZE(categories)) {
248 if (ch == ARRAY_SIZE(categories))
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000249 continue;
Jordan Crousede7fc552008-05-06 22:03:16 +0000250 if (categories[ch].count == 0)
251 continue;
252
Jordan Crouse7249f792008-03-20 00:11:05 +0000253 curwin = ch;
Jordan Crousede7fc552008-05-06 22:03:16 +0000254 print_submenu(&categories[curwin]);
255 redraw_module(&categories[curwin]);
Jordan Crouse7249f792008-03-20 00:11:05 +0000256 continue;
257 }
258 }
259
Uwe Hermann29413c72008-05-21 13:49:03 +0000260 if (key == KEY_ESC)
Jordan Crouse98cc0562008-05-20 20:16:34 +0000261 return;
Jordan Crousede7fc552008-05-06 22:03:16 +0000262
263 handle_category_key(&categories[curwin], key);
Jordan Crouse7249f792008-03-20 00:11:05 +0000264 }
265}
266
267int main(void)
268{
269 int i, j;
270
Jordan Crouse7249f792008-03-20 00:11:05 +0000271 initscr();
272
273 init_pair(1, COLOR_WHITE, COLOR_GREEN);
274 init_pair(2, COLOR_BLACK, COLOR_WHITE);
275 init_pair(3, COLOR_WHITE, COLOR_WHITE);
276
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000277 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
278 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
Jordan Crouse7249f792008-03-20 00:11:05 +0000279
280 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
281 wattrset(modwin, COLOR_PAIR(2));
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000282 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
Jordan Crouse7249f792008-03-20 00:11:05 +0000283
Jordan Crouseaa6e3782008-05-07 20:43:15 +0000284 for (i = 0; i < SCREEN_Y - 1; i++) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000285 wmove(modwin, i - 1, 0);
286
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000287 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000288 waddch(modwin, ' ');
289 }
290
Jordan Crouse9b1c7c12008-05-20 20:16:03 +0000291 wrefresh(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000292
Jordan Crousede7fc552008-05-06 22:03:16 +0000293 for (i = 0; i < ARRAY_SIZE(categories); i++) {
Uwe Hermann941aaee2008-07-18 14:08:18 +0000294 for (j = 0; j < categories[i].count; j++)
Jordan Crousede7fc552008-05-06 22:03:16 +0000295 categories[i].modules[j]->init();
296
297 }
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000298
Jordan Crouse7249f792008-03-20 00:11:05 +0000299 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000300
301 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000302}
Jordan Crouse50838112008-05-27 20:07:47 +0000303
Uwe Hermanna70872cf2008-08-05 14:36:20 +0000304PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
305PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
306PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);