Change license from GPLv3 to LGPLv3.
[seabios.git] / src / optionroms.c
index 0f99c2ee739e3b291e5aed456cfd6f3028f26bf6..c2a563b56bd8b8e0d162f9e26c8a6ffeb7e5252b 100644 (file)
@@ -3,23 +3,22 @@
 // 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.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "bregs.h" // struct bregs
-#include "biosvar.h" // struct ipl_entry_s
+#include "farptr.h" // FARPTR_TO_SEG
+#include "config.h" // CONFIG_*
 #include "util.h" // dprintf
 #include "pci.h" // pci_find_class
 #include "pci_regs.h" // PCI_ROM_ADDRESS
 #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
+#include "boot.h" // IPL
 
 
 /****************************************************************
  * Definitions
  ****************************************************************/
 
-// $PnP string with special alignment in romlayout.S
-extern char pnp_string[];
-
 struct rom_header {
     u16 signature;
     u8 size;
@@ -93,16 +92,12 @@ callrom(struct rom_header *rom, u16 offset, u16 bdf)
     br.bx = 0xffff;
     br.dx = 0xffff;
     br.es = SEG_BIOS;
-    br.di = (u32)pnp_string - BUILD_BIOS_ADDR;
+    br.di = get_pnp_offset();
     br.cs = seg;
     br.ip = offset;
     call16big(&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));
 }
 
 // Verify that an option rom looks valid
@@ -126,7 +121,19 @@ static struct pnp_data *
 get_pnp_rom(struct rom_header *rom)
 {
     struct pnp_data *pnp = (struct pnp_data *)((u8*)rom + rom->pnpoffset);
-    if (pnp->signature != *(u32*)pnp_string)
+    if (pnp->signature != PNP_SIGNATURE)
+        return NULL;
+    return pnp;
+}
+
+// Check for multiple pnp option rom headers.
+static struct pnp_data *
+get_pnp_next(struct rom_header *rom, struct pnp_data *pnp)
+{
+    if (! pnp->nextoffset)
+        return NULL;
+    pnp = (struct pnp_data *)((u8*)rom + pnp->nextoffset);
+    if (pnp->signature != PNP_SIGNATURE)
         return NULL;
     return pnp;
 }
@@ -145,18 +152,16 @@ get_pci_rom(struct rom_header *rom)
 static void
 add_ipl(struct rom_header *rom, struct pnp_data *pnp)
 {
-#define ebda ((struct extended_bios_data_area_s *)MAKE_FARPTR(SEG_EBDA, 0))
-
     // Found a device that thinks it can boot the system.  Record
     // its BEV and product name string.
 
     if (! CONFIG_BOOT)
         return;
 
-    if (ebda->ipl.count >= ARRAY_SIZE(ebda->ipl.table))
+    if (IPL.count >= ARRAY_SIZE(IPL.table))
         return;
 
-    struct ipl_entry_s *ip = &ebda->ipl.table[ebda->ipl.count];
+    struct ipl_entry_s *ip = &IPL.table[IPL.count];
     ip->type = IPL_TYPE_BEV;
     ip->vector = (FARPTR_TO_SEG(rom) << 16) | pnp->bev;
 
@@ -164,7 +169,7 @@ add_ipl(struct rom_header *rom, struct pnp_data *pnp)
     if (desc)
         ip->description = MAKE_FARPTR(FARPTR_TO_SEG(rom), desc);
 
-    ebda->ipl.count++;
+    IPL.count++;
 }
 
 // Copy a rom to its permanent location below 1MiB
@@ -345,9 +350,13 @@ optionrom_setup()
         if (pnp->bev)
             // Can boot system - add to IPL list.
             add_ipl(rom, pnp);
-        else if (pnp->bcv)
-            // Has BCV - run it now.
-            callrom(rom, pnp->bcv, 0);
+        else
+            // Check for BCV (there may be multiple).
+            while (pnp && pnp->bcv) {
+                // Has BCV - run it now.
+                callrom(rom, pnp->bcv, 0);
+                pnp = get_pnp_next(rom, pnp);
+            }
     }
 }