Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Dec 2001 19:20:33 +0100
From:      Thomas Moestl <tmoestl@gmx.net>
To:        arch@FreeBSD.org
Subject:   Please review: changes to MI bus code for sparc64
Message-ID:  <20011213192033.A871@crow.dom2ip.de>

next in thread | raw e-mail | index | archive | help
Hi,

I've attached a patch with changes I had to make to MI bus-related
code for the sparc64 port. I would like to commit soonish (around the
21st) if there are no objections.

The changes are in detail:
- pass the bus device to isa_init()
- add a generic resource list printing function, and make use of it in
  the PCI and ISA code (this may change the order in which the
  resources are printed in  the ISA case).
- add a generic __BUS_ACCESSOR macro to generate ivar accessors like
  PCI_ACCESSOR did, and make use of it in the PCI code
- add a 'PCI_BROKEN_INTPIN' option. It activates a workaround for a
  bug in some Sun PCI devices, which have the intpin register wired to
  0 although they use this interrupt generation mechanism.
- another new option, PCI_INTLINE_0_BAD, indicates that an intline
  register value of 0 is used to indicate an unrouted interrupt. It is
  required for some Sun boxes in conjunction with PCI_BROKEN_INTPIN to
  avoid the confusing detection of interrupts that are not actually
  present.
- make most functions in pci_pci.c non-static and add a new header
  (pcib.h) and an extension pointer to the softc to allow drivers for
  non-standard PCI-PCI bridges to use this code instead of duplicating
  most of it.
- add a variation of rman_reserve_resource(),
  rman_reserve_resource_bound(), that can additionally honor a
  boundary for the allocation. This way, the resource manager can be
  used to handle DVMA allocations, for example.
- fix a few bugs in subr_bus.c and subr_rman.c related to the use of
  min()/max() when ulmin()/ulmax() should be used.

It is tested on sparc64 and i386, and build-tested on alpha. It would
be nice if somebody could try to build a kernel with it on ia64 (there
is a one-line change to ia64-specific code).

The patch is also available at
 http://people.FreeBSD.org/~tmm/sparc64-bus-mi.diff

Comments?

Thanks,
	- thomas


--- freebsd/sys/isa/isa_common.c	Sat Sep  8 19:46:52 2001
+++ sparc64/sys/isa/isa_common.c	Wed Oct 10 00:59:24 2001
@@ -92,7 +92,7 @@
 isa_probe(device_t dev)
 {
 	device_set_desc(dev, "ISA bus");
-	isa_init();		/* Allow machdep code to initialise */
+	isa_init(dev);		/* Allow machdep code to initialise */
 	return 0;
 }
 
@@ -634,37 +634,6 @@
 }
 
 static int
-isa_print_resources(struct resource_list *rl, const char *name, int type,
-		    int count, const char *format)
-{
-	struct resource_list_entry *rle;
-	int printed;
-	int i, retval = 0;;
-
-	printed = 0;
-	for (i = 0; i < count; i++) {
-		rle = resource_list_find(rl, type, i);
-		if (rle) {
-			if (printed == 0)
-				retval += printf(" %s ", name);
-			else if (printed > 0)
-				retval += printf(",");
-			printed++;
-			retval += printf(format, rle->start);
-			if (rle->count > 1) {
-				retval += printf("-");
-				retval += printf(format,
-						 rle->start + rle->count - 1);
-			}
-		} else if (i > 3) {
-			/* check the first few regardless */
-			break;
-		}
-	}
-	return retval;
-}
-
-static int
 isa_print_all_resources(device_t dev)
 {
 	struct	isa_device *idev = DEVTOISA(dev);
@@ -674,14 +643,10 @@
 	if (SLIST_FIRST(rl) || device_get_flags(dev))
 		retval += printf(" at");
 	
-	retval += isa_print_resources(rl, "port", SYS_RES_IOPORT,
-				      ISA_NPORT, "%#lx");
-	retval += isa_print_resources(rl, "iomem", SYS_RES_MEMORY,
-				      ISA_NMEM, "%#lx");
-	retval += isa_print_resources(rl, "irq", SYS_RES_IRQ,
-				      ISA_NIRQ, "%ld");
-	retval += isa_print_resources(rl, "drq", SYS_RES_DRQ,
-				      ISA_NDRQ, "%ld");
+	retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
+	retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
+	retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
+	retval += resource_list_print_type(rl, "drq", SYS_RES_DRQ, "%ld");
 	if (device_get_flags(dev))
 		retval += printf(" flags %#x", device_get_flags(dev));
 
--- freebsd/sys/isa/isa_common.h	Sat Sep  8 19:46:52 2001
+++ sparc64/sys/isa/isa_common.h	Wed Oct 10 00:59:27 2001
@@ -65,7 +65,7 @@
 /*
  * These functions are architecture dependant.
  */
-extern void isa_init(void);
+extern void isa_init(device_t dev);
 extern struct resource *isa_alloc_resource(device_t bus, device_t child,
 					   int type, int *rid,
 					   u_long start, u_long end,
--- freebsd/sys/dev/pci/pci.c	Sun Nov  4 01:39:41 2001
+++ sparc64/sys/dev/pci/pci.c	Fri Oct 26 20:03:58 2001
@@ -78,9 +78,6 @@
 					  device_t dev);
 static void		pci_add_children(device_t dev, int busno);
 static int		pci_probe(device_t dev);
-static int		pci_print_resources(struct resource_list *rl, 
-					    const char *name, int type,
-					    const char *format);
 static int		pci_print_child(device_t dev, device_t child);
 static void		pci_probe_nomatch(device_t dev, device_t child);
 static int		pci_describe_parse_line(char **ptr, int *vendor, 
@@ -190,6 +187,12 @@
 
 u_int32_t pci_numdevs = 0;
 
+#ifdef PCI_INTLINE_0_BAD
+#define PCI_INTLINE_ASSIGNED(l)	((l) != 255 && (l) != 0)
+#else
+#define PCI_INTLINE_ASSIGNED(l)	((l) != 255)
+#endif
+
 /* return base address of memory or port map */
 
 static u_int32_t
@@ -619,6 +622,10 @@
 #endif /* PCI_DEBUG */
 		if (cfg->intpin > 0)
 			printf("\tintpin=%c, irq=%d\n", cfg->intpin +'a' -1, cfg->intline);
+#ifdef PCI_BROKEN_INTPIN
+		if (cfg->intpin == 0 && PCI_INTLINE_ASSIGNED(cfg->intline))
+			printf("\tintpin=(broken), irq=%d\n", cfg->intline);
+#endif
 		if (cfg->pp_cap) {
 			u_int16_t status;
 
@@ -748,7 +755,11 @@
 			pci_add_map(pcib, b, s, f, q->arg1, rl);
 	}
 
-	if (cfg->intpin > 0 && cfg->intline != 255) {
+#ifdef PCI_BROKEN_INTPIN
+	if (PCI_INTLINE_ASSIGNED(cfg->intline)) {
+#else
+	if (cfg->intpin > 0 && PCI_INTLINE_ASSIGNED(cfg->intline)) {
+#endif	
 #ifdef __ia64__
 		/*
 		 * Re-route interrupts on ia64 so that we can get the
@@ -831,34 +842,6 @@
 }
 
 static int
-pci_print_resources(struct resource_list *rl, const char *name, int type,
-		    const char *format)
-{
-	struct resource_list_entry *rle;
-	int printed, retval;
-
-	printed = 0;
-	retval = 0;
-	/* Yes, this is kinda cheating */
-	SLIST_FOREACH(rle, rl, link) {
-		if (rle->type == type) {
-			if (printed == 0)
-				retval += printf(" %s ", name);
-			else if (printed > 0)
-				retval += printf(",");
-			printed++;
-			retval += printf(format, rle->start);
-			if (rle->count > 1) {
-				retval += printf("-");
-				retval += printf(format, rle->start +
-						 rle->count - 1);
-			}
-		}
-	}
-	return retval;
-}
-
-static int
 pci_print_child(device_t dev, device_t child)
 {
 	struct pci_devinfo *dinfo;
@@ -872,9 +855,9 @@
 
 	retval += bus_print_child_header(dev, child);
 
-	retval += pci_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
-	retval += pci_print_resources(rl, "mem", SYS_RES_MEMORY, "%#lx");
-	retval += pci_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
+	retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
+	retval += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
+	retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
 	if (device_get_flags(dev))
 		retval += printf(" flags %#x", device_get_flags(dev));
 
@@ -1219,7 +1202,11 @@
 		 * If device doesn't have an interrupt routed, and is deserving of 
 		 * an interrupt, try to assign it one.
 		 */
-		if ((type == SYS_RES_IRQ) && (cfg->intline == 255 || cfg->intline == 0) && (cfg->intpin != 0)) {
+#ifdef PCI_BROKEN_INTPIN
+		if ((type == SYS_RES_IRQ) && !PCI_INTLINE_ASSIGNED(cfg->intline)) {
+#else
+		if ((type == SYS_RES_IRQ) && !PCI_INTLINE_ASSIGNED(cfg->intline) && (cfg->intpin != 0)) {
+#endif
 			cfg->intline = PCIB_ROUTE_INTERRUPT(device_get_parent(dev), child,
 							    cfg->intpin);
 			if (cfg->intline != 255) {
--- freebsd/sys/dev/pci/pci_pci.c	Mon Dec 10 20:43:24 2001
+++ sparc64/sys/dev/pci/pci_pci.c	Thu Dec 13 04:06:09 2001
@@ -32,6 +32,8 @@
 
 /*
  * PCI:PCI bridge support.
+ * Some functions are also used in drivers for incompatible PCI:PCI bridges,
+ * like sparc64/pci/apb.c.
  */
 
 #include <sys/param.h>
@@ -43,39 +45,12 @@
 
 #include <pci/pcivar.h>
 #include <pci/pcireg.h>
+#include <pci/pcib.h>
 
 #include "pcib_if.h"
 
-/*
- * Bridge-specific data.
- */
-struct pcib_softc 
-{
-    device_t	dev;
-    u_int16_t	command;	/* command register */
-    u_int8_t	secbus;		/* secondary bus number */
-    u_int8_t	subbus;		/* subordinate bus number */
-    pci_addr_t	pmembase;	/* base address of prefetchable memory */
-    pci_addr_t	pmemlimit;	/* topmost address of prefetchable memory */
-    pci_addr_t	membase;	/* base address of memory window */
-    pci_addr_t	memlimit;	/* topmost address of memory window */
-    u_int32_t	iobase;		/* base address of port window */
-    u_int32_t	iolimit;	/* topmost address of port window */
-    u_int16_t	secstat;	/* secondary bus status register */
-    u_int16_t	bridgectl;	/* bridge control register */
-    u_int8_t	seclat;		/* secondary bus latency timer */
-};
-
 static int		pcib_probe(device_t dev);
 static int		pcib_attach(device_t dev);
-static int		pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result);
-static int		pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value);
-static struct resource *pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, 
-					    u_long start, u_long end, u_long count, u_int flags);
-static int		pcib_maxslots(device_t dev);
-static u_int32_t	pcib_read_config(device_t dev, int b, int s, int f, int reg, int width);
-static void		pcib_write_config(device_t dev, int b, int s, int f, int reg, u_int32_t val, int width);
-static int		pcib_route_interrupt(device_t pcib, device_t dev, int pin);
 
 static device_method_t pcib_methods[] = {
     /* Device interface */
@@ -229,7 +204,7 @@
     return(0);
 }
 
-static int
+int
 pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
 {
     struct pcib_softc	*sc = device_get_softc(dev);
@@ -242,7 +217,7 @@
     return(ENOENT);
 }
 
-static int
+int
 pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
 {
     struct pcib_softc	*sc = device_get_softc(dev);
@@ -259,7 +234,7 @@
  * We have to trap resource allocation requests and ensure that the bridge
  * is set up to, or capable of handling them.
  */
-static struct resource *
+struct resource *
 pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, 
 		    u_long start, u_long end, u_long count, u_int flags)
 {
@@ -335,7 +310,7 @@
 /*
  * PCIB interface.
  */
-static int
+int
 pcib_maxslots(device_t dev)
 {
     return(PCI_SLOTMAX);
@@ -344,13 +319,13 @@
 /*
  * Since we are a child of a PCI bus, its parent must support the pcib interface.
  */
-static u_int32_t
+u_int32_t
 pcib_read_config(device_t dev, int b, int s, int f, int reg, int width)
 {
     return(PCIB_READ_CONFIG(device_get_parent(device_get_parent(dev)), b, s, f, reg, width));
 }
 
-static void
+void
 pcib_write_config(device_t dev, int b, int s, int f, int reg, u_int32_t val, int width)
 {
     PCIB_WRITE_CONFIG(device_get_parent(device_get_parent(dev)), b, s, f, reg, val, width);
@@ -359,7 +334,7 @@
 /*
  * Route an interrupt across a PCI bridge.
  */
-static int
+int
 pcib_route_interrupt(device_t pcib, device_t dev, int pin)
 {
     device_t	bus;
--- freebsd/sys/dev/pci/pcivar.h	Sun Aug  5 19:55:43 2001
+++ sparc64/sys/dev/pci/pcivar.h	Wed Oct 10 00:59:22 2001
@@ -182,20 +182,8 @@
 /*
  * Simplified accessors for pci devices
  */
-#define PCI_ACCESSOR(A, B, T)						\
-									\
-static __inline T pci_get_ ## A(device_t dev)				\
-{									\
-    uintptr_t v;							\
-    BUS_READ_IVAR(device_get_parent(dev), dev, PCI_IVAR_ ## B, &v);	\
-    return (T) v;							\
-}									\
-									\
-static __inline void pci_set_ ## A(device_t dev, T t)			\
-{									\
-    uintptr_t v = (uintptr_t) t;					\
-    BUS_WRITE_IVAR(device_get_parent(dev), dev, PCI_IVAR_ ## B, v);	\
-}
+#define PCI_ACCESSOR(var, ivar, type)						\
+	__BUS_ACCESSOR(pci, var, PCI, ivar, type)
 
 PCI_ACCESSOR(subvendor,		SUBVENDOR,	u_int16_t)
 PCI_ACCESSOR(subdevice,		SUBDEVICE,	u_int16_t)
--- /dev/null	Thu Dec 13 16:44:55 2001
+++ sparc64/sys/dev/pci/pcib.h	Wed Oct 10 00:59:22 2001
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
+ * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2000 BSDi
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	$FreeBSD$
+ */
+
+#ifndef _PCIB_H_
+#define _PCIB_H_
+
+/*
+ * Bridge-specific data.
+ */
+struct pcib_softc 
+{
+    device_t	dev;
+    u_int16_t	command;	/* command register */
+    u_int8_t	secbus;		/* secondary bus number */
+    u_int8_t	subbus;		/* subordinate bus number */
+    pci_addr_t	pmembase;	/* base address of prefetchable memory */
+    pci_addr_t	pmemlimit;	/* topmost address of prefetchable memory */
+    pci_addr_t	membase;	/* base address of memory window */
+    pci_addr_t	memlimit;	/* topmost address of memory window */
+    u_int32_t	iobase;		/* base address of port window */
+    u_int32_t	iolimit;	/* topmost address of port window */
+    u_int16_t	secstat;	/* secondary bus status register */
+    u_int16_t	bridgectl;	/* bridge control register */
+    u_int8_t	seclat;		/* secondary bus latency timer */
+    void	*extptr;	/* softc extension for derived drivers */
+};
+
+int		pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result);
+int		pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value);
+struct resource *pcib_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		pcib_maxslots(device_t dev);
+u_int32_t	pcib_read_config(device_t dev, int b, int s, int f, int reg, int width);
+void		pcib_write_config(device_t dev, int b, int s, int f, int reg, u_int32_t val, int width);
+int		pcib_route_interrupt(device_t pcib, device_t dev, int pin);
+int		pcib_dev_iterate(device_t dev, uintptr_t *cookie, int flags, int *slot, int *func,
+				 uintptr_t *data, uintptr_t *iterator);
+
+#endif /* _PCIB_H_ */
--- freebsd/sys/sys/bus.h	Sun Nov  4 01:40:09 2001
+++ sparc64/sys/sys/bus.h	Sun Nov  4 01:14:54 2001
@@ -180,6 +180,14 @@
 			      int type, int rid, struct resource *res);
 
 /*
+ * Print all resources of a specified type, for use in bus_print_child.
+ * The name is printed if at least one resource of the given type is available.
+ * The format ist used to print resource start and end.
+ */
+int	resource_list_print_type(struct resource_list *rl,
+				 const char *name, int type,
+				 const char *format);
+/*
  * The root bus, to which all top-level busses are attached.
  */
 extern device_t root_bus;
@@ -410,6 +418,26 @@
 };									\
 DECLARE_MODULE(name##_##busname, name##_##busname##_mod,		\
 	       SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
+
+/*
+ * Generic ivar accessor generation macros for bus drivers
+ */
+#define __BUS_ACCESSOR(varp, var, ivarp, ivar, type)			\
+									\
+static __inline type varp ## _get_ ## var(device_t dev)			\
+{									\
+	uintptr_t v;							\
+	BUS_READ_IVAR(device_get_parent(dev), dev,			\
+	    ivarp ## _IVAR_ ## ivar, &v);				\
+	return ((type) v);						\
+}									\
+									\
+static __inline void varp ## _set_ ## var(device_t dev, type t)		\
+{									\
+	uintptr_t v = (uintptr_t) t;					\
+	BUS_WRITE_IVAR(device_get_parent(dev), dev,			\
+	    ivarp ## _IVAR_ ## ivar, v);				\
+}
 
 #endif /* _KERNEL */
 
--- freebsd/sys/sys/rman.h	Sat Sep  8 19:53:09 2001
+++ sparc64/sys/sys/rman.h	Thu Nov 22 23:54:27 2001
@@ -126,6 +126,9 @@
 struct resource *rman_reserve_resource(struct rman *rm, u_long start,
 					u_long end, u_long count,
 					u_int flags, struct device *dev);
+struct resource *rman_reserve_resource_bound(struct rman *rm, u_long start,
+					u_long end, u_long count, u_long bound,
+					u_int flags, struct device *dev);
 uint32_t rman_make_alignment_flags(uint32_t size);
 
 #define rman_get_start(r)	((r)->r_start)
--- freebsd/sys/kern/subr_bus.c	Mon Dec 10 20:44:39 2001
+++ sparc64/sys/kern/subr_bus.c	Thu Dec 13 04:06:25 2001
@@ -1207,8 +1207,8 @@
 
 	if (isdefault) {
 		start = rle->start;
-		count = max(count, rle->count);
-		end = max(rle->end, start + count - 1);
+		count = ulmax(count, rle->count);
+		end = ulmax(rle->end, start + count - 1);
 	}
 
 	rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
@@ -1253,6 +1253,34 @@
 
 	rle->res = NULL;
 	return (0);
+}
+
+int
+resource_list_print_type(struct resource_list *rl, const char *name, int type,
+    const char *format)
+{
+	struct resource_list_entry *rle;
+	int printed, retval;
+
+	printed = 0;
+	retval = 0;
+	/* Yes, this is kinda cheating */
+	SLIST_FOREACH(rle, rl, link) {
+		if (rle->type == type) {
+			if (printed == 0)
+				retval += printf(" %s ", name);
+			else
+				retval += printf(",");
+			printed++;
+			retval += printf(format, rle->start);
+			if (rle->count > 1) {
+				retval += printf("-");
+				retval += printf(format, rle->start +
+						 rle->count - 1);
+			}
+		}
+	}
+	return retval;
 }
 
 /*
--- freebsd/sys/kern/subr_rman.c	Sun Nov 25 14:51:37 2001
+++ sparc64/sys/kern/subr_rman.c	Thu Nov 22 23:54:25 2001
@@ -175,12 +175,13 @@
 }
 
 struct resource *
-rman_reserve_resource(struct rman *rm, u_long start, u_long end, u_long count,
-		      u_int flags, struct device *dev)
+rman_reserve_resource_bound(struct rman *rm, u_long start, u_long end,
+		      u_long count, u_long bound,  u_int flags,
+		      struct device *dev)
 {
 	u_int	want_activate;
 	struct	resource *r, *s, *rv;
-	u_long	rstart, rend;
+	u_long	rstart, rend, amask, bmask;
 
 	rv = 0;
 
@@ -202,6 +203,9 @@
 		goto out;
 	}
 
+	amask = (1ul << RF_ALIGNMENT(flags)) - 1;
+	/* If bound is 0, bmask will also be 0 */
+	bmask = ~(bound - 1);
 	/*
 	 * First try to find an acceptable totally-unshared region.
 	 */
@@ -215,10 +219,19 @@
 			DPRINTF(("region is allocated\n"));
 			continue;
 		}
-		rstart = max(s->r_start, start);
-		rstart = (rstart + ((1ul << RF_ALIGNMENT(flags))) - 1) &
-		    ~((1ul << RF_ALIGNMENT(flags)) - 1);
-		rend = min(s->r_end, max(rstart + count, end));
+		rstart = ulmax(s->r_start, start);
+		/*
+		 * Try to find a region by adjusting to boundary and alignment
+		 * until both conditions are satisfied. This is not an optimal
+		 * algorithm, but in most cases it isn't really bad, either.
+		 */
+		do {
+			rstart = (rstart + amask) & ~amask;
+			if (((rstart ^ (rstart + count)) & bmask) != 0)
+				rstart += bound - (rstart & ~bmask);
+		} while ((rstart & amask) != 0 && rstart < end &&
+		    rstart < s->r_end);
+		rend = ulmin(s->r_end, ulmax(rstart + count, end));
 		DPRINTF(("truncated region: [%#lx, %#lx]; size %#lx (requested %#lx)\n",
 		       rstart, rend, (rend - rstart + 1), count));
 
@@ -313,10 +326,12 @@
 			break;
 		if ((s->r_flags & flags) != flags)
 			continue;
-		rstart = max(s->r_start, start);
-		rend = min(s->r_end, max(start + count, end));
+		rstart = ulmax(s->r_start, start);
+		rend = ulmin(s->r_end, ulmax(start + count, end));
 		if (s->r_start >= start && s->r_end <= end
-		    && (s->r_end - s->r_start + 1) == count) {
+		    && (s->r_end - s->r_start + 1) == count &&
+		    (s->r_start & amask) == 0 &&
+		    ((s->r_start ^ s->r_end) & bmask) == 0) {
 			rv = malloc(sizeof *rv, M_RMAN, M_NOWAIT | M_ZERO);
 			if (rv == 0)
 				goto out;
@@ -368,6 +383,15 @@
 	return (rv);
 }
 
+struct resource *
+rman_reserve_resource(struct rman *rm, u_long start, u_long end, u_long count,
+		      u_int flags, struct device *dev)
+{
+
+	return (rman_reserve_resource_bound(rm, start, end, count, 0, flags,
+	    dev));
+}
+
 static int
 int_rman_activate_resource(struct rman *rm, struct resource *r,
 			   struct resource **whohas)
@@ -575,7 +599,7 @@
 	 * Find the hightest bit set, and add one if more than one bit
 	 * set.  We're effectively computing the ceil(log2(size)) here.
 	 */
-	for (i = 32; i > 0; i--)
+	for (i = 31; i > 0; i--)
 		if ((1 << i) & size)
 			break;
 	if (~(1 << i) & size)
--- freebsd/sys/i386/isa/isa.c	Fri Oct 12 16:18:20 2001
+++ sparc64/sys/i386/isa/isa.c	Thu Dec 13 17:53:29 2001
@@ -68,7 +68,7 @@
 #include <isa/isa_common.h>
 
 void
-isa_init(void)
+isa_init(device_t dev)
 {
 }
 
--- freebsd/sys/alpha/isa/isa.c	Sun Aug  5 19:43:26 2001
+++ sparc64/sys/alpha/isa/isa.c	Thu Dec 13 17:53:29 2001
@@ -94,7 +94,7 @@
 }
 
 void
-isa_init(void)
+isa_init(device_t dev)
 {
 	isa_init_intr();
 }
--- freebsd/sys/ia64/isa/isa.c	Sun Aug  5 20:05:14 2001
+++ sparc64/sys/ia64/isa/isa.c	Thu Dec 13 17:53:29 2001
@@ -69,7 +69,7 @@
 #include <isa/isa_common.h>
 
 void
-isa_init(void)
+isa_init(device_t dev)
 {
 }
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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