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

Kevin O'Connor kevin at koconnor.net
Sun Jul 3 02:06:10 CEST 2011


On Fri, Jun 24, 2011 at 05:24:35PM +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.

Thanks.

I must admit, I'm having a hard time "wrapping my head around" this
new allocator.

Also, see my comments below.

[...]
> +static struct pci_bus {
> +    /* pci region stats */
> +    u32 io_count[16 - PCI_IO_INDEX_SHIFT];
> +    u32 mem_count[32 - PCI_MEM_INDEX_SHIFT];
> +    u32 prefmem_count[32 - PCI_MEM_INDEX_SHIFT];
> +    u32 io_sum, io_max;
> +    u32 mem_sum, mem_max;
> +    u32 prefmem_sum, prefmem_max;
> +    /* seconday bus region sizes */
> +    u32 io_size, mem_size, prefmem_size;
> +    /* pci region assignments */
> +    u32 io_bases[16 - PCI_IO_INDEX_SHIFT];
> +    u32 mem_bases[32 - PCI_MEM_INDEX_SHIFT];
> +    u32 prefmem_bases[32 - PCI_MEM_INDEX_SHIFT];
> +    u32 io_base, mem_base, prefmem_base;
> +} *busses;

Hrmm - is there an opportunity to define an array of three "region
types" (io, mem, prefmem) instead?  The coreboot PCI assignment code
does this.

[...]
> +static void pci_bios_check_device_in_bus(int bus)
> +{
> +    struct pci_device *pci;
> +
> +    dprintf(1, "PCI: check devices bus %d\n", bus);
> +    foreachpci(pci) {
> +        if (pci->rootbus != bus)

rootbus doesn't look correct here - it's an identifier for independent
root PCI buses - pci_bdf_to_bus(pci->bdf) is likely what you want.

[...]
> +static int pci_bios_init_root_regions(void)
> +{
> +    struct pci_bus *bus = &busses[0];
> +    int h1, h2;
> +
> +    /* io ports */
> +    bus->io_base = 0xc000;
> +
> +    /* try to fit all into one memory hole */
> +    for (h1 = mem_holes_count-1; h1 >= 0; h1--) {
> +        if (bus->mem_sum < bus->prefmem_sum) {

I'm a bit confused by what this code does.  However, tracking a list
of memory regions and filling allocations in those regions is what the
pmm code does.  Can an IO zone be created and addSpace()/pmm_malloc()
be used?

-Kevin



More information about the SeaBIOS mailing list