All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
To: linux-ia64@vger.kernel.org
Subject: [Linux-ia64] Re: [Pcihpd-discuss] Re: PCI Hotplug Drivers for 2.5
Date: Fri, 25 Oct 2002 15:37:25 +0000	[thread overview]
Message-ID: <marc-linux-ia64-105590709805247@msgid-missing> (raw)
In-Reply-To: <marc-linux-ia64-105590709805235@msgid-missing>

On Thu, Oct 24, 2002 at 06:22:44PM -0400, Scott Murray wrote:
> I hopefully will have something working against 2.5.44 tomorrow.  I think
> the only potentially contentious piece that I'd like to get reviewed and
> maybe integrated before the feature freeze is the resource reservation
> stuff.  There seemed to be no serious objections to the 2.4.x version I
> posted a while back, so maybe this won't be a big deal.  Everything else
> is either __devinit/export tweaks or driver code.

The setup-bus code already does resource reservation, but only for
cardbus. It can be easily extended for any type of hotplug
controller though. Other enhancements (like configurable amount
of reserved IO/memory) also shouldn't be a problem.

Also I have a patch (appended) that allows to use pbus_size_bridges()
for cardbus bridges (which have different resource layout vs. PCI-to-PCI
ones).

BTW, 2.5 setup-* stuff went into 2.4 recently. :-)

Ivan.

--- 2.5.36/drivers/pci/setup-res.c	Wed Sep 18 04:59:13 2002
+++ linux/drivers/pci/setup-res.c	Thu Sep 19 19:31:45 2002
@@ -137,7 +137,7 @@ pci_assign_resource(struct pci_dev *dev,
 }
 
 /* Sort resources by alignment */
-void __init
+void __devinit
 pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
 {
 	int i;
--- 2.5.36/drivers/pci/setup-bus.c	Wed Sep 18 04:58:56 2002
+++ linux/drivers/pci/setup-bus.c	Thu Sep 19 19:29:04 2002
@@ -35,7 +35,7 @@
 
 #define ROUND_UP(x, a)		(((x) + (a) - 1) & ~((a) - 1))
 
-static int __init
+static int __devinit
 pbus_assign_resources_sorted(struct pci_bus *bus)
 {
 	struct list_head *ln;
@@ -85,7 +85,7 @@ pbus_assign_resources_sorted(struct pci_
    requires that if there is no I/O ports or memory behind the
    bridge, corresponding range must be turned off by writing base
    value greater than limit to the bridge's base/limit registers.  */
-static void __init
+static void __devinit
 pci_setup_bridge(struct pci_bus *bus)
 {
 	struct pbus_set_ranges_data ranges;
@@ -168,7 +168,7 @@ pci_setup_bridge(struct pci_bus *bus)
 /* Check whether the bridge supports optional I/O and
    prefetchable memory ranges. If not, the respective
    base/limit registers must be read-only and read as 0. */
-static void __init
+static void __devinit
 pci_bridge_check_ranges(struct pci_bus *bus)
 {
 	u16 io;
@@ -206,20 +206,38 @@ pci_bridge_check_ranges(struct pci_bus *
 		b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
 }
 
+/* Find first free bus resource of a given type */
+static struct resource * __devinit
+pbus_find_resource(struct pci_bus *bus, unsigned long type)
+{
+	int i;
+	struct resource *r;
+
+	for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
+		r = bus->resource[i];
+		if (r && !((r->flags ^ type) & type) && !r->parent)
+			return r;
+	}
+	return NULL;
+}
+
 /* Sizing the IO windows of the PCI-PCI bridge is trivial,
    since these windows have 4K granularity and the IO ranges
    of non-bridge PCI devices are limited to 256 bytes.
    We must be careful with the ISA aliasing though. */
-static void __init
+static void __devinit
 pbus_size_io(struct pci_bus *bus)
 {
 	struct list_head *ln;
-	struct resource *b_res = bus->resource[0];
+	struct resource *b_res = pbus_find_resource(bus, IORESOURCE_IO);
 	unsigned long size = 0, size1 = 0;
 
-	if (!(b_res->flags & IORESOURCE_IO))
+	if (!b_res)
 		return;
 
+	DBGC((KERN_INFO "PCI: found %s resource %ld for IO\n",
+			bus->name, b_res - bus->resource[0]));
+
 	for (ln=bus->devices.next; ln != &bus->devices; ln=ln->next) {
 		struct pci_dev *dev = pci_dev_b(ln);
 		int i;
@@ -259,15 +277,21 @@ pbus_size_io(struct pci_bus *bus)
 
 /* Calculate the size of the bus and minimal alignment which
    guarantees that all child resources fit in this size. */
-static void __init
+static int __devinit
 pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long type)
 {
 	struct list_head *ln;
 	unsigned long min_align, align, size;
 	unsigned long aligns[12];	/* Alignments from 1Mb to 2Gb */
 	int order, max_order;
-	struct resource *b_res = (type & IORESOURCE_PREFETCH) ?
-				 bus->resource[2] : bus->resource[1];
+	struct resource *b_res = pbus_find_resource(bus, type);
+
+	if (!b_res)
+		return 0;
+
+	DBGC((KERN_INFO "PCI: found %s resource %ld for %s\n",
+			bus->name, b_res - bus->resource[0],
+			type & IORESOURCE_PREFETCH ? "PREF" : "MEM"));
 
 	memset(aligns, 0, sizeof(aligns));
 	max_order = 0;
@@ -325,17 +349,18 @@ pbus_size_mem(struct pci_bus *bus, unsig
 	size = ROUND_UP(size, min_align);
 	if (!size) {
 		b_res->flags = 0;
-		return;
+		return 1;
 	}
 	b_res->start = min_align;
 	b_res->end = size + min_align - 1;
+	return 1;
 }
 
-void __init
+void __devinit
 pbus_size_bridges(struct pci_bus *bus)
 {
 	struct list_head *ln;
-	unsigned long mask, type;
+	unsigned long mask, prefetch;
 
 	for (ln=bus->children.next; ln != &bus->children; ln=ln->next)
 		pbus_size_bridges(pci_bus_b(ln));
@@ -348,17 +373,15 @@ pbus_size_bridges(struct pci_bus *bus)
 
 	pbus_size_io(bus);
 
-	mask = type = IORESOURCE_MEM;
+	mask = IORESOURCE_MEM;
+	prefetch = IORESOURCE_MEM | IORESOURCE_PREFETCH;
 	/* If the bridge supports prefetchable range, size it separately. */
-	if (bus->resource[2] &&
-	    bus->resource[2]->flags & IORESOURCE_PREFETCH) {
-		pbus_size_mem(bus, IORESOURCE_PREFETCH, IORESOURCE_PREFETCH);
-		mask |= IORESOURCE_PREFETCH;	/* Size non-prefetch only. */
-	}
-	pbus_size_mem(bus, mask, type);
+	if (pbus_size_mem(bus, prefetch, prefetch))
+		mask = prefetch;		/* Size non-prefetch only. */
+	pbus_size_mem(bus, mask, IORESOURCE_MEM);
 }
 
-void __init
+void __devinit
 pbus_assign_resources(struct pci_bus *bus)
 {
 	struct list_head *ln;
@@ -367,7 +390,8 @@ pbus_assign_resources(struct pci_bus *bu
 	if (found_vga) {
 		struct pci_bus *b;
 
-		/* Propagate presence of the VGA to upstream bridges */
+		/* Propagate presence of the VGA to upstream bridges.
+		   This hack eventually will go away. */
 		for (b = bus; b->parent; b = b->parent) {
 			b->resource[0]->flags |= IORESOURCE_BUS_HAS_VGA;
 		}


  parent reply	other threads:[~2002-10-25 15:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-24 17:44 [Linux-ia64] Re: [Pcihpd-discuss] Re: PCI Hotplug Drivers for 2.5 Scott Murray
2002-10-24 21:49 ` Greg KH
2002-10-24 22:22 ` Scott Murray
2002-10-25 15:37 ` Ivan Kokshaysky [this message]
2002-10-25 22:02 ` Scott Murray
2002-10-25 22:25 ` Russell King
2002-10-26 23:36 ` Scott Murray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-ia64-105590709805247@msgid-missing \
    --to=ink@jurassic.park.msu.ru \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.