[SeaBIOS] [PATCH v2 1/4] pci: add two-pass pci initialization code

Kevin O'Connor kevin at koconnor.net
Mon Jul 4 18:07:39 CEST 2011


On Mon, Jul 04, 2011 at 12:59:09PM +0200, Gerd Hoffmann wrote:
> This patch adds a second device scan to the pci initialization, which
> counts the memory bars of the various sizes and types.  Then it
> calculates the sizes and the packing of the prefetchable and
> non-prefetchable pci memory windows and prints the results.
> 
> The patch doesn't actually map the devices to make debugging easier.

Looks like the patch has a couple of minor issues (see below).  But,
otherwise I'm okay with it.  I'll commit it if there are no further
comments.

> +static struct pci_bus {
> +    struct {
> +        /* pci region stats */
> +        u32 count[32 - PCI_MEM_INDEX_SHIFT];
> +        u32 sum, max;
> +        /* seconday bus region sizes */
> +        u32 size;
> +        /* pci region assignments */
> +        u32 bases[32 - PCI_MEM_INDEX_SHIFT];
> +        u32 base;
> +    } r[PCI_REGION_TYPE_COUNT];
> +} *busses;

Having bus->r[x] and dev->r[x] is a bit confusing.  Maybe rename
dev->r to dev->bars?

[...]
@@ -440,6 +508,223 @@ pci_bios_init_bus(void)
 {       
     u8 pci_bus = 0;
     pci_bios_init_bus_rec(0 /* host bus */, &pci_bus);
+    busses_count = pci_bus + 1;
+    busses = malloc_tmphigh(busses_count * sizeof(struct pci_bus));
+}       

You should be able to move this to after pci_probe() and do:

busses = malloc_tmp(sizeof(*buses) * (MaxPCIBus + 1));

Note, if you use malloc_tmphigh, then "qemu -m 1" wont boot.

[...]
> +static void pci_bios_check_device(struct pci_bus *bus, struct pci_device *dev)
> +{
> +    u16 bdf = dev->bdf;
> +    u32 limit;
> +    int i,type;
> +
> +    if (dev->class == PCI_CLASS_BRIDGE_PCI) {
> +        if (dev->secondary_bus >= busses_count) {
> +            /* should never trigger */
> +            dprintf(1, "PCI: bus count too small (%d), skipping bus #%d\n",
> +                    busses_count, dev->secondary_bus);
> +            return;
> +        }
> +        struct pci_bus *s = busses + dev->secondary_bus;
> +        pci_bios_check_device_in_bus(dev->secondary_bus);
> +        for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
> +            s->r[type].size = pci_size_roundup(s->r[type].sum);

Out of curiosity - is this pci_size_roundup() needed?  You wont get
the best memory usage this way.

[...]
> +static void pci_bios_map_device_in_bus(int bus)
> +{
> +    struct pci_device *pci;
> +
> +    foreachpci(pci) {
> +        if (pci->rootbus != bus)
> +            continue;

rootbus isn't correct here.

[...]
> +    /* matches acpi-dsdt.dsl */
> +    u32 start = 0xe0000000;
> +    u32 end   = BUILD_IOAPIC_ADDR;

This should use BUILD_PCIMEM_START instead of 0xe0000000.  If there is
a change from 0xf0000000 to 0xe0000000 it should be in a separate
patch.

-Kevin



More information about the SeaBIOS mailing list