Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6:
x86: avoid high BIOS area when allocating address space
x86: avoid E820 regions when allocating address space
x86: avoid low BIOS area when allocating address space
resources: add arch hook for preventing allocation in reserved areas
Revert "resources: support allocating space within a region from the top down"
Revert "PCI: allocate bus resources from the top down"
Revert "x86/PCI: allocate space from the end of a region, not the beginning"
Revert "x86: allocate space within a region top-down"
Revert "PCI: fix pci_bus_alloc_resource() hang, prefer positive decode"
PCI: Update MCP55 quirk to not affect non HyperTransport variants

+76 -190
-5
Documentation/kernel-parameters.txt
··· 2175 2175 reset_devices [KNL] Force drivers to reset the underlying device 2176 2176 during initialization. 2177 2177 2178 - resource_alloc_from_bottom 2179 - Allocate new resources from the beginning of available 2180 - space, not the end. If you need to use this, please 2181 - report a bug. 2182 - 2183 2178 resume= [SWSUSP] 2184 2179 Specify the partition device for software suspend 2185 2180
+3
arch/x86/include/asm/e820.h
··· 72 72 #define BIOS_BEGIN 0x000a0000 73 73 #define BIOS_END 0x00100000 74 74 75 + #define BIOS_ROM_BASE 0xffe00000 76 + #define BIOS_ROM_END 0xffffffff 77 + 75 78 #ifdef __KERNEL__ 76 79 /* see comment in arch/x86/kernel/e820.c */ 77 80 extern struct e820map e820;
+1
arch/x86/kernel/Makefile
··· 45 45 obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o 46 46 obj-y += tsc.o io_delay.o rtc.o 47 47 obj-y += pci-iommu_table.o 48 + obj-y += resource.o 48 49 49 50 obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o 50 51 obj-y += process.o
+48
arch/x86/kernel/resource.c
··· 1 + #include <linux/ioport.h> 2 + #include <asm/e820.h> 3 + 4 + static void resource_clip(struct resource *res, resource_size_t start, 5 + resource_size_t end) 6 + { 7 + resource_size_t low = 0, high = 0; 8 + 9 + if (res->end < start || res->start > end) 10 + return; /* no conflict */ 11 + 12 + if (res->start < start) 13 + low = start - res->start; 14 + 15 + if (res->end > end) 16 + high = res->end - end; 17 + 18 + /* Keep the area above or below the conflict, whichever is larger */ 19 + if (low > high) 20 + res->end = start - 1; 21 + else 22 + res->start = end + 1; 23 + } 24 + 25 + static void remove_e820_regions(struct resource *avail) 26 + { 27 + int i; 28 + struct e820entry *entry; 29 + 30 + for (i = 0; i < e820.nr_map; i++) { 31 + entry = &e820.map[i]; 32 + 33 + resource_clip(avail, entry->addr, 34 + entry->addr + entry->size - 1); 35 + } 36 + } 37 + 38 + void arch_remove_reservations(struct resource *avail) 39 + { 40 + /* Trim out BIOS areas (low 1MB and high 2MB) and E820 regions */ 41 + if (avail->flags & IORESOURCE_MEM) { 42 + if (avail->start < BIOS_END) 43 + avail->start = BIOS_END; 44 + resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END); 45 + 46 + remove_e820_regions(avail); 47 + } 48 + }
-1
arch/x86/kernel/setup.c
··· 769 769 770 770 x86_init.oem.arch_setup(); 771 771 772 - resource_alloc_from_bottom = 0; 773 772 iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1; 774 773 setup_memory_map(); 775 774 parse_setup_data();
+5 -13
arch/x86/pci/i386.c
··· 65 65 resource_size_t size, resource_size_t align) 66 66 { 67 67 struct pci_dev *dev = data; 68 - resource_size_t start = round_down(res->end - size + 1, align); 68 + resource_size_t start = res->start; 69 69 70 70 if (res->flags & IORESOURCE_IO) { 71 - 72 - /* 73 - * If we're avoiding ISA aliases, the largest contiguous I/O 74 - * port space is 256 bytes. Clearing bits 9 and 10 preserves 75 - * all 256-byte and smaller alignments, so the result will 76 - * still be correctly aligned. 77 - */ 78 - if (!skip_isa_ioresource_align(dev)) 79 - start &= ~0x300; 80 - } else if (res->flags & IORESOURCE_MEM) { 81 - if (start < BIOS_END) 82 - start = res->end; /* fail; no space */ 71 + if (skip_isa_ioresource_align(dev)) 72 + return start; 73 + if (start & 0x300) 74 + start = (start + 0x3ff) & ~0x3ff; 83 75 } 84 76 return start; 85 77 }
+5 -76
drivers/pci/bus.c
··· 64 64 } 65 65 } 66 66 67 - static bool pci_bus_resource_better(struct resource *res1, bool pos1, 68 - struct resource *res2, bool pos2) 69 - { 70 - /* If exactly one is positive decode, always prefer that one */ 71 - if (pos1 != pos2) 72 - return pos1 ? true : false; 73 - 74 - /* Prefer the one that contains the highest address */ 75 - if (res1->end != res2->end) 76 - return (res1->end > res2->end) ? true : false; 77 - 78 - /* Otherwise, prefer the one with highest "center of gravity" */ 79 - if (res1->start != res2->start) 80 - return (res1->start > res2->start) ? true : false; 81 - 82 - /* Otherwise, choose one arbitrarily (but consistently) */ 83 - return (res1 > res2) ? true : false; 84 - } 85 - 86 - static bool pci_bus_resource_positive(struct pci_bus *bus, struct resource *res) 87 - { 88 - struct pci_bus_resource *bus_res; 89 - 90 - /* 91 - * This relies on the fact that pci_bus.resource[] refers to P2P or 92 - * CardBus bridge base/limit registers, which are always positively 93 - * decoded. The pci_bus.resources list contains host bridge or 94 - * subtractively decoded resources. 95 - */ 96 - list_for_each_entry(bus_res, &bus->resources, list) { 97 - if (bus_res->res == res) 98 - return (bus_res->flags & PCI_SUBTRACTIVE_DECODE) ? 99 - false : true; 100 - } 101 - return true; 102 - } 103 - 104 - /* 105 - * Find the next-best bus resource after the cursor "res". If the cursor is 106 - * NULL, return the best resource. "Best" means that we prefer positive 107 - * decode regions over subtractive decode, then those at higher addresses. 108 - */ 109 - static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus, 110 - unsigned int type, 111 - struct resource *res) 112 - { 113 - bool res_pos, r_pos, prev_pos = false; 114 - struct resource *r, *prev = NULL; 115 - int i; 116 - 117 - res_pos = pci_bus_resource_positive(bus, res); 118 - pci_bus_for_each_resource(bus, r, i) { 119 - if (!r) 120 - continue; 121 - 122 - if ((r->flags & IORESOURCE_TYPE_BITS) != type) 123 - continue; 124 - 125 - r_pos = pci_bus_resource_positive(bus, r); 126 - if (!res || pci_bus_resource_better(res, res_pos, r, r_pos)) { 127 - if (!prev || pci_bus_resource_better(r, r_pos, 128 - prev, prev_pos)) { 129 - prev = r; 130 - prev_pos = r_pos; 131 - } 132 - } 133 - } 134 - 135 - return prev; 136 - } 137 - 138 67 /** 139 68 * pci_bus_alloc_resource - allocate a resource from a parent bus 140 69 * @bus: PCI bus ··· 89 160 resource_size_t), 90 161 void *alignf_data) 91 162 { 92 - int ret = -ENOMEM; 163 + int i, ret = -ENOMEM; 93 164 struct resource *r; 94 165 resource_size_t max = -1; 95 - unsigned int type = res->flags & IORESOURCE_TYPE_BITS; 96 166 97 167 type_mask |= IORESOURCE_IO | IORESOURCE_MEM; 98 168 ··· 99 171 if (!(res->flags & IORESOURCE_MEM_64)) 100 172 max = PCIBIOS_MAX_MEM_32; 101 173 102 - /* Look for space at highest addresses first */ 103 - r = pci_bus_find_resource_prev(bus, type, NULL); 104 - for ( ; r; r = pci_bus_find_resource_prev(bus, type, r)) { 174 + pci_bus_for_each_resource(bus, r, i) { 175 + if (!r) 176 + continue; 177 + 105 178 /* type_mask must match */ 106 179 if ((res->flags ^ r->flags) & type_mask) 107 180 continue;
+3
drivers/pci/quirks.c
··· 2329 2329 { 2330 2330 u32 cfg; 2331 2331 2332 + if (!pci_find_capability(dev, PCI_CAP_ID_HT)) 2333 + return; 2334 + 2332 2335 pci_read_config_dword(dev, 0x74, &cfg); 2333 2336 2334 2337 if (cfg & ((1 << 2) | (1 << 15))) {
+1 -1
include/linux/ioport.h
··· 112 112 /* PC/ISA/whatever - the normal PC address spaces: IO and memory */ 113 113 extern struct resource ioport_resource; 114 114 extern struct resource iomem_resource; 115 - extern int resource_alloc_from_bottom; 116 115 117 116 extern struct resource *request_resource_conflict(struct resource *root, struct resource *new); 118 117 extern int request_resource(struct resource *root, struct resource *new); ··· 123 124 extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new); 124 125 extern int insert_resource(struct resource *parent, struct resource *new); 125 126 extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new); 127 + extern void arch_remove_reservations(struct resource *avail); 126 128 extern int allocate_resource(struct resource *root, struct resource *new, 127 129 resource_size_t size, resource_size_t min, 128 130 resource_size_t max, resource_size_t align,
+10 -94
kernel/resource.c
··· 40 40 41 41 static DEFINE_RWLOCK(resource_lock); 42 42 43 - /* 44 - * By default, we allocate free space bottom-up. The architecture can request 45 - * top-down by clearing this flag. The user can override the architecture's 46 - * choice with the "resource_alloc_from_bottom" kernel boot option, but that 47 - * should only be a debugging tool. 48 - */ 49 - int resource_alloc_from_bottom = 1; 50 - 51 - static __init int setup_alloc_from_bottom(char *s) 52 - { 53 - printk(KERN_INFO 54 - "resource: allocating from bottom-up; please report a bug\n"); 55 - resource_alloc_from_bottom = 1; 56 - return 0; 57 - } 58 - early_param("resource_alloc_from_bottom", setup_alloc_from_bottom); 59 - 60 43 static void *r_next(struct seq_file *m, void *v, loff_t *pos) 61 44 { 62 45 struct resource *p = v; ··· 357 374 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; 358 375 } 359 376 377 + void __weak arch_remove_reservations(struct resource *avail) 378 + { 379 + } 380 + 360 381 static resource_size_t simple_align_resource(void *data, 361 382 const struct resource *avail, 362 383 resource_size_t size, ··· 384 397 } 385 398 386 399 /* 387 - * Find the resource before "child" in the sibling list of "root" children. 388 - */ 389 - static struct resource *find_sibling_prev(struct resource *root, struct resource *child) 390 - { 391 - struct resource *this; 392 - 393 - for (this = root->child; this; this = this->sibling) 394 - if (this->sibling == child) 395 - return this; 396 - 397 - return NULL; 398 - } 399 - 400 - /* 401 400 * Find empty slot in the resource tree given range and alignment. 402 - * This version allocates from the end of the root resource first. 403 - */ 404 - static int find_resource_from_top(struct resource *root, struct resource *new, 405 - resource_size_t size, resource_size_t min, 406 - resource_size_t max, resource_size_t align, 407 - resource_size_t (*alignf)(void *, 408 - const struct resource *, 409 - resource_size_t, 410 - resource_size_t), 411 - void *alignf_data) 412 - { 413 - struct resource *this; 414 - struct resource tmp, avail, alloc; 415 - 416 - tmp.start = root->end; 417 - tmp.end = root->end; 418 - 419 - this = find_sibling_prev(root, NULL); 420 - for (;;) { 421 - if (this) { 422 - if (this->end < root->end) 423 - tmp.start = this->end + 1; 424 - } else 425 - tmp.start = root->start; 426 - 427 - resource_clip(&tmp, min, max); 428 - 429 - /* Check for overflow after ALIGN() */ 430 - avail = *new; 431 - avail.start = ALIGN(tmp.start, align); 432 - avail.end = tmp.end; 433 - if (avail.start >= tmp.start) { 434 - alloc.start = alignf(alignf_data, &avail, size, align); 435 - alloc.end = alloc.start + size - 1; 436 - if (resource_contains(&avail, &alloc)) { 437 - new->start = alloc.start; 438 - new->end = alloc.end; 439 - return 0; 440 - } 441 - } 442 - 443 - if (!this || this->start == root->start) 444 - break; 445 - 446 - tmp.end = this->start - 1; 447 - this = find_sibling_prev(root, this); 448 - } 449 - return -EBUSY; 450 - } 451 - 452 - /* 453 - * Find empty slot in the resource tree given range and alignment. 454 - * This version allocates from the beginning of the root resource first. 455 401 */ 456 402 static int find_resource(struct resource *root, struct resource *new, 457 403 resource_size_t size, resource_size_t min, ··· 398 478 struct resource *this = root->child; 399 479 struct resource tmp = *new, avail, alloc; 400 480 481 + tmp.flags = new->flags; 401 482 tmp.start = root->start; 402 483 /* 403 - * Skip past an allocated resource that starts at 0, since the 404 - * assignment of this->start - 1 to tmp->end below would cause an 405 - * underflow. 484 + * Skip past an allocated resource that starts at 0, since the assignment 485 + * of this->start - 1 to tmp->end below would cause an underflow. 406 486 */ 407 487 if (this && this->start == 0) { 408 488 tmp.start = this->end + 1; 409 489 this = this->sibling; 410 490 } 411 - for (;;) { 491 + for(;;) { 412 492 if (this) 413 493 tmp.end = this->start - 1; 414 494 else 415 495 tmp.end = root->end; 416 496 417 497 resource_clip(&tmp, min, max); 498 + arch_remove_reservations(&tmp); 418 499 419 500 /* Check for overflow after ALIGN() */ 420 501 avail = *new; ··· 430 509 return 0; 431 510 } 432 511 } 433 - 434 512 if (!this) 435 513 break; 436 - 437 514 tmp.start = this->end + 1; 438 515 this = this->sibling; 439 516 } ··· 464 545 alignf = simple_align_resource; 465 546 466 547 write_lock(&resource_lock); 467 - if (resource_alloc_from_bottom) 468 - err = find_resource(root, new, size, min, max, align, alignf, alignf_data); 469 - else 470 - err = find_resource_from_top(root, new, size, min, max, align, alignf, alignf_data); 548 + err = find_resource(root, new, size, min, max, align, alignf, alignf_data); 471 549 if (err >= 0 && __request_resource(root, new)) 472 550 err = -EBUSY; 473 551 write_unlock(&resource_lock);