From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0083.outbound.protection.outlook.com [104.47.38.83]) by dpdk.org (Postfix) with ESMTP id 2BC328D85 for ; Sat, 15 Oct 2016 15:44:58 +0200 (CEST) Received: from DM5PR03CA0021.namprd03.prod.outlook.com (10.175.104.31) by BN3PR03MB1414.namprd03.prod.outlook.com (10.163.34.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.16; Sat, 15 Oct 2016 13:44:56 +0000 Received: from BN1BFFO11FD001.protection.gbl (2a01:111:f400:7c10::1:130) by DM5PR03CA0021.outlook.office365.com (2603:10b6:3:118::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.5 via Frontend Transport; Sat, 15 Oct 2016 13:44:50 +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 BN1BFFO11FD001.mail.protection.outlook.com (10.58.144.64) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.669.7 via Frontend Transport; Sat, 15 Oct 2016 13:44:49 +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 u9FDhhgS021870; Sat, 15 Oct 2016 06:44:46 -0700 From: Shreyansh Jain To: CC: , , , Shreyansh Jain Date: Sat, 15 Oct 2016 19:15:03 +0530 Message-ID: <1476539108-13170-13-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476539108-13170-1-git-send-email-shreyansh.jain@nxp.com> References: <1473410639-10367-1-git-send-email-shreyansh.jain@nxp.com> <1476539108-13170-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131210126898700114; (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)(110136003)(626004)(5003940100001)(5660300001)(68736007)(85426001)(2351001)(92566002)(229853001)(48376002)(47776003)(50466002)(106466001)(356003)(8666005)(104016004)(19580405001)(33646002)(2950100002)(6916009)(4326007)(76176999)(6666003)(305945005)(50986999)(2906002)(87936001)(19580395003)(586003)(36756003)(86362001)(81156014)(8936002)(8676002)(7846002)(81166006)(189998001)(97736004)(105606002)(77096005)(50226002)(7059030)(403724002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB1414; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD001; 1:iAveyjW5gVOGHKIDDLPDXgkRT9lac+3WZ0YaY/cDH6XzTA6E5bUZbO1qHD+6OyuqSoMsKumz2BH4A5Sh2b1fD7a1bIFyKVXZI1Ja88IvysYtXe4CD2acoih6/cW9RvPZdamNGvCSYM1/Ppqrs38FxFiqYGkacK6J7n4aJatgnGyJSCrz+qx3yH/Fui9+mmaiI4lL3SveQUwjc6hJrb8elkysfa1ISaEOjwOTxhQGP1jEmlmcFn1wiLIouls2jRbvx5fyk5Y2GOCeHTMJ3UQAxX5es/2bTvgSsPmZWmgnbolrqw4gLIoQn/KiGllX51tG/nhfb6R+0v/7GtXJ7TgI+VSrAwHhjd5J28j4JlnHIL9MaYedUgOAp2CqNCyto0tLr9a0b3jL6ptsDg+tn3ve6FYs4PFFT5pV+0AhwMDjW/RXI6zm2hlCIu2dAqccyIYpbeoNzIft8NhTK0MGjA7YCTtgFft/FxPJAeNhN4WdvnjfjBt4lBO1xJFg5Uf5DQgPtphMJvmYAljX3iYlAvT3o0dVtfvGbsdx+Wi3mPUPl5TkDHOq87hCiWPQH8ISSAqQuugg0VzrL8NltEzCEH9TX5ROw1UI94c5m7H1Owfp+zltItxH0NQ7JoK4MFk2zl1w1pVlZQWVCC6BzIehZxzOAnyhilm7siSE03rVmCgyjbLs8yOqYyy9geZj7KIy2c8PAATItMQ0+5uzg2Zf7FseeVL0LkH26crRauQF6qDDX6M= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 9adfe0b6-872f-4300-1452-08d3f5016f1f X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1414; 2:i4s6EcLKNGxnGAqWEC54F0eO8KhxwYTXP8W1oXMircxmO28CsAOxo+V175I68WR2HuEXdBwRADwns7nPuJTkV68lI7yLubZ+v2PoFw/Hk2q2qttJ1bVLWGx0PSiIBrbbADPWJOauS4JcnEfg/sYm6JDvXGZHSRf2e9RegMA0g9ph7JIgg+aSkAAQvHW4JqzDzGB0dNs4kGe4d0pbbnRMLQ==; 3:qESl/EFvDnCtKfUbYdsP6dHYVEq50sZgiH5i1EjigyY/Q1oHxZsWJTD3XICLYySmsoPenyBrofY1MUDqfbu8v8nKRxxyc3EAuTVY/OpGKD5RXeIN9rZYe3iJI9zrikzA4XEzWRY5RB93Bi4ozGWl09G72qocTSYHeOa9yzwK0Tc+UXlTVqNf5g9OU2rnJ3L9JXGtxzpR9nxxpbiT5dUSuWghK4rZkSzBwywmqIy9d/bBBocBjK/pJ6t3J5ogtoad X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1414; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1414; 25:A0G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joHGFJlZamXzEDyALvIh3Lv6d1VWKgaKjgL/ar2rD3kfY0bvMlg==; 4:342Bo/Z/SNHbWuNbMUI4KbDQvly0cEMxfomX+mL4UqfeJ05wfbecyWXNAQzaQnBP1HJPtcP8EHZjs7jr8c9Mnel2N33B4OVWeGMKK4nDI9VzAFfopDObhlYMNu8ZukFwhyCt7yrGCpy9qKkxChlMk/JZflDv8AF7w2HQyJgbONpuHt6jYgUrfdeVzdEUH5ZQ//Ksk08Tk1BHGOTGdDaN6kQ/94OXL0zZBxuFMbmcfCJrSezPqOTr73k9Hr/IcF3ct0Bl9F8c5CJXaFD+4x5z8g9ZZDxqDika9o/bQM2pSjGhqsfZdDK97UzJxLZysCd7Q0qqrmrQdlvVVm+86Fo78Xxi4iWDoTlQ30eHnCsi6EjTo1fnm532gVfkxw4XSt2I8cPp4EQq4r7J2GsIdMfT6zwi0h++XhFO3PDQBbLI8GyJJZIacv59S1mYVxZFhckvHdJHbdVE0lfYpm3IyksG0+M/rIiZey38Q0md3aJBHKS0C1fVP6DFoeELaRh/Gof/JhRElJroAd1M8rHlkZDrpw4ENS4ET1T56EKoziIeGX5PLck0pMcOw2eIPGoYqqzo 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)(13017025)(5005006)(13018025)(13024025)(13015025)(13023025)(8121501046)(3002001)(10201501046)(6055026); SRVR:BN3PR03MB1414; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR03MB1414; X-Forefront-PRVS: 00963989E5 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB1414; 23:noWPq17jE0VlJP2h8RA6Hv7bwxSDSEXI/p7OaGXpp?= =?us-ascii?Q?sHhPqoWKKoZAmmMdoWwU3YbyKefciwPTScPbkmhsKLhkIFK7aN9rZp3q49+P?= =?us-ascii?Q?F03Np+6I3moUNv7d4YCIH1NUF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Q?0XB5mamxq8f0s2Kz1phUk5TvyDXKrwwDH3qRj8UjCiNsEjb/sH5cBXE4XEn6?= =?us-ascii?Q?gAGgWNPr6HE1m0qSTbXEp6vEh7U4fSmYy2cWCVo4KATjtxLAex2U+AMxFlDw?= =?us-ascii?Q?i/F8tdlGlRldAbeer4UAkpBvWnbb4VfhEswrf/Xw60F03agRdKpyryZvjjUM?= =?us-ascii?Q?8DmlBme8x1Gd+oR8J7SpmtPiQtPTR45TD4R?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1414; 6:tp3YBERFo3b7Bs1SuelqG9a3p9MNSSVHJs0wcrQImDw+8ExKaJVgtW3acyZtHi5rAIGIgG9hJwfivKaRuwY/hU5lCj1eQKKvuQ4w4GS5OlRzQbNdVEo5Qv50hMvkIgRIeNwhwMEMRw79meekxskL9tUKI4JIoaztIG8nSM6AKJXXE9VmFfA0rpZqWg9TQ4tcm61sQseVCDY0HyKyMTiJqqGxW3KUOJEtLFpgZ2XoTSsvXkmsHzLagm0dcwkaqip9flFrlKWD5zK02vEZugAQqBmilU3HRRErfZ604VtEag31562kbs8vAu+kw/wHhfck; 5:yFil8SNY7ofzV8f4zC/Xe0Vob90VupREVQXOS2sRZwrKdG8WuJ/TvIELZdyZMcaoLZX4cHpG1iL6Gq1MoWmF3TmBfSzWYKC6Nb+G2vej7xYXujVieZHttjIeKY5BvRHAR0RsXu8fpsSmvrn55FQA4I+E3fJRrBFB1p7tCASFkLGPY48wPG+8Ya5LG0OiLkJF; 24:gtZgTCXqvY5/+HAajdPYVKfhksA6/aVnn8GARq76SbTuavwLSRf5mq/IeUr9ToSqKF57W/B4I0IqDzybdJ2IjbH1Rm/sw0kfkpF8PhUMPLs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1414; 7:tMalK0n53FL1AmGlacVhBa4fzpU+Za7pDOS8x8Hz2lrQO1fXnedHnnwa7RWXuDQIqAmSzHtqXoTH8uKcsBXdAqPnVEaeXa615MMb05hqR730qACvGHOlr3TwwUW9nPgvXPPOKOBa+pSJSYa0DBJZ1kYv0mHsjasxD3iekLsxTU+uvR9/nfXQ1MEngDNkMdyCNXkqzsZaMdDdZh+9KeKnsW1ysCkQU0SCiu9b0i6gOe0zPX5VEjC8RDRhmRzNT7pyb/KTSDbbRwQ3hxMjn+3gVuooN9Vz6lhEHRcsIQ2aSsGoWOujuTflaK3GaiRPb2AHvLRJ0R1c/cn1mqWq1ZxUqcYsRFnjJ9MW3jU2AL6ua2Q= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2016 13:44:49.5580 (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: BN3PR03MB1414 Subject: [dpdk-dev] [PATCH v4 12/17] 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: Sat, 15 Oct 2016 13:44:59 -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 1865be5..93205c9 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 @@ -252,6 +268,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 d8286bb..d07bb40 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(void) { struct dirent *e; -- 2.7.4