From patchwork Fri Aug 11 06:11:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashok Reddy Soma X-Patchwork-Id: 1820146 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=rNhf0p/p; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMYN450zqz1yf2 for ; Fri, 11 Aug 2023 16:11:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 83DB2868DB; Fri, 11 Aug 2023 08:11:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="rNhf0p/p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 62548868DE; Fri, 11 Aug 2023 08:11:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2061b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe5a::61b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 192C6861E6 for ; Fri, 11 Aug 2023 08:11:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=ashok.reddy.soma@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DyM0NcLxhI7pUTkpNlmGzQ9GM6kuT2teQU15dDbUGkfGpASuNd/LfzP9qFwSn6961a4kokgYQKXiOysovEXTtycKDSsZXgyVvGR0CNguQrmyIfDld0vKimTy1fyDjT8uQBYcSR404Sd0UoGbilcJidfbC/3VWBvorzibNkoCOkPjC2Z/En2TatlDtN3uIfVl132hwWHX9cIzgOyjVwcbpLI7MrY9SGkQoMwJs/Zh2nLM6+xVXoXf5lbcMSgIbnB08bPuU2jR/cesaRCmmXoM2RPKbunIlGRL5r7g/zXAGjw4ZlaC8Jm9smN4jwMCUUzgsLMA6KXFLKw5kLNn3d0NUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2B1T33RkwEPKJmReH6z8eS3yZ8JkqpvvXL475ZznekA=; b=NrYn5p9FSB/akqHFSG2obLOj3DBicLypV2Mfsee7iXyU6to3kvisbSHNZBdZVqqh1g/T3294RO14RukbdLsCqAP/yD9jKkX4jXz9K/fAT6xKDC6lLXylFub5/TwCmhDKVwXsmrAy+JpexhVTPrss4KXNtZouaiOIxvAHt0fMb++3O6Baod1mWB6WMS8Brk/oSB6gvwZILJGVq6xLTwESX7bfiqkPBvDR/5JKLzqy8SfsMmx+nRYb4ZASG/LEIQLyCXK2IxhoCcbBHe1tfT7xaDewop+5jxhcGr4Ezouzy6iXtbtZzV56/j7ISFZvlpVzEkC0znLb/jrk9GrUFrDsuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.denx.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2B1T33RkwEPKJmReH6z8eS3yZ8JkqpvvXL475ZznekA=; b=rNhf0p/p+uhUJolJCpGoRNmoK35kqkSdqgiyWJpKSO46bZq0lJSVM0HHqur6oY4jX1+fbBP5GfSEjpRiulA5V8aYU7/u/u9QZPzla3GuLaAdC6RggSje3yFR81ycSxMHv2BvaIUDF3GytiBrQhU78gYmIJhHiuSrFWaYS5KI5gw= Received: from SN4PR0501CA0040.namprd05.prod.outlook.com (2603:10b6:803:41::17) by DM3PR12MB9433.namprd12.prod.outlook.com (2603:10b6:0:47::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Fri, 11 Aug 2023 06:11:33 +0000 Received: from SN1PEPF00026369.namprd02.prod.outlook.com (2603:10b6:803:41:cafe::9b) by SN4PR0501CA0040.outlook.office365.com (2603:10b6:803:41::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.18 via Frontend Transport; Fri, 11 Aug 2023 06:11:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00026369.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6652.19 via Frontend Transport; Fri, 11 Aug 2023 06:11:32 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 11 Aug 2023 01:11:32 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 10 Aug 2023 23:11:31 -0700 Received: from xhdashokred41.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Fri, 11 Aug 2023 01:11:30 -0500 From: Ashok Reddy Soma To: CC: , , , "Ashok Reddy Soma" Subject: [PATCH] dm: core: support reading a single indexed u64 value Date: Fri, 11 Aug 2023 00:11:21 -0600 Message-ID: <20230811061121.23964-1-ashok.reddy.soma@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026369:EE_|DM3PR12MB9433:EE_ X-MS-Office365-Filtering-Correlation-Id: 1bb1c045-2fb9-45ba-c6e5-08db9a31cf66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KbhnafHNaOZNPF7Y5FkprpDSNoT641gevw4g6VHBZVvux/BcX9VoI8/3q9sVZQVf1i+vimjM4xSdUfHpJuHpApH8z8c+HJjqx318eqfZof/lEHAZ4XuxoloWzSokf+opnLTGY95xTdT8mfY09vsFzMjUOIZk9rcDBpEubcgPc8UWD7MA6bHXy12P/nXZpoYt8oHaqs3Fh0R5pne3HAe48bo5zr2eOzmVyOFXrN3ShUqC1VI5w7hySwnLWD2zEurQH3D4WwcnGrnb4ZxnZPtToXY1FRfGjUGZG6vWBAlDg21CrmtP55xnXSoAIsTjuXtv6H2/uuqJ0LD1Ye9X9ZBUtxICXgieERzNf8woc6GGj7d/NIry93R3xQusRUk7HnvI+x1a3hb2/q/KV8O4/bz+IXvAvoJ2G5XoNIgxzUGWa7ou1tl1tWXbF9WBJgqrbAROZcavJ9PFIYjm3XeVqRxN7G80vku+mgRbZC4nIoSLeTkZPCuukReoJCM+RIkjWKQLwBNIIsRduaCnA5VTHnJZ5xMDrx5UhthqGbj8aLBNa0tt7Hj3q7M4VSAM+xoG7Hx9rJ9aCvz/G7gMF1RfwMiY8S0qXHTjn2iEKPPJTCeCOkdeCY7TWrkMGSgTs+n5BYVYRKeOCriATlXZLLooK4KcF3XfG9m3HjDfNfgrDc3tPhsrRfLN5BK1YIVe2hXZfzjEMVPQDFDbNB5jyStDYNH6UnL/ySKnlATkhQdZ1qyWgcGa3sJQqIRzIYyH4TsKJuUlw1OWmxe8T4HcCZuzAEduHQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(396003)(346002)(136003)(376002)(39860400002)(82310400008)(1800799006)(451199021)(186006)(40470700004)(36840700001)(46966006)(40460700003)(40480700001)(54906003)(70586007)(6916009)(26005)(1076003)(478600001)(6666004)(70206006)(36756003)(336012)(83380400001)(426003)(47076005)(2616005)(36860700001)(103116003)(41300700001)(2906002)(316002)(4326008)(86362001)(82740400003)(81166007)(356005)(8936002)(5660300002)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 06:11:32.6127 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1bb1c045-2fb9-45ba-c6e5-08db9a31cf66 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00026369.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9433 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add helper function to allow reading a single indexed u64 value from a device-tree property containing multiple u64 values, that is an array of u64's. Signed-off-by: Ashok Reddy Soma --- drivers/core/of_access.c | 22 ++++++++++++++++++++++ drivers/core/ofnode.c | 30 ++++++++++++++++++++++++++++++ include/dm/of_access.h | 19 +++++++++++++++++++ include/dm/ofnode.h | 12 ++++++++++++ 4 files changed, 83 insertions(+) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 57f10445b1..b5c315ac3a 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -570,6 +570,28 @@ int of_read_u32_index(const struct device_node *np, const char *propname, return 0; } +int of_read_u64_index(const struct device_node *np, const char *propname, + int index, u64 *outp) +{ + const __be64 *val; + + debug("%s: %s: ", __func__, propname); + if (!np) + return -EINVAL; + + val = of_find_property_value_of_size(np, propname, + sizeof(*outp) * (index + 1)); + if (IS_ERR(val)) { + debug("(not found)\n"); + return PTR_ERR(val); + } + + *outp = be64_to_cpup(val + index); + debug("%#x (%d)\n", *outp, *outp); + + return 0; +} + int of_read_u64(const struct device_node *np, const char *propname, u64 *outp) { const __be64 *val; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8df16e56af..9a43343ed3 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -344,6 +344,36 @@ int ofnode_read_u32_index(ofnode node, const char *propname, int index, return 0; } +int ofnode_read_u64_index(ofnode node, const char *propname, int index, + u64 *outp) +{ + const fdt64_t *cell; + int len; + + assert(ofnode_valid(node)); + + if (ofnode_is_np(node)) + return of_read_u64_index(ofnode_to_np(node), propname, index, + outp); + + cell = fdt_getprop(ofnode_to_fdt(node), ofnode_to_offset(node), + propname, &len); + if (!cell) { + debug("(not found)\n"); + return -EINVAL; + } + + if (len < (sizeof(int) * (index + 1))) { + debug("(not large enough)\n"); + return -EOVERFLOW; + } + + *outp = fdt64_to_cpu(cell[index]); + debug("%#llx (%lld)\n", *outp, *outp); + + return 0; +} + u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index, u32 def) { diff --git a/include/dm/of_access.h b/include/dm/of_access.h index c556a18f7d..9e027c9293 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -333,6 +333,25 @@ int of_read_u32(const struct device_node *np, const char *propname, u32 *outp); int of_read_u32_index(const struct device_node *np, const char *propname, int index, u32 *outp); +/** + * of_read_u64_index() - Find and read a 64-bit value from a multi-value + * property + * + * Search for a property in a device node and read a 64-bit value from + * it. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @index: index of the u32 in the list of values + * @outp: pointer to return value, modified only if return value is 0. + * + * Return: + * 0 on success, -EINVAL if the property does not exist, or -EOVERFLOW if the + * property data isn't large enough. + */ +int of_read_u64_index(const struct device_node *np, const char *propname, + int index, u64 *outp); + /** * of_read_u64() - Find and read a 64-bit integer from a property * diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0f38b3e736..0a85db31f3 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -434,6 +434,18 @@ int ofnode_read_u32(ofnode node, const char *propname, u32 *outp); int ofnode_read_u32_index(ofnode node, const char *propname, int index, u32 *outp); +/** + * ofnode_read_u64_index() - Read a 64-bit integer from a multi-value property + * + * @node: valid node reference to read property from + * @propname: name of the property to read from + * @index: index of the integer to return + * @outp: place to put value (if found) + * Return: 0 if OK, -ve on error + */ +int ofnode_read_u64_index(ofnode node, const char *propname, int index, + u64 *outp); + /** * ofnode_read_s32() - Read a 32-bit integer from a property *