FDT(4): Port to RTEMS

This commit is contained in:
Sebastian Huber
2017-03-02 16:29:11 +01:00
parent f0dd0c506a
commit c1205ee81e
16 changed files with 1053 additions and 3 deletions

View File

@@ -0,0 +1,58 @@
#include <machine/rtems-bsd-kernel-space.h>
/*-
* Copyright (c) 2015 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.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_subr.h>
int
OF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *tag,
bus_space_handle_t *handle, bus_size_t *sz)
{
bus_addr_t addr;
bus_size_t size;
int err;
err = ofw_reg_to_paddr(dev, regno, &addr, &size, NULL);
if (err != 0)
return (err);
*tag = 0;
if (sz != NULL)
*sz = size;
return (bus_space_map(*tag, addr, size, 0, handle));
}

View File

@@ -7,7 +7,7 @@
*/
/*
* Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved.
* Copyright (c) 2009, 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -50,11 +50,21 @@
#include <sys/malloc.h>
#include <machine/bus.h>
#include <rtems/bsd/local/opt_platform.h>
#ifdef FDT
#include <dev/ofw/ofw_bus.h>
#endif
#include <rtems/bsd/bsd.h>
#include <rtems/irq-extension.h>
/* #define DISABLE_INTERRUPT_EXTENSION */
#if defined(__i386__) || defined(FDT)
#define ENABLE_RESOURCE_ACTIVATE_DEACTIVATE
#endif
RTEMS_BSD_DECLARE_SET(nexus, rtems_bsd_device);
RTEMS_BSD_DEFINE_SET(nexus, rtems_bsd_device);
@@ -205,17 +215,24 @@ nexus_release_resource(device_t bus, device_t child, int type, int rid,
return (rman_release_resource(res));
}
#ifdef __i386__
#ifdef ENABLE_RESOURCE_ACTIVATE_DEACTIVATE
static int
nexus_activate_resource(device_t bus, device_t child, int type, int rid,
struct resource *res)
{
switch (type) {
#ifdef __i386__
case SYS_RES_IOPORT:
rman_set_bustag(res, X86_BUS_SPACE_IO);
break;
#endif
case SYS_RES_MEMORY:
#ifdef __i386__
rman_set_bustag(res, X86_BUS_SPACE_MEM);
#else
rman_set_bushandle(res, rman_get_start(res));
#endif
break;
}
return (rman_activate_resource(res));
@@ -330,6 +347,16 @@ nexus_teardown_intr(device_t dev, device_t child, struct resource *res,
return (err);
}
#ifdef FDT
static int
nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int icells,
pcell_t *intr)
{
return ((int)bsp_fdt_map_intr(intr[0]));
}
#endif /* FDT */
static device_method_t nexus_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, nexus_probe),
@@ -344,13 +371,18 @@ static device_method_t nexus_methods[] = {
DEVMETHOD(bus_add_child, bus_generic_add_child),
DEVMETHOD(bus_alloc_resource, nexus_alloc_resource),
DEVMETHOD(bus_release_resource, nexus_release_resource),
#ifdef __i386__
#ifdef ENABLE_RESOURCE_ACTIVATE_DEACTIVATE
DEVMETHOD(bus_activate_resource, nexus_activate_resource),
DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
#endif
DEVMETHOD(bus_setup_intr, nexus_setup_intr),
DEVMETHOD(bus_teardown_intr, nexus_teardown_intr),
#ifdef FDT
/* OFW interface */
DEVMETHOD(ofw_bus_map_intr, nexus_ofw_map_intr),
#endif
{ 0, 0 }
};