Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Jun 2013 02:23:20 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 230215 for review
Message-ID:  <201306270223.r5R2NKtt027139@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@230215?ac=10

Change 230215 by jhb@jhb_pipkin on 2013/06/27 02:22:25

	- Give the PCI bus driver its own release_resource method
	  so it can free resources for PCI-PCI bridge windows.
	- Fix a few bugs with walking the ISA non-alias ranges.
	
	With these changes a system with a bridge with ISA enabled set
	is able to boot ok and appears to DTRT with allocating the little
	subranges instead of the big I/O port range.

Affected files ...

.. //depot/projects/pci/sys/dev/pci/pci.c#40 edit
.. //depot/projects/pci/sys/dev/pci/pci_pci.c#33 edit
.. //depot/projects/pci/sys/dev/pci/pci_private.h#14 edit

Differences ...

==== //depot/projects/pci/sys/dev/pci/pci.c#40 (text+ko) ====

@@ -156,7 +156,7 @@
 	DEVMETHOD(bus_delete_resource,	pci_delete_resource),
 	DEVMETHOD(bus_alloc_resource,	pci_alloc_resource),
 	DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
-	DEVMETHOD(bus_release_resource,	bus_generic_rl_release_resource),
+	DEVMETHOD(bus_release_resource,	pci_release_resource),
 	DEVMETHOD(bus_activate_resource, pci_activate_resource),
 	DEVMETHOD(bus_deactivate_resource, pci_deactivate_resource),
 	DEVMETHOD(bus_child_detached,	pci_child_detached),
@@ -4248,11 +4248,11 @@
 pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
 		   u_long start, u_long end, u_long count, u_int flags)
 {
-	struct pci_devinfo *dinfo = device_get_ivars(child);
-	struct resource_list *rl = &dinfo->resources;
+	struct pci_devinfo *dinfo;
+	struct resource_list *rl;
 	struct resource_list_entry *rle;
 	struct resource *res;
-	pcicfgregs *cfg = &dinfo->cfg;
+	pcicfgregs *cfg;
 
 	if (device_get_parent(child) != dev)
 		return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
@@ -4261,6 +4261,9 @@
 	/*
 	 * Perform lazy resource allocation
 	 */
+	dinfo = device_get_ivars(child);
+	rl = &dinfo->resources;
+	cfg = &dinfo->cfg;
 	switch (type) {
 	case SYS_RES_IRQ:
 		/*
@@ -4316,6 +4319,41 @@
 }
 
 int
+pci_release_resource(device_t dev, device_t child, int type, int rid,
+    struct resource *r)
+{
+	struct pci_devinfo *dinfo;
+	struct resource_list *rl;
+	pcicfgregs *cfg;
+
+	if (device_get_parent(child) != dev)
+		return (BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
+		    type, rid, r));
+
+	dinfo = device_get_ivars(child);
+	cfg = &dinfo->cfg;
+#ifdef NEW_PCIB
+	/*
+	 * PCI-PCI bridge I/O window resources are not BARs.  For
+	 * those allocations just pass the request up the tree.
+	 */
+	if (cfg->hdrtype == PCIM_HDRTYPE_BRIDGE &&
+	    (type == SYS_RES_IOPORT || type == SYS_RES_MEMORY)) {
+		switch (rid) {
+		case PCIR_IOBASEL_1:
+		case PCIR_MEMBASE_1:
+		case PCIR_PMBASEL_1:
+			return (bus_generic_release_resource(dev, child, type,
+			    rid, r));
+		}
+	}
+#endif
+
+	rl = &dinfo->resources;
+	return (resource_list_release(rl, dev, child, type, rid, r));
+}
+
+int
 pci_activate_resource(device_t dev, device_t child, int type, int rid,
     struct resource *r)
 {

==== //depot/projects/pci/sys/dev/pci/pci_pci.c#33 (text+ko) ====

@@ -272,22 +272,25 @@
 {
 	u_long next_end;
 
-	/* ISA aliases are only in the lower 64KB of I/O space. */
-	while (start <= MIN(end, 65535)) {
-		/*
-		 * If start is within an ISA alias range, move up to
-		 * the start of the next non-alias range.  As a
-		 * special case, addresses in the range 0x000 - 0x0ff
-		 * should also be skipped since those are used for
-		 * various system I/O devices in ISA systems.
-		 */
+	/*
+	 * If start is within an ISA alias range, move up to the start
+	 * of the next non-alias range.  As a special case, addresses
+	 * in the range 0x000 - 0x0ff should also be skipped since
+	 * those are used for various system I/O devices in ISA
+	 * systems.
+	 */
+	if (start <= 65535) {
 		if (start < 0x100 || (start & 0x300) != 0) {
-			start &= ~0x3fful;
+			start &= ~0x3ff;
 			start += 0x400;
 		}
+	}
+
+	/* ISA aliases are only in the lower 64KB of I/O space. */
+	while (start <= MIN(end, 65535)) {
 		next_end = MIN(start | 0xff, end);
-		cb(start, end, arg);
-		start = next_end + 1;
+		cb(start, next_end, arg);
+		start += 0x400;
 	}
 
 	if (start <= end)

==== //depot/projects/pci/sys/dev/pci/pci_private.h#14 (text+ko) ====

@@ -98,6 +98,8 @@
 struct resource	*pci_alloc_resource(device_t dev, device_t child, 
 		    int type, int *rid, u_long start, u_long end, u_long count,
 		    u_int flags);
+int		pci_release_resource(device_t dev, device_t child, int type,
+		    int rid, struct resource *r);
 int		pci_activate_resource(device_t dev, device_t child, int type,
 		    int rid, struct resource *r);
 int		pci_deactivate_resource(device_t dev, device_t child, int type,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306270223.r5R2NKtt027139>