1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// Option rom scanning code.
//
// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
// Copyright (C) 2002 MandrakeSoft S.A.
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "bregs.h" // struct bregs
#include "biosvar.h" // struct ipl_entry_s
#include "util.h" // dprintf
// $PnP string with special alignment in romlayout.S
extern char pnp_string[];
struct rom_header {
u16 signature;
u8 size;
u8 initVector[4];
u8 reserved[17];
u16 pcioffset;
u16 pnpoffset;
} PACKED;
struct pci_data {
u32 signature;
u16 vendor;
u16 device;
u16 vitaldata;
u16 dlen;
u8 drevision;
u8 class_lo;
u16 class_hi;
u16 ilen;
u16 irevision;
u8 type;
u8 indicator;
u16 reserved;
} PACKED;
struct pnp_data {
u32 signature;
u8 revision;
u8 len;
u16 nextoffset;
u8 reserved_08;
u8 checksum;
u32 devid;
u16 manufacturer;
u16 productname;
u8 type_lo;
u16 type_hi;
u8 dev_flags;
u16 bcv;
u16 dv;
u16 bev;
u16 reserved_1c;
u16 staticresource;
} PACKED;
// Execute a given option rom.
static void
callrom(u16 seg, u16 offset)
{
dprintf(1, "Running option rom at %x:%x\n", seg, offset);
struct bregs br;
memset(&br, 0, sizeof(br));
// XXX - should set br.ax to PCI Bus/DevFn
br.bx = 0xffff;
br.dx = 0xffff;
br.es = SEG_BIOS;
br.di = (u32)pnp_string - BUILD_BIOS_ADDR;
br.cs = seg;
br.ip = offset;
call16(&br);
debug_serial_setup();
if (GET_BDA(ebda_seg) != SEG_EBDA)
BX_PANIC("Option rom at %x:%x attempted to move ebda from %x to %x\n"
, seg, offset, SEG_EBDA, GET_BDA(ebda_seg));
}
#define ebda ((struct extended_bios_data_area_s *)MAKE_FARPTR(SEG_EBDA, 0))
// Find and run any "option roms" found in the given address range.
static void
rom_scan(u32 start, u32 end)
{
if (! CONFIG_OPTIONROMS)
return;
u8 *p = (u8*)start;
for (; p < (u8*)end; p += 2048) {
struct rom_header *rom = (struct rom_header *)p;
if (rom->signature != 0xaa55)
continue;
u32 len = rom->size * 512;
u8 sum = checksum(p, len);
if (sum != 0) {
dprintf(1, "Found option rom with bad checksum:"
" loc=%p len=%d sum=%x\n"
, rom, len, sum);
continue;
}
p = (u8*)(((u32)p + len) / 2048 * 2048);
callrom(FARPTR_TO_SEG(rom), FARPTR_TO_OFFSET(rom->initVector));
// Look at the ROM's PnP Expansion header. Properly, we're supposed
// to init all the ROMs and then go back and build an IPL table of
// all the bootable devices, but we can get away with one pass.
struct pnp_data *pnp = (struct pnp_data *)((u8*)rom + rom->pnpoffset);
if (pnp->signature != *(u32*)pnp_string)
continue;
u16 entry = pnp->bev;
if (!entry)
continue;
// Found a device that thinks it can boot the system. Record
// its BEV and product name string.
if (! CONFIG_BOOT)
continue;
if (ebda->ipl.count >= ARRAY_SIZE(ebda->ipl.table))
continue;
struct ipl_entry_s *ip = &ebda->ipl.table[ebda->ipl.count];
ip->type = IPL_TYPE_BEV;
ip->vector = (FARPTR_TO_SEG(rom) << 16) | entry;
u16 desc = pnp->productname;
if (desc)
ip->description = MAKE_FARPTR(FARPTR_TO_SEG(rom), desc);
ebda->ipl.count++;
}
}
// Call into vga code to turn on console.
void
vga_setup()
{
dprintf(1, "Scan for VGA option rom\n");
rom_scan(0xc0000, 0xc8000);
dprintf(1, "Turning on vga console\n");
struct bregs br;
memset(&br, 0, sizeof(br));
br.ax = 0x0003;
call16_int(0x10, &br);
// Write to screen.
printf("Starting SeaBIOS\n\n");
}
void
optionrom_setup()
{
dprintf(1, "Scan for option roms\n");
rom_scan(0xc8000, 0xf0000);
}
|