Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 1 | // 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'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 7 | |
| 8 | #include "bregs.h" // struct bregs |
Kevin O'Connor | 35ae726 | 2009-01-19 15:44:44 -0500 | [diff] [blame] | 9 | #include "farptr.h" // FLATPTR_TO_SEG |
Kevin O'Connor | c659fde | 2008-12-28 23:43:20 -0500 | [diff] [blame] | 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 11 | #include "util.h" // dprintf |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 12 | #include "pci.h" // pci_find_class |
| 13 | #include "pci_regs.h" // PCI_ROM_ADDRESS |
| 14 | #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA |
Kevin O'Connor | c659fde | 2008-12-28 23:43:20 -0500 | [diff] [blame] | 15 | #include "boot.h" // IPL |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 16 | |
| 17 | |
| 18 | /**************************************************************** |
| 19 | * Definitions |
| 20 | ****************************************************************/ |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 21 | |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 22 | struct 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 | |
| 31 | struct 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 | |
| 47 | struct 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'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 67 | #define OPTION_ROM_START 0xc0000 |
| 68 | #define OPTION_ROM_SIGNATURE 0xaa55 |
| 69 | #define OPTION_ROM_ALIGN 2048 |
| 70 | #define OPTION_ROM_INITVECTOR offsetof(struct rom_header, initVector[0]) |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 71 | #define PCI_ROM_SIGNATURE 0x52494350 // PCIR |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 72 | #define PCIROM_CODETYPE_X86 0 |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 73 | |
| 74 | // Next available position for an option rom. |
| 75 | static u32 next_rom; |
| 76 | |
| 77 | |
| 78 | /**************************************************************** |
| 79 | * Helper functions |
| 80 | ****************************************************************/ |
| 81 | |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 82 | // Execute a given option rom. |
| 83 | static void |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 84 | callrom(struct rom_header *rom, u16 offset, u16 bdf) |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 85 | { |
Kevin O'Connor | 35ae726 | 2009-01-19 15:44:44 -0500 | [diff] [blame] | 86 | u16 seg = FLATPTR_TO_SEG(rom); |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 87 | dprintf(1, "Running option rom at %x:%x\n", seg, offset); |
| 88 | |
| 89 | struct bregs br; |
| 90 | memset(&br, 0, sizeof(br)); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 91 | br.ax = bdf; |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 92 | br.bx = 0xffff; |
| 93 | br.dx = 0xffff; |
| 94 | br.es = SEG_BIOS; |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 95 | br.di = get_pnp_offset(); |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 96 | br.cs = seg; |
| 97 | br.ip = offset; |
Kevin O'Connor | 6e5b4a4 | 2008-12-06 13:03:52 -0500 | [diff] [blame] | 98 | call16big(&br); |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 99 | |
| 100 | debug_serial_setup(); |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 103 | // Execute a BCV option rom registered via add_bcv(). |
| 104 | void |
| 105 | call_bcv(u16 seg, u16 ip) |
| 106 | { |
| 107 | callrom(MAKE_FLATPTR(seg, 0), ip, 0); |
| 108 | } |
| 109 | |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 110 | // Verify that an option rom looks valid |
| 111 | static int |
| 112 | is_valid_rom(struct rom_header *rom) |
| 113 | { |
| 114 | if (rom->signature != OPTION_ROM_SIGNATURE) |
| 115 | return 0; |
| 116 | u32 len = rom->size * 512; |
Kevin O'Connor | 94fd47e | 2009-02-15 15:21:10 -0500 | [diff] [blame] | 117 | u8 sum = checksum(rom, len); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 118 | if (sum != 0) { |
| 119 | dprintf(1, "Found option rom with bad checksum: loc=%p len=%d sum=%x\n" |
| 120 | , rom, len, sum); |
| 121 | return 0; |
| 122 | } |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | // Check if a valid option rom has a pnp struct; return it if so. |
| 127 | static struct pnp_data * |
| 128 | get_pnp_rom(struct rom_header *rom) |
| 129 | { |
| 130 | struct pnp_data *pnp = (struct pnp_data *)((u8*)rom + rom->pnpoffset); |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 131 | if (pnp->signature != PNP_SIGNATURE) |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 132 | return NULL; |
| 133 | return pnp; |
| 134 | } |
| 135 | |
Kevin O'Connor | 3f57b5c | 2008-12-20 23:32:16 -0500 | [diff] [blame] | 136 | // Check for multiple pnp option rom headers. |
| 137 | static struct pnp_data * |
| 138 | get_pnp_next(struct rom_header *rom, struct pnp_data *pnp) |
| 139 | { |
| 140 | if (! pnp->nextoffset) |
| 141 | return NULL; |
| 142 | pnp = (struct pnp_data *)((u8*)rom + pnp->nextoffset); |
Kevin O'Connor | 0c3068d | 2008-12-21 17:51:36 -0500 | [diff] [blame] | 143 | if (pnp->signature != PNP_SIGNATURE) |
Kevin O'Connor | 3f57b5c | 2008-12-20 23:32:16 -0500 | [diff] [blame] | 144 | return NULL; |
| 145 | return pnp; |
| 146 | } |
| 147 | |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 148 | // Check if a valid option rom has a pci struct; return it if so. |
| 149 | static struct pci_data * |
| 150 | get_pci_rom(struct rom_header *rom) |
| 151 | { |
| 152 | struct pci_data *pci = (struct pci_data *)((u32)rom + rom->pcioffset); |
| 153 | if (pci->signature != PCI_ROM_SIGNATURE) |
| 154 | return NULL; |
| 155 | return pci; |
| 156 | } |
| 157 | |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 158 | // Copy a rom to its permanent location below 1MiB |
| 159 | static struct rom_header * |
| 160 | copy_rom(struct rom_header *rom) |
| 161 | { |
| 162 | u32 romsize = rom->size * 512; |
| 163 | if (next_rom + romsize > BUILD_BIOS_ADDR) { |
| 164 | // Option rom doesn't fit. |
| 165 | dprintf(1, "Option rom %p doesn't fit.\n", rom); |
| 166 | return NULL; |
| 167 | } |
| 168 | dprintf(4, "Copying option rom from %p to %x\n", rom, next_rom); |
| 169 | memcpy((void*)next_rom, rom, romsize); |
| 170 | return (struct rom_header *)next_rom; |
| 171 | } |
| 172 | |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 173 | // Check if an option rom is at a hardcoded location for a device. |
| 174 | static struct rom_header * |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 175 | lookup_hardcode(u32 vendev) |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 176 | { |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 177 | if (OPTIONROM_VENDEV_1 |
| 178 | && ((OPTIONROM_VENDEV_1 >> 16) |
| 179 | | ((OPTIONROM_VENDEV_1 & 0xffff)) << 16) == vendev) |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 180 | return copy_rom((struct rom_header *)OPTIONROM_MEM_1); |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 181 | if (OPTIONROM_VENDEV_2 |
| 182 | && ((OPTIONROM_VENDEV_2 >> 16) |
| 183 | | ((OPTIONROM_VENDEV_2 & 0xffff)) << 16) == vendev) |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 184 | return copy_rom((struct rom_header *)OPTIONROM_MEM_2); |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 185 | struct rom_header *rom = cb_find_optionrom(vendev); |
| 186 | if (rom) |
| 187 | return copy_rom(rom); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | // Map the option rom of a given PCI device. |
| 192 | static struct rom_header * |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 193 | map_optionrom(u16 bdf, u32 vendev) |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 194 | { |
Kevin O'Connor | e5a36d5 | 2008-11-12 20:10:13 -0500 | [diff] [blame] | 195 | dprintf(6, "Attempting to map option rom on dev %x\n", bdf); |
| 196 | |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 197 | u8 htype = pci_config_readb(bdf, PCI_HEADER_TYPE); |
| 198 | if ((htype & 0x7f) != PCI_HEADER_TYPE_NORMAL) { |
| 199 | dprintf(6, "Skipping non-normal pci device (type=%x)\n", htype); |
| 200 | return NULL; |
| 201 | } |
| 202 | |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 203 | u32 orig = pci_config_readl(bdf, PCI_ROM_ADDRESS); |
| 204 | pci_config_writel(bdf, PCI_ROM_ADDRESS, ~PCI_ROM_ADDRESS_ENABLE); |
| 205 | u32 sz = pci_config_readl(bdf, PCI_ROM_ADDRESS); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 206 | |
Kevin O'Connor | e5a36d5 | 2008-11-12 20:10:13 -0500 | [diff] [blame] | 207 | dprintf(6, "Option rom sizing returned %x %x\n", orig, sz); |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 208 | orig &= ~PCI_ROM_ADDRESS_ENABLE; |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 209 | if (!sz || sz == 0xffffffff) |
| 210 | goto fail; |
| 211 | |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 212 | if (orig < 16*1024*1024) { |
| 213 | dprintf(6, "Preset rom address doesn't look valid\n"); |
| 214 | goto fail; |
| 215 | } |
| 216 | |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 217 | // Looks like a rom - enable it. |
| 218 | pci_config_writel(bdf, PCI_ROM_ADDRESS, orig | PCI_ROM_ADDRESS_ENABLE); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 219 | |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 220 | struct rom_header *rom = (struct rom_header *)orig; |
| 221 | for (;;) { |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 222 | dprintf(5, "Inspecting possible rom at %p (dv=%x bdf=%x)\n" |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 223 | , rom, vendev, bdf); |
| 224 | if (rom->signature != OPTION_ROM_SIGNATURE) { |
| 225 | dprintf(6, "No option rom signature (got %x)\n", rom->signature); |
| 226 | goto fail; |
| 227 | } |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 228 | struct pci_data *pci = get_pci_rom(rom); |
| 229 | if (! pci) { |
| 230 | dprintf(6, "No valid pci signature found\n"); |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 231 | goto fail; |
| 232 | } |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 233 | |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 234 | u32 vd = (pci->device << 16) | pci->vendor; |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 235 | if (vd == vendev && pci->type == PCIROM_CODETYPE_X86) |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 236 | // A match |
| 237 | break; |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 238 | dprintf(6, "Didn't match dev/ven (got %x) or type (got %d)\n" |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 239 | , vd, pci->type); |
| 240 | if (pci->indicator & 0x80) { |
| 241 | dprintf(6, "No more images left\n"); |
| 242 | goto fail; |
| 243 | } |
| 244 | rom = (struct rom_header *)((u32)rom + pci->ilen * 512); |
Kevin O'Connor | e5a36d5 | 2008-11-12 20:10:13 -0500 | [diff] [blame] | 245 | } |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 246 | |
Kevin O'Connor | 5a1b828 | 2008-11-29 20:39:06 -0500 | [diff] [blame] | 247 | rom = copy_rom(rom); |
| 248 | pci_config_writel(bdf, PCI_ROM_ADDRESS, orig); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 249 | return rom; |
| 250 | fail: |
| 251 | // Not valid - restore original and exit. |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 252 | pci_config_writel(bdf, PCI_ROM_ADDRESS, orig); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 253 | return NULL; |
| 254 | } |
| 255 | |
| 256 | // Attempt to map and initialize the option rom on a given PCI device. |
| 257 | static struct rom_header * |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 258 | init_optionrom(u16 bdf) |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 259 | { |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 260 | u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID); |
| 261 | dprintf(4, "Attempting to init PCI bdf %x (dev/ven %x)\n", bdf, vendev); |
| 262 | struct rom_header *rom = lookup_hardcode(vendev); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 263 | if (! rom) |
Kevin O'Connor | 4c0c85a | 2009-04-11 23:31:29 -0400 | [diff] [blame^] | 264 | rom = map_optionrom(bdf, vendev); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 265 | if (! rom) |
| 266 | // No ROM present. |
| 267 | return NULL; |
| 268 | |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 269 | if (! is_valid_rom(rom)) |
| 270 | return NULL; |
| 271 | |
| 272 | if (get_pnp_rom(rom)) |
| 273 | // Init the PnP rom. |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 274 | callrom(rom, OPTION_ROM_INITVECTOR, bdf); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 275 | |
| 276 | next_rom += ALIGN(rom->size * 512, OPTION_ROM_ALIGN); |
| 277 | |
| 278 | return rom; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | /**************************************************************** |
| 283 | * Non-VGA option rom init |
| 284 | ****************************************************************/ |
| 285 | |
| 286 | void |
| 287 | optionrom_setup() |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 288 | { |
| 289 | if (! CONFIG_OPTIONROMS) |
| 290 | return; |
| 291 | |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 292 | dprintf(1, "Scan for option roms\n"); |
| 293 | |
| 294 | u32 post_vga = next_rom; |
| 295 | |
| 296 | if (CONFIG_OPTIONROMS_DEPLOYED) { |
| 297 | // Option roms are already deployed on the system. |
| 298 | u32 pos = next_rom; |
| 299 | while (pos < BUILD_BIOS_ADDR) { |
| 300 | struct rom_header *rom = (struct rom_header *)pos; |
| 301 | if (! is_valid_rom(rom)) { |
| 302 | pos += OPTION_ROM_ALIGN; |
| 303 | continue; |
| 304 | } |
| 305 | if (get_pnp_rom(rom)) |
| 306 | callrom(rom, OPTION_ROM_INITVECTOR, 0); |
| 307 | pos += ALIGN(rom->size * 512, OPTION_ROM_ALIGN); |
| 308 | next_rom = pos; |
| 309 | } |
| 310 | } else { |
| 311 | // Find and deploy PCI roms. |
Kevin O'Connor | e633832 | 2008-11-29 20:31:49 -0500 | [diff] [blame] | 312 | int bdf, max; |
Kevin O'Connor | 4132e02 | 2008-12-04 19:39:10 -0500 | [diff] [blame] | 313 | foreachpci(bdf, max) { |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 314 | u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE); |
Kevin O'Connor | 62eea67 | 2008-12-06 11:57:45 -0500 | [diff] [blame] | 315 | if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA |
| 316 | || (CONFIG_ATA && v == PCI_CLASS_STORAGE_IDE)) |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 317 | continue; |
| 318 | init_optionrom(bdf); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
| 322 | // All option roms found and deployed - now build BEV/BCV vectors. |
| 323 | |
| 324 | u32 pos = post_vga; |
| 325 | while (pos < next_rom) { |
| 326 | struct rom_header *rom = (struct rom_header *)pos; |
| 327 | if (! is_valid_rom(rom)) { |
| 328 | pos += OPTION_ROM_ALIGN; |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 329 | continue; |
| 330 | } |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 331 | pos += ALIGN(rom->size * 512, OPTION_ROM_ALIGN); |
| 332 | struct pnp_data *pnp = get_pnp_rom(rom); |
| 333 | if (! pnp) { |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 334 | // Legacy rom. |
| 335 | add_bcv(FLATPTR_TO_SEG(rom), OPTION_ROM_INITVECTOR, 0); |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 336 | continue; |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 337 | } |
| 338 | // PnP rom. |
| 339 | if (pnp->bev) |
| 340 | // Can boot system - add to IPL list. |
Kevin O'Connor | 9f4e1d9 | 2009-02-08 15:44:08 -0500 | [diff] [blame] | 341 | add_bev(FLATPTR_TO_SEG(rom), pnp->bev, pnp->productname); |
Kevin O'Connor | 3f57b5c | 2008-12-20 23:32:16 -0500 | [diff] [blame] | 342 | else |
| 343 | // Check for BCV (there may be multiple). |
| 344 | while (pnp && pnp->bcv) { |
Kevin O'Connor | 0a92412 | 2009-02-08 19:43:47 -0500 | [diff] [blame] | 345 | add_bcv(FLATPTR_TO_SEG(rom), pnp->bcv, pnp->productname); |
Kevin O'Connor | 3f57b5c | 2008-12-20 23:32:16 -0500 | [diff] [blame] | 346 | pnp = get_pnp_next(rom, pnp); |
| 347 | } |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 351 | |
| 352 | /**************************************************************** |
| 353 | * VGA init |
| 354 | ****************************************************************/ |
| 355 | |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 356 | // Call into vga code to turn on console. |
| 357 | void |
| 358 | vga_setup() |
| 359 | { |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 360 | if (! CONFIG_OPTIONROMS) |
| 361 | return; |
| 362 | |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 363 | dprintf(1, "Scan for VGA option rom\n"); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 364 | next_rom = OPTION_ROM_START; |
| 365 | |
| 366 | if (CONFIG_OPTIONROMS_DEPLOYED) { |
| 367 | // Option roms are already deployed on the system. |
| 368 | struct rom_header *rom = (struct rom_header *)OPTION_ROM_START; |
| 369 | if (! is_valid_rom(rom)) |
| 370 | return; |
| 371 | callrom(rom, OPTION_ROM_INITVECTOR, 0); |
| 372 | next_rom += ALIGN(rom->size * 512, OPTION_ROM_ALIGN); |
| 373 | } else { |
| 374 | // Find and deploy PCI VGA rom. |
Kevin O'Connor | 4132e02 | 2008-12-04 19:39:10 -0500 | [diff] [blame] | 375 | int bdf = pci_find_class(PCI_CLASS_DISPLAY_VGA); |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 376 | if (bdf < 0) |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 377 | // Device not found |
| 378 | return; |
| 379 | |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 380 | struct rom_header *rom = init_optionrom(bdf); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 381 | if (rom && !get_pnp_rom(rom)) |
| 382 | // Call rom even if it isn't a pnp rom. |
Kevin O'Connor | be19cdc | 2008-11-09 15:33:47 -0500 | [diff] [blame] | 383 | callrom(rom, OPTION_ROM_INITVECTOR, bdf); |
Kevin O'Connor | ceea03c | 2008-11-08 21:36:35 -0500 | [diff] [blame] | 384 | } |
Kevin O'Connor | 714325c | 2008-11-01 20:32:27 -0400 | [diff] [blame] | 385 | |
| 386 | dprintf(1, "Turning on vga console\n"); |
| 387 | struct bregs br; |
| 388 | memset(&br, 0, sizeof(br)); |
| 389 | br.ax = 0x0003; |
| 390 | call16_int(0x10, &br); |
| 391 | |
| 392 | // Write to screen. |
| 393 | printf("Starting SeaBIOS\n\n"); |
| 394 | } |