summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzbb <zbb@FreeBSD.org>2016-02-18 13:00:04 +0000
committerzbb <zbb@FreeBSD.org>2016-02-18 13:00:04 +0000
commitd2a1177be6963874bcf8d15330e4ea74c36d6823 (patch)
tree2affdba8f0124a43a93eb47db8afb77ab54cfd50
parentd520d79a17fed19e354e59fe3a6046fa89bcf8e3 (diff)
downloadFreeBSD-src-d2a1177be6963874bcf8d15330e4ea74c36d6823.zip
FreeBSD-src-d2a1177be6963874bcf8d15330e4ea74c36d6823.tar.gz
Introduce bus_get_bus_tag() method
Provide bus_get_bus_tag() for sparc64, powerpc, arm, arm64 and mips nexus and its children in order to return a platform specific default tag. This is required to ensure generic correctness of the bus_space tag. It is especially needed for arches where child bus tag does not match the parent bus tag. This solves the problem with ppc architecture where the PCI bus tag differs from parent bus tag which is big-endian. This commit is a part of the following patch: https://reviews.freebsd.org/D4879 Submitted by: Marcin Mazurek <mma@semihalf.com> Obtained from: Semihalf Sponsored by: Annapurna Labs Reviewed by: jhibbits, mmel Differential Revision: https://reviews.freebsd.org/D4879
-rw-r--r--sys/arm/arm/nexus.c13
-rw-r--r--sys/arm64/arm64/nexus.c9
-rw-r--r--sys/kern/bus_if.m11
-rw-r--r--sys/kern/subr_bus.c33
-rw-r--r--sys/powerpc/powerpc/nexus.c9
-rw-r--r--sys/sparc64/sparc64/nexus.c9
-rw-r--r--sys/sys/bus.h4
7 files changed, 88 insertions, 0 deletions
diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c
index 97e9e25..b1c6b08 100644
--- a/sys/arm/arm/nexus.c
+++ b/sys/arm/arm/nexus.c
@@ -85,6 +85,7 @@ static struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
rman_res_t, rman_res_t, rman_res_t, u_int);
static int nexus_activate_resource(device_t, device_t, int, int,
struct resource *);
+static bus_space_tag_t nexus_get_bus_tag(device_t, device_t);
#ifdef ARM_INTRNG
#ifdef SMP
static int nexus_bind_intr(device_t, device_t, struct resource *, int);
@@ -124,6 +125,7 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(bus_release_resource, nexus_release_resource),
DEVMETHOD(bus_setup_intr, nexus_setup_intr),
DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
+ DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
#ifdef ARM_INTRNG
DEVMETHOD(bus_describe_intr, nexus_describe_intr),
#ifdef SMP
@@ -260,6 +262,17 @@ nexus_release_resource(device_t bus, device_t child, int type, int rid,
return (rman_release_resource(res));
}
+static bus_space_tag_t
+nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
+{
+
+#ifdef FDT
+ return(fdtbus_bs_tag);
+#else
+ return((void *)1);
+#endif
+}
+
static int
nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
enum intr_polarity pol)
diff --git a/sys/arm64/arm64/nexus.c b/sys/arm64/arm64/nexus.c
index 611addd..c56c7aa 100644
--- a/sys/arm64/arm64/nexus.c
+++ b/sys/arm64/arm64/nexus.c
@@ -113,6 +113,7 @@ static int nexus_deactivate_resource(device_t, device_t, int, int,
static int nexus_setup_intr(device_t dev, device_t child, struct resource *res,
int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep);
static int nexus_teardown_intr(device_t, device_t, struct resource *, void *);
+static bus_space_tag_t nexus_get_bus_tag(device_t, device_t);
#ifdef SMP
static int nexus_bind_intr(device_t, device_t, struct resource *, int);
#endif
@@ -134,6 +135,7 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
DEVMETHOD(bus_setup_intr, nexus_setup_intr),
DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
+ DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
#ifdef SMP
DEVMETHOD(bus_bind_intr, nexus_bind_intr),
#endif
@@ -307,6 +309,13 @@ nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu)
}
#endif
+static bus_space_tag_t
+nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
+{
+
+ return(&memmap_bus);
+}
+
static int
nexus_activate_resource(device_t bus, device_t child, int type, int rid,
struct resource *r)
diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m
index e55b1ce..8acadd7 100644
--- a/sys/kern/bus_if.m
+++ b/sys/kern/bus_if.m
@@ -637,6 +637,17 @@ METHOD bus_dma_tag_t get_dma_tag {
} DEFAULT bus_generic_get_dma_tag;
/**
+ * @brief Returns bus_space_tag_t for use w/ devices on the bus.
+ *
+ * @param _dev the parent device of @p _child
+ * @param _child the device to which the tag will belong
+ */
+METHOD bus_space_tag_t get_bus_tag {
+ device_t _dev;
+ device_t _child;
+} DEFAULT bus_generic_get_bus_tag;
+
+/**
* @brief Allow the bus to determine the unit number of a device.
*
* @param _dev the parent device of @p _child
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 6aca991..3e4568b 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -4095,6 +4095,22 @@ bus_generic_get_dma_tag(device_t dev, device_t child)
}
/**
+ * @brief Helper function for implementing BUS_GET_BUS_TAG().
+ *
+ * This simple implementation of BUS_GET_BUS_TAG() simply calls the
+ * BUS_GET_BUS_TAG() method of the parent of @p dev.
+ */
+bus_space_tag_t
+bus_generic_get_bus_tag(device_t dev, device_t child)
+{
+
+ /* Propagate up the bus hierarchy until someone handles it. */
+ if (dev->parent != NULL)
+ return (BUS_GET_BUS_TAG(dev->parent, child));
+ return (NULL);
+}
+
+/**
* @brief Helper function for implementing BUS_GET_RESOURCE().
*
* This implementation of BUS_GET_RESOURCE() uses the
@@ -4576,6 +4592,23 @@ bus_get_dma_tag(device_t dev)
}
/**
+ * @brief Wrapper function for BUS_GET_BUS_TAG().
+ *
+ * This function simply calls the BUS_GET_BUS_TAG() method of the
+ * parent of @p dev.
+ */
+bus_space_tag_t
+bus_get_bus_tag(device_t dev)
+{
+ device_t parent;
+
+ parent = device_get_parent(dev);
+ if (parent == NULL)
+ return (NULL);
+ return (BUS_GET_BUS_TAG(parent, dev));
+}
+
+/**
* @brief Wrapper function for BUS_GET_DOMAIN().
*
* This function simply calls the BUS_GET_DOMAIN() method of the
diff --git a/sys/powerpc/powerpc/nexus.c b/sys/powerpc/powerpc/nexus.c
index dff21f8..1ad118c 100644
--- a/sys/powerpc/powerpc/nexus.c
+++ b/sys/powerpc/powerpc/nexus.c
@@ -66,6 +66,7 @@ static bus_setup_intr_t nexus_setup_intr;
static bus_teardown_intr_t nexus_teardown_intr;
static bus_activate_resource_t nexus_activate_resource;
static bus_deactivate_resource_t nexus_deactivate_resource;
+static bus_space_tag_t nexus_get_bus_tag(device_t, device_t);
#ifdef SMP
static bus_bind_intr_t nexus_bind_intr;
#endif
@@ -87,6 +88,7 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(bus_bind_intr, nexus_bind_intr),
#endif
DEVMETHOD(bus_config_intr, nexus_config_intr),
+ DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
/* ofw_bus interface */
DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr),
@@ -155,6 +157,13 @@ nexus_teardown_intr(device_t bus __unused, device_t child __unused,
return (powerpc_teardown_intr(ih));
}
+static bus_space_tag_t
+nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
+{
+
+ return(&bs_be_tag);
+}
+
#ifdef SMP
static int
nexus_bind_intr(device_t bus __unused, device_t child __unused,
diff --git a/sys/sparc64/sparc64/nexus.c b/sys/sparc64/sparc64/nexus.c
index 7082220..67a954b 100644
--- a/sys/sparc64/sparc64/nexus.c
+++ b/sys/sparc64/sparc64/nexus.c
@@ -98,6 +98,7 @@ static bus_bind_intr_t nexus_bind_intr;
#endif
static bus_describe_intr_t nexus_describe_intr;
static bus_get_dma_tag_t nexus_get_dma_tag;
+static bus_get_bus_tag_t nexus_get_bus_tag;
static ofw_bus_get_devinfo_t nexus_get_devinfo;
static int nexus_inlist(const char *, const char *const *);
@@ -135,6 +136,7 @@ static device_method_t nexus_methods[] = {
#endif
DEVMETHOD(bus_describe_intr, nexus_describe_intr),
DEVMETHOD(bus_get_dma_tag, nexus_get_dma_tag),
+ DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
/* ofw_bus interface */
DEVMETHOD(ofw_bus_get_devinfo, nexus_get_devinfo),
@@ -502,6 +504,13 @@ nexus_get_dma_tag(device_t bus __unused, device_t child __unused)
return (&nexus_dmatag);
}
+static bus_space_tag_t
+nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
+{
+
+ return (&nexus_bustag);
+}
+
static const struct ofw_bus_devinfo *
nexus_get_devinfo(device_t bus __unused, device_t child)
{
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index 4348ae7..15f5c06 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -30,6 +30,7 @@
#define _SYS_BUS_H_
#include <machine/_limits.h>
+#include <machine/_bus.h>
#include <sys/_bus_dma.h>
#include <sys/ioccom.h>
@@ -383,6 +384,8 @@ int bus_generic_detach(device_t dev);
void bus_generic_driver_added(device_t dev, driver_t *driver);
bus_dma_tag_t
bus_generic_get_dma_tag(device_t dev, device_t child);
+bus_space_tag_t
+ bus_generic_get_bus_tag(device_t dev, device_t child);
int bus_generic_get_domain(device_t dev, device_t child, int *domain);
struct resource_list *
bus_generic_get_resource_list (device_t, device_t);
@@ -448,6 +451,7 @@ int bus_activate_resource(device_t dev, int type, int rid,
int bus_deactivate_resource(device_t dev, int type, int rid,
struct resource *r);
bus_dma_tag_t bus_get_dma_tag(device_t dev);
+bus_space_tag_t bus_get_bus_tag(device_t dev);
int bus_get_domain(device_t dev, int *domain);
int bus_release_resource(device_t dev, int type, int rid,
struct resource *r);
OpenPOWER on IntegriCloud