From patchwork Thu Oct 21 15:25:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 516051 Delivered-To: patch@linaro.org Received: by 2002:ac0:bf50:0:0:0:0:0 with SMTP id o16csp23392imj; Thu, 21 Oct 2021 08:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWdUzMH/VShMsK0/BNAh12+vXnJ7tqLIRwCFSQ6spTrBPaK08XcwPOX+VvnoXzubTzK5bE X-Received: by 2002:a9d:60dd:: with SMTP id b29mr5308897otk.117.1634830643421; Thu, 21 Oct 2021 08:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634830643; cv=none; d=google.com; s=arc-20160816; b=nJqnK/CW65kk9hJ0ToKXcsngbdRO42x3MBpR7c8Erf3ADyKNUpy5SNRTPgc7pWS4Rl TLwcua173RkxV7lBd6o5rL13+EEqp9Fj8Iwp36syCC1NQsiQnkI7Q5zMiufOF1yxZUc2 WcQxotcfhaJoTsv49ygl2Y02+B/ncsl0lMbE0EPJ5frnMcWh7Y8klDukkp+UwXgqRIG+ c03Mn3GkBcYOfnGSVHsgXKygfDy3QrJAxEO6lAqhT6R459SNfdZ+8gpME/Ya2QaGHbpL rMtkeubutxbzdHGJMv/vdu2u6nVIGQHR4R/VWlh3TU4mmwtFL39gb/XEXMUZF1/y+crc PX9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=n/Pvx/0svSuMmT8RY9aB1ty9PqQ7g1AslPNBWP29bj4=; b=nVTqV/8YhYpg0uzaOZsYTDHuEmRY22FhGSx11lPGF0BYx+lYLWHWdElNxWvZKZDiYa YLjwgddNPaxlPx2pSDf8oG4y9Evb/kA8s4ING6ZLmkssx1sJIEskW/X+DkOvqgr4RcYg E10J/Y8AMFJXVlgA0v2kQN6MfTlHdkSkIWjzGp5TMV0J9pN2H6GV3C3mD0C2Y3CUsOeQ LwbTkcoF3x+xcG6IIKiaWSi4aS7Tl67IIPQsTayzm5SwUWIcMDtqqDKunlKXg+o25Nx8 YqbEQUMiMLg1LGGReoLrXGRPzLElJfBBYKAO+MfXxXHbJ80owrvD5axtg74pxPJjr3TH ZPBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IZkgbko5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i23si7602530otf.234.2021.10.21.08.37.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Oct 2021 08:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IZkgbko5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mda8A-0005An-Mi for patch@linaro.org; Thu, 21 Oct 2021 11:37:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdZx5-0000Ft-Le for qemu-devel@nongnu.org; Thu, 21 Oct 2021 11:25:55 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:46773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mdZx3-0002az-IT for qemu-devel@nongnu.org; Thu, 21 Oct 2021 11:25:55 -0400 Received: by mail-pl1-x631.google.com with SMTP id i1so629087plr.13 for ; Thu, 21 Oct 2021 08:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n/Pvx/0svSuMmT8RY9aB1ty9PqQ7g1AslPNBWP29bj4=; b=IZkgbko5fuzLbo+t9lofjVjBRx3O1FNT6lYKUHkO4DFgHcY2zFU1SHEXhwJbsQiE82 501peJCttK2CWxkblzku8Suqv6Dx5TPgh2O+vgQ21Rj+bBUR+Nom+MOYfXmauUu/fm+Y nJDJ96RD9dasfekVVE5BvJzhWeH05Bua9JcTI+HubEr8kq+3MyLZuFYwUxTe8/e7AcLd Q5FybFfFqiGbm3TS2Oc9Xh/4vXZXhFZ6UiC+4F8KHFVKWjEOTSjHqiL/f9icMTjpfErP UQo1yilSPUp0URy1Z3xhZ/z+o/ADeACJaouwS0Ce8nHFdjx3x2X+gIKmHNPCa2Ig5fY0 FaDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n/Pvx/0svSuMmT8RY9aB1ty9PqQ7g1AslPNBWP29bj4=; b=EcEUSWYN4GEo0tvC+F96ur05/zCvWO46cZZcqxV1M5YkMaoGcbC6D8sv6LFG7cLrj6 q3Yj/YmHe8UtdbHGEEzwsqP+YHvdL/WBla48T2IzhAcsGZC+3edUmyagZRaYjtSTKjo0 58sPP0H1klrowUeod+rbmfBfEP5RrF2Ghpl90Pqc/UI7f6R/JtxQMVu3eg/6+57kYEuI vDgoLcqeSEBrWZjPpjt18Eeke4T3tMP9Sw1M+B5NSqu1MnuBw64ggaAJ5QeAbkitNb76 ZXbFYNyhBz8efmc7QPiQXAsgEmF562foWFCJQZHgKg6fcv4exTr0JYXqFmu62XF0oZlg dxRQ== X-Gm-Message-State: AOAM531KId5P+A+5+wEMCV/0KOgkl24Sd9M0W2RoLttwOBMBVVKnFrS2 CJsZORmZiocF+qXREUem1QZ0t8ydp1HdTQ== X-Received: by 2002:a17:903:234d:b0:13f:3180:626a with SMTP id c13-20020a170903234d00b0013f3180626amr5869978plh.49.1634829952126; Thu, 21 Oct 2021 08:25:52 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id y3sm5676257pge.44.2021.10.21.08.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 08:25:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 13/19] device_tree: Add qemu_fdt_add_path Date: Thu, 21 Oct 2021 08:25:35 -0700 Message-Id: <20211021152541.781175-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211021152541.781175-1-richard.henderson@linaro.org> References: <20211021152541.781175-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yanan Wang , Andrew Jones , Alistair Francis , David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Yanan Wang qemu_fdt_add_path() works like qemu_fdt_add_subnode(), except it also adds all missing subnodes from the given path. We'll use it in a coming patch where we will add cpu-map to the device tree. And we also tweak an error message of qemu_fdt_add_subnode(). Co-developed-by: Andrew Jones Signed-off-by: Yanan Wang Reviewed-by: David Gibson Reviewed-by: Andrew Jones Cc: David Gibson Cc: Alistair Francis Message-Id: <20211020142125.7516-3-wangyanan55@huawei.com> Signed-off-by: Richard Henderson --- include/sysemu/device_tree.h | 1 + softmmu/device_tree.c | 44 ++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index 8a2fe55622..ef060a9759 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -121,6 +121,7 @@ uint32_t qemu_fdt_get_phandle(void *fdt, const char *path); uint32_t qemu_fdt_alloc_phandle(void *fdt); int qemu_fdt_nop_node(void *fdt, const char *node_path); int qemu_fdt_add_subnode(void *fdt, const char *name); +int qemu_fdt_add_path(void *fdt, const char *path); #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \ do { \ diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index b621f63fba..3965c834ca 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -540,8 +540,8 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) retval = fdt_add_subnode(fdt, parent, basename); if (retval < 0) { - error_report("FDT: Failed to create subnode %s: %s", name, - fdt_strerror(retval)); + error_report("%s: Failed to create subnode %s: %s", + __func__, name, fdt_strerror(retval)); exit(1); } @@ -549,6 +549,46 @@ int qemu_fdt_add_subnode(void *fdt, const char *name) return retval; } +/* + * qemu_fdt_add_path: Like qemu_fdt_add_subnode(), but will add + * all missing subnodes from the given path. + */ +int qemu_fdt_add_path(void *fdt, const char *path) +{ + const char *name; + const char *p = path; + int namelen, retval; + int parent = 0; + + if (path[0] != '/') { + return -1; + } + + while (p) { + name = p + 1; + p = strchr(name, '/'); + namelen = p != NULL ? p - name : strlen(name); + + retval = fdt_subnode_offset_namelen(fdt, parent, name, namelen); + if (retval < 0 && retval != -FDT_ERR_NOTFOUND) { + error_report("%s: Unexpected error in finding subnode %.*s: %s", + __func__, namelen, name, fdt_strerror(retval)); + exit(1); + } else if (retval == -FDT_ERR_NOTFOUND) { + retval = fdt_add_subnode_namelen(fdt, parent, name, namelen); + if (retval < 0) { + error_report("%s: Failed to create subnode %.*s: %s", + __func__, namelen, name, fdt_strerror(retval)); + exit(1); + } + } + + parent = retval; + } + + return retval; +} + void qemu_fdt_dumpdtb(void *fdt, int size) { const char *dumpdtb = current_machine->dumpdtb;