Author: zbb Date: Thu Feb 18 13:00:04 2016 New Revision: 295755 URL: https://svnweb.freebsd.org/changeset/base/295755
Log: 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 <m...@semihalf.com> Obtained from: Semihalf Sponsored by: Annapurna Labs Reviewed by: jhibbits, mmel Differential Revision: https://reviews.freebsd.org/D4879 Modified: head/sys/arm/arm/nexus.c head/sys/arm64/arm64/nexus.c head/sys/kern/bus_if.m head/sys/kern/subr_bus.c head/sys/powerpc/powerpc/nexus.c head/sys/sparc64/sparc64/nexus.c head/sys/sys/bus.h Modified: head/sys/arm/arm/nexus.c ============================================================================== --- head/sys/arm/arm/nexus.c Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/arm/arm/nexus.c Thu Feb 18 13:00:04 2016 (r295755) @@ -85,6 +85,7 @@ static struct resource *nexus_alloc_reso 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, dev 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) Modified: head/sys/arm64/arm64/nexus.c ============================================================================== --- head/sys/arm64/arm64/nexus.c Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/arm64/arm64/nexus.c Thu Feb 18 13:00:04 2016 (r295755) @@ -113,6 +113,7 @@ static int nexus_deactivate_resource(dev 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 c } #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) Modified: head/sys/kern/bus_if.m ============================================================================== --- head/sys/kern/bus_if.m Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/kern/bus_if.m Thu Feb 18 13:00:04 2016 (r295755) @@ -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 Modified: head/sys/kern/subr_bus.c ============================================================================== --- head/sys/kern/subr_bus.c Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/kern/subr_bus.c Thu Feb 18 13:00:04 2016 (r295755) @@ -4095,6 +4095,22 @@ bus_generic_get_dma_tag(device_t dev, de } /** + * @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 Modified: head/sys/powerpc/powerpc/nexus.c ============================================================================== --- head/sys/powerpc/powerpc/nexus.c Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/powerpc/powerpc/nexus.c Thu Feb 18 13:00:04 2016 (r295755) @@ -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 __unuse 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, Modified: head/sys/sparc64/sparc64/nexus.c ============================================================================== --- head/sys/sparc64/sparc64/nexus.c Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/sparc64/sparc64/nexus.c Thu Feb 18 13:00:04 2016 (r295755) @@ -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, 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) { Modified: head/sys/sys/bus.h ============================================================================== --- head/sys/sys/bus.h Thu Feb 18 11:53:57 2016 (r295754) +++ head/sys/sys/bus.h Thu Feb 18 13:00:04 2016 (r295755) @@ -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 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); _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"