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
This commit is contained in:
Zbigniew Bodek 2016-02-18 13:00:04 +00:00
parent e2d4f32f4e
commit b998c9656b
7 changed files with 88 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -636,6 +636,17 @@ METHOD bus_dma_tag_t get_dma_tag {
device_t _child;
} 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.
*

View File

@ -4094,6 +4094,22 @@ bus_generic_get_dma_tag(device_t dev, device_t child)
return (NULL);
}
/**
* @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().
*
@ -4575,6 +4591,23 @@ bus_get_dma_tag(device_t dev)
return (BUS_GET_DMA_TAG(parent, 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().
*

View File

@ -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,

View File

@ -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)
{

View File

@ -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);