]> xenbits.xensource.com Git - seabios.git/commitdiff
fix low bits in ROM and I/O sizing
authorKevin O'Connor <kevin@koconnor.net>
Wed, 14 Oct 2009 23:28:04 +0000 (19:28 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 14 Oct 2009 23:28:04 +0000 (19:28 -0400)
This cleans up handling of low bits during BAR sizing,
to match PCI spec requirements, and to use symbolic
constants from pci_regs.h

Issues fixed:
For ROM BARs, bit 0 is writeable (enable bit), which we not
only don't want to set, but it will stick and make us think
it's an I/O port resource.
Further, PCI spec defines the following bits as reserved:
- bit 1 in I/O BAR
- bits 10:1 in ROM BAR
and we should be careful and preserve any values there,
and should ignore anything we read from these registers.
Bits 3:2 in I/O BAR might be writeable, so it
is wrong to mask them when calculating BAR size.

Spec references:
See 6.2.5.1 for I/O and memory, and 6.2.5.2 for ROM,
6.1 for reserved bit handling;
pages 225, 228 and 214 in PCI spec revision 3.0.

See also Qemu pcbios commit 6ddb9f5c742b2b82b1755d7ec2a127f6e20e3806

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
src/pciinit.c

index 71177bca8011e0dce613ef62d2aae8d0de884a3e..39c8f0faa0e10e5cbbe6170434237d5377420ee2 100644 (file)
@@ -126,16 +126,28 @@ static void pci_bios_init_device(u16 bdf)
         /* default memory mappings */
         for (i = 0; i < PCI_NUM_REGIONS; i++) {
             int ofs;
-            u32 val, size;
-
+            u32 old, val, mask, size;
             if (i == PCI_ROM_SLOT)
                 ofs = PCI_ROM_ADDRESS;
             else
                 ofs = PCI_BASE_ADDRESS_0 + i * 4;
-            pci_config_writel(bdf, ofs, 0xffffffff);
+
+            old = pci_config_readl(bdf, ofs);
+            if (i == PCI_ROM_SLOT) {
+                mask = PCI_ROM_ADDRESS_MASK;
+                pci_config_writel(bdf, ofs, mask);
+            } else {
+                if (val & PCI_BASE_ADDRESS_SPACE_IO)
+                    mask = PCI_BASE_ADDRESS_IO_MASK;
+                else
+                    mask = PCI_BASE_ADDRESS_MEM_MASK;
+                pci_config_writel(bdf, ofs, ~0);
+            }
             val = pci_config_readl(bdf, ofs);
+            pci_config_writel(bdf, ofs, old);
+
             if (val != 0) {
-                size = (~(val & ~0xf)) + 1;
+                size = (~(val & mask)) + 1;
                 if (val & PCI_BASE_ADDRESS_SPACE_IO)
                     paddr = &pci_bios_io_addr;
                 else if (size >= 0x04000000)