From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0081.outbound.protection.outlook.com [104.47.33.81]) by dpdk.org (Postfix) with ESMTP id D65C5591F for ; Mon, 24 Oct 2016 13:59:52 +0200 (CEST) Received: from CY1PR03CA0025.namprd03.prod.outlook.com (10.174.128.35) by BN3PR03MB2369.namprd03.prod.outlook.com (10.166.74.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.16; Mon, 24 Oct 2016 11:59:51 +0000 Received: from BL2FFO11FD028.protection.gbl (2a01:111:f400:7c09::167) by CY1PR03CA0025.outlook.office365.com (2603:10b6:600::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Mon, 24 Oct 2016 11:59:51 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD028.mail.protection.outlook.com (10.173.161.107) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.669.7 via Frontend Transport; Mon, 24 Oct 2016 11:59:50 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9OBwEMa008267; Mon, 24 Oct 2016 04:59:47 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Mon, 24 Oct 2016 17:29:35 +0530 Message-ID: <1477310380-17944-17-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477310380-17944-1-git-send-email-shreyansh.jain@nxp.com> References: <1476539108-13170-1-git-send-email-shreyansh.jain@nxp.com> <1477310380-17944-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131217839905697286; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(2906002)(4326007)(68736007)(6666003)(76176999)(50986999)(7846002)(33646002)(8666005)(356003)(305945005)(5003940100001)(189998001)(586003)(47776003)(105606002)(19580405001)(19580395003)(36756003)(97736004)(50466002)(48376002)(229853001)(2351001)(106466001)(11100500001)(626004)(92566002)(87936001)(5660300001)(85426001)(6916009)(104016004)(2950100002)(86362001)(81166006)(81156014)(110136003)(77096005)(50226002)(8676002)(8936002)(403724002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2369; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD028; 1:y92AQ+738kNCl83SHzmu9lcFjKyjVEAv6phwx9cIdcKkOMQs/SIbfbQ7yK8gyzv/q5WqKBaV6Qhp7AFoLP/b3v/oA4wrn3DQ85JfI9PQiO+q4Sq7Qv5Q80FMt/ivHC5ArP6d2Rt4ZXpLkmN1GSrFPR7z0sW/fezl86zckbMMc2qvDQF68GxoCmL0EanMtrju22WgwaeZtRb82auP7cDetERnjIf+VIqbgYSSfu/18mIiWxkfwRkok828s865h2v8QanNtt4albCF3DIV10St9/pLGA1Yzv65Fjg8IlcPLfp/tI+zIVhC6XAHVnftb+ajFdTNWq+6XXyrirjgtY52JrMeoBEPvjcf8W8dbiVDbS6dmoY+jyEXO/dnx9MiVfOO8aYanSYzGq9bUydR5o7RjauaASbiPKpnfX4qVoGl98yfCx9cAzV7A7xX0mk/FjA4PeSM71lD0LPkxhJTJ/iUcntuDWRngxPRm7+VSFGNhhZWlajxKyyTO7VIUqXb2+iJ8KvA8w2stpxySNDMqaXIzoG2bSxP1GMYPOapsXZjmcqidvjECCy5xN9BxHHJ4zkVhfMj70DJsqe7sN9oOTbOCDyAvR22CtHtz6Cib2uBPMIvVy20kimPk9Z55CkEXB36TtLXXl74t/jUZVt7Utwn0xGGbyz2MCfmr2Xd8vN0naO/bMZKHBIDWYL8ibZjT1p9BoPVuXg3gdqSGCEWbNEWdFNyZYNvOpuSbsurRgI8MBY= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: d6f0e139-89d8-41ab-ee06-08d3fc05423c X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2369; 2:cqdVINY9jvC28AEeZq18cWAdGzv2bJtGlkGD4O6rJFvgE7aluA0K+GuSDNwDiI0c7yIMNxb2Si0EqmFTTSvNWNYY6Mk2h1i1m7N4d9/uiuI9a5U06Bel1teuG7q/FLaGURn84+7SyKlQ02TqlZIio2z7A5E6SAovsZIa9A2FfF3AAcTY9Xmsl3A+8bVvt0pwCHw4LmYPVLoLv7KXmXZWjA==; 3:WGVMcNrLbDdmc5IVDQHY2qOJY4dekUATrmCbvqOxfbe05gb2iRfjUUXHNkKAPuBUDntRBsw4En/qsbKJSXdqoOVfQoveuBkkEaIQH8FyIP8y2IJEM4KC5bJphfxCWw4XHvzaeLW3tU7zB5uIOu2qw/24B+dmLiUa6KUGrsmg9iqqCsQ5p6c/uVwaZQemWJm0C5Vy0MSRhc2lZdbyss8GOqSgUTq7IohxT6b9vBKD5z0LkduPj70xkek2EOETttKU X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB2369; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2369; 25:eerswFHDQ8bGzg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BkrzN5C32d8hYY92wVZI2Kcbzixu93WAV4Y48tTvdeWHKAQYHsP9LNubH8=; 4:3qUoaFtHOHuU9Mzbc03GewS02j7tBnT3SHDnqYgYRvbaV3viiNXctWmq+HVeagefDbaGvb/ia2s3WWZCcB+gbEfUzeXROfEZnnGTeUWH4iDvboGPzn21atJ0j5I9UqhYQ5U4ET/5WBK1OOxiQIWrBoybL4PbzMpE1jzwC7/vVxImLBwlZqbbKBY+9DbOgWPeO+Z16i2rb0qXTlwRIccFeIQoKUQpx1zkjtmKOUPxmAyPHWsQLCDK3M3kYrWFjosMpcRZBiY7CtEqn6Mq/Qb1/63FkZeLlsnCpSHXBJRYus0DikFNiMzubfxnE+c4B+lf0cEC4HxTNWP57Bt3IcfSdbjz3u2uDXsYgc1iYfebi4BrwIjBt0OStFTMWfSR5TveFFol6bv+zAFvp2M4mhkGNv0Uc3A7KGqY7k9ha2nH6JfQNYeqywX5fN5qoGsDsVYJMXkIteqQfZNOoX1MjkRcOyiuUARv39hy2ZPscMnxJoFIMcxBF9mfz9QWV9TkGgiIsizNPJ3MFrK8cwZ7+ucWGRVCUGiWiokkzwjleBG+wPo1yaSldO/+R8QlDdD+bQVy X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13023025)(13018025)(13024025)(13015025)(13017025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:BN3PR03MB2369; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB2369; X-Forefront-PRVS: 0105DAA385 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB2369; 23:6szUh8+t6BtA0SyI29k18weXaXyd7nPvu+kScVjxM?= =?us-ascii?Q?H2kYV8sWA7yLyOPMdEBOi0NHZ09X01eseCmTIMtfOnkLdQhTiIcR06oCFFTN?= =?us-ascii?Q?kFWsfNYBUB2nBZeNejiRA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u3xbcHsc0b0/At?= =?us-ascii?Q?DwwB3oVPwMsck7+KbrPYsAv5Kw13LTR5xGV24hGh+jPOox3CphYwxYZYz11z?= =?us-ascii?Q?McRSlM3LAxE6/pm7Ve16Yy//Q37QQRVuJ9GJKoPeHOa3OnOvFXZemv+hnI5s?= =?us-ascii?Q?gbCTeK2AmaIHq/f3fGv34bCW4HiKgS3dflFG5yitjqYkPUG85fdm59Hvw1cz?= =?us-ascii?Q?Buysa2iIRuTvekdi8kmqt1SjFyX1693cE4iRexE7eLzwlpKx/Z61Vc1vw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2369; 6:53d8BhGQFjZ6buQN7MfK9vg5MCAjH4BsgAwPSuoyaFuvRLpCt1CahNBixjwzlLXAs4jXJ5SKF1Ch8DZF8HwijrFYpnwELyL8Ho9HeiTdiuuD6ApshU2XXlUHP0epTi9LB0BKVmsP/S+Wi9fFbDN3W4zVKMQByQOwTe0X4udFtAXcb083DroowhEazfJl/ui6a/tNGY0ua/SEPpcjdHWgLwM+wCEZ5wPGttgG9z01NKVEmFwwGsTG0tJv4YWMSbwaz3bACNwQLB5MiSjkHjWL6xj/atvklMPAzpX62tdhrHYqEzA1G9Cova97iwvRhEGh; 5:MKD/k2wSk+ZhJEt/A/t51nBE8R5loc4YTzZh2GJL5xR5f+YmPQmGdXcJWxaKFdXdMwL6TnWjRN7GPOo2GzTnZGC8gWOAI606Uloy66pi+saCKky5CHnMaqtidyQiqDLjqOG77rrgbuGce4cWNdPYE5hJVAzuTNnEs2v2PWBvOmGXegnCXBl046+aD9xHRsRD; 24:rMSIQXHS1DfjxUV0m5S/6dB3C3FgnNn3zKn7JMo60IJBk7a1bncUPVLwX+tKEAkt9PCts8EpvtM3IUAsTVXzRnnWUdpgoYRDWxAcJo9cfzg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2369; 7:5j3yXFKwuV8vrWf5m/bGhpp8/agjtyq+CcN19J+EYY5WvD+q8EJZVd0mWpWsJElNHVvj0EWYzH3pmimJtrw05nYklA8bsC4KfOT6X2Dgu4iuBpT6Yegr9YTnukj7nbCjJkPw5RiAn5hQOHjSoYK4QPpLQAiYVwjWMsZasjRfcOpR76oH2d0DZSkTxtXvQMy6kSosAD367Cqx6bdz8HQIhzHPJ/u8NxwQSRbCgT4JI98no8MA68bU+vBy73MaoXxo1e1jsnkPp8ZteRmOZjlkQ4PZZ0a+LiOq1mYTnLrA6qM/xke1T1LsX4WtXRdDy0YLhe4Yy5/ZG7UOP3FVgJOO3EAdPRaWB38boYFBUQ0ANFU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Oct 2016 11:59:50.3981 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB2369 Subject: [dpdk-dev] [PATCH v5 16/21] eal/soc: additional features for SoC 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: Mon, 24 Oct 2016 11:59:54 -0000 From: Jan Viktorin Additional features introduced: - Find kernel driver through sysfs bindings - Dummy implementation for mapping to kernel driver - DMA coherency value from sysfs - Numa node number from sysfs - Support for updating device during probe if already registered Signed-off-by: Jan Viktorin [Shreyansh: merge multiple patches into single set] Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_common_soc.c | 30 ++++++++ lib/librte_eal/common/eal_private.h | 23 ++++++ lib/librte_eal/common/include/rte_soc.h | 28 +++++++ lib/librte_eal/linuxapp/eal/eal_soc.c | 129 ++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) diff --git a/lib/librte_eal/common/eal_common_soc.c b/lib/librte_eal/common/eal_common_soc.c index 44f5559..29c38e0 100644 --- a/lib/librte_eal/common/eal_common_soc.c +++ b/lib/librte_eal/common/eal_common_soc.c @@ -114,6 +114,26 @@ rte_eal_soc_probe_one_driver(struct rte_soc_driver *drv, return ret; } + if (!dev->is_dma_coherent) { + if (!(drv->drv_flags & RTE_SOC_DRV_ACCEPT_NONCC)) { + RTE_LOG(DEBUG, EAL, + " device is not DMA coherent, skipping\n"); + return 1; + } + } + + if (drv->drv_flags & RTE_SOC_DRV_NEED_MAPPING) { + /* map resources */ + ret = rte_eal_soc_map_device(dev); + if (ret) + return ret; + } else if (drv->drv_flags & RTE_SOC_DRV_FORCE_UNBIND + && rte_eal_process_type() == RTE_PROC_PRIMARY) { + /* unbind */ + if (soc_unbind_kernel_driver(dev) < 0) + return -1; + } + dev->driver = drv; RTE_VERIFY(drv->probe != NULL); return drv->probe(drv, dev); @@ -166,6 +186,10 @@ rte_eal_soc_detach_dev(struct rte_soc_driver *drv, if (drv->remove && (drv->remove(dev) < 0)) return -1; /* negative value is an error */ + if (drv->drv_flags & RTE_SOC_DRV_NEED_MAPPING) + /* unmap resources for devices */ + rte_eal_soc_unmap_device(dev); + /* clear driver structure */ dev->driver = NULL; @@ -241,6 +265,12 @@ rte_eal_soc_probe_one(const struct rte_soc_addr *addr) if (addr == NULL) return -1; + /* update current SoC device in global list, kernel bindings might have + * changed since last time we looked at it. + */ + if (soc_update_device(addr) < 0) + goto err_return; + TAILQ_FOREACH(dev, &soc_device_list, next) { if (rte_eal_compare_soc_addr(&dev->addr, addr)) continue; diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index d810f9f..30c648d 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -159,6 +159,29 @@ int pci_update_device(const struct rte_pci_addr *addr); int pci_unbind_kernel_driver(struct rte_pci_device *dev); /** + * Update a soc device object by asking the kernel for the latest information. + * + * This function is private to EAL. + * + * @param addr + * The SoC address to look for + * @return + * - 0 on success. + * - negative on error. + */ +int soc_update_device(const struct rte_soc_addr *addr); + +/** + * Unbind kernel driver for this device + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int soc_unbind_kernel_driver(struct rte_soc_device *dev); + +/** * Map the PCI resource of a PCI device in virtual memory * * This function is private to EAL. diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h index a9b3129..3b8b03f 100644 --- a/lib/librte_eal/common/include/rte_soc.h +++ b/lib/librte_eal/common/include/rte_soc.h @@ -46,9 +46,11 @@ extern "C" { #include #include +#include #include #include #include +#include #include #include @@ -63,6 +65,14 @@ extern struct soc_device_list soc_device_list; TAILQ_HEAD(soc_driver_list, rte_soc_driver); /**< SoC drivers in D-linked Q. */ TAILQ_HEAD(soc_device_list, rte_soc_device); /**< SoC devices in D-linked Q. */ +#define SOC_MAX_RESOURCE 6 + +struct rte_soc_resource { + uint64_t phys_addr; + uint64_t len; + void *addr; +}; + struct rte_soc_id { union { const char *compatible; /**< OF compatible specification */ @@ -84,8 +94,12 @@ struct rte_soc_device { struct rte_device device; /**< Inherit code device */ struct rte_soc_addr addr; /**< SoC device Location */ struct rte_soc_id *id; /**< SoC device ID list */ + struct rte_soc_resource mem_resource[SOC_MAX_RESOURCE]; struct rte_intr_handle intr_handle; /**< Interrupt handle */ struct rte_soc_driver *driver; /**< Associated driver */ + int numa_node; /**< NUMA node connection */ + int is_dma_coherent; /**< DMA coherent device */ + enum rte_kernel_driver kdrv; /**< Kernel driver */ }; struct rte_soc_driver; @@ -139,6 +153,8 @@ struct rte_soc_driver { #define RTE_SOC_DRV_INTR_LSC 0x0008 /** Device driver supports detaching capability */ #define RTE_SOC_DRV_DETACHABLE 0x0010 +/** Device driver accepts DMA non-coherent devices */ +#define RTE_SOC_DRV_ACCEPT_NONCC 0x0020 /** * Utility function to write a SoC device name, this device name can later be @@ -256,6 +272,18 @@ int rte_eal_soc_probe_one(const struct rte_soc_addr *addr); int rte_eal_soc_detach(const struct rte_soc_addr *addr); /** + * Map SoC device resources into userspace. + * + * This is called by the EAL if (drv_flags & RTE_SOC_DRV_NEED_MAPPING). + */ +int rte_eal_soc_map_device(struct rte_soc_device *dev); + +/** + * Unmap the device resources. + */ +void rte_eal_soc_unmap_device(struct rte_soc_device *dev); + +/** * Dump discovered SoC devices. * * @param f diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c b/lib/librte_eal/linuxapp/eal/eal_soc.c index d8dfe97..95f7565 100644 --- a/lib/librte_eal/linuxapp/eal/eal_soc.c +++ b/lib/librte_eal/linuxapp/eal/eal_soc.c @@ -63,6 +63,45 @@ soc_get_sysfs_path(void) return path; } +int +soc_unbind_kernel_driver(struct rte_soc_device *dev) +{ + char devpath[PATH_MAX]; + + snprintf(devpath, sizeof(devpath), "%s/%s", + soc_get_sysfs_path(), dev->addr.name); + + return rte_eal_unbind_kernel_driver(devpath, dev->addr.name); +} + +int +rte_eal_soc_map_device(struct rte_soc_device *dev) +{ + int ret = -1; + + /* try mapping the NIC resources using VFIO if it exists */ + switch (dev->kdrv) { + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + ret = 1; + break; + } + + return ret; +} + +void +rte_eal_soc_unmap_device(struct rte_soc_device *dev) +{ + switch (dev->kdrv) { + default: + RTE_LOG(DEBUG, EAL, + " Not managed by a supported kernel driver, skipped\n"); + break; + } +} + static char * dev_read_uevent(const char *dirname) { @@ -260,6 +299,68 @@ dev_content_free(struct rte_soc_device *dev) } } +static int +dev_setup_associated_driver(struct rte_soc_device *dev, const char *dirname) +{ + char filename[PATH_MAX]; + char driver[PATH_MAX]; + int ret; + + /* parse driver */ + snprintf(filename, sizeof(filename), "%s/driver", dirname); + ret = rte_eal_get_kernel_driver_by_path(filename, driver); + if (ret < 0) { + RTE_LOG(ERR, EAL, "Fail to get kernel driver for %s\n", + dirname); + return 1; + } + + if (!ret) + dev->kdrv = RTE_KDRV_UNKNOWN; + else + dev->kdrv = RTE_KDRV_NONE; + + return 0; +} + +static int +dev_setup_numa_node(struct rte_soc_device *dev, const char *dirname) +{ + char filename[PATH_MAX]; + + /* if no NUMA support, set default to 0 */ + unsigned long tmp = 0; + int ret = 0; + + /* get numa node */ + snprintf(filename, sizeof(filename), "%s/numa_node", dirname); + + if (eal_parse_sysfs_value(filename, &tmp) < 0) + ret = 1; + + dev->numa_node = tmp; + return ret; +} + +static int +dev_detect_is_coherent(struct rte_soc_device *dev) +{ + char filename[PATH_MAX]; + FILE *f; + + if (dev->addr.fdt_path == NULL) + return 0; /* no way to detect */ + + snprintf(filename, sizeof(filename), "%s%s/dma-coherent", + "/proc/device-tree", dev->addr.fdt_path); + f = fopen(filename, "r"); + if (f == NULL) + return 0; + + fclose(f); + return 1; +} + /** * Scan one SoC sysfs entry, and fill the devices list from it. * We require to have the uevent file with records: OF_FULLNAME and @@ -299,6 +400,18 @@ soc_scan_one(const char *dirname, const char *name) goto fail; free(uevent); /* not needed anymore */ + ret = dev_setup_associated_driver(dev, dirname); + if (ret) + goto fail; + + ret = dev_setup_numa_node(dev, dirname); + if (ret < 0) + goto fail; + + dev->is_dma_coherent = dev_detect_is_coherent(dev); + RTE_LOG(DEBUG, EAL, " DMA %s\n", + dev->is_dma_coherent ? "coherent" : "non-coherent"); + /* device is valid, add in list (sorted) */ if (TAILQ_EMPTY(&soc_device_list)) { TAILQ_INSERT_TAIL(&soc_device_list, dev, next); @@ -313,6 +426,11 @@ soc_scan_one(const char *dirname, const char *name) if (ret < 0) { TAILQ_INSERT_BEFORE(dev2, dev, next); } else { /* already registered */ + dev2->kdrv = dev->kdrv; + dev2->is_dma_coherent = dev->is_dma_coherent; + memmove(dev2->mem_resource, dev->mem_resource, + sizeof(dev->mem_resource)); + dev_content_free(dev2); dev2->addr.fdt_path = dev->addr.fdt_path; dev2->id = dev->id; @@ -333,6 +451,17 @@ fail: } int +soc_update_device(const struct rte_soc_addr *addr) +{ + char filename[PATH_MAX]; + + snprintf(filename, sizeof(filename), "%s/%s", + soc_get_sysfs_path(), addr->name); + + return soc_scan_one(filename, addr->name); +} + +int rte_eal_soc_scan_platform_bus(void) { struct dirent *e; -- 2.7.4