From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0047.outbound.protection.outlook.com [104.47.33.47]) by dpdk.org (Postfix) with ESMTP id EC74BBB29 for ; Thu, 27 Oct 2016 17:18:02 +0200 (CEST) Received: from CY1PR03CA0002.namprd03.prod.outlook.com (10.174.128.12) by SN2PR03MB2382.namprd03.prod.outlook.com (10.166.210.149) 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:02 +0000 Received: from BY2FFO11FD032.protection.gbl (2a01:111:f400:7c0c::109) by CY1PR03CA0002.outlook.office365.com (2603:10b6:600::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12 via Frontend Transport; Thu, 27 Oct 2016 15:18:01 +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 BY2FFO11FD032.mail.protection.outlook.com (10.1.14.210) 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:01 +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 u9RFGIfj027183; Thu, 27 Oct 2016 08:17:58 -0700 From: Shreyansh Jain To: Date: Thu, 27 Oct 2016 20:47:41 +0530 Message-ID: <1477581467-12588-16-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: 131220550816811059; (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)(189002)(199003)(36756003)(47776003)(104016004)(6666003)(33646002)(4326007)(5003940100001)(2906002)(97736004)(86362001)(68736007)(48376002)(586003)(626004)(19580395003)(19580405001)(76176999)(8936002)(6916009)(5660300001)(110136003)(87936001)(77096005)(11100500001)(85426001)(189998001)(81156014)(50986999)(2950100002)(81166006)(50466002)(105606002)(356003)(92566002)(106466001)(8666005)(50226002)(229853001)(2351001)(305945005)(7846002)(8676002)(7059030)(403724002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR03MB2382; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD032; 1:SOLwWwZVA1xRMkYU+M74xFXV2Zxw7rSVoH4g8VptOkVX2vOR5fM81QAw7PRdz0p+lmLoQgI1yFERbd51WeSU3xDdT5IqhLlqx8HUS4v+zO9tv/eS6E1i8RKMgKLpsfA33rXGAB3UEHyMZWMtvdCeUzMtUvjejH33akxemdaYl0SUmPcWQNYJ5UFspBIrmaikbarPWmm30eOa3ekcQJhWHbm2dKsQg38Jo8TwjPSXUVp5YlUStv+0bMSohUl+56MO2crOhyacWFL7QZyDcDgeNJ87oL5Ds9DYvESrCPGGBJsj9IczFf3ggA601ohA/8B12101UHMMN3SI6jC2u677gkf6zWzX1W9M3dTDUSxByxk/6C7Gn/fwQBtuREmRhjlW3rTGs2r6EXWegbeyzrIcFGyWiokMMerqAySKkzP3jXIWFpEoAfxY/D1P2bahyT6Tq+2kySMCBr5vh1t873NdEhl9mLYrBa89G46vtmI4NlfKMBzXGgGCMouJIggt/roKyprIRoFb4HwIwQ8yyv6yyPqQL+8WcsvbDeqEL50Q7h7IkCquHuPx3hdD/ceRCdINTuLMnerlhn/2xmSxipJgVP3J4KDuNUbKzDtAVGDTDUWzE5vHJbYwC5UhgM/nQQo1SeEX+5jlGgxuocN30ls7AK5o00MCnqjkDxWmNpC8RjJatWIZCAXvygr+pPrM8qZXCY9T8sysYcDBwyoQSVT6blGXk3rnkNQ1F9vXdM6Ecvk= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: d101958b-c778-47cb-c833-08d3fe7c7121 X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2382; 2:gcnbS/D9KI7DV3H6/R7GCapiYW4KFcZL6NO08z9KuIaU/cHZ/oBx0xgenh5gk2I7Xv0qOnLb2gEUGIGMv1IQinMPG0zJ6BXf5sgQ/NTnAzGrkC40cKF2Y13H2h8UgoBwT3OopV71TuUM6Qah5JL5j0bN3tAMWtvvqS8DTGtgtrmUzxIK0LD89Lj3kOtxP/B6JOKy0tE7XbAcU65JirsSYw==; 3:DJVYD9aIduBYt03Mth1qmWXAXyWrxGkfMuf0lB1OQrkSigR3e1WDYxiqg2nSQfZH1m5D7UGSyPY84FOEias2OAb4h0E7iV8eYKJdRXMzKpthbQlNkE9AI0Nfd1DaL3d4tYISKJfU+5qdDKSQQrKEEkG1yE4J7PhmL5NtSDojFRb0poXjtpoyX1TiHw1kHL2jYeX8d8fyl2oiza0+OR4gMGmI7k7lWP1m/3pJB9gEh6bwFMvQ2F/99TwtFRpS4P53; 25:pGx0c8/OxSXibs1rWFqp0vW8DW1VLLTJ/xuoyZ+C9iNSN5FeE9wqjBLmtJkZP9EFruCImxbJpKtqt5Xs1Cqcdxy6wScGkgA6JY+JdBrGEpMMn7V6DLHpBzNrBbrcm2jqYSHJ7EGy3q2XwmfPzJBwct6QLpK1gdhkNyEfVq4QnYEkQPZPo24CcMjLZpckZobPod5W2B82zdwPaoLY05qamGaWY+MFJyUFvyAOIoPGhH6alw6YTsnXelxU5HPQZumYyfEMUDojGUXkLQmRFBVVJQvQy+Cf7qDKc3b7pzeZPi8DXTrpkG9pSrxV/dMeezCrdirs2wQCwqPCjJqMk24eLZhle6KQ86MIoiS7KWBMadyUViI+jbQzdQr6DJvkWPkIeaPU2U5wfUIbZ901mm4uWli5MVx7ZN8MKCEdaW0RarIfNAtZiPwYFS5zvNCHzmRckB5kH5rcwjRtg7moczgarA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR03MB2382; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2382; 31:gfoHgbM96Mv0wJA5D7FDYvbh4IIp6+Q75nS253I4eatlLEE28+8+wM9JwDJ29OMwtHEjWQusoUFWS4xfJpldoSM5VzxoHuuJZ62Lq8xy6BuvxAQLCNAiQkqEKAG7IGZmaupvM4aGdk94v9src8FVL5SbzJJTt+pprb8BcL/bxOWJYZLNILnbODewv7nlUNMivpYl68ir23H6fxuewc3wc6K052gLJxVReN5s2T216wPsPY6oIrentEgj39iQvLp34T1ZL0aDGNEs3VSDpUlGZg==; 4:7dFzec9dMiae6do8Q9lSKBVs8hnPWFR//2w4HX6z6fkctZ/dZwI0FkaN/3RgfF8WpmXvGG6tW892U6o6XWbDAZvq3A81sK8UafFgbI3FzMVx0rKy/vT+HkEuLoLsbw8WdJefeHodP4DgsLDeVV7VGapXfwTLfjuxhcYis1D8me0UPIiwUbuQbxCxds0nN/QtKkbDb25SlxDrpjL3hkp9AnCmLclKQOyrBgfBrf60S3whNoLC7IJ46R0QdZZmrGAXAIRoxdiaD8VBWdxRRRP7cRxZwyRCm0EYY1qKir/vTrYcmtViLGMMwDveJj5OmkzLlMYL3pO2n6mYdzFzPs7YQcpijknKRh6wNnDNFCk6vwuVkGOzLrQzHQ1AoY25V0E5AbiX1KXQE328+MpJo9BXkfEyTpNO3gBmgGNmjJcdxdcZWng4NEPcJ4tEG/NAEugIjp/fQl+lzEhCDCH0BAdue3y6ykdVm47YNksEROznKEO9J52LGv2ZTqls2+84E0TBMoqtRypuxrrsyyrIW7vy8rvW0lBCBB+lWmZs7g//NI9VcHPdR9H5r+rnuR4/ewKL 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)(13015025)(13018025)(13024025)(5005006)(8121501046)(13023025)(3002001)(10201501046)(6055026); SRVR:SN2PR03MB2382; BCL:0; PCL:0; RULEID:(400006); SRVR:SN2PR03MB2382; X-Forefront-PRVS: 0108A997B2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB2382; 23:o8a69iUUL5IVljdGQrsxNLS71lcxaTV6p2esNF8jm?= =?us-ascii?Q?Nu15zygLzSk6mI9yMFK3kjYG1biYl6FvfvzQsV8YsqF8UPPzrGtDsdf4IsY4?= =?us-ascii?Q?Olvbc2HeYhF9n6QxpzvGuFsjE7whe0OuKoF1h5xy4HlP+50PIGRkj+kDcS+e?= =?us-ascii?Q?2IfGmgvXymHxYNllIKPLJjAuoQBm8rG77fDgO4FOS+m1HkAZPJwBKFX/IxPM?= =?us-ascii?Q?AIHrFIulPXE0QHqkARF+qhwvNPtcpg0iVIdhnEhjksZofPHmpFN2aty+9LKi?= =?us-ascii?Q?r3PKgoZmRWuzN2RFDTLsMEpBQEBw7Tm2NQ1/gxsHCLn+R+bVcY5hnA6gowXG?= =?us-ascii?Q?TMK+RyaLWYlEM1p0/yxHzl7Hy+XP7/LqWZNrYwbOHsvIs8NvbadLVARybYJ9?= =?us-ascii?Q?ipCQmWxceRDgIdJTJGI2DHLNsrI9FngyYDviWo6e3obwyv8kWPxbrb9MoEjE?= =?us-ascii?Q?hOgS8TkkAq2KB65OAoSPySgEibXt40cxSRva+JL4X69hjvl860ZgBf18Yl0v?= =?us-ascii?Q?s8uoFowNJXCU8NFunP8jMiCoHEQu6EgccdW5xrmMlpa0nJ9xUF2fQGkoY2uG?= =?us-ascii?Q?trAiF01eCfIFc2X51F2ACJ06d8tnddXddVqLVMI0PVb0ps4HNgMeEGElTyBc?= =?us-ascii?Q?uFqfD1h4nVwr6fPEm+nICiPnfcTlbWoMq/WYLi5WQmJapY68V2WdtFc93kjn?= =?us-ascii?Q?B0E4gPc56ZKO33yH6YiNuGxRW7fShNf6rNijMseGWtIi5GKKZJonQ7tKJW+W?= =?us-ascii?Q?gMtUtF2yOOJ41qFDkbWnGxEA3eOOEENtVs42GtHk3ouJPv+2/xA4VGlt7jBL?= =?us-ascii?Q?pov6VhMldTXeKVjRcojvEgc0QZ1ppjxfNCEg61C9UYL2d+23N5kMhNonU5AJ?= =?us-ascii?Q?kLebscwFRMErJtMH7BlaXV/bcZE2qX4wgA2zN6AGLPBjvaMP6uUDA/wym09I?= =?us-ascii?Q?+cViVIvVE1OjDl1WN5rJlXw9zlbCFnnH0wmH4RXE6tU9KDw+zcrCsP8H5eQm?= =?us-ascii?Q?nvuXZridQ+U3jW9dLT256+qgHNufRgJTkmDloHJtnVrcld6X41dWiyxy45wg?= =?us-ascii?Q?3KUuvPO1dgE7MwHupfhMyW8qm3wjwsf1nrknruXe6AMat6FJXgCVkGDXN0qq?= =?us-ascii?Q?j9G9/MaQw2jhZ5V4ppMeKA1p7xdRQragDkeCNnEH1OkTgAEJ+AJV7g6q0RLA?= =?us-ascii?Q?nRS+L4EVZch8rHXxjaxx9WXO9xww1rxVTpS8hMBw5zDY2fKIGy7abxf3Q=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2382; 6:DDmipa6JQkDeXH2k99gR5nA3D5qEfh9ohQfYuq74Iunqs/NYC0K2jWDmcDlrN273idZYtes5z3FCfpY7CiaIfVLrf6hdcRN3QE0GHvkgaY41/ZsBHifFSHs8R0A39PlXGofOXbPmXwDarMn8Wqp8eC5DU7zNUdc2e2OTOWaZaE23IuCQdU9NTjfxELGtGH+ppz+wT2ZX2SJUQEv+0gCgSK35fJqHmv2T+7m1iZco86mRfDhjuv78tvMvDlfE6316iA4xJaW93qb1/wWuZgMz/ywqBPLt7vG7Ye5b9f3Wmtkbb1jE8XQgYAAD1FtOItS/; 5:G2IVDIoJR9eeHsTaSKJCzIrUGfRmOKkhLg7bjge601X3Z9hjWB48nS9/dfQbM44T44jFjOpzhzU8S2cRibnnyg424KVleKdAvy1TZ3d/7xGLfNCx0JZ1Hv1PBAm1p8d0eFmX56z1ASS61kCZf3hVqTF8Z8mYgjse7Sul1Oa/sf8pr3FiQhijKfzA0vcr+9nk; 24:qj+DB7ae0TvYtt8qMA3zG34rTznhSCeu38tRDBMFxB/fH87DmbMPJWHxlAT175+lPJLwovdHdFapmByHMkhYqEpyg30WRk716yWQ8pwjcKY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2382; 7:tWUjO8FgflBT/McYksNwAKnQn831oRIgoGcHBxzZjpnuXQOADS/qlef5pRYtHWKjlHeVAQBLmd/trdOYnzXTaStFPjxcP81FhN5PKZk/jGP6cQD2vDiKSDhZJoR7v52QF0Mt0hiyGlcxEdt0M9yStdMwt2E30z5tpqnu6c1R0kb7D18Vis9hJ4TjVq03s3nxrXkmk6ScBMiBZFx6tsjU9OGyKLor/WJT6ogiNrwvQDm8qOc0hsMlI/MgImie2xyxR8AtWnqchm1OK9A05dRU/JAaZpJbmkWkOYnSAUreuJAFGKxD9pZvgYsU3O9c17yM4SgDKx0GZRx2RNF74CofAqp0OwZBAckk+xXbXgMYXLg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2016 15:18:01.4939 (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: SN2PR03MB2382 Cc: Shreyansh Jain , thomas.monjalon@6wind.com, viktorin@rehivetech.com Subject: [dpdk-dev] [PATCH v6 15/21] eal/soc: add default scan for Soc devices 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:03 -0000 From: Jan Viktorin Default implementation which scans the sysfs platform devices hierarchy. For each device, extract the ueven and convert into rte_soc_device. The information populated can then be used in probe to match against the drivers registered. Signed-off-by: Jan Viktorin [Shreyansh: restructure commit to be an optional implementation] Signed-off-by: Shreyansh Jain -- v5: - Update rte_eal_soc_scan to rte_eal_soc_scan_platform_bus - Fix comments over scan and match functions --- lib/librte_eal/common/include/rte_soc.h | 16 +- lib/librte_eal/linuxapp/eal/eal_soc.c | 315 ++++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h index 38f897d..8be3db7 100644 --- a/lib/librte_eal/common/include/rte_soc.h +++ b/lib/librte_eal/common/include/rte_soc.h @@ -64,7 +64,10 @@ 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. */ struct rte_soc_id { - const char *compatible; /**< OF compatible specification */ + union { + const char *compatible; /**< OF compatible specification */ + char *_compatible; + }; uint64_t priv_data; /**< SoC Driver specific data */ }; @@ -200,7 +203,16 @@ rte_eal_parse_soc_spec(const char *spec, struct rte_soc_addr *addr) } /** - * Default function for matching the Soc driver with device. Each driver can + * Helper function for scanning for new SoC devices on platform bus. + * + * @return + * 0 on success + * !0 on failure to scan + */ +int rte_eal_soc_scan_platform_bus(void); + +/** + * Helper function for matching the Soc driver with device. Each driver can * either use this function or define their own soc matching function. * This function relies on the compatible string extracted from sysfs. But, * a SoC might have different way of identifying its devices. Such SoC can diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c b/lib/librte_eal/linuxapp/eal/eal_soc.c index 3929a76..d8dfe97 100644 --- a/lib/librte_eal/linuxapp/eal/eal_soc.c +++ b/lib/librte_eal/linuxapp/eal/eal_soc.c @@ -48,6 +48,321 @@ #include #include +/** Pathname of SoC devices directory. */ +#define SYSFS_SOC_DEVICES "/sys/bus/platform/devices" + +static const char * +soc_get_sysfs_path(void) +{ + const char *path = NULL; + + path = getenv("SYSFS_SOC_DEVICES"); + if (path == NULL) + return SYSFS_SOC_DEVICES; + + return path; +} + +static char * +dev_read_uevent(const char *dirname) +{ + char filename[PATH_MAX]; + struct stat st; + char *buf; + ssize_t total = 0; + int fd; + + snprintf(filename, sizeof(filename), "%s/uevent", dirname); + fd = open(filename, O_RDONLY); + if (fd < 0) { + RTE_LOG(WARNING, EAL, "Failed to open file %s\n", filename); + return strdup(""); + } + + if (fstat(fd, &st) < 0) { + RTE_LOG(ERR, EAL, "Failed to stat file %s\n", filename); + close(fd); + return NULL; + } + + if (st.st_size == 0) { + close(fd); + return strdup(""); + } + + buf = malloc(st.st_size + 1); + if (buf == NULL) { + RTE_LOG(ERR, EAL, "Failed to alloc memory to read %s\n", + filename); + close(fd); + return NULL; + } + + while (total < st.st_size) { + ssize_t rlen = read(fd, buf + total, st.st_size - total); + if (rlen < 0) { + if (errno == EINTR) + continue; + + RTE_LOG(ERR, EAL, "Failed to read file %s\n", filename); + + free(buf); + close(fd); + return NULL; + } + if (rlen == 0) /* EOF */ + break; + + total += rlen; + } + + buf[total] = '\0'; + close(fd); + + return buf; +} + +static const char * +dev_uevent_find(const char *uevent, const char *key) +{ + const size_t keylen = strlen(key); + const size_t total = strlen(uevent); + const char *p = uevent; + + /* check whether it is the first key */ + if (!strncmp(uevent, key, keylen)) + return uevent + keylen; + + /* check 2nd key or further... */ + do { + p = strstr(p, key); + if (p == NULL) + break; + + if (p[-1] == '\n') /* check we are at a new line */ + return p + keylen; + + p += keylen; /* skip this one */ + } while (p - uevent < (ptrdiff_t) total); + + return NULL; +} + +static char * +strdup_until_nl(const char *p) +{ + const char *nl = strchr(p, '\n'); + if (nl == NULL) + return strdup(p); /* no newline, copy until '\0' */ + + return strndup(p, nl - p); +} + +static int +dev_parse_uevent(struct rte_soc_device *dev, const char *uevent) +{ + const char *of; + const char *compat_n; + char *err; + long n; + char compat[strlen("OF_COMPATIBLE_NNNN=")]; + long i; + + of = dev_uevent_find(uevent, "OF_FULLNAME="); + if (of == NULL) + return 1; /* don't care about this device */ + + dev->addr.fdt_path = strdup_until_nl(of); + if (dev->addr.fdt_path == NULL) { + RTE_LOG(ERR, PMD, + "Failed to alloc memory for fdt_path\n"); + return -1; + } + + RTE_LOG(DEBUG, EAL, "Detected device %s (%s)\n", + dev->addr.name, dev->addr.fdt_path); + + compat_n = dev_uevent_find(uevent, "OF_COMPATIBLE_N="); + if (compat_n == NULL) { + RTE_LOG(ERR, EAL, "No OF_COMPATIBLE_N found\n"); + return -1; + } + + n = strtoul(compat_n, &err, 0); + if (*err != '\n' && err != NULL) { + RTE_LOG(ERR, EAL, "Failed to parse OF_COMPATIBLE_N: %.10s\n", + err); + goto fail_fdt_path; + } + + if (n == 0) + return 1; /* cannot match anything */ + if (n > 9999) { /* match NNNN */ + RTE_LOG(ERR, EAL, "OF_COMPATIBLE_N is invalid: %ld\n", n); + goto fail_fdt_path; + } + + dev->id = calloc(n + 1, sizeof(*dev->id)); + if (dev->id == NULL) { + RTE_LOG(ERR, PMD, "Failed to alloc memory for ID\n"); + free(dev->addr.fdt_path); + return -1; + } + + for (i = 0; i < n; ++i) { + snprintf(compat, sizeof(compat), "OF_COMPATIBLE_%lu=", i); + const char *val; + + val = dev_uevent_find(uevent, compat); + if (val == NULL) { + RTE_LOG(ERR, EAL, "%s was not found\n", compat); + goto fail_id; + } + + dev->id[i]._compatible = strdup_until_nl(val); + if (dev->id[i]._compatible == NULL) { + RTE_LOG(ERR, PMD, + "Failed to alloc memory for compatible\n"); + goto fail_id; + } + + RTE_LOG(DEBUG, EAL, " compatible: %s\n", + dev->id[i].compatible); + } + + dev->id[n]._compatible = NULL; /* mark last one */ + + return 0; + +fail_id: + while (i-- >= 0) + free(dev->id[i]._compatible); + free(dev->id); +fail_fdt_path: + free(dev->addr.fdt_path); + return -1; +} + +static void +dev_content_free(struct rte_soc_device *dev) +{ + int i; + + if (dev->addr.fdt_path) + free(dev->addr.fdt_path); + + if (dev->id != NULL) { + for (i = 0; dev->id[i]._compatible; ++i) + free(dev->id[i]._compatible); + + free(dev->id); + dev->id = NULL; + } +} + +/** + * Scan one SoC sysfs entry, and fill the devices list from it. + * We require to have the uevent file with records: OF_FULLNAME and + * OF_COMPATIBLE array (with at least one entry). Otherwise, such device + * is skipped. + */ +static int +soc_scan_one(const char *dirname, const char *name) +{ + struct rte_soc_device *dev; + char *uevent; + int ret; + + uevent = dev_read_uevent(dirname); + if (uevent == NULL) + return -1; + + if (uevent[0] == '\0') { + /* ignore directory without uevent file */ + free(uevent); + return 1; + } + + dev = malloc(sizeof(*dev) + strlen(name) + 1); + if (dev == NULL) { + RTE_LOG(ERR, PMD, "Failed to alloc memory for %s\n", name); + free(uevent); + return -1; + } + + memset(dev, 0, sizeof(*dev)); + dev->addr.name = (char *) (dev + 1); + strcpy(dev->addr.name, name); + + ret = dev_parse_uevent(dev, uevent); + if (ret) + goto fail; + free(uevent); /* not needed anymore */ + + /* device is valid, add in list (sorted) */ + if (TAILQ_EMPTY(&soc_device_list)) { + TAILQ_INSERT_TAIL(&soc_device_list, dev, next); + } else { + struct rte_soc_device *dev2; + + TAILQ_FOREACH(dev2, &soc_device_list, next) { + ret = rte_eal_compare_soc_addr(&dev->addr, &dev2->addr); + if (ret > 0) + continue; + + if (ret < 0) { + TAILQ_INSERT_BEFORE(dev2, dev, next); + } else { /* already registered */ + dev_content_free(dev2); + dev2->addr.fdt_path = dev->addr.fdt_path; + dev2->id = dev->id; + free(dev); + } + return 0; + } + TAILQ_INSERT_TAIL(&soc_device_list, dev, next); + } + + return 0; + +fail: + free(uevent); + dev_content_free(dev); + free(dev); + return ret; +} + +int +rte_eal_soc_scan_platform_bus(void) +{ + struct dirent *e; + DIR *dir; + char dirname[PATH_MAX]; + + dir = opendir(soc_get_sysfs_path()); + if (dir == NULL) { + RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n", + __func__, strerror(errno)); + return -1; + } + + while ((e = readdir(dir)) != NULL) { + if (e->d_name[0] == '.') + continue; + + snprintf(dirname, sizeof(dirname), "%s/%s", + soc_get_sysfs_path(), e->d_name); + if (soc_scan_one(dirname, e->d_name) < 0) + goto error; + } + closedir(dir); + return 0; + +error: + closedir(dir); + return -1; +} + /* Init the SoC EAL subsystem */ int rte_eal_soc_init(void) -- 2.7.4