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 94784ECAAD8 for ; Wed, 31 Aug 2022 03:11:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D2CB584A1A; Wed, 31 Aug 2022 05:10:37 +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="VfID9m5y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5C5D3849FA; Wed, 31 Aug 2022 05:09:56 +0200 (CEST) Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) (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 7138D849DE for ; Wed, 31 Aug 2022 05:09:51 +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-ot1-x32a.google.com with SMTP id h20-20020a056830165400b00638ac7ddba5so9435286otr.4 for ; Tue, 30 Aug 2022 20:09:51 -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=4p3JTLeiLhHt2ixi9WitjDHilblPOMrehhAbjZIQkYo=; b=VfID9m5yNtICjR6i7ALfzPWl9HwqKilL3Zj7ch5VU6WAWw0N6dJiZeWe2l9xx5b69B V06SXswcEes2i9bQRRxtKXvvthn8ugH5KmpKQe3P5KpxgrXHtiZkOsmjHxuI1asBI81m FaJgDXWyltfo4du8nB0KvOYwegYg0pM90HTgQ= 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=4p3JTLeiLhHt2ixi9WitjDHilblPOMrehhAbjZIQkYo=; b=wlbMJtnTBS8gv0CiIy49CQVG+u5nVr98BadAnPVY+myK1V0+4Nqt7BXg95RA4gJlhf cZ0SvyzkZsoRBz6M9JTEOtWh90gwv49sm/WL7pen3zDJhlM4I6rPv9ONpKW1BFJEZCTe +TddBVjv3Bmgey123udQF80nkn0Ut4FjNHaK7dDIr9cR4mOur/GbIiOALZfu3rx/7bMi ItE/UhZGBhpouZJoKY8coz43nAoXbGDN6z8mecJoFPTCK5knNm6Ud/OkRYgaRWFzS+nd 0MbZiIF7zJlG62K+Q+bvy0uIW1TlMJOAHb2xdkpElYSZpJJi7OcGyQxY+MgL9GUrxZST Ct9Q== X-Gm-Message-State: ACgBeo1q/xPJcnXiaglwOaH7/MqFZlYNpVmbb/yCsjMv1yeZbYiL1Os/ 6a1xciHoy5gUzNwdwJ0Pe8qSSKbqvNlfZA== X-Google-Smtp-Source: AA6agR65yTvGRMaTjfSjr18a4gc0F/zrdLy0r7wjgNsyjxNncJSe1XlP7rFSXV4voBdkDpDpOzvqYQ== X-Received: by 2002:a05:6830:349:b0:63a:cd5d:9014 with SMTP id h9-20020a056830034900b0063acd5d9014mr7234761ote.29.1661915356136; Tue, 30 Aug 2022 20:09:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:09:15 -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 17/21] dm: core: Add a way to look up a phandle in an oftree Date: Tue, 30 Aug 2022 21:08:13 -0600 Message-Id: <20220831030817.27804-18-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 When we have multiple trees, the ofnode logic needs to be told which one to use. Create a new function which takes an oftree argument, along with a helper to obtain the FDT pointer from an oftree. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 14 ++++++++++++++ include/dm/ofnode.h | 25 +++++++++++++++++++++++++ test/dm/ofnode.c | 2 ++ 3 files changed, 41 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 6ee114bd5a8..aceb809c1f2 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -337,6 +337,20 @@ ofnode ofnode_get_by_phandle(uint phandle) return node; } +ofnode oftree_get_by_phandle(oftree tree, uint phandle) +{ + ofnode node; + + if (of_live_active()) + node = np_to_ofnode(of_find_node_by_phandle(tree.np, phandle)); + else + node.of_offset = + fdt_node_offset_by_phandle(oftree_lookup_fdt(tree), + phandle); + + return node; +} + static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size, bool translate) { diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index d8d5082806e..ad196af2d45 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -120,6 +120,22 @@ static inline bool ofnode_valid(ofnode node) return node.of_offset >= 0; } +/** + * oftree_lookup_fdt() - object the FDT pointer from an oftree + * + * This can only be called when flat tree is enabled + * + * @tree: Tree to look at + * @return FDT pointer from the tree + */ +static inline void *oftree_lookup_fdt(oftree tree) +{ + if (of_live_active()) + return NULL; + else + return tree.fdt; +} + /** * offset_to_ofnode() - convert a DT offset to an ofnode * @@ -526,6 +542,15 @@ int ofnode_get_path(ofnode node, char *buf, int buflen); */ ofnode ofnode_get_by_phandle(uint phandle); +/** + * oftree_get_by_phandle() - get ofnode from phandle + * + * @tree: tree to use + * @phandle: phandle to look up + * Return: ofnode reference to the phandle + */ +ofnode oftree_get_by_phandle(oftree tree, uint phandle); + /** * ofnode_read_size() - read the size of a property * diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 7f195a725a0..6a5beadbadc 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -36,6 +36,8 @@ static int dm_test_ofnode_get_by_phandle(struct unit_test_state *uts) /* test unknown phandle */ ut_assert(!ofnode_valid(ofnode_get_by_phandle(0x1000000))); + ut_assert(ofnode_valid(oftree_get_by_phandle(oftree_default(), 1))); + return 0; } DM_TEST(dm_test_ofnode_get_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- 2.37.2.672.g94769d06f0-goog