Devices with 36-bit paddr on 32-bit system

Justin Hibbits jrh29 at alumni.cwru.edu
Sat Aug 29 18:35:48 UTC 2015


Hey, I already had that thought, too, you just encouraged me to take
it :)  Anyway, here's an initial patch.  I've *only* tested it on one
PowerPC board (the one needing this change), none of my other devices,
and no other architectures.  Thoughts?

tl;dr I went with using bus_addr_t for the addresses, and kept u_long
for the sizes (I can change it to use bus_size_t instead, but it's
already vm_offset_t on PowerPC, which is long anyway).

Since I took the diff as a whole, and erased unrelated bits, there may
still be unrelated bits in the diff, which can be ignored (all part of
my larger work).

- Justin

On Fri, Aug 28, 2015 at 1:59 PM, Adrian Chadd <adrian.chadd at gmail.com> wrote:
> +1 on this.
>
> Also - justin/i figured it out (well, I made the suggestion, he did
> the suggestion) which is just to do a big/single mapping of the
> relevant hardware window into vmem early in boot, and hack that bus
> nexus to treat things as being in that vmem region. He's gotten pretty
> far along the device bringup path now. That way the rmem allocation is
> just from that vmem region.
>
>
>
> -adrian
>
>
>
> On 28 August 2015 at 10:35, John Baldwin <jhb at freebsd.org> wrote:
>> On Tuesday, August 25, 2015 08:55:45 AM Marcel Moolenaar wrote:
>>>
>>> > On Aug 24, 2015, at 11:44 PM, Justin Hibbits <jrh29 at alumni.cwru.edu> wrote:
>>> >
>>> > With my work porting FreeBSD to PowerPC e500mc and e5500, I have
>>> > devices in my device tree mapped well above the 4GB mark
>>> > (0xffexxxxxx), and have no idea how to properly address them for
>>> > resources in rman.  Do we already have a solution to support this?
>>> > Part of the problem is the powerpc nexus does a straight convert to
>>> > vm_offset_t of rman_get_start() (itself returning a u_long), and
>>> > vm_offset_t is not necessarily equal to vm_paddr_t (on Book-E powerpc
>>> > vm_offset_t is 32-bits, vm_paddr_t is 64-bits).
>>>
>>> I think the best solution is to represent a resource address
>>> space with a type other than u_long. It makes sense to have
>>> it use bus_addr_t or vm_paddr_t for example. Such a change
>>> comes at a high price for sure, but you’ll fix it once and
>>> for all. I don’t think you should kluge your way out of this...
>>
>> Expanding beyond u_long is the right solution.  PAE doesn't generally suffer
>> from this on i386 (though the ram0 device "punts" and ignores RAM ranges above
>> 4G as a workaround).
>>
>> However, u_long is baked into the bus resource API quite a bit.  Specifically,
>> the values 0ul and ~0ul are used as magic numbers in lots of places to request
>> "anywhere" locations.  Some of this has been mitigated by
>> bus_alloc_resource_any(), but that doesn't cover all cases.  You will probably
>> want to add some explicit constants and do a sweep replacing the magic numbers
>> with those first (and MFC the constants at least to make it easier to port
>> drivers across branches).  Then you can change the type.
>>
>> As far as the best type: rman's are in theory generic and not just for bus
>> addresses.  I'd be tempted to let each platform define an rman_addr_t along
>> with RMAN_ADDR_MAX constants, but in practice it is probably fine to use
>> bus_addr_t and BUS_SPACE_MAXADDR.  If you do that it also means you can skip
>> the step of having to MFC new constants.
>>
>> Note that various bus APIs will have to change to use bus_addr_t instead of
>> u_long as well.
>>
>> --
>> John Baldwin
>> _______________________________________________
>> freebsd-arch at freebsd.org mailing list
>> https://lists.freebsd.org/mailman/listinfo/freebsd-arch
>> To unsubscribe, send any mail to "freebsd-arch-unsubscribe at freebsd.org"
-------------- next part --------------
Index: sys/dev/ata/ata-pci.c
===================================================================
--- sys/dev/ata/ata-pci.c	(revision 287189)
+++ sys/dev/ata/ata-pci.c	(working copy)
@@ -217,7 +217,7 @@
 
 struct resource *
 ata_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)
+		       bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct ata_pci_controller *controller = device_get_softc(dev);
 	struct resource *res = NULL;
Index: sys/dev/ata/ata-pci.h
===================================================================
--- sys/dev/ata/ata-pci.h	(revision 287189)
+++ sys/dev/ata/ata-pci.h	(working copy)
@@ -535,7 +535,7 @@
 int ata_pci_print_child(device_t dev, device_t child);
 int ata_pci_child_location_str(device_t dev, device_t child, char *buf,
     size_t buflen);
-struct resource * ata_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 resource * ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags);
 int ata_pci_release_resource(device_t dev, device_t child, int type, int rid, struct resource *r);
 int ata_pci_setup_intr(device_t dev, device_t child, struct resource *irq, int flags, driver_filter_t *filter, driver_intr_t *function, void *argument, void **cookiep);
  int ata_pci_teardown_intr(device_t dev, device_t child, struct resource *irq, void *cookie);
Index: sys/dev/ata/chipsets/ata-promise.c
===================================================================
--- sys/dev/ata/chipsets/ata-promise.c	(revision 287189)
+++ sys/dev/ata/chipsets/ata-promise.c	(working copy)
@@ -191,18 +191,19 @@
 	!BUS_READ_IVAR(device_get_parent(GRANDPARENT(dev)),
 		       GRANDPARENT(dev), PCI_IVAR_DEVID, &devid) &&
 	((devid == ATA_DEC_21150) || (devid == ATA_DEC_21150_1))) {
-	static long start = 0, end = 0;
+	static bus_addr_t start = 0;
+	static u_long count = 0;
 
 	if (pci_get_slot(dev) == 1) {
-	    bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &end);
+	    bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &count);
 	    strcat(buffer, " (channel 0+1)");
 	}
-	else if (pci_get_slot(dev) == 2 && start && end) {
-	    bus_set_resource(dev, SYS_RES_IRQ, 0, start, end);
+	else if (pci_get_slot(dev) == 2 && start && count) {
+	    bus_set_resource(dev, SYS_RES_IRQ, 0, start, count);
 	    strcat(buffer, " (channel 2+3)");
 	}
 	else {
-	    start = end = 0;
+	    start = count = 0;
 	}
     }
     sprintf(buffer, "%s %s controller", buffer, ata_mode2str(idx->max_dma));
Index: sys/dev/fdt/simplebus.c
===================================================================
--- sys/dev/fdt/simplebus.c	(revision 287189)
+++ sys/dev/fdt/simplebus.c	(working copy)
@@ -46,7 +46,7 @@
 static int		simplebus_probe(device_t dev);
 static int		simplebus_attach(device_t dev);
 static struct resource *simplebus_alloc_resource(device_t, device_t, int,
-    int *, u_long, u_long, u_long, u_int);
+    int *, bus_addr_t, bus_addr_t, u_long, u_int);
 static void		simplebus_probe_nomatch(device_t bus, device_t child);
 static int		simplebus_print_child(device_t bus, device_t child);
 static device_t		simplebus_add_child(device_t dev, u_int order,
@@ -318,7 +318,7 @@
 
 static struct resource *
 simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct simplebus_softc *sc;
 	struct simplebus_devinfo *di;
@@ -331,7 +331,7 @@
 	 * Request for the default allocation with a given rid: use resource
 	 * list stored in the local device info.
 	 */
-	if ((start == 0UL) && (end == ~0UL)) {
+	if ((start == RM_MIN_START) && (end == RM_MAX_END)) {
 		if ((di = device_get_ivars(child)) == NULL)
 			return (NULL);
 
@@ -365,7 +365,8 @@
 		if (j == sc->nranges && sc->nranges != 0) {
 			if (bootverbose)
 				device_printf(bus, "Could not map resource "
-				    "%#lx-%#lx\n", start, end);
+				    "%#llx-%#llx\n", (uint64_t)start,
+				    (uint64_t)end);
 
 			return (NULL);
 		}
@@ -381,8 +382,8 @@
 	int rv;
 
 	rv = 0;
-	rv += resource_list_print_type(&di->rl, "mem", SYS_RES_MEMORY, "%#lx");
-	rv += resource_list_print_type(&di->rl, "irq", SYS_RES_IRQ, "%ld");
+	rv += resource_list_print_type(&di->rl, "mem", SYS_RES_MEMORY, "%#llx");
+	rv += resource_list_print_type(&di->rl, "irq", SYS_RES_IRQ, "%lld");
 	return (rv);
 }
 
Index: sys/dev/gpio/gpiobus.c
===================================================================
--- sys/dev/gpio/gpiobus.c	(revision 287189)
+++ sys/dev/gpio/gpiobus.c	(working copy)
@@ -178,7 +178,7 @@
 	sc->sc_intr_rman.rm_type = RMAN_ARRAY;
 	sc->sc_intr_rman.rm_descr = "GPIO Interrupts";
 	if (rman_init(&sc->sc_intr_rman) != 0 ||
-	    rman_manage_region(&sc->sc_intr_rman, 0, ~0) != 0)
+	    rman_manage_region(&sc->sc_intr_rman, 0, ~(bus_addr_t)0) != 0)
 		panic("%s: failed to set up rman.", __func__);
 
 	if (GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins) != 0)
@@ -488,7 +488,7 @@
 
 static int
 gpiobus_set_resource(device_t dev, device_t child, int type, int rid,
-    u_long start, u_long count)
+    bus_addr_t start, u_long count)
 {
 	struct gpiobus_ivar *devi;
 	struct resource_list_entry *rle;
@@ -506,7 +506,7 @@
 
 static struct resource *
 gpiobus_alloc_resource(device_t bus, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct gpiobus_softc *sc;
 	struct resource *rv;
@@ -516,7 +516,7 @@
 
 	if (type != SYS_RES_IRQ)
 		return (NULL);
-	isdefault = (start == 0UL && end == ~0UL && count == 1);
+	isdefault = (start == 0UL && end == ~(bus_addr_t)0UL && count == 1);
 	rle = NULL;
 	if (isdefault) {
 		rl = BUS_GET_RESOURCE_LIST(bus, child);
Index: sys/dev/ofw/ofwbus.c
===================================================================
--- sys/dev/ofw/ofwbus.c	(revision 287189)
+++ sys/dev/ofw/ofwbus.c	(working copy)
@@ -156,7 +156,7 @@
 	sc->sc_mem_rman.rm_descr = "Device Memory";
 	if (rman_init(&sc->sc_intr_rman) != 0 ||
 	    rman_init(&sc->sc_mem_rman) != 0 ||
-	    rman_manage_region(&sc->sc_intr_rman, 0, ~0) != 0 ||
+	    rman_manage_region(&sc->sc_intr_rman, 0, BUS_SPACE_MAXADDR) != 0 ||
 	    rman_manage_region(&sc->sc_mem_rman, 0, BUS_SPACE_MAXADDR) != 0)
 		panic("%s: failed to set up rmans.", __func__);
 
@@ -178,7 +178,7 @@
 
 static struct resource *
 ofwbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct ofwbus_softc *sc;
 	struct rman *rm;
@@ -186,7 +186,7 @@
 	struct resource_list_entry *rle;
 	int isdefault, passthrough;
 
-	isdefault = (start == 0UL && end == ~0UL);
+	isdefault = (start == RM_MIN_START && end == RM_MAX_END);
 	passthrough = (device_get_parent(child) != bus);
 	sc = device_get_softc(bus);
 	rle = NULL;
@@ -201,7 +201,7 @@
 		}
 		start = rle->start;
 		count = ulmax(count, rle->count);
-		end = ulmax(rle->end, start + count - 1);
+		end = qmax(rle->end, start + count - 1);
 	}
 
 	switch (type) {
@@ -239,7 +239,7 @@
 
 static int
 ofwbus_adjust_resource(device_t bus, device_t child __unused, int type,
-    struct resource *r, u_long start, u_long end)
+    struct resource *r, bus_addr_t start, bus_addr_t end)
 {
 	struct ofwbus_softc *sc;
 	struct rman *rm;
Index: sys/dev/pci/hostb_pci.c
===================================================================
--- sys/dev/pci/hostb_pci.c	(revision 287189)
+++ sys/dev/pci/hostb_pci.c	(working copy)
@@ -102,7 +102,7 @@
 
 static struct resource *
 pci_hostb_alloc_resource(device_t dev, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 
 	return (bus_alloc_resource(dev, type, rid, start, end, count, flags));
Index: sys/dev/pci/pci.c
===================================================================
--- sys/dev/pci/pci.c	(revision 287189)
+++ sys/dev/pci/pci.c	(working copy)
@@ -4710,7 +4710,7 @@
 
 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)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 #ifdef PCI_IOV
 	struct pci_devinfo *dinfo;
Index: sys/dev/pci/pci_pci.c
===================================================================
--- sys/dev/pci/pci_pci.c	(revision 287189)
+++ sys/dev/pci/pci_pci.c	(working copy)
@@ -212,9 +212,10 @@
  * ISA alias range.
  */
 static int
-pcib_is_isa_range(struct pcib_softc *sc, u_long start, u_long end, u_long count)
+pcib_is_isa_range(struct pcib_softc *sc, bus_addr_t start, bus_addr_t end,
+    u_long count)
 {
-	u_long next_alias;
+	bus_addr_t next_alias;
 
 	if (!(sc->bridgectl & PCIB_BCR_ISA_ENABLE))
 		return (0);
@@ -275,13 +276,13 @@
 	}
 }
 
-typedef void (nonisa_callback)(u_long start, u_long end, void *arg);
+typedef void (nonisa_callback)(bus_addr_t start, bus_addr_t end, void *arg);
 
 static void
-pcib_walk_nonisa_ranges(u_long start, u_long end, nonisa_callback *cb,
+pcib_walk_nonisa_ranges(bus_addr_t start, bus_addr_t end, nonisa_callback *cb,
     void *arg)
 {
-	u_long next_end;
+	bus_addr_t next_end;
 
 	/*
 	 * If start is within an ISA alias range, move up to the start
@@ -309,7 +310,7 @@
 }
 
 static void
-count_ranges(u_long start, u_long end, void *arg)
+count_ranges(bus_addr_t start, bus_addr_t end, void *arg)
 {
 	int *countp;
 
@@ -324,7 +325,7 @@
 };
 
 static void
-alloc_ranges(u_long start, u_long end, void *arg)
+alloc_ranges(bus_addr_t start, bus_addr_t end, void *arg)
 {
 	struct alloc_state *as;
 	struct pcib_window *w;
@@ -348,7 +349,7 @@
 }
 
 static int
-pcib_alloc_nonisa_ranges(struct pcib_softc *sc, u_long start, u_long end)
+pcib_alloc_nonisa_ranges(struct pcib_softc *sc, bus_addr_t start, bus_addr_t end)
 {
 	struct alloc_state as;
 	int i, new_count;
@@ -387,7 +388,7 @@
 	char buf[64];
 	int error, rid;
 
-	if (max_address != (u_long)max_address)
+	if (max_address != (bus_addr_t)max_address)
 		max_address = ~0ul;
 	w->rman.rm_start = 0;
 	w->rman.rm_end = max_address;
@@ -609,7 +610,7 @@
 
 static struct resource *
 pcib_suballoc_bus(struct pcib_secbus *bus, device_t child, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource *res;
 
@@ -633,9 +634,9 @@
  * subbus.
  */
 static int
-pcib_grow_subbus(struct pcib_secbus *bus, u_long new_end)
+pcib_grow_subbus(struct pcib_secbus *bus, bus_addr_t new_end)
 {
-	u_long old_end;
+	bus_addr_t old_end;
 	int error;
 
 	old_end = rman_get_end(bus->res);
@@ -658,10 +659,10 @@
 
 struct resource *
 pcib_alloc_subbus(struct pcib_secbus *bus, device_t child, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource *res;
-	u_long start_free, end_free, new_end;
+	bus_addr_t start_free, end_free, new_end;
 
 	/*
 	 * First, see if the request can be satisified by the existing
@@ -1158,8 +1159,8 @@
  */
 static struct resource *
 pcib_suballoc_resource(struct pcib_softc *sc, struct pcib_window *w,
-    device_t child, int type, int *rid, u_long start, u_long end, u_long count,
-    u_int flags)
+    device_t child, int type, int *rid, bus_addr_t start, bus_addr_t end,
+    u_long count, u_int flags)
 {
 	struct resource *res;
 
@@ -1196,10 +1197,10 @@
 /* Allocate a fresh resource range for an unconfigured window. */
 static int
 pcib_alloc_new_window(struct pcib_softc *sc, struct pcib_window *w, int type,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource *res;
-	u_long base, limit, wmask;
+	bus_addr_t base, limit, wmask;
 	int rid;
 
 	/*
@@ -1269,7 +1270,7 @@
 /* Try to expand an existing window to the requested base and limit. */
 static int
 pcib_expand_window(struct pcib_softc *sc, struct pcib_window *w, int type,
-    u_long base, u_long limit)
+    bus_addr_t base, bus_addr_t limit)
 {
 	struct resource *res;
 	int error, i, force_64k_base;
@@ -1367,9 +1368,10 @@
  */
 static int
 pcib_grow_window(struct pcib_softc *sc, struct pcib_window *w, int type,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
-	u_long align, start_free, end_free, front, back, wmask;
+	bus_addr_t start_free, end_free, front, back;
+	bus_addr_t align, wmask;
 	int error;
 
 	/*
@@ -1400,8 +1402,8 @@
 		if (error) {
 			if (bootverbose)
 				device_printf(sc->dev,
-		    "failed to allocate initial %s window (%#lx-%#lx,%#lx)\n",
-				    w->name, start, end, count);
+		    "failed to allocate initial %s window (%#jx-%#jx,%#lx)\n",
+				    w->name, (uintmax_t)start, (uintmax_t)end, count);
 			return (error);
 		}
 		if (bootverbose)
@@ -1534,7 +1536,7 @@
  */
 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)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct pcib_softc *sc;
 	struct resource *r;
@@ -1623,7 +1625,7 @@
 
 int
 pcib_adjust_resource(device_t bus, device_t child, int type, struct resource *r,
-    u_long start, u_long end)
+    bus_addr_t start, bus_addr_t end)
 {
 	struct pcib_softc *sc;
 
@@ -1658,7 +1660,7 @@
  */
 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)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct pcib_softc	*sc = device_get_softc(dev);
 	const char *name, *suffix;
Index: sys/dev/pci/pci_private.h
===================================================================
--- sys/dev/pci/pci_private.h	(revision 287189)
+++ sys/dev/pci/pci_private.h	(working copy)
@@ -103,8 +103,8 @@
 int		pci_msi_count_method(device_t dev, device_t child);
 int		pci_msix_count_method(device_t dev, device_t child);
 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 type, int *rid, bus_addr_t start, bus_addr_t 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,
Index: sys/dev/pci/pci_subr.c
===================================================================
--- sys/dev/pci/pci_subr.c	(revision 287189)
+++ sys/dev/pci/pci_subr.c	(working copy)
@@ -178,8 +178,8 @@
 }
 
 int
-pcib_host_res_decodes(struct pcib_host_resources *hr, int type, u_long start,
-    u_long end, u_int flags)
+pcib_host_res_decodes(struct pcib_host_resources *hr, int type, bus_addr_t start,
+    bus_addr_t end, u_int flags)
 {
 	struct resource_list_entry *rle;
 	int rid;
@@ -201,11 +201,11 @@
 
 struct resource *
 pcib_host_res_alloc(struct pcib_host_resources *hr, device_t dev, int type,
-    int *rid, u_long start, u_long end, u_long count, u_int flags)
+    int *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource_list_entry *rle;
 	struct resource *r;
-	u_long new_start, new_end;
+	bus_addr_t new_start, new_end;
 
 	if (flags & RF_PREFETCHABLE)
 		KASSERT(type == SYS_RES_MEMORY,
@@ -229,8 +229,8 @@
 		if (((flags & RF_PREFETCHABLE) != 0) !=
 		    ((rle->flags & RLE_PREFETCH) != 0))
 			continue;
-		new_start = ulmax(start, rle->start);
-		new_end = ulmin(end, rle->end);
+		new_start = qmax(start, rle->start);
+		new_end = qmin(end, rle->end);
 		if (new_start > new_end ||
 		    new_start + count - 1 > new_end ||
 		    new_start + count < new_start)
@@ -261,7 +261,7 @@
 
 int
 pcib_host_res_adjust(struct pcib_host_resources *hr, device_t dev, int type,
-    struct resource *r, u_long start, u_long end)
+    struct resource *r, bus_addr_t start, bus_addr_t end)
 {
 	struct resource_list_entry *rle;
 
@@ -329,8 +329,8 @@
 }
 
 struct resource *
-pci_domain_alloc_bus(int domain, device_t dev, int *rid, u_long start,
-    u_long end, u_long count, u_int flags)
+pci_domain_alloc_bus(int domain, device_t dev, int *rid, bus_addr_t start,
+    bus_addr_t end, u_long count, u_int flags)
 {
 	struct pci_domain *d;
 	struct resource *res;
@@ -349,7 +349,7 @@
 
 int
 pci_domain_adjust_bus(int domain, device_t dev, struct resource *r,
-    u_long start, u_long end)
+    bus_addr_t start, bus_addr_t end)
 {
 #ifdef INVARIANTS
 	struct pci_domain *d;
Index: sys/dev/pci/pcib_private.h
===================================================================
--- sys/dev/pci/pcib_private.h	(revision 287189)
+++ sys/dev/pci/pcib_private.h	(working copy)
@@ -49,13 +49,13 @@
 int		pcib_host_res_free(device_t pcib,
 		    struct pcib_host_resources *hr);
 int		pcib_host_res_decodes(struct pcib_host_resources *hr, int type,
-		    u_long start, u_long end, u_int flags);
+		    bus_addr_t start, bus_addr_t end, u_int flags);
 struct resource *pcib_host_res_alloc(struct pcib_host_resources *hr,
-		    device_t dev, int type, int *rid, u_long start, u_long end,
-		    u_long count, u_int flags);
+		    device_t dev, int type, int *rid, bus_addr_t start,
+		    bus_addr_t end, u_long count, u_int flags);
 int		pcib_host_res_adjust(struct pcib_host_resources *hr,
-		    device_t dev, int type, struct resource *r, u_long start,
-		    u_long end);
+		    device_t dev, int type, struct resource *r, bus_addr_t start,
+		    bus_addr_t end);
 #endif
 
 /*
@@ -132,13 +132,13 @@
     int slot, int func, uint8_t *busnum);
 #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
 struct resource *pci_domain_alloc_bus(int domain, device_t dev, int *rid,
-		    u_long start, u_long end, u_long count, u_int flags);
+		    bus_addr_t start, bus_addr_t end, u_long count, u_int flags);
 int		pci_domain_adjust_bus(int domain, device_t dev,
-		    struct resource *r, u_long start, u_long end);
+		    struct resource *r, bus_addr_t start, bus_addr_t end);
 int		pci_domain_release_bus(int domain, device_t dev, int rid,
 		    struct resource *r);
 struct resource *pcib_alloc_subbus(struct pcib_secbus *bus, device_t child,
-		    int *rid, u_long start, u_long end, u_long count,
+		    int *rid, bus_addr_t start, bus_addr_t end, u_long count,
 		    u_int flags);
 void		pcib_setup_secbus(device_t dev, struct pcib_secbus *bus,
     int min_count);
@@ -152,10 +152,11 @@
 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);
+					    bus_addr_t start, bus_addr_t end,
+					    u_long count, u_int flags);
 #ifdef NEW_PCIB
 int		pcib_adjust_resource(device_t bus, device_t child, int type,
-    struct resource *r, u_long start, u_long end);
+    struct resource *r, bus_addr_t start, bus_addr_t end);
 int		pcib_release_resource(device_t dev, device_t child, int type, int rid,
     struct resource *r);
 #endif
Index: sys/dev/pci/vga_pci.c
===================================================================
--- sys/dev/pci/vga_pci.c	(revision 287189)
+++ sys/dev/pci/vga_pci.c	(working copy)
@@ -68,7 +68,7 @@
 
 static struct vga_resource *lookup_res(struct vga_pci_softc *sc, int rid);
 static struct resource *vga_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 type, int *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags);
 static int	vga_pci_release_resource(device_t dev, device_t child, int type,
     int rid, struct resource *r);
 
@@ -163,8 +163,8 @@
 #endif
 
 	rid = PCIR_BIOS;
-	res = vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, 0ul,
-	    ~0ul, 1, RF_ACTIVE);
+	res = vga_pci_alloc_resource(dev, NULL, SYS_RES_MEMORY, &rid, RM_MIN_START,
+	    RM_MAX_END, 1, RF_ACTIVE);
 	if (res == NULL) {
 		return (NULL);
 	}
@@ -333,7 +333,7 @@
 
 static struct resource *
 vga_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)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct vga_resource *vr;
 
Index: sys/dev/scc/scc_bfe.h
===================================================================
--- sys/dev/scc/scc_bfe.h	(revision 287189)
+++ sys/dev/scc/scc_bfe.h	(working copy)
@@ -143,8 +143,8 @@
 int scc_bfe_probe(device_t dev, u_int regshft, u_int rclk, u_int rid);
 
 struct resource *scc_bus_alloc_resource(device_t, device_t, int, int *,
-    u_long, u_long, u_long, u_int);
-int scc_bus_get_resource(device_t, device_t, int, int, u_long *, u_long *);
+    bus_addr_t, bus_addr_t, u_long, u_int);
+int scc_bus_get_resource(device_t, device_t, int, int, bus_addr_t *, u_long *);
 int scc_bus_read_ivar(device_t, device_t, int, uintptr_t *);
 int scc_bus_release_resource(device_t, device_t, int, int, struct resource *);
 int scc_bus_setup_intr(device_t, device_t, struct resource *, int,
Index: sys/dev/scc/scc_core.c
===================================================================
--- sys/dev/scc/scc_core.c	(revision 287189)
+++ sys/dev/scc/scc_core.c	(working copy)
@@ -103,7 +103,8 @@
 	struct scc_softc *sc, *sc0;
 	const char *sep;
 	bus_space_handle_t bh;
-	u_long base, size, start, sz;
+	bus_addr_t base, start;
+	bus_size_t size, sz;
 	int c, error, mode, sysdev;
 
 	/*
@@ -407,7 +408,7 @@
 
 struct resource *
 scc_bus_alloc_resource(device_t dev, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource_list_entry *rle;
 	struct scc_chan *ch;
@@ -431,7 +432,7 @@
 
 int
 scc_bus_get_resource(device_t dev, device_t child, int type, int rid,
-    u_long *startp, u_long *countp)
+    bus_addr_t *startp, u_long *countp)
 {
 	struct resource_list_entry *rle;
 	struct scc_chan *ch;
Index: sys/kern/bus_if.m
===================================================================
--- sys/kern/bus_if.m	(revision 287189)
+++ sys/kern/bus_if.m	(working copy)
@@ -44,7 +44,7 @@
 CODE {
 	static struct resource *
 	null_alloc_resource(device_t dev, device_t child,
-	    int type, int *rid, u_long start, u_long end,
+	    int type, int *rid, bus_addr_t start, bus_addr_t end,
 	    u_long count, u_int flags)
 	{
 	    return (0);
@@ -262,8 +262,8 @@
 	device_t	_child;
 	int		_type;
 	int	       *_rid;
-	u_long		_start;
-	u_long		_end;
+	bus_addr_t	_start;
+	bus_addr_t	_end;
 	u_long		_count;
 	u_int		_flags;
 } DEFAULT null_alloc_resource;
@@ -330,8 +330,8 @@
 	device_t	_child;
 	int		_type;
 	struct resource *_res;
-	u_long		_start;
-	u_long		_end;
+	bus_addr_t	_start;
+	bus_addr_t	_end;
 };
 
 /**
@@ -431,7 +431,7 @@
 	device_t	_child;
 	int		_type;
 	int		_rid;
-	u_long		_start;
+	bus_addr_t	_start;
 	u_long		_count;
 };
 
@@ -455,7 +455,7 @@
 	device_t	_child;
 	int		_type;
 	int		_rid;
-	u_long		*_startp;
+	bus_addr_t	*_startp;
 	u_long		*_countp;
 };
 
Index: sys/kern/subr_bus.c
===================================================================
--- sys/kern/subr_bus.c	(revision 287189)
+++ sys/kern/subr_bus.c	(working copy)
@@ -3063,8 +3063,8 @@
  * @param count		XXX end-start+1
  */
 int
-resource_list_add_next(struct resource_list *rl, int type, u_long start,
-    u_long end, u_long count)
+resource_list_add_next(struct resource_list *rl, int type, bus_addr_t start,
+    bus_addr_t end, u_long count)
 {
 	int rid;
 
@@ -3092,7 +3092,7 @@
  */
 struct resource_list_entry *
 resource_list_add(struct resource_list *rl, int type, int rid,
-    u_long start, u_long end, u_long count)
+    bus_addr_t start, bus_addr_t end, u_long count)
 {
 	struct resource_list_entry *rle;
 
@@ -3250,7 +3250,7 @@
  */
 struct resource *
 resource_list_reserve(struct resource_list *rl, device_t bus, device_t child,
-    int type, int *rid, u_long start, u_long end, u_long count, u_int flags)
+    int type, int *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource_list_entry *rle = NULL;
 	int passthrough = (device_get_parent(child) != bus);
@@ -3307,7 +3307,7 @@
  */
 struct resource *
 resource_list_alloc(struct resource_list *rl, device_t bus, device_t child,
-    int type, int *rid, u_long start, u_long end, u_long count, u_int flags)
+    int type, int *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource_list_entry *rle = NULL;
 	int passthrough = (device_get_parent(child) != bus);
@@ -3949,7 +3949,7 @@
  */
 int
 bus_generic_adjust_resource(device_t dev, device_t child, int type,
-    struct resource *r, u_long start, u_long end)
+    struct resource *r, bus_addr_t start, bus_addr_t end)
 {
 	/* Propagate up the bus hierarchy until someone handles it. */
 	if (dev->parent)
@@ -3966,7 +3966,7 @@
  */
 struct resource *
 bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	/* Propagate up the bus hierarchy until someone handles it. */
 	if (dev->parent)
@@ -4104,7 +4104,7 @@
  */
 int
 bus_generic_rl_get_resource(device_t dev, device_t child, int type, int rid,
-    u_long *startp, u_long *countp)
+    bus_addr_t *startp, u_long *countp)
 {
 	struct resource_list *		rl = NULL;
 	struct resource_list_entry *	rle = NULL;
@@ -4135,7 +4135,7 @@
  */
 int
 bus_generic_rl_set_resource(device_t dev, device_t child, int type, int rid,
-    u_long start, u_long count)
+    bus_addr_t start, u_long count)
 {
 	struct resource_list *		rl = NULL;
 
@@ -4203,7 +4203,7 @@
  */
 struct resource *
 bus_generic_rl_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 *rid, bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct resource_list *		rl = NULL;
 
@@ -4289,7 +4289,7 @@
  * parent of @p dev.
  */
 struct resource *
-bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end,
+bus_alloc_resource(device_t dev, int type, int *rid, bus_addr_t start, bus_addr_t end,
     u_long count, u_int flags)
 {
 	if (dev->parent == NULL)
@@ -4305,8 +4305,8 @@
  * parent of @p dev.
  */
 int
-bus_adjust_resource(device_t dev, int type, struct resource *r, u_long start,
-    u_long end)
+bus_adjust_resource(device_t dev, int type, struct resource *r, bus_addr_t start,
+    bus_addr_t end)
 {
 	if (dev->parent == NULL)
 		return (EINVAL);
@@ -4436,7 +4436,7 @@
  */
 int
 bus_set_resource(device_t dev, int type, int rid,
-    u_long start, u_long count)
+    bus_addr_t start, u_long count)
 {
 	return (BUS_SET_RESOURCE(device_get_parent(dev), dev, type, rid,
 	    start, count));
@@ -4450,7 +4450,7 @@
  */
 int
 bus_get_resource(device_t dev, int type, int rid,
-    u_long *startp, u_long *countp)
+    bus_addr_t *startp, u_long *countp)
 {
 	return (BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
 	    startp, countp));
@@ -4462,10 +4462,11 @@
  * This function simply calls the BUS_GET_RESOURCE() method of the
  * parent of @p dev and returns the start value.
  */
-u_long
+bus_addr_t
 bus_get_resource_start(device_t dev, int type, int rid)
 {
-	u_long start, count;
+	bus_addr_t start;
+	u_long count;
 	int error;
 
 	error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
@@ -4484,7 +4485,8 @@
 u_long
 bus_get_resource_count(device_t dev, int type, int rid)
 {
-	u_long start, count;
+	bus_addr_t start;
+	u_long count;
 	int error;
 
 	error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
Index: sys/kern/subr_rman.c
===================================================================
--- sys/kern/subr_rman.c	(revision 287189)
+++ sys/kern/subr_rman.c	(working copy)
@@ -90,8 +90,8 @@
 	TAILQ_ENTRY(resource_i)	r_link;
 	LIST_ENTRY(resource_i)	r_sharelink;
 	LIST_HEAD(, resource_i)	*r_sharehead;
-	u_long	r_start;	/* index of the first entry in this resource */
-	u_long	r_end;		/* index of the last entry (inclusive) */
+	bus_addr_t	r_start;	/* index of the first entry in this resource */
+	bus_addr_t	r_end;		/* index of the last entry (inclusive) */
 	u_int	r_flags;
 	void	*r_virtual;	/* virtual address of this resource */
 	struct device *r_dev;	/* device which has allocated this resource */
@@ -135,7 +135,7 @@
 	}
 
 	if (rm->rm_start == 0 && rm->rm_end == 0)
-		rm->rm_end = ~0ul;
+		rm->rm_end = RM_MAX_END;
 	if (rm->rm_type == RMAN_UNINIT)
 		panic("rman_init");
 	if (rm->rm_type == RMAN_GAUGE)
@@ -154,13 +154,13 @@
 }
 
 int
-rman_manage_region(struct rman *rm, u_long start, u_long end)
+rman_manage_region(struct rman *rm, bus_addr_t start, bus_addr_t end)
 {
 	struct resource_i *r, *s, *t;
 	int rv = 0;
 
-	DPRINTF(("rman_manage_region: <%s> request: start %#lx, end %#lx\n",
-	    rm->rm_descr, start, end));
+	DPRINTF(("rman_manage_region: <%s> request: start %#llx, end %#llx\n",
+	    rm->rm_descr, (uint64_t)start, (uint64_t)end));
 	if (start < rm->rm_start || end > rm->rm_end)
 		return EINVAL;
 	r = int_alloc_resource(M_NOWAIT);
@@ -174,7 +174,7 @@
 
 	/* Skip entries before us. */
 	TAILQ_FOREACH(s, &rm->rm_list, r_link) {
-		if (s->r_end == ULONG_MAX)
+		if (s->r_end == BUS_SPACE_MAXADDR)
 			break;
 		if (s->r_end + 1 >= r->r_start)
 			break;
@@ -274,7 +274,7 @@
 }
 
 int
-rman_first_free_region(struct rman *rm, u_long *start, u_long *end)
+rman_first_free_region(struct rman *rm, bus_addr_t *start, bus_addr_t *end)
 {
 	struct resource_i *r;
 
@@ -292,7 +292,7 @@
 }
 
 int
-rman_last_free_region(struct rman *rm, u_long *start, u_long *end)
+rman_last_free_region(struct rman *rm, bus_addr_t *start, bus_addr_t *end)
 {
 	struct resource_i *r;
 
@@ -311,7 +311,7 @@
 
 /* Shrink or extend one or both ends of an allocated resource. */
 int
-rman_adjust_resource(struct resource *rr, u_long start, u_long end)
+rman_adjust_resource(struct resource *rr, bus_addr_t start, bus_addr_t end)
 {
 	struct resource_i *r, *s, *t, *new;
 	struct rman *rm;
@@ -434,18 +434,19 @@
 #define	SHARE_TYPE(f)	(f & (RF_SHAREABLE | RF_PREFETCHABLE))
 
 struct resource *
-rman_reserve_resource_bound(struct rman *rm, u_long start, u_long end,
-			    u_long count, u_long bound, u_int flags,
+rman_reserve_resource_bound(struct rman *rm, bus_addr_t start, bus_addr_t end,
+			    u_long count, bus_addr_t bound, u_int flags,
 			    struct device *dev)
 {
 	u_int new_rflags;
 	struct resource_i *r, *s, *rv;
-	u_long rstart, rend, amask, bmask;
+	bus_addr_t rstart, rend, amask, bmask;
 
 	rv = NULL;
 
-	DPRINTF(("rman_reserve_resource_bound: <%s> request: [%#lx, %#lx], "
-	       "length %#lx, flags %u, device %s\n", rm->rm_descr, start, end,
+	DPRINTF(("rman_reserve_resource_bound: <%s> request: [%#llx, %#llx], "
+	       "length %#lx, flags %u, device %s\n", rm->rm_descr,
+	       (uint64_t)start, (uint64_t)end,
 	       count, flags,
 	       dev == NULL ? "<null>" : device_get_nameunit(dev)));
 	KASSERT((flags & RF_FIRSTSHARE) == 0,
@@ -464,9 +465,10 @@
 		goto out;
 	}
 
-	amask = (1ul << RF_ALIGNMENT(flags)) - 1;
-	KASSERT(start <= ULONG_MAX - amask,
-	    ("start (%#lx) + amask (%#lx) would wrap around", start, amask));
+	amask = (1ull << RF_ALIGNMENT(flags)) - 1;
+	KASSERT(start <= BUS_SPACE_MAXADDR - amask,
+	    ("start (%#llx) + amask (%#llx) would wrap around", (uint64_t)start,
+	    (uint64_t)amask));
 
 	/* If bound is 0, bmask will also be 0 */
 	bmask = ~(bound - 1);
@@ -474,19 +476,20 @@
 	 * First try to find an acceptable totally-unshared region.
 	 */
 	for (s = r; s; s = TAILQ_NEXT(s, r_link)) {
-		DPRINTF(("considering [%#lx, %#lx]\n", s->r_start, s->r_end));
+		DPRINTF(("considering [%#llx, %#llx]\n", (uint64_t)s->r_start,
+		    (uint64_t)s->r_end));
 		/*
 		 * The resource list is sorted, so there is no point in
 		 * searching further once r_start is too large.
 		 */
 		if (s->r_start > end - (count - 1)) {
-			DPRINTF(("s->r_start (%#lx) + count - 1> end (%#lx)\n",
-			    s->r_start, end));
+			DPRINTF(("s->r_start (%#llx) + count - 1> end (%#llx)\n",
+			    (uint64_t)s->r_start, (uint64_t)end));
 			break;
 		}
-		if (s->r_start > ULONG_MAX - amask) {
-			DPRINTF(("s->r_start (%#lx) + amask (%#lx) too large\n",
-			    s->r_start, amask));
+		if (s->r_start > BUS_SPACE_MAXADDR - amask) {
+			DPRINTF(("s->r_start (%#llx) + amask (%#llx) too large\n",
+			    (uint64_t)s->r_start, (uint64_t)amask));
 			break;
 		}
 		if (s->r_flags & RF_ALLOCATED) {
@@ -493,7 +496,7 @@
 			DPRINTF(("region is allocated\n"));
 			continue;
 		}
-		rstart = ulmax(s->r_start, start);
+		rstart = qmax(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
@@ -505,17 +508,18 @@
 				rstart += bound - (rstart & ~bmask);
 		} while ((rstart & amask) != 0 && rstart < end &&
 		    rstart < s->r_end);
-		rend = ulmin(s->r_end, ulmax(rstart + count - 1, end));
+		rend = qmin(s->r_end, qmax(rstart + count - 1, end));
 		if (rstart > rend) {
 			DPRINTF(("adjusted start exceeds end\n"));
 			continue;
 		}
-		DPRINTF(("truncated region: [%#lx, %#lx]; size %#lx (requested %#lx)\n",
-		       rstart, rend, (rend - rstart + 1), count));
+		DPRINTF(("truncated region: [%#llx, %#llx]; size %#lx (requested %#lx)\n",
+		       (uint64_t)rstart, (uint64_t)rend, (u_long)(rend - rstart + 1), count));
 
 		if ((rend - rstart + 1) >= count) {
-			DPRINTF(("candidate region: [%#lx, %#lx], size %#lx\n",
-			       rstart, rend, (rend - rstart + 1)));
+			DPRINTF(("candidate region: [%#llx, %#llx], size %#lx\n",
+			       (uint64_t)rstart, (uint64_t)rend,
+			       (u_long)(rend - rstart + 1)));
 			if ((s->r_end - s->r_start + 1) == count) {
 				DPRINTF(("candidate region is entire chunk\n"));
 				rv = s;
@@ -545,10 +549,10 @@
 
 			if (s->r_start < rv->r_start && s->r_end > rv->r_end) {
 				DPRINTF(("splitting region in three parts: "
-				       "[%#lx, %#lx]; [%#lx, %#lx]; [%#lx, %#lx]\n",
-				       s->r_start, rv->r_start - 1,
-				       rv->r_start, rv->r_end,
-				       rv->r_end + 1, s->r_end));
+				       "[%#llx, %#llx]; [%#llx, %#llx]; [%#llx, %#llx]\n",
+				       (uint64_t)s->r_start, (uint64_t)rv->r_start - 1,
+				       (uint64_t)rv->r_start, (uint64_t)rv->r_end,
+				       (uint64_t)rv->r_end + 1, (uint64_t)s->r_end));
 				/*
 				 * We are allocating in the middle.
 				 */
@@ -641,8 +645,8 @@
 }
 
 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(struct rman *rm, bus_addr_t start, bus_addr_t end,
+		      u_long count, u_int flags, struct device *dev)
 {
 
 	return (rman_reserve_resource_bound(rm, start, end, count, 0, flags,
@@ -803,13 +807,13 @@
 }
 
 void
-rman_set_start(struct resource *r, u_long start)
+rman_set_start(struct resource *r, bus_addr_t start)
 {
 
 	r->__r_i->r_start = start;
 }
 
-u_long
+bus_addr_t
 rman_get_start(struct resource *r)
 {
 
@@ -817,13 +821,13 @@
 }
 
 void
-rman_set_end(struct resource *r, u_long end)
+rman_set_end(struct resource *r, bus_addr_t end)
 {
 
 	r->__r_i->r_end = end;
 }
 
-u_long
+bus_addr_t
 rman_get_end(struct resource *r)
 {
 
@@ -830,7 +834,7 @@
 	return (r->__r_i->r_end);
 }
 
-u_long
+bus_size_t
 rman_get_size(struct resource *r)
 {
 
Index: sys/powerpc/include/bus.h
===================================================================
--- sys/powerpc/include/bus.h	(revision 287189)
+++ sys/powerpc/include/bus.h	(working copy)
@@ -79,9 +79,14 @@
 #define BUS_SPACE_MAXADDR 	0xFFFFFFFFFFFFFFFFUL
 #define BUS_SPACE_MAXSIZE 	0xFFFFFFFFFFFFFFFFUL
 #else
+#ifdef BOOKE
+#define BUS_SPACE_MAXADDR 	0xFFFFFFFFFUL
+#define BUS_SPACE_MAXSIZE 	0xFFFFFFFFUL
+#else
 #define BUS_SPACE_MAXADDR 	0xFFFFFFFFUL
 #define BUS_SPACE_MAXSIZE 	0xFFFFFFFFUL
 #endif
+#endif
 
 #define	BUS_SPACE_MAP_CACHEABLE		0x01
 #define	BUS_SPACE_MAP_LINEAR		0x02
Index: sys/powerpc/include/platform.h
===================================================================
--- sys/powerpc/include/platform.h	(revision 287189)
+++ sys/powerpc/include/platform.h	(working copy)
@@ -39,8 +39,8 @@
 #include <machine/pcpu.h>
 
 struct mem_region {
-	vm_offset_t	mr_start;
-	vm_size_t	mr_size;
+	uint64_t	mr_start;
+	uint64_t	mr_size;
 };
 
 void	mem_regions(struct mem_region **, int *, struct mem_region **, int *);
Index: sys/powerpc/mpc85xx/lbc.c
===================================================================
--- sys/powerpc/mpc85xx/lbc.c	(revision 287189)
+++ sys/powerpc/mpc85xx/lbc.c	(working copy)
@@ -69,7 +69,7 @@
 static int lbc_attach(device_t);
 static int lbc_shutdown(device_t);
 static struct resource *lbc_alloc_resource(device_t, device_t, int, int *,
-    u_long, u_long, u_long, u_int);
+    bus_addr_t, bus_addr_t, u_long, u_int);
 static int lbc_print_child(device_t, device_t);
 static int lbc_release_resource(device_t, device_t, int, int,
     struct resource *);
@@ -113,7 +113,8 @@
 
 devclass_t lbc_devclass;
 
-DRIVER_MODULE(lbc, ofwbus, lbc_driver, lbc_devclass, 0, 0);
+EARLY_DRIVER_MODULE(lbc, ofwbus, lbc_driver, lbc_devclass, 0, 0,
+    BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
 
 /*
  * Calculate address mask used by OR(n) registers. Use memory region size to
@@ -354,7 +355,7 @@
 fdt_lbc_reg_decode(phandle_t node, struct lbc_softc *sc,
     struct lbc_devinfo *di)
 {
-	u_long start, end, count;
+	uint64_t start, end, count;
 	pcell_t *reg, *regptr;
 	pcell_t addr_cells, size_cells;
 	int tuple_size, tuples;
@@ -391,8 +392,8 @@
 		start = sc->sc_banks[bank].kva + start;
 		end = start + count - 1;
 
-		debugf("reg addr bank = %d, start = %lx, end = %lx, "
-		    "count = %lx\n", bank, start, end, count);
+		debugf("reg addr bank = %d, start = %llx, end = %llx, "
+		    "count = %llx\n", bank, start, end, count);
 
 		/* Use bank (CS) cell as rid. */
 		resource_list_add(&di->di_res, SYS_RES_MEMORY, bank, start,
@@ -434,7 +435,7 @@
 	struct lbc_softc *sc;
 	struct lbc_devinfo *di;
 	struct rman *rm;
-	u_long offset, start, size;
+	uint64_t offset, start, size;
 	device_t cdev;
 	phandle_t node, child;
 	pcell_t *ranges, *rangesptr;
@@ -663,7 +664,7 @@
 
 static struct resource *
 lbc_alloc_resource(device_t bus, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct lbc_softc *sc;
 	struct lbc_devinfo *di;
Index: sys/powerpc/ofw/ofw_pci.c
===================================================================
--- sys/powerpc/ofw/ofw_pci.c	(revision 287189)
+++ sys/powerpc/ofw/ofw_pci.c	(working copy)
@@ -62,8 +62,8 @@
 static int		ofw_pci_read_ivar(device_t, device_t, int,
 			    uintptr_t *);
 static struct		resource * ofw_pci_alloc_resource(device_t bus,
-			    device_t child, int type, int *rid, u_long start,
-			    u_long end, u_long count, u_int flags);
+			    device_t child, int type, int *rid, bus_addr_t start,
+			    bus_addr_t end, u_long count, u_int flags);
 static int		ofw_pci_release_resource(device_t bus, device_t child,
     			    int type, int rid, struct resource *res);
 static int		ofw_pci_activate_resource(device_t bus, device_t child,
@@ -72,8 +72,8 @@
     			    device_t child, int type, int rid,
     			    struct resource *res);
 static int		ofw_pci_adjust_resource(device_t bus, device_t child,
-			    int type, struct resource *res, u_long start,
-			    u_long end);
+			    int type, struct resource *res, bus_addr_t start,
+			    bus_addr_t end);
 
 /*
  * pcib interface.
@@ -307,7 +307,7 @@
 
 static struct resource *
 ofw_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
-    u_long start, u_long end, u_long count, u_int flags)
+    bus_addr_t start, bus_addr_t end, u_long count, u_int flags)
 {
 	struct			ofw_pci_softc *sc;
 	struct			resource *rv;
@@ -453,7 +453,7 @@
 
 static int
 ofw_pci_adjust_resource(device_t bus, device_t child, int type,
-    struct resource *res, u_long start, u_long end)
+    struct resource *res, bus_addr_t start, bus_addr_t end)
 {
 	struct rman *rm = NULL;
 	struct ofw_pci_softc *sc = device_get_softc(bus);
Index: sys/powerpc/powerpc/nexus.c
===================================================================
--- sys/powerpc/powerpc/nexus.c	(revision 287189)
+++ sys/powerpc/powerpc/nexus.c	(working copy)
@@ -189,13 +189,13 @@
 {
 
 	if (type == SYS_RES_MEMORY) {
-		vm_offset_t start;
+		vm_paddr_t start;
 		void *p;
 
-		start = (vm_offset_t) rman_get_start(r);
+		start = rman_get_start(r);
 		if (bootverbose)
-			printf("nexus mapdev: start %zx, len %ld\n", start,
-			    rman_get_size(r));
+			printf("nexus mapdev: start %llx, len %ld\n",
+			    (uint64_t)start, rman_get_size(r));
 
 		p = pmap_mapdev(start, (vm_size_t) rman_get_size(r));
 		if (p == NULL)
Index: sys/powerpc/powerpc/platform.c
===================================================================
--- sys/powerpc/powerpc/platform.c	(revision 287189)
+++ sys/powerpc/powerpc/platform.c	(working copy)
@@ -86,8 +86,8 @@
 memr_merge(struct mem_region *from, struct mem_region *to)
 {
 	vm_offset_t end;
-	end = ulmax(to->mr_start + to->mr_size, from->mr_start + from->mr_size);
-	to->mr_start = ulmin(from->mr_start, to->mr_start);
+	end = qmax(to->mr_start + to->mr_size, from->mr_start + from->mr_size);
+	to->mr_start = qmin(from->mr_start, to->mr_start);
 	to->mr_size = end - to->mr_start;
 }
 
Index: sys/sys/bus.h
===================================================================
--- sys/sys/bus.h	(revision 287189)
+++ sys/sys/bus.h	(working copy)
@@ -29,6 +29,7 @@
 #ifndef _SYS_BUS_H_
 #define _SYS_BUS_H_
 
+#include <machine/_bus.h>
 #include <machine/_limits.h>
 #include <sys/_bus_dma.h>
 #include <sys/ioccom.h>
@@ -292,8 +293,8 @@
 	int	rid;			/**< @brief resource identifier */
 	int	flags;			/**< @brief resource flags */
 	struct	resource *res;		/**< @brief the real resource when allocated */
-	u_long	start;			/**< @brief start of resource range */
-	u_long	end;			/**< @brief end of resource range */
+	bus_addr_t	start;		/**< @brief start of resource range */
+	bus_addr_t	end;		/**< @brief end of resource range */
 	u_long	count;			/**< @brief count within range */
 };
 STAILQ_HEAD(resource_list, resource_list_entry);
@@ -307,10 +308,10 @@
 struct resource_list_entry *
 	resource_list_add(struct resource_list *rl,
 			  int type, int rid,
-			  u_long start, u_long end, u_long count);
+			  bus_addr_t start, bus_addr_t end, u_long count);
 int	resource_list_add_next(struct resource_list *rl,
 			  int type,
-			  u_long start, u_long end, u_long count);
+			  bus_addr_t start, bus_addr_t end, u_long count);
 int	resource_list_busy(struct resource_list *rl,
 			   int type, int rid);
 int	resource_list_reserved(struct resource_list *rl, int type, int rid);
@@ -323,7 +324,7 @@
 	resource_list_alloc(struct resource_list *rl,
 			    device_t bus, device_t child,
 			    int type, int *rid,
-			    u_long start, u_long end,
+			    bus_addr_t start, bus_addr_t end,
 			    u_long count, u_int flags);
 int	resource_list_release(struct resource_list *rl,
 			      device_t bus, device_t child,
@@ -335,7 +336,7 @@
 	resource_list_reserve(struct resource_list *rl,
 			      device_t bus, device_t child,
 			      int type, int *rid,
-			      u_long start, u_long end,
+			      bus_addr_t start, bus_addr_t end,
 			      u_long count, u_int flags);
 int	resource_list_unreserve(struct resource_list *rl,
 				device_t bus, device_t child,
@@ -362,11 +363,11 @@
 	bus_generic_add_child(device_t dev, u_int order, const char *name,
 			      int unit);
 int	bus_generic_adjust_resource(device_t bus, device_t child, int type,
-				    struct resource *r, u_long start,
-				    u_long end);
+				    struct resource *r, bus_addr_t start,
+				    bus_addr_t end);
 struct resource *
 	bus_generic_alloc_resource(device_t bus, device_t child, int type,
-				   int *rid, u_long start, u_long end,
+				   int *rid, bus_addr_t start, bus_addr_t end,
 				   u_long count, u_int flags);
 int	bus_generic_attach(device_t dev);
 int	bus_generic_bind_intr(device_t dev, device_t child,
@@ -405,11 +406,11 @@
 
 struct resource *
 	bus_generic_rl_alloc_resource (device_t, device_t, int, int *,
-				       u_long, u_long, u_long, u_int);
+				       bus_addr_t, bus_addr_t, u_long, u_int);
 void	bus_generic_rl_delete_resource (device_t, device_t, int, int);
-int	bus_generic_rl_get_resource (device_t, device_t, int, int, u_long *,
+int	bus_generic_rl_get_resource (device_t, device_t, int, int, bus_addr_t *,
 				     u_long *);
-int	bus_generic_rl_set_resource (device_t, device_t, int, int, u_long,
+int	bus_generic_rl_set_resource (device_t, device_t, int, int, bus_addr_t,
 				     u_long);
 int	bus_generic_rl_release_resource (device_t, device_t, int, int,
 					 struct resource *);
@@ -439,10 +440,10 @@
 			      struct resource **res);
 
 int	bus_adjust_resource(device_t child, int type, struct resource *r,
-			    u_long start, u_long end);
+			    bus_addr_t start, bus_addr_t end);
 struct	resource *bus_alloc_resource(device_t dev, int type, int *rid,
-				     u_long start, u_long end, u_long count,
-				     u_int flags);
+				     bus_addr_t start, bus_addr_t end,
+				     u_long count, u_int flags);
 int	bus_activate_resource(device_t dev, int type, int rid,
 			      struct resource *r);
 int	bus_deactivate_resource(device_t dev, int type, int rid,
@@ -460,10 +461,10 @@
 int	bus_describe_intr(device_t dev, struct resource *irq, void *cookie,
 			  const char *fmt, ...);
 int	bus_set_resource(device_t dev, int type, int rid,
-			 u_long start, u_long count);
+			 bus_addr_t start, u_long count);
 int	bus_get_resource(device_t dev, int type, int rid,
-			 u_long *startp, u_long *countp);
-u_long	bus_get_resource_start(device_t dev, int type, int rid);
+			 bus_addr_t *startp, u_long *countp);
+bus_addr_t	bus_get_resource_start(device_t dev, int type, int rid);
 u_long	bus_get_resource_count(device_t dev, int type, int rid);
 void	bus_delete_resource(device_t dev, int type, int rid);
 int	bus_child_present(device_t child);
@@ -474,7 +475,8 @@
 static __inline struct resource *
 bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
 {
-	return (bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags));
+	return (bus_alloc_resource(dev, type, rid, (bus_addr_t)0ul,
+	    ~(bus_addr_t)0ul, 1, flags));
 }
 
 /*
Index: sys/sys/rman.h
===================================================================
--- sys/sys/rman.h	(revision 287189)
+++ sys/sys/rman.h	(working copy)
@@ -54,6 +54,9 @@
 #define	RF_ALIGNMENT_LOG2(x)	((x) << RF_ALIGNMENT_SHIFT)
 #define	RF_ALIGNMENT(x)		(((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT)
 
+#define RM_MIN_START	((bus_addr_t)0)
+#define RM_MAX_END	(~(bus_addr_t)0)
+
 enum	rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
 
 /*
@@ -70,8 +73,8 @@
 	uintptr_t	r_device;		/* device owning this resource */
 	char		r_devname[RM_TEXTLEN];	/* device name XXX obsolete */
 
-	u_long		r_start;		/* offset in resource space */
-	u_long		r_size;			/* size in resource space */
+	bus_addr_t	r_start;		/* offset in resource space */
+	bus_size_t	r_size;			/* size in resource space */
 	u_int		r_flags;		/* RF_* flags */
 };
 
@@ -79,8 +82,8 @@
 	uintptr_t	rm_handle;		/* rman uniquifier */
 	char		rm_descr[RM_TEXTLEN];	/* rman description */
 
-	u_long		rm_start;		/* base of managed region */
-	u_long		rm_size;		/* size of managed region */
+	bus_addr_t	rm_start;		/* base of managed region */
+	bus_size_t	rm_size;		/* size of managed region */
 	enum rman_type	rm_type;		/* region type */
 };
 
@@ -108,8 +111,8 @@
 	struct	resource_head 	rm_list;
 	struct	mtx *rm_mtx;	/* mutex used to protect rm_list */
 	TAILQ_ENTRY(rman)	rm_link; /* link in list of all rmans */
-	u_long	rm_start;	/* index of globally first entry */
-	u_long	rm_end;		/* index of globally last entry */
+	bus_addr_t	rm_start;	/* index of globally first entry */
+	bus_addr_t	rm_end;	/* index of globally last entry */
 	enum	rman_type rm_type; /* what type of resource this is */
 	const	char *rm_descr;	/* text descripion of this resource */
 };
@@ -116,39 +119,39 @@
 TAILQ_HEAD(rman_head, rman);
 
 int	rman_activate_resource(struct resource *r);
-int	rman_adjust_resource(struct resource *r, u_long start, u_long end);
+int	rman_adjust_resource(struct resource *r, bus_addr_t start, bus_addr_t end);
 int	rman_await_resource(struct resource *r, int pri, int timo);
-int	rman_first_free_region(struct rman *rm, u_long *start, u_long *end);
+int	rman_first_free_region(struct rman *rm, bus_addr_t *start, bus_addr_t *end);
 bus_space_handle_t rman_get_bushandle(struct resource *);
 bus_space_tag_t rman_get_bustag(struct resource *);
-u_long	rman_get_end(struct resource *);
+bus_addr_t	rman_get_end(struct resource *);
 struct device *rman_get_device(struct resource *);
 u_int	rman_get_flags(struct resource *);
 int	rman_get_rid(struct resource *);
-u_long	rman_get_size(struct resource *);
-u_long	rman_get_start(struct resource *);
+bus_size_t	rman_get_size(struct resource *);
+bus_addr_t	rman_get_start(struct resource *);
 void   *rman_get_virtual(struct resource *);
 int	rman_deactivate_resource(struct resource *r);
 int	rman_fini(struct rman *rm);
 int	rman_init(struct rman *rm);
 int	rman_init_from_resource(struct rman *rm, struct resource *r);
-int	rman_last_free_region(struct rman *rm, u_long *start, u_long *end);
+int	rman_last_free_region(struct rman *rm, bus_addr_t *start, bus_addr_t *end);
 uint32_t rman_make_alignment_flags(uint32_t size);
-int	rman_manage_region(struct rman *rm, u_long start, u_long end);
+int	rman_manage_region(struct rman *rm, bus_addr_t start, bus_addr_t end);
 int	rman_is_region_manager(struct resource *r, struct rman *rm);
 int	rman_release_resource(struct resource *r);
-struct resource *rman_reserve_resource(struct rman *rm, u_long start,
-					u_long end, u_long count,
+struct resource *rman_reserve_resource(struct rman *rm, bus_addr_t start,
+					bus_addr_t 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,
+struct resource *rman_reserve_resource_bound(struct rman *rm, bus_addr_t start,
+					bus_addr_t end, u_long count, bus_addr_t bound,
 					u_int flags, struct device *dev);
 void	rman_set_bushandle(struct resource *_r, bus_space_handle_t _h);
 void	rman_set_bustag(struct resource *_r, bus_space_tag_t _t);
 void	rman_set_device(struct resource *_r, struct device *_dev);
-void	rman_set_end(struct resource *_r, u_long _end);
+void	rman_set_end(struct resource *_r, bus_addr_t _end);
 void	rman_set_rid(struct resource *_r, int _rid);
-void	rman_set_start(struct resource *_r, u_long _start);
+void	rman_set_start(struct resource *_r, bus_addr_t _start);
 void	rman_set_virtual(struct resource *_r, void *_v);
 
 extern	struct rman_head rman_head;


More information about the freebsd-arch mailing list