Rather than have each driver have to remember to add a constructor to it to make sure its gets registered properly, wrap that process up in a macro to make registration a one line affair. This also sets the stage for us to make registration of vdev pmds and physical pmds a uniform process
Signed-off-by: Neil Horman <nhorman at tuxdriver.com> --- lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/include/rte_pmd.h | 69 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/common/include/rte_pmd.h diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index 2f99bf4..b918a73 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -37,7 +37,7 @@ INC += rte_log.h rte_memcpy.h rte_memory.h rte_memzone.h rte_pci.h INC += rte_pci_dev_ids.h rte_per_lcore.h rte_prefetch.h rte_random.h INC += rte_rwlock.h rte_spinlock.h rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_cpuflags.h rte_version.h rte_tailq_elem.h -INC += rte_eal_memconfig.h rte_malloc_heap.h +INC += rte_eal_memconfig.h rte_malloc_heap.h rte_pmd.h INC += rte_hexdump.h rte_devargs.h rte_vdev.h ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y) diff --git a/lib/librte_eal/common/include/rte_pmd.h b/lib/librte_eal/common/include/rte_pmd.h new file mode 100644 index 0000000..b37fa28 --- /dev/null +++ b/lib/librte_eal/common/include/rte_pmd.h @@ -0,0 +1,69 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2014 Neil Horman <nhorman at tuxdriver.com. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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. + */ + +/** + * @file + * + * API for error cause tracking + */ + +#ifndef _RTE_PMD_H_ +#define _RTE_PMD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +enum rte_pmd_driver_type { + PMD_VDEV = 1 +}; + +extern void rte_eal_nonpci_dev_init_register(const char *name, int (*dev_initfn)(const char *, const char *)); +#define PMD_REGISTER_DRIVER(d, t)\ +void devinitfn_ ##d(void);\ +void __attribute__((constructor, used)) devinitfn_ ##d(void)\ +{\ + enum rte_pmd_driver_type _t = (t);\ + switch(_t)\ + {\ + case PMD_VDEV:\ + rte_eal_vdev_driver_register(&d);\ + break;\ + };\ +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_PMD_H_ */ -- 1.8.3.1