]> xenbits.xensource.com Git - people/julieng/freebsd.git/commitdiff
xenpv: use memory above the MMIO region
authorRoger Pau Monne <roger.pau@citrix.com>
Tue, 23 Sep 2014 16:56:48 +0000 (18:56 +0200)
committerJulien Grall <julien.grall@linaro.org>
Sun, 12 Apr 2015 11:07:59 +0000 (12:07 +0100)
Using memory below 4GB might cause problems with MMIO regions from physical
devices. In order to prevent that, always use memory from above the MMIO
hole for devices that hang off the xenpv bus.

Sponsored by: Citrix Systems R&D

sys/x86/xen/xenpv.c

index bdda88374f27cad751ca7ba06ac67f6a3d5d0559..607d26982b9f1c203393b4ffea68b7b4a1ed6f96 100644 (file)
@@ -34,12 +34,16 @@ __FBSDID("$FreeBSD$");
 #include <sys/module.h>
 #include <sys/pcpu.h>
 #include <sys/smp.h>
+#include <sys/rman.h>
 
 #include <xen/xen-os.h>
 #include <xen/gnttab.h>
 
 static devclass_t xenpv_devclass;
 
+/* End of MMIO region on x86 (4GB) */
+#define MMIO_END       (4*1073741824UL)
+
 static void
 xenpv_identify(driver_t *driver, device_t parent)
 {
@@ -85,6 +89,24 @@ xenpv_attach(device_t dev)
        return (0);
 }
 
+static struct resource *
+xenpv_alloc_resource(device_t dev, device_t child, int type, int *rid,
+    u_long start, u_long end, u_long count, u_int flags)
+{
+
+       /*
+        * Devices hanging off xenpv request memory in order to
+        * map grants or foreign pages. By default use memory
+        * after the MMIO region in order to prevent clashes with
+        * real devices.
+        */
+       if (type == SYS_RES_MEMORY && start < MMIO_END)
+               start = MMIO_END;
+
+        return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
+           count, flags));
+}
+
 static device_method_t xenpv_methods[] = {
        /* Device interface */
        DEVMETHOD(device_identify,              xenpv_identify),
@@ -95,7 +117,7 @@ static device_method_t xenpv_methods[] = {
 
        /* Bus interface */
        DEVMETHOD(bus_add_child,                bus_generic_add_child),
-       DEVMETHOD(bus_alloc_resource,           bus_generic_alloc_resource),
+       DEVMETHOD(bus_alloc_resource,           xenpv_alloc_resource),
        DEVMETHOD(bus_release_resource,         bus_generic_release_resource),
        DEVMETHOD(bus_activate_resource,        bus_generic_activate_resource),
        DEVMETHOD(bus_deactivate_resource,      bus_generic_deactivate_resource),