Changeset 4394

Show
Ignore:
Timestamp:
07/02/09 20:56:24 (8 months ago)
Author:
myles
Message:

Move the v3 resource allocator to v2.

Major changes:
1. Separate resource allocation into:

  1. Read Resources
  2. Avoid fixed resources (constrain limits)
  3. Allocate resources
  4. Set resources

Usage notes:
Resources which have IORESOURCE_FIXED set in the flags constrain the placement
of other resources. All fixed resources will end up outside (above or below)
the allocated resources.

Domains usually start with base = 0 and limit = 2address_bits - 1.

I've added an IOAPIC to all platforms so that the old limit of 0xfec00000 is
still there for resources. Some platforms may want to change that, but I didn't
want to break anyone's board.

Resources are allocated in a single block for memory and another for I/O.
Currently the resource allocator doesn't support holes.

Signed-off-by: Myles Watson <mylesgw@…>
Acked-by: Ronald G. Minnich <rminnich@…>
Acked-by: Patrick Georgi <patrick.georgi@…>

Location:
trunk/coreboot-v2/src
Files:
62 modified

Legend:

Unmodified
Added
Removed
  • trunk/coreboot-v2/src/cpu/amd/sc520/sc520.c

    r3943 r4394  
    6363} 
    6464 
     65static void sc520_read_resources(device_t dev) 
     66{ 
     67        struct resource* res; 
     68 
     69        pci_dev_read_resources(dev); 
     70 
     71        res = new_resource(dev, 1); 
     72        res->base = 0x0UL; 
     73        res->size = 0x400UL; 
     74        res->limit = 0xffffUL; 
     75        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     76 
     77        res = new_resource(dev, 3); /* IOAPIC */ 
     78        res->base = 0xfec00000; 
     79        res->size = 0x00001000; 
     80        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     81} 
     82 
    6583 
    6684static struct device_operations cpu_operations = { 
    67         .read_resources   = pci_dev_read_resources, 
     85        .read_resources   = sc520_read_resources, 
    6886        .set_resources    = pci_dev_set_resources, 
    6987        .enable_resources = sc520_enable_resources, 
     
    7896        .device = 0x3000 
    7997}; 
    80  
    81  
    82  
    83 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    84  
    85 static void pci_domain_read_resources(device_t dev) 
    86 { 
    87         struct resource *resource; 
    88   printk_spew("%s\n", __func__); 
    89         /* Initialize the system wide io space constraints */ 
    90         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    91         resource->limit = 0xffffUL; 
    92         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    93  
    94         /* Initialize the system wide memory resources constraints */ 
    95         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    96         resource->limit = 0xffffffffULL; 
    97         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    98 } 
    9998 
    10099static void ram_resource(device_t dev, unsigned long index, 
     
    185184} 
    186185 
    187 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    188 { 
    189   printk_spew("%s\n", __func__); 
    190         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    191         return max; 
    192 } 
    193  
    194  
    195186#if 0 
    196187void sc520_enable_resources(device_t dev) { 
     
    220211         * function the whole thing will hang in an endless loop on 
    221212         * the ts5300. If this is really needed on another platform, 
    222          * something is conceptionally wrong. 
     213         * something is conceptually wrong. 
    223214         */ 
    224215        .enable_resources = 0, //enable_resources, 
  • trunk/coreboot-v2/src/cpu/emulation/qemu-x86/northbridge.c

    r4381 r4394  
    99#include "chip.h" 
    1010#include "northbridge.h" 
    11  
    12 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    13  
    14 static void pci_domain_read_resources(device_t dev) 
    15 { 
    16         struct resource *resource; 
    17  
    18         /* Initialize the system wide io space constraints */ 
    19         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    20         resource->limit = 0xffffUL; 
    21         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    22  
    23         /* Initialize the system wide memory resources constraints */ 
    24         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    25         resource->limit = 0xffffffffULL; 
    26         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    27 } 
    2811 
    2912static void ram_resource(device_t dev, unsigned long index, 
     
    7154#endif 
    7255 
    73 static void pci_domain_set_resources(device_t dev) 
     56static void cpu_pci_domain_set_resources(device_t dev) 
    7457{ 
    7558        static const uint8_t ramregs[] = { 
     
    128111} 
    129112 
    130 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
     113static void cpu_pci_domain_read_resources(struct device *dev) 
    131114{ 
    132         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    133         return max; 
     115        struct resource *res; 
     116 
     117        pci_domain_read_resources(dev); 
     118 
     119        /* Reserve space for the IOAPIC.  This should be in the Southbridge, 
     120         * but I couldn't tell which device to put it in. */ 
     121        res = new_resource(dev, 2); 
     122        res->base = 0xfec00000UL; 
     123        res->size = 0x100000UL; 
     124        res->limit = 0xffffffffUL; 
     125        res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | 
     126                     IORESOURCE_ASSIGNED; 
     127 
     128        /* Reserve space for the LAPIC.  There's one in every processor, but 
     129         * the space only needs to be reserved once, so we do it here. */ 
     130        res = new_resource(dev, 3); 
     131        res->base = 0xfee00000UL; 
     132        res->size = 0x10000UL; 
     133        res->limit = 0xffffffffUL; 
     134        res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | 
     135                     IORESOURCE_ASSIGNED; 
    134136} 
    135137 
    136138static struct device_operations pci_domain_ops = { 
    137         .read_resources         = pci_domain_read_resources, 
    138         .set_resources          = pci_domain_set_resources, 
     139        .read_resources         = cpu_pci_domain_read_resources, 
     140        .set_resources          = cpu_pci_domain_set_resources, 
    139141        .enable_resources       = enable_childrens_resources, 
    140142        .init                   = 0, 
  • trunk/coreboot-v2/src/cpu/ppc/ppc4xx/pci_domain.c

    r4381 r4394  
    77#include <device/pci_ids.h> 
    88#include <console/console.h> 
    9  
    10 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    11 { 
    12         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    13         return max; 
    14 } 
    15  
    16 static void pci_domain_read_resources(device_t dev) 
    17 { 
    18         struct resource *resource; 
    19  
    20         /* Initialize the system wide io space constraints */ 
    21         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    22         resource->limit = 0xffffUL; 
    23         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    24  
    25         /* Initialize the system wide memory resources constraints */ 
    26         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    27         resource->limit = 0xffffffffULL; 
    28         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    29 } 
    309 
    3110static void ram_resource(device_t dev, unsigned long index, 
  • trunk/coreboot-v2/src/devices/cardbus_device.c

    r3052 r4394  
    7878        if (resource) { 
    7979                min_size = resource->size; 
    80                 compute_allocate_resource(&dev->link[0], resource,  
    81                         resource->flags, resource->flags); 
    8280                /* Allways allocate at least the miniumum size to a 
    8381                 * cardbus bridge in case a new card is plugged in. 
  • trunk/coreboot-v2/src/devices/device.c

    r4271 r4394  
    1313 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) 
    1414 * Copyright (C) 2005-2006 Stefan Reinauer <stepan@openbios.org> 
     15 * Copyright (C) 2009 Myles Watson <mylesgw@gmail.com> 
    1516 */ 
    1617 
     
    4445extern struct device **last_dev_p; 
    4546 
    46 /** The upper limit of MEM resource of the devices. 
    47  * Reserve 20M for the system */ 
    48 #define DEVICE_MEM_HIGH 0xFEBFFFFFUL 
    49 /** The lower limit of IO resource of the devices. 
    50  * Reserve 4k for ISA/Legacy devices */ 
    51 #define DEVICE_IO_START 0x1000 
    5247 
    5348/** 
     
    7267        spin_lock(&dev_lock); 
    7368 
    74         /* Find the last child of our parent */ 
    75         for(child = parent->children; child && child->sibling; ) { 
     69        /* Find the last child of our parent. */ 
     70        for (child = parent->children; child && child->sibling; /* */ ) { 
    7671                child = child->sibling; 
    7772        } 
    7873 
    7974        dev = malloc(sizeof(*dev)); 
    80         if (dev == 0) { 
     75        if (dev == 0) 
    8176                die("DEV: out of memory.\n"); 
    82         } 
     77 
    8378        memset(dev, 0, sizeof(*dev)); 
    8479        memcpy(&dev->path, path, sizeof(*path)); 
    8580 
    86         /* Initialize the back pointers in the link fields */ 
    87         for(link = 0; link < MAX_LINKS; link++) { 
    88                 dev->link[link].dev  = dev; 
     81        /* Initialize the back pointers in the link fields. */ 
     82        for (link = 0; link < MAX_LINKS; link++) { 
     83                dev->link[link].dev = dev; 
    8984                dev->link[link].link = link; 
    9085        } 
    9186 
    92         /* By default devices are enabled */ 
     87        /* By default devices are enabled. */ 
    9388        dev->enabled = 1; 
    9489 
     
    133128        struct device *curdev; 
    134129 
    135         printk_spew("%s read_resources bus %d link: %d\n", 
    136                 dev_path(bus->dev), bus->secondary, bus->link); 
    137  
    138         /* Walk through all of the devices and find which resources they need. */ 
    139         for(curdev = bus->children; curdev; curdev = curdev->sibling) { 
    140                 unsigned links; 
     130        printk_spew("%s %s bus %x link: %d\n", dev_path(bus->dev), __func__, 
     131                    bus->secondary, bus->link); 
     132 
     133        /* Walk through all devices and find which resources they need. */ 
     134        for (curdev = bus->children; curdev; curdev = curdev->sibling) { 
    141135                int i; 
    142                 if (curdev->have_resources) { 
    143                         continue; 
    144                 } 
    145136                if (!curdev->enabled) { 
    146137                        continue; 
     
    148139                if (!curdev->ops || !curdev->ops->read_resources) { 
    149140                        printk_err("%s missing read_resources\n", 
    150                                 dev_path(curdev)); 
     141                                   dev_path(curdev)); 
    151142                        continue; 
    152143                } 
    153144                curdev->ops->read_resources(curdev); 
    154                 curdev->have_resources = 1; 
    155                 /* Read in subtractive resources behind the current device */ 
    156                 links = 0; 
    157                 for(i = 0; i < curdev->resources; i++) { 
    158                         struct resource *resource; 
    159                         unsigned link; 
    160                         resource = &curdev->resource[i]; 
    161                         if (!(resource->flags & IORESOURCE_SUBTRACTIVE)) 
    162                                 continue; 
    163                         link = IOINDEX_SUBTRACTIVE_LINK(resource->index); 
    164                         if (link > MAX_LINKS) { 
    165                                 printk_err("%s subtractive index on link: %d\n", 
    166                                         dev_path(curdev), link); 
    167                                 continue; 
    168                         } 
    169                         if (!(links & (1 << link))) { 
    170                                 links |= (1 << link); 
    171                                 read_resources(&curdev->link[link]); 
    172                         } 
    173                 } 
     145 
     146                /* Read in the resources behind the current device's links. */ 
     147                for (i = 0; i < curdev->links; i++) 
     148                        read_resources(&curdev->link[i]); 
    174149        } 
    175150        printk_spew("%s read_resources bus %d link: %d done\n", 
    176                 dev_path(bus->dev), bus->secondary, bus->link); 
     151                    dev_path(bus->dev), bus->secondary, bus->link); 
    177152} 
    178153 
    179154struct pick_largest_state { 
    180155        struct resource *last; 
    181         struct device   *result_dev; 
     156        struct device *result_dev; 
    182157        struct resource *result; 
    183158        int seen_last; 
    184159}; 
    185160 
    186 static void pick_largest_resource(void *gp, 
    187         struct device *dev, struct resource *resource) 
     161static void pick_largest_resource(void *gp, struct device *dev, 
     162                                  struct resource *resource) 
    188163{ 
    189164        struct pick_largest_state *state = gp; 
    190165        struct resource *last; 
     166 
    191167        last = state->last; 
    192         /* Be certain to pick the successor to last */ 
     168 
     169        /* Be certain to pick the successor to last. */ 
    193170        if (resource == last) { 
    194171                state->seen_last = 1; 
     
    207184            (state->result->align < resource->align) || 
    208185            ((state->result->align == resource->align) && 
    209              (state->result->size < resource->size))) 
    210         { 
     186             (state->result->size < resource->size))) { 
    211187                state->result_dev = dev; 
    212188                state->result = resource; 
     
    214190} 
    215191 
    216 static struct device *largest_resource(struct bus *bus, struct resource **result_res, 
    217         unsigned long type_mask, unsigned long type) 
     192static struct device *largest_resource(struct bus *bus, 
     193                                       struct resource **result_res, 
     194                                       unsigned long type_mask, 
     195                                       unsigned long type) 
    218196{ 
    219197        struct pick_largest_state state; 
    220198 
    221199        state.last = *result_res; 
    222         state.result_dev = 0; 
    223         state.result = 0; 
     200        state.result_dev = NULL; 
     201        state.result = NULL; 
    224202        state.seen_last = 0; 
    225203 
     
    234212 * 
    235213 * The problem. 
    236  *  - Allocate resources locations for every device. 
     214 *  - Allocate resource locations for every device. 
    237215 *  - Don't overlap, and follow the rules of bridges. 
    238216 *  - Don't overlap with resources in fixed locations. 
     
    241219 * The strategy. 
    242220 * - Devices that have fixed addresses are the minority so don't 
    243  *   worry about them too much.  Instead only use part of the address 
    244  *   space for devices with programmable addresses.  This easily handles 
     221 *   worry about them too much. Instead only use part of the address 
     222 *   space for devices with programmable addresses. This easily handles 
    245223 *   everything except bridges. 
    246224 * 
    247  * - PCI devices are required to have thier sizes and their alignments 
    248  *   equal.  In this case an optimal solution to the packing problem 
    249  *   exists.  Allocate all devices from highest alignment to least 
    250  *   alignment or vice versa.  Use this. 
    251  * 
    252  * - So we can handle more than PCI run two allocation passes on 
    253  *   bridges.  The first to see how large the resources are behind 
    254  *   the bridge, and what their alignment requirements are.  The 
    255  *   second to assign a safe address to the devices behind the 
    256  *   bridge.  This allows me to treat a bridge as just a device with 
    257  *   a couple of resources, and not need to special case it in the 
    258  *   allocator.  Also this allows handling of other types of bridges. 
    259  * 
    260  */ 
    261  
    262 void compute_allocate_resource( 
    263         struct bus *bus, 
    264         struct resource *bridge, 
    265         unsigned long type_mask, 
    266         unsigned long type) 
     225 * - PCI devices are required to have their sizes and their alignments 
     226 *   equal. In this case an optimal solution to the packing problem 
     227 *   exists. Allocate all devices from highest alignment to least 
     228 *   alignment or vice versa. Use this. 
     229 * 
     230 * - So we can handle more than PCI run two allocation passes on bridges. The 
     231 *   first to see how large the resources are behind the bridge, and what 
     232 *   their alignment requirements are. The second to assign a safe address to 
     233 *   the devices behind the bridge. This allows us to treat a bridge as just 
     234 *   a device with a couple of resources, and not need to special case it in 
     235 *   the allocator. Also this allows handling of other types of bridges. 
     236 * 
     237 */ 
     238void compute_resources(struct bus *bus, struct resource *bridge, 
     239                       unsigned long type_mask, unsigned long type) 
    267240{ 
    268241        struct device *dev; 
    269242        struct resource *resource; 
    270243        resource_t base; 
    271         unsigned long align, min_align; 
    272         min_align = 0; 
    273         base = bridge->base; 
    274  
    275         printk_spew("%s compute_allocate_resource %s: base: %08Lx size: %08Lx align: %d gran: %d\n", 
    276                 dev_path(bus->dev), 
    277                 (bridge->flags & IORESOURCE_IO)? "io": 
    278                 (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem", 
    279                 base, bridge->size, bridge->align, bridge->gran); 
    280  
    281         /* We want different minimum alignments for different kinds of 
    282          * resources.  These minimums are not device type specific 
    283          * but resource type specific. 
     244        base = round(bridge->base, bridge->align); 
     245 
     246        printk_spew( "%s %s_%s: base: %llx size: %llx align: %d gran: %d limit: %llx\n", 
     247               dev_path(bus->dev), __func__, 
     248               (type & IORESOURCE_IO) ? "io" : (type & IORESOURCE_PREFETCH) ? 
     249               "prefmem" : "mem", 
     250               base, bridge->size, bridge->align, bridge->gran, bridge->limit); 
     251 
     252        /* For each child which is a bridge, compute_resource_needs. */ 
     253        for (dev = bus->children; dev; dev = dev->sibling) { 
     254                unsigned i; 
     255                struct resource *child_bridge; 
     256 
     257                if (!dev->links) 
     258                        continue; 
     259 
     260                /* Find the resources with matching type flags. */ 
     261                for (i = 0; i < dev->resources; i++) { 
     262                        unsigned link; 
     263                        child_bridge = &dev->resource[i]; 
     264 
     265                        if (!(child_bridge->flags & IORESOURCE_BRIDGE) || 
     266                            (child_bridge->flags & type_mask) != type) 
     267                                continue; 
     268 
     269                        /* Split prefetchable memory if combined.  Many domains 
     270                         * use the same address space for prefetchable memory 
     271                         * and non-prefetchable memory.  Bridges below them 
     272                         * need it separated.  Add the PREFETCH flag to the 
     273                         * type_mask and type. 
     274                         */ 
     275                        link = IOINDEX_LINK(child_bridge->index); 
     276                        compute_resources(&dev->link[link], child_bridge, 
     277                                          type_mask | IORESOURCE_PREFETCH, 
     278                                          type | (child_bridge->flags & 
     279                                                  IORESOURCE_PREFETCH)); 
     280                } 
     281        } 
     282 
     283        /* Remember we haven't found anything yet. */ 
     284        resource = NULL; 
     285 
     286        /* Walk through all the resources on the current bus and compute the 
     287         * amount of address space taken by them.  Take granularity and 
     288         * alignment into account. 
    284289         */ 
    285         if (bridge->flags & IORESOURCE_IO) { 
    286                 min_align = log2(DEVICE_IO_ALIGN); 
    287         } 
    288         if (bridge->flags & IORESOURCE_MEM) { 
    289                 min_align = log2(DEVICE_MEM_ALIGN); 
    290         } 
    291  
    292         /* Make certain I have read in all of the resources */ 
    293         read_resources(bus); 
    294  
    295         /* Remember I haven't found anything yet. */ 
    296         resource = 0; 
    297  
    298         /* Walk through all the devices on the current bus and 
    299          * compute the addresses. 
    300          */ 
    301         while((dev = largest_resource(bus, &resource, type_mask, type))) { 
    302                 resource_t size; 
    303                 /* Do NOT I repeat do not ignore resources which have zero size. 
    304                  * If they need to be ignored dev->read_resources should not even 
    305                  * return them.   Some resources must be set even when they have 
    306                  * no size.  PCI bridge resources are a good example of this. 
    307                  */ 
    308                 /* Make certain we are dealing with a good minimum size */ 
    309                 size = resource->size; 
    310                 align = resource->align; 
    311                 if (align < min_align) { 
    312                         align = min_align; 
    313                 } 
    314  
    315                 /* Propagate the resource alignment to the bridge register  */ 
    316                 if (align > bridge->align) { 
    317                         bridge->align = align; 
    318                 } 
    319  
    320                 if (resource->flags & IORESOURCE_FIXED) { 
    321                         continue; 
    322                 } 
    323  
    324                 /* Propogate the resource limit to the bridge register */ 
     290        while ((dev = largest_resource(bus, &resource, type_mask, type))) { 
     291 
     292                /* Size 0 resources can be skipped. */ 
     293                if (!resource->size) { 
     294                        continue; 
     295                } 
     296 
     297                /* Propagate the resource alignment to the bridge resource. */ 
     298                if (resource->align > bridge->align) { 
     299                        bridge->align = resource->align; 
     300                } 
     301 
     302                /* Propagate the resource limit to the bridge register. */ 
    325303                if (bridge->limit > resource->limit) { 
    326304                        bridge->limit = resource->limit; 
    327305                } 
    328 #warning This heuristic should be replaced by real devices with fixed resources. 
    329                 /* Artificially deny limits between DEVICE_MEM_HIGH and 0xffffffff */ 
    330                 if ((bridge->limit > DEVICE_MEM_HIGH) && (bridge->limit <= 0xffffffff)) { 
    331                         bridge->limit = DEVICE_MEM_HIGH; 
     306 
     307                /* Warn if it looks like APICs aren't declared. */ 
     308                if ((resource->limit == 0xffffffff) && 
     309                    (resource->flags & IORESOURCE_ASSIGNED)) { 
     310                        printk_err("Resource limit looks wrong! (no APIC?)\n"); 
     311                        printk_err("%s %02lx limit %08Lx\n", dev_path(dev), 
     312                                   resource->index, resource->limit); 
    332313                } 
    333314 
    334315                if (resource->flags & IORESOURCE_IO) { 
    335                         /* Don't allow potential aliases over the 
    336                          * legacy pci expansion card addresses. 
    337                          * The legacy pci decodes only 10 bits, 
    338                          * uses 100h - 3ffh. Therefor, only 0 - ff 
    339                          * can be used out of each 400h block of io 
    340                          * space. 
     316                        /* Don't allow potential aliases over the legacy PCI 
     317                         * expansion card addresses. The legacy PCI decodes 
     318                         * only 10 bits, uses 0x100 - 0x3ff. Therefore, only 
     319                         * 0x00 - 0xff can be used out of each 0x400 block of 
     320                         * I/O space. 
    341321                         */ 
    342322                        if ((base & 0x300) != 0) { 
    343323                                base = (base & ~0x3ff) + 0x400; 
    344324                        } 
    345                         /* Don't allow allocations in the VGA IO range. 
     325                        /* Don't allow allocations in the VGA I/O range. 
    346326                         * PCI has special cases for that. 
    347327                         */ 
     
    350330                        } 
    351331                } 
    352                 if (((round(base, align) + size) -1) <= resource->limit) { 
    353                         /* base must be aligned to size */ 
    354                         base = round(base, align); 
    355                         resource->base = base; 
    356                         resource->flags |= IORESOURCE_ASSIGNED; 
    357                         resource->flags &= ~IORESOURCE_STORED; 
    358                         base += size; 
    359  
    360                         printk_spew("%s %02lx *  [0x%08Lx - 0x%08Lx] %s\n", 
    361                                 dev_path(dev), 
    362                                 resource->index, 
    363                                 resource->base, 
    364                                 resource->base + resource->size - 1, 
    365                                 (resource->flags & IORESOURCE_IO)? "io": 
    366                                 (resource->flags & IORESOURCE_PREFETCH)? "prefmem": "mem"); 
    367                 } 
    368 #if CONFIG_PCIE_CONFIGSPACE_HOLE 
    369 #warning Handle PCIe hole differently... 
    370                 if (base >= 0xf0000000 && base < 0xf4000000) { 
    371                         base = 0xf4000000; 
    372                 } 
    373 #endif 
     332                /* Base must be aligned. */ 
     333                base = round(base, resource->align); 
     334                resource->base = base; 
     335                base += resource->size; 
     336 
     337                printk_spew("%s %02lx *  [0x%llx - 0x%llx] %s\n", 
     338                            dev_path(dev), resource->index, 
     339                            resource->base, 
     340                            resource->base + resource->size - 1, 
     341                            (resource->flags & IORESOURCE_IO) ? "io" : 
     342                            (resource->flags & IORESOURCE_PREFETCH) ? 
     343                             "prefmem" : "mem"); 
    374344        } 
    375345        /* A pci bridge resource does not need to be a power 
     
    379349         * decoded by the bridge. 
    380350         */ 
    381         bridge->size = round(base, bridge->gran) - bridge->base; 
    382  
    383         printk_spew("%s compute_allocate_resource %s: base: %08Lx size: %08Lx align: %d gran: %d done\n", 
    384                     dev_path(bus->dev), 
    385                     (bridge->flags & IORESOURCE_IO)? "io": 
    386                      (bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem", 
    387                     base, bridge->size, bridge->align, bridge->gran); 
     351        bridge->size = round(base, bridge->gran) - 
     352                       round(bridge->base, bridge->align); 
     353 
     354        printk_spew("%s %s_%s: base: %llx size: %llx align: %d gran: %d limit: %llx done\n", 
     355                    dev_path(bus->dev), __func__, 
     356                    (bridge->flags & IORESOURCE_IO) ? "io" : 
     357                     (bridge->flags & IORESOURCE_PREFETCH) ?  "prefmem" : "mem", 
     358                    base, bridge->size, bridge->align, bridge->gran, bridge->limit); 
     359} 
     360 
     361/** 
     362 * This function is the second part of the resource allocator. 
     363 * 
     364 * The problem. 
     365 *  - Allocate resource locations for every device. 
     366 *  - Don't overlap, and follow the rules of bridges. 
     367 *  - Don't overlap with resources in fixed locations. 
     368 *  - Be efficient so we don't have ugly strategies. 
     369 * 
     370 * The strategy. 
     371 * - Devices that have fixed addresses are the minority so don't 
     372 *   worry about them too much. Instead only use part of the address 
     373 *   space for devices with programmable addresses. This easily handles 
     374 *   everything except bridges. 
     375 * 
     376 * - PCI devices are required to have their sizes and their alignments 
     377 *   equal. In this case an optimal solution to the packing problem 
     378 *   exists. Allocate all devices from highest alignment to least 
     379 *   alignment or vice versa. Use this. 
     380 * 
     381 * - So we can handle more than PCI run two allocation passes on bridges. The 
     382 *   first to see how large the resources are behind the bridge, and what 
     383 *   their alignment requirements are. The second to assign a safe address to 
     384 *   the devices behind the bridge. This allows us to treat a bridge as just 
     385 *   a device with a couple of resources, and not need to special case it in 
     386 *   the allocator. Also this allows handling of other types of bridges. 
     387 * 
     388 * - This function assigns the resources a value. 
     389 * 
     390 * @param bus The bus we are traversing. 
     391 * @param bridge The bridge resource which must contain the bus' resources. 
     392 * @param type_mask This value gets anded with the resource type. 
     393 * @param type This value must match the result of the and. 
     394 */ 
     395void allocate_resources(struct bus *bus, struct resource *bridge, 
     396                        unsigned long type_mask, unsigned long type) 
     397{ 
     398        struct device *dev; 
     399        struct resource *resource; 
     400        resource_t base; 
     401        base = bridge->base; 
     402 
     403        printk_spew("%s %s_%s: base:%llx size:%llx align:%d gran:%d limit:%llx\n", 
     404               dev_path(bus->dev), __func__, 
     405               (type & IORESOURCE_IO) ? "io" : (type & IORESOURCE_PREFETCH) ? 
     406               "prefmem" : "mem", 
     407               base, bridge->size, bridge->align, bridge->gran, bridge->limit); 
     408 
     409        /* Remember we haven't found anything yet. */ 
     410        resource = NULL; 
     411 
     412        /* Walk through all the resources on the current bus and allocate them 
     413         * address space. 
     414         */ 
     415        while ((dev = largest_resource(bus, &resource, type_mask, type))) { 
     416 
     417                /* Propagate the bridge limit to the resource register. */ 
     418                if (resource->limit > bridge->limit) { 
     419                        resource->limit = bridge->limit; 
     420                } 
     421 
     422                /* Size 0 resources can be skipped. */ 
     423                if (!resource->size) { 
     424                        /* Set the base to limit so it doesn't confuse tolm. */ 
     425                        resource->base = resource->limit; 
     426                        resource->flags |= IORESOURCE_ASSIGNED; 
     427                        continue; 
     428                } 
     429 
     430                if (resource->flags & IORESOURCE_IO) { 
     431                        /* Don't allow potential aliases over the legacy PCI 
     432                         * expansion card addresses. The legacy PCI decodes 
     433                         * only 10 bits, uses 0x100 - 0x3ff. Therefore, only 
     434                         * 0x00 - 0xff can be used out of each 0x400 block of 
     435                         * I/O space. 
     436                         */ 
     437                        if ((base & 0x300) != 0) { 
     438                                base = (base & ~0x3ff) + 0x400; 
     439                        } 
     440                        /* Don't allow allocations in the VGA I/O range. 
     441                         * PCI has special cases for that. 
     442                         */ 
     443                        else if ((base >= 0x3b0) && (base <= 0x3df)) { 
     444                                base = 0x3e0; 
     445                        } 
     446                } 
     447 
     448                if ((round(base, resource->align) + resource->size - 1) <= 
     449                    resource->limit) { 
     450                        /* Base must be aligned. */ 
     451                        base = round(base, resource->align); 
     452                        resource->base = base; 
     453                        resource->flags |= IORESOURCE_ASSIGNED; 
     454                        resource->flags &= ~IORESOURCE_STORED; 
     455                        base += resource->size; 
     456                } else { 
     457                        printk_err("!! Resource didn't fit !!\n"); 
     458                        printk_err("   aligned base %llx size %llx limit %llx\n", 
     459                               round(base, resource->align), resource->size, 
     460                               resource->limit); 
     461                        printk_err("   %llx needs to be <= %llx (limit)\n", 
     462                               (round(base, resource->align) + 
     463                                resource->size) - 1, resource->limit); 
     464                        printk_err("   %s%s %02lx *  [0x%llx - 0x%llx] %s\n", 
     465                               (resource-> 
     466                                flags & IORESOURCE_ASSIGNED) ? "Assigned: " : 
     467                               "", dev_path(dev), resource->index, 
     468                               resource->base, 
     469                               resource->base + resource->size - 1, 
     470                               (resource-> 
     471                                flags & IORESOURCE_IO) ? "io" : (resource-> 
     472                                                                 flags & 
     473                                                                 IORESOURCE_PREFETCH) 
     474                               ? "prefmem" : "mem"); 
     475                } 
     476 
     477                printk_spew("%s%s %02lx *  [0x%llx - 0x%llx] %s\n", 
     478                       (resource->flags & IORESOURCE_ASSIGNED) ? "Assigned: " 
     479                       : "", 
     480                       dev_path(dev), resource->index, resource->base, 
     481                       resource->size ? resource->base + resource->size - 1 : 
     482                       resource->base, 
     483                       (resource->flags & IORESOURCE_IO) ? "io" : 
     484                       (resource->flags & IORESOURCE_PREFETCH) ? "prefmem" : 
     485                       "mem"); 
     486        } 
     487        /* A PCI bridge resource does not need to be a power of two size, but 
     488         * it does have a minimum granularity. Round the size up to that 
     489         * minimum granularity so we know not to place something else at an 
     490         * address positively decoded by the bridge. 
     491         */ 
     492 
     493        bridge->flags |= IORESOURCE_ASSIGNED; 
     494 
     495        printk_spew("%s %s_%s: next_base: %llx size: %llx align: %d gran: %d done\n", 
     496               dev_path(bus->dev), __func__, 
     497               (type & IORESOURCE_IO) ? "io" : (type & IORESOURCE_PREFETCH) ? 
     498               "prefmem" : "mem", 
     499               base, bridge->size, bridge->align, bridge->gran); 
     500 
     501        /* For each child which is a bridge, allocate_resources. */ 
     502        for (dev = bus->children; dev; dev = dev->sibling) { 
     503                unsigned i; 
     504                struct resource *child_bridge; 
     505 
     506                if (!dev->links) 
     507                        continue; 
     508 
     509                /* Find the resources with matching type flags. */ 
     510                for (i = 0; i < dev->resources; i++) { 
     511                        unsigned link; 
     512                        child_bridge = &dev->resource[i]; 
     513 
     514                        if (!(child_bridge->flags & IORESOURCE_BRIDGE) || 
     515                            (child_bridge->flags & type_mask) != type) 
     516                                continue; 
     517 
     518                        /* Split prefetchable memory if combined.  Many domains 
     519                         * use the same address space for prefetchable memory 
     520                         * and non-prefetchable memory.  Bridges below them 
     521                         * need it separated.  Add the PREFETCH flag to the 
     522                         * type_mask and type. 
     523                         */ 
     524                        link = IOINDEX_LINK(child_bridge->index); 
     525                        allocate_resources(&dev->link[link], child_bridge, 
     526                                           type_mask | IORESOURCE_PREFETCH, 
     527                                           type | (child_bridge->flags & 
     528                                                   IORESOURCE_PREFETCH)); 
     529                } 
     530        } 
     531} 
     532 
     533#if CONFIG_PCI_64BIT_PREF_MEM == 1 
     534        #define MEM_MASK (IORESOURCE_PREFETCH | IORESOURCE_MEM) 
     535#else 
     536        #define MEM_MASK (IORESOURCE_MEM) 
     537#endif 
     538#define IO_MASK (IORESOURCE_IO) 
     539#define PREF_TYPE (IORESOURCE_PREFETCH | IORESOURCE_MEM) 
     540#define MEM_TYPE (IORESOURCE_MEM) 
     541#define IO_TYPE (IORESOURCE_IO) 
     542 
     543struct constraints { 
     544        struct resource pref, io, mem; 
     545}; 
     546 
     547static void constrain_resources(struct device *dev, struct constraints* limits) 
     548{ 
     549        struct device *child; 
     550        struct resource *res; 
     551        struct resource *lim; 
     552        int i; 
     553 
     554        printk_spew("%s: %s\n", __func__, dev_path(dev)); 
     555 
     556        /* Constrain limits based on the fixed resources of this device. */ 
     557        for (i = 0; i < dev->resources; i++) { 
     558                res = &dev->resource[i]; 
     559                if (!(res->flags & IORESOURCE_FIXED)) 
     560                        continue; 
     561 
     562                /* PREFETCH, MEM, or I/O - skip any others. */ 
     563                if ((res->flags & MEM_MASK) == PREF_TYPE) 
     564                        lim = &limits->pref; 
     565                else if ((res->flags & MEM_MASK) == MEM_TYPE) 
     566                        lim = &limits->mem; 
     567                else if ((res->flags & IO_MASK) == IO_TYPE) 
     568                        lim = &limits->io; 
     569                else 
     570                        continue; 
     571 
     572                /* Is it already outside the limits? */ 
     573                if (res->size && (((res->base + res->size -1) < lim->base) || 
     574                                  (res->base > lim->limit))) 
     575                        continue; 
     576 
     577                /* Choose to be above or below fixed resources.  This 
     578                 * check is signed so that "negative" amounts of space 
     579                 * are handled correctly. 
     580                 */ 
     581                if ((signed long long)(lim->limit - (res->base + res->size -1)) > 
     582                    (signed long long)(res->base - lim->base)) 
     583                        lim->base = res->base + res->size; 
     584                else 
     585                        lim->limit = res->base -1; 
     586        } 
     587 
     588        /* Descend into every enabled child and look for fixed resources. */ 
     589        for (i = 0; i < dev->links; i++) 
     590                for (child = dev->link[i].children; child; 
     591                     child = child->sibling) 
     592                        if (child->enabled) 
     593                                constrain_resources(child, limits); 
     594} 
     595 
     596static void avoid_fixed_resources(struct device *dev) 
     597{ 
     598        struct constraints limits; 
     599        struct resource *res; 
     600        int i; 
     601 
     602        printk_spew("%s: %s\n", __func__, dev_path(dev)); 
     603        /* Initialize constraints to maximum size. */ 
     604 
     605        limits.pref.base = 0; 
     606        limits.pref.limit = 0xffffffffffffffffULL; 
     607        limits.io.base = 0; 
     608        limits.io.limit = 0xffffffffffffffffULL; 
     609        limits.mem.base = 0; 
     610        limits.mem.limit = 0xffffffffffffffffULL; 
     611 
     612        /* Constrain the limits to dev's initial resources. */ 
     613        for (i = 0; i < dev->resources; i++) { 
     614                res = &dev->resource[i]; 
     615                if ((res->flags & IORESOURCE_FIXED)) 
     616                        continue; 
     617                printk_spew("%s:@%s %02lx limit %08Lx\n", __func__, 
     618                             dev_path(dev), res->index, res->limit); 
     619                if ((res->flags & MEM_MASK) == PREF_TYPE && 
     620                    (res->limit < limits.pref.limit)) 
     621                        limits.pref.limit = res->limit; 
     622                if ((res->flags & MEM_MASK) == MEM_TYPE && 
     623                    (res->limit < limits.mem.limit)) 
     624                        limits.mem.limit = res->limit; 
     625                if ((res->flags & IO_MASK) == IO_TYPE && 
     626                    (res->limit < limits.io.limit)) 
     627                        limits.io.limit = res->limit; 
     628        } 
     629 
     630        /* Look through the tree for fixed resources and update the limits. */ 
     631        constrain_resources(dev, &limits); 
     632 
     633        /* Update dev's resources with new limits. */ 
     634        for (i = 0; i < dev->resources; i++) { 
     635                struct resource *lim; 
     636                res = &dev->resource[i]; 
     637 
     638                if ((res->flags & IORESOURCE_FIXED)) 
     639                        continue; 
     640 
     641                /* PREFETCH, MEM, or I/O - skip any others. */ 
     642                if ((res->flags & MEM_MASK) == PREF_TYPE) 
     643                        lim = &limits.pref; 
     644                else if ((res->flags & MEM_MASK) == MEM_TYPE) 
     645                        lim = &limits.mem; 
     646                else if ((res->flags & IO_MASK) == IO_TYPE) 
     647                        lim = &limits.io; 
     648                else 
     649                        continue; 
     650 
     651                printk_spew("%s2: %s@%02lx limit %08Lx\n", __func__, 
     652                             dev_path(dev), res->index, res->limit); 
     653                printk_spew("\tlim->base %08Lx lim->limit %08Lx\n", 
     654                             lim->base, lim->limit); 
     655 
     656                /* Is the resource outside the limits? */ 
     657                if (lim->base > res->base) 
     658                        res->base = lim->base; 
     659                if (res->limit > lim->limit) 
     660                        res->limit = lim->limit; 
     661        } 
    388662} 
    389663 
     
    393667{ 
    394668#warning "FIXME modify allocate_vga_resource so it is less pci centric!" 
    395 #warning "This function knows to much about PCI stuff, it should be just a ietrator/visitor." 
    396  
    397         /* FIXME handle the VGA pallette snooping */ 
     669#warning "This function knows too much about PCI stuff, it should be just a iterator/visitor." 
     670 
     671        /* FIXME: Handle the VGA palette snooping. */ 
    398672        struct device *dev, *vga, *vga_onboard, *vga_first, *vga_last; 
    399673        struct bus *bus; 
     
    403677        vga_first = 0; 
    404678        vga_last = 0; 
    405         for(dev = all_devices; dev; dev = dev->next) { 
    406                 if (!dev->enabled) continue; 
     679        for (dev = all_devices; dev; dev = dev->next) { 
     680                if (!dev->enabled) 
     681                        continue; 
    407682                if (((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) && 
    408                         ((dev->class >> 8) != PCI_CLASS_DISPLAY_OTHER)) 
    409                 { 
    410                         if (!vga_first) { 
    411                                 if (dev->on_mainboard) { 
    412                                         vga_onboard = dev; 
    413                                 } else { 
    414                                         vga_first = dev; 
    415                                 } 
    416                         } else { 
    417                                 if (dev->on_mainboard) { 
    418                                         vga_onboard = dev; 
    419                                 } else { 
    420                                         vga_last = dev; 
    421                                 } 
    422                         } 
    423  
    424                         /* It isn't safe to enable other VGA cards */ 
     683                    ((dev->class >> 8) != PCI_CLASS_DISPLAY_OTHER)) { 
     684                        if (!vga_first) { 
     685                                if (dev->on_mainboard) { 
     686                                        vga_onboard = dev; 
     687                                } else { 
     688                                        vga_first = dev; 
     689                                } 
     690                        } else { 
     691                                if (dev->on_mainboard) { 
     692                                        vga_onboard = dev; 
     693                                } else { 
     694                                        vga_last = dev; 
     695                                } 
     696                        } 
     697 
     698                        /* It isn't safe to enable other VGA cards. */ 
    425699                        dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO); 
    426700                } 
    427701        } 
    428702 
    429         vga = vga_last; 
    430  
    431         if(!vga) { 
    432                 vga = vga_first; 
    433         } 
    434  
     703        vga = vga_last; 
     704 
     705        if (!vga) { 
     706                vga = vga_first; 
     707        } 
    435708#if CONFIG_CONSOLE_VGA_ONBOARD_AT_FIRST == 1 
    436         if (vga_onboard) // will use on board vga as pri 
     709        if (vga_onboard)        // Will use on board VGA as pri. 
    437710#else 
    438         if (!vga) // will use last add on adapter as pri 
     711        if (!vga)               // Will use last add on adapter as pri. 
    439712#endif 
    440         { 
    441                 vga = vga_onboard; 
    442         } 
    443  
     713        { 
     714                vga = vga_onboard; 
     715        } 
    444716 
    445717        if (vga) { 
    446                 /* vga is first add on card or the only onboard vga */ 
     718                /* VGA is first add on card or the only onboard VGA. */ 
    447719                printk_debug("Allocating VGA resource %s\n", dev_path(vga)); 
    448                 /* All legacy VGA cards have MEM & I/O space registers */ 
     720                /* All legacy VGA cards have MEM & I/O space registers. */ 
    449721                vga->command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_IO); 
    450722                vga_pri = vga; 
    451723                bus = vga->bus; 
    452724        } 
    453         /* Now walk up the bridges setting the VGA enable */ 
    454         while(bus) { 
     725        /* Now walk up the bridges setting the VGA enable. */ 
     726        while (bus) { 
    455727                printk_debug("Setting PCI_BRIDGE_CTL_VGA for bridge %s\n", 
    456728                             dev_path(bus->dev)); 
    457729                bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA; 
    458                 bus = (bus == bus->dev->bus)? 0 : bus->dev->bus; 
     730                bus = (bus == bus->dev->bus) ? 0 : bus->dev->bus; 
    459731        } 
    460732} 
    461733 
    462734#endif 
    463  
    464735 
    465736/** 
     
    481752 
    482753        printk_spew("%s assign_resources, bus %d link: %d\n", 
    483                 dev_path(bus->dev), bus->secondary, bus->link); 
    484  
    485         for(curdev = bus->children; curdev; curdev = curdev->sibling) { 
     754                    dev_path(bus->dev), bus->secondary, bus->link); 
     755 
     756        for (curdev = bus->children; curdev; curdev = curdev->sibling) { 
    486757                if (!curdev->enabled || !curdev->resources) { 
    487758                        continue; 
     
    489760                if (!curdev->ops || !curdev->ops->set_resources) { 
    490761                        printk_err("%s missing set_resources\n", 
    491                                 dev_path(curdev)); 
     762                                   dev_path(curdev)); 
    492763                        continue; 
    493764                } 
     
    495766        } 
    496767        printk_spew("%s assign_resources, bus %d link: %d\n", 
    497                 dev_path(bus->dev), bus->secondary, bus->link); 
     768                    dev_path(bus->dev), bus->secondary, bus->link); 
    498769} 
    499770 
     
    540811int reset_bus(struct bus *bus) 
    541812{ 
    542         if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) 
    543         { 
     813        if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) { 
    544814                bus->dev->ops->reset_bus(bus); 
    545815                bus->reset_needed = 0; 
     
    552822 * @brief Scan for devices on a bus. 
    553823 * 
    554  * If there are bridges on the bus, recursively scan the buses behind the bridges. 
    555  * If the setting up and tuning of the bus causes a reset to be required, 
    556  * reset the bus and scan it again. 
    557  * 
    558  * @param bus pointer to the bus device 
    559  * @param max current bus number 
    560  * 
    561  * @return The maximum bus number found, after scanning all subordinate busses 
    562  */ 
    563 unsigned int scan_bus(device_t bus, unsigned int max) 
     824 * If there are bridges on the bus, recursively scan the buses behind the 
     825 * bridges. If the setting up and tuning of the bus causes a reset to be 
     826 * required, reset the bus and scan it again. 
     827 * 
     828 * @param busdev Pointer to the bus device. 
     829 * @param max Current bus number. 
     830 * @return The maximum bus number found, after scanning all subordinate buses. 
     831 */ 
     832unsigned int scan_bus(struct device *busdev, unsigned int max) 
    564833{ 
    565834        unsigned int new_max; 
    566835        int do_scan_bus; 
    567         if (    !bus || 
    568                 !bus->enabled || 
    569                 !bus->ops || 
    570                 !bus->ops->scan_bus) 
    571         { 
     836        if (!busdev || !busdev->enabled || !busdev->ops || 
     837            !busdev->ops->scan_bus) { 
    572838                return max; 
    573839        } 
     840 
    574841        do_scan_bus = 1; 
    575         while(do_scan_bus) { 
     842        while (do_scan_bus) { 
    576843                int link; 
    577                 new_max = bus->ops->scan_bus(bus, max); 
     844                new_max = busdev->ops->scan_bus(busdev, max); 
    578845                do_scan_bus = 0; 
    579                 for(link = 0; link < bus->links; link++) { 
    580                         if (bus->link[link].reset_needed) { 
    581                                 if (reset_bus(&bus->link[link])) { 
     846                for (link = 0; link < busdev->links; link++) { 
     847                        if (busdev->link[link].reset_needed) { 
     848                                if (reset_bus(&busdev->link[link])) { 
    582849                                        do_scan_bus = 1; 
    583850                                } else { 
    584                                         bus->bus->reset_needed = 1; 
     851                                        busdev->bus->reset_needed = 1; 
    585852                                } 
    586853                        } 
     
    589856        return new_max; 
    590857} 
    591  
    592858 
    593859/** 
     
    620886        root = &dev_root; 
    621887 
    622         show_all_devs(BIOS_DEBUG, "Before Phase 3."); 
     888        show_all_devs(BIOS_DEBUG, "Before Device Enumeration."); 
    623889        printk_debug("Compare with tree...\n"); 
    624890 
     
    644910 * relocated to their final position and stored to the hardware. 
    645911 * 
    646  * I/O resources start at DEVICE_IO_START and grow upward. MEM resources start 
    647  * at DEVICE_MEM_HIGH and grow downward. 
     912 * I/O resources grow upward. MEM resources grow downward. 
    648913 * 
    649914 * Since the assignment is hierarchical we set the values into the dev_root 
     
    652917void dev_configure(void) 
    653918{ 
    654         struct resource *io, *mem; 
     919        struct resource *res; 
    655920        struct device *root; 
     921        struct device *child; 
     922        int i; 
    656923 
    657924        printk_info("Allocating resources...\n"); 
     
    659926        root = &dev_root; 
    660927 
    661         print_resource_tree(root, BIOS_DEBUG, "Original."); 
    662  
    663         if (!root->ops || !root->ops->read_resources) { 
    664                 printk_err("dev_root missing read_resources\n"); 
    665                 return; 
    666         } 
    667         if (!root->ops || !root->ops->set_resources) { 
    668                 printk_err("dev_root missing set_resources\n"); 
    669                 return; 
    670         } 
     928        /* Each domain should create resources which contain the entire address 
     929         * space for IO, MEM, and PREFMEM resources in the domain. The 
     930         * allocation of device resources will be done from this address space. 
     931         */ 
     932 
     933        /* Read the resources for the entire tree. */ 
    671934 
    672935        printk_info("Reading resources...\n"); 
    673         root->ops->read_resources(root); 
     936        read_resources(&root->link[0]); 
    674937        printk_info("Done reading resources.\n"); 
    675938 
    676939        print_resource_tree(root, BIOS_DEBUG, "After reading."); 
    677940 
    678         /* Get the resources */ 
    679         io  = &root->resource[0]; 
    680         mem = &root->resource[1]; 
    681         /* Make certain the io devices are allocated somewhere safe. */ 
    682         io->base = DEVICE_IO_START; 
    683         io->flags |= IORESOURCE_ASSIGNED; 
    684         io->flags &= ~IORESOURCE_STORED; 
    685         /* Now reallocate the pci resources memory with the 
    686          * highest addresses I can manage. 
     941        /* Compute resources for all domains. */ 
     942        for (child = root->link[0].children; child; child = child->sibling) { 
     943                if (!(child->path.type == DEVICE_PATH_PCI_DOMAIN)) 
     944                        continue; 
     945                for (i = 0; i < child->resources; i++) { 
     946                        res = &child->resource[i]; 
     947                        if (res->flags & IORESOURCE_FIXED) 
     948                                continue; 
     949                        if (res->flags & IORESOURCE_PREFETCH) { 
     950                                compute_resources(&child->link[0], 
     951                                               res, MEM_MASK, PREF_TYPE); 
     952                                continue; 
     953                        } 
     954                        if (res->flags & IORESOURCE_MEM) { 
     955                                compute_resources(&child->link[0], 
     956                                               res, MEM_MASK, MEM_TYPE); 
     957                                continue; 
     958                        } 
     959                        if (res->flags & IORESOURCE_IO) { 
     960                                compute_resources(&child->link[0], 
     961                                               res, IO_MASK, IO_TYPE); 
     962                                continue; 
     963                        } 
     964                } 
     965        } 
     966 
     967        /* For all domains. */ 
     968        for (child = root->link[0].children; child; child=child->sibling) 
     969                if (child->path.type == DEVICE_PATH_PCI_DOMAIN) 
     970                        avoid_fixed_resources(child); 
     971 
     972        /* Now we need to adjust the resources. MEM resources need to start at 
     973         * the highest address managable. 
    687974         */ 
    688         mem->base = resource_max(&root->resource[1]); 
    689         mem->flags |= IORESOURCE_ASSIGNED; 
    690         mem->flags &= ~IORESOURCE_STORED; 
     975        for (child = root->link[0].children; child; child = child->sibling) { 
     976                if (child->path.type != DEVICE_PATH_PCI_DOMAIN) 
     977                        continue; 
     978                for (i = 0; i < child->resources; i++) { 
     979                        res = &child->resource[i]; 
     980                        if (!(res->flags & IORESOURCE_MEM) || 
     981                            res->flags & IORESOURCE_FIXED) 
     982                                continue; 
     983                        res->base = resource_max(res); 
     984                } 
     985        } 
    691986 
    692987#if CONFIG_CONSOLE_VGA == 1 
    693         /* Allocate the VGA I/O resource.. */ 
     988        /* Allocate the VGA I/O resource. */ 
    694989        allocate_vga_resource(); 
    695990        print_resource_tree(root, BIOS_DEBUG, "After VGA."); 
     
    698993        /* Store the computed resource allocations into device registers ... */ 
    699994        printk_info("Setting resources...\n"); 
    700         root->ops->set_resources(root); 
     995        for (child = root->link[0].children; child; child = child->sibling) { 
     996                if (!(child->path.type == DEVICE_PATH_PCI_DOMAIN)) 
     997                        continue; 
     998                for (i = 0; i < child->resources; i++) { 
     999                        res = &child->resource[i]; 
     1000                        if (res->flags & IORESOURCE_FIXED) 
     1001                                continue; 
     1002                        if (res->flags & IORESOURCE_PREFETCH) { 
     1003                                allocate_resources(&child->link[0], 
     1004                                               res, MEM_MASK, PREF_TYPE); 
     1005                                continue; 
     1006                        } 
     1007                        if (res->flags & IORESOURCE_MEM) { 
     1008                                allocate_resources(&child->link[0], 
     1009                                               res, MEM_MASK, MEM_TYPE); 
     1010                                continue; 
     1011                        } 
     1012                        if (res->flags & IORESOURCE_IO) { 
     1013                                allocate_resources(&child->link[0], 
     1014                                               res, IO_MASK, IO_TYPE); 
     1015                                continue; 
     1016                        } 
     1017                } 
     1018        } 
     1019        assign_resources(&root->link[0]); 
    7011020        printk_info("Done setting resources.\n"); 
    702 #if 0 
    703         mem->flags |= IORESOURCE_STORED; 
    704         report_resource_stored(root, mem, ""); 
    705 #endif 
    7061021        print_resource_tree(root, BIOS_DEBUG, "After assigning values."); 
    7071022 
     
    7371052 
    7381053        printk_info("Initializing devices...\n"); 
    739         for(dev = all_devices; dev; dev = dev->next) { 
     1054        for (dev = all_devices; dev; dev = dev->next) { 
    7401055                if (dev->enabled && !dev->initialized && 
    741                         dev->ops && dev->ops->init) 
    742                 { 
     1056                    dev->ops && dev->ops->init) { 
    7431057                        if (dev->path.type == DEVICE_PATH_I2C) { 
    744                                 printk_debug("smbus: %s[%d]->", 
    745                                         dev_path(dev->bus->dev), dev->bus->link); 
     1058                                printk_debug("smbus: %s[%d]->", 
     1059                                             dev_path(dev->bus->dev), 
     1060                                             dev->bus->link); 
    7461061                        } 
    7471062                        printk_debug("%s init\n", dev_path(dev)); 
     
    7531068        show_all_devs(BIOS_DEBUG, "After init."); 
    7541069} 
    755  
  • trunk/coreboot-v2/src/devices/device_util.c

    r4381 r4394  
    488488                int i; 
    489489                /* Ignore disabled devices */ 
    490                 if (!curdev->have_resources) continue; 
     490                if (!curdev->enabled) continue; 
    491491                for(i = 0; i < curdev->resources; i++) { 
    492492                        struct resource *resource = &curdev->resource[i]; 
     
    515515                int i; 
    516516                /* Ignore disabled devices */ 
    517                 if (!curdev->have_resources) continue; 
     517                if (!curdev->enabled) continue; 
    518518                for(i = 0; i < curdev->resources; i++) { 
    519519                        struct resource *resource = &curdev->resource[i]; 
  • trunk/coreboot-v2/src/devices/pci_device.c

    r4381 r4394  
    1616 
    1717/* 
    18  *      PCI Bus Services, see include/linux/pci.h for further explanation. 
    19  * 
    20  *      Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, 
    21  *      David Mosberger-Tang 
    22  * 
    23  *      Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> 
     18 * PCI Bus Services, see include/linux/pci.h for further explanation. 
     19 * 
     20 * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, 
     21 * David Mosberger-Tang 
     22 * 
     23 * Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> 
    2424 */ 
    2525 
     
    5252#endif 
    5353 
    54 uint8_t pci_moving_config8(struct device *dev, unsigned reg) 
    55 { 
    56         uint8_t value, ones, zeroes; 
     54u8 pci_moving_config8(struct device *dev, unsigned int reg) 
     55{ 
     56        u8 value, ones, zeroes; 
    5757        value = pci_read_config8(dev, reg); 
    5858 
     
    6868} 
    6969 
    70 uint16_t pci_moving_config16(struct device *dev, unsigned reg) 
    71 { 
    72         uint16_t value, ones, zeroes; 
     70u16 pci_moving_config16(struct device * dev, unsigned int reg) 
     71{ 
     72        u16 value, ones, zeroes; 
    7373        value = pci_read_config16(dev, reg); 
    7474 
     
    8484} 
    8585 
    86 uint32_t pci_moving_config32(struct device *dev, unsigned reg) 
    87 { 
    88         uint32_t value, ones, zeroes; 
     86u32 pci_moving_config32(struct device * dev, unsigned int reg) 
     87{ 
     88        u32 value, ones, zeroes; 
    8989        value = pci_read_config32(dev, reg); 
    9090 
     
    100100} 
    101101 
    102 unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last) 
     102/** 
     103 * Given a device, a capability type, and a last position, return the next 
     104 * matching capability. Always start at the head of the list. 
     105 * 
     106 * @param dev Pointer to the device structure. 
     107 * @param cap_type PCI_CAP_LIST_ID of the PCI capability we're looking for. 
     108 * @param last Location of the PCI capability register to start from. 
     109 */ 
     110unsigned pci_find_next_capability(struct device *dev, unsigned cap, 
     111                                  unsigned last) 
    103112{ 
    104113        unsigned pos; 
     
    110119                return 0; 
    111120        } 
    112         switch(dev->hdr_type & 0x7f) { 
     121        switch (dev->hdr_type & 0x7f) { 
    113122        case PCI_HEADER_TYPE_NORMAL: 
    114123        case PCI_HEADER_TYPE_BRIDGE: 
     
    122131        } 
    123132        pos = pci_read_config8(dev, pos); 
    124         while(reps-- && (pos >= 0x40)) {   /* loop through the linked list */ 
     133        while (reps-- && (pos >= 0x40)) {       /* Loop through the linked list. */ 
    125134                int this_cap; 
    126135                pos &= ~3; 
    127136                this_cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID); 
    128                 printk_spew("Capability: 0x%02x @ 0x%02x\n", cap, pos); 
     137                printk_spew("Capability: type 0x%02x @ 0x%02x\n", this_cap, 
     138                            pos); 
    129139                if (this_cap == 0xff) { 
    130140                        break; 
     
    141151} 
    142152 
     153/** 
     154 * Given a device, and a capability type, return the next matching 
     155 * capability. Always start at the head of the list. 
     156 * 
     157 * @param dev Pointer to the device structure. 
     158 * @param cap_type PCI_CAP_LIST_ID of the PCI capability we're looking for. 
     159 */ 
    143160unsigned pci_find_capability(device_t dev, unsigned cap) 
    144161{ 
    145162        return pci_find_next_capability(dev, cap, 0); 
    146  
    147 } 
    148  
    149 /** Given a device and register, read the size of the BAR for that register. 
    150  * @param dev       Pointer to the device structure 
    151  * @param resource  Pointer to the resource structure 
    152  * @param index     Address of the pci configuration register 
     163} 
     164 
     165/** 
     166 * Given a device and register, read the size of the BAR for that register. 
     167 * 
     168 * @param dev Pointer to the device structure. 
     169 * @param index Address of the PCI configuration register. 
    153170 */ 
    154171struct resource *pci_get_resource(struct device *dev, unsigned long index) 
     
    156173        struct resource *resource; 
    157174        unsigned long value, attr; 
    158         resource_t  moving, limit; 
    159  
    160         /* Initialize the resources to nothing */ 
     175        resource_t moving, limit; 
     176 
     177        /* Initialize the resources to nothing. */ 
    161178        resource = new_resource(dev, index); 
    162179 
    163         /* Get the initial value */ 
     180        /* Get the initial value. */ 
    164181        value = pci_read_config32(dev, index); 
    165182 
    166         /* See which bits move */ 
     183        /* See which bits move. */ 
    167184        moving = pci_moving_config32(dev, index); 
    168185 
    169         /* Initialize attr to the bits that do not move */ 
     186        /* Initialize attr to the bits that do not move. */ 
    170187        attr = value & ~moving; 
    171188 
    172         /* If it is a 64bit resource look at the high half as well */ 
     189        /* If it is a 64bit resource look at the high half as well. */ 
    173190        if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) && 
    174                 ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == PCI_BASE_ADDRESS_MEM_LIMIT_64)) 
    175         { 
    176                 /* Find the high bits that move */ 
    177                 moving |= ((resource_t)pci_moving_config32(dev, index + 4)) << 32; 
     191            ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == 
     192             PCI_BASE_ADDRESS_MEM_LIMIT_64)) { 
     193                /* Find the high bits that move. */ 
     194                moving |= 
     195                    ((resource_t) pci_moving_config32(dev, index + 4)) << 32; 
    178196        } 
    179197        /* Find the resource constraints. 
    180          * 
    181198         * Start by finding the bits that move. From there: 
    182199         * - Size is the least significant bit of the bits that move. 
    183200         * - Limit is all of the bits that move plus all of the lower bits. 
    184          * See PCI Spec 6.2.5.1 ... 
     201         * See PCI Spec 6.2.5.1. 
    185202         */ 
    186203        limit = 0; 
     
    188205                resource->size = 1; 
    189206                resource->align = resource->gran = 0; 
    190                 while(!(moving & resource->size)) { 
     207                while (!(moving & resource->size)) { 
    191208                        resource->size <<= 1; 
    192209                        resource->align += 1; 
    193                         resource->gran  += 1; 
     210                        resource->gran += 1; 
    194211                } 
    195212                resource->limit = limit = moving | (resource->size - 1); 
    196213        } 
    197         /* 
    198          * some broken hardware has read-only registers that do not 
     214 
     215        /* Some broken hardware has read-only registers that do not 
    199216         * really size correctly. 
    200          * Example: the acer m7229 has BARs 1-4 normally read-only. 
     217         * Example: the Acer M7229 has BARs 1-4 normally read-only. 
    201218         * so BAR1 at offset 0x10 reads 0x1f1. If you size that register 
    202219         * by writing 0xffffffff to it, it will read back as 0x1f1 -- a 
     
    208225        if (moving == 0) { 
    209226                if (value != 0) { 
    210                         printk_debug( 
    211                                 "%s register %02lx(%08lx), read-only ignoring it\n", 
    212                                 dev_path(dev), index, value); 
     227                        printk_debug 
     228                            ("%s register %02lx(%08lx), read-only ignoring it\n", 
     229                             dev_path(dev), index, value); 
    213230                } 
    214231                resource->flags = 0; 
    215         } 
    216         else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { 
    217                 /* An I/O mapped base address */ 
     232        } else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { 
     233                /* An I/O mapped base address. */ 
    218234                attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK; 
    219235                resource->flags |= IORESOURCE_IO; 
    220                 /* I don't want to deal with 32bit I/O resources */ 
     236                /* I don't want to deal with 32bit I/O resources. */ 
    221237                resource->limit = 0xffff; 
    222         } 
    223         else { 
    224                 /* A Memory mapped base address */ 
     238        } else { 
     239                /* A Memory mapped base address. */ 
    225240                attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK; 
    226241                resource->flags |= IORESOURCE_MEM; 
     
    230245                attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK; 
    231246                if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) { 
    232                         /* 32bit limit */ 
     247                        /* 32bit limit. */ 
    233248                        resource->limit = 0xffffffffUL; 
    234                 } 
    235                 else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { 
    236                         /* 1MB limit */ 
     249                } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { 
     250                        /* 1MB limit. */ 
    237251                        resource->limit = 0x000fffffUL; 
    238                 } 
    239                 else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { 
    240                         /* 64bit limit */ 
     252                } else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { 
     253                        /* 64bit limit. */ 
    241254                        resource->limit = 0xffffffffffffffffULL; 
    242255                        resource->flags |= IORESOURCE_PCI64; 
    243                 } 
    244                 else { 
    245                         /* Invalid value */ 
     256                } else { 
     257                        /* Invalid value. */ 
     258                        printk_err("Broken BAR with value %lx\n", attr); 
     259                        printk_err(" on dev %s at index %02lx\n", 
     260                               dev_path(dev), index); 
    246261                        resource->flags = 0; 
    247262                } 
    248263        } 
    249         /* Don't let the limit exceed which bits can move */ 
     264        /* Don't let the limit exceed which bits can move. */ 
    250265        if (resource->limit > limit) { 
    251266                resource->limit = limit; 
    252267        } 
    253 #if 0 
    254         if (resource->flags) { 
    255                 printk_debug("%s %02x ->", 
    256                         dev_path(dev), resource->index); 
    257                 printk_debug(" value: 0x%08Lx zeroes: 0x%08Lx ones: 0x%08Lx attr: %08lx\n", 
    258                         value, zeroes, ones, attr); 
    259                 printk_debug( 
    260                         "%s %02x -> size: 0x%08Lx max: 0x%08Lx %s\n ", 
    261                         dev_path(dev), 
    262                         resource->index, 
    263                         resource->size, resource->limit, 
    264                         resource_type(resource)); 
    265         } 
    266 #endif 
    267268 
    268269        return resource; 
    269270} 
    270271 
     272/** 
     273 * Given a device and an index, read the size of the BAR for that register. 
     274 * 
     275 * @param dev Pointer to the device structure. 
     276 * @param index Address of the PCI configuration register. 
     277 */ 
    271278static void pci_get_rom_resource(struct device *dev, unsigned long index) 
    272279{ 
    273280        struct resource *resource; 
    274281        unsigned long value; 
    275         resource_t  moving; 
    276  
    277         if ((dev->on_mainboard) && (dev->rom_address == 0)) { 
    278                 //skip it if rom_address is not set in MB Config.lb 
    279                 return; 
    280         } 
    281  
    282         /* Initialize the resources to nothing */ 
     282        resource_t moving; 
     283 
     284        if ((dev->on_mainboard) && (dev->rom_address == 0)) { 
     285                /* Skip it if rom_address is not set in the MB Config.lb. */ 
     286                return; 
     287        } 
     288 
     289        /* Initialize the resources to nothing. */ 
    283290        resource = new_resource(dev, index); 
    284291 
    285         /* Get the initial value */ 
     292        /* Get the initial value. */ 
    286293        value = pci_read_config32(dev, index); 
    287294 
    288         /* See which bits move */ 
     295        /* See which bits move. */ 
    289296        moving = pci_moving_config32(dev, index); 
    290         /* clear the Enable bit */ 
     297 
     298        /* Clear the Enable bit. */ 
    291299        moving = moving & ~PCI_ROM_ADDRESS_ENABLE; 
    292300 
    293301        /* Find the resource constraints. 
    294          * 
    295302         * Start by finding the bits that move. From there: 
    296303         * - Size is the least significant bit of the bits that move. 
    297304         * - Limit is all of the bits that move plus all of the lower bits. 
    298          * See PCI Spec 6.2.5.1 ... 
     305         * See PCI Spec 6.2.5.1. 
    299306         */ 
    300307        if (moving) { 
     
    304311                        resource->size <<= 1; 
    305312                        resource->align += 1; 
    306                         resource->gran  += 1; 
     313                        resource->gran += 1; 
    307314                } 
    308315                resource->limit = moving | (resource->size - 1); 
    309         } 
    310  
    311         if (moving == 0) { 
     316                resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; 
     317        } else { 
    312318                if (value != 0) { 
    313                         printk_debug("%s register %02lx(%08lx), read-only ignoring it\n", 
    314                                      dev_path(dev), index, value); 
     319                        printk_debug 
     320                            ("%s register %02lx(%08lx), read-only ignoring it\n", 
     321                             dev_path(dev), index, value); 
    315322                } 
    316323                resource->flags = 0; 
    317         } else { 
    318                 resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; 
    319         } 
    320  
    321         /* for on board device with embedded ROM image, the ROM image is at 
     324        } 
     325 
     326        /* For on board device with embedded ROM image, the ROM image is at 
    322327         * fixed address specified in the Config.lb, the dev->rom_address is 
    323328         * inited by driver_pci_onboard_ops::enable_dev() */ 
    324329        if ((dev->on_mainboard) && (dev->rom_address != 0)) { 
    325                 resource->base   = dev->rom_address; 
     330                resource->base = dev->rom_address; 
    326331                resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY | 
    327                         IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     332                    IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    328333        } 
    329334 
     
    331336} 
    332337 
    333 /** Read the base address registers for a given device. 
    334  * @param dev Pointer to the dev structure 
    335  * @param howmany How many registers to read (6 for device, 2 for bridge) 
     338/** 
     339 * Read the base address registers for a given device. 
     340 * 
     341 * @param dev Pointer to the dev structure. 
     342 * @param howmany How many registers to read (6 for device, 2 for bridge). 
    336343 */ 
    337344static void pci_read_bases(struct device *dev, unsigned int howmany) 
     
    339346        unsigned long index; 
    340347 
    341         for(index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) { 
     348        for (index = PCI_BASE_ADDRESS_0; 
     349             (index < PCI_BASE_ADDRESS_0 + (howmany << 2));) { 
    342350                struct resource *resource; 
    343351                resource = pci_get_resource(dev, index); 
    344                 index += (resource->flags & IORESOURCE_PCI64)?8:4; 
     352                index += (resource->flags & IORESOURCE_PCI64) ? 8 : 4; 
    345353        } 
    346354 
     
    348356} 
    349357 
    350 static void pci_set_resource(struct device *dev, struct resource *resource); 
    351  
    352 static void pci_record_bridge_resource( 
    353         struct device *dev, resource_t moving, 
    354         unsigned index, unsigned long mask, unsigned long type) 
    355 { 
    356         /* Initiliaze the constraints on the current bus */ 
     358static void pci_record_bridge_resource(struct device *dev, resource_t moving, 
     359                                       unsigned index, unsigned long type) 
     360{ 
     361        /* Initialize the constraints on the current bus. */ 
    357362        struct resource *resource; 
    358         resource = 0; 
     363        resource = NULL; 
    359364        if (moving) { 
    360365                unsigned long gran; 
     
    364369                gran = 0; 
    365370                step = 1; 
    366                 while((moving & step) == 0) { 
     371                while ((moving & step) == 0) { 
    367372                        gran += 1; 
    368373                        step <<= 1; 
     
    371376                resource->align = gran; 
    372377                resource->limit = moving | (step - 1); 
    373                 resource->flags = type | IORESOURCE_PCI_BRIDGE; 
    374                 compute_allocate_resource(&dev->link[0], resource, mask, type); 
    375                 /* If there is nothing behind the resource, 
    376                  * clear it and forget it. 
    377                  */ 
    378                 if (resource->size == 0) { 
    379 #if CONFIG_PCI_64BIT_PREF_MEM == 1 
    380                         resource->base = moving; 
    381 #else 
    382                         resource->base = moving & 0xffffffff; 
    383 #endif 
    384                         resource->flags |= IORESOURCE_ASSIGNED; 
    385                         resource->flags &= ~IORESOURCE_STORED; 
    386                         pci_set_resource(dev, resource); 
    387                         resource->flags = 0; 
    388                 } 
     378                resource->flags = type | IORESOURCE_PCI_BRIDGE | 
     379                                  IORESOURCE_BRIDGE; 
    389380        } 
    390381        return; 
     
    395386        resource_t moving_base, moving_limit, moving; 
    396387 
    397         /* See if the bridge I/O resources are implemented */ 
    398         moving_base = ((uint32_t)pci_moving_config8(dev, PCI_IO_BASE)) << 8; 
    399         moving_base |= ((uint32_t)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; 
    400  
    401         moving_limit = ((uint32_t)pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; 
    402         moving_limit |= ((uint32_t)pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; 
     388        /* See if the bridge I/O resources are implemented. */ 
     389        moving_base = ((u32) pci_moving_config8(dev, PCI_IO_BASE)) << 8; 
     390        moving_base |= 
     391            ((u32) pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; 
     392 
     393        moving_limit = ((u32) pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; 
     394        moving_limit |= 
     395            ((u32) pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; 
    403396 
    404397        moving = moving_base & moving_limit; 
    405398 
    406         /* Initialize the io space constraints on the current bus */ 
    407         pci_record_bridge_resource( 
    408                 dev, moving, PCI_IO_BASE, 
    409                 IORESOURCE_IO, IORESOURCE_IO); 
    410  
    411  
    412         /* See if the bridge prefmem resources are implemented */ 
    413         moving_base =  ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; 
    414         moving_base |= ((resource_t)pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32; 
    415  
    416         moving_limit =  ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16; 
    417         moving_limit |= ((resource_t)pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32; 
     399        /* Initialize the I/O space constraints on the current bus. */ 
     400        pci_record_bridge_resource(dev, moving, PCI_IO_BASE, IORESOURCE_IO); 
     401 
     402        /* See if the bridge prefmem resources are implemented. */ 
     403        moving_base = 
     404            ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; 
     405        moving_base |= 
     406            ((resource_t) pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 
     407            32; 
     408 
     409        moving_limit = 
     410            ((resource_t) pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 
     411            16; 
     412        moving_limit |= 
     413            ((resource_t) pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 
     414            32; 
    418415 
    419416        moving = moving_base & moving_limit; 
    420         /* Initiliaze the prefetchable memory constraints on the current bus */ 
    421         pci_record_bridge_resource( 
    422                 dev, moving, PCI_PREF_MEMORY_BASE, 
    423                 IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    424                 IORESOURCE_MEM | IORESOURCE_PREFETCH); 
    425  
    426  
    427         /* See if the bridge mem resources are implemented */ 
    428         moving_base = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; 
    429         moving_limit = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; 
     417        /* Initialize the prefetchable memory constraints on the current bus. */ 
     418        pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE, 
     419                                   IORESOURCE_MEM | IORESOURCE_PREFETCH); 
     420 
     421        /* See if the bridge mem resources are implemented. */ 
     422        moving_base = ((u32) pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; 
     423        moving_limit = ((u32) pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; 
    430424 
    431425        moving = moving_base & moving_limit; 
    432426 
    433         /* Initialize the memory resources on the current bus */ 
    434         pci_record_bridge_resource( 
    435                 dev, moving, PCI_MEMORY_BASE, 
    436                 IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    437                 IORESOURCE_MEM); 
     427        /* Initialize the memory resources on the current bus. */ 
     428        pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE, 
     429                                   IORESOURCE_MEM); 
    438430 
    439431        compact_resources(dev); 
     
    453445} 
    454446 
     447void pci_domain_read_resources(struct device *dev) 
     448{ 
     449        struct resource *res; 
     450 
     451        /* Initialize the system-wide I/O space constraints. */ 
     452        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
     453        res->limit = 0xffffUL; 
     454        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     455                     IORESOURCE_ASSIGNED; 
     456 
     457        /* Initialize the system-wide memory resources constraints. */ 
     458        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
     459        res->limit = 0xffffffffULL; 
     460        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     461                     IORESOURCE_ASSIGNED; 
     462} 
     463 
    455464static void pci_set_resource(struct device *dev, struct resource *resource) 
    456465{ 
    457466        resource_t base, end; 
    458467 
    459         /* Make certain the resource has actually been set */ 
     468        /* Make certain the resource has actually been assigned a value. */ 
    460469        if (!(resource->flags & IORESOURCE_ASSIGNED)) { 
    461                 printk_err("ERROR: %s %02lx %s size: 0x%010Lx not assigned\n", 
    462                         dev_path(dev), resource->index, 
    463                         resource_type(resource), 
    464                         resource->size); 
     470                printk_err("ERROR: %s %02lx %s size: 0x%010llx not assigned\n", 
     471                           dev_path(dev), resource->index, 
     472                           resource_type(resource), resource->size); 
    465473                return; 
    466474        } 
    467475 
    468         /* If I have already stored this resource don't worry about it */ 
     476        /* If I have already stored this resource don't worry about it. */ 
    469477        if (resource->flags & IORESOURCE_STORED) { 
    470478                return; 
    471479        } 
    472480 
    473         /* If the resources is substractive don't worry about it */ 
     481        /* If the resource is subtractive don't worry about it. */ 
    474482        if (resource->flags & IORESOURCE_SUBTRACTIVE) { 
    475483                return; 
    476484        } 
    477485 
    478         /* Only handle PCI memory and IO resources for now */ 
    479         if (!(resource->flags & (IORESOURCE_MEM |IORESOURCE_IO))) 
     486        /* Only handle PCI memory and I/O resources for now. */ 
     487        if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) 
    480488                return; 
    481489 
    482         /* Enable the resources in the command register */ 
     490        /* Enable the resources in the command register. */ 
    483491        if (resource->size) { 
    484492                if (resource->flags & IORESOURCE_MEM) { 
     
    492500                } 
    493501        } 
    494         /* Get the base address */ 
     502        /* Get the base address. */ 
    495503        base = resource->base; 
    496504 
    497         /* Get the end */ 
     505        /* Get the end. */ 
    498506        end = resource_end(resource); 
    499507 
    500         /* Now store the resource */ 
     508        /* Now store the resource. */ 
    501509        resource->flags |= IORESOURCE_STORED; 
     510 
     511        /* PCI Bridges have no enable bit.  They are disabled if the base of 
     512         * the range is greater than the limit.  If the size is zero, disable 
     513         * by setting the base = limit and end = limit - 2^gran. 
     514         */ 
     515        if (resource->size == 0 && (resource->flags & IORESOURCE_PCI_BRIDGE)) { 
     516                base = resource->limit; 
     517                end = resource->limit - (1 << resource->gran); 
     518                resource->base = base; 
     519        } 
     520 
    502521        if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) { 
    503522                unsigned long base_lo, base_hi; 
    504                 /* 
    505                  * some chipsets allow us to set/clear the IO bit. 
    506                  * (e.g. VIA 82c686a.) So set it to be safe) 
     523                /* Some chipsets allow us to set/clear the I/O bit 
     524                 * (e.g. VIA 82c686a). So set it to be safe. 
    507525                 */ 
    508526                base_lo = base & 0xffffffff; 
     
    515533                        pci_write_config32(dev, resource->index + 4, base_hi); 
    516534                } 
    517         } 
    518         else if (resource->index == PCI_IO_BASE) { 
    519                 /* set the IO ranges */ 
    520                 compute_allocate_resource(&dev->link[0], resource, 
    521                         IORESOURCE_IO, IORESOURCE_IO); 
    522                 pci_write_config8(dev,  PCI_IO_BASE, base >> 8); 
     535        } else if (resource->index == PCI_IO_BASE) { 
     536                /* Set the I/O ranges. */ 
     537                pci_write_config8(dev, PCI_IO_BASE, base >> 8); 
    523538                pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16); 
    524                 pci_write_config8(dev,  PCI_IO_LIMIT, end >> 8); 
     539                pci_write_config8(dev, PCI_IO_LIMIT, end >> 8); 
    525540                pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16); 
    526         } 
    527         else if (resource->index == PCI_MEMORY_BASE) { 
    528                 /* set the memory range  */ 
    529                 compute_allocate_resource(&dev->link[0], resource, 
    530                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    531                         IORESOURCE_MEM); 
     541        } else if (resource->index == PCI_MEMORY_BASE) { 
     542                /* Set the memory range. */ 
    532543                pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16); 
    533544                pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16); 
    534         } 
    535         else if (resource->index == PCI_PREF_MEMORY_BASE) { 
    536                 /* set the prefetchable memory range */ 
    537                 compute_allocate_resource(&dev->link[0], resource, 
    538                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    539                         IORESOURCE_MEM | IORESOURCE_PREFETCH); 
     545        } else if (resource->index == PCI_PREF_MEMORY_BASE) { 
     546                /* Set the prefetchable memory range. */ 
    540547                pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16); 
    541548                pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32); 
    542549                pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16); 
    543550                pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32); 
    544         } 
    545         else { 
    546                 /* Don't let me think I stored the resource */ 
     551        } else { 
     552                /* Don't let me think I stored the resource. */ 
    547553                resource->flags &= ~IORESOURCE_STORED; 
    548554                printk_err("ERROR: invalid resource->index %lx\n", 
    549                         resource->index); 
     555                           resource->index); 
    550556        } 
    551557        report_resource_stored(dev, resource, ""); 
     
    557563        struct resource *resource, *last; 
    558564        unsigned link; 
    559         uint8_t line; 
     565        u8 line; 
    560566 
    561567        last = &dev->resource[dev->resources]; 
    562568 
    563         for(resource = &dev->resource[0]; resource < last; resource++) { 
     569        for (resource = &dev->resource[0]; resource < last; resource++) { 
    564570                pci_set_resource(dev, resource); 
    565571        } 
    566         for(link = 0; link < dev->links; link++) { 
     572        for (link = 0; link < dev->links; link++) { 
    567573                struct bus *bus; 
    568574                bus = &dev->link[link]; 
     
    572578        } 
    573579 
    574         /* set a default latency timer */ 
     580        /* Set a default latency timer. */ 
    575581        pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40); 
    576582 
    577         /* set a default secondary latency timer */ 
     583        /* Set a default secondary latency timer. */ 
    578584        if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) { 
    579585                pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40); 
    580586        } 
    581587 
    582         /* zero the irq settings */ 
     588        /* Zero the IRQ settings. */ 
    583589        line = pci_read_config8(dev, PCI_INTERRUPT_PIN); 
    584590        if (line) { 
    585591                pci_write_config8(dev, PCI_INTERRUPT_LINE, 0); 
    586592        } 
    587         /* set the cache line size, so far 64 bytes is good for everyone */ 
     593        /* Set the cache line size, so far 64 bytes is good for everyone. */ 
    588594        pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2); 
    589595} 
     
    592598{ 
    593599        const struct pci_operations *ops; 
    594         uint16_t command; 
    595  
    596         /* Set the subsystem vendor and device id for mainboard devices */ 
     600        u16 command; 
     601 
     602        /* Set the subsystem vendor and device id for mainboard devices. */ 
    597603        ops = ops_pci(dev); 
    598604        if (dev->on_mainboard && ops && ops->set_subsystem) { 
    599605                printk_debug("%s subsystem <- %02x/%02x\n", 
    600                         dev_path(dev), 
    601                         CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, 
    602                         CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); 
     606                             dev_path(dev), 
     607                             CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, 
     608                             CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); 
    603609                ops->set_subsystem(dev, 
    604                         CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, 
    605                         CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); 
     610                                   CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, 
     611                                   CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); 
    606612        } 
    607613        command = pci_read_config16(dev, PCI_COMMAND); 
    608614        command |= dev->command; 
     615        /* v3 has 
     616         * command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR);  // Error check. 
     617         */ 
    609618        printk_debug("%s cmd <- %02x\n", dev_path(dev), command); 
    610619        pci_write_config16(dev, PCI_COMMAND, command); 
     
    613622void pci_bus_enable_resources(struct device *dev) 
    614623{ 
    615         uint16_t ctrl; 
    616         /* enable IO in command register if there is VGA card 
    617          * connected with (even it does not claim IO resource) */ 
     624        u16 ctrl; 
     625 
     626        /* Enable I/O in command register if there is VGA card 
     627         * connected with (even it does not claim I/O resource). 
     628         */ 
    618629        if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA) 
    619630                dev->command |= PCI_COMMAND_IO; 
    620631        ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); 
    621632        ctrl |= dev->link[0].bridge_ctrl; 
    622         ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */ 
     633        ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR);  /* Error check. */ 
    623634        printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); 
    624635        pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); 
    625636 
    626637        pci_dev_enable_resources(dev); 
    627  
    628638        enable_childrens_resources(dev); 
    629639} 
     
    641651} 
    642652 
    643 void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device) 
     653void pci_dev_set_subsystem(struct device *dev, unsigned vendor, unsigned device) 
    644654{ 
    645655        pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, 
    646                 ((device & 0xffff) << 16) | (vendor & 0xffff)); 
     656                           ((device & 0xffff) << 16) | (vendor & 0xffff)); 
    647657} 
    648658 
     
    651661{ 
    652662#if CONFIG_PCI_ROM_RUN == 1 || CONFIG_VGA_ROM_RUN == 1 
    653         void run_bios(struct device * dev, unsigned long addr); 
     663        void run_bios(struct device *dev, unsigned long addr); 
    654664        struct rom_header *rom, *ram; 
    655665 
     
    659669         * all other option ROM types. 
    660670         */ 
    661         if ((dev->class>>8)!=PCI_CLASS_DISPLAY_VGA) 
     671        if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) 
    662672                return; 
    663673#endif 
     
    686696 
    687697struct device_operations default_pci_ops_dev = { 
    688         .read_resources   = pci_dev_read_resources, 
    689         .set_resources    = pci_dev_set_resources, 
     698        .read_resources = pci_dev_read_resources, 
     699        .set_resources = pci_dev_set_resources, 
    690700        .enable_resources = pci_dev_enable_resources, 
    691         .init            = pci_dev_init, 
    692         .scan_bus        = 0, 
    693         .enable           = 0, 
    694         .ops_pci          = &pci_dev_ops_pci, 
     701        .init = pci_dev_init, 
     702        .scan_bus = 0, 
     703        .enable = 0, 
     704        .ops_pci = &pci_dev_ops_pci, 
    695705}; 
    696706 
     
    701711 
    702712struct device_operations default_pci_ops_bus = { 
    703         .read_resources   = pci_bus_read_resources, 
    704         .set_resources    = pci_dev_set_resources, 
     713        .read_resources = pci_bus_read_resources, 
     714        .set_resources = pci_dev_set_resources, 
    705715        .enable_resources = pci_bus_enable_resources, 
    706         .init            = 0, 
    707         .scan_bus        = pci_scan_bridge, 
    708         .enable           = 0, 
    709         .reset_bus        = pci_bus_reset, 
    710         .ops_pci          = &pci_bus_ops_pci, 
     716        .init = 0, 
     717        .scan_bus = pci_scan_bridge, 
     718        .enable = 0, 
     719        .reset_bus = pci_bus_reset, 
     720        .ops_pci = &pci_bus_ops_pci, 
    711721}; 
    712722 
     
    714724 * @brief Detect the type of downstream bridge 
    715725 * 
    716  * This function is a heuristic to detect which type 
    717  * of bus is downstream of a pci to pci bridge.  This 
    718  * functions by looking for various capability blocks 
    719  * to figure out the type of downstream bridge.  PCI-X 
    720  * PCI-E, and Hypertransport all seem to have appropriate 
    721  * capabilities. 
     726 * This function is a heuristic to detect which type of bus is downstream 
     727 * of a PCI-to-PCI bridge. This functions by looking for various capability 
     728 * blocks to figure out the type of downstream bridge. PCI-X, PCI-E, and 
     729 * Hypertransport all seem to have appropriate capabilities. 
    722730 * 
    723731 * When only a PCI-Express capability is found the type 
    724732 * is examined to see which type of bridge we have. 
    725733 * 
    726  * @param dev 
    727  * 
    728  * @return appropriate bridge operations 
     734 * @param dev Pointer to the device structure of the bridge. 
     735 * @return Appropriate bridge operations. 
    729736 */ 
    730737static struct device_operations *get_pci_bridge_ops(device_t dev) 
     
    744751#if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1 
    745752        pos = 0; 
    746         while((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) { 
     753        while ((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) { 
    747754                unsigned flags; 
    748755                flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); 
     
    750757                        /* Host or Secondary Interface */ 
    751758                        printk_debug("%s subbordinate bus Hypertransport\n", 
    752                                 dev_path(dev)); 
     759                                     dev_path(dev)); 
    753760                        return &default_ht_ops_bus; 
    754761                } 
     
    760767                unsigned flags; 
    761768                flags = pci_read_config16(dev, pos + PCI_EXP_FLAGS); 
    762                 switch((flags & PCI_EXP_FLAGS_TYPE) >> 4) { 
     769                switch ((flags & PCI_EXP_FLAGS_TYPE) >> 4) { 
    763770                case PCI_EXP_TYPE_ROOT_PORT: 
    764771                case PCI_EXP_TYPE_UPSTREAM: 
    765772                case PCI_EXP_TYPE_DOWNSTREAM: 
    766773                        printk_debug("%s subbordinate bus PCI Express\n", 
    767                                 dev_path(dev)); 
     774                                     dev_path(dev)); 
    768775                        return &default_pciexp_ops_bus; 
    769776                case PCI_EXP_TYPE_PCI_BRIDGE: 
    770                         printk_debug("%s subbordinate PCI\n", 
    771                                 dev_path(dev)); 
     777                        printk_debug("%s subbordinate PCI\n", dev_path(dev)); 
    772778                        return &default_pci_ops_bus; 
    773779                default: 
     
    780786 
    781787/** 
    782  * @brief Set up PCI device operation 
    783  * 
    784  * 
    785  * @param dev 
    786  * 
     788 * Set up PCI device operation.  Check if it already has a driver.  If not, use 
     789 * find_device_operations, or set to a default based on type. 
     790 * 
     791 * @param dev Pointer to the device whose pci_ops you want to set. 
    787792 * @see pci_drivers 
    788793 */ 
     
    795800 
    796801        /* Look through the list of setup drivers and find one for 
    797          * this pci device 
    798          */ 
    799         for(driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) { 
     802         * this PCI device. 
     803         */ 
     804        for (driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) { 
    800805                if ((driver->vendor == dev->vendor) && 
    801                         (driver->device == dev->device)) 
    802                 { 
     806                    (driver->device == dev->device)) { 
    803807                        dev->ops = driver->ops; 
    804808                        printk_spew("%s [%04x/%04x] %sops\n", 
    805                                 dev_path(dev), 
    806                                 driver->vendor, driver->device, 
    807                                 (driver->ops->scan_bus?"bus ":"")); 
     809                                    dev_path(dev), 
     810                                    driver->vendor, driver->device, 
     811                                    (driver->ops->scan_bus ? "bus " : "")); 
    808812                        return; 
    809813                } 
     
    811815 
    812816        /* If I don't have a specific driver use the default operations */ 
    813         switch(dev->hdr_type & 0x7f) {  /* header type */ 
     817        switch (dev->hdr_type & 0x7f) { /* header type */ 
    814818        case PCI_HEADER_TYPE_NORMAL:    /* standard header */ 
    815819                if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) 
     
    828832#endif 
    829833        default: 
    830         bad: 
     834              bad: 
    831835                if (dev->enabled) { 
    832836                        printk_err("%s [%04x/%04x/%06x] has unknown header " 
    833                                 "type %02x, ignoring.\n", 
    834                                 dev_path(dev), 
    835                                 dev->vendor, dev->device, 
    836                                 dev->class >> 8, dev->hdr_type); 
     837                                   "type %02x, ignoring.\n", 
     838                                   dev_path(dev), 
     839                                   dev->vendor, dev->device, 
     840                                   dev->class >> 8, dev->hdr_type); 
    837841                } 
    838842        } 
    839843        return; 
    840844} 
    841  
    842  
    843845 
    844846/** 
     
    849851 * removes the device structure from the linked list. 
    850852 * 
    851  * @param list the device structure list 
    852  * @param devfn a device/function number 
    853  * 
    854  * @return pointer to the device structure found or null of we have not 
     853 * @param list The device structure list. 
     854 * @param devfn A device/function number. 
     855 * 
     856 * @return Pointer to the device structure found or NULL if we have not 
    855857 *         allocated a device for this devfn yet. 
    856858 */ 
     
    859861        struct device *dev; 
    860862        dev = 0; 
    861         for(; *list; list = &(*list)->sibling) { 
     863        for (; *list; list = &(*list)->sibling) { 
    862864                if ((*list)->path.type != DEVICE_PATH_PCI) { 
    863865                        printk_err("child %s not a pci device\n", 
    864                                 dev_path(*list)); 
     866                                   dev_path(*list)); 
    865867                        continue; 
    866868                } 
    867869                if ((*list)->path.pci.devfn == devfn) { 
    868                         /* Unlink from the list */ 
     870                        /* Unlink from the list. */ 
    869871                        dev = *list; 
    870872                        *list = (*list)->sibling; 
    871                         dev->sibling = 0; 
     873                        dev->sibling = NULL; 
    872874                        break; 
    873875                } 
    874876        } 
    875         /* Just like alloc_dev add the device to the  list of device on the bus. 
    876          * When the list of devices was formed we removed all of the parents 
    877          * children, and now we are interleaving static and dynamic devices in 
    878          * order on the bus. 
     877 
     878        /* Just like alloc_dev() add the device to the list of devices on the 
     879         * bus. When the list of devices was formed we removed all of the 
     880         * parents children, and now we are interleaving static and dynamic 
     881         * devices in order on the bus. 
    879882         */ 
    880883        if (dev) { 
    881                 device_t child; 
    882                 /* Find the last child of our parent */ 
    883                 for(child = dev->bus->children; child && child->sibling; ) { 
     884                struct device *child; 
     885                /* Find the last child of our parent. */ 
     886                for (child = dev->bus->children; child && child->sibling;) { 
    884887                        child = child->sibling; 
    885888                } 
    886                 /* Place the device on the list of children of it's parent. */ 
     889                /* Place the device on the list of children of its parent. */ 
    887890                if (child) { 
    888891                        child->sibling = dev; 
     
    898901 * @brief Scan a PCI bus. 
    899902 * 
    900  * Determine the existence of a given PCI device. 
     903 * Determine the existence of a given PCI device. Allocate a new struct device 
     904 * if dev==NULL was passed in and the device exists in hardware. 
    901905 * 
    902906 * @param bus pointer to the bus structure 
     
    906910 *         or the NULL if no device is found. 
    907911 */ 
    908 device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn) 
    909 { 
    910         uint32_t id, class; 
    911         uint8_t hdr_type; 
    912  
    913         /* Detect if a device is present */ 
     912device_t pci_probe_dev(device_t dev, struct bus * bus, unsigned devfn) 
     913{ 
     914        u32 id, class; 
     915        u8 hdr_type; 
     916 
     917        /* Detect if a device is present. */ 
    914918        if (!dev) { 
    915919                struct device dummy; 
    916                 dummy.bus              = bus; 
    917                 dummy.path.type        = DEVICE_PATH_PCI; 
     920                dummy.bus = bus; 
     921                dummy.path.type = DEVICE_PATH_PCI; 
    918922                dummy.path.pci.devfn = devfn; 
    919923                id = pci_read_config32(&dummy, PCI_VENDOR_ID); 
    920                 /* Have we found somthing? 
     924                /* Have we found something? 
    921925                 * Some broken boards return 0 if a slot is empty. 
    922926                 */ 
    923                 if (    (id == 0xffffffff) || (id == 0x00000000) || 
    924                         (id == 0x0000ffff) || (id == 0xffff0000)) 
    925                 { 
     927                if ((id == 0xffffffff) || (id == 0x00000000) || 
     928                    (id == 0x0000ffff) || (id == 0xffff0000)) { 
    926929                        printk_spew("%s, bad id 0x%x\n", dev_path(&dummy), id); 
    927930                        return NULL; 
    928931                } 
    929932                dev = alloc_dev(bus, &dummy.path); 
    930         } 
    931         else { 
    932                 /* Enable/disable the device.  Once we have 
    933                  * found the device specific operations this 
    934                  * operations we will disable the device with 
    935                  * those as well. 
     933        } else { 
     934                /* Enable/disable the device. Once we have found the device- 
     935                 * specific operations this operations we will disable the 
     936                 * device with those as well. 
    936937                 * 
    937938                 * This is geared toward devices that have subfunctions 
     
    939940                 * 
    940941                 * If a device is a stuff option on the motherboard 
    941                  * it may be absent and enable_dev must cope. 
    942                  * 
     942                 * it may be absent and enable_dev() must cope. 
    943943                 */ 
    944                 /* Run the magice enable sequence for the device */ 
     944                /* Run the magic enable sequence for the device. */ 
    945945                if (dev->chip_ops && dev->chip_ops->enable_dev) { 
    946946                        dev->chip_ops->enable_dev(dev); 
    947947                } 
    948                 /* Now read the vendor and device id */ 
     948                /* Now read the vendor and device ID. */ 
    949949                id = pci_read_config32(dev, PCI_VENDOR_ID); 
    950950 
    951  
    952                 /* If the device does not have a pci id disable it. 
    953                  * Possibly this is because we have already disabled 
    954                  * the device.  But this also handles optional devices 
    955                  * that may not always show up. 
     951                /* If the device does not have a PCI ID disable it. Possibly 
     952                 * this is because we have already disabled the device. But 
     953                 * this also handles optional devices that may not always 
     954                 * show up. 
    956955                 */ 
    957956                /* If the chain is fully enumerated quit */ 
    958                 if (    (id == 0xffffffff) || (id == 0x00000000) || 
    959                         (id == 0x0000ffff) || (id == 0xffff0000)) 
    960                 { 
     957                if ((id == 0xffffffff) || (id == 0x00000000) || 
     958                    (id == 0x0000ffff) || (id == 0xffff0000)) { 
    961959                        if (dev->enabled) { 
    962960                                printk_info("Disabling static device: %s\n", 
    963                                         dev_path(dev)); 
     961                                            dev_path(dev)); 
    964962                                dev->enabled = 0; 
    965963                        } 
     
    967965                } 
    968966        } 
    969         /* Read the rest of the pci configuration information */ 
     967        /* Read the rest of the PCI configuration information. */ 
    970968        hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE); 
    971969        class = pci_read_config32(dev, PCI_CLASS_REVISION); 
    972970 
    973         /* Store the interesting information in the device structure */ 
     971        /* Store the interesting information in the device structure. */ 
    974972        dev->vendor = id & 0xffff; 
    975973        dev->device = (id >> 16) & 0xffff; 
    976974        dev->hdr_type = hdr_type; 
    977         /* class code, the upper 3 bytes of PCI_CLASS_REVISION */ 
     975 
     976        /* Class code, the upper 3 bytes of PCI_CLASS_REVISION. */ 
    978977        dev->class = class >> 8; 
    979978 
    980  
    981         /* Architectural/System devices always need to 
    982          * be bus masters. 
    983          */ 
     979        /* Architectural/System devices always need to be bus masters. */ 
    984980        if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM) { 
    985981                dev->command |= PCI_COMMAND_MASTER; 
    986982        } 
    987         /* Look at the vendor and device id, or at least the 
    988          * header type and class and figure out which set of 
    989          * configuration methods to use.  Unless we already 
    990          * have some pci ops. 
     983        /* Look at the vendor and device ID, or at least the header type and 
     984         * class and figure out which set of configuration methods to use. 
     985         * Unless we already have some PCI ops. 
    991986         */ 
    992987        set_pci_ops(dev); 
    993988 
    994         /* Now run the magic enable/disable sequence for the device */ 
     989        /* Now run the magic enable/disable sequence for the device. */ 
    995990        if (dev->ops && dev->ops->enable) { 
    996991                dev->ops->enable(dev); 
    997992        } 
    998993 
    999  
    1000         /* Display the device and error if we don't have some pci operations 
    1001          * for it. 
    1002          */ 
     994        /* Display the device. */ 
    1003995        printk_debug("%s [%04x/%04x] %s%s\n", 
    1004                 dev_path(dev), 
    1005                 dev->vendor, dev->device, 
    1006                 dev->enabled?"enabled": "disabled", 
    1007                 dev->ops?"" : " No operations" 
    1008                 ); 
     996                     dev_path(dev), 
     997                     dev->vendor, dev->device, 
     998                     dev->enabled ? "enabled" : "disabled", 
     999                     dev->ops ? "" : " No operations"); 
    10091000 
    10101001        return dev; 
     
    10281019 */ 
    10291020unsigned int pci_scan_bus(struct bus *bus, 
    1030         unsigned min_devfn, unsigned max_devfn, 
    1031         unsigned int max) 
     1021                          unsigned min_devfn, unsigned max_devfn, 
     1022                          unsigned int max) 
    10321023{ 
    10331024        unsigned int devfn; 
    1034         device_t old_devices; 
    1035         device_t child; 
     1025        struct device *old_devices; 
     1026        struct device *child; 
    10361027 
    10371028#if CONFIG_PCI_BUS_SEGN_BITS 
    1038         printk_debug("PCI: pci_scan_bus for bus %04x:%02x\n", bus->secondary >> 8, bus->secondary & 0xff); 
     1029        printk_debug("PCI: pci_scan_bus for bus %04x:%02x\n", 
     1030                     bus->secondary >> 8, bus->secondary & 0xff); 
    10391031#else 
    10401032        printk_debug("PCI: pci_scan_bus for bus %02x\n", bus->secondary); 
     
    10421034 
    10431035        old_devices = bus->children; 
    1044         bus->children = 0; 
     1036        bus->children = NULL; 
    10451037 
    10461038        post_code(0x24); 
    1047         /* probe all devices/functions on this bus with some optimization for 
    1048          * non-existence and single funcion devices 
     1039        /* Probe all devices/functions on this bus with some optimization for 
     1040         * non-existence and single function devices. 
    10491041         */ 
    10501042        for (devfn = min_devfn; devfn <= max_devfn; devfn++) { 
    1051                 device_t dev; 
     1043                struct device *dev; 
    10521044 
    10531045                /* First thing setup the device structure */ 
    10541046                dev = pci_scan_get_dev(&old_devices, devfn); 
    10551047 
    1056                 /* See if a device is present and setup the device 
    1057                  * structure. 
    1058                  */ 
     1048                /* See if a device is present and setup the device structure. */ 
    10591049                dev = pci_probe_dev(dev, bus, devfn); 
    10601050 
    1061                 /* if this is not a multi function device, 
    1062                  * or the device is not present don't waste 
    1063                  * time probing another function. 
     1051                /* If this is not a multi function device, or the device is 
     1052                 * not present don't waste time probing another function. 
    10641053                 * Skip to next device. 
    10651054                 */ 
    10661055                if ((PCI_FUNC(devfn) == 0x00) && 
    1067                         (!dev || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) 
    1068                 { 
     1056                    (!dev 
     1057                     || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) { 
    10691058                        devfn += 0x07; 
    10701059                } 
     
    10721061        post_code(0x25); 
    10731062 
    1074         /* Die if any left over static devices are are found. 
     1063        /* Warn if any leftover static devices are are found. 
    10751064         * There's probably a problem in the Config.lb. 
    1076         */ 
    1077         if(old_devices) { 
     1065         */ 
     1066        if (old_devices) { 
    10781067                device_t left; 
    1079                 for(left = old_devices; left; left = left->sibling) { 
    1080                         printk_err("%s\n", dev_path(left)); 
    1081                 } 
    1082                 printk_warning("PCI: Left over static devices.  Check your mainboard Config.lb\n"); 
    1083         } 
    1084  
    1085         /* For all children that implement scan_bus (i.e. bridges) 
     1068                printk_warning("PCI: Left over static devices:\n"); 
     1069                for (left = old_devices; left; left = left->sibling) { 
     1070                        printk_warning("%s\n", dev_path(left)); 
     1071                } 
     1072                printk_warning("PCI: Check your mainboard Config.lb.\n"); 
     1073        } 
     1074 
     1075        /* For all children that implement scan_bus() (i.e. bridges) 
    10861076         * scan the bus behind that child. 
    10871077         */ 
    1088         for(child = bus->children; child; child = child->sibling) { 
     1078        for (child = bus->children; child; child = child->sibling) { 
    10891079                max = scan_bus(child, max); 
    10901080        } 
    10911081 
    1092         /* 
    1093          * We've scanned the bus and so we know all about what's on 
    1094          * the other side of any bridges that may be on this bus plus 
    1095          * any devices. 
    1096          * 
     1082        /* We've scanned the bus and so we know all about what's on the other 
     1083         * side of any bridges that may be on this bus plus any devices. 
    10971084         * Return how far we've got finding sub-buses. 
    10981085         */ 
     
    11021089} 
    11031090 
    1104  
    11051091/** 
    11061092 * @brief Scan a PCI bridge and the buses behind the bridge. 
     
    11111097 * This function is the default scan_bus() method for PCI bridge devices. 
    11121098 * 
    1113  * @param dev pointer to the bridge device 
    1114  * @param max the highest bus number assgined up to now 
    1115  * 
    1116  * @return The maximum bus number found, after scanning all subordinate busses 
     1099 * @param dev Pointer to the bridge device. 
     1100 * @param max The highest bus number assigned up to now. 
     1101 * @return The maximum bus number found, after scanning all subordinate buses. 
    11171102 */ 
    11181103unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, 
    1119         unsigned int (*do_scan_bus)(struct bus *bus, 
    1120                 unsigned min_devfn, unsigned max_devfn, unsigned int max)) 
     1104                                unsigned int (*do_scan_bus) (struct bus * bus, 
     1105                                                             unsigned min_devfn, 
     1106                                                             unsigned max_devfn, 
     1107                                                             unsigned int max)) 
    11211108{ 
    11221109        struct bus *bus; 
    1123         uint32_t buses; 
    1124         uint16_t cr; 
     1110        u32 buses; 
     1111        u16 cr; 
    11251112 
    11261113        printk_spew("%s for %s\n", __func__, dev_path(dev)); 
     
    11421129        pci_write_config16(dev, PCI_STATUS, 0xffff); 
    11431130 
    1144         /* 
    1145          * Read the existing primary/secondary/subordinate bus 
     1131        /* Read the existing primary/secondary/subordinate bus 
    11461132         * number configuration. 
    11471133         */ 
     
    11531139         */ 
    11541140        buses &= 0xff000000; 
    1155         buses |= (((unsigned int) (dev->bus->secondary) << 0) | 
    1156                 ((unsigned int) (bus->secondary) << 8) | 
    1157                 ((unsigned int) (bus->subordinate) << 16)); 
     1141        buses |= (((unsigned int)(dev->bus->secondary) << 0) | 
     1142                  ((unsigned int)(bus->secondary) << 8) | 
     1143                  ((unsigned int)(bus->subordinate) << 16)); 
    11581144        pci_write_config32(dev, PCI_PRIMARY_BUS, buses); 
    11591145 
     
    11671153         */ 
    11681154        bus->subordinate = max; 
    1169         buses = (buses & 0xff00ffff) | 
    1170                 ((unsigned int) (bus->subordinate) << 16); 
     1155        buses = (buses & 0xff00ffff) | ((unsigned int)(bus->subordinate) << 16); 
    11711156        pci_write_config32(dev, PCI_PRIMARY_BUS, buses); 
    11721157        pci_write_config16(dev, PCI_COMMAND, cr); 
     
    11841169 * This function is the default scan_bus() method for PCI bridge devices. 
    11851170 * 
    1186  * @param dev pointer to the bridge device 
     1171 * @param dev Pointer to the bridge device. 
     1172 * @param max The highest bus number assigned up to now. 
     1173 * @return The maximum bus number found, after scanning all subordinate buses. 
     1174 */ 
     1175unsigned int pci_scan_bridge(struct device *dev, unsigned int max) 
     1176{ 
     1177        return do_pci_scan_bridge(dev, max, pci_scan_bus); 
     1178} 
     1179 
     1180/** 
     1181 * @brief Scan a PCI domain. 
     1182 * 
     1183 * This function is the default scan_bus() method for PCI domains. 
     1184 * 
     1185 * @param dev pointer to the domain 
    11871186 * @param max the highest bus number assgined up to now 
    11881187 * 
    11891188 * @return The maximum bus number found, after scanning all subordinate busses 
    11901189 */ 
    1191 unsigned int pci_scan_bridge(struct device *dev, unsigned int max) 
    1192 { 
    1193         return do_pci_scan_bridge(dev, max, pci_scan_bus); 
    1194 } 
    1195  
    1196 /* 
    1197     Tell the EISA int controller this int must be level triggered 
    1198     THIS IS A KLUDGE -- sorry, this needs to get cleaned up. 
    1199 */ 
     1190unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
     1191{ 
     1192        max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
     1193        return max; 
     1194} 
     1195 
     1196/** 
     1197 * Tell the EISA int controller this int must be level triggered. 
     1198 * 
     1199 * THIS IS A KLUDGE -- sorry, this needs to get cleaned up. 
     1200 */ 
    12001201void pci_level_irq(unsigned char intNum) 
    12011202{ 
    1202         unsigned short intBits = inb(0x4d0) | (((unsigned) inb(0x4d1)) << 8); 
     1203        unsigned short intBits = inb(0x4d0) | (((unsigned)inb(0x4d1)) << 8); 
    12031204 
    12041205        printk_spew("%s: current ints are 0x%x\n", __func__, intBits); 
     
    12071208        printk_spew("%s: try to set ints 0x%x\n", __func__, intBits); 
    12081209 
    1209         // Write new values 
    1210         outb((unsigned char) intBits, 0x4d0); 
    1211         outb((unsigned char) (intBits >> 8), 0x4d1); 
    1212  
    1213         /* this seems like an error but is not ... */ 
    1214 #if 1 
     1210        /* Write new values. */ 
     1211        outb((unsigned char)intBits, 0x4d0); 
     1212        outb((unsigned char)(intBits >> 8), 0x4d1); 
     1213 
     1214        /* This seems like an error but is not. */ 
    12151215        if (inb(0x4d0) != (intBits & 0xff)) { 
    1216           printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n", 
    1217                      __func__, intBits &0xff, inb(0x4d0)); 
     1216                printk_err( 
     1217                           "%s: lower order bits are wrong: want 0x%x, got 0x%x\n", 
     1218                           __func__, intBits & 0xff, inb(0x4d0)); 
    12181219        } 
    12191220        if (inb(0x4d1) != ((intBits >> 8) & 0xff)) { 
    1220           printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n", 
    1221                      __func__, (intBits>>8) &0xff, inb(0x4d1)); 
    1222         } 
    1223 #endif 
    1224 } 
    1225  
    1226 /* 
    1227     This function assigns IRQs for all functions contained within 
    1228     the indicated device address.  If the device does not exist or does 
    1229     not require interrupts then this function has no effect. 
    1230  
    1231     This function should be called for each PCI slot in your system. 
    1232  
    1233     pIntAtoD is an array of IRQ #s that are assigned to PINTA through PINTD of 
    1234     this slot. 
    1235     The particular irq #s that are passed in depend on the routing inside 
    1236     your southbridge and on your motherboard. 
    1237  
    1238     -kevinh@ispiri.com 
     1221                printk_err( 
     1222                           "%s: lower order bits are wrong: want 0x%x, got 0x%x\n", 
     1223                           __func__, (intBits >> 8) & 0xff, inb(0x4d1)); 
     1224        } 
     1225} 
     1226 
     1227/** 
     1228 * This function assigns IRQs for all functions contained within the 
     1229 * indicated device address. If the device does not exist or does not 
     1230 * require interrupts then this function has no effect. 
     1231 * 
     1232 * This function should be called for each PCI slot in your system. 
     1233 * 
     1234 * pIntAtoD is an array of IRQ #s that are assigned to PINTA through PINTD of 
     1235 * this slot. 
     1236 * 
     1237 * The particular irq #s that are passed in depend on the routing inside 
     1238 * your southbridge and on your motherboard. 
     1239 * 
     1240 * -kevinh@ispiri.com 
     1241 * 
    12391242*/ 
    12401243void pci_assign_irqs(unsigned bus, unsigned slot, 
    1241         const unsigned char pIntAtoD[4]) 
     1244                     const unsigned char pIntAtoD[4]) 
    12421245{ 
    12431246        unsigned functNum; 
    1244         device_t pdev; 
     1247        struct device *pdev; 
    12451248        unsigned char line; 
    12461249        unsigned char irq; 
    12471250        unsigned char readback; 
    12481251 
    1249         /* Each slot may contain up to eight functions */ 
     1252        /* Each slot may contain up to eight functions. */ 
    12501253        for (functNum = 0; functNum < 8; functNum++) { 
    12511254                pdev = dev_find_slot(bus, (slot << 3) + functNum); 
    12521255 
    12531256                if (pdev) { 
    1254                   line = pci_read_config8(pdev, PCI_INTERRUPT_PIN); 
    1255  
    1256                         // PCI spec says all other values are reserved 
     1257                        line = pci_read_config8(pdev, PCI_INTERRUPT_PIN); 
     1258 
     1259                        /* PCI spec says all other values are reserved. */ 
    12571260                        if ((line >= 1) && (line <= 4)) { 
    12581261                                irq = pIntAtoD[line - 1]; 
    12591262 
    1260                                 printk_debug("Assigning IRQ %d to %d:%x.%d\n", \ 
    1261                                         irq, bus, slot, functNum); 
    1262  
    1263                                 pci_write_config8(pdev, PCI_INTERRUPT_LINE,\ 
    1264                                         pIntAtoD[line - 1]); 
    1265  
    1266                                 readback = pci_read_config8(pdev, PCI_INTERRUPT_LINE); 
     1263                                printk_debug("Assigning IRQ %d to %d:%x.%d\n", 
     1264                                             irq, bus, slot, functNum); 
     1265 
     1266                                pci_write_config8(pdev, PCI_INTERRUPT_LINE, 
     1267                                                  pIntAtoD[line - 1]); 
     1268 
     1269                                readback = 
     1270                                    pci_read_config8(pdev, PCI_INTERRUPT_LINE); 
    12671271                                printk_debug("  Readback = %d\n", readback); 
    12681272 
    1269                                 // Change to level triggered 
     1273                                // Change to level triggered. 
    12701274                                pci_level_irq(pIntAtoD[line - 1]); 
    12711275                        } 
  • trunk/coreboot-v2/src/devices/root_device.c

    r3052 r4394  
    3535void root_dev_read_resources(device_t root) 
    3636{ 
    37         struct resource *resource; 
    38  
    39         /* Initialize the system wide io space constraints */ 
    40         resource = new_resource(root, 0); 
    41         resource->base  = 0x400; 
    42         resource->size  = 0; 
    43         resource->align = 0; 
    44         resource->gran  = 0; 
    45         resource->limit = 0xffffUL; 
    46         resource->flags = IORESOURCE_IO; 
    47         compute_allocate_resource(&root->link[0], resource,  
    48                 IORESOURCE_IO, IORESOURCE_IO); 
    49  
    50         /* Initialize the system wide memory resources constraints */ 
    51         resource = new_resource(root, 1); 
    52         resource->base  = 0; 
    53         resource->size  = 0; 
    54         resource->align = 0; 
    55         resource->gran  = 0; 
    56         resource->limit = 0xffffffffUL; 
    57         resource->flags = IORESOURCE_MEM; 
    58         compute_allocate_resource(&root->link[0], resource, 
    59                 IORESOURCE_MEM, IORESOURCE_MEM); 
     37        printk_err("%s should never be called.\n", __func__); 
    6038} 
    6139 
     
    6947void root_dev_set_resources(device_t root) 
    7048{ 
    71         struct bus *bus; 
    72  
    73         bus = &root->link[0]; 
    74         compute_allocate_resource(bus, 
    75                 &root->resource[0], IORESOURCE_IO, IORESOURCE_IO); 
    76         compute_allocate_resource(bus,  
    77                 &root->resource[1], IORESOURCE_MEM, IORESOURCE_MEM); 
    78         assign_resources(bus); 
     49        printk_err("%s should never be called.\n", __func__); 
    7950} 
    8051 
  • trunk/coreboot-v2/src/include/device/device.h

    r4271 r4394  
    7070        unsigned int    enabled : 1;    /* set if we should enable the device */ 
    7171        unsigned int    initialized : 1; /* set if we have initialized the device */ 
    72         unsigned int    have_resources : 1; /* Set if we have read the devices resources */ 
    7372        unsigned int    on_mainboard : 1; 
    7473        unsigned long   rom_address; 
    7574 
    76         uint8_t command; 
     75        u8 command; 
    7776 
    7877        /* Base registers for this device. I/O, MEM and Expansion ROM */ 
     
    8079        unsigned int resources; 
    8180 
    82         /* link are (down stream) buses attached to the device, usually a leaf 
     81        /* links are (downstream) buses attached to the device, usually a leaf 
    8382         * device with no children have 0 buses attached and a bridge has 1 bus  
    8483         */ 
     
    107106int reset_bus(struct bus *bus); 
    108107unsigned int scan_bus(struct device *bus, unsigned int max); 
    109 void compute_allocate_resource(struct bus *bus, struct resource *bridge, 
    110         unsigned long type_mask, unsigned long type); 
    111108void assign_resources(struct bus *bus); 
    112109void enable_resources(struct device *dev); 
     
    143140 
    144141extern struct device_operations default_dev_ops_root; 
     142void pci_domain_read_resources(struct device *dev); 
     143unsigned int pci_domain_scan_bus(struct device *dev, unsigned int max); 
    145144void root_dev_read_resources(device_t dev); 
    146145void root_dev_set_resources(device_t dev); 
  • trunk/coreboot-v2/src/include/device/resource.h

    r1982 r4394  
    1 #ifndef RESOURCE_H 
    2 #define RESOURCE_H 
     1#ifndef DEVICE_RESOURCE_H 
     2#define DEVICE_RESOURCE_H 
    33 
    44#include <stdint.h> 
     
    2020                                                 * to the bus below. 
    2121                                                 */ 
     22#define IORESOURCE_BRIDGE       0x00080000      /* The IO resource has a bus below it. */ 
    2223#define IORESOURCE_STORED       0x20000000      /* The IO resource assignment has been stored in the device */ 
    2324#define IORESOURCE_ASSIGNED     0x40000000      /* An IO resource that has been assigned a value */ 
     
    6364 
    6465 
    65 typedef uint64_t resource_t; 
     66typedef u64 resource_t; 
    6667struct resource { 
    6768        resource_t base;        /* Base address of the resource */ 
     
    7576}; 
    7677 
    77 /* Macros to generate index values for subtractive resources */ 
     78/* Macros to generate index values for resources */ 
    7879#define IOINDEX_SUBTRACTIVE(IDX,LINK) (0x10000000 + ((IDX) << 8) + LINK) 
    7980#define IOINDEX_SUBTRACTIVE_LINK(IDX) (IDX & 0xff) 
     81 
     82#define IOINDEX(IDX,LINK) (((LINK) << 16) + IDX) 
     83#define IOINDEX_LINK(IDX) (( IDX & 0xf0000) >> 16) 
     84#define IOINDEX_IDX(IDX) (IDX & 0xffff) 
    8085 
    8186/* Generic resource helper functions */ 
     
    102107extern const char *resource_type(struct resource *resource); 
    103108 
    104 #endif /* RESOURCE_H */ 
     109#endif /* DEVICE_RESOURCE_H */ 
  • trunk/coreboot-v2/src/northbridge/amd/amdfam10/northbridge.c

    r4381 r4394  
    342342                        continue; 
    343343                for(link = 0; !res && (link < 8); link++) { 
    344                         res = probe_resource(dev, 0x1000 + reg + (link<<16)); // 8 links, 0x1000 man f1, 
     344                        res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); 
    345345                } 
    346346        } 
     
    386386        } 
    387387 
    388         resource = new_resource(dev, 0x1000 + reg + (link<<16)); 
     388                resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); 
    389389 
    390390        return resource; 
     
    422422 
    423423        } 
    424         resource = new_resource(dev, 0x1000 + reg + (link<<16)); 
     424        resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); 
    425425        return resource; 
    426426} 
     
    448448                resource->limit = 0xffffUL; 
    449449                resource->flags = IORESOURCE_IO; 
    450                 compute_allocate_resource(&dev->link[link], resource, 
    451                                         IORESOURCE_IO, IORESOURCE_IO); 
    452450        } 
    453451 
     
    461459                resource->limit = 0xffffffffffULL; 
    462460                resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 
    463                 compute_allocate_resource(&dev->link[link], resource, 
    464                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    465                         IORESOURCE_MEM | IORESOURCE_PREFETCH); 
    466461 
    467462#if CONFIG_EXT_CONF_SUPPORT == 1 
     
    482477                resource->limit = 0xffffffffffULL; 
    483478                resource->flags = IORESOURCE_MEM; 
    484                 compute_allocate_resource(&dev->link[link], resource, 
    485                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    486                         IORESOURCE_MEM); 
    487479 
    488480#if CONFIG_EXT_CONF_SUPPORT == 1 
     
    542534        /* Get the register and link */ 
    543535        reg  = resource->index & 0xfff; // 4k 
    544         link = ( resource->index>> 16)& 0x7; // 8 links 
     536        link = IOINDEX_LINK(resource->index); 
    545537 
    546538        if (resource->flags & IORESOURCE_IO) { 
    547                 compute_allocate_resource(&dev->link[link], resource, 
    548                         IORESOURCE_IO, IORESOURCE_IO); 
    549539 
    550540                set_io_addr_reg(dev, nodeid, link, reg, rbase>>8, rend>>8); 
     
    552542        } 
    553543        else if (resource->flags & IORESOURCE_MEM) { 
    554                 compute_allocate_resource(&dev->link[link], resource, 
    555                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    556                         resource->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH)); 
    557544                set_mmio_addr_reg(nodeid, link, reg, (resource->index >>24), rbase>>8, rend>>8, sysconf.nodes) ;// [39:8] 
    558545                store_conf_mmio_addr(nodeid, link, reg, (resource->index >>24), rbase>>8, rend>>8); 
     
    658645}; 
    659646 
    660 static void pci_domain_read_resources(device_t dev) 
     647static void amdfam10_domain_read_resources(device_t dev) 
    661648{ 
    662649        struct resource *resource; 
     
    673660                if ((base & 3) != 0) { 
    674661                        unsigned nodeid, link; 
    675                         device_t dev; 
     662                        device_t reg_dev; 
    676663                        if(reg<0xc0) { // mmio 
    677664                                nodeid = (limit & 0xf) + (base&0x30); 
     
    680667                        } 
    681668                        link   = (limit >> 4) & 7; 
    682                         dev = __f0_dev[nodeid]; 
    683                         if (dev) { 
    684                                 /* Reserve the resource  */ 
    685                                 struct resource *resource; 
    686                                 resource = new_resource(dev, 0x1000 + reg + (link<<16)); 
    687                                 if (resource) { 
    688                                         resource->flags = 1; 
     669                        reg_dev = __f0_dev[nodeid]; 
     670                        if (reg_dev) { 
     671                                /* Reserve the resource  */ 
     672                                struct resource *reg_resource; 
     673                                reg_resource = new_resource(reg_dev, IOINDEX(0x1000 + reg, link)); 
     674                                if (reg_resource) { 
     675                                        reg_resource->flags = 1; 
    689676                                } 
    690677                        } 
     
    712699                resource->limit = 0xffffUL; 
    713700                resource->flags = IORESOURCE_IO; 
    714                 compute_allocate_resource(&dev->link[link], resource, 
    715                         IORESOURCE_IO, IORESOURCE_IO); 
    716701 
    717702                /* Initialize the system wide prefetchable memory resources constraints */ 
     
    719704                resource->limit = 0xfcffffffffULL; 
    720705                resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 
    721                 compute_allocate_resource(&dev->link[link], resource, 
    722                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    723                         IORESOURCE_MEM | IORESOURCE_PREFETCH); 
    724706 
    725707                /* Initialize the system wide memory resources constraints */ 
     
    727709                resource->limit = 0xfcffffffffULL; 
    728710                resource->flags = IORESOURCE_MEM; 
    729                 compute_allocate_resource(&dev->link[link], resource, 
    730                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    731                         IORESOURCE_MEM); 
    732711        } 
    733712#endif 
     
    770749        return tolm; 
    771750} 
    772  
    773 #if CONFIG_PCI_64BIT_PREF_MEM == 1 
    774 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH) 
    775 #endif 
    776751 
    777752#if CONFIG_HW_MEM_HOLE_SIZEK != 0 
     
    981956                resource->flags &= ~IORESOURCE_STORED; 
    982957                link = (resource>>2) & 3; 
    983                 compute_allocate_resource(&dev->link[link], resource, 
    984                         BRIDGE_IO_MASK, resource->flags & BRIDGE_IO_MASK); 
    985  
    986958                resource->flags |= IORESOURCE_STORED; 
    987959                report_resource_stored(dev, resource, ""); 
     
    11431115} 
    11441116 
    1145 static u32 pci_domain_scan_bus(device_t dev, u32 max) 
     1117static u32 amdfam10_domain_scan_bus(device_t dev, u32 max) 
    11461118{ 
    11471119        u32 reg; 
     
    11931165 
    11941166static struct device_operations pci_domain_ops = { 
    1195         .read_resources   = pci_domain_read_resources, 
     1167        .read_resources   = amdfam10_domain_read_resources, 
    11961168        .set_resources    = pci_domain_set_resources, 
    11971169        .enable_resources = enable_childrens_resources, 
    11981170        .init             = 0, 
    1199         .scan_bus         = pci_domain_scan_bus, 
     1171        .scan_bus         = amdfam10_domain_scan_bus, 
    12001172#if CONFIG_MMCONF_SUPPORT_DEFAULT 
    12011173        .ops_pci_bus      = &pci_ops_mmconf, 
  • trunk/coreboot-v2/src/northbridge/amd/amdk8/misc_control.c

    r4381 r4394  
    5454                /* Add a Gart apeture resource */ 
    5555                resource = new_resource(dev, 0x94); 
    56                 resource->size = iommu?CONFIG_AGP_APERTURE_SIZE:1; 
     56                resource->size = CONFIG_AGP_APERTURE_SIZE; 
    5757                resource->align = log2(resource->size); 
    5858                resource->gran  = log2(resource->size); 
  • trunk/coreboot-v2/src/northbridge/amd/amdk8/northbridge.c

    r4381 r4394  
    298298                        continue; 
    299299                for(link = 0; !res && (link < 3); link++) { 
    300                         res = probe_resource(dev, 0x100 + (reg | link)); 
     300                        res = probe_resource(dev, IOINDEX(0x100 + reg, link)); 
    301301                } 
    302302        } 
     
    336336        } 
    337337        if (reg > 0) { 
    338                 resource = new_resource(dev, 0x100 + (reg | link)); 
     338                resource = new_resource(dev, IOINDEX(0x100 + reg, link)); 
    339339        } 
    340340        return resource; 
     
    363363        } 
    364364        if (reg > 0) { 
    365                 resource = new_resource(dev, 0x100 + (reg | link)); 
     365                resource = new_resource(dev, IOINDEX(0x100 + reg, link)); 
    366366        } 
    367367        return resource; 
     
    380380                resource->gran  = log2(HT_IO_HOST_ALIGN); 
    381381                resource->limit = 0xffffUL; 
    382                 resource->flags = IORESOURCE_IO; 
    383                 compute_allocate_resource(&dev->link[link], resource, 
    384                         IORESOURCE_IO, IORESOURCE_IO); 
     382                resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; 
    385383        } 
    386384 
     
    394392                resource->limit = 0xffffffffffULL; 
    395393                resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 
    396                 compute_allocate_resource(&dev->link[link], resource, 
    397                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    398                         IORESOURCE_MEM | IORESOURCE_PREFETCH); 
     394#ifdef CONFIG_PCI_64BIT_PREF_MEM 
     395                resource->flags |= IORESOURCE_BRIDGE; 
     396#endif 
    399397        } 
    400398 
     
    406404                resource->align = log2(HT_MEM_HOST_ALIGN); 
    407405                resource->gran  = log2(HT_MEM_HOST_ALIGN); 
    408                 resource->limit = 0xffffffffffULL; 
    409                 resource->flags = IORESOURCE_MEM; 
    410                 compute_allocate_resource(&dev->link[link], resource, 
    411                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    412                         IORESOURCE_MEM); 
     406                resource->limit = 0xffffffffULL; 
     407                resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; 
    413408        } 
    414409} 
     
    433428        /* Make certain the resource has actually been set */ 
    434429        if (!(resource->flags & IORESOURCE_ASSIGNED)) { 
     430                printk_err("%s: can't set unassigned resource @%lx %lx\n", 
     431                           __func__, resource->index, resource->flags); 
    435432                return; 
    436433        } 
     
    438435        /* If I have already stored this resource don't worry about it */ 
    439436        if (resource->flags & IORESOURCE_STORED) { 
     437                printk_err("%s: can't set stored resource @%lx %lx\n", __func__, 
     438                           resource->index, resource->flags); 
    440439                return; 
    441440        } 
     
    449448                return; 
    450449        } 
     450 
     451        if (resource->size == 0) 
     452                return; 
     453 
    451454        /* Get the base address */ 
    452455        rbase = resource->base; 
     
    457460        /* Get the register and link */ 
    458461        reg  = resource->index & 0xfc; 
    459         link = resource->index & 3; 
     462        link = IOINDEX_LINK(resource->index); 
    460463 
    461464        if (resource->flags & IORESOURCE_IO) { 
    462465                uint32_t base, limit; 
    463                 compute_allocate_resource(&dev->link[link], resource, 
    464                         IORESOURCE_IO, IORESOURCE_IO); 
    465466                base  = f1_read_config32(reg); 
    466467                limit = f1_read_config32(reg + 0x4); 
     
    487488        else if (resource->flags & IORESOURCE_MEM) { 
    488489                uint32_t base, limit; 
    489                 compute_allocate_resource(&dev->link[link], resource, 
    490                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    491                         resource->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH)); 
    492490                base  = f1_read_config32(reg); 
    493491                limit = f1_read_config32(reg + 0x4); 
     
    635633}; 
    636634 
    637 static void pci_domain_read_resources(device_t dev) 
     635static void amdk8_domain_read_resources(device_t dev) 
    638636{ 
    639637        struct resource *resource; 
     
    656654                                /* Reserve the resource  */ 
    657655                                struct resource *reg_resource; 
    658                                 reg_resource = new_resource(reg_dev, 0x100 + (reg | link)); 
     656                                reg_resource = new_resource(reg_dev, IOINDEX(0x100 + reg, link)); 
    659657                                if (reg_resource) { 
    660658                                        reg_resource->flags = 1; 
     
    663661                } 
    664662        } 
    665 #if CONFIG_PCI_64BIT_PREF_MEM == 0 
    666         /* Initialize the system wide io space constraints */ 
    667         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    668         resource->base  = 0x400; 
    669         resource->limit = 0xffffUL; 
    670         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    671  
    672         /* Initialize the system wide memory resources constraints */ 
    673         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    674         resource->limit = 0xfcffffffffULL; 
    675         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    676 #else 
    677         /* Initialize the system wide io space constraints */ 
    678         resource = new_resource(dev, 0); 
    679         resource->base  = 0x400; 
    680         resource->limit = 0xffffUL; 
    681         resource->flags = IORESOURCE_IO; 
    682         compute_allocate_resource(&dev->link[0], resource, 
    683                 IORESOURCE_IO, IORESOURCE_IO); 
    684  
     663 
     664        pci_domain_read_resources(dev); 
     665 
     666#if CONFIG_PCI_64BIT_PREF_MEM == 1 
    685667        /* Initialize the system wide prefetchable memory resources constraints */ 
    686         resource = new_resource(dev, 1); 
     668        resource = new_resource(dev, 2); 
    687669        resource->limit = 0xfcffffffffULL; 
    688670        resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; 
    689         compute_allocate_resource(&dev->link[0], resource, 
    690                 IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    691                 IORESOURCE_MEM | IORESOURCE_PREFETCH); 
    692  
    693         /* Initialize the system wide memory resources constraints */ 
    694         resource = new_resource(dev, 2); 
    695         resource->limit = 0xfcffffffffULL; 
    696         resource->flags = IORESOURCE_MEM; 
    697         compute_allocate_resource(&dev->link[0], resource, 
    698                 IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    699                 IORESOURCE_MEM); 
    700671#endif 
    701672} 
     
    739710        return tolm; 
    740711} 
    741  
    742 #if CONFIG_PCI_64BIT_PREF_MEM == 1 
    743 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH) 
    744 #endif 
    745712 
    746713#if CONFIG_HW_MEM_HOLE_SIZEK != 0 
     
    899866#endif 
    900867 
    901 static void pci_domain_set_resources(device_t dev) 
     868static void amdk8_domain_set_resources(device_t dev) 
    902869{ 
    903870#if CONFIG_PCI_64BIT_PREF_MEM == 1 
     
    965932        for(resource = &dev->resource[0]; resource < last; resource++) 
    966933        { 
    967 #if 1 
    968934                resource->flags |= IORESOURCE_ASSIGNED; 
    969                 resource->flags &= ~IORESOURCE_STORED; 
    970 #endif 
    971                 compute_allocate_resource(&dev->link[0], resource, 
    972                         BRIDGE_IO_MASK, resource->flags & BRIDGE_IO_MASK); 
    973  
    974935                resource->flags |= IORESOURCE_STORED; 
    975936                report_resource_stored(dev, resource, ""); 
     
    11261087} 
    11271088 
    1128 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
     1089static unsigned int amdk8_domain_scan_bus(device_t dev, unsigned int max) 
    11291090{ 
    11301091        unsigned reg; 
     
    11611122 
    11621123static struct device_operations pci_domain_ops = { 
    1163         .read_resources   = pci_domain_read_resources, 
    1164         .set_resources    = pci_domain_set_resources, 
     1124        .read_resources   = amdk8_domain_read_resources, 
     1125        .set_resources    = amdk8_domain_set_resources, 
    11651126        .enable_resources = enable_childrens_resources, 
    11661127        .init             = 0, 
    1167         .scan_bus         = pci_domain_scan_bus, 
     1128        .scan_bus         = amdk8_domain_scan_bus, 
    11681129        .ops_pci_bus      = &pci_cf8_conf1, 
    11691130}; 
  • trunk/coreboot-v2/src/northbridge/amd/gx1/northbridge.c

    r4381 r4394  
    6767}; 
    6868 
    69  
    70  
    71 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    72  
    73 static void pci_domain_read_resources(device_t dev) 
    74 { 
    75         struct resource *resource; 
    76  
    77         printk_spew("%s:%s()\n", NORTHBRIDGE_FILE, __func__); 
    78  
    79         /* Initialize the system wide io space constraints */ 
    80         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    81         resource->limit = 0xffffUL; 
    82         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    83  
    84         /* Initialize the system wide memory resources constraints */ 
    85         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    86         resource->limit = 0xffffffffULL; 
    87         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    88 } 
    89  
    9069static void ram_resource(device_t dev, unsigned long index, 
    9170        unsigned long basek, unsigned long sizek) 
     
    186165        } 
    187166        assign_resources(&dev->link[0]); 
    188 } 
    189  
    190 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    191 { 
    192         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    193         return max; 
    194167} 
    195168 
  • trunk/coreboot-v2/src/northbridge/amd/gx2/northbridge.c

    r4381 r4394  
    357357}; 
    358358 
    359 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    360  
    361 static void pci_domain_read_resources(device_t dev) 
    362 { 
    363         struct resource *resource; 
    364  
    365         printk_spew("%s:%s()\n", NORTHBRIDGE_FILE, __func__); 
    366  
    367         /* Initialize the system wide io space constraints */ 
    368         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    369         resource->limit = 0xffffUL; 
    370         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    371  
    372         /* Initialize the system wide memory resources constraints */ 
    373         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    374         resource->limit = 0xffffffffULL; 
    375         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    376 } 
    377  
    378359static void ram_resource(device_t dev, unsigned long index, 
    379360        unsigned long basek, unsigned long sizek) 
     
    467448#endif 
    468449        assign_resources(&dev->link[0]); 
    469 } 
    470  
    471 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    472 { 
    473         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    474         return max; 
    475450} 
    476451 
  • trunk/coreboot-v2/src/northbridge/amd/lx/northbridge.c

    r4381 r4394  
    7474#define IOD_BM(msr, pdid1, bizarro, ibase, imask) {msr, {.hi=(pdid1<<29)|(bizarro<<28)|(ibase>>12), .lo=(ibase<<20)|imask}} 
    7575#define IOD_SC(msr, pdid1, bizarro, en, wen, ren, ibase) {msr, {.hi=(pdid1<<29)|(bizarro<<28), .lo=(en<<24)|(wen<<21)|(ren<<20)|(ibase<<3)}} 
    76  
    77 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    7876 
    7977extern void graphics_init(void); 
     
    383381}; 
    384382 
    385 static void pci_domain_read_resources(device_t dev) 
    386 { 
    387         struct resource *resource; 
    388         printk_spew(">> Entering northbridge.c: %s\n", __func__); 
    389  
    390         /* Initialize the system wide io space constraints */ 
    391         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    392         resource->limit = 0xffffUL; 
    393         resource->flags = 
    394             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    395  
    396         /* Initialize the system wide memory resources constraints */ 
    397         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    398         resource->limit = 0xffffffffULL; 
    399         resource->flags = 
    400             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    401 } 
    402  
    403383static void ram_resource(device_t dev, unsigned long index, 
    404384                         unsigned long basek, unsigned long sizek) 
     
    471451} 
    472452 
    473 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    474 { 
    475         printk_spew(">> Entering northbridge.c: %s\n", __func__); 
    476  
    477         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    478         return max; 
    479 } 
    480  
    481453static struct device_operations pci_domain_ops = { 
    482454        .read_resources = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/ibm/cpc710/cpc710_northbridge.c

    r2490 r4394  
    99#include <cpu/cpu.h> 
    1010#include "chip.h" 
    11  
    12 static void pci_domain_read_resources(device_t dev) 
    13 { 
    14         struct resource *resource; 
    15  
    16         /* Initialize the system wide io space constraints */ 
    17         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    18         resource->base  = 0; 
    19         resource->limit = 0xffffUL; 
    20         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    21  
    22         /* Initialize the system wide memory resources constraints */ 
    23         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    24         resource->base  = 0x80000000ULL; 
    25         resource->limit = 0xfeffffffULL; /* We can put pci resources in the system controll area */ 
    26         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    27 } 
    2811 
    2912static void ram_resource(device_t dev, unsigned long index, 
     
    5235        /* And assign the resources */ 
    5336        assign_resources(&dev->link[0]); 
    54 } 
    55  
    56  
    57 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    58 { 
    59         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    60         return max; 
    6137} 
    6238 
  • trunk/coreboot-v2/src/northbridge/ibm/cpc925/cpc925_northbridge.c

    r2490 r4394  
    99#include <cpu/cpu.h> 
    1010#include "chip.h" 
    11  
    12 static void pci_domain_read_resources(device_t dev) 
    13 { 
    14         struct resource *resource; 
    15  
    16         /* Initialize the system wide io space constraints */ 
    17         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    18         resource->base  = 0; 
    19         resource->limit = 0xffffUL; 
    20         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    21  
    22         /* Initialize the system wide memory resources constraints */ 
    23         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    24         resource->base  = 0x80000000ULL; 
    25         resource->limit = 0xfeffffffULL; /* We can put pci resources in the system controll area */ 
    26         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    27 } 
    2811 
    2912static void ram_resource(device_t dev, unsigned long index, 
     
    5235        /* And assign the resources */ 
    5336        assign_resources(&dev->link[0]); 
    54 } 
    55  
    56  
    57 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    58 { 
    59         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    60         return max; 
    6137} 
    6238 
  • trunk/coreboot-v2/src/northbridge/intel/e7501/northbridge.c

    r4381 r4394  
    99#include <bitops.h> 
    1010#include "chip.h" 
    11  
    12 static void pci_domain_read_resources(device_t dev) 
    13 { 
    14         struct resource *resource; 
    15         unsigned reg; 
    16  
    17         /* Initialize the system wide io space constraints */ 
    18         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    19         resource->base = 0x400; //yhlu 
    20         resource->limit = 0xffffUL; 
    21         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    22  
    23         /* Initialize the system wide memory resources constraints */ 
    24         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    25         resource->limit = 0xffffffffULL; 
    26         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    27 } 
    2811 
    2912static void ram_resource(device_t dev, unsigned long index, 
     
    156139} 
    157140 
    158 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    159 { 
    160         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    161         return max; 
    162 } 
    163  
    164141static struct device_operations pci_domain_ops = { 
    165142        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/intel/e7520/northbridge.c

    r4381 r4394  
    2929} 
    3030 
    31  
    32 static void pci_domain_read_resources(device_t dev) 
    33 { 
    34         struct resource *resource; 
    35  
    36         /* Initialize the system wide io space constraints */ 
    37         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    38         resource->base  = 0; 
    39         resource->size  = 0; 
    40         resource->align = 0; 
    41         resource->gran  = 0; 
    42         resource->limit = 0xffffUL; 
    43         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    44  
    45         /* Initialize the system wide memory resources constraints */ 
    46         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    47         resource->base  = 0; 
    48         resource->size  = 0; 
    49         resource->align = 0; 
    50         resource->gran  = 0; 
    51         resource->limit = 0xffffffffUL; 
    52         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    53 } 
    54  
    5531static void tolm_test(void *gp, struct device *dev, struct resource *new) 
    5632{ 
     
    9167#if 1 
    9268        printk_debug("PCI mem marker = %x\n", pci_tolm); 
    93 #endif   
     69#endif 
    9470        /* FIXME Me temporary hack */ 
    9571        if(pci_tolm > 0xe0000000) 
     
    12399                        remaplimitk  = 0 << 16; 
    124100                        remapoffsetk = 0 << 16; 
    125                 }  
     101                } 
    126102                else { 
    127103                        /* The PCI memory hole overlaps memory 
     
    166142                } 
    167143                if (remaplimitk >= remapbasek) { 
    168                         ram_resource(dev, 6, remapbasek,  
     144                        ram_resource(dev, 6, remapbasek, 
    169145                                (remaplimitk + 64*1024) - remapbasek); 
    170146                } 
     
    179155} 
    180156 
    181 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    182 { 
    183         max = pci_scan_bus(&dev->link[0], 0, 0xff, max); 
    184         if (max > max_bus) { 
    185                 max_bus = max; 
    186         } 
    187         return max; 
     157static u32 e7520_domain_scan_bus(device_t dev, u32 max) 
     158{ 
     159        max_bus = pci_domain_scan_bus(dev, max); 
     160        return max_bus; 
    188161} 
    189162 
     
    193166        .enable_resources = enable_childrens_resources, 
    194167        .init             = 0, 
    195         .scan_bus         = pci_domain_scan_bus, 
     168        .scan_bus         = e7520_domain_scan_bus, 
    196169        .ops_pci_bus      = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */ 
    197170}; 
  • trunk/coreboot-v2/src/northbridge/intel/e7525/northbridge.c

    r4381 r4394  
    2929} 
    3030 
    31  
    32 static void pci_domain_read_resources(device_t dev) 
    33 { 
    34         struct resource *resource; 
    35  
    36         /* Initialize the system wide io space constraints */ 
    37         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    38         resource->base  = 0; 
    39         resource->size  = 0; 
    40         resource->align = 0; 
    41         resource->gran  = 0; 
    42         resource->limit = 0xffffUL; 
    43         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    44  
    45         /* Initialize the system wide memory resources constraints */ 
    46         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    47         resource->base  = 0; 
    48         resource->size  = 0; 
    49         resource->align = 0; 
    50         resource->gran  = 0; 
    51         resource->limit = 0xffffffffUL; 
    52         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    53 } 
    54  
    5531static void tolm_test(void *gp, struct device *dev, struct resource *new) 
    5632{ 
     
    9167#if 1 
    9268        printk_debug("PCI mem marker = %x\n", pci_tolm); 
    93 #endif   
     69#endif 
    9470        /* FIXME Me temporary hack */ 
    9571        if(pci_tolm > 0xe0000000) 
     
    12399                        remaplimitk  = 0 << 16; 
    124100                        remapoffsetk = 0 << 16; 
    125                 }  
     101                } 
    126102                else { 
    127103                        /* The PCI memory hole overlaps memory 
     
    161137                /* Report the memory regions */ 
    162138                ram_resource(dev, 3,   0, 640); 
    163                 ram_resource(dev, 4, 768, tolmk - 768); 
     139                ram_resource(dev, 4, 768, (tolmk - 768)); 
    164140                if (tomk > 4*1024*1024) { 
    165141                        ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024); 
    166142                } 
    167143                if (remaplimitk >= remapbasek) { 
    168                         ram_resource(dev, 6, remapbasek,  
     144                        ram_resource(dev, 6, remapbasek, 
    169145                                (remaplimitk + 64*1024) - remapbasek); 
    170146                } 
     
    179155} 
    180156 
    181 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    182 { 
    183         max = pci_scan_bus(&dev->link[0], 0, 0xff, max); 
    184         if (max > max_bus) { 
    185                 max_bus = max; 
    186         } 
    187         return max; 
     157static u32 e7525_domain_scan_bus(device_t dev, u32 max) 
     158{ 
     159        max_bus = pci_domain_scan_bus(dev, max); 
     160        return max_bus; 
    188161} 
    189162 
     
    193166        .enable_resources = enable_childrens_resources, 
    194167        .init             = 0, 
    195         .scan_bus         = pci_domain_scan_bus, 
     168        .scan_bus         = e7525_domain_scan_bus, 
    196169        .ops_pci_bus      = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */ 
    197170}; 
  • trunk/coreboot-v2/src/northbridge/intel/i3100/northbridge.c

    r4381 r4394  
    4848        resource->flags =  IORESOURCE_MEM | IORESOURCE_CACHEABLE | \ 
    4949                IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; 
    50 } 
    51  
    52  
    53 static void pci_domain_read_resources(device_t dev) 
    54 { 
    55         struct resource *resource; 
    56  
    57         /* Initialize the system wide io space constraints */ 
    58         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    59         resource->base  = 0; 
    60         resource->size  = 0; 
    61         resource->align = 0; 
    62         resource->gran  = 0; 
    63         resource->limit = 0xffffUL; 
    64         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    65  
    66         /* Initialize the system wide memory resources constraints */ 
    67         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    68         resource->base  = 0; 
    69         resource->size  = 0; 
    70         resource->align = 0; 
    71         resource->gran  = 0; 
    72         resource->limit = 0xffffffffUL; 
    73         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    7450} 
    7551 
     
    200176} 
    201177 
    202 static u32 pci_domain_scan_bus(device_t dev, u32 max) 
    203 { 
    204         max = pci_scan_bus(&dev->link[0], 0, 0xff, max); 
    205         if (max > max_bus) { 
    206                 max_bus = max; 
    207         } 
    208         return max; 
     178static u32 i3100_domain_scan_bus(device_t dev, u32 max) 
     179{ 
     180        max_bus = pci_domain_scan_bus(dev, max); 
     181        return max_bus; 
    209182} 
    210183 
     
    214187        .enable_resources = enable_childrens_resources, 
    215188        .init             = 0, 
    216         .scan_bus         = pci_domain_scan_bus, 
     189        .scan_bus         = i3100_domain_scan_bus, 
    217190        .ops_pci_bus      = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */ 
    218191}; 
  • trunk/coreboot-v2/src/northbridge/intel/i440bx/northbridge.c

    r4381 r4394  
    3333        .device = 0x7190, 
    3434}; 
    35  
    36  
    37 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    38  
    39 static void pci_domain_read_resources(device_t dev) 
    40 { 
    41         struct resource *resource; 
    42  
    43         /* Initialize the system wide io space constraints */ 
    44         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    45         resource->limit = 0xffffUL; 
    46         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    47  
    48         /* Initialize the system wide memory resources constraints */ 
    49         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    50         resource->limit = 0xffffffffULL; 
    51         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    52 } 
    5335 
    5436static void ram_resource(device_t dev, unsigned long index, 
     
    9678#endif 
    9779 
    98 static void pci_domain_set_resources(device_t dev) 
     80static void i440bx_domain_set_resources(device_t dev) 
    9981{ 
    10082        device_t mc_dev; 
     
    141123} 
    142124 
    143 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    144 { 
    145         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    146         return max; 
    147 } 
    148  
    149125static struct device_operations pci_domain_ops = { 
    150126        .read_resources         = pci_domain_read_resources, 
    151         .set_resources          = pci_domain_set_resources, 
     127        .set_resources          = i440bx_domain_set_resources, 
    152128        .enable_resources       = enable_childrens_resources, 
    153129        .init                   = 0, 
  • trunk/coreboot-v2/src/northbridge/intel/i82810/northbridge.c

    r4381 r4394  
    5353}; 
    5454 
    55 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    56  
    57 static void pci_domain_read_resources(device_t dev) 
    58 { 
    59         struct resource *resource; 
    60         unsigned reg; 
    61  
    62         /* Initialize the system wide io space constraints */ 
    63         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    64         resource->base = 0x400; 
    65         resource->limit = 0xffffUL; 
    66         resource->flags = 
    67             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    68  
    69         /* Initialize the system wide memory resources constraints */ 
    70         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    71         resource->limit = 0xffffffffULL; 
    72         resource->flags = 
    73             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    74 } 
    75  
    7655static void ram_resource(device_t dev, unsigned long index, 
    7756                         unsigned long basek, unsigned long sizek) 
     
    182161} 
    183162 
    184 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    185 { 
    186         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    187         return max; 
    188 } 
    189  
    190163static struct device_operations pci_domain_ops = { 
    191164        .read_resources         = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/intel/i82830/northbridge.c

    r4381 r4394  
    5151        .device = 0x3575, 
    5252}; 
    53  
    54 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    55  
    56 static void pci_domain_read_resources(device_t dev) 
    57 { 
    58         struct resource *resource; 
    59  
    60         /* Initialize the system wide I/O space constraints. */ 
    61         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    62         resource->limit = 0xffffUL; 
    63         resource->flags = 
    64             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    65  
    66         /* Initialize the system wide memory resources constraints. */ 
    67         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    68         resource->limit = 0xffffffffULL; 
    69         resource->flags = 
    70             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    71 } 
    7253 
    7354static void ram_resource(device_t dev, unsigned long index, 
     
    159140} 
    160141 
    161 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    162 { 
    163         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    164         return max; 
    165 } 
    166  
    167142static struct device_operations pci_domain_ops = { 
    168143        .read_resources         = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/intel/i855gme/northbridge.c

    r4381 r4394  
    3131#include <cpu/x86/cache.h> 
    3232#include "chip.h" 
    33  
    34 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    35  
    36 static void pci_domain_read_resources(device_t dev) 
    37 { 
    38         struct resource *resource; 
    39         unsigned reg; 
    40  
    41         /* Initialize the system wide io space constraints */ 
    42         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    43         resource->limit = 0xffffUL; 
    44         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    45  
    46         /* Initialize the system wide memory resources constraints */ 
    47         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    48         resource->limit = 0xffffffffULL; 
    49         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    50 } 
    5133 
    5234static void ram_resource(device_t dev, unsigned long index, 
     
    157139} 
    158140 
    159 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    160 { 
    161         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    162         return max; 
    163 } 
    164  
    165141static struct device_operations pci_domain_ops = { 
    166142        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/intel/i855pm/northbridge.c

    r4381 r4394  
    1010#include <bitops.h> 
    1111#include "chip.h" 
    12  
    13 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    14  
    15 static void pci_domain_read_resources(device_t dev) 
    16 { 
    17         struct resource *resource; 
    18  
    19         /* Initialize the system wide io space constraints */ 
    20         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    21         resource->limit = 0xffffUL; 
    22         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    23  
    24         /* Initialize the system wide memory resources constraints */ 
    25         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    26         resource->limit = 0xffffffffULL; 
    27         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    28 } 
    2912 
    3013static void ram_resource(device_t dev, unsigned long index, 
     
    124107} 
    125108 
    126 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    127 { 
    128         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    129         return max; 
    130 } 
    131  
    132109static struct device_operations pci_domain_ops = { 
    133110        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/intel/i945/northbridge.c

    r4381 r4394  
    4242        resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | 
    4343            IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; 
    44 } 
    45  
    46 static void pci_domain_read_resources(device_t dev) 
    47 { 
    48         struct resource *resource; 
    49  
    50         /* Initialize the system wide io space constraints */ 
    51         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    52         resource->base = 0; 
    53         resource->size = 0; 
    54         resource->align = 0; 
    55         resource->gran = 0; 
    56         resource->limit = 0xffffUL; 
    57         resource->flags = 
    58             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    59  
    60         /* Initialize the system wide memory resources constraints */ 
    61         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    62         resource->base = 0; 
    63         resource->size = 0; 
    64         resource->align = 0; 
    65         resource->gran = 0; 
    66         resource->limit = 0xffffffffUL; 
    67         resource->flags = 
    68             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    6944} 
    7045 
     
    185160} 
    186161 
    187 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    188 { 
    189         max = pci_scan_bus(&dev->link[0], 0, 0xff, max); 
    190162        /* TODO We could determine how many PCIe busses we need in 
    191163         * the bar. For now that number is hardcoded to a max of 64. 
     164         * See e7525/northbridge.c for an example. 
    192165         */ 
    193         return max; 
    194 } 
    195  
    196166static struct device_operations pci_domain_ops = { 
    197167        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/motorola/mpc107/mpc107_northbridge.c

    r3053 r4394  
    1717 * devices. 
    1818 */ 
    19 static void pci_domain_read_resources(device_t dev) 
     19static void mpc107_domain_read_resources(device_t dev) 
    2020{ 
    2121        struct resource *resource; 
     
    102102} 
    103103 
    104  
    105 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    106 { 
    107         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    108         return max; 
    109 } 
    110  
    111104static struct device_operations pci_domain_ops = { 
    112         .read_resources   = pci_domain_read_resources, 
     105        .read_resources   = mpc107_domain_read_resources, 
    113106        .set_resources    = pci_domain_set_resources, 
    114107        .enable_resources = enable_childrens_resources, 
  • trunk/coreboot-v2/src/northbridge/via/cn400/northbridge.c

    r4386 r4394  
    102102}; 
    103103 
    104 static void pci_domain_read_resources(device_t dev) 
     104static void cn400_domain_read_resources(device_t dev) 
    105105{ 
    106106        struct resource *resource; 
    107107 
    108         printk_spew("Entering cn400 pci_domain_read_resources.\n"); 
     108        printk_spew("Entering %s.\n", __func__); 
    109109 
    110110        /* Initialize the system wide I/O space constraints. */ 
     
    120120            IORESOURCE_ASSIGNED; 
    121121 
    122         printk_spew("Leaving cn400 pci_domain_read_resources.\n"); 
     122        printk_spew("Leaving %s.\n", __func__); 
    123123} 
    124124 
     
    174174#endif 
    175175 
    176 static void pci_domain_set_resources(device_t dev) 
     176static void cn400_domain_set_resources(device_t dev) 
    177177{ 
    178178        /* The order is important to find the correct RAM size. */ 
     
    181181        u32 pci_tolm; 
    182182 
    183         printk_spew("Entering cn400 pci_domain_set_resources.\n"); 
     183        printk_spew("Entering %s.\n", __func__); 
    184184 
    185185        pci_tolm = find_pci_tolm(&dev->link[0]); 
     
    227227        assign_resources(&dev->link[0]); 
    228228         
    229         printk_spew("Leaving cn400 pci_domain_set_resources.\n"); 
    230 } 
    231  
    232 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    233 { 
    234         printk_debug("Entering cn400 pci_domain_scan_bus.\n"); 
     229        printk_spew("Leaving %s.\n", __func__); 
     230} 
     231 
     232static unsigned int cn400_domain_scan_bus(device_t dev, unsigned int max) 
     233{ 
     234        printk_debug("Entering %s.\n", __func__); 
    235235 
    236236        max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
     
    239239 
    240240static const struct device_operations pci_domain_ops = { 
    241         .read_resources   = pci_domain_read_resources, 
    242         .set_resources    = pci_domain_set_resources, 
     241        .read_resources   = cn400_domain_read_resources, 
     242        .set_resources    = cn400_domain_set_resources, 
    243243        .enable_resources = enable_childrens_resources, 
    244244        .init             = 0, 
    245         .scan_bus         = pci_domain_scan_bus, 
     245        .scan_bus         = cn400_domain_scan_bus, 
    246246}; 
    247247 
  • trunk/coreboot-v2/src/northbridge/via/cn700/northbridge.c

    r4381 r4394  
    9898}; 
    9999 
    100 static void pci_domain_read_resources(device_t dev) 
    101 { 
    102         struct resource *resource; 
    103  
    104         printk_spew("Entering cn700 pci_domain_read_resources.\n"); 
    105  
    106         /* Initialize the system wide I/O space constraints. */ 
    107         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    108         resource->limit = 0xffffUL; 
    109         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
    110             IORESOURCE_ASSIGNED; 
    111  
    112         /* Initialize the system wide memory resources constraints. */ 
    113         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    114         resource->limit = 0xffffffffULL; 
    115         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
    116             IORESOURCE_ASSIGNED; 
    117  
    118         printk_spew("Leaving cn700 pci_domain_read_resources.\n"); 
    119 } 
    120  
    121100static void ram_resource(device_t dev, unsigned long index, 
    122101                         unsigned long basek, unsigned long sizek) 
     
    224203} 
    225204 
    226 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    227 { 
    228         printk_debug("Entering cn700 pci_domain_scan_bus.\n"); 
    229  
    230         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    231         return max; 
    232 } 
    233  
    234205static const struct device_operations pci_domain_ops = { 
    235206        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/via/cx700/cx700_lpc.c

    r4126 r4394  
    330330void cx700_read_resources(device_t dev) 
    331331{ 
    332         struct resource *resource; 
     332        struct resource *res; 
    333333 
    334334        /* Make sure we call our childrens set/enable functions - these 
     
    338338        pci_dev_read_resources(dev); 
    339339 
    340         resource = new_resource(dev, 1); 
    341         resource->flags |= 
    342             IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IO | IORESOURCE_STORED; 
    343         resource->size = 2; 
    344         resource->base = 0x2e; 
     340        res = new_resource(dev, 1); 
     341        res->base = 0x0UL; 
     342        res->size = 0x400UL; 
     343        res->limit = 0xffffUL; 
     344        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     345 
     346        res = new_resource(dev, 3); /* IOAPIC */ 
     347        res->base = 0xfec00000; 
     348        res->size = 0x00001000; 
     349        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    345350} 
    346351 
  • trunk/coreboot-v2/src/northbridge/via/cx700/northbridge.c

    r4381 r4394  
    3232#include "chip.h" 
    3333#include "northbridge.h" 
    34  
    35 static void pci_domain_read_resources(device_t dev) 
    36 { 
    37         struct resource *resource; 
    38  
    39         /* Initialize the system wide io space constraints */ 
    40         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    41         resource->limit = 0xffffUL; 
    42         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    43  
    44         /* Initialize the system wide memory resources constraints */ 
    45         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    46         resource->limit = 0xffffffffULL; 
    47         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    48 } 
    4934 
    5035static void ram_resource(device_t dev, unsigned long index, 
     
    147132} 
    148133 
    149 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    150 { 
    151         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    152         return max; 
    153 } 
    154  
    155134static struct device_operations pci_domain_ops = { 
    156135        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/via/vt8601/northbridge.c

    r4381 r4394  
    4545        .device = 0x0601, /* 0x8601 is the AGP bridge? */ 
    4646}; 
    47  
    48 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    49  
    50 static void pci_domain_read_resources(device_t dev) 
    51 { 
    52         struct resource *resource; 
    53  
    54         /* Initialize the system wide io space constraints */ 
    55         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    56         resource->limit = 0xffffUL; 
    57         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    58  
    59         /* Initialize the system wide memory resources constraints */ 
    60         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    61         resource->limit = 0xffffffffULL; 
    62         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    63 } 
    6447 
    6548static void ram_resource(device_t dev, unsigned long index, 
     
    161144} 
    162145 
    163 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    164 { 
    165         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    166         return max; 
    167 } 
    168  
    169146static struct device_operations pci_domain_ops = { 
    170147        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/via/vt8623/northbridge.c

    r4381 r4394  
    190190        .device = 0x3122, 
    191191}; 
    192  
    193  
    194 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM) 
    195  
    196 static void pci_domain_read_resources(device_t dev) 
    197 { 
    198         struct resource *resource; 
    199  
    200         printk_spew("Entering vt8623 pci_domain_read_resources.\n"); 
    201  
    202         /* Initialize the system wide io space constraints */ 
    203         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0)); 
    204         resource->limit = 0xffffUL; 
    205         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
    206                 IORESOURCE_ASSIGNED; 
    207  
    208         /* Initialize the system wide memory resources constraints */ 
    209         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0)); 
    210         resource->limit = 0xffffffffULL; 
    211         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
    212                 IORESOURCE_ASSIGNED; 
    213  
    214         printk_spew("Leaving vt8623 pci_domain_read_resources.\n"); 
    215 } 
    216192 
    217193static void ram_resource(device_t dev, unsigned long index, 
     
    314290} 
    315291 
    316 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    317 { 
    318         printk_spew("Entering vt8623 pci_domain_scan_bus.\n"); 
    319  
    320         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    321         return max; 
    322 } 
    323  
    324292static struct device_operations pci_domain_ops = { 
    325293        .read_resources   = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/northbridge/via/vx800/northbridge.c

    r4314 r4394  
    7070}; 
    7171 
    72 static void pci_domain_read_resources(device_t dev) 
    73 { 
    74         struct resource *resource; 
    75  
    76         printk_spew("Entering vx800 pci_domain_read_resources.\n"); 
    77  
    78         /* Initialize the system wide io space constraints */ 
    79         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    80         resource->limit = 0xffffUL; 
    81         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
    82             IORESOURCE_ASSIGNED; 
    83  
    84         /* Initialize the system wide memory resources constraints */ 
    85         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    86         resource->limit = 0xffffffffULL; 
    87         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
    88             IORESOURCE_ASSIGNED; 
    89  
    90         printk_spew("Leaving vx800 pci_domain_read_resources.\n"); 
    91 } 
    92  
    9372static void ram_resource(device_t dev, unsigned long index, 
    9473                         unsigned long basek, unsigned long sizek) 
     
    196175} 
    197176 
    198 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max) 
    199 { 
    200         printk_debug("Entering vx800 pci_domain_scan_bus.\n"); 
    201  
    202         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max); 
    203         return max; 
    204 } 
    205  
    206177static const struct device_operations pci_domain_ops = { 
    207178        .read_resources = pci_domain_read_resources, 
  • trunk/coreboot-v2/src/southbridge/amd/amd8111/amd8111_lpc.c

    r4335 r4394  
    163163        struct resource *res; 
    164164 
    165         /* Get the normal pci resources of this device */ 
     165        /* Get the normal PCI resources of this device. */ 
    166166        pci_dev_read_resources(dev); 
    167167 
    168         /* Add an extra subtractive resource for both memory and I/O */ 
     168        /* Add an extra subtractive resource for both memory and I/O. */ 
    169169        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    170         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    171          
     170        res->base = 0; 
     171        res->size = 0x1000; 
     172        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     173                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     174 
    172175        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    173         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     176        res->base = 0xff800000; 
     177        res->size = 0x00800000; /* 8 MB for flash */ 
     178        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     179                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     180 
     181        res = new_resource(dev, 3); /* IOAPIC */ 
     182        res->base = 0xfec00000; 
     183        res->size = 0x00001000; 
     184        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    174185} 
    175186 
  • trunk/coreboot-v2/src/southbridge/amd/amd8131/amd8131_bridge.c

    r4335 r4394  
    365365                dev->command |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; 
    366366                res->flags |= IORESOURCE_STORED; 
    367                 compute_allocate_resource(&dev->link[0], res, 
    368                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    369                         IORESOURCE_MEM); 
    370367                base = res->base; 
    371368                end  = resource_end(res); 
  • trunk/coreboot-v2/src/southbridge/amd/amd8132/amd8132_bridge.c

    r3964 r4394  
    351351                dev->command |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; 
    352352                res->flags |= IORESOURCE_STORED; 
    353                 compute_allocate_resource(&dev->link[0], res, 
    354                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
    355                         IORESOURCE_MEM); 
    356353                base = res->base; 
    357354                end  = resource_end(res); 
  • trunk/coreboot-v2/src/southbridge/amd/cs5530/cs5530_isa.c

    r3052 r4394  
    2626#include "cs5530.h" 
    2727 
     28static void cs5530_read_resources(device_t dev) 
     29{ 
     30        struct resource* res; 
     31 
     32        pci_dev_read_resources(dev); 
     33 
     34        res = new_resource(dev, 1); 
     35        res->base = 0x0UL; 
     36        res->size = 0x400UL; 
     37        res->limit = 0xffffUL; 
     38        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     39 
     40        res = new_resource(dev, 3); /* IOAPIC */ 
     41        res->base = 0xfec00000; 
     42        res->size = 0x00001000; 
     43        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     44} 
     45 
    2846static void isa_init(struct device *dev) 
    2947{ 
     
    4664 
    4765static struct device_operations isa_ops = { 
    48         .read_resources         = pci_dev_read_resources, 
     66        .read_resources         = cs5530_read_resources, 
    4967        .set_resources          = pci_dev_set_resources, 
    5068        .enable_resources       = cs5530_pci_dev_enable_resources, 
  • trunk/coreboot-v2/src/southbridge/amd/cs5535/cs5535.c

    r3943 r4394  
    7070} 
    7171 
     72static void cs5535_read_resources(device_t dev) 
     73{ 
     74        struct resource* res; 
     75 
     76        pci_dev_read_resources(dev); 
     77 
     78        res = new_resource(dev, 1); 
     79        res->base = 0x0UL; 
     80        res->size = 0x400UL; 
     81        res->limit = 0xffffUL; 
     82        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     83 
     84        res = new_resource(dev, 3); /* IOAPIC */ 
     85        res->base = 0xfec00000; 
     86        res->size = 0x00001000; 
     87        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     88} 
     89 
    7290static void cs5535_pci_dev_enable_resources(device_t dev) 
    7391{ 
     
    7896 
    7997static struct device_operations southbridge_ops = { 
    80         .read_resources   = pci_dev_read_resources, 
     98        .read_resources   = cs5535_read_resources, 
    8199        .set_resources    = pci_dev_set_resources, 
    82100        .enable_resources = cs5535_pci_dev_enable_resources, 
  • trunk/coreboot-v2/src/southbridge/amd/cs5536/cs5536.c

    r3980 r4394  
    608608} 
    609609 
     610static void cs5536_read_resources(device_t dev) 
     611{ 
     612        struct resource *res; 
     613 
     614        pci_dev_read_resources(dev); 
     615 
     616        res = new_resource(dev, 1); 
     617        res->base = 0x0UL; 
     618        res->size = 0x400UL; 
     619        res->limit = 0xffffUL; 
     620        res->flags = IORESOURCE_IO | 
     621                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     622 
     623        res = new_resource(dev, 3); /* IOAPIC */ 
     624        res->base = 0xfec00000; 
     625        res->size = 0x00001000; 
     626        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     627} 
     628 
    610629static void southbridge_enable(struct device *dev) 
    611630{ 
     
    622641 
    623642static struct device_operations southbridge_ops = { 
    624         .read_resources = pci_dev_read_resources, 
     643        .read_resources = cs5536_read_resources, 
    625644        .set_resources = pci_dev_set_resources, 
    626645        .enable_resources = cs5536_pci_dev_enable_resources, 
  • trunk/coreboot-v2/src/southbridge/amd/sb600/sb600_lpc.c

    r3785 r4394  
    7171        pci_get_resource(dev, 0xA0); /* SPI ROM base address */ 
    7272 
    73         /* Add an extra subtractive resource for both memory and I/O */ 
     73        /* Add an extra subtractive resource for both memory and I/O. */ 
    7474        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    75         res->flags = 
    76             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     75        res->base = 0; 
     76        res->size = 0x1000; 
     77        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     78                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    7779 
    7880        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    79         res->flags = 
    80             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     81        res->base = 0xff800000; 
     82        res->size = 0x00800000; /* 8 MB for flash */ 
     83        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     84                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     85 
     86        res = new_resource(dev, 3); /* IOAPIC */ 
     87        res->base = 0xfec00000; 
     88        res->size = 0x00001000; 
     89        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    8190 
    8291        compact_resources(dev); 
     
    112121                     child = child->sibling) { 
    113122                        enable_resources(child); 
    114                         if (child->have_resources 
     123                        if (child->enabled 
    115124                            && (child->path.type == DEVICE_PATH_PNP)) { 
    116125                                for (i = 0; i < child->resources; i++) { 
  • trunk/coreboot-v2/src/southbridge/broadcom/bcm5785/bcm5785_lpc.c

    r2891 r4394  
    3030{ 
    3131        struct resource *res; 
    32         unsigned long index; 
    3332 
    3433        /* Get the normal pci resources of this device */ 
    35         pci_dev_read_resources(dev);  
    36          
    37         /* Add an extra subtractive resource for both memory and I/O */ 
    38         res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    39         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
    40          
    41         res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    42         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     34        pci_dev_read_resources(dev); 
    4335 
     36        /* Add an extra subtractive resource for both memory and I/O. */ 
     37        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
     38        res->base = 0; 
     39        res->size = 0x1000; 
     40        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     41                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     42 
     43        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
     44        res->base = 0xff800000; 
     45        res->size = 0x00800000; /* 8 MB for flash */ 
     46        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     47                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     48 
     49        res = new_resource(dev, 3); /* IOAPIC */ 
     50        res->base = 0xfec00000; 
     51        res->size = 0x00001000; 
     52        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    4453} 
    4554 
     
    7079                for (child = dev->link[link].children; child; child = child->sibling) { 
    7180                        enable_resources(child); 
    72                         if(child->have_resources && (child->path.type == DEVICE_PATH_PNP)) { 
     81                        if(child->enabled && (child->path.type == DEVICE_PATH_PNP)) { 
    7382                                for(i=0;i<child->resources;i++) { 
    7483                                        struct resource *res; 
  • trunk/coreboot-v2/src/southbridge/broadcom/bcm5785/bcm5785_sb_pci_main.c

    r4335 r4394  
    5252        /* Get the normal pci resources of this device */ 
    5353        pci_dev_read_resources(dev);             
    54          
    5554        /* Get Resource for SMBUS */     
    5655        pci_get_resource(dev, 0x90);     
  • trunk/coreboot-v2/src/southbridge/intel/esb6300/esb6300_lpc.c

    r4335 r4394  
    362362        res = pci_get_resource(dev, GPIO_BAR); 
    363363 
    364         /* Add an extra subtractive resource for both memory and I/O */ 
     364        /* Add an extra subtractive resource for both memory and I/O. */ 
    365365        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    366         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     366        res->base = 0; 
     367        res->size = 0x1000; 
     368        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     369                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    367370 
    368371        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    369         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     372        res->base = 0xff800000; 
     373        res->size = 0x00800000; /* 8 MB for flash */ 
     374        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     375                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     376 
     377        res = new_resource(dev, 3); /* IOAPIC */ 
     378        res->base = 0xfec00000; 
     379        res->size = 0x00001000; 
     380        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    370381} 
    371382 
  • trunk/coreboot-v2/src/southbridge/intel/i3100/i3100_lpc.c

    r4392 r4394  
    400400        res = pci_get_resource(dev, GPIO_BAR); 
    401401 
    402         /* Add an extra subtractive resource for both memory and I/O */ 
     402        /* Add an extra subtractive resource for both memory and I/O. */ 
    403403        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    404         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     404        res->base = 0; 
     405        res->size = 0x1000; 
     406        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     407                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    405408 
    406409        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    407         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     410        res->base = 0xff800000; 
     411        res->size = 0x00800000; /* 8 MB for flash */ 
     412        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     413                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     414 
     415        res = new_resource(dev, 3); /* IOAPIC */ 
     416        res->base = 0xfec00000; 
     417        res->size = 0x00001000; 
     418        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    408419 
    409420        /* Add resource for RCBA */ 
  • trunk/coreboot-v2/src/southbridge/intel/i82371eb/i82371eb_isa.c

    r4269 r4394  
    5656} 
    5757 
    58 static const struct device_operations isa_ops = { 
    59         .read_resources         = pci_dev_read_resources, 
     58static void sb_read_resources(struct device *dev) 
     59{ 
     60        struct resource *res; 
     61 
     62        pci_dev_read_resources(dev); 
     63 
     64        res = new_resource(dev, 1); 
     65        res->base = 0x0UL; 
     66        res->size = 0x1000UL; 
     67        res->limit = 0xffffUL; 
     68        res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     69 
     70        res = new_resource(dev, 2); 
     71        res->base = 0xff800000UL; 
     72        res->size = 0x00800000UL; /* 8 MB for flash */ 
     73        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     74 
     75        res = new_resource(dev, 3); /* IOAPIC */ 
     76        res->base = 0xfec00000; 
     77        res->size = 0x00001000; 
     78        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     79} 
     80 
     81const struct device_operations isa_ops = { 
     82        .read_resources         = sb_read_resources, 
    6083        .set_resources          = pci_dev_set_resources, 
    6184        .enable_resources       = pci_dev_enable_resources, 
  • trunk/coreboot-v2/src/southbridge/intel/i82801ca/i82801ca_lpc.c

    r4381 r4394  
    208208        struct resource *res; 
    209209 
    210         /* Get the normal pci resources of this device */ 
     210        /* Get the normal PCI resources of this device. */ 
    211211        pci_dev_read_resources(dev); 
    212212 
    213         /* Add an extra subtractive resource for both memory and I/O */ 
     213        /* Add an extra subtractive resource for both memory and I/O. */ 
    214214        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    215         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     215        res->base = 0; 
     216        res->size = 0x1000; 
     217        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     218                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    216219 
    217220        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    218         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     221        res->base = 0xff800000; 
     222        res->size = 0x00800000; /* 8 MB for flash */ 
     223        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     224                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     225 
     226        res = new_resource(dev, 3); /* IOAPIC */ 
     227        res->base = 0xfec00000; 
     228        res->size = 0x00001000; 
     229        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    219230} 
    220231 
  • trunk/coreboot-v2/src/southbridge/intel/i82801dbm/i82801dbm_lpc.c

    r4340 r4394  
    183183        struct resource *res; 
    184184 
    185         /* Get the normal pci resources of this device */ 
     185        /* Get the normal PCI resources of this device. */ 
    186186        pci_dev_read_resources(dev); 
    187187 
    188         /* Add an extra subtractive resource for both memory and I/O */ 
     188        /* Add an extra subtractive resource for both memory and I/O. */ 
    189189        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    190         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     190        res->base = 0; 
     191        res->size = 0x1000; 
     192        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     193                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    191194 
    192195        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    193         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     196        res->base = 0xff800000; 
     197        res->size = 0x00800000; /* 8 MB for flash */ 
     198        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     199                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     200 
     201        res = new_resource(dev, 3); /* IOAPIC */ 
     202        res->base = 0xfec00000; 
     203        res->size = 0x00001000; 
     204        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    194205} 
    195206 
  • trunk/coreboot-v2/src/southbridge/intel/i82801er/i82801er_lpc.c

    r4381 r4394  
    335335        struct resource *res; 
    336336 
    337         /* Get the normal pci resources of this device */ 
     337        /* Get the normal PCI resources of this device. */ 
    338338        pci_dev_read_resources(dev); 
    339339 
     
    344344        res = pci_get_resource(dev, GPIO_BAR); 
    345345 
    346         /* Add an extra subtractive resource for both memory and I/O */ 
     346        /* Add an extra subtractive resource for both memory and I/O. */ 
    347347        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    348         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     348        res->base = 0; 
     349        res->size = 0x1000; 
     350        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     351                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    349352 
    350353        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    351         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     354        res->base = 0xff800000; 
     355        res->size = 0x00800000; /* 8 MB for flash */ 
     356        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     357                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     358 
     359        res = new_resource(dev, 3); /* IOAPIC */ 
     360        res->base = 0xfec00000; 
     361        res->size = 0x00001000; 
     362        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    352363} 
    353364 
  • trunk/coreboot-v2/src/southbridge/intel/i82801gx/i82801gx_lpc.c

    r4381 r4394  
    420420        /* Add an extra subtractive resource for both memory and I/O. */ 
    421421        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    422         res->flags = 
    423             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     422        res->base = 0; 
     423        res->size = 0x1000; 
     424        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     425                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    424426 
    425427        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    426         res->flags = 
    427             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     428        res->base = 0xff800000; 
     429        res->size = 0x00800000; /* 8 MB for flash */ 
     430        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     431                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     432 
     433        res = new_resource(dev, 3); /* IOAPIC */ 
     434        res->base = 0xfec00000; 
     435        res->size = 0x00001000; 
     436        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    428437} 
    429438 
  • trunk/coreboot-v2/src/southbridge/intel/i82801xx/i82801xx_lpc.c

    r4335 r4394  
    341341        /* Add an extra subtractive resource for both memory and I/O. */ 
    342342        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    343         res->flags = 
    344             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     343        res->base = 0; 
     344        res->size = 0x1000; 
     345        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     346                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    345347 
    346348        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    347         res->flags = 
    348             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     349        res->base = 0xff800000; 
     350        res->size = 0x00800000; /* 8 MB for flash */ 
     351        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     352                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     353 
     354        res = new_resource(dev, 3); /* IOAPIC */ 
     355        res->base = 0xfec00000; 
     356        res->size = 0x00001000; 
     357        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    349358} 
    350359 
  • trunk/coreboot-v2/src/southbridge/nvidia/ck804/ck804_lpc.c

    r4381 r4394  
    276276        /* Add an extra subtractive resource for both memory and I/O. */ 
    277277        res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); 
    278         res->flags = 
    279             IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     278        res->base = 0; 
     279        res->size = 0x1000; 
     280        res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | 
     281                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    280282 
    281283        res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); 
    282         res->flags = 
    283             IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED; 
     284        res->base = 0xff800000; 
     285        res->size = 0x00800000; /* 8 MB for flash */ 
     286        res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | 
     287                     IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
     288 
     289        res = new_resource(dev, 3); /* IOAPIC */ 
     290        res->base = 0xfec00000; 
     291        res->size = 0x00001000; 
     292        res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; 
    284293} 
    285294 
     
    309318                for (child = dev->link[link].children; child; child = child->sibling) { 
    310319                        enable_resources(child); 
    311                         if (child->have_resources && (child->path.type == DEVICE_PATH_PNP)) { 
     320                        if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) { 
    312321                                for (i = 0; i < child->resources; i++) { 
    313322                                        struct resource *res; 
  • trunk/coreboot-v2/src/southbridge/nvidia/ck804/ck804_pci.c

    r3631 r4394  
    66#include <console/console.h> 
    77#include <device/device.h> 
     8#include <device/resource.h> 
    89#include <device/pci.h> 
    910#include <device/pci_ids.h> 
     
    1415{ 
    1516        uint32_t dword; 
    16 #if CONFIG_PCI_64BIT_PREF_MEM == 1 
    1717        device_t pci_domain_dev; 
    18         struct resource *mem1, *mem2; 
    19 #endif 
     18        struct resource *mem, *pref; 
    2019 
    2120        dword = pci_read_config32(dev, 0x04); 
     
    3736#endif 
    3837 
    39 #if CONFIG_PCI_64BIT_PREF_MEM == 1 
    4038        pci_domain_dev = dev->bus->dev; 
    4139        while (pci_domain_dev) { 
     
    4846                return;         /* Impossible */ 
    4947 
    50         mem1 = find_resource(pci_domain_dev, 1);        // prefmem, it could be 64bit 
    51         mem2 = find_resource(pci_domain_dev, 2);        // mem 
    52         if (mem1->base > mem2->base) { 
    53                 dword = mem2->base & (0xffff0000UL); 
    54                 printk_debug("PCI DOMAIN mem2 base = 0x%010Lx\n", mem2->base); 
     48        pref = probe_reso