blob: 092393a56c413b82e2f5cd085c151b0761692fb8 [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
Kevin O'Connor2d2fa312013-09-14 21:55:26 -04008#include "bregs.h" // struct bregs
9#include "config.h" // CONFIG_*
10#include "farptr.h" // FLATPTR_TO_SEG
Kevin O'Connor4d8510c2016-02-03 01:28:20 -050011#include "hw/pci.h" // pci_config_readl
12#include "hw/pcidevice.h" // foreachpci
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040013#include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA
14#include "hw/pci_regs.h" // PCI_ROM_ADDRESS
Kevin O'Connor9dea5902013-09-14 20:23:54 -040015#include "malloc.h" // rom_confirm
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040016#include "output.h" // dprintf
Kevin O'Connor41639f82013-09-14 19:37:36 -040017#include "romfile.h" // romfile_loadint
Kevin O'Connor3df600b2013-09-14 19:28:55 -040018#include "stacks.h" // farcall16big
Kevin O'Connor8fb3a5e2013-09-14 22:27:14 -040019#include "std/optionrom.h" // struct rom_header
Kevin O'Connor4f790aa2013-09-14 23:04:08 -040020#include "std/pnpbios.h" // PNP_SIGNATURE
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040021#include "string.h" // memset
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040022#include "util.h" // get_pnp_offset
Stefan Berger2aff1c12015-05-26 15:48:33 -040023#include "tcgbios.h" // tpm_*
Kevin O'Connorceea03c2008-11-08 21:36:35 -050024
tpearson@raptorengineeringinc.comd23eba62015-02-17 15:04:17 -060025static int EnforceChecksum, S3ResumeVga, RunPCIroms;
26
Kevin O'Connorceea03c2008-11-08 21:36:35 -050027
28/****************************************************************
29 * Helper functions
30 ****************************************************************/
31
Kevin O'Connor714325c2008-11-01 20:32:27 -040032// Execute a given option rom.
33static void
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040034__callrom(struct rom_header *rom, u16 offset, u16 bdf)
Kevin O'Connor714325c2008-11-01 20:32:27 -040035{
Kevin O'Connor35ae7262009-01-19 15:44:44 -050036 u16 seg = FLATPTR_TO_SEG(rom);
Kevin O'Connor91b53a72009-05-05 22:52:09 -040037 dprintf(1, "Running option rom at %04x:%04x\n", seg, offset);
Kevin O'Connor714325c2008-11-01 20:32:27 -040038
39 struct bregs br;
40 memset(&br, 0, sizeof(br));
Kevin O'Connorf8e800d2009-09-24 21:01:16 -040041 br.flags = F_IF;
Kevin O'Connorceea03c2008-11-08 21:36:35 -050042 br.ax = bdf;
Kevin O'Connor714325c2008-11-01 20:32:27 -040043 br.bx = 0xffff;
44 br.dx = 0xffff;
45 br.es = SEG_BIOS;
Kevin O'Connor0c3068d2008-12-21 17:51:36 -050046 br.di = get_pnp_offset();
Kevin O'Connor9f985422009-09-09 11:34:39 -040047 br.code = SEGOFF(seg, offset);
Kevin O'Connorad901592009-12-13 11:25:25 -050048 start_preempt();
Kevin O'Connorc7ffbac2012-03-25 11:04:10 -040049 farcall16big(&br);
Kevin O'Connorad901592009-12-13 11:25:25 -050050 finish_preempt();
Kevin O'Connor714325c2008-11-01 20:32:27 -040051}
52
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040053// Execute a given option rom at the standard entry vector.
David Woodhouse5c8dd962013-01-25 19:31:47 -060054void
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040055callrom(struct rom_header *rom, u16 bdf)
56{
57 __callrom(rom, OPTION_ROM_INITVECTOR, bdf);
58}
59
Kevin O'Connor0a924122009-02-08 19:43:47 -050060// Execute a BCV option rom registered via add_bcv().
61void
62call_bcv(u16 seg, u16 ip)
63{
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040064 __callrom(MAKE_FLATPTR(seg, 0), ip, 0);
Kevin O'Connor0a924122009-02-08 19:43:47 -050065}
66
Kevin O'Connorceea03c2008-11-08 21:36:35 -050067// Verify that an option rom looks valid
68static int
69is_valid_rom(struct rom_header *rom)
70{
Kevin O'Connorc36273f2009-04-16 20:43:07 -040071 dprintf(6, "Checking rom %p (sig %x size %d)\n"
72 , rom, rom->signature, rom->size);
Kevin O'Connorceea03c2008-11-08 21:36:35 -050073 if (rom->signature != OPTION_ROM_SIGNATURE)
74 return 0;
Kevin O'Connor674e4602009-04-13 19:19:22 -040075 if (! rom->size)
76 return 0;
Kevin O'Connorceea03c2008-11-08 21:36:35 -050077 u32 len = rom->size * 512;
Kevin O'Connor94fd47e2009-02-15 15:21:10 -050078 u8 sum = checksum(rom, len);
Kevin O'Connorceea03c2008-11-08 21:36:35 -050079 if (sum != 0) {
80 dprintf(1, "Found option rom with bad checksum: loc=%p len=%d sum=%x\n"
81 , rom, len, sum);
Kevin O'Connore010d852011-07-05 20:47:35 -040082 if (EnforceChecksum)
Kevin O'Connorcc975642011-03-06 19:22:46 -050083 return 0;
Kevin O'Connorceea03c2008-11-08 21:36:35 -050084 }
85 return 1;
86}
87
88// Check if a valid option rom has a pnp struct; return it if so.
89static struct pnp_data *
90get_pnp_rom(struct rom_header *rom)
91{
Kevin O'Connore8f00ee2009-07-04 04:04:36 -040092 struct pnp_data *pnp = (void*)((u8*)rom + rom->pnpoffset);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -050093 if (pnp->signature != PNP_SIGNATURE)
Kevin O'Connorceea03c2008-11-08 21:36:35 -050094 return NULL;
95 return pnp;
96}
97
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -050098// Check for multiple pnp option rom headers.
99static struct pnp_data *
100get_pnp_next(struct rom_header *rom, struct pnp_data *pnp)
101{
102 if (! pnp->nextoffset)
103 return NULL;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400104 pnp = (void*)((u8*)rom + pnp->nextoffset);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500105 if (pnp->signature != PNP_SIGNATURE)
Kevin O'Connor3f57b5c2008-12-20 23:32:16 -0500106 return NULL;
107 return pnp;
108}
109
Kevin O'Connor62eea672008-12-06 11:57:45 -0500110// Check if a valid option rom has a pci struct; return it if so.
111static struct pci_data *
112get_pci_rom(struct rom_header *rom)
113{
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400114 struct pci_data *pd = (void*)((u32)rom + rom->pcioffset);
115 if (pd->signature != PCI_ROM_SIGNATURE)
Kevin O'Connor62eea672008-12-06 11:57:45 -0500116 return NULL;
Kevin O'Connor97dce0f2013-02-15 22:46:09 -0500117 if (rom->pcioffset & 3)
118 dprintf(1, "WARNING! Found unaligned PCI rom (vd=%04x:%04x)\n"
119 , pd->vendor, pd->device);
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400120 return pd;
Kevin O'Connor62eea672008-12-06 11:57:45 -0500121}
122
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400123// Run rom init code and note rom size.
124static int
125init_optionrom(struct rom_header *rom, u16 bdf, int isvga)
126{
127 if (! is_valid_rom(rom))
128 return -1;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400129 struct rom_header *newrom = rom_reserve(rom->size * 512);
130 if (!newrom) {
131 warn_noalloc();
132 return -1;
133 }
134 if (newrom != rom)
135 memmove(newrom, rom, rom->size * 512);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400136
Stefan Berger5deeec12015-06-09 19:56:33 -0400137 tpm_option_rom(newrom, rom->size * 512);
138
Kevin O'Connor5e019082012-05-20 21:11:43 -0400139 if (isvga || get_pnp_rom(newrom))
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400140 // Only init vga and PnP roms here.
Kevin O'Connor5e019082012-05-20 21:11:43 -0400141 callrom(newrom, bdf);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400142
Kevin O'Connor5e019082012-05-20 21:11:43 -0400143 return rom_confirm(newrom->size * 512);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400144}
145
Kevin O'Connorbca3a872010-12-24 14:42:42 -0500146#define RS_PCIROM (1LL<<33)
147
148static void
149setRomSource(u64 *sources, struct rom_header *rom, u64 source)
150{
151 if (sources)
152 sources[((u32)rom - BUILD_ROM_START) / OPTION_ROM_ALIGN] = source;
153}
154
Kevin O'Connor031ef552010-12-27 19:26:57 -0500155static int
156getRomPriority(u64 *sources, struct rom_header *rom, int instance)
157{
158 u64 source = sources[((u32)rom - BUILD_ROM_START) / OPTION_ROM_ALIGN];
159 if (!source)
160 return -1;
161 if (source & RS_PCIROM)
Kevin O'Connorfce91892011-07-09 14:47:47 -0400162 return bootprio_find_pci_rom((void*)(u32)source, instance);
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400163 struct romfile_s *file = (void*)(u32)source;
164 return bootprio_find_named_rom(file->name, instance);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500165}
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400166
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400167
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400168/****************************************************************
169 * Roms in CBFS
170 ****************************************************************/
171
Kevin O'Connor5e019082012-05-20 21:11:43 -0400172static struct rom_header *
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400173deploy_romfile(struct romfile_s *file)
Kevin O'Connor5e019082012-05-20 21:11:43 -0400174{
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400175 u32 size = file->size;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400176 struct rom_header *rom = rom_reserve(size);
177 if (!rom) {
178 warn_noalloc();
179 return NULL;
180 }
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400181 int ret = file->copy(file, rom, size);
Kevin O'Connor5e019082012-05-20 21:11:43 -0400182 if (ret <= 0)
183 return NULL;
184 return rom;
185}
186
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400187// Run all roms in a given CBFS directory.
188static void
Kevin O'Connorbca3a872010-12-24 14:42:42 -0500189run_file_roms(const char *prefix, int isvga, u64 *sources)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400190{
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400191 struct romfile_s *file = NULL;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400192 for (;;) {
Kevin O'Connore2304262010-06-13 16:05:17 -0400193 file = romfile_findprefix(prefix, file);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400194 if (!file)
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400195 break;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400196 struct rom_header *rom = deploy_romfile(file);
197 if (rom) {
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400198 setRomSource(sources, rom, (u32)file);
Kevin O'Connorbca3a872010-12-24 14:42:42 -0500199 init_optionrom(rom, 0, isvga);
200 }
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400201 }
202}
203
204
205/****************************************************************
206 * PCI roms
207 ****************************************************************/
208
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400209// Verify device is a vga device with legacy address decoding enabled.
Alex Williamson7adfd712013-03-20 10:58:47 -0600210int
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400211is_pci_vga(struct pci_device *pci)
212{
213 if (pci->class != PCI_CLASS_DISPLAY_VGA)
214 return 0;
215 u16 cmd = pci_config_readw(pci->bdf, PCI_COMMAND);
216 if (!(cmd & PCI_COMMAND_IO && cmd & PCI_COMMAND_MEMORY))
217 return 0;
218 while (pci->parent) {
219 pci = pci->parent;
220 u32 ctrl = pci_config_readb(pci->bdf, PCI_BRIDGE_CONTROL);
221 if (!(ctrl & PCI_BRIDGE_CTL_VGA))
222 return 0;
223 }
224 return 1;
225}
226
Kevin O'Connor5e019082012-05-20 21:11:43 -0400227// Copy a rom to its permanent location below 1MiB
228static struct rom_header *
229copy_rom(struct rom_header *rom)
230{
231 u32 romsize = rom->size * 512;
232 struct rom_header *newrom = rom_reserve(romsize);
233 if (!newrom) {
234 warn_noalloc();
235 return NULL;
236 }
237 dprintf(4, "Copying option rom (size %d) from %p to %p\n"
238 , romsize, rom, newrom);
239 iomemcpy(newrom, rom, romsize);
240 return newrom;
241}
242
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500243// Map the option rom of a given PCI device.
244static struct rom_header *
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400245map_pcirom(struct pci_device *pci)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500246{
Kevin O'Connor7b673002016-02-03 03:03:15 -0500247 dprintf(6, "Attempting to map option rom on dev %pP\n", pci);
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500248
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400249 if ((pci->header_type & 0x7f) != PCI_HEADER_TYPE_NORMAL) {
250 dprintf(6, "Skipping non-normal pci device (type=%x)\n"
251 , pci->header_type);
Kevin O'Connor62eea672008-12-06 11:57:45 -0500252 return NULL;
253 }
254
Kevin O'Connor7b673002016-02-03 03:03:15 -0500255 u16 bdf = pci->bdf;
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500256 u32 orig = pci_config_readl(bdf, PCI_ROM_ADDRESS);
257 pci_config_writel(bdf, PCI_ROM_ADDRESS, ~PCI_ROM_ADDRESS_ENABLE);
258 u32 sz = pci_config_readl(bdf, PCI_ROM_ADDRESS);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500259
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500260 dprintf(6, "Option rom sizing returned %x %x\n", orig, sz);
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500261 orig &= ~PCI_ROM_ADDRESS_ENABLE;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500262 if (!sz || sz == 0xffffffff)
263 goto fail;
264
Kevin O'Connor64cf2fb2009-04-18 17:01:02 -0400265 if (orig == sz || (u32)(orig + 4*1024*1024) < 20*1024*1024) {
266 // Don't try to map to a pci addresses at its max, in the last
267 // 4MiB of ram, or the first 16MiB of ram.
Kevin O'Connor62eea672008-12-06 11:57:45 -0500268 dprintf(6, "Preset rom address doesn't look valid\n");
269 goto fail;
270 }
271
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500272 // Looks like a rom - enable it.
273 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig | PCI_ROM_ADDRESS_ENABLE);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500274
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400275 struct rom_header *rom = (void*)orig;
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500276 for (;;) {
Kevin O'Connor7b673002016-02-03 03:03:15 -0500277 dprintf(5, "Inspecting possible rom at %p (vd=%04x:%04x bdf=%pP)\n"
278 , rom, pci->vendor, pci->device, pci);
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500279 if (rom->signature != OPTION_ROM_SIGNATURE) {
280 dprintf(6, "No option rom signature (got %x)\n", rom->signature);
281 goto fail;
282 }
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400283 struct pci_data *pd = get_pci_rom(rom);
284 if (! pd) {
Kevin O'Connor62eea672008-12-06 11:57:45 -0500285 dprintf(6, "No valid pci signature found\n");
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500286 goto fail;
287 }
Kevin O'Connor62eea672008-12-06 11:57:45 -0500288
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400289 if (pd->vendor == pci->vendor && pd->device == pci->device
290 && pd->type == PCIROM_CODETYPE_X86)
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500291 // A match
292 break;
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400293 dprintf(6, "Didn't match dev/ven (got %04x:%04x) or type (got %d)\n"
294 , pd->vendor, pd->device, pd->type);
295 if (pd->indicator & 0x80) {
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500296 dprintf(6, "No more images left\n");
297 goto fail;
298 }
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400299 rom = (void*)((u32)rom + pd->ilen * 512);
Kevin O'Connore5a36d52008-11-12 20:10:13 -0500300 }
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500301
Kevin O'Connor5a1b8282008-11-29 20:39:06 -0500302 rom = copy_rom(rom);
303 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500304 return rom;
305fail:
306 // Not valid - restore original and exit.
Kevin O'Connorbe19cdc2008-11-09 15:33:47 -0500307 pci_config_writel(bdf, PCI_ROM_ADDRESS, orig);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500308 return NULL;
309}
310
311// Attempt to map and initialize the option rom on a given PCI device.
Kevin O'Connoreeca36c2015-08-10 15:37:13 -0400312static void
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400313init_pcirom(struct pci_device *pci, int isvga, u64 *sources)
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500314{
Kevin O'Connor7b673002016-02-03 03:03:15 -0500315 dprintf(4, "Attempting to init PCI bdf %pP (vd %04x:%04x)\n"
316 , pci, pci->vendor, pci->device);
Kevin O'Connoreeca36c2015-08-10 15:37:13 -0400317
318 char fname[17];
319 snprintf(fname, sizeof(fname), "pci%04x,%04x.rom"
320 , pci->vendor, pci->device);
321 struct romfile_s *file = romfile_find(fname);
322 struct rom_header *rom = NULL;
323 if (file)
324 rom = deploy_romfile(file);
325 else if (RunPCIroms > 1 || (RunPCIroms == 1 && isvga))
Kevin O'Connor862d5fb2011-06-20 22:19:17 -0400326 rom = map_pcirom(pci);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500327 if (! rom)
328 // No ROM present.
Kevin O'Connoreeca36c2015-08-10 15:37:13 -0400329 return;
Kevin O'Connorfce91892011-07-09 14:47:47 -0400330 setRomSource(sources, rom, RS_PCIROM | (u32)pci);
Kevin O'Connor7b673002016-02-03 03:03:15 -0500331 init_optionrom(rom, pci->bdf, isvga);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500332}
333
334
335/****************************************************************
336 * Non-VGA option rom init
337 ****************************************************************/
338
339void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500340optionrom_setup(void)
Kevin O'Connor714325c2008-11-01 20:32:27 -0400341{
342 if (! CONFIG_OPTIONROMS)
343 return;
344
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500345 dprintf(1, "Scan for option roms\n");
Kevin O'Connorbca3a872010-12-24 14:42:42 -0500346 u64 sources[(BUILD_BIOS_ADDR - BUILD_ROM_START) / OPTION_ROM_ALIGN];
347 memset(sources, 0, sizeof(sources));
Kevin O'Connor5e019082012-05-20 21:11:43 -0400348 u32 post_vga = rom_get_last();
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500349
Kevin O'Connor9d691ac2016-04-01 14:23:36 -0400350 // Find and deploy PCI roms.
351 struct pci_device *pci;
352 foreachpci(pci) {
353 if (pci->class == PCI_CLASS_DISPLAY_VGA || pci->have_driver)
354 continue;
355 init_pcirom(pci, 0, sources);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500356 }
Kevin O'Connor9d691ac2016-04-01 14:23:36 -0400357
358 // Find and deploy CBFS roms not associated with a device.
359 run_file_roms("genroms/", 0, sources);
Kevin O'Connor5e019082012-05-20 21:11:43 -0400360 rom_reserve(0);
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500361
362 // All option roms found and deployed - now build BEV/BCV vectors.
363
364 u32 pos = post_vga;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400365 while (pos < rom_get_last()) {
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400366 struct rom_header *rom = (void*)pos;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500367 if (! is_valid_rom(rom)) {
368 pos += OPTION_ROM_ALIGN;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400369 continue;
370 }
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500371 pos += ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
372 struct pnp_data *pnp = get_pnp_rom(rom);
373 if (! pnp) {
Kevin O'Connor0a924122009-02-08 19:43:47 -0500374 // Legacy rom.
Kevin O'Connor031ef552010-12-27 19:26:57 -0500375 boot_add_bcv(FLATPTR_TO_SEG(rom), OPTION_ROM_INITVECTOR, 0
376 , getRomPriority(sources, rom, 0));
Kevin O'Connor714325c2008-11-01 20:32:27 -0400377 continue;
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500378 }
Kevin O'Connor1e157252012-01-14 11:55:35 -0500379 // PnP rom - check for BEV and BCV boot capabilities.
380 int instance = 0;
381 while (pnp) {
382 if (pnp->bev)
383 boot_add_bev(FLATPTR_TO_SEG(rom), pnp->bev, pnp->productname
384 , getRomPriority(sources, rom, instance++));
385 else if (pnp->bcv)
Kevin O'Connor031ef552010-12-27 19:26:57 -0500386 boot_add_bcv(FLATPTR_TO_SEG(rom), pnp->bcv, pnp->productname
387 , getRomPriority(sources, rom, instance++));
Kevin O'Connor1e157252012-01-14 11:55:35 -0500388 else
389 break;
390 pnp = get_pnp_next(rom, pnp);
Kevin O'Connor031ef552010-12-27 19:26:57 -0500391 }
Kevin O'Connor714325c2008-11-01 20:32:27 -0400392 }
393}
394
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500395
396/****************************************************************
397 * VGA init
398 ****************************************************************/
399
Kevin O'Connor422263d2011-07-05 20:56:07 -0400400int ScreenAndDebug;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400401struct rom_header *VgaROM;
Kevin O'Connor8b0c5092011-07-05 20:50:32 -0400402
Kevin O'Connor714325c2008-11-01 20:32:27 -0400403// Call into vga code to turn on console.
404void
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500405vgarom_setup(void)
Kevin O'Connor714325c2008-11-01 20:32:27 -0400406{
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500407 if (! CONFIG_OPTIONROMS)
408 return;
409
Kevin O'Connor714325c2008-11-01 20:32:27 -0400410 dprintf(1, "Scan for VGA option rom\n");
Kevin O'Connorceea03c2008-11-08 21:36:35 -0500411
Kevin O'Connor422263d2011-07-05 20:56:07 -0400412 // Load some config settings that impact VGA.
Kevin O'Connore010d852011-07-05 20:47:35 -0400413 EnforceChecksum = romfile_loadint("etc/optionroms-checksum", 1);
Kevin O'Connor897fb112013-02-07 23:32:48 -0500414 S3ResumeVga = romfile_loadint("etc/s3-resume-vga-init", CONFIG_QEMU);
tpearson@raptorengineeringinc.comd23eba62015-02-17 15:04:17 -0600415 RunPCIroms = romfile_loadint("etc/pci-optionrom-exec", 2);
Kevin O'Connor422263d2011-07-05 20:56:07 -0400416 ScreenAndDebug = romfile_loadint("etc/screen-and-debug", 1);
Kevin O'Connore010d852011-07-05 20:47:35 -0400417
Kevin O'Connor9d691ac2016-04-01 14:23:36 -0400418 // Clear option rom memory
419 memset((void*)BUILD_ROM_START, 0, rom_get_max() - BUILD_ROM_START);
Kevin O'Connore8264652010-09-15 22:06:19 -0400420
Kevin O'Connor9d691ac2016-04-01 14:23:36 -0400421 // Find and deploy PCI VGA rom.
422 struct pci_device *pci;
423 foreachpci(pci) {
424 if (!is_pci_vga(pci))
425 continue;
426 vgahook_setup(pci);
427 init_pcirom(pci, 1, NULL);
428 break;
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400429 }
Kevin O'Connor9d691ac2016-04-01 14:23:36 -0400430
431 // Find and deploy CBFS vga-style roms not associated with a device.
432 run_file_roms("vgaroms/", 1, NULL);
Kevin O'Connor5e019082012-05-20 21:11:43 -0400433 rom_reserve(0);
Kevin O'Connore8f00ee2009-07-04 04:04:36 -0400434
Gerd Hoffmannd6728f32017-09-18 10:47:23 +0200435 if (rom_get_last() != BUILD_ROM_START)
436 // VGA rom found
437 VgaROM = (void*)BUILD_ROM_START;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400438}
Kevin O'Connord282af72009-07-04 04:10:32 -0400439
440void
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500441s3_resume_vga(void)
Kevin O'Connord282af72009-07-04 04:10:32 -0400442{
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500443 if (!S3ResumeVga)
Kevin O'Connord282af72009-07-04 04:10:32 -0400444 return;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400445 if (!VgaROM || ! is_valid_rom(VgaROM))
Kevin O'Connord282af72009-07-04 04:10:32 -0400446 return;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400447 callrom(VgaROM, 0);
Kevin O'Connord282af72009-07-04 04:10:32 -0400448}