]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
platform: relax rom scanning alignment for ahci platforms
authorDan Williams <dan.j.williams@intel.com>
Sat, 1 Aug 2009 00:11:41 +0000 (17:11 -0700)
committerDan Williams <dan.j.williams@intel.com>
Sat, 1 Aug 2009 00:11:41 +0000 (17:11 -0700)
The PCI-3.0 Firmware specification allows for option-roms to have
512-byte alignment rather than 2048-byte.  As there does not appear to
be a reliable method to detect a PCI-3.0 compliant BIOS from userspace
we allow the imsm platform detection code to presume that a system
modern enough to have an Intel AHCI controller does not have
dangerous/legacy ISA regions in the option-ROM memory space.

An environment variable to disable this behaviour, IMSM_SAFE_OROM_SCAN,
is added in case this presumption is ever proven wrong.

Reported-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
platform-intel.c
probe_roms.c
probe_roms.h

index 5160227be222e20682ef73d631566c98b4bc018e..eaf4c483d5f95b5547cb61b842002b71488dd13c 100644 (file)
@@ -157,6 +157,7 @@ static int scan(const void *start, const void *end)
 const struct imsm_orom *find_imsm_orom(void)
 {
        static int populated = 0;
+       unsigned long align;
 
        /* it's static data so we only need to read it once */
        if (populated)
@@ -184,7 +185,11 @@ const struct imsm_orom *find_imsm_orom(void)
                return NULL;
 
        /* scan option-rom memory looking for an imsm signature */
-       if (probe_roms_init() != 0)
+       if (check_env("IMSM_SAFE_OROM_SCAN"))
+               align = 2048;
+       else
+               align = 512;
+       if (probe_roms_init(align) != 0)
                return NULL;
        probe_roms();
        populated = scan_adapter_roms(scan);
index 06ec3f5a4485c78e6c8ffc7ccadb65ef2cf57169..a9a86388f394233fd36796e7713ea43ce8d71a2f 100644 (file)
@@ -32,6 +32,8 @@ static void *rom_mem = MAP_FAILED;
 static int rom_fd = -1;
 const static int rom_len = 0xf0000 - 0xc0000; /* option-rom memory region */
 static int _sigbus;
+static unsigned long rom_align;
+
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
 static void sigbus(int sig)
@@ -76,11 +78,20 @@ void probe_roms_exit(void)
        }
 }
 
-int probe_roms_init(void)
+int probe_roms_init(unsigned long align)
 {
        int fd;
        int rc = 0;
 
+       /* valid values are 2048 and 512.  512 is for PCI-3.0 compliant
+        * systems, or systems that do not have dangerous/legacy ISA
+        * devices.  2048 should always be safe
+        */
+       if (align == 512 || align == 2048)
+               rom_align = align;
+       else
+               return -1;
+
        if (signal(SIGBUS, sigbus) == SIG_ERR)
                rc = -1;
        if (rc == 0) {
@@ -208,6 +219,11 @@ int scan_adapter_roms(scan_fn fn)
        return found;
 }
 
+static unsigned long align(unsigned long addr, unsigned long alignment)
+{
+       return (addr + alignment - 1) & ~(alignment - 1);
+}
+
 void probe_roms(void)
 {
        const void *rom;
@@ -220,7 +236,7 @@ void probe_roms(void)
 
        /* video rom */
        upper = adapter_rom_resources[0].start;
-       for (start = video_rom_resource.start; start < upper; start += 2048) {
+       for (start = video_rom_resource.start; start < upper; start += rom_align) {
                rom = isa_bus_to_virt(start);
                if (!romsignature(rom))
                        continue;
@@ -239,7 +255,7 @@ void probe_roms(void)
                break;
        }
 
-       start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
+       start = align(video_rom_resource.end + 1, rom_align);
        if (start < upper)
                start = upper;
 
@@ -255,7 +271,7 @@ void probe_roms(void)
        }
 
        /* check for adapter roms on 2k boundaries */
-       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
+       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += rom_align) {
                rom = isa_bus_to_virt(start);
                if (!romsignature(rom))
                        continue;
@@ -273,7 +289,7 @@ void probe_roms(void)
                adapter_rom_resources[i].start = start;
                adapter_rom_resources[i].end = start + length - 1;
 
-               start = adapter_rom_resources[i++].end & ~2047UL;
+               start = adapter_rom_resources[i++].end & ~(rom_align - 1);
        }
 }
 
index 557e93356905b9e0899f488ac529a76ef1fbc58c..a1e291a10cceaf989553871473eae1677ac83b07 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 void probe_roms_exit(void);
-int probe_roms_init(void);
+int probe_roms_init(unsigned long align);
 typedef int (*scan_fn)(const void *start, const void *end);
 int scan_adapter_roms(scan_fn fn);
 void probe_roms(void);