blob: bdc0cb5f1247003eb4f6a0439aaf5e27a2d1c3e3 [file] [log] [blame]
Kevin O'Connor714325c2008-11-01 20:32:27 -04001// Option rom scanning code.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2002 MandrakeSoft S.A.
5//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connor714325c2008-11-01 20:32:27 -04007
8#include "bregs.h" // struct bregs
Kevin O'Connor35ae7262009-01-19 15:44:44 -05009#include "farptr.h" // FLATPTR_TO_SEG
Kevin O'Connorc659fde2008-12-28 23:43:20 -050010#include "config.h" // CONFIG_*
Kevin O'Connor714325c2008-11-01 20:32:27 -040011#include "util.h" // dprintf
Kevin O'Connor51fd0a12009-09-12 13:20:14 -040012#include "pci.h" // foreachpci
Kevin O'Connorceea03c2008-11-08 21:36:35 -050013#include "pci_regs.h" // PCI_ROM_ADDRESS
14#include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
Kevin O'Connorc659fde2008-12-28 23:43:20 -050015#include "boot.h" // IPL
Kevin O'Connorceea03c2008-11-08 21:36:35 -050016
17
18/****************************************************************
19 * Definitions
20 ****************************************************************/
Kevin O'Connor714325c2008-11-01 20:32:27 -040021
Kevin O'Connor714325c2008-11-01 20:32:27 -040022struct rom_header {
23 u16 signature;
24 u8 size;
25 u8 initVector[4];
26 u8 reserved[17];
27 u16 pcioffset;
28 u16 pnpoffset;
29} PACKED;
30
31struct pci_data {
32 u32 signature;
33 u16 vendor;
34 u16 device;
35 u16 vitaldata;
36 u16 dlen;
37 u8 drevision;
38 u8 class_lo;
39 u16 class_hi;
40 u16 ilen;
41 u16 irevision;
42 u8 type;
43 u8 indicator;
44 u16 reserved;
45} PACKED;
46
47struct pnp_data {
48 u32 signature;
49 u8 revision;
50 u8 len;
51 u16 nextoffset;
52 u8 reserved_08;
53 u8 checksum;
54 u32 devid;
55 u16 manufacturer;
56 u16 productname;
57 u8 type_lo;
58 u16 type_hi;
59 u8 dev_flags;
60 u16 bcv;
61 u16 dv;
62 u16 bev;
63 u16 reserved_1c;
64 u16 staticresource;
65} PACKED;
66
Kevin O'Connorceea03c2008-11-08 21:36:35 -050067#define OPTION_ROM_SIGNATURE 0xaa55
68#define OPTION_ROM_ALIGN 2048
69#define OPTION_ROM_INITVECTOR offsetof(struct rom_header, initVector[0])
Kevin O'Connor5a1b8282008-11-29 20:39:06 -050070#define PCI_ROM_SIGNATURE 0x52494350 // PCIR
Kevin O'Connor62eea672008-12-06 11:57:45 -050071#define PCIROM_CODETYPE_X86 0
Kevin O'Connorceea03c2008-11-08 21:36:35 -050072
Kevin O'Connore7739302009-07-26 19:16:09 -040073// The end of the last deployed rom.
74u32 RomEnd;
Kevin O'Connorceea03c2008-11-08 21:36:35 -050075
76
77/****************************************************************
78 * Helper functions
79 ****************************************************************/
80
Kevin O'Connor714325c2008-11-01 20:32:27 -040081// Execute a given option rom.
82static void
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040083__callrom(struct rom_header *rom, u16 offset, u16 bdf)
Kevin O'Connor714325c2008-11-01 20:32:27 -040084{
Kevin O'Connor35ae7262009-01-19 15:44:44 -050085 u16 seg = FLATPTR_TO_SEG(rom);
Kevin O'Connor91b53a72009-05-05 22:52:09 -040086 dprintf(1, "Running option rom at %04x:%04x\n", seg, offset);
Kevin O'Connor714325c2008-11-01 20:32:27 -040087
88 struct bregs br;
89 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -040090 br.flags = F_IF;
Kevin O'Connorceea03c2008-11-08 21:36:35 -050091 br.ax = bdf;
Kevin O'Connor714325c2008-11-01 20:32:27 -040092 br.bx = 0xffff;
93 br.dx = 0xffff;
94 br.es = SEG_BIOS;
Kevin O'Connor0c3068d2008-12-21 17:51:36 -050095 br.di = get_pnp_offset();
Kevin O'Connor9f985422009-09-09 11:34:39 -040096 br.code = SEGOFF(seg, offset);
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050097 call16big(&br);
Kevin O'Connor714325c2008-11-01 20:32:27 -040098
99 debug_serial_setup();
Kevin O'Connor714325c2008-11-01 20:32:27 -0400100}
101
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400102// Execute a given option rom at the standard entry vector.
103static void
104callrom(struct rom_header *rom, u16 bdf)
105{
106 __callrom(rom, OPTION_ROM_INITVECTOR, bdf);
107}
108
Kevin O'Connor0a924122009-02-08 19:43:47 -0500109// Execute a BCV option rom registered via add_bcv().
110void
111call_bcv(u16 seg, u16 ip)
112{
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400113 __callrom(MAKE_FLATPTR(seg, 0), ip, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -0500114}
115
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500116// Verify that an option rom looks valid
117static int
118is_valid_rom(struct rom_header *rom)
119{
Kevin O'Connorc36273f2009-04-16 20:43:07 -0400120 dprintf(6, "Checking rom %p (sig %x size %d)\n"
121 , rom, rom->signature, rom->size);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500122 if (rom->signature != OPTION_ROM_SIGNATURE)
123 return 0;
Kevin O'Connor674e4602009-04-13 19:19:22 -0400124 if (! rom->size)
125 return 0;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500126 u32 len = rom->size * 512;
Kevin O'Connor94fd47e2009-02-15 15:21:10 -0500127 u8 sum = checksum(rom, len);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500128 if (sum != 0) {
129 dprintf(1, "Found option rom with bad checksum: loc=%p len=%d sum=%x\n"
130 , rom, len, sum);
131 return 0;
132 }
133 return 1;
134}
135
136// Check if a valid option rom has a pnp struct; return it if so.
137static struct pnp_data *
138get_pnp_rom(struct rom_header *rom)
139{
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400140 struct pnp_data *pnp = (void*)((u8*)rom + rom->pnpoffset);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500141 if (pnp->signature != PNP_SIGNATURE)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500142 return NULL;
143 return pnp;
144}
145
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -0500146// Check for multiple pnp option rom headers.
147static struct pnp_data *
148get_pnp_next(struct rom_header *rom, struct pnp_data *pnp)
149{
150 if (! pnp->nextoffset)
151 return NULL;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400152 pnp = (void*)((u8*)rom + pnp->nextoffset);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500153 if (pnp->signature != PNP_SIGNATURE)
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -0500154 return NULL;
155 return pnp;
156}
157
Kevin O'Connor62eea672008-12-06 11:57:45 -0500158// Check if a valid option rom has a pci struct; return it if so.
159static struct pci_data *
160get_pci_rom(struct rom_header *rom)
161{
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400162 struct pci_data *pci = (void*)((u32)rom + rom->pcioffset);
Kevin O'Connor62eea672008-12-06 11:57:45 -0500163 if (pci->signature != PCI_ROM_SIGNATURE)
164 return NULL;
165 return pci;
166}
167
Kevin O'Connor5b8f8092009-09-20 19:47:45 -0400168// Return the memory position up to which roms may be located.
169static inline u32
170max_rom()
171{
172 extern u8 code32_start[];
173 if ((u32)code32_start > BUILD_BIOS_ADDR)
174 return BUILD_BIOS_ADDR;
175 return (u32)code32_start;
176}
177
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500178// Copy a rom to its permanent location below 1MiB
179static struct rom_header *
180copy_rom(struct rom_header *rom)
181{
182 u32 romsize = rom->size * 512;
Kevin O'Connor5b8f8092009-09-20 19:47:45 -0400183 if (RomEnd + romsize > max_rom()) {
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500184 // Option rom doesn't fit.
185 dprintf(1, "Option rom %p doesn't fit.\n", rom);
186 return NULL;
187 }
Kevin O'Connorc36273f2009-04-16 20:43:07 -0400188 dprintf(4, "Copying option rom (size %d) from %p to %x\n"
Kevin O'Connore7739302009-07-26 19:16:09 -0400189 , romsize, rom, RomEnd);
190 memcpy((void*)RomEnd, rom, romsize);
191 return (void*)RomEnd;
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500192}
193
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400194// Run rom init code and note rom size.
195static int
196init_optionrom(struct rom_header *rom, u16 bdf, int isvga)
197{
198 if (! is_valid_rom(rom))
199 return -1;
200
201 if (isvga || get_pnp_rom(rom))
202 // Only init vga and PnP roms here.
203 callrom(rom, bdf);
204
Kevin O'Connore7739302009-07-26 19:16:09 -0400205 RomEnd = (u32)rom + ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400206
207 return 0;
208}
209
210
211/****************************************************************
212 * Roms in CBFS
213 ****************************************************************/
214
215// Check if an option rom is at a hardcoded location or in CBFS.
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500216static struct rom_header *
Kevin O'Connor4c0c85a2009-04-11 23:31:29 -0400217lookup_hardcode(u32 vendev)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500218{
Kevin O'Connor4c0c85a2009-04-11 23:31:29 -0400219 if (OPTIONROM_VENDEV_1
220 && ((OPTIONROM_VENDEV_1 >> 16)
221 | ((OPTIONROM_VENDEV_1 & 0xffff)) << 16) == vendev)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400222 return copy_rom((void*)OPTIONROM_MEM_1);
Kevin O'Connor4c0c85a2009-04-11 23:31:29 -0400223 if (OPTIONROM_VENDEV_2
224 && ((OPTIONROM_VENDEV_2 >> 16)
225 | ((OPTIONROM_VENDEV_2 & 0xffff)) << 16) == vendev)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400226 return copy_rom((void*)OPTIONROM_MEM_2);
Kevin O'Connor5b8f8092009-09-20 19:47:45 -0400227 int ret = cbfs_copy_optionrom((void*)RomEnd, max_rom() - RomEnd, vendev);
Kevin O'Connorcbd6ca02009-04-27 21:51:13 -0400228 if (ret < 0)
229 return NULL;
Kevin O'Connore7739302009-07-26 19:16:09 -0400230 return (void*)RomEnd;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500231}
232
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400233// Run all roms in a given CBFS directory.
234static void
235run_cbfs_roms(const char *prefix, int isvga)
236{
Kevin O'Connor1f836252009-08-16 20:17:35 -0400237 struct cbfs_file *file = NULL;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400238 for (;;) {
Kevin O'Connor00882592009-08-18 22:21:10 -0400239 file = cbfs_findprefix(prefix, file);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400240 if (!file)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400241 break;
Kevin O'Connor5b8f8092009-09-20 19:47:45 -0400242 int ret = cbfs_copyfile(file, (void*)RomEnd, max_rom() - RomEnd);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400243 if (ret > 0)
244 init_optionrom((void*)RomEnd, 0, isvga);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400245 }
246}
247
248
249/****************************************************************
250 * PCI roms
251 ****************************************************************/
252
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500253// Map the option rom of a given PCI device.
254static struct rom_header *
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400255map_pcirom(u16 bdf, u32 vendev)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500256{
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400257 dprintf(6, "Attempting to map option rom on dev %02x:%02x.%x\n"
258 , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf));
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500259
Kevin O'Connor62eea672008-12-06 11:57:45 -0500260 u8 htype = pci_config_readb(bdf, PCI_HEADER_TYPE);
261 if ((htype & 0x7f) != PCI_HEADER_TYPE_NORMAL) {
262 dprintf(6, "Skipping non-normal pci device (type=%x)\n", htype);
263 return NULL;
264 }
265
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500266 u32 orig = pci_config_readl(bdf, PCI_ROM_ADDRESS);
267 pci_config_writel(bdf, PCI_ROM_ADDRESS, ~PCI_ROM_ADDRESS_ENABLE);
268 u32 sz = pci_config_readl(bdf, PCI_ROM_ADDRESS);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500269
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500270 dprintf(6, "Option rom sizing returned %x %x\n", orig, sz);
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500271 orig &= ~PCI_ROM_ADDRESS_ENABLE;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500272 if (!sz || sz == 0xffffffff)
273 goto fail;
274
Kevin O'Connor64cf2fb2009-04-18 17:01:02 -0400275 if (orig == sz || (u32)(orig + 4*1024*1024) < 20*1024*1024) {
276 // Don't try to map to a pci addresses at its max, in the last
277 // 4MiB of ram, or the first 16MiB of ram.
Kevin O'Connor62eea672008-12-06 11:57:45 -0500278 dprintf(6, "Preset rom address doesn't look valid\n");
279 goto fail;
280 }
281
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500282 // Looks like a rom - enable it.
283 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig | PCI_ROM_ADDRESS_ENABLE);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500284
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400285 struct rom_header *rom = (void*)orig;
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500286 for (;;) {
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400287 dprintf(5, "Inspecting possible rom at %p (dv=%08x bdf=%x)\n"
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500288 , rom, vendev, bdf);
289 if (rom->signature != OPTION_ROM_SIGNATURE) {
290 dprintf(6, "No option rom signature (got %x)\n", rom->signature);
291 goto fail;
292 }
Kevin O'Connor62eea672008-12-06 11:57:45 -0500293 struct pci_data *pci = get_pci_rom(rom);
294 if (! pci) {
295 dprintf(6, "No valid pci signature found\n");
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500296 goto fail;
297 }
Kevin O'Connor62eea672008-12-06 11:57:45 -0500298
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500299 u32 vd = (pci->device << 16) | pci->vendor;
Kevin O'Connor62eea672008-12-06 11:57:45 -0500300 if (vd == vendev && pci->type == PCIROM_CODETYPE_X86)
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500301 // A match
302 break;
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400303 dprintf(6, "Didn't match dev/ven (got %08x) or type (got %d)\n"
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500304 , vd, pci->type);
305 if (pci->indicator & 0x80) {
306 dprintf(6, "No more images left\n");
307 goto fail;
308 }
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400309 rom = (void*)((u32)rom + pci->ilen * 512);
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500310 }
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500311
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500312 rom = copy_rom(rom);
313 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500314 return rom;
315fail:
316 // Not valid - restore original and exit.
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500317 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500318 return NULL;
319}
320
321// Attempt to map and initialize the option rom on a given PCI device.
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400322static int
323init_pcirom(u16 bdf, int isvga)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500324{
Kevin O'Connor4c0c85a2009-04-11 23:31:29 -0400325 u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID);
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400326 dprintf(4, "Attempting to init PCI bdf %02x:%02x.%x (dev/ven %08x)\n"
Kevin O'Connor91b53a72009-05-05 22:52:09 -0400327 , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)
328 , vendev);
Kevin O'Connor4c0c85a2009-04-11 23:31:29 -0400329 struct rom_header *rom = lookup_hardcode(vendev);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500330 if (! rom)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400331 rom = map_pcirom(bdf, vendev);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500332 if (! rom)
333 // No ROM present.
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400334 return -1;
335 return init_optionrom(rom, bdf, isvga);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500336}
337
338
339/****************************************************************
340 * Non-VGA option rom init
341 ****************************************************************/
342
343void
344optionrom_setup()
Kevin O'Connor714325c2008-11-01 20:32:27 -0400345{
346 if (! CONFIG_OPTIONROMS)
347 return;
348
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500349 dprintf(1, "Scan for option roms\n");
350
Kevin O'Connore7739302009-07-26 19:16:09 -0400351 u32 post_vga = RomEnd;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500352
353 if (CONFIG_OPTIONROMS_DEPLOYED) {
354 // Option roms are already deployed on the system.
Kevin O'Connore7739302009-07-26 19:16:09 -0400355 u32 pos = RomEnd;
Kevin O'Connor5b8f8092009-09-20 19:47:45 -0400356 while (pos < max_rom()) {
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400357 int ret = init_optionrom((void*)pos, 0, 0);
358 if (ret)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500359 pos += OPTION_ROM_ALIGN;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400360 else
Kevin O'Connore7739302009-07-26 19:16:09 -0400361 pos = RomEnd;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500362 }
363 } else {
364 // Find and deploy PCI roms.
Kevin O'Connore6338322008-11-29 20:31:49 -0500365 int bdf, max;
Kevin O'Connor4132e022008-12-04 19:39:10 -0500366 foreachpci(bdf, max) {
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500367 u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
Kevin O'Connor62eea672008-12-06 11:57:45 -0500368 if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA
369 || (CONFIG_ATA && v == PCI_CLASS_STORAGE_IDE))
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500370 continue;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400371 init_pcirom(bdf, 0);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500372 }
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400373
374 // Find and deploy CBFS roms not associated with a device.
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400375 run_cbfs_roms("genroms/", 0);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500376 }
377
378 // All option roms found and deployed - now build BEV/BCV vectors.
379
380 u32 pos = post_vga;
Kevin O'Connore7739302009-07-26 19:16:09 -0400381 while (pos < RomEnd) {
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400382 struct rom_header *rom = (void*)pos;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500383 if (! is_valid_rom(rom)) {
384 pos += OPTION_ROM_ALIGN;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400385 continue;
386 }
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500387 pos += ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
388 struct pnp_data *pnp = get_pnp_rom(rom);
389 if (! pnp) {
Kevin O'Connor0a924122009-02-08 19:43:47 -0500390 // Legacy rom.
391 add_bcv(FLATPTR_TO_SEG(rom), OPTION_ROM_INITVECTOR, 0);
Kevin O'Connor714325c2008-11-01 20:32:27 -0400392 continue;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500393 }
394 // PnP rom.
395 if (pnp->bev)
396 // Can boot system - add to IPL list.
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500397 add_bev(FLATPTR_TO_SEG(rom), pnp->bev, pnp->productname);
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -0500398 else
399 // Check for BCV (there may be multiple).
400 while (pnp && pnp->bcv) {
Kevin O'Connor0a924122009-02-08 19:43:47 -0500401 add_bcv(FLATPTR_TO_SEG(rom), pnp->bcv, pnp->productname);
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -0500402 pnp = get_pnp_next(rom, pnp);
403 }
Kevin O'Connor714325c2008-11-01 20:32:27 -0400404 }
405}
406
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500407
408/****************************************************************
409 * VGA init
410 ****************************************************************/
411
Kevin O'Connor714325c2008-11-01 20:32:27 -0400412// Call into vga code to turn on console.
413void
414vga_setup()
415{
Kevin O'Connore7739302009-07-26 19:16:09 -0400416 VGAbdf = -1;
417 RomEnd = BUILD_ROM_START;
418
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500419 if (! CONFIG_OPTIONROMS)
420 return;
421
Kevin O'Connor714325c2008-11-01 20:32:27 -0400422 dprintf(1, "Scan for VGA option rom\n");
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500423
424 if (CONFIG_OPTIONROMS_DEPLOYED) {
425 // Option roms are already deployed on the system.
Kevin O'Connore7739302009-07-26 19:16:09 -0400426 init_optionrom((void*)BUILD_ROM_START, 0, 1);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500427 } else {
428 // Find and deploy PCI VGA rom.
Kevin O'Connor04eece22009-07-19 19:05:30 -0400429 int bdf = VGAbdf = pci_find_vga();
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400430 if (bdf >= 0)
431 init_pcirom(bdf, 1);
Kevin O'Connor09880da2009-06-17 20:35:41 -0400432
433 // Find and deploy CBFS vga-style roms not associated with a device.
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400434 run_cbfs_roms("vgaroms/", 1);
435 }
436
Kevin O'Connore7739302009-07-26 19:16:09 -0400437 if (RomEnd == BUILD_ROM_START) {
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400438 // No VGA rom found
Kevin O'Connore7739302009-07-26 19:16:09 -0400439 RomEnd += OPTION_ROM_ALIGN;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400440 return;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500441 }
Kevin O'Connor714325c2008-11-01 20:32:27 -0400442
443 dprintf(1, "Turning on vga console\n");
444 struct bregs br;
445 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -0400446 br.flags = F_IF;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400447 br.ax = 0x0003;
448 call16_int(0x10, &br);
449
450 // Write to screen.
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400451 printf("Starting SeaBIOS (version %s)\n\n", VERSION);
Kevin O'Connor714325c2008-11-01 20:32:27 -0400452}
Kevin O'Connord282af72009-07-04 04:10:32 -0400453
454void
455s3_resume_vga_init()
456{
457 if (!CONFIG_S3_RESUME_VGA_INIT)
458 return;
Kevin O'Connore7739302009-07-26 19:16:09 -0400459 struct rom_header *rom = (void*)BUILD_ROM_START;
Kevin O'Connord282af72009-07-04 04:10:32 -0400460 if (! is_valid_rom(rom))
461 return;
462 callrom(rom, 0);
463}