Skip to content

Commit

Permalink
Merge branch 'pci/resource' into next
Browse files Browse the repository at this point in the history
* pci/resource: (26 commits)
  Revert "[PATCH] Insert GART region into resource map"
  PCI: Log IDE resource quirk in dmesg
  PCI: Change pci_bus_alloc_resource() type_mask to unsigned long
  PCI: Check all IORESOURCE_TYPE_BITS in pci_bus_alloc_from_region()
  resources: Set type in __request_region()
  PCI: Don't check resource_size() in pci_bus_alloc_resource()
  s390/PCI: Use generic pci_enable_resources()
  tile PCI RC: Use default pcibios_enable_device()
  sparc/PCI: Use default pcibios_enable_device() (Leon only)
  sh/PCI: Use default pcibios_enable_device()
  microblaze/PCI: Use default pcibios_enable_device()
  alpha/PCI: Use default pcibios_enable_device()
  PCI: Add "weak" generic pcibios_enable_device() implementation
  PCI: Don't enable decoding if BAR hasn't been assigned an address
  PCI: Mark 64-bit resource as IORESOURCE_UNSET if we only support 32-bit
  PCI: Don't try to claim IORESOURCE_UNSET resources
  PCI: Check IORESOURCE_UNSET before updating BAR
  PCI: Don't clear IORESOURCE_UNSET when updating BAR
  PCI: Mark resources as IORESOURCE_UNSET if we can't assign them
  PCI: Remove pci_find_parent_resource() use for allocation
  ...
  • Loading branch information
Bjorn Helgaas committed Mar 19, 2014
2 parents 91b4adc + f2e6027 commit 30723cb
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 169 deletions.
6 changes: 0 additions & 6 deletions arch/alpha/kernel/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@ void pcibios_fixup_bus(struct pci_bus *bus)
}
}

int
pcibios_enable_device(struct pci_dev *dev, int mask)
{
return pci_enable_resources(dev, mask);
}

/*
* If we set up a device for bus mastering, we need to check the latency
* timer as certain firmware forgets to set it properly, as seen
Expand Down
5 changes: 0 additions & 5 deletions arch/microblaze/pci/pci-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,6 @@ void pcibios_finish_adding_to_bus(struct pci_bus *bus)
}
EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus);

int pcibios_enable_device(struct pci_dev *dev, int mask)
{
return pci_enable_resources(dev, mask);
}

static void pcibios_setup_phb_resources(struct pci_controller *hose,
struct list_head *resources)
{
Expand Down
16 changes: 1 addition & 15 deletions arch/s390/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,27 +686,13 @@ int pcibios_add_device(struct pci_dev *pdev)
int pcibios_enable_device(struct pci_dev *pdev, int mask)
{
struct zpci_dev *zdev = get_zdev(pdev);
struct resource *res;
u16 cmd;
int i;

zdev->pdev = pdev;
zpci_debug_init_device(zdev);
zpci_fmb_enable_device(zdev);
zpci_map_resources(zdev);

pci_read_config_word(pdev, PCI_COMMAND, &cmd);
for (i = 0; i < PCI_BAR_COUNT; i++) {
res = &pdev->resource[i];

if (res->flags & IORESOURCE_IO)
return -EINVAL;

if (res->flags & IORESOURCE_MEM)
cmd |= PCI_COMMAND_MEMORY;
}
pci_write_config_word(pdev, PCI_COMMAND, cmd);
return 0;
return pci_enable_resources(pdev, mask);
}

void pcibios_disable_device(struct pci_dev *pdev)
Expand Down
5 changes: 0 additions & 5 deletions arch/sh/drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,
return start;
}

int pcibios_enable_device(struct pci_dev *dev, int mask)
{
return pci_enable_resources(dev, mask);
}

static void __init
pcibios_bus_report_status_early(struct pci_channel *hose,
int top_bus, int current_bus,
Expand Down
5 changes: 0 additions & 5 deletions arch/sparc/kernel/leon_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ resource_size_t pcibios_align_resource(void *data, const struct resource *res,
return res->start;
}

int pcibios_enable_device(struct pci_dev *dev, int mask)
{
return pci_enable_resources(dev, mask);
}

/* in/out routines taken from pcic.c
*
* This probably belongs here rather than ioport.c because
Expand Down
12 changes: 0 additions & 12 deletions arch/tile/kernel/pci_gx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,18 +1064,6 @@ char *__init pcibios_setup(char *str)
return str;
}

/*
* Enable memory address decoding, as appropriate, for the
* device described by the 'dev' struct.
*
* This is called from the generic PCI layer, and can be called
* for bridges or endpoints.
*/
int pcibios_enable_device(struct pci_dev *dev, int mask)
{
return pci_enable_resources(dev, mask);
}

/*
* Called for each device after PCI setup is done.
* We initialize the PCI device capabilities conservatively, assuming that
Expand Down
20 changes: 1 addition & 19 deletions arch/x86/kernel/aperture_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <linux/pci_ids.h>
#include <linux/pci.h>
#include <linux/bitops.h>
#include <linux/ioport.h>
#include <linux/suspend.h>
#include <asm/e820.h>
#include <asm/io.h>
Expand Down Expand Up @@ -54,18 +53,6 @@ int fallback_aper_force __initdata;

int fix_aperture __initdata = 1;

static struct resource gart_resource = {
.name = "GART",
.flags = IORESOURCE_MEM,
};

static void __init insert_aperture_resource(u32 aper_base, u32 aper_size)
{
gart_resource.start = aper_base;
gart_resource.end = aper_base + aper_size - 1;
insert_resource(&iomem_resource, &gart_resource);
}

/* This code runs before the PCI subsystem is initialized, so just
access the northbridge directly. */

Expand Down Expand Up @@ -96,7 +83,6 @@ static u32 __init allocate_aperture(void)
memblock_reserve(addr, aper_size);
printk(KERN_INFO "Mapping aperture over %d KB of RAM @ %lx\n",
aper_size >> 10, addr);
insert_aperture_resource((u32)addr, aper_size);
register_nosave_region(addr >> PAGE_SHIFT,
(addr+aper_size) >> PAGE_SHIFT);

Expand Down Expand Up @@ -444,12 +430,8 @@ int __init gart_iommu_hole_init(void)

out:
if (!fix && !fallback_aper_force) {
if (last_aper_base) {
unsigned long n = (32 * 1024 * 1024) << last_aper_order;

insert_aperture_resource((u32)last_aper_base, n);
if (last_aper_base)
return 1;
}
return 0;
}

Expand Down
85 changes: 42 additions & 43 deletions drivers/message/i2o/iop.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,44 @@ static int i2o_iop_activate(struct i2o_controller *c)
return i2o_hrt_get(c);
};

static void i2o_res_alloc(struct i2o_controller *c, unsigned long flags)
{
i2o_status_block *sb = c->status_block.virt;
struct resource *res = &c->mem_resource;
resource_size_t size, align;
int err;

res->name = c->pdev->bus->name;
res->flags = flags;
res->start = 0;
res->end = 0;
osm_info("%s: requires private memory resources.\n", c->name);

if (flags & IORESOURCE_MEM) {
size = sb->desired_mem_size;
align = 1 << 20; /* unspecified, use 1Mb and play safe */
} else {
size = sb->desired_io_size;
align = 1 << 12; /* unspecified, use 4Kb and play safe */
}

err = pci_bus_alloc_resource(c->pdev->bus, res, size, align, 0, 0,
NULL, NULL);
if (err < 0)
return;

if (flags & IORESOURCE_MEM) {
c->mem_alloc = 1;
sb->current_mem_size = resource_size(res);
sb->current_mem_base = res->start;
} else if (flags & IORESOURCE_IO) {
c->io_alloc = 1;
sb->current_io_size = resource_size(res);
sb->current_io_base = res->start;
}
osm_info("%s: allocated PCI space %pR\n", c->name, res);
}

/**
* i2o_iop_systab_set - Set the I2O System Table of the specified IOP
* @c: I2O controller to which the system table should be send
Expand All @@ -665,52 +703,13 @@ static int i2o_iop_systab_set(struct i2o_controller *c)
struct i2o_message *msg;
i2o_status_block *sb = c->status_block.virt;
struct device *dev = &c->pdev->dev;
struct resource *root;
int rc;

if (sb->current_mem_size < sb->desired_mem_size) {
struct resource *res = &c->mem_resource;
res->name = c->pdev->bus->name;
res->flags = IORESOURCE_MEM;
res->start = 0;
res->end = 0;
osm_info("%s: requires private memory resources.\n", c->name);
root = pci_find_parent_resource(c->pdev, res);
if (root == NULL)
osm_warn("%s: Can't find parent resource!\n", c->name);
if (root && allocate_resource(root, res, sb->desired_mem_size, sb->desired_mem_size, sb->desired_mem_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
NULL, NULL) >= 0) {
c->mem_alloc = 1;
sb->current_mem_size = resource_size(res);
sb->current_mem_base = res->start;
osm_info("%s: allocated %llu bytes of PCI memory at "
"0x%016llX.\n", c->name,
(unsigned long long)resource_size(res),
(unsigned long long)res->start);
}
}
if (sb->current_mem_size < sb->desired_mem_size)
i2o_res_alloc(c, IORESOURCE_MEM);

if (sb->current_io_size < sb->desired_io_size) {
struct resource *res = &c->io_resource;
res->name = c->pdev->bus->name;
res->flags = IORESOURCE_IO;
res->start = 0;
res->end = 0;
osm_info("%s: requires private memory resources.\n", c->name);
root = pci_find_parent_resource(c->pdev, res);
if (root == NULL)
osm_warn("%s: Can't find parent resource!\n", c->name);
if (root && allocate_resource(root, res, sb->desired_io_size, sb->desired_io_size, sb->desired_io_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
NULL, NULL) >= 0) {
c->io_alloc = 1;
sb->current_io_size = resource_size(res);
sb->current_mem_base = res->start;
osm_info("%s: allocated %llu bytes of PCI I/O at "
"0x%016llX.\n", c->name,
(unsigned long long)resource_size(res),
(unsigned long long)res->start);
}
}
if (sb->current_io_size < sb->desired_io_size)
i2o_res_alloc(c, IORESOURCE_IO);

msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
if (IS_ERR(msg))
Expand Down
8 changes: 3 additions & 5 deletions drivers/pci/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void pci_clip_resource_to_region(struct pci_bus *bus,

static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
resource_size_t size, resource_size_t align,
resource_size_t min, unsigned int type_mask,
resource_size_t min, unsigned long type_mask,
resource_size_t (*alignf)(void *,
const struct resource *,
resource_size_t,
Expand All @@ -144,7 +144,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
struct resource *r, avail;
resource_size_t max;

type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
type_mask |= IORESOURCE_TYPE_BITS;

pci_bus_for_each_resource(bus, r, i) {
if (!r)
Expand All @@ -162,8 +162,6 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,

avail = *r;
pci_clip_resource_to_region(bus, &avail, region);
if (!resource_size(&avail))
continue;

/*
* "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to
Expand Down Expand Up @@ -202,7 +200,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
*/
int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
resource_size_t size, resource_size_t align,
resource_size_t min, unsigned int type_mask,
resource_size_t min, unsigned long type_mask,
resource_size_t (*alignf)(void *,
const struct resource *,
resource_size_t,
Expand Down
8 changes: 0 additions & 8 deletions drivers/pci/host-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
bridge->release_data = release_data;
}

static bool resource_contains(struct resource *res1, struct resource *res2)
{
return res1->start <= res2->start && res1->end >= res2->end;
}

void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
struct resource *res)
{
Expand All @@ -45,9 +40,6 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
resource_size_t offset = 0;

list_for_each_entry(window, &bridge->windows, list) {
if (resource_type(res) != resource_type(window->res))
continue;

if (resource_contains(window->res, res)) {
offset = window->offset;
break;
Expand Down
46 changes: 30 additions & 16 deletions drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,33 +401,40 @@ EXPORT_SYMBOL_GPL(pci_find_ht_capability);
* @res: child resource record for which parent is sought
*
* For given resource region of given device, return the resource
* region of parent bus the given region is contained in or where
* it should be allocated from.
* region of parent bus the given region is contained in.
*/
struct resource *
pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
{
const struct pci_bus *bus = dev->bus;
struct resource *r;
int i;
struct resource *best = NULL, *r;

pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;
if (res->start && !(res->start >= r->start && res->end <= r->end))
continue; /* Not contained */
if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM))
continue; /* Wrong type */
if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH))
return r; /* Exact match */
/* We can't insert a non-prefetch resource inside a prefetchable parent .. */
if (r->flags & IORESOURCE_PREFETCH)
continue;
/* .. but we can put a prefetchable resource inside a non-prefetchable one */
if (!best)
best = r;
if (res->start && resource_contains(r, res)) {

/*
* If the window is prefetchable but the BAR is
* not, the allocator made a mistake.
*/
if (r->flags & IORESOURCE_PREFETCH &&
!(res->flags & IORESOURCE_PREFETCH))
return NULL;

/*
* If we're below a transparent bridge, there may
* be both a positively-decoded aperture and a
* subtractively-decoded region that contain the BAR.
* We want the positively-decoded one, so this depends
* on pci_bus_for_each_resource() giving us those
* first.
*/
return r;
}
}
return best;
return NULL;
}

/**
Expand Down Expand Up @@ -1178,6 +1185,11 @@ int pci_load_and_free_saved_state(struct pci_dev *dev,
}
EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state);

int __weak pcibios_enable_device(struct pci_dev *dev, int bars)
{
return pci_enable_resources(dev, bars);
}

static int do_pci_enable_device(struct pci_dev *dev, int bars)
{
int err;
Expand Down Expand Up @@ -4262,6 +4274,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
"Rounding up size of resource #%d to %#llx.\n",
i, (unsigned long long)size);
}
r->flags |= IORESOURCE_UNSET;
r->end = size - 1;
r->start = 0;
}
Expand All @@ -4275,6 +4288,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev)
r = &dev->resource[i];
if (!(r->flags & IORESOURCE_MEM))
continue;
r->flags |= IORESOURCE_UNSET;
r->end = resource_size(r) - 1;
r->start = 0;
}
Expand Down
Loading

0 comments on commit 30723cb

Please sign in to comment.