2 * This file is part of the coreinfo project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
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.
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
25 extern struct coreinfo_module cpuinfo_module;
26 extern struct coreinfo_module pci_module;
27 extern struct coreinfo_module coreboot_module;
28 extern struct coreinfo_module nvram_module;
29 extern struct coreinfo_module bootlog_module;
31 struct coreinfo_module *system_modules[] = {
32 #ifdef CONFIG_MODULE_CPUINFO
35 #ifdef CONFIG_MODULE_PCI
38 #ifdef CONFIG_MODULE_NVRAM
43 struct coreinfo_module *coreboot_modules[] = {
44 #ifdef CONFIG_MODULE_COREBOOT
47 #ifdef CONFIG_MODULE_BOOTLOG
56 struct coreinfo_module **modules;
60 .modules = system_modules,
61 .count = ARRAY_SIZE(system_modules),
65 .modules = coreboot_modules,
66 .count = ARRAY_SIZE(coreboot_modules),
71 static WINDOW *modwin;
74 void print_module_title(WINDOW *win, const char *title)
78 wattrset(win, COLOR_PAIR(2));
79 mvwprintw(win, 0, 1, title);
83 for (i = 0; i < 78; i++)
87 static void print_submenu(struct coreinfo_cat *cat)
95 for (j = 0; j < SCREEN_X; j++)
101 for (i = 0; i < cat->count; i++)
102 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, cat->modules[i]->name);
104 mvprintw(22, 0, menu);
107 #ifdef CONFIG_SHOW_DATE_TIME
108 static void print_time_and_date(void)
112 while(nvram_updating())
117 mvprintw(23, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
118 tm.tm_mon, tm.tm_mday, 1900+tm.tm_year, tm.tm_hour,
119 tm.tm_min, tm.tm_sec);
123 static void print_menu(void)
129 wmove(stdscr, 23, 0);
131 for (j = 0; j < SCREEN_X; j++)
134 for (i = 0; i < ARRAY_SIZE(categories); i++) {
135 if (categories[i].count == 0)
138 ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
141 mvprintw(23, 0, menu);
143 #ifdef CONFIG_SHOW_DATE_TIME
144 print_time_and_date();
148 static void center(int row, const char *str)
150 int len = strlen(str);
153 wmove(stdscr, row, 0);
155 for (j = 0; j < SCREEN_X; j++)
158 mvprintw(row, (SCREEN_X - len) / 2, str);
161 /* FIXME: Currently unused. */
163 static void header(int row, const char *str)
168 int len = strlen(str) + 4;
170 for (i = 0; i < (SCREEN_X - len) / 2; i++)
171 ptr += sprintf(ptr, "=");
173 ptr += sprintf(ptr, "[ %s ]", str);
177 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
178 ptr += sprintf(ptr, "=");
180 mvprintw(row, 0, buf);
184 static void redraw_module(struct coreinfo_cat *cat)
190 cat->modules[cat->cur]->redraw(modwin);
194 static void handle_category_key(struct coreinfo_cat *cat, int key)
196 if (key >= 'a' && key <= 'z') {
197 int index = key - 'a';
199 if (index < cat->count) {
207 if (cat->count && cat->modules[cat->cur]->handle) {
208 if (cat->modules[cat->cur]->handle(key))
213 static void loop(void)
217 center(0, "coreinfo v0.1");
220 print_submenu(&categories[curwin]);
221 redraw_module(&categories[curwin]);
226 #ifdef CONFIG_SHOW_DATE_TIME
227 print_time_and_date();
236 if (key >= KEY_F(1) && key <= KEY_F(9)) {
237 unsigned char ch = key - KEY_F(1);
239 if (ch <= ARRAY_SIZE(categories)) {
240 if (ch == ARRAY_SIZE(categories))
242 if (categories[ch].count == 0)
246 print_submenu(&categories[curwin]);
247 redraw_module(&categories[curwin]);
253 handle_category_key(&categories[curwin], key);
261 curses_enable_serial(0);
262 curses_enable_vga(1);
266 init_pair(1, COLOR_WHITE, COLOR_GREEN);
267 init_pair(2, COLOR_BLACK, COLOR_WHITE);
268 init_pair(3, COLOR_WHITE, COLOR_WHITE);
270 modwin = newwin(22, 80, 1, 0);
272 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
273 wattrset(modwin, COLOR_PAIR(2));
275 for (i = 0; i < 23; i++) {
276 wmove(modwin, i - 1, 0);
278 for (j = 0; j < SCREEN_X; j++)
284 for (i = 0; i < ARRAY_SIZE(categories); i++) {
285 for(j = 0; j < categories[i].count; j++)
286 categories[i].modules[j]->init();