Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB3CFECAAA1 for ; Wed, 31 Aug 2022 03:12:03 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F146084A04; Wed, 31 Aug 2022 05:10:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="Fu94Q5tM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51E3384A31; Wed, 31 Aug 2022 05:10:15 +0200 (CEST) Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 05439849C4 for ; Wed, 31 Aug 2022 05:10:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-11eb8b133fbso16939677fac.0 for ; Tue, 30 Aug 2022 20:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Gr2wsoJqXYfqdTm6cOzyi0YTm8Hk1S63pu136yCklM8=; b=Fu94Q5tMPD+wTGWbVQ7Pe+uG3cTd3xBPCkVcJicQzxOsIL7OHsfMRvHrEUEkKivm22 Fmb9em+chqf+p20c4UkSqwi37mPNjF8ZjrfMkkgHPBbKELXzDZavNr4ivyEyw82MNwkJ cSx452VsdLvTCjkm9FA/eS0RQcb1IIrqClBz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Gr2wsoJqXYfqdTm6cOzyi0YTm8Hk1S63pu136yCklM8=; b=YyOCzq+3VfMNy/fuJ4RhHnG2ZYoEPNYxM6fLGwjHGihkyBlGMEpJdLp0b8zgz1gchx pTLiwe0j4TSWYMR0LLvL3Wta6Ya9UvtqqWbITEPTAfh6cI3xjlhXTJdOdmuBo/78Eqxq SlA0YfBDIYHFnUDmWmDaEuZyhmqP+jw8M2ILGMXtAgiHDc9XgSYwYDlh+KlYlEPFj8la 4upHsXOoEHXANAD0NO9+XToi+9Lc4TvIbeEybgCW0D+afAP6E5Enz/dnGyaMygLxHgZh 6yxTBxshn9XjYM8YBwR9yjBK6kxHe9bMEbnM0yV9UuMRn2Rbx029PKm4yhikO1XqHEMt d4YA== X-Gm-Message-State: ACgBeo3ZG1sGq+vsZLlk/zKRkrskZowZ1qmjEQF3Uqbtlxc9x2A1dO6o NS5EznXM2LHPqS4+Xsug76sCM/N3poyXhw== X-Google-Smtp-Source: AA6agR74s9bFipsVDfvRMzdeMBQgekN+4/vdeH7ArCx0apdprbx3oba3TlBvbl7bEfFaMIfoUPviIQ== X-Received: by 2002:a05:6808:e8a:b0:32e:493b:1d8 with SMTP id k10-20020a0568080e8a00b0032e493b01d8mr431239oil.124.1661915357028; Tue, 30 Aug 2022 20:09:17 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id fp39-20020a05687065a700b00116d5103487sm9282605oab.31.2022.08.30.20.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:09:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Kishon Vijay Abraham I , Tom Rini , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH 18/21] dm: core: Allow obtaining a node offset in the same tree Date: Tue, 30 Aug 2022 21:08:14 -0600 Message-Id: <20220831030817.27804-19-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220831030817.27804-1-sjg@chromium.org> References: <20220831030817.27804-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean In some cases we want to obtain an ofnode in the same tree as a different ofnode, such as when looking up a subnode. At present this is trivial, since there is only one tree. When there are multiple trees, this implementation will change. Also move the ofnode_to_offset() function up higher in the header file, since we will need to provide a different implementation with multiple trees. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 2 +- include/dm/ofnode.h | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index aceb809c1f2..a5c6e309615 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1273,7 +1273,7 @@ int ofnode_add_subnode(ofnode node, const char *name, ofnode *subnodep) ofnode_to_offset(node), name); if (offset < 0) return offset == -FDT_ERR_EXISTS ? -EEXIST : 0; - subnode = offset_to_ofnode(offset); + subnode = noffset_to_ofnode(node, offset); } *subnodep = subnode; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ad196af2d45..a79909c12e1 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -54,6 +54,23 @@ static inline void *ofnode_to_fdt(ofnode node) return (void *)gd->fdt_blob; } +/** + * ofnode_to_offset() - convert an ofnode to a flat DT offset + * + * This cannot be called if the reference contains a node pointer. + * + * @node: Reference containing offset (possibly invalid) + * Return: DT offset (can be -1) + */ +static inline int ofnode_to_offset(ofnode node) +{ +#ifdef OF_CHECKS + if (of_live_active()) + return -1; +#endif + return node.of_offset; +} + /** * ofnode_to_np() - convert an ofnode to a live DT node pointer * @@ -90,20 +107,22 @@ static inline struct device_node *ofnode_to_npw(ofnode node) } /** - * ofnode_to_offset() - convert an ofnode to a flat DT offset + * noffset_to_ofnode() - convert a DT offset to an ofnode * - * This cannot be called if the reference contains a node pointer. - * - * @node: Reference containing offset (possibly invalid) - * Return: DT offset (can be -1) + * @other_node: Node in the same tree to use as a reference + * @of_offset: DT offset (either valid, or -1) + * Return: reference to the associated DT offset */ -static inline int ofnode_to_offset(ofnode node) +static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) { -#ifdef OF_CHECKS + ofnode node; + if (of_live_active()) - return -1; -#endif - return node.of_offset; + node.np = NULL; + else + node.of_offset = of_offset; + + return node; } /** -- 2.37.2.672.g94769d06f0-goog