Enable setting the dma tag at the nexus level

Allow to set the dma tag for nexus in the platform init code,
so that all busses and devices would be able to inherit it.
This change is useful e.g. for setting coherent dma tag for
the platforms with hardware IO cache coherency.

Submitted by: ian
      	      Michal Mazur <mkm@semihalf.com>
Reviewed by: ian
Differential revision: https://reviews.freebsd.org/D11202
This commit is contained in:
Zbigniew Bodek 2017-06-21 18:25:35 +00:00
parent 990b485c6f
commit 474612c372
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=320198
2 changed files with 61 additions and 0 deletions

View File

@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$");
#include <machine/resource.h>
#include <machine/intr.h>
#include <arm/arm/nexusvar.h>
#ifdef FDT
#include <machine/fdt.h>
#include <dev/ofw/ofw_bus_subr.h>
@ -87,6 +89,7 @@ static struct resource *nexus_alloc_resource(device_t, device_t, int, 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);
static bus_dma_tag_t nexus_get_dma_tag(device_t dev, device_t child);
#ifdef INTRNG
#ifdef SMP
static int nexus_bind_intr(device_t, device_t, struct resource *, int);
@ -112,6 +115,13 @@ static int nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent,
int icells, pcell_t *intr);
#endif
/*
* Normally NULL (which results in defaults which are handled in
* busdma_machdep), platform init code can use nexus_set_dma_tag() to set this
* to a tag that will be inherited by all busses and devices on the platform.
*/
static bus_dma_tag_t nexus_dma_tag;
static device_method_t nexus_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, nexus_probe),
@ -127,6 +137,7 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(bus_setup_intr, nexus_setup_intr),
DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
DEVMETHOD(bus_get_bus_tag, nexus_get_bus_tag),
DEVMETHOD(bus_get_dma_tag, nexus_get_dma_tag),
#ifdef INTRNG
DEVMETHOD(bus_describe_intr, nexus_describe_intr),
#ifdef SMP
@ -275,6 +286,20 @@ nexus_get_bus_tag(device_t bus __unused, device_t child __unused)
#endif
}
static bus_dma_tag_t
nexus_get_dma_tag(device_t dev, device_t child)
{
return nexus_dma_tag;
}
void
nexus_set_dma_tag(bus_dma_tag_t tag)
{
nexus_dma_tag = tag;
}
static int
nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
enum intr_polarity pol)

36
sys/arm/arm/nexusvar.h Normal file
View File

@ -0,0 +1,36 @@
/*-
* Copyright (c) 2017 Ian Lepore <ian@freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _ARM_ARM_NEXUSVAR_H_
#define _ARM_ARM_NEXUSVAR_H_
/* Set a platform busdma tag to be inherited by all busses and devices. */
void nexus_set_dma_tag(bus_dma_tag_t _tag);
#endif