From patchwork Sat May 27 10:25:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shreyansh Jain X-Patchwork-Id: 24756 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id A771156A1; Sat, 27 May 2017 12:18:06 +0200 (CEST) Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0066.outbound.protection.outlook.com [104.47.42.66]) by dpdk.org (Postfix) with ESMTP id 2638E5398 for ; Sat, 27 May 2017 12:18:02 +0200 (CEST) Received: from BN6PR03CA0056.namprd03.prod.outlook.com (2603:10b6:404:4c::18) by DM2PR0301MB0909.namprd03.prod.outlook.com (2a01:111:e400:501c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Sat, 27 May 2017 10:17:58 +0000 Received: from BN1BFFO11FD027.protection.gbl (2a01:111:f400:7c10::1:123) by BN6PR03CA0056.outlook.office365.com (2603:10b6:404:4c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9 via Frontend Transport; Sat, 27 May 2017 10:17:58 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD027.mail.protection.outlook.com (10.58.144.90) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1075.5 via Frontend Transport; Sat, 27 May 2017 10:17:58 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.39]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id v4RAHYtq029968; Sat, 27 May 2017 03:17:56 -0700 From: Shreyansh Jain To: CC: , Date: Sat, 27 May 2017 15:55:02 +0530 Message-ID: <1495880735-1651-7-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495880735-1651-1-git-send-email-shreyansh.jain@nxp.com> References: <1495880735-1651-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131403538787080067; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39850400002)(39450400003)(39380400002)(39840400002)(39860400002)(39410400002)(39400400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(9170700003)(53936002)(305945005)(86362001)(2906002)(356003)(68736007)(6916009)(81166006)(105606002)(2351001)(2950100002)(106466001)(5003940100001)(36756003)(33646002)(8676002)(50226002)(85426001)(48376002)(8936002)(50466002)(47776003)(6666003)(77096006)(110136004)(38730400002)(189998001)(498600001)(8656002)(54906002)(4326008)(104016004)(5660300001)(76176999)(50986999)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0909; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD027; 1:GMxm54Eihr0uhCotX5mslLOhuONKYUEwECCEHPDOTIpuQDEPdzLtiNwkNgNonAVF5xdKb8OscJcS/+f7sYFZCcqGctM81zGWI/A65llFEEYQVd+MFTbCW0U6tOXzqC07y+O+nCkrTvgUS1MTLu+e2hy7iM+kvCLeklucVOPTM2JnMeF6qba1miGEVUVkaqDl2UlEFNQG/44cm/evn6wui+a74XVUt3Ia4Ap3DGZVXaFEsttPrDAYh/ptVodrulBQX/krIyWkSmdIuiyPlawNf+V0N/bZfFZcinttkYHpPjPX+4ayWW+DnbnovHprYTCyRaCmg9nqjo6yIDyaNfgxXdQUJI1JNCvOtDonWjTULrxILFUzfjDOc4LePYqLtB4JyZu42pZe3xsrr+QHLT8lZKgGjH2cygp6tF07o5ClCQbGIp2j2D/2LaIUCLfsrCS2nAIHNUyCQo9BsIqKoBdN+u2lv+FnAeYOmDShR4c5V0yYJdGscYkVGND+77StmURvWkyxNoWajRlzjXnYqs0cK102y58+Cc4QVXBXgyE3g8ZOwoGGgzO0wb5hFOxQBxPQdXJFDlyhCGNjFdfk+oA7qLaEgk/ionbAhhp3dxUdDXjLu/5bTUAJyLR8eRXWtY5fGpraTxy0DWtp1ehdwgdetncghiDO/FEFidKNRnBvY6lYb7JoYrBbx/8rDktcwmHokpCHt6A/6VPmEylAlHkxCw== MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM2PR0301MB0909: X-MS-Office365-Filtering-Correlation-Id: c4063fb4-cb1f-4c26-b621-08d4a4e9a616 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131430075)(201703131517081); SRVR:DM2PR0301MB0909; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0909; 3:HtUTfyQDk57Q6/7n3/Gk6ZeQLJGCzmmlAklpxWBsqegtCIgTKu8vR44Y56YEcIsp8CnWtE+Rlpd3Ia8ktIK/M37VxyNojOG4sSA5sJkL/teMEKLdHYVdXyXIkfemfnKw9CeKxLeMVxdB6TVeD0hwx6dtwGccUokpEFZFF+p4XwPxJiIZpyDVP7jl2cEC5vqy6mC8CndBz7/SUnctxjOYI0Ziy+++9r1xH0ZZqDee7MlSS/SsGMMGVSshlrScA+vk5B7d9+qJcE2240r89PxsyyFoaRAOYjVjbKtAQNP90xRYTNM2nTN/IcWEbxjLmPB28Ad0KetAma/NA6eM0UUgmq+95qnBVtfmlgARdDoD7BAc2XdgRYe958ko1n2RveuYZIHDnJAP978XmsVVBX8zrpCwejBPnLmdzWAy6aT+wD+XE5NgpbRUxEu36jqandYU; 25:Labhzkd/7+JGE9IGLNChJeUwxrzobC5TkceunTXYgkLO4MJsonb5pq7aYEhrpj3gtSh2kTmxzxudFLjqoTJpeWfnCYNsf44gSr5kiGZntCk9ys3VjQ+Fm1yFiwnRHEBt1WVQYwpmEn3wFtDQ+zC6idhOAE4yuzDQF7mTeOuFbeRU6IV73gxcms86fhRkbWtRcgsN1kwWr+kYvswpFW6TVHduFh8W0pOcooPYb6FbVHMQ6BJGGfllzyFyZt9cRmXXZDhGyNJovHdpo9SFC+9wH6IC32g44q+RA/fwgcF/mj7E7+NZ+MjfIQgnPgOEhy1T/bjlmvaUpvyKFbgZ1qxcASvy1zrGcmj7kNCpLPOkMHInNs1yqHpc9J/cb9Y+/HjdcZjPWWmFiXEheXjnuxaFmjBLvmws7+cbmrG33wg4Cdl2Ye7s10XfVizZbeF4+tnQ+7wpAzR392rMWgWtLzfvuOutGq2Y7T2Tw8aIZVYezh4= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0909; 31:ALnAFuC3JoOI2VEWuFpfbK49p0uAGfuD/Xuw/jNrTYAz0MAytofig5g26l+CGUeXNQRr0bPJ5+0s3z5Xf1Su/1RA3na3+iGdIluMS0RFEO1EZ78AmRu/FyYAwG6sKJv3L1BaVA2seQ6120ChzqWiAm2TCAme05uzS5W/+sRaeEOlLN+vHjCH5cpOksuWEEhRkMs7i5+h9feWvll+MaveWrGgagttLo0cBSQVtDDB2ZzS2gMyx5GXrdmYXL05uJQX X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700073)(100105000095)(100000701073)(100105300095)(100000702073)(100105100095)(6095135)(601004)(2401047)(13018025)(5005006)(8121501046)(13016025)(100000703073)(100105400095)(10201501046)(3002001)(93006095)(93001095)(6055026)(6096035)(20161123565025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123556025)(20161123561025)(20161123563025)(100000704073)(100105200095)(100000705073)(100105500095); SRVR:DM2PR0301MB0909; BCL:0; PCL:0; RULEID:(100000800073)(100110000095)(100000801073)(100110300095)(100000802073)(100110100095)(100000803073)(100110400095)(400006)(100000804073)(100110200095)(100000805073)(100110500095); SRVR:DM2PR0301MB0909; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0909; 4:8uVnoxtTuF1HPRnyxieEyaqQ8RwJxBNBvZhcRlKi?= B4HO5fBQvy8/+qrPxg1ZcTAbpQIi4zze7LnuMr5XbOTmPV/v0ptK1DFuyP/vgktkwd5Kzb31Dot5pwF99mhC8sz+ESjvO/ev3Qo3IOsoHaHvykBn4AqPGiBOUq6d4D4NIFt7wrDIUh8TsnTPOTP+1h5xX85BdeU9fc+dT/2ymvD7/5U7E6gyXpitVGc60+BJFUvHmgF/KxhJxLnuTpFZPd/1+eCxZcMq2tx22UTxhYSTylmKOVN/yW8WHH17SjluPobv6+yXFn9FNAzvigFmRzIi7lPkEAwesi0ZywuekQfcOjyj1jLJ4Hu4GyCHebbbKPehtWFm6BSg31wBNY5YplZzVUSEZr72sDg18lfvidtUSapvJxapkrR4COHq4Hr+XvfmfUj5MlsUr87flMfQ6PkHHOmPs4sSYjnErmmrbsK8HedSqUb8QyYdziPbUWGyFEBpmQlprlownehSnO5rFLtsEw1yIyeMbhrkX4pLPhyh5xbzWr9W9MZOxqzfF4B5O0tvILIbUhevk0hrfJONDsSDsAKndkZ+vB7j5c1rYLG+frdJiCfW219GqLXrNMmjlDS9b0Ta1g8wmo94e2noirc6KsvkPkrFVa8BEqx/5Q5BmCjBAIdDI3E0oYMWyj5NayOqumtJvjWvcl7hhPNdoTEWnkJiobhimTG1UKRVH0PQd5/tBMPiwqm8qDg/TGs5oh2si5SfChbv1tg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Rul0sX42AiiIVXzFcNuay1mSgmjZiKNK4Q3A4BLNIaybcvuiIw8sVDoKUKXMs9AB8NU1gK3OQMqktmTebM0FxIiJUtxoMllvI9LMA6umoqI9VJwvPpKL9bEIaP5PyRM4uA+Yq/720kQDVKnAds5wwTwYtoGu8uRavW0W3oHo3gXUvnIAJorPgT8DHY7r1vDRGMF/oepWPq4R3Uxevhgf/AdhGLM1tNRpatiBNaXWS44PVBmAbiutXPDGyvMkNBFLCJcDDONyCfqkLSGPxNEIo0JUmPr4NQCPiWN0mUy1mF63/SkFHog/jkZJzS3Zyn0ZqjfYPvC54i2tkg== X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0909; 5:Rrmsv0+fHb9QHNdubK4E0yoUhC45yHt4v8f8c23ckkl/dXEzaQNnY81c8mFA/NetDzWcuqDX83z0njJpmUysK30F8F97/35WUuExEsU4V54qFS3jNUpm4nBz03dwj9xzQnHupOB4OfFtsEKzh7bYzJFsTimQHY84xJIe9F3rUMR+pva8VmUngZ+sQczHAX/BF1oChGYOJ9kWpFZDxUkU2Ta0Liq4KKY2j3bAmpKj0jfVF4m4R9qtwscB5pp4ZiGo2xGpNePktJtHiQcFGpOZLPue5+c6uaaWBvYPkhWI0GIsnICEonNOjtPj8aHUZSreD2hvOoXf7zcrVdc573I43S67yJYSHdke0YKRagQ9BeDiLdMXRZk1FoOne7JTaJbon5lvz8CHSE4+1Yt967ImEPSFmPH6oaAuOOD4Xk04iVkmc0RQzeDvyMJr5658HHKC4QMuTfo2e0DMFNmEeoKBOyS3BBux6ie+DXXP1cxyVr6wxZqqhNuTkubWaJjnqIKCy5y2wN5O6eM78kwsml4evg==; 24:zDnJcw5tlQRZzK+OnE8YnHQyGkmPx3/Epdn89WehgGq1B0ff/r48ZjWO4cRACNdpygrZgwLylQ9Om4Kx++9oGyF+bksjpfXVYeI6vJvkqiM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0909; 7:82VhA+6jODtfGExYbm1FmXei9hVqW/j8KD9et+K8k2uO/I4waGw9W32reLF5ANVSGbUexKGemVJULkemQwukalFcyzvoiwkUsac+ZsGdqlv5R8dmqSYfwePsqiblhgifqyk/lyYyGA4GvzED2m7NsxgMVzncSlifce5w0kinTBxjXEUgwr6Gu+rmZTWb4F+pKeqyQuu7b370YrpUpxP7ZKDHrBOWD1L+DPSuZQWfEXclAvcoxs8poGPeAuqlgBxG2iCD9JIei+Zo6rNwf8tk/os4tmKr9W7jh55bhTCJbTc8ettVUa8tGaTiY53XUrvlwOwKml0shxXd+/QDD0IHZw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2017 10:17:58.4740 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0909 Subject: [dpdk-dev] [RFC Patch 06/39] bus/dpaa: add OF parser for device scanning X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This layer is used by Bus driver's scan function. Devices are parsed using OF parser and added to DPAA device list. Signed-off-by: Geoff Thorpe Signed-off-by: Shreyansh Jain --- drivers/bus/dpaa/Makefile | 7 + drivers/bus/dpaa/base/fman/of.c | 576 ++++++++++++++++++++++++++++++++++++++++ drivers/bus/dpaa/include/of.h | 191 +++++++++++++ 3 files changed, 774 insertions(+) create mode 100644 drivers/bus/dpaa/base/fman/of.c create mode 100644 drivers/bus/dpaa/include/of.h diff --git a/drivers/bus/dpaa/Makefile b/drivers/bus/dpaa/Makefile index ae48bf2..9069a2b 100644 --- a/drivers/bus/dpaa/Makefile +++ b/drivers/bus/dpaa/Makefile @@ -45,7 +45,12 @@ CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) endif +CFLAGS +=-Wno-pointer-arith +CFLAGS +=-Wno-cast-qual +CFLAGS += -D _GNU_SOURCE + CFLAGS += -I$(RTE_BUS_DPAA)/ +CFLAGS += -I$(RTE_BUS_DPAA)/include CFLAGS += -I$(RTE_SDK)/lib/librte_eal/linuxapp/eal CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common/include @@ -59,5 +64,7 @@ LIBABIVER := 1 SRCS-$(CONFIG_RTE_LIBRTE_DPAA_BUS) += \ dpaa_bus.c +SRCS-$(CONFIG_RTE_LIBRTE_DPAA_BUS) += \ + base/fman/of.c \ include $(RTE_SDK)/mk/rte.lib.mk diff --git a/drivers/bus/dpaa/base/fman/of.c b/drivers/bus/dpaa/base/fman/of.c new file mode 100644 index 0000000..6cc3987 --- /dev/null +++ b/drivers/bus/dpaa/base/fman/of.c @@ -0,0 +1,576 @@ +/*- + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * BSD LICENSE + * + * Copyright 2010-2016 Freescale Semiconductor Inc. + * Copyright 2017 NXP. + * + * 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 the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * GPL LICENSE SUMMARY + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * 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 HOLDERS 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 + +static int alive; +static struct dt_dir root_dir; +static const char *base_dir; +static COMPAT_LIST_HEAD(linear); + +static int +of_open_dir(const char *relative_path, struct dirent ***d) +{ + int ret; + char full_path[PATH_MAX]; + + snprintf(full_path, PATH_MAX, "%s/%s", base_dir, relative_path); + ret = scandir(full_path, d, 0, versionsort); + if (ret < 0) + DPAA_BUS_LOG(ERR, "Failed to open directory %s", + full_path); + return ret; +} + +static void +of_close_dir(struct dirent **d, int num) +{ + while (num--) + free(d[num]); + free(d); +} + +static int +of_open_file(const char *relative_path) +{ + int ret; + char full_path[PATH_MAX]; + + snprintf(full_path, PATH_MAX, "%s/%s", base_dir, relative_path); + ret = open(full_path, O_RDONLY); + if (ret < 0) + DPAA_BUS_LOG(ERR, "Failed to open directory %s", + full_path); + return ret; +} + +static void +process_file(struct dirent *dent, struct dt_dir *parent) +{ + int fd; + struct dt_file *f = malloc(sizeof(*f)); + + if (!f) { + DPAA_BUS_LOG(DEBUG, "Unable to allocate memory for file node"); + return; + } + f->node.is_file = 1; + snprintf(f->node.node.name, NAME_MAX, "%s", dent->d_name); + snprintf(f->node.node.full_name, PATH_MAX, "%s/%s", + parent->node.node.full_name, dent->d_name); + f->parent = parent; + fd = of_open_file(f->node.node.full_name); + if (fd < 0) { + DPAA_BUS_LOG(DEBUG, "Unable to open file node"); + free(f); + return; + } + f->len = read(fd, f->buf, OF_FILE_BUF_MAX); + close(fd); + if (f->len < 0) { + DPAA_BUS_LOG(DEBUG, "Unable to read file node"); + free(f); + return; + } + list_add_tail(&f->node.list, &parent->files); +} + +static const struct dt_dir * +node2dir(const struct device_node *n) +{ + struct dt_node *dn = container_of((struct device_node *)n, + struct dt_node, node); + const struct dt_dir *d = container_of(dn, struct dt_dir, node); + + assert(!dn->is_file); + return d; +} + +/* process_dir() calls iterate_dir(), but the latter will also call the former + * when recursing into sub-directories, so a predeclaration is needed. + */ +static int process_dir(const char *relative_path, struct dt_dir *dt); + +static int +iterate_dir(struct dirent **d, int num, struct dt_dir *dt) +{ + int loop; + /* Iterate the directory contents */ + for (loop = 0; loop < num; loop++) { + struct dt_dir *subdir; + int ret; + /* Ignore dot files of all types (especially "..") */ + if (d[loop]->d_name[0] == '.') + continue; + switch (d[loop]->d_type) { + case DT_REG: + process_file(d[loop], dt); + break; + case DT_DIR: + subdir = malloc(sizeof(*subdir)); + if (!subdir) { + perror("malloc"); + return -ENOMEM; + } + snprintf(subdir->node.node.name, NAME_MAX, "%s", + d[loop]->d_name); + snprintf(subdir->node.node.full_name, PATH_MAX, + "%s/%s", dt->node.node.full_name, + d[loop]->d_name); + subdir->parent = dt; + ret = process_dir(subdir->node.node.full_name, subdir); + if (ret) + return ret; + list_add_tail(&subdir->node.list, &dt->subdirs); + break; + default: + DPAA_BUS_LOG(DEBUG, "Ignoring invalid dt entry %s/%s", + dt->node.node.full_name, d[loop]->d_name); + } + } + return 0; +} + +static int +process_dir(const char *relative_path, struct dt_dir *dt) +{ + struct dirent **d; + int ret, num; + + dt->node.is_file = 0; + INIT_LIST_HEAD(&dt->subdirs); + INIT_LIST_HEAD(&dt->files); + ret = of_open_dir(relative_path, &d); + if (ret < 0) + return ret; + num = ret; + ret = iterate_dir(d, num, dt); + of_close_dir(d, num); + return (ret < 0) ? ret : 0; +} + +static void +linear_dir(struct dt_dir *d) +{ + struct dt_file *f; + struct dt_dir *dd; + + d->compatible = NULL; + d->status = NULL; + d->lphandle = NULL; + d->a_cells = NULL; + d->s_cells = NULL; + d->reg = NULL; + list_for_each_entry(f, &d->files, node.list) { + if (!strcmp(f->node.node.name, "compatible")) { + if (d->compatible) + DPAA_BUS_LOG(DEBUG, "Duplicate compatible in" + " %s", d->node.node.full_name); + d->compatible = f; + } else if (!strcmp(f->node.node.name, "status")) { + if (d->status) + DPAA_BUS_LOG(DEBUG, "Duplicate status in %s", + d->node.node.full_name); + d->status = f; + } else if (!strcmp(f->node.node.name, "linux,phandle")) { + if (d->lphandle) + DPAA_BUS_LOG(DEBUG, "Duplicate lphandle in %s", + d->node.node.full_name); + d->lphandle = f; + } else if (!strcmp(f->node.node.name, "#address-cells")) { + if (d->a_cells) + DPAA_BUS_LOG(DEBUG, "Duplicate a_cells in %s", + d->node.node.full_name); + d->a_cells = f; + } else if (!strcmp(f->node.node.name, "#size-cells")) { + if (d->s_cells) + DPAA_BUS_LOG(DEBUG, "Duplicate s_cells in %s", + d->node.node.full_name); + d->s_cells = f; + } else if (!strcmp(f->node.node.name, "reg")) { + if (d->reg) + DPAA_BUS_LOG(DEBUG, "Duplicate reg in %s", + d->node.node.full_name); + d->reg = f; + } + } + + list_for_each_entry(dd, &d->subdirs, node.list) { + list_add_tail(&dd->linear, &linear); + linear_dir(dd); + } +} + +int +of_init_path(const char *dt_path) +{ + int ret; + + base_dir = dt_path; + + /* This needs to be singleton initialization */ + DPAA_BUS_WARN(alive, "Double-init of device-tree driver!"); + + /* Prepare root node (the remaining fields are set in process_dir()) */ + root_dir.node.node.name[0] = '\0'; + root_dir.node.node.full_name[0] = '\0'; + INIT_LIST_HEAD(&root_dir.node.list); + root_dir.parent = NULL; + + /* Kick things off... */ + ret = process_dir("", &root_dir); + if (ret) { + DPAA_BUS_LOG(ERR, "Unable to parse device tree"); + return ret; + } + + /* Now make a flat, linear list of directories */ + linear_dir(&root_dir); + alive = 1; + return 0; +} + +static void +destroy_dir(struct dt_dir *d) +{ + struct dt_file *f, *tmpf; + struct dt_dir *dd, *tmpd; + + list_for_each_entry_safe(f, tmpf, &d->files, node.list) { + list_del(&f->node.list); + free(f); + } + list_for_each_entry_safe(dd, tmpd, &d->subdirs, node.list) { + destroy_dir(dd); + list_del(&dd->node.list); + free(dd); + } +} + +void +of_finish(void) +{ + DPAA_BUS_WARN(!alive, "Double-finish of device-tree driver!"); + + destroy_dir(&root_dir); + INIT_LIST_HEAD(&linear); + alive = 0; +} + +static const struct dt_dir * +next_linear(const struct dt_dir *f) +{ + if (f->linear.next == &linear) + return NULL; + return list_entry(f->linear.next, struct dt_dir, linear); +} + +static int +check_compatible(const struct dt_file *f, const char *compatible) +{ + const char *c = (char *)f->buf; + unsigned int len, remains = f->len; + + while (remains) { + len = strlen(c); + if (!strcmp(c, compatible)) + return 1; + + if (remains < len + 1) + break; + + c += (len + 1); + remains -= (len + 1); + } + return 0; +} + +const struct device_node * +of_find_compatible_node(const struct device_node *from, + const char *type __always_unused, + const char *compatible) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + + if (list_empty(&linear)) + return NULL; + if (!from) + d = list_entry(linear.next, struct dt_dir, linear); + else + d = node2dir(from); + for (d = next_linear(d); d && (!d->compatible || + !check_compatible(d->compatible, + compatible)); + d = next_linear(d)) + ; + if (d) + return &d->node.node; + return NULL; +} + +const void * +of_get_property(const struct device_node *from, const char *name, + size_t *lenp) +{ + const struct dt_dir *d; + const struct dt_file *f; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + + d = node2dir(from); + list_for_each_entry(f, &d->files, node.list) + if (!strcmp(f->node.node.name, name)) { + if (lenp) + *lenp = f->len; + return f->buf; + } + return NULL; +} + +bool +of_device_is_available(const struct device_node *dev_node) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + d = node2dir(dev_node); + if (!d->status) + return true; + if (!strcmp((char *)d->status->buf, "okay")) + return true; + if (!strcmp((char *)d->status->buf, "ok")) + return true; + return false; +} + +const struct device_node * +of_find_node_by_phandle(phandle ph) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + list_for_each_entry(d, &linear, linear) + if (d->lphandle && (d->lphandle->len == 4) && + !memcmp(d->lphandle->buf, &ph, 4)) + return &d->node.node; + return NULL; +} + +const struct device_node * +of_get_parent(const struct device_node *dev_node) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + + if (!dev_node) + return NULL; + d = node2dir(dev_node); + if (!d->parent) + return NULL; + return &d->parent->node.node; +} + +const struct device_node * +of_get_next_child(const struct device_node *dev_node, + const struct device_node *prev) +{ + const struct dt_dir *p, *c; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + + if (!dev_node) + return NULL; + p = node2dir(dev_node); + if (prev) { + c = node2dir(prev); + DPAA_BUS_WARN((c->parent != p), "Parent/child mismatch"); + if (c->parent != p) + return NULL; + if (c->node.list.next == &p->subdirs) + /* prev was the last child */ + return NULL; + c = list_entry(c->node.list.next, struct dt_dir, node.list); + return &c->node.node; + } + /* Return first child */ + if (list_empty(&p->subdirs)) + return NULL; + c = list_entry(p->subdirs.next, struct dt_dir, node.list); + return &c->node.node; +} + +uint32_t +of_n_addr_cells(const struct device_node *dev_node) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised"); + if (!dev_node) + return OF_DEFAULT_NA; + d = node2dir(dev_node); + while ((d = d->parent)) + if (d->a_cells) { + unsigned char *buf = + (unsigned char *)&d->a_cells->buf[0]; + assert(d->a_cells->len == 4); + return ((uint32_t)buf[0] << 24) | + ((uint32_t)buf[1] << 16) | + ((uint32_t)buf[2] << 8) | + (uint32_t)buf[3]; + } + return OF_DEFAULT_NA; +} + +uint32_t +of_n_size_cells(const struct device_node *dev_node) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + if (!dev_node) + return OF_DEFAULT_NA; + d = node2dir(dev_node); + while ((d = d->parent)) + if (d->s_cells) { + unsigned char *buf = + (unsigned char *)&d->s_cells->buf[0]; + assert(d->s_cells->len == 4); + return ((uint32_t)buf[0] << 24) | + ((uint32_t)buf[1] << 16) | + ((uint32_t)buf[2] << 8) | + (uint32_t)buf[3]; + } + return OF_DEFAULT_NS; +} + +const uint32_t * +of_get_address(const struct device_node *dev_node, size_t idx, + uint64_t *size, uint32_t *flags __rte_unused) +{ + const struct dt_dir *d; + const unsigned char *buf; + uint32_t na = of_n_addr_cells(dev_node); + uint32_t ns = of_n_size_cells(dev_node); + + if (!dev_node) + d = &root_dir; + else + d = node2dir(dev_node); + if (!d->reg) + return NULL; + assert(d->reg->len % ((na + ns) * 4) == 0); + assert(d->reg->len / ((na + ns) * 4) > (unsigned int) idx); + buf = (const unsigned char *)&d->reg->buf[0]; + buf += (na + ns) * idx * 4; + if (size) + for (*size = 0; ns > 0; ns--, na++) + *size = (*size << 32) + + (((uint32_t)buf[4 * na] << 24) | + ((uint32_t)buf[4 * na + 1] << 16) | + ((uint32_t)buf[4 * na + 2] << 8) | + (uint32_t)buf[4 * na + 3]); + return (const uint32_t *)buf; +} + +uint64_t +of_translate_address(const struct device_node *dev_node, + const uint32_t *addr) +{ + uint64_t phys_addr, tmp_addr; + const struct device_node *parent; + const uint32_t *ranges; + size_t rlen; + uint32_t na, pna; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + assert(dev_node != NULL); + + na = of_n_addr_cells(dev_node); + phys_addr = of_read_number(addr, na); + + dev_node = of_get_parent(dev_node); + if (!dev_node) + return 0; + else if (node2dir(dev_node) == &root_dir) + return phys_addr; + + do { + pna = of_n_addr_cells(dev_node); + parent = of_get_parent(dev_node); + if (!parent) + return 0; + + ranges = of_get_property(dev_node, "ranges", &rlen); + /* "ranges" property is missing. Translation breaks */ + if (!ranges) + return 0; + /* "ranges" property is empty. Do 1:1 translation */ + else if (rlen == 0) + continue; + else + tmp_addr = of_read_number(ranges + na, pna); + + na = pna; + dev_node = parent; + phys_addr += tmp_addr; + } while (node2dir(parent) != &root_dir); + + return phys_addr; +} + +bool +of_device_is_compatible(const struct device_node *dev_node, + const char *compatible) +{ + const struct dt_dir *d; + + DPAA_BUS_WARN(!alive, "Device-tree driver not initialised!"); + if (!dev_node) + d = &root_dir; + else + d = node2dir(dev_node); + if (d->compatible && check_compatible(d->compatible, compatible)) + return true; + return false; +} diff --git a/drivers/bus/dpaa/include/of.h b/drivers/bus/dpaa/include/of.h new file mode 100644 index 0000000..e422a53 --- /dev/null +++ b/drivers/bus/dpaa/include/of.h @@ -0,0 +1,191 @@ +/*- + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * BSD LICENSE + * + * Copyright 2010-2016 Freescale Semiconductor, Inc. + * Copyright 2017 NXP. + * 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 the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * GPL LICENSE SUMMARY + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * 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 HOLDERS 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 __OF_H +#define __OF_H + +#include + +#ifndef OF_INIT_DEFAULT_PATH +#define OF_INIT_DEFAULT_PATH "/proc/device-tree" +#endif + +#define OF_DEFAULT_NA 1 +#define OF_DEFAULT_NS 1 + +#define OF_FILE_BUF_MAX 256 + +/** + * Layout of Device Tree: + * dt_dir + * |- dt_dir + * | |- dt_dir + * | | |- dt_dir + * | | | |- dt_file + * | | | ``- dt_file + * | | ``- dt_file + * | `-dt_file` + * ``- dt_file + * + * +------------------+ + * |dt_dir | + * |+----------------+| + * ||dt_node || + * ||+--------------+|| + * |||device_node ||| + * ||+--------------+|| + * || list_dt_nodes || + * |+----------------+| + * | list of subdir | + * | list of files | + * +------------------+ + */ + +/** + * Device description on of a device node in device tree. + */ +struct device_node { + char name[NAME_MAX]; + char full_name[PATH_MAX]; +}; + +/** + * List of device nodes available in a device tree layout + */ +struct dt_node { + struct device_node node; /**< Property of node */ + int is_file; /**< FALSE==dir, TRUE==file */ + struct list_head list; /**< Nodes within a parent subdir */ +}; + +/** + * Types we use to represent directories and files + */ +struct dt_file; +struct dt_dir { + struct dt_node node; + struct list_head subdirs; + struct list_head files; + struct list_head linear; + struct dt_dir *parent; + struct dt_file *compatible; + struct dt_file *status; + struct dt_file *lphandle; + struct dt_file *a_cells; + struct dt_file *s_cells; + struct dt_file *reg; +}; + +struct dt_file { + struct dt_node node; + struct dt_dir *parent; + ssize_t len; + uint64_t buf[OF_FILE_BUF_MAX >> 3]; /** ASDF: Why? */ +}; + +const struct device_node *of_find_compatible_node( + const struct device_node *from, + const char *type __always_unused, + const char *compatible) + __attribute__((nonnull(3))); + +#define for_each_compatible_node(dev_node, type, compatible) \ + for (dev_node = of_find_compatible_node(NULL, type, compatible); \ + dev_node != NULL; \ + dev_node = of_find_compatible_node(dev_node, type, compatible)) + +const void *of_get_property(const struct device_node *from, const char *name, + size_t *lenp) __attribute__((nonnull(2))); +bool of_device_is_available(const struct device_node *dev_node); + +const struct device_node *of_find_node_by_phandle(phandle ph); + +const struct device_node *of_get_parent(const struct device_node *dev_node); + +const struct device_node *of_get_next_child(const struct device_node *dev_node, + const struct device_node *prev); + +#define for_each_child_node(parent, child) \ + for (child = of_get_next_child(parent, NULL); child != NULL; \ + child = of_get_next_child(parent, child)) + +uint32_t of_n_addr_cells(const struct device_node *dev_node); +uint32_t of_n_size_cells(const struct device_node *dev_node); + +const uint32_t *of_get_address(const struct device_node *dev_node, size_t idx, + uint64_t *size, uint32_t *flags); + +uint64_t of_translate_address(const struct device_node *dev_node, + const u32 *addr) __attribute__((nonnull)); + +bool of_device_is_compatible(const struct device_node *dev_node, + const char *compatible); + +/* of_init() must be called prior to initialisation or use of any driver + * subsystem that is device-tree-dependent. Eg. Qman/Bman, config layers, etc. + * The path should usually be "/proc/device-tree". + */ +int of_init_path(const char *dt_path); + +/* of_finish() allows a controlled tear-down of the device-tree layer, eg. if a + * full reload is desired without a process exit. + */ +void of_finish(void); + +/* Use of this wrapper is recommended. */ +static inline int of_init(void) +{ + return of_init_path(OF_INIT_DEFAULT_PATH); +} + +/* Read a numeric property according to its size and return it as a 64-bit + * value. + */ +static inline uint64_t of_read_number(const __be32 *cell, int size) +{ + uint64_t r = 0; + + while (size--) + r = (r << 32) | be32toh(*(cell++)); + return r; +} + +#endif /* __OF_H */