From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0046.outbound.protection.outlook.com [104.47.41.46]) by dpdk.org (Postfix) with ESMTP id 6D983BB68 for ; Thu, 27 Oct 2016 17:18:05 +0200 (CEST) Received: from BN6PR03CA0011.namprd03.prod.outlook.com (10.168.230.149) by CY1PR0301MB1628.namprd03.prod.outlook.com (10.162.166.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Thu, 27 Oct 2016 15:18:04 +0000 Received: from BN1AFFO11FD049.protection.gbl (2a01:111:f400:7c10::194) by BN6PR03CA0011.outlook.office365.com (2603:10b6:404:23::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.16 via Frontend Transport; Thu, 27 Oct 2016 15:18:04 +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 BN1AFFO11FD049.mail.protection.outlook.com (10.58.53.64) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.679.5 via Frontend Transport; Thu, 27 Oct 2016 15:18:04 +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 u9RFGIfk027183; Thu, 27 Oct 2016 08:18:01 -0700 From: Shreyansh Jain To: Date: Thu, 27 Oct 2016 20:47:42 +0530 Message-ID: <1477581467-12588-17-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> References: <1477310380-17944-1-git-send-email-shreyansh.jain@nxp.com> <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131220550844444155; (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)(1109001)(1110001)(339900001)(189002)(199003)(33646002)(36756003)(8936002)(2950100002)(626004)(19580405001)(19580395003)(11100500001)(5003940100001)(586003)(50226002)(92566002)(6916009)(110136003)(68736007)(2351001)(229853001)(2906002)(105606002)(7846002)(87936001)(85426001)(106466001)(305945005)(47776003)(50466002)(77096005)(81156014)(81166006)(189998001)(48376002)(76176999)(356003)(50986999)(104016004)(8676002)(6666003)(86362001)(8666005)(4326007)(5660300001)(97736004)(7059030)(403724002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB1628; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD049; 1:vF9w45Xd3Qv+fgItqRDFnqlCYPly3MClLTQLq6OZqA3msm466BOLJv7JxQf2xHKbK9Hw7UR6BUEDaQjwrt3ccScY6bNYcZjHhW4V9rngb9dpC/664zeJTzp5m9EbY/JZBboh/S49oDBey2c3phRkjGS1IRN+3uTQs7ovS9PA1j8jpl8l+JUOoPI+Co5kzlCAqXw4I7VNn7CHd+TQmX27d9npu56c75xARG+Jblw8f0HIHSdzQKGArmdiUf/26N9USagBkFaaPIi8u5zZ5Fy+kNl6qYZmJZZD1FPFYqdCyzuvrjPlBHQ36nwL6mcGQyV3U5zh3shaW6WQ3OUbh+6OE/ODc/oUWbEoAQJLXV3xZAY6AB4PNdvWXpQfAtfzVX7a7UWonmDfPWPl9p3bWLsixkvoUW7462OgZhNeHzrby0i8qvXOSdcqv7gCQNasjxYkyiQMdOYIIkr7FbEa5yJ32HYL4ebNuwOxlT1nnV1GDeKR4Zo6bZ52BeM56TBjY29UZaI74xf+tBFiptB13qBKMU5GYqsZLCrgdQPQwgvOPRcl5LwUNKnkCDlcxYtVI2YFBWOFKJnle4wUqfoB9cFuxdrXE4lI9unv/+j+5s+xFbuZI4njDz4Yx0UPTDBBAAE0LWgPbV6fHJ1bfDyYOewsYSp2E+7X9tqH/cmLpU9H8In9zbHLDtrJqSOlxp2yHs9y7mMNafjyXzw2BOZNeNjNDUEnbPXpdGIwvqZj/yRc8WU= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 7895771a-1c2a-4fa6-01ad-08d3fe7c72b2 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1628; 2:6+WmFvwBSca/oyg5uNJv+SfBYNOgKXmxDuHaJQFOJDrjgOUURZOU2NHkuC94AnYx/vYBZ6HJLufNaM21twWPHL2+s4WBOUrs6YzZavi6Pz9d5UN3D0QyBzJ2M8dQ6xBwuaLMrXuFiwmDih5N0ZNN8bifqFZ4r6pTHvZjXjOZDtJi09XjE2g3vRMqM4y9VBnidJA4L3tcrByOgQBAip9JqQ==; 3:uNZ23PZw7YH/VS+j1oY0QrA2hHuGf1mD3GTcw+ufWRiU/fxOWnfmjBCpcfwZdWCo4QwRIHv8N3SRQKvxmzN+94ryQ5maDyqNwnbt98gyGr3DA7vbEyIoEqMLpKa8RdaSegQ2zUhbVP2DR/y+/uoPwT2vJbDReaXfGMKlRuY9P1YFre8nTzfKR5ngw5rkmINPZM9z5epQVHm3h/MmqvEPnajd4LXWKfNDfK4Hesv/ia28RbL5gAJfN3onIENqOo6v X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1628; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1628; 25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7pz29/VxHmw/RCSyIHVY8N7tokLbjkf0VWyTj2PKJlP3zwetby61PD3QpuWKcOlVNxRDzZth2wSbVLAcDlg=; 4:JAKuiulbjnGAJFZW6D4dDL0H6NBwLr3GzP3gODFSDLBFu/z6wSu7de0PQjNNhNmhzeBAfGRhzZHbtWT7PNHE0ng+h2HjRPCSdf9yr2LnJ0fuPvNh7THPu7A+G/OZdPRJS+J6tNMebbodHrwb2uNPmG+1SYVAFObjJLEj8izYhGtfsZLDMG0e4BMh00jYGfS/CB/AjoxCAnnRnPg8VKiRb7WEAAlGN6CTEzcMHGpC+LGmfxOsN4uMwFXfeAI7UecYRyXl3up3NNcXKR0sSHFDtvts6uS0Y3QLRUa7RmTZQA/WqllXGaXv8jnHhM8vGLt3meDkrP+IZADPlYq8pYZLfZoDTbXgqm/cQqH9pG3WjUeYJ1/dAhMec6DeiIEBbXxC8DG/kKpqtJBeihruSl0bSYWx1OCbasvpweEIugVqdFQ7o1XMRQnTzGwJ7qtLsTNGCMRbQSafIq/z/bYTxsu+U6wIjlaSq9uRudmvNrtyzdX08EywnAMncNUAuwYAGStam2VdzZl2sMDqzVwzK8M2gfRfdaMVhbvXDw1mzZjPROPwv7BnTZc7+5pzkLEeaZa5 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)(13018025)(13024025)(13023025)(13015025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:CY1PR0301MB1628; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB1628; X-Forefront-PRVS: 0108A997B2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB1628; 23:kgC/tHeRUO3vQICkN6jR6oy1B8b237LP/49cRHV?= =?us-ascii?Q?wgP5EfFggDo9Oeqzv7U4+EpLUSYyE0q10b20hgsmKUOFzCHuGuyzeUXasJfT?= =?us-asc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A+brJf31T0WeD?= =?us-ascii?Q?2+13NsEt83Ga65EXI1d//1Pb13RXLDTU+f61avplWZ23ijoRKIoNwueGdGpG?= =?us-ascii?Q?PF9U2ZGNWQXoQjGXPKve019QIICuGF6zZ5HdiiH7nPAYjij9X/rUe1wbNIZB?= =?us-ascii?Q?UsH2Cy0pjJX2BD0Goxf6XnkL4dXv4LyrUphSkchMSKo/NhUGNx0GFeNTbeWA?= =?us-ascii?Q?jqvPYE3qTDx1rEqXQrtorzV5Jq97Maqgdq6YKx9yZIlLQmCbJKcEMP2+bXQ?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1628; 6:fpaFiPfthiApUIwIL9qeRf6jv4P1DNuasBmeUEsmIfQQSLgeVkfiMbZ9hSBpwWKQn6hLasO/nMHy31rVfe7HYnEtvnLg+lOBiZ9fySOyyiuMtkvva24H3dnymgbOydp1yebc0Y1qPd4f1kuWxDj7SDFdQPhzit2mQaaTokN6RCVHQQNg1cLBB5xeQtHO7u3gbYbY/ycOkWSIOHhLZ1PJ+s3Dq7ZYJSONAJiOF9BXHqsbj/GZuhrcSyZzjUQjcTtyCgX385Q497+XOs1jPTYA8U0mq1QR67sSq1935DHwfZ4yXyf+OWbKLKKjwFFPw19a; 5:WjAER3anf2uoy5JYjPpNLF7sEvM34iJ1zaiqtbYhJvJ2NCeSboJ2uDHWGkmOF9wn+xQUxqkg+6mSlkjwItKfzFl5GdHdDR814Meocwy5JClMHVdvl/JaOBu2Js/pVDpInxleyTF3JgiQR5IhURMhafGDEKkAPXap73jFTYLVUSAhmunj9coj03DyF2HSRdKd; 24:e2jWPWtgQ2MBwmx0fiABCscR7t+HBGYmUYMoHjgKoCx67rC9TtPnza0iMaP6+VSKsEJf1+3fYTNGUEl+2nl9bidJmWSMDPk9OzgvRsaFoDQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1628; 7:z1wcEPMytPiLVlmz4KmaHTSWSY0ijvLjKGE4IlsNE208cpzih04w1NhN4y1+VP2MJirBTLkvmgV4+nF11YCCLsEv1oeAF4UCjigL2sGpZYh90IsVDb8+zkpFID4gAb9CpcTqP/+2awvJN979V2AiLDZJmHcMaF51XnarswoSe6+vGbM+8IS7LTq3xP+jHOMZ+tg+muy7KVHimjhJGQwbnU7903gji9SsrGKNsUvJCZf60KgqTsRRJGOwFZYLBITmtoT+6LRXvKMrq7kMHpkw2Q/4vu5FCi1tpNav4jJ24iuuwSgx1zYXgnCBae2O+WgcFsAW7SOt8tsshFukwK3P3KsbJa0yfNauhRo/7KO3rI8= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2016 15:18:04.1324 (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: CY1PR0301MB1628 Cc: Shreyansh Jain , thomas.monjalon@6wind.com, viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v6 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: Thu, 27 Oct 2016 15:18:06 -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 8be3db7..d7f7ec8 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