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 static void print_menu(void)
113 wmove(stdscr, 23, 0);
115 for (j = 0; j < SCREEN_X; j++)
118 for (i = 0; i < ARRAY_SIZE(categories); i++) {
119 if (categories[i].count == 0)
122 ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
125 mvprintw(23, 0, menu);
127 #ifdef CONFIG_SHOW_DATE_TIME
128 mvprintw(23, 59, "%02d/%02d/20%02d - %02d:%02d:%02d",
129 bcd2dec(nvram_read(NVRAM_RTC_MONTH)),
130 bcd2dec(nvram_read(NVRAM_RTC_DAY)),
131 bcd2dec(nvram_read(NVRAM_RTC_YEAR)),
132 bcd2dec(nvram_read(NVRAM_RTC_HOURS)),
133 bcd2dec(nvram_read(NVRAM_RTC_MINUTES)),
134 bcd2dec(nvram_read(NVRAM_RTC_SECONDS)));
138 static void center(int row, const char *str)
140 int len = strlen(str);
143 wmove(stdscr, row, 0);
145 for (j = 0; j < SCREEN_X; j++)
148 mvprintw(row, (SCREEN_X - len) / 2, str);
151 /* FIXME: Currently unused. */
153 static void header(int row, const char *str)
158 int len = strlen(str) + 4;
160 for (i = 0; i < (SCREEN_X - len) / 2; i++)
161 ptr += sprintf(ptr, "=");
163 ptr += sprintf(ptr, "[ %s ]", str);
167 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
168 ptr += sprintf(ptr, "=");
170 mvprintw(row, 0, buf);
174 static void redraw_module(struct coreinfo_cat *cat)
180 cat->modules[cat->cur]->redraw(modwin);
184 static void handle_category_key(struct coreinfo_cat *cat, int key)
186 if (key >= 'a' && key <= 'z') {
187 int index = key - 'a';
189 if (index < cat->count) {
197 if (cat->count && cat->modules[cat->cur]->handle) {
198 if (cat->modules[cat->cur]->handle(key))
203 static void loop(void)
207 center(0, "coreinfo v0.1");
210 print_submenu(&categories[curwin]);
211 redraw_module(&categories[curwin]);
219 if (key >= KEY_F(1) && key <= KEY_F(9)) {
220 unsigned char ch = key - KEY_F(1);
222 if (ch <= ARRAY_SIZE(categories)) {
223 if (ch == ARRAY_SIZE(categories))
225 if (categories[ch].count == 0)
229 print_submenu(&categories[curwin]);
230 redraw_module(&categories[curwin]);
236 handle_category_key(&categories[curwin], key);
244 curses_enable_serial(0);
245 curses_enable_vga(1);
249 init_pair(1, COLOR_WHITE, COLOR_GREEN);
250 init_pair(2, COLOR_BLACK, COLOR_WHITE);
251 init_pair(3, COLOR_WHITE, COLOR_WHITE);
253 modwin = newwin(22, 80, 1, 0);
255 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
256 wattrset(modwin, COLOR_PAIR(2));
258 for (i = 0; i < 23; i++) {
259 wmove(modwin, i - 1, 0);
261 for (j = 0; j < SCREEN_X; j++)
267 for (i = 0; i < ARRAY_SIZE(categories); i++) {
268 for(j = 0; j < categories[i].count; j++)
269 categories[i].modules[j]->init();