Received: by 2002:a19:c144:0:0:0:0:0 with SMTP id r65csp203173lff; Thu, 5 Aug 2021 05:40:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvj+FXkfirH4Hj3FiofHKBGifF8EX+e+2ZJCaU1r/t93t7g9KuWAuJbDLqVgsw2n/h9rBM X-Received: by 2002:a67:f659:: with SMTP id u25mr4477367vso.4.1628167232057; Thu, 05 Aug 2021 05:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628167232; cv=none; d=google.com; s=arc-20160816; b=j70M8CtPzHurFqGE+lYLa1LrKe5xFkiCWoowZlnFuER8EVQ4zhVgIRxfpJNlh6DJ0z nq2mcuBHZcNAGFZfejrfNrnnrRBowcgB03SEx6ApVGSI71BS+GYMNZSVqa4dheD1R3D0 fmd2mnV+YIwsSoOKsN1y2doBTBfYG14MK+HIidOsfjxxIEA93uuF70ihzyx7sorxO5Sv g3SU8DQ1efAZknp4BEU9WH5P//KVLtPrLO4kzn/ye/akapc6S1P4SBJbVUDV5dR+aPRK J+8mSMFkXE4hvcc+4ig1IxRg64BpZX4rvsuU/Zd0/1Ga11OGxP5hNj6u490wlvjNhtNF uE4g== 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:mime-version:references :in-reply-to:message-id:date:subject:to:from; bh=Pqf74XDB+paQELGG0WjI2k1JMJQg2U9iMe5NUvi3vWg=; b=wNL4z/d+vKlfPi532hUO6MR4jXnOGY4SaQH0Z+QenKC3j0yIMYgM0hZEWzEqYR+/z8 +Tn3ARdBBU9bDdccbpT/hjB8469QYhXOHyDmyDtvSvLS7JotIgrkk6NKtoSLm7YI7FPE r6D/OJR2/nw6+1Pei3uGjNIIL/JrhO/7vzP04BikVBawI0tIrVSGCk9xBljz/s4leKbA cIBJceH1VOB6QKT1pFec9BZf+iBsmGpyW/KhPpuo0M+xzsuI3sMp5tLqWLlyVheNy1oR KjUnFkRqVHKK7cb/qQA0MvoWfF1s3zI5PBaCUsVD3/YqvUlJsgwEUnKbWOzgq4l0VyQG My4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p25si2900274uar.96.2021.08.05.05.40.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Aug 2021 05:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: from localhost ([::1]:45330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBcfn-0004oh-B7 for alex.bennee@linaro.org; Thu, 05 Aug 2021 08:40:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBcf1-000451-71; Thu, 05 Aug 2021 08:39:43 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2461) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBcew-00061X-An; Thu, 05 Aug 2021 08:39:43 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GgSkx702jzZxhM; Thu, 5 Aug 2021 20:35:53 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 20:39:28 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 20:39:27 +0800 From: Yanan Wang To: Peter Maydell , Andrew Jones , "Michael S . Tsirkin" , Igor Mammedov Subject: [PATCH for-6.2 v5 2/5] device_tree: Add qemu_fdt_add_path Date: Thu, 5 Aug 2021 20:39:18 +0800 Message-ID: <20210805123921.62540-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210805123921.62540-1-wangyanan55@huawei.com> References: <20210805123921.62540-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Salil Mehta , qemu-devel@nongnu.org, Yanan Wang , Shannon Zhao , qemu-arm@nongnu.org, Alistair Francis , wanghaibin.wang@huawei.com, David Gibson Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: qoX4qNwv8Chs 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(). Reviewed-by: David Gibson Cc: David Gibson Cc: Alistair Francis Co-developed-by: Andrew Jones Signed-off-by: Yanan Wang --- include/sysemu/device_tree.h | 1 + softmmu/device_tree.c | 44 ++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) 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; -- 2.19.1