From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id EFC8E5592 for ; Fri, 6 May 2016 15:50:08 +0200 (CEST) Received: from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz [147.229.13.147]) by wes1-so2.wedos.net (Postfix) with ESMTPSA id 3r1Y7N5CdSz78D; Fri, 6 May 2016 15:50:08 +0200 (CEST) From: Jan Viktorin To: dev@dpdk.org Cc: Jan Viktorin , David Marchand , Thomas Monjalon , Bruce Richardson , Declan Doherty , jianbo.liu@linaro.org, jerin.jacob@caviumnetworks.com, Keith Wiles , Stephen Hemminger Date: Fri, 6 May 2016 15:47:48 +0200 Message-Id: <1462542490-15556-7-git-send-email-viktorin@rehivetech.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1462542490-15556-1-git-send-email-viktorin@rehivetech.com> References: <1462542490-15556-1-git-send-email-viktorin@rehivetech.com> In-Reply-To: <1451682326-5834-1-git-send-email-viktorin@rehivetech.com> References: <1451682326-5834-1-git-send-email-viktorin@rehivetech.com> Subject: [dpdk-dev] [PATCH v1 06/28] eal/soc: introduce very essential SoC infra definitions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 13:50:09 -0000 Define initial structures and functions for the SoC infrastructure. We support only a very minimal functions now. More features will be added in the following commits. It is to be refactored when a generic rte_device/driver pair is added to DPDK. Signed-off-by: Jan Viktorin --- app/test/Makefile | 1 + app/test/test_soc.c | 93 ++++++++++++++++++++++ lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_private.h | 4 + lib/librte_eal/common/include/rte_soc.h | 134 ++++++++++++++++++++++++++++++++ 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 app/test/test_soc.c create mode 100644 lib/librte_eal/common/include/rte_soc.h diff --git a/app/test/Makefile b/app/test/Makefile index a4907d5..33c44c2 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -43,6 +43,7 @@ APP = test # SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) := commands.c SRCS-y += test.c +SRCS-y += test_soc.c SRCS-y += test_pci.c SRCS-y += test_prefetch.c SRCS-y += test_byteorder.c diff --git a/app/test/test_soc.c b/app/test/test_soc.c new file mode 100644 index 0000000..a49fc9b --- /dev/null +++ b/app/test/test_soc.c @@ -0,0 +1,93 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 RehiveTech. All rights reserved. + * 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 RehiveTech 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. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "test.h" + +static char *safe_strdup(const char *s) +{ + char *c = strdup(s); + if (c == NULL) + rte_panic("failed to strdup '%s'\n", s); + + return c; +} + +static int test_compare_addr(void) +{ + struct rte_soc_addr a0; + struct rte_soc_addr a1; + struct rte_soc_addr a2; + + a0.name = safe_strdup("ethernet0"); + a0.fdt_path = NULL; + + a1.name = safe_strdup("ethernet0"); + a1.fdt_path = NULL; + + a2.name = safe_strdup("ethernet1"); + a2.fdt_path = NULL; + + TEST_ASSERT(!rte_eal_compare_soc_addr(&a0, &a1), + "Failed to compare two soc addresses that equal"); + TEST_ASSERT(rte_eal_compare_soc_addr(&a0, &a2), + "Failed to compare two soc addresses that differs"); + + free(a2.name); + free(a1.name); + free(a0.name); + return 0; +} + +static int +test_soc(void) +{ + if (test_compare_addr()) + return -1; + + return 0; +} + +static struct test_command soc_cmd = { + .command = "soc_autotest", + .callback = test_soc, +}; +REGISTER_TEST_COMMAND(soc_cmd); diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index f5ea0ee..a409c22 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -33,7 +33,7 @@ include $(RTE_SDK)/mk/rte.vars.mk INC := rte_branch_prediction.h rte_common.h INC += rte_debug.h rte_eal.h rte_errno.h rte_launch.h rte_lcore.h -INC += rte_log.h rte_memory.h rte_memzone.h rte_pci.h +INC += rte_log.h rte_memory.h rte_memzone.h rte_soc.h rte_pci.h INC += rte_pci_dev_ids.h rte_per_lcore.h rte_random.h INC += rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_version.h diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index b8ce5b9..5145215 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -36,6 +36,7 @@ #include #include +#include /** * Initialize the memzone subsystem (private to eal). @@ -183,6 +184,9 @@ int rte_eal_ivshmem_init(void); int rte_eal_ivshmem_obj_init(void); #endif +struct rte_soc_driver; +struct rte_soc_device; + struct rte_pci_driver; struct rte_pci_device; diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h new file mode 100644 index 0000000..cde588a --- /dev/null +++ b/lib/librte_eal/common/include/rte_soc.h @@ -0,0 +1,134 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 RehiveTech. All rights reserved. + * 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. + */ + +#ifndef _RTE_SOC_H_ +#define _RTE_SOC_H_ + +/** + * @file + * + * RTE SoC Interface + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include + +#include + +struct rte_soc_id { + const char *compatible; /**< OF compatible specification */ +}; + +struct rte_soc_addr { + char *name; /**< name used in sysfs */ + char *fdt_path; /**< path to the associated node in FDT */ +}; + +/** + * A structure describing a SoC device. + */ +struct rte_soc_device { + TAILQ_ENTRY(rte_soc_device) next; /**< Next probed SoC device */ + struct rte_soc_addr addr; /**< SoC device Location */ + struct rte_soc_id *id; /**< SoC device ID list */ + struct rte_soc_driver *driver; /**< Associated driver */ +}; + +struct rte_soc_driver; + +/** + * Initialization function for the driver called during SoC probing. + */ +typedef int (soc_devinit_t)(struct rte_soc_driver *, struct rte_soc_device *); + +/** + * Uninitialization function for the driver called during hotplugging. + */ +typedef int (soc_devuninit_t)(struct rte_soc_device *); + +/** + * A structure describing a SoC driver. + */ +struct rte_soc_driver { + TAILQ_ENTRY(rte_soc_driver) next; /**< Next in list */ + const char *name; /**< Driver name */ + soc_devinit_t *devinit; /**< Device initialization */ + soc_devuninit_t *devuninit; /**< Device uninitialization */ + const struct rte_soc_id *id_table; /**< ID table, NULL terminated */ +}; + +/** + * Utility function to write a SoC device name, this device name can later be + * used to retrieve the corresponding rte_soc_addr using above functions. + * + * @param addr + * The SoC address + * @param output + * The output buffer string + * @param size + * The output buffer size + * @return + * 0 on success, negative on error. + */ +static inline void +rte_eal_soc_device_name(const struct rte_soc_addr *addr, + char *output, size_t size) +{ + int ret; + RTE_VERIFY(addr != NULL); + RTE_VERIFY(size >= strlen(addr->name)); + ret = snprintf(output, size, "%s", addr->name); + RTE_VERIFY(ret >= 0); +} + +static inline int +rte_eal_compare_soc_addr(const struct rte_soc_addr *a0, + const struct rte_soc_addr *a1) +{ + if (a0 == NULL || a1 == NULL) + return -1; + + RTE_VERIFY(a0->name != NULL); + RTE_VERIFY(a1->name != NULL); + + return strcmp(a0->name, a1->name); +} + +#endif -- 2.8.0