From 6cfc98de31b19e24cff0e9fba0c09f796e48d5e9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 1 Oct 2014 14:20:42 +0200 Subject: nexus: Use a linker set for the devices --- Makefile | 1 - freebsd-to-rtems.py | 1 - rtemsbsd/bsp/bsp-bsd-nexus-devices.c | 86 ---------------------- rtemsbsd/include/bsp/nexus-devices.h | 61 +++++++++++++++ rtemsbsd/include/rtems/bsd/bsd.h | 17 +++-- rtemsbsd/rtems/rtems-bsd-nexus.c | 18 ++--- .../include/rtems/bsd/test/default-network-init.h | 2 + testsuite/swi01/init.c | 5 -- testsuite/timeout01/init.c | 5 -- 9 files changed, 84 insertions(+), 112 deletions(-) delete mode 100644 rtemsbsd/bsp/bsp-bsd-nexus-devices.c create mode 100644 rtemsbsd/include/bsp/nexus-devices.h diff --git a/Makefile b/Makefile index e79cc74d..4f82d460 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,6 @@ LIB_C_FILES += rtemsbsd/telnetd/check_passwd.c LIB_C_FILES += rtemsbsd/telnetd/des.c LIB_C_FILES += rtemsbsd/telnetd/pty.c LIB_C_FILES += rtemsbsd/telnetd/telnetd.c -LIB_C_FILES += rtemsbsd/bsp/bsp-bsd-nexus-devices.c LIB_GEN_FILES += rtemsbsd/rtems/rtems-kvm-symbols.c LIB_C_FILES += rtemsbsd/rtems/rtems-kvm-symbols.c rtemsbsd/rtems/rtems-kvm-symbols.c: rtemsbsd/rtems/generate_kvm_symbols diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py index 64eb4751..5b747fea 100755 --- a/freebsd-to-rtems.py +++ b/freebsd-to-rtems.py @@ -707,7 +707,6 @@ rtems.addRTEMSSourceFiles( 'telnetd/des.c', 'telnetd/pty.c', 'telnetd/telnetd.c', - 'bsp/bsp-bsd-nexus-devices.c', ] ) diff --git a/rtemsbsd/bsp/bsp-bsd-nexus-devices.c b/rtemsbsd/bsp/bsp-bsd-nexus-devices.c deleted file mode 100644 index bf8aeefc..00000000 --- a/rtemsbsd/bsp/bsp-bsd-nexus-devices.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2013 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * 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 - -#include - -#include - -#if defined(LIBBSP_ARM_REALVIEW_PBX_A9_BSP_H) - -#include - -static const rtems_bsd_device_resource smc0_res[] = { - { - .type = RTEMS_BSD_RES_MEMORY, - .start_request = 0, - .start_actual = 0x4e000000 - }, { - .type = RTEMS_BSD_RES_IRQ, - .start_request = 0, - .start_actual = RVPBXA9_IRQ_ETHERNET - } -}; - -const rtems_bsd_device rtems_bsd_nexus_devices[] = { - { - .name = "smc", - .unit = 0, - .resource_count = RTEMS_ARRAY_SIZE(smc0_res), - .resources = &smc0_res[0] - } -}; - -SYSINIT_DRIVER_REFERENCE(smc, nexus); - -#elif defined(__GENMCF548X_BSP_H) - -const rtems_bsd_device rtems_bsd_nexus_devices[] = { - { - .name = "fec", - .unit = 0 - }, { - .name = "fec", - .unit = 1 - } -}; - -SYSINIT_DRIVER_REFERENCE(fec, nexus); - -#else - -const rtems_bsd_device rtems_bsd_nexus_devices[0]; - -#endif - -const size_t rtems_bsd_nexus_device_count = - RTEMS_ARRAY_SIZE(rtems_bsd_nexus_devices); diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h new file mode 100644 index 00000000..6fae2e92 --- /dev/null +++ b/rtemsbsd/include/bsp/nexus-devices.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 + +#include + +#if defined(LIBBSP_ARM_REALVIEW_PBX_A9_BSP_H) + +#include + +static const rtems_bsd_device_resource smc0_res[] = { + { + .type = RTEMS_BSD_RES_MEMORY, + .start_request = 0, + .start_actual = 0x4e000000 + }, { + .type = RTEMS_BSD_RES_IRQ, + .start_request = 0, + .start_actual = RVPBXA9_IRQ_ETHERNET + } +}; + +RTEMS_BSD_DEFINE_NEXUS_DEVICE(smc, 0, RTEMS_ARRAY_SIZE(smc0_res), + &smc0_res[0]); + +#elif defined(__GENMCF548X_BSP_H) + +RTEMS_BSD_DEFINE_NEXUS_DEVICE(fec, 0, 0, NULL); + +RTEMS_BSD_DEFINE_NEXUS_DEVICE(fec, 1, 0, NULL); + +#endif diff --git a/rtemsbsd/include/rtems/bsd/bsd.h b/rtemsbsd/include/rtems/bsd/bsd.h index af03b443..a9118ecc 100644 --- a/rtemsbsd/include/rtems/bsd/bsd.h +++ b/rtemsbsd/include/rtems/bsd/bsd.h @@ -40,12 +40,16 @@ #ifndef _RTEMS_BSD_BSD_H_ #define _RTEMS_BSD_BSD_H_ +#include +#include +#include + +#include + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#include - typedef enum { RTEMS_BSD_RES_IRQ = 1, RTEMS_BSD_RES_MEMORY = 3 @@ -62,11 +66,14 @@ typedef struct { int unit; size_t resource_count; const rtems_bsd_device_resource *resources; + const struct sysinit *driver_reference; } rtems_bsd_device; -extern const rtems_bsd_device rtems_bsd_nexus_devices[]; - -extern const size_t rtems_bsd_nexus_device_count; +#define RTEMS_BSD_DEFINE_NEXUS_DEVICE(name, unit, resource_count, resources) \ + extern struct sysinit SYSINIT_ENTRY_NAME(name##_nexusmodule); \ + RTEMS_BSD_DEFINE_SET_ITEM(nexus, name##unit, rtems_bsd_device) = \ + { #name, unit, (resource_count), (resources), \ + &SYSINIT_ENTRY_NAME(name##_nexusmodule) } rtems_status_code rtems_bsd_initialize(void); diff --git a/rtemsbsd/rtems/rtems-bsd-nexus.c b/rtemsbsd/rtems/rtems-bsd-nexus.c index ce8f646b..60cc8cd0 100644 --- a/rtemsbsd/rtems/rtems-bsd-nexus.c +++ b/rtemsbsd/rtems/rtems-bsd-nexus.c @@ -7,7 +7,7 @@ */ /* - * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved. + * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved. * * embedded brains GmbH * Dornierstr. 4 @@ -54,6 +54,10 @@ /* #define DISABLE_INTERRUPT_EXTENSION */ +RTEMS_BSD_DECLARE_SET(nexus, rtems_bsd_device); + +RTEMS_BSD_DEFINE_SET(nexus, rtems_bsd_device); + RTEMS_STATIC_ASSERT(SYS_RES_MEMORY == RTEMS_BSD_RES_MEMORY, RTEMS_BSD_RES_MEMORY); RTEMS_STATIC_ASSERT(SYS_RES_IRQ == RTEMS_BSD_RES_IRQ, RTEMS_BSD_RES_IRQ); @@ -67,7 +71,7 @@ nexus_probe(device_t dev) { rtems_status_code status; int err; - size_t i; + const rtems_bsd_device *nd; device_set_desc(dev, "RTEMS Nexus device"); @@ -100,9 +104,7 @@ nexus_probe(device_t dev) err = rman_manage_region(&irq_rman, irq_rman.rm_start, irq_rman.rm_end); BSD_ASSERT(err == 0); - for (i = 0; i < rtems_bsd_nexus_device_count; ++i) { - const rtems_bsd_device *nd = &rtems_bsd_nexus_devices[i]; - + SET_FOREACH(nd, nexus) { device_add_child(dev, nd->name, nd->unit); } @@ -133,7 +135,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct rman *rm; - size_t i; + const rtems_bsd_device *nd; switch (type) { case SYS_RES_MEMORY: @@ -146,9 +148,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, return (NULL); } - for (i = 0; i < rtems_bsd_nexus_device_count; ++i) { - const rtems_bsd_device *nd = &rtems_bsd_nexus_devices[i]; - + SET_FOREACH(nd, nexus) { if (strcmp(device_get_name(child), nd->name) == 0 && device_get_unit(child) == nd->unit) { struct resource *res = NULL; diff --git a/testsuite/include/rtems/bsd/test/default-network-init.h b/testsuite/include/rtems/bsd/test/default-network-init.h index 5643308e..fb4aa704 100644 --- a/testsuite/include/rtems/bsd/test/default-network-init.h +++ b/testsuite/include/rtems/bsd/test/default-network-init.h @@ -272,6 +272,8 @@ Init(rtems_task_argument arg) SYSINIT_NEED_NET_PF_UNIX; +#include + #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_STUB_DRIVER diff --git a/testsuite/swi01/init.c b/testsuite/swi01/init.c index 0108f6ce..ec5ae2b9 100644 --- a/testsuite/swi01/init.c +++ b/testsuite/swi01/init.c @@ -39,11 +39,6 @@ #include "swi_test.h" -const rtems_bsd_device rtems_bsd_nexus_devices[0]; - -const size_t rtems_bsd_nexus_device_count = - RTEMS_ARRAY_SIZE(rtems_bsd_nexus_devices); - static void Init(rtems_task_argument arg) { rtems_status_code sc; diff --git a/testsuite/timeout01/init.c b/testsuite/timeout01/init.c index efab0757..92385e57 100644 --- a/testsuite/timeout01/init.c +++ b/testsuite/timeout01/init.c @@ -39,11 +39,6 @@ #include "timeout_test.h" -const rtems_bsd_device rtems_bsd_nexus_devices[0]; - -const size_t rtems_bsd_nexus_device_count = - RTEMS_ARRAY_SIZE(rtems_bsd_nexus_devices); - static void Init(rtems_task_argument arg) { rtems_status_code sc; -- cgit v1.2.3