From patchwork Wed Jun 21 17:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lizhi Hou X-Patchwork-Id: 13287775 X-Patchwork-Delegate: bhelgaas@google.com 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0960C001E0 for ; Wed, 21 Jun 2023 17:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbjFUReh (ORCPT ); Wed, 21 Jun 2023 13:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbjFUReg (ORCPT ); Wed, 21 Jun 2023 13:34:36 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9197919B; Wed, 21 Jun 2023 10:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMmrigKA4hn5SSFJSWaRkncCbTOwgNULL1jRs/7TdrB1grP6JlQKel66n9dUk/JZ0rTdlhIn0/V8tB3xCybOiO5a1mgvr0wsBfSci4Zij3sAqKTUKdDSxIkUQ4T48ozJN0ICio+YGhFPHxoCSLDGC4ppbrIxKp6En8VP3XrtNAZu4l9r5vTVTg0LqKo4kCMVSDhXdTQ+Kd3SJ1GSBDNV3CU9agKvFwuMGkPBMOB42WrTlfc4966vQV8O6KriLFByaxD/TkhYvIuZzENyOc1y7BPEkq1dCyoX7H+rlVRHDcrxeBejQA3CJ9+vmux/+YJB4TtuU3JhhndqwRpO7+oU/w== 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=MADuss227WzePRnbWXwwjohHHj2nTjBiOHJxq1H/10o=; b=f5d+sBmmT7Cpxg0FaxgXKt3P0GRyyxOaSMx/6Srs+09lz70ipdDloJNTwvRy0mrduswHku287EDj4aFgvz1CZk2mL5pQC4XAlxJU0w/zfywBxtKqqcwJZgQMJWar6o1G7dOMbh94Hio+hLqD2ET96GG40Dg6lnyvRaGzHRRWlmBI2bQnmaDcMAmd6FjV6st7cSH5t7BycyfRhQBytgArownba0b7Oi4InBtUl2FMHij1tEX+zd6fRsjTPBtsNxw+kpx2o9wy2XNv4iYHveSjp9POVnjotXv+4fubD8UisDkcoUgAGA7POkYNH9n/i7Ahzt1DKUxpqHQ5T2WTUEKEeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=MADuss227WzePRnbWXwwjohHHj2nTjBiOHJxq1H/10o=; b=w8XNa+uCCWSZKY/53OZkTTaQblqOos7/iTrooARnG1pZ8vdGVYFctDhoYOCP9hg4Ou57EAni2eD5tPyVr6KiP9vaNWiOHDHZzSqlzJoq0YcTFdzSo9l840bYLhVo4fcC/J1lX0AMHLk9qolgDld/O9y6YmyX2fRdJ4/HKGcgC6s= Received: from CY5PR15CA0031.namprd15.prod.outlook.com (2603:10b6:930:1b::33) by DS0PR12MB8341.namprd12.prod.outlook.com (2603:10b6:8:f8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.21; Wed, 21 Jun 2023 17:34:31 +0000 Received: from CY4PEPF0000E9CE.namprd03.prod.outlook.com (2603:10b6:930:1b:cafe::bf) by CY5PR15CA0031.outlook.office365.com (2603:10b6:930:1b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.23 via Frontend Transport; Wed, 21 Jun 2023 17:34:31 +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 CY4PEPF0000E9CE.mail.protection.outlook.com (10.167.241.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6521.20 via Frontend Transport; Wed, 21 Jun 2023 17:34:31 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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.23; Wed, 21 Jun 2023 12:34:30 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Wed, 21 Jun 2023 10:34:29 -0700 Received: from xsjlizhih40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.23 via Frontend Transport; Wed, 21 Jun 2023 12:34:29 -0500 From: Lizhi Hou To: , , , CC: Lizhi Hou , , , Subject: [PATCH V9 4/5] of: overlay: Extend of_overlay_fdt_apply() to specify the target node Date: Wed, 21 Jun 2023 10:34:08 -0700 Message-ID: <1687368849-36722-5-git-send-email-lizhi.hou@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1687368849-36722-1-git-send-email-lizhi.hou@amd.com> References: <1687368849-36722-1-git-send-email-lizhi.hou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9CE:EE_|DS0PR12MB8341:EE_ X-MS-Office365-Filtering-Correlation-Id: 1860fda1-c414-4b75-62d2-08db727dc57b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CZphwl/9xPD7viDfwWp4XX2A4pPIJBIvMZU3Q3Gbjlu1hCffnvR9aIzfuiZo/5rEYSdQ1lalwxvJFgstjOHJHndOiMv6JIojDbcx3UcQosSD5lZuPuqW/VkrSK5wz0Oq1y4CZCBzRhtB16y2vCf2ueJyZuPhAOcE2J7cv1fB4U2ZjymQNgyz+bHnkN8/dT8Iy3TuACd/pCIwuANXWQZGWry4mXRAIh60UCGXL4GhEC8P5GMmFTU0Pzc9yBHtzhFpeqRGBPAaSU7ktfzhklNNH5eIGPbs0Cgc0x81zF8WdvYQJ/AVhgpQMLBD81QKMNux/nCUjHlTdoVdN15zeZQ40GPXeB6WbCseaXL4WBeehFAdzuoFS+NbDEdMEybCUc05cMn+kylwacR1GhJNiIS7K2bYR3AryCYme4OwXuwuIbTFFykDrLozF4st3B4LUtjU3leFTFLJmEJHQmDV4moZ1vXeWb6fWV0sJpdolIpARRQ1qqXnaQxByKBmcN+DFyMQs9C6S6OgQzPR9JBCsxhfJIGJJpFuLySsJId3z4XZL0SfgFBTZp/qAokXM9iSyt45v2Y6vBck1XD0Dsq6u//dnbq8dFd106LO7m1RJygmxJUV1CKWXfzQfcMeyYmSMSnSzjwuWC179U2ab6dcBBNcwwZSJUTKesVv3zRvcWW2SrFsdrArIRZ2XyYkpiK9+Ety4ajACnPj1GhdrObdPiM1LSCn01fiEtj4ePe7NMYl8O3huFHPl2hRn/0oxUhL1DGnQyWGYnk+sLxEIun132m+pw== 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)(39860400002)(136003)(346002)(376002)(396003)(451199021)(36840700001)(40470700004)(46966006)(81166007)(40480700001)(82740400003)(356005)(82310400005)(86362001)(36756003)(40460700003)(4326008)(316002)(44832011)(26005)(186003)(110136005)(5660300002)(54906003)(8936002)(70586007)(426003)(6666004)(41300700001)(336012)(36860700001)(2906002)(47076005)(2616005)(8676002)(478600001)(83380400001)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2023 17:34:31.1639 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1860fda1-c414-4b75-62d2-08db727dc57b 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: CY4PEPF0000E9CE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8341 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Currently, in an overlay fdt fragment, it needs to specify the exact location in base DT. In another word, when the fdt fragment is generated, the base DT location for the fragment is already known. There is new use case that the base DT location is unknown when fdt fragment is generated. For example, the add-on device provide a fdt overlay with its firmware to describe its downstream devices. Because it is add-on device which can be plugged to different systems, its firmware will not be able to know the overlay location in base DT. Instead, the device driver will load the overlay fdt and apply it to base DT at runtime. In this case, of_overlay_fdt_apply() needs to be extended to specify the target node for device driver to apply overlay fdt. int overlay_fdt_apply(..., struct device_node *base); Signed-off-by: Lizhi Hou --- drivers/of/overlay.c | 42 +++++++++++++++++++++++++++++++----------- drivers/of/unittest.c | 3 ++- include/linux/of.h | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 7feb643f1370..6f3ae30c878d 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -682,9 +682,11 @@ static int build_changeset(struct overlay_changeset *ovcs) * 1) "target" property containing the phandle of the target * 2) "target-path" property containing the path of the target */ -static struct device_node *find_target(struct device_node *info_node) +static struct device_node *find_target(struct device_node *info_node, + struct device_node *target_base) { struct device_node *node; + char *target_path; const char *path; u32 val; int ret; @@ -700,10 +702,23 @@ static struct device_node *find_target(struct device_node *info_node) ret = of_property_read_string(info_node, "target-path", &path); if (!ret) { - node = of_find_node_by_path(path); - if (!node) - pr_err("find target, node: %pOF, path '%s' not found\n", - info_node, path); + if (target_base) { + target_path = kasprintf(GFP_KERNEL, "%pOF%s", target_base, path); + if (!target_path) + return NULL; + node = of_find_node_by_path(target_path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, target_path); + } + kfree(target_path); + } else { + node = of_find_node_by_path(path); + if (!node) { + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, path); + } + } return node; } @@ -715,6 +730,7 @@ static struct device_node *find_target(struct device_node *info_node) /** * init_overlay_changeset() - initialize overlay changeset from overlay tree * @ovcs: Overlay changeset to build + * @target_base: Point to the target node to apply overlay * * Initialize @ovcs. Populate @ovcs->fragments with node information from * the top level of @overlay_root. The relevant top level nodes are the @@ -725,7 +741,8 @@ static struct device_node *find_target(struct device_node *info_node) * detected in @overlay_root. On error return, the caller of * init_overlay_changeset() must call free_overlay_changeset(). */ -static int init_overlay_changeset(struct overlay_changeset *ovcs) +static int init_overlay_changeset(struct overlay_changeset *ovcs, + struct device_node *target_base) { struct device_node *node, *overlay_node; struct fragment *fragment; @@ -786,7 +803,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs) fragment = &fragments[cnt]; fragment->overlay = overlay_node; - fragment->target = find_target(node); + fragment->target = find_target(node, target_base); if (!fragment->target) { of_node_put(fragment->overlay); ret = -EINVAL; @@ -877,6 +894,7 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * * of_overlay_apply() - Create and apply an overlay changeset * @ovcs: overlay changeset + * @base: point to the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -900,7 +918,8 @@ static void free_overlay_changeset(struct overlay_changeset *ovcs) * the caller of of_overlay_apply() must call free_overlay_changeset(). */ -static int of_overlay_apply(struct overlay_changeset *ovcs) +static int of_overlay_apply(struct overlay_changeset *ovcs, + struct device_node *base) { int ret = 0, ret_revert, ret_tmp; @@ -908,7 +927,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) if (ret) goto out; - ret = init_overlay_changeset(ovcs); + ret = init_overlay_changeset(ovcs, base); if (ret) goto out; @@ -952,6 +971,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) * @overlay_fdt: pointer to overlay FDT * @overlay_fdt_size: number of bytes in @overlay_fdt * @ret_ovcs_id: pointer for returning created changeset id + * @base: pointer for the target node to apply overlay * * Creates and applies an overlay changeset. * @@ -967,7 +987,7 @@ static int of_overlay_apply(struct overlay_changeset *ovcs) */ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ret_ovcs_id) + int *ret_ovcs_id, struct device_node *base) { void *new_fdt; void *new_fdt_align; @@ -1037,7 +1057,7 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, } ovcs->overlay_mem = overlay_mem; - ret = of_overlay_apply(ovcs); + ret = of_overlay_apply(ovcs, base); /* * If of_overlay_apply() error, calling free_overlay_changeset() may * result in a memory leak if the apply partly succeeded, so do NOT diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1193a574fa36..4a0774954b93 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -3506,7 +3506,8 @@ static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id) if (!size) pr_err("no overlay data for %s\n", overlay_name); - ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id); + ret = of_overlay_fdt_apply(info->dtbo_begin, size, &info->ovcs_id, + NULL); if (ovcs_id) *ovcs_id = info->ovcs_id; if (ret < 0) diff --git a/include/linux/of.h b/include/linux/of.h index 82d0a476ec75..5fe5257a7ab7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1668,7 +1668,7 @@ struct of_overlay_notify_data { #ifdef CONFIG_OF_OVERLAY int of_overlay_fdt_apply(const void *overlay_fdt, u32 overlay_fdt_size, - int *ovcs_id); + int *ovcs_id, struct device_node *target_base); int of_overlay_remove(int *ovcs_id); int of_overlay_remove_all(void);