google/cyan: Add Wifi regulatory method
[coreboot.git] / payloads / coreinfo / coreinfo.c
blob41b5f12cb1ceb956875af4c048fd8b6cef070db0
1 /*
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.
16 #include "coreinfo.h"
18 #define KEY_ESC 27
20 extern struct coreinfo_module cpuinfo_module;
21 extern struct coreinfo_module pci_module;
22 extern struct coreinfo_module coreboot_module;
23 extern struct coreinfo_module multiboot_module;
24 extern struct coreinfo_module nvram_module;
25 extern struct coreinfo_module bootlog_module;
26 extern struct coreinfo_module ramdump_module;
27 extern struct coreinfo_module lar_module;
28 extern struct coreinfo_module cbfs_module;
30 struct coreinfo_module *system_modules[] = {
31 #if IS_ENABLED(CONFIG_MODULE_CPUINFO)
32 &cpuinfo_module,
33 #endif
34 #if IS_ENABLED(CONFIG_MODULE_PCI)
35 &pci_module,
36 #endif
37 #if IS_ENABLED(CONFIG_MODULE_NVRAM)
38 &nvram_module,
39 #endif
40 #if IS_ENABLED(CONFIG_MODULE_RAMDUMP)
41 &ramdump_module,
42 #endif
45 struct coreinfo_module *firmware_modules[] = {
46 #if IS_ENABLED(CONFIG_MODULE_COREBOOT)
47 &coreboot_module,
48 #endif
49 #if IS_ENABLED(CONFIG_MODULE_MULTIBOOT)
50 &multiboot_module,
51 #endif
52 #if IS_ENABLED(CONFIG_MODULE_BOOTLOG)
53 &bootlog_module,
54 #endif
55 #if IS_ENABLED(CONFIG_MODULE_LAR)
56 &lar_module,
57 #endif
58 #if IS_ENABLED(CONFIG_MODULE_CBFS)
59 &cbfs_module,
60 #endif
63 struct coreinfo_cat {
64 char name[15];
65 int cur;
66 int count;
67 struct coreinfo_module **modules;
68 } categories[] = {
70 .name = "System",
71 .modules = system_modules,
72 .count = ARRAY_SIZE(system_modules),
75 .name = "Firmware",
76 .modules = firmware_modules,
77 .count = ARRAY_SIZE(firmware_modules),
81 static WINDOW *modwin, *menuwin;
82 static int curwin;
84 void print_module_title(WINDOW *win, const char *title)
86 int i;
88 wattrset(win, COLOR_PAIR(2));
89 mvwprintw(win, 0, 1, title);
91 wmove(win, 1, 1);
92 for (i = 0; i < 78; i++)
93 waddch(win, ACS_HLINE);
96 static void print_submenu(struct coreinfo_cat *cat)
98 int i, j;
99 char menu[80];
100 char *ptr = menu;
102 wmove(menuwin, 0, 0);
104 for (j = 0; j < SCREEN_X; j++)
105 waddch(menuwin, ' ');
107 if (!cat->count)
108 return;
110 for (i = 0; i < cat->count; i++)
111 ptr += sprintf(ptr, "[%c: %s] ", 'A' + i,
112 cat->modules[i]->name);
114 mvwprintw(menuwin, 0, 0, menu);
117 #if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
118 static void print_time_and_date(void)
120 struct tm tm;
122 while (nvram_updating())
123 mdelay(10);
125 rtc_read_clock(&tm);
127 mvwprintw(menuwin, 0, 57, "%02d/%02d/%04d - %02d:%02d:%02d",
128 tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour,
129 tm.tm_min, tm.tm_sec);
131 #endif
133 static void print_menu(void)
135 int i, j;
136 char menu[80];
137 char *ptr = menu;
139 wmove(menuwin, 1, 0);
140 for (j = 0; j < SCREEN_X; j++)
141 waddch(menuwin, ' ');
143 for (i = 0; i < ARRAY_SIZE(categories); i++) {
144 if (categories[i].count == 0)
145 continue;
147 ptr += sprintf(ptr, "F%d: %s ", i + 1, categories[i].name);
150 mvwprintw(menuwin, 1, 0, menu);
152 #if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
153 print_time_and_date();
154 #endif
157 static void center(int row, const char *str)
159 int j, len = strlen(str);
161 wmove(stdscr, row, 0);
162 for (j = 0; j < SCREEN_X; j++)
163 waddch(stdscr, ' ');
165 mvprintw(row, (SCREEN_X - len) / 2, str);
168 /* FIXME: Currently unused. */
169 #if 0
170 static void header(int row, const char *str)
172 char buf[SCREEN_X];
173 char *ptr = buf;
174 int i;
175 int len = strlen(str) + 4;
177 for (i = 0; i < (SCREEN_X - len) / 2; i++)
178 ptr += sprintf(ptr, "=");
180 ptr += sprintf(ptr, "[ %s ]", str);
182 for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
183 ptr += sprintf(ptr, "=");
185 mvprintw(row, 0, buf);
187 #endif
189 static void redraw_module(struct coreinfo_cat *cat)
191 if (cat->count == 0)
192 return;
194 wclear(modwin);
195 cat->modules[cat->cur]->redraw(modwin);
196 wrefresh(modwin);
199 static void handle_category_key(struct coreinfo_cat *cat, int key)
201 if (key >= 'a' && key <= 'z') {
202 int index = key - 'a';
203 if (index < cat->count) {
204 cat->cur = index;
205 redraw_module(cat);
206 return;
210 if (cat->count && cat->modules[cat->cur]->handle) {
211 if (cat->modules[cat->cur]->handle(key))
212 redraw_module(cat);
216 static void loop(void)
218 int key;
220 center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION);
221 refresh();
223 print_menu();
224 print_submenu(&categories[curwin]);
225 redraw_module(&categories[curwin]);
227 halfdelay(10);
229 while (1) {
230 #if IS_ENABLED(CONFIG_SHOW_DATE_TIME)
231 print_time_and_date();
232 wrefresh(menuwin);
233 #endif
235 key = getch();
237 if (key == ERR)
238 continue;
240 if (key >= KEY_F(1) && key <= KEY_F(9)) {
241 unsigned char ch = key - KEY_F(1);
243 if (ch <= ARRAY_SIZE(categories)) {
244 if (ch == ARRAY_SIZE(categories))
245 continue;
246 if (categories[ch].count == 0)
247 continue;
249 curwin = ch;
250 print_submenu(&categories[curwin]);
251 redraw_module(&categories[curwin]);
252 continue;
256 if (key == KEY_ESC)
257 return;
259 handle_category_key(&categories[curwin], key);
263 int main(void)
265 int i, j;
267 #if IS_ENABLED(CONFIG_LP_USB)
268 usb_initialize();
269 #endif
271 initscr();
273 start_color();
274 init_pair(1, COLOR_WHITE, COLOR_GREEN);
275 init_pair(2, COLOR_WHITE, COLOR_BLACK);
276 init_pair(3, COLOR_BLACK, COLOR_WHITE);
278 modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0);
279 menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0);
281 wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
282 wattrset(modwin, COLOR_PAIR(2));
283 wattrset(menuwin, COLOR_PAIR(1) | A_BOLD);
285 werase(modwin);
287 for (i = 0; i < ARRAY_SIZE(categories); i++) {
288 for (j = 0; j < categories[i].count; j++)
289 categories[i].modules[j]->init();
292 noecho(); /* don't let curses echo keyboard chars */
293 keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */
294 curs_set(0); /* Hide blinking cursor */
296 loop();
298 /* reboot */
299 outb(0x6, 0xcf9);
300 halt();
301 return 0;
304 PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME);
305 PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME);
306 PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC);