Commit 46bdfe6a authored by Linus Torvalds's avatar Linus Torvalds

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
parents c15524a4 a2c606d5
......@@ -2175,11 +2175,6 @@ and is between 256 and 4096 characters. It is defined in the file
reset_devices [KNL] Force drivers to reset the underlying device
during initialization.
resource_alloc_from_bottom
Allocate new resources from the beginning of available
space, not the end. If you need to use this, please
report a bug.
resume= [SWSUSP]
Specify the partition device for software suspend
......
......@@ -72,6 +72,9 @@ struct e820map {
#define BIOS_BEGIN 0x000a0000
#define BIOS_END 0x00100000
#define BIOS_ROM_BASE 0xffe00000
#define BIOS_ROM_END 0xffffffff
#ifdef __KERNEL__
/* see comment in arch/x86/kernel/e820.c */
extern struct e820map e820;
......
......@@ -45,6 +45,7 @@ obj-y += pci-dma.o quirks.o i8237.o topology.o kdebugfs.o
obj-y += alternative.o i8253.o pci-nommu.o hw_breakpoint.o
obj-y += tsc.o io_delay.o rtc.o
obj-y += pci-iommu_table.o
obj-y += resource.o
obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o
obj-y += process.o
......
#include <linux/ioport.h>
#include <asm/e820.h>
static void resource_clip(struct resource *res, resource_size_t start,
resource_size_t end)
{
resource_size_t low = 0, high = 0;
if (res->end < start || res->start > end)
return; /* no conflict */
if (res->start < start)
low = start - res->start;
if (res->end > end)
high = res->end - end;
/* Keep the area above or below the conflict, whichever is larger */
if (low > high)
res->end = start - 1;
else
res->start = end + 1;
}
static void remove_e820_regions(struct resource *avail)
{
int i;
struct e820entry *entry;
for (i = 0; i < e820.nr_map; i++) {
entry = &e820.map[i];
resource_clip(avail, entry->addr,
entry->addr + entry->size - 1);
}
}
void arch_remove_reservations(struct resource *avail)
{
/* Trim out BIOS areas (low 1MB and high 2MB) and E820 regions */
if (avail->flags & IORESOURCE_MEM) {
if (avail->start < BIOS_END)
avail->start = BIOS_END;
resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
remove_e820_regions(avail);
}
}
......@@ -769,7 +769,6 @@ void __init setup_arch(char **cmdline_p)
x86_init.oem.arch_setup();
resource_alloc_from_bottom = 0;
iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
setup_memory_map();
parse_setup_data();
......
......@@ -65,21 +65,13 @@ pcibios_align_resource(void *data, const struct resource *res,
resource_size_t size, resource_size_t align)
{
struct pci_dev *dev = data;
resource_size_t start = round_down(res->end - size + 1, align);
resource_size_t start = res->start;
if (res->flags & IORESOURCE_IO) {
/*
* If we're avoiding ISA aliases, the largest contiguous I/O
* port space is 256 bytes. Clearing bits 9 and 10 preserves
* all 256-byte and smaller alignments, so the result will
* still be correctly aligned.
*/
if (!skip_isa_ioresource_align(dev))
start &= ~0x300;
} else if (res->flags & IORESOURCE_MEM) {
if (start < BIOS_END)
start = res->end; /* fail; no space */
if (skip_isa_ioresource_align(dev))
return start;
if (start & 0x300)
start = (start + 0x3ff) & ~0x3ff;
}
return start;
}
......
......@@ -64,77 +64,6 @@ void pci_bus_remove_resources(struct pci_bus *bus)
}
}
static bool pci_bus_resource_better(struct resource *res1, bool pos1,
struct resource *res2, bool pos2)
{
/* If exactly one is positive decode, always prefer that one */
if (pos1 != pos2)
return pos1 ? true : false;
/* Prefer the one that contains the highest address */
if (res1->end != res2->end)
return (res1->end > res2->end) ? true : false;
/* Otherwise, prefer the one with highest "center of gravity" */
if (res1->start != res2->start)
return (res1->start > res2->start) ? true : false;
/* Otherwise, choose one arbitrarily (but consistently) */
return (res1 > res2) ? true : false;
}
static bool pci_bus_resource_positive(struct pci_bus *bus, struct resource *res)
{
struct pci_bus_resource *bus_res;
/*
* This relies on the fact that pci_bus.resource[] refers to P2P or
* CardBus bridge base/limit registers, which are always positively
* decoded. The pci_bus.resources list contains host bridge or
* subtractively decoded resources.
*/
list_for_each_entry(bus_res, &bus->resources, list) {
if (bus_res->res == res)
return (bus_res->flags & PCI_SUBTRACTIVE_DECODE) ?
false : true;
}
return true;
}
/*
* Find the next-best bus resource after the cursor "res". If the cursor is
* NULL, return the best resource. "Best" means that we prefer positive
* decode regions over subtractive decode, then those at higher addresses.
*/
static struct resource *pci_bus_find_resource_prev(struct pci_bus *bus,
unsigned int type,
struct resource *res)
{
bool res_pos, r_pos, prev_pos = false;
struct resource *r, *prev = NULL;
int i;
res_pos = pci_bus_resource_positive(bus, res);
pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;
if ((r->flags & IORESOURCE_TYPE_BITS) != type)
continue;
r_pos = pci_bus_resource_positive(bus, r);
if (!res || pci_bus_resource_better(res, res_pos, r, r_pos)) {
if (!prev || pci_bus_resource_better(r, r_pos,
prev, prev_pos)) {
prev = r;
prev_pos = r_pos;
}
}
}
return prev;
}
/**
* pci_bus_alloc_resource - allocate a resource from a parent bus
* @bus: PCI bus
......@@ -160,10 +89,9 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
resource_size_t),
void *alignf_data)
{
int ret = -ENOMEM;
int i, ret = -ENOMEM;
struct resource *r;
resource_size_t max = -1;
unsigned int type = res->flags & IORESOURCE_TYPE_BITS;
type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
......@@ -171,9 +99,10 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
if (!(res->flags & IORESOURCE_MEM_64))
max = PCIBIOS_MAX_MEM_32;
/* Look for space at highest addresses first */
r = pci_bus_find_resource_prev(bus, type, NULL);
for ( ; r; r = pci_bus_find_resource_prev(bus, type, r)) {
pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;
/* type_mask must match */
if ((res->flags ^ r->flags) & type_mask)
continue;
......
......@@ -2329,6 +2329,9 @@ static void __devinit nvbridge_check_legacy_irq_routing(struct pci_dev *dev)
{
u32 cfg;
if (!pci_find_capability(dev, PCI_CAP_ID_HT))
return;
pci_read_config_dword(dev, 0x74, &cfg);
if (cfg & ((1 << 2) | (1 << 15))) {
......
......@@ -112,7 +112,6 @@ struct resource_list {
/* PC/ISA/whatever - the normal PC address spaces: IO and memory */
extern struct resource ioport_resource;
extern struct resource iomem_resource;
extern int resource_alloc_from_bottom;
extern struct resource *request_resource_conflict(struct resource *root, struct resource *new);
extern int request_resource(struct resource *root, struct resource *new);
......@@ -124,6 +123,7 @@ extern void reserve_region_with_split(struct resource *root,
extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new);
extern int insert_resource(struct resource *parent, struct resource *new);
extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
extern void arch_remove_reservations(struct resource *avail);
extern int allocate_resource(struct resource *root, struct resource *new,
resource_size_t size, resource_size_t min,
resource_size_t max, resource_size_t align,
......
......@@ -40,23 +40,6 @@ EXPORT_SYMBOL(iomem_resource);
static DEFINE_RWLOCK(resource_lock);
/*
* By default, we allocate free space bottom-up. The architecture can request
* top-down by clearing this flag. The user can override the architecture's
* choice with the "resource_alloc_from_bottom" kernel boot option, but that
* should only be a debugging tool.
*/
int resource_alloc_from_bottom = 1;
static __init int setup_alloc_from_bottom(char *s)
{
printk(KERN_INFO
"resource: allocating from bottom-up; please report a bug\n");
resource_alloc_from_bottom = 1;
return 0;
}
early_param("resource_alloc_from_bottom", setup_alloc_from_bottom);
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
{
struct resource *p = v;
......@@ -374,6 +357,10 @@ int __weak page_is_ram(unsigned long pfn)
return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
}
void __weak arch_remove_reservations(struct resource *avail)
{
}
static resource_size_t simple_align_resource(void *data,
const struct resource *avail,
resource_size_t size,
......@@ -396,75 +383,8 @@ static bool resource_contains(struct resource *res1, struct resource *res2)
return res1->start <= res2->start && res1->end >= res2->end;
}
/*
* Find the resource before "child" in the sibling list of "root" children.
*/
static struct resource *find_sibling_prev(struct resource *root, struct resource *child)
{
struct resource *this;
for (this = root->child; this; this = this->sibling)
if (this->sibling == child)
return this;
return NULL;
}
/*
* Find empty slot in the resource tree given range and alignment.
* This version allocates from the end of the root resource first.
*/
static int find_resource_from_top(struct resource *root, struct resource *new,
resource_size_t size, resource_size_t min,
resource_size_t max, resource_size_t align,
resource_size_t (*alignf)(void *,
const struct resource *,
resource_size_t,
resource_size_t),
void *alignf_data)
{
struct resource *this;
struct resource tmp, avail, alloc;
tmp.start = root->end;
tmp.end = root->end;
this = find_sibling_prev(root, NULL);
for (;;) {
if (this) {
if (this->end < root->end)
tmp.start = this->end + 1;
} else
tmp.start = root->start;
resource_clip(&tmp, min, max);
/* Check for overflow after ALIGN() */
avail = *new;
avail.start = ALIGN(tmp.start, align);
avail.end = tmp.end;
if (avail.start >= tmp.start) {
alloc.start = alignf(alignf_data, &avail, size, align);
alloc.end = alloc.start + size - 1;
if (resource_contains(&avail, &alloc)) {
new->start = alloc.start;
new->end = alloc.end;
return 0;
}
}
if (!this || this->start == root->start)
break;
tmp.end = this->start - 1;
this = find_sibling_prev(root, this);
}
return -EBUSY;
}
/*
* Find empty slot in the resource tree given range and alignment.
* This version allocates from the beginning of the root resource first.
*/
static int find_resource(struct resource *root, struct resource *new,
resource_size_t size, resource_size_t min,
......@@ -478,23 +398,24 @@ static int find_resource(struct resource *root, struct resource *new,
struct resource *this = root->child;
struct resource tmp = *new, avail, alloc;
tmp.flags = new->flags;
tmp.start = root->start;
/*
* Skip past an allocated resource that starts at 0, since the
* assignment of this->start - 1 to tmp->end below would cause an
* underflow.
* Skip past an allocated resource that starts at 0, since the assignment
* of this->start - 1 to tmp->end below would cause an underflow.
*/
if (this && this->start == 0) {
tmp.start = this->end + 1;
this = this->sibling;
}
for (;;) {
for(;;) {
if (this)
tmp.end = this->start - 1;
else
tmp.end = root->end;
resource_clip(&tmp, min, max);
arch_remove_reservations(&tmp);
/* Check for overflow after ALIGN() */
avail = *new;
......@@ -509,10 +430,8 @@ static int find_resource(struct resource *root, struct resource *new,
return 0;
}
}
if (!this)
break;
tmp.start = this->end + 1;
this = this->sibling;
}
......@@ -545,10 +464,7 @@ int allocate_resource(struct resource *root, struct resource *new,
alignf = simple_align_resource;
write_lock(&resource_lock);
if (resource_alloc_from_bottom)
err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
else
err = find_resource_from_top(root, new, size, min, max, align, alignf, alignf_data);
if (err >= 0 && __request_resource(root, new))
err = -EBUSY;
write_unlock(&resource_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment