blob: 13a08f24a2f1f45eb53afb2fa73013fa2d0c1e34 [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
22#define SCREEN_Y 24
23#define SCREEN_X 80
24
25extern struct coreinfo_module cpuinfo_module;
26extern struct coreinfo_module pci_module;
27extern struct coreinfo_module coreboot_module;
Uwe Hermannab5b3e02008-03-31 20:30:18 +000028extern struct coreinfo_module nvram_module;
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000029extern struct coreinfo_module bootlog_module;
Jordan Crouse7249f792008-03-20 00:11:05 +000030
Uwe Hermanna0c00932008-03-27 20:46:49 +000031struct coreinfo_module *modules[] = {
Uwe Hermannab5b3e02008-03-31 20:30:18 +000032#ifdef CONFIG_MODULE_CPUINFO
Jordan Crouse7249f792008-03-20 00:11:05 +000033 &cpuinfo_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000034#endif
35#ifdef CONFIG_MODULE_PCI
Jordan Crouse7249f792008-03-20 00:11:05 +000036 &pci_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000037#endif
38#ifdef CONFIG_MODULE_COREBOOT
Uwe Hermanna0c00932008-03-27 20:46:49 +000039 &coreboot_module,
Uwe Hermannab5b3e02008-03-31 20:30:18 +000040#endif
41#ifdef CONFIG_MODULE_NVRAM
42 &nvram_module,
43#endif
Uwe Hermann0ab8cdd2008-04-22 20:19:53 +000044#ifdef CONFIG_MODULE_BOOTLOG
45 &bootlog_module,
46#endif
Jordan Crouse7249f792008-03-20 00:11:05 +000047};
48
49static WINDOW *modwin;
50static int curwin;
51
52void print_module_title(WINDOW *win, const char *title)
53{
54 int i;
55
56 wattrset(win, COLOR_PAIR(2));
57 mvwprintw(win, 0, 1, title);
58
59 wmove(win, 1, 1);
60
Uwe Hermann3a406fe2008-03-20 01:11:28 +000061 for (i = 0; i < 78; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +000062 waddch(win, '\304');
63}
64
Uwe Hermann0bfb5c42008-03-23 15:34:04 +000065static void print_menu(void)
Uwe Hermann3a406fe2008-03-20 01:11:28 +000066{
Uwe Hermann35845a22008-03-20 20:05:22 +000067 int i, j;
Jordan Crouse7249f792008-03-20 00:11:05 +000068 char menu[80];
69 char *ptr = menu;
Jordan Crouse7249f792008-03-20 00:11:05 +000070
71 wmove(stdscr, 23, 0);
72
Uwe Hermann3a406fe2008-03-20 01:11:28 +000073 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +000074 waddch(stdscr, ' ');
75
Uwe Hermanna0c00932008-03-27 20:46:49 +000076 for (i = 0; i < ARRAY_SIZE(modules); i++)
Jordan Crouse7249f792008-03-20 00:11:05 +000077 ptr += sprintf(ptr, "F%d: %s ", i + 1, modules[i]->name);
78
Uwe Hermann6c44dfb2008-04-04 16:49:09 +000079 if (ARRAY_SIZE(modules) != 0)
80 mvprintw(23, 0, menu);
Uwe Hermannab5b3e02008-03-31 20:30:18 +000081
82#ifdef CONFIG_SHOW_DATE_TIME
83 mvprintw(23, 59, "%02d/%02d/20%02d - %02d:%02d:%02d",
84 bcd2dec(nvram_read(NVRAM_RTC_MONTH)),
85 bcd2dec(nvram_read(NVRAM_RTC_DAY)),
86 bcd2dec(nvram_read(NVRAM_RTC_YEAR)),
87 bcd2dec(nvram_read(NVRAM_RTC_HOURS)),
88 bcd2dec(nvram_read(NVRAM_RTC_MINUTES)),
89 bcd2dec(nvram_read(NVRAM_RTC_SECONDS)));
90#endif
Jordan Crouse7249f792008-03-20 00:11:05 +000091}
92
Uwe Hermann0bfb5c42008-03-23 15:34:04 +000093static void center(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +000094{
95 int len = strlen(str);
96 int j;
97
98 wmove(stdscr, row, 0);
99
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000100 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000101 waddch(stdscr, ' ');
102
103 mvprintw(row, (SCREEN_X - len) / 2, str);
104}
105
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000106/* FIXME: Currently unused. */
107#if 0
108static void header(int row, const char *str)
Jordan Crouse7249f792008-03-20 00:11:05 +0000109{
110 char buf[SCREEN_X];
111 char *ptr = buf;
112 int i;
113 int len = strlen(str) + 4;
114
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000115 for (i = 0; i < (SCREEN_X - len) / 2; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000116 ptr += sprintf(ptr, "=");
117
118 ptr += sprintf(ptr, "[ %s ]", str);
119
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000120 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000121 ptr += sprintf(ptr, "=");
122
123 mvprintw(row, 0, buf);
124}
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000125#endif
Jordan Crouse7249f792008-03-20 00:11:05 +0000126
127static void redraw_module(void)
128{
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000129 if (ARRAY_SIZE(modules) == 0)
130 return;
131
Jordan Crouse7249f792008-03-20 00:11:05 +0000132 wclear(modwin);
133 modules[curwin]->redraw(modwin);
134 refresh();
135}
136
Uwe Hermann0bfb5c42008-03-23 15:34:04 +0000137static void loop(void)
Jordan Crouse7249f792008-03-20 00:11:05 +0000138{
139 int key;
140
141 center(0, "coreinfo v0.1");
142
143 print_menu();
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000144 if (ARRAY_SIZE(modules) != 0)
145 modules[curwin]->redraw(modwin);
Jordan Crouse7249f792008-03-20 00:11:05 +0000146 refresh();
147
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000148 while (1) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000149 key = getch();
150
151 if (key == ERR)
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000152 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000153
154 if (key >= KEY_F(1) && key <= KEY_F(9)) {
155 unsigned char ch = key - KEY_F(1);
156
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000157 if (ch <= ARRAY_SIZE(modules)) {
158 if (ch == ARRAY_SIZE(modules))
159 continue;
Jordan Crouse7249f792008-03-20 00:11:05 +0000160 curwin = ch;
161 redraw_module();
162 continue;
163 }
164 }
165
Uwe Hermann6c44dfb2008-04-04 16:49:09 +0000166 if (ARRAY_SIZE(modules) != 0 && modules[curwin]->handle)
Jordan Crouse7249f792008-03-20 00:11:05 +0000167 if (modules[curwin]->handle(key))
168 redraw_module();
169 }
170}
171
172int main(void)
173{
174 int i, j;
175
176 curses_enable_serial(0);
177 curses_enable_vga(1);
178
179 initscr();
180
181 init_pair(1, COLOR_WHITE, COLOR_GREEN);
182 init_pair(2, COLOR_BLACK, COLOR_WHITE);
183 init_pair(3, COLOR_WHITE, COLOR_WHITE);
184
185 modwin = newwin(23, 80, 1, 0);
186
187 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
188 wattrset(modwin, COLOR_PAIR(2));
189
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000190 for (i = 0; i < 23; i++) {
Jordan Crouse7249f792008-03-20 00:11:05 +0000191 wmove(modwin, i - 1, 0);
192
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000193 for (j = 0; j < SCREEN_X; j++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000194 waddch(modwin, ' ');
195 }
196
197 refresh();
198
Uwe Hermanna0c00932008-03-27 20:46:49 +0000199 for (i = 0; i < ARRAY_SIZE(modules); i++)
Jordan Crouse7249f792008-03-20 00:11:05 +0000200 modules[i]->init();
Uwe Hermann3a406fe2008-03-20 01:11:28 +0000201
Jordan Crouse7249f792008-03-20 00:11:05 +0000202 loop();
Uwe Hermann35845a22008-03-20 20:05:22 +0000203
204 return 0;
Jordan Crouse7249f792008-03-20 00:11:05 +0000205}