Cosmetic changes and coding style fixes by running 'indent', with some

manual fixups afterwards (trivial).

No functionality changes, compile-tested.

Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>



git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3174 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Uwe Hermann 2008-03-20 01:11:28 +00:00
parent 7249f79792
commit 3a406feb17
6 changed files with 142 additions and 172 deletions

View File

@ -17,14 +17,14 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
CC=gcc
CC = gcc
CROSS_CFLAGS = -m32
INCLUDES = -I../libpayload/include
INCLUDES += -I$(shell $(CC) $(CROSS_CFLAGS) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
LIBPAYLOAD=../libpayload/libpayload.a
LIBGCC:=$(shell $(CC) $(CROSS_CFLAGS) -print-libgcc-file-name)
LIBPAYLOAD = ../libpayload/libpayload.a
LIBGCC := $(shell $(CC) $(CROSS_CFLAGS) -print-libgcc-file-name)
CFLAGS := -Werror -fno-stack-protector -nostdinc $(INCLUDES)
MODULES = cpuinfo_module.o cpuid.o pci_module.o coreboot_module.o
@ -34,12 +34,12 @@ TARGET = coreinfo.elf
all: $(TARGET)
clean:
@ rm -f $(TARGET) $(MODULES) $(OBJECTS)
@rm -f $(TARGET) $(MODULES) $(OBJECTS)
$(TARGET): $(OBJECTS) $(MODULES)
#ld --verbose -T ../libpayload/libpayload.ldscript -o $@ $(OBJECTS) --whole-archive $(LIBPAYLOAD) --no-whole-archive $(LIBGCC)
@#ld --verbose -T ../libpayload/libpayload.ldscript -o $@ $(OBJECTS) --whole-archive $(LIBPAYLOAD) --no-whole-archive $(LIBGCC)
ld -T ../libpayload/libpayload.ldscript -o $@ $(OBJECTS) $(MODULES) ../libpayload/i386/head.o $(LIBPAYLOAD) $(LIBGCC)
@ strip $@
@strip $@
.S.o:
$(AS) --32 -o $@ $<

View File

@ -72,7 +72,7 @@ int coreboot_module_redraw(WINDOW *win)
if (cb_info.console.tag != 0x0) {
mvwprintw(win, row++, 2, "Default Output Console: ");
switch(cb_info.console.type) {
switch (cb_info.console.type) {
case CB_TAG_CONSOLE_SERIAL8250:
wprintw(win, "Serial Port");
break;
@ -97,17 +97,14 @@ int coreboot_module_redraw(WINDOW *win)
row++;
mvwprintw(win, row++, 2, "-- Memory Map --");
for(i = 0; i < cb_info.mem_count; i++) {
switch(cb_info.range[i].type) {
for (i = 0; i < cb_info.mem_count; i++) {
switch (cb_info.range[i].type) {
case CB_MEM_RAM:
mvwprintw(win, row++, 4, " RAM: ");
break;
case CB_MEM_RESERVED:
mvwprintw(win, row++, 4, "Reserved: ");
break;
case CB_MEM_TABLE:
mvwprintw(win, row++, 4, " Table: ");
}
@ -121,15 +118,15 @@ int coreboot_module_redraw(WINDOW *win)
static void parse_memory(unsigned char *ptr)
{
struct cb_memory *mem = (struct cb_memory *) ptr;
struct cb_memory *mem = (struct cb_memory *)ptr;
int max = (MEM_RANGE_COUNT(mem) > MAX_MEMORY_COUNT)
? MAX_MEMORY_COUNT : MEM_RANGE_COUNT(mem);
int i;
for(i = 0; i < max; i++) {
for (i = 0; i < max; i++) {
struct cb_memory_range *range =
(struct cb_memory_range *) MEM_RANGE_PTR(mem, i);
(struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
memcpy(&cb_info.range[i], range, sizeof(*range));
}
@ -140,7 +137,7 @@ static void parse_memory(unsigned char *ptr)
static void parse_mainboard(unsigned char *ptr)
{
struct cb_mainboard *mb = (struct cb_mainboard *) ptr;
struct cb_mainboard *mb = (struct cb_mainboard *)ptr;
strncpy(cb_info.vendor, MB_VENDOR_STRING(mb), 31);
strncpy(cb_info.part, MB_PART_STRING(mb), 31);
@ -148,7 +145,7 @@ static void parse_mainboard(unsigned char *ptr)
static void parse_strings(unsigned char *ptr)
{
struct cb_string *string = (struct cb_string *) ptr;
struct cb_string *string = (struct cb_string *)ptr;
int index = string->tag - CB_TAG_VERSION;
strncpy(cb_info.strings[index], string->string, 63);
@ -157,60 +154,58 @@ static void parse_strings(unsigned char *ptr)
static void parse_serial(unsigned char *ptr)
{
memcpy(&cb_info.serial, (struct cb_serial *) ptr,
memcpy(&cb_info.serial, (struct cb_serial *)ptr,
sizeof(struct cb_serial));
}
static void parse_console(unsigned char *ptr)
{
memcpy(&cb_info.console, (struct cb_console *) ptr,
memcpy(&cb_info.console, (struct cb_console *)ptr,
sizeof(struct cb_console));
}
static int parse_header(void *addr, int len)
{
struct cb_header *header;
unsigned char *ptr = (unsigned char *) addr;
unsigned char *ptr = (unsigned char *)addr;
int i;
for (i = 0; i < len; i += 16, ptr += 16) {
header = (struct cb_header *) ptr;
header = (struct cb_header *)ptr;
if (!strncmp(header->signature, "LBIO", 4))
break;
}
/* We walked the entire space and didn't find anything */
/* We walked the entire space and didn't find anything. */
if (i >= len)
return -1;
if (!header->table_bytes)
return 0;
/* FIXME: Check the checksum */
/* FIXME: Check the checksum. */
if (ipchksum((uint16_t *) header, sizeof(*header)))
return -1;
if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes) !=
header->table_checksum)
if (ipchksum((uint16_t *) (ptr + sizeof(*header)), header->table_bytes)
!= header->table_checksum)
return -1;
/* Now, walk the tables */
/* Now, walk the tables. */
ptr += header->header_bytes;
for(i = 0; i < header->table_entries; i++) {
struct cb_record *rec = (struct cb_record *) ptr;
for (i = 0; i < header->table_entries; i++) {
struct cb_record *rec = (struct cb_record *)ptr;
switch(rec->tag) {
switch (rec->tag) {
case CB_TAG_MEMORY:
parse_memory(ptr);
break;
case CB_TAG_MAINBOARD:
parse_mainboard(ptr);
break;
case CB_TAG_VERSION:
case CB_TAG_EXTRA_VERSION:
case CB_TAG_BUILD:
@ -223,15 +218,12 @@ static int parse_header(void *addr, int len)
case CB_TAG_ASSEMBLER:
parse_strings(ptr);
break;
case CB_TAG_SERIAL:
parse_serial(ptr);
break;
case CB_TAG_CONSOLE:
parse_console(ptr);
break;
default:
break;
}
@ -244,19 +236,16 @@ static int parse_header(void *addr, int len)
int coreboot_module_init(void)
{
int ret = parse_header((void *) 0x00000, 0x1000);
int ret = parse_header((void *)0x00000, 0x1000);
if (ret != 1)
ret = parse_header((void *) 0xf0000, 0x1000);
/* return error if we couldn't find it at either address */
ret = parse_header((void *)0xf0000, 0x1000);
/* Return error if we couldn't find it at either address. */
tables_good = (ret == 1) ? 0 : -1;
return tables_good;
}
struct coreinfo_module coreboot_module = {
.name = "Coreboot",
.init = coreboot_module_init,

View File

@ -46,22 +46,22 @@ void print_module_title(WINDOW *win, const char *title)
wmove(win, 1, 1);
for(i = 0; i < 78; i++)
for (i = 0; i < 78; i++)
waddch(win, '\304');
}
void print_menu(void) {
int i, len;
void print_menu(void)
{
int i, j, len;
char menu[80];
char *ptr = menu;
int j;
wmove(stdscr, 23, 0);
for(j = 0; j < SCREEN_X; j++)
for (j = 0; j < SCREEN_X; j++)
waddch(stdscr, ' ');
for(i = 0; i < MODULE_COUNT; i++)
for (i = 0; i < MODULE_COUNT; i++)
ptr += sprintf(ptr, "F%d: %s ", i + 1, modules[i]->name);
mvprintw(23, 0, menu);
@ -74,7 +74,7 @@ void center(int row, const char *str)
wmove(stdscr, row, 0);
for(j = 0; j < SCREEN_X; j++)
for (j = 0; j < SCREEN_X; j++)
waddch(stdscr, ' ');
mvprintw(row, (SCREEN_X - len) / 2, str);
@ -87,13 +87,12 @@ void header(int row, const char *str)
int i;
int len = strlen(str) + 4;
for(i = 0; i < (SCREEN_X - len) / 2; i++)
for (i = 0; i < (SCREEN_X - len) / 2; i++)
ptr += sprintf(ptr, "=");
ptr += sprintf(ptr, "[ %s ]", str);
for(i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X ; i++)
for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++)
ptr += sprintf(ptr, "=");
mvprintw(row, 0, buf);
@ -116,7 +115,7 @@ int loop(void)
modules[curwin]->redraw(modwin);
refresh();
while(1) {
while (1) {
key = getch();
if (key == ERR)
@ -156,16 +155,16 @@ int main(void)
wattrset(stdscr, COLOR_PAIR(1) | A_BOLD);
wattrset(modwin, COLOR_PAIR(2));
for(i = 0; i < 23; i++) {
for (i = 0; i < 23; i++) {
wmove(modwin, i - 1, 0);
for(j = 0; j < SCREEN_X; j++)
for (j = 0; j < SCREEN_X; j++)
waddch(modwin, ' ');
}
refresh();
for(i = 0; i < MODULE_COUNT; i++)
for (i = 0; i < MODULE_COUNT; i++)
modules[i]->init();
loop();

View File

@ -21,18 +21,18 @@
#define COREINFO_H_
#include <libpayload.h>
#include <curses.h>
struct coreinfo_module {
char name[15];
int (*init)(void);
int (*redraw)(WINDOW *);
int (*handle)(int);
int (*init) (void);
int (*redraw) (WINDOW *);
int (*handle) (int);
};
extern void docpuid(int, unsigned long *, unsigned long *, unsigned long *, unsigned long *);
extern void docpuid(int, unsigned long *, unsigned long *, unsigned long *,
unsigned long *);
void print_module_title(WINDOW *, const char *title);
void print_module_title(WINDOW *win, const char *title);
#endif

View File

@ -40,13 +40,14 @@ const char *generic_cap_flags[] = {
"fxsr", "sse", "sse2", "ss", "ht", "tm", NULL, "pbe"
};
/* CPUID 0x00000001 ECX flags */
/* CPUID 0x00000001 ECX flags */
const char *intel_cap_generic_ecx_flags[] = {
"sse3", NULL, NULL, "monitor", "ds-cpl", "vmx", NULL, "est",
"tm2", "ssse3", "cntx-id", NULL, NULL, "cx16", "xTPR", NULL,
NULL, NULL, "dca", NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
/* CPUID 0x80000001 EDX flags */
const char *intel_cap_extended_edx_flags[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@ -54,6 +55,7 @@ const char *intel_cap_extended_edx_flags[] = {
NULL, NULL, NULL, NULL, "xd", NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, "em64t", NULL, NULL,
};
/* CPUID 0x80000001 ECX flags */
const char *intel_cap_extended_ecx_flags[] = {
"lahf_lm", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@ -96,7 +98,7 @@ void decode_flags(WINDOW *win, unsigned long reg, const char **flags, int *row)
wmove(win, lrow, 2);
for(i = 0; i < 32; i++) {
for (i = 0; i < 32; i++) {
if (flags[i] == NULL)
continue;
@ -112,7 +114,6 @@ void decode_flags(WINDOW *win, unsigned long reg, const char **flags, int *row)
*row = lrow;
}
static void get_features(WINDOW *win, int *row)
{
unsigned long eax, ebx, ecx, edx;
@ -127,7 +128,7 @@ static void get_features(WINDOW *win, int *row)
lrow++;
switch(vendor) {
switch (vendor) {
case VENDOR_AMD:
wmove(win, lrow++, 1);
wprintw(win, "AMD Extended Flags: ");
@ -136,7 +137,6 @@ static void get_features(WINDOW *win, int *row)
decode_flags(win, edx, amd_cap_extended_edx_flags, &lrow);
decode_flags(win, ecx, amd_cap_extended_ecx_flags, &lrow);
break;
case VENDOR_INTEL:
wmove(win, lrow++, 1);
wprintw(win, "Intel Extended Flags: ");
@ -152,46 +152,43 @@ static void get_features(WINDOW *win, int *row)
static void do_name(WINDOW *win, int row)
{
char str[80];
char str[80], name[49], *p;
unsigned long eax, ebx, ecx, edx;
int i, t;
char name[49], *p;
p = name;
for(i = 0x80000002; i <= 0x80000004; i++) {
for (i = 0x80000002; i <= 0x80000004; i++) {
docpuid(i, &eax, &ebx, &ecx, &edx);
if (eax == 0)
break;
for(t = 0; t < 4; t++)
for (t = 0; t < 4; t++)
*p++ = eax >> (8 * t);
for(t = 0; t < 4; t++)
for (t = 0; t < 4; t++)
*p++ = ebx >> (8 * t);
for(t = 0; t < 4; t++)
for (t = 0; t < 4; t++)
*p++ = ecx >> (8 * t);
for(t = 0; t < 4; t++)
for (t = 0; t < 4; t++)
*p++ = edx >> (8 * t);
}
mvwprintw(win, row,1, "Processor: %s", name);
mvwprintw(win, row, 1, "Processor: %s", name);
}
int cpuinfo_module_redraw(WINDOW *win)
int cpuinfo_module_redraw(WINDOW * win)
{
unsigned long eax, ebx, ecx, edx;
unsigned int brand;
char str[80];
char *vstr;
char str[80], *vstr;
int row = 2;
print_module_title(win, "CPU Information");
docpuid(0, NULL, &vendor, NULL, NULL);
switch(vendor) {
switch (vendor) {
case VENDOR_INTEL:
vstr = "Intel";
break;
@ -221,7 +218,7 @@ int cpuinfo_module_redraw(WINDOW *win)
docpuid(0x00000001, &eax, &ebx, &ecx, &edx);
mvwprintw(win, row++, 1, "Family: %X",(eax >> 8) & 0x0f);
mvwprintw(win, row++, 1, "Family: %X", (eax >> 8) & 0x0f);
mvwprintw(win, row++, 1, "Model: %X",
((eax >> 4) & 0xf) | ((eax >> 16) & 0xf) << 4);
@ -229,18 +226,15 @@ int cpuinfo_module_redraw(WINDOW *win)
if (vendor == VENDOR_AMD) {
docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
brand = ((ebx >> 9) & 0x1F);
brand = ((ebx >> 9) & 0x1f);
mvwprintw(win, row++, 1,"Brand: %X", brand);
mvwprintw(win, row++, 1, "Brand: %X", brand);
}
if (cpu_khz != 0) {
mvwprintw(win, row++, 1, "CPU Speed: %d Mhz",
cpu_khz / 1000);
}
else {
if (cpu_khz != 0)
mvwprintw(win, row++, 1, "CPU Speed: %d Mhz", cpu_khz / 1000);
else
mvwprintw(win, row++, 1, "CPU Speed: Error");
}
row++;
get_features(win, &row);
@ -250,13 +244,12 @@ unsigned int getticks(void)
{
unsigned long long start, end;
/* Read the number of ticks during the period */
/* Read the number of ticks during the period. */
start = rdtsc();
mdelay(100);
end = rdtsc();
return (unsigned int) ((end - start) / 100);
return (unsigned int)((end - start) / 100);
}
int cpuinfo_module_init(void)

View File

@ -29,7 +29,7 @@ static struct pci_devices devices[64];
static int devices_index;
#define REG_VENDOR_ID 0x00
#define REG_HEADER_TYPE 0x0E
#define REG_HEADER_TYPE 0x0e
#define REG_PRIMARY_BUS 0x18
#define HEADER_TYPE_NORMAL 0
@ -37,7 +37,7 @@ static int devices_index;
#define HEADER_TYPE_CARDBUS 2
#define PCI_ADDR(_bus, _dev, _reg) \
(0x80000000 | (_bus << 16) | (_dev << 8) | (_reg & ~3))
(0x80000000 | (_bus << 16) | (_dev << 8) | (_reg & ~3))
/* Number of entries to show in the list */
#define MENU_VISIBLE 16
@ -67,8 +67,7 @@ static int partition(struct pci_devices *list, int len)
swap(&list[len / 2], &list[len - 1]);
for(i = 0; i < len - 1; i++) {
for (i = 0; i < len - 1; i++) {
if (list[i].device < val) {
swap(&list[i], &list[index]);
index++;
@ -76,6 +75,7 @@ static int partition(struct pci_devices *list, int len)
}
swap(&list[index], &list[len - 1]);
return index;
}
@ -95,15 +95,15 @@ static void quicksort(struct pci_devices *list, int len)
static void pci_read_dword(unsigned int bus, unsigned int devfn,
unsigned int reg, unsigned int *val)
{
outl(PCI_ADDR(bus, devfn, reg), 0xCF8);
*val = inl(0xCFC);
outl(PCI_ADDR(bus, devfn, reg), 0xcf8);
*val = inl(0xcfc);
}
static void pci_read_byte(unsigned int bus, unsigned int devfn,
unsigned int reg, unsigned char *val)
{
outl(PCI_ADDR(bus, devfn, reg), 0xCF8);
*val = inb(0xCFC + (reg & 3));
outl(PCI_ADDR(bus, devfn, reg), 0xcf8);
*val = inb(0xcfc + (reg & 3));
}
static int show_config_space(WINDOW *win, int row, int col, int index)
@ -112,23 +112,23 @@ static int show_config_space(WINDOW *win, int row, int col, int index)
int bus, devfn;
int i, x, y;
bus = (devices[index].device >> 8) & 0xFF;
devfn = devices[index].device & 0xFF;
bus = (devices[index].device >> 8) & 0xff;
devfn = devices[index].device & 0xff;
for(i = 0; i < 64; i+= 4)
pci_read_dword(bus, devfn, i, ((int *) &cspace[i]));
for (i = 0; i < 64; i += 4)
pci_read_dword(bus, devfn, i, ((int *)&cspace[i]));
for(y = 0; y < 4; y++) {
for(x = 0; x < 16; x++)
mvwprintw(win, row + y, col + (x * 3), "%2.2X ", cspace[(y * 16) + x]);
for (y = 0; y < 4; y++) {
for (x = 0; x < 16; x++)
mvwprintw(win, row + y, col + (x * 3), "%2.2X ",
cspace[(y * 16) + x]);
}
}
int pci_module_redraw(WINDOW *win)
{
unsigned int bus, devfn, func;
int i;
int last;
int i, last;
print_module_title(win, "PCI Device List");
@ -137,54 +137,53 @@ int pci_module_redraw(WINDOW *win)
if (last > devices_index)
last = devices_index;
for(i = 0; i < MENU_VISIBLE; i++) {
for (i = 0; i < MENU_VISIBLE; i++) {
int item = menu_first + i;
/* Draw a blank space */
/* Draw a blank space. */
if (item >= devices_index) {
wattrset(win, COLOR_PAIR(2));
mvwprintw(win, 2 + i, 1, " ");
continue;
}
bus = (devices[item].device >> 8) & 0xFF;
devfn = (devices[item].device & 0xFF) / 8;
func = (devices[item].device & 0xFF) % 8;
bus = (devices[item].device >> 8) & 0xff;
devfn = (devices[item].device & 0xff) / 8;
func = (devices[item].device & 0xff) % 8;
if (item == menu_selected)
wattrset(win, COLOR_PAIR(3) | A_BOLD);
else
wattrset(win, COLOR_PAIR(2));
mvwprintw(win, 2+i, 1, "%X:%2.2X.%2.2X %X:%X ",
mvwprintw(win, 2 + i, 1, "%X:%2.2X.%2.2X %X:%X ",
bus, devfn, func,
devices[item].id & 0xFFFF,
(devices[item].id >> 16) & 0xFFFF);
devices[item].id & 0xffff,
(devices[item].id >> 16) & 0xffff);
wattrset(win, COLOR_PAIR(2));
if (i == 0) {
if (item != 0)
mvwprintw(win, 2+ i, 19, "\30");
mvwprintw(win, 2 + i, 19, "\30");
}
if (i == MENU_VISIBLE - 1) {
if ((item + 1) < devices_index)
mvwprintw(win, 2+ i, 19, "\31");
mvwprintw(win, 2 + i, 19, "\31");
}
}
wattrset(win, COLOR_PAIR(2));
for(i = 0; i < 16; i++)
for (i = 0; i < 16; i++)
mvwprintw(win, 2, 26 + (i * 3), "%2.2X ", i);
wmove(win, 3, 25);
for(i = 0; i < 48; i++)
for (i = 0; i < 48; i++)
waddch(win, (i == 0) ? '\332' : '\304');
for(i = 0; i < 4; i++) {
for (i = 0; i < 4; i++) {
mvwprintw(win, 4 + i, 23, "%2.2X", i * 16);
wmove(win, 4 + i, 25);
waddch(win, '\263');
@ -201,32 +200,27 @@ static void pci_scan_bus(int bus)
unsigned int val;
unsigned char hdr;
for(devfn = 0; devfn < 0x100; ) {
for(func = 0; func < 8; func++, devfn++) {
for (devfn = 0; devfn < 0x100;) {
for (func = 0; func < 8; func++, devfn++) {
pci_read_dword(bus, devfn, REG_VENDOR_ID, &val);
/* Nobody home */
/* Nobody home. */
if (val == 0xffffffff || val == 0x00000000 ||
val == 0x0000ffff || val == 0xffff0000)
continue;
/* FIXME: Remove this arbitrary limitation */
/* FIXME: Remove this arbitrary limitation. */
if (devices_index >= 64)
return;
devices[devices_index].device =
((bus & 0xFF) << 8) | (devfn & 0xFF);
((bus & 0xff) << 8) | (devfn & 0xff);
devices[devices_index++].id = val;
/* If this is a bridge, then follow it */
/* If this is a bridge, then follow it. */
pci_read_byte(bus, devfn, REG_HEADER_TYPE, &hdr);
hdr &= 0x7F;
hdr &= 0x7f;
if (hdr == HEADER_TYPE_BRIDGE ||
hdr == HEADER_TYPE_CARDBUS) {
unsigned int busses;
@ -234,7 +228,7 @@ static void pci_scan_bus(int bus)
pci_read_dword(bus, devfn, REG_PRIMARY_BUS,
&busses);
pci_scan_bus((busses >> 8) & 0xFF);
pci_scan_bus((busses >> 8) & 0xff);
}
}
@ -247,21 +241,18 @@ int pci_module_handle(int key)
{
int ret = 0;
switch(key) {
switch (key) {
case KEY_DOWN:
if (menu_selected + 1 < devices_index) {
menu_selected++;
ret = 1;
}
break;
case KEY_UP:
if (menu_selected > 0) {
menu_selected--;
ret = 1;
}
break;
}
@ -276,7 +267,6 @@ int pci_module_handle(int key)
menu_first = 0;
}
return ret;
}
@ -285,7 +275,6 @@ int pci_module_init(void)
unsigned int val;
int bus = 0;
pci_scan_bus(0);
return 0;