From patchwork Thu Sep 2 06:05:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671FAC25AEB for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13FA460F6C for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 13FA460F6C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176910.322072 (Exim 4.92) (envelope-from ) id 1mLgYq-0004ff-7B; Thu, 02 Sep 2021 06:50:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176910.322072; Thu, 02 Sep 2021 06:50:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYq-0004f4-3V; Thu, 02 Sep 2021 06:50:56 +0000 Received: by outflank-mailman (input) for mailman id 176910; Thu, 02 Sep 2021 06:06:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfs8-0004ZP-Ju for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:06:48 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (unknown [40.107.92.53]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f479392f-0bb3-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:06:47 +0000 (UTC) Received: from DM5PR07CA0167.namprd07.prod.outlook.com (2603:10b6:3:ee::33) by DM6PR02MB4218.namprd02.prod.outlook.com (2603:10b6:5:a0::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Thu, 2 Sep 2021 06:06:45 +0000 Received: from DM3NAM02FT050.eop-nam02.prod.protection.outlook.com (2603:10b6:3:ee:cafe::29) by DM5PR07CA0167.outlook.office365.com (2603:10b6:3:ee::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:06:45 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT050.mail.protection.outlook.com (10.13.5.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:06:45 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:06:44 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:06:44 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfs4-000F6q-1L; Wed, 01 Sep 2021 23:06:44 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f479392f-0bb3-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W9cc6jUikAlp+4tIMYtHViI3oxKr/q1xm+LoyryDZHotnMiUXsZgpfvUIHty6EejDMZNwtXqhJ4BzJnBD6K5nNAmAqrk9sTOElDdhpOYjgcohynI6CCOkXXzBYScsJAuXa2CVB3U6mQD5XbQql66mkorGckbhNeOU3mjNbNIeNQke9JP1vUyJSbQVZEctoLMoAqeumBjLgBNgYB63xhURgjNno9VkV5gTJRbfg6vfXG1qFbG4vrL50If1CPtKfkIitJj0JHTgqOO6Yh+aB0P8m2vBB0CyS3LtGyNnheKWa3Uxhpm+8hbCbCsruwx/aHDLp7k4ms0dh1xcjiMwnsZEw== 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-SenderADCheck; bh=p0sULzvu56yUkRR8j2QyEg/IiWAf0h/83PzvUjdhg/o=; b=mPdDmT3Baq+YiuR8uzEKBZhOsWrbumyFJsNnoIyMcvi0YQbxAdwVPtm00y9H40s7hz0zmfqtFyw7W/uyr6se3CD0xoafNwty2IuJ5rhCn9oe1kce/lI+kqxLGhvnROdoaVygFtThXelxQ/72qCSSM/R8ZmkHsZdeb/q3mFZ3YwMcPc83A64ReGEjREV5o+U3BmqrA3KRAXFDWlyLzJ7PL6nfGEmXCks8KtbINCmOwG2SC5JVbb1mw5pVNk1Z9OBSpQH+mtPE+zhsIX5fP60GE8mrxD+Ct6/mT+1GlOMIkVdlMG4RAFp2duNGaJnYxYKpw3x/UlRzsOXCGabQJU4C8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p0sULzvu56yUkRR8j2QyEg/IiWAf0h/83PzvUjdhg/o=; b=TiuU8dH4jgG+X2FlI0nGaDbqiNe+3eB17iIgiAudaWv47XmqislETrrLTz1wKXNThHGL0Jc4aCKMr+LI+L4lpEy4DEwj/TFVQmJCkQax8Dz0rhWqm9aEM/KVzmnn3D1dx5pz+rLxqrZLLwhBfN0oU3pt5UWQgndjjWPmbHhdUaQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Volodymyr Babchuk Subject: [XEN][RFC PATCH 01/13] device tree: Remove __init from function type Date: Wed, 1 Sep 2021 23:05:51 -0700 Message-ID: <1630562763-390068-2-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b402bf5-966b-4cbd-aa4a-08d96dd7d797 X-MS-TrafficTypeDiagnostic: DM6PR02MB4218: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0HMU2JX5WpfuP5g1RAWmdCLTpQ2YBrd+IW8uYGBCTUstQQxgphy0rUMYUt6hGkyZyazn4d/7zTjiT6Qs9aBLxgrUa1osuklJGTortSVQXmNa2Fk1PSvTS5UZ7XopWxT9ACqkIQ3QmUrWlONzxiztbYVJyAUzffYwkSfPxq9ylwe7eebs5mpWjHQ2md5gsBGbmuYeuZ6UXogEiNyruqJvRmJ9B9wW61t5hkmjSZZac8CBSicVuKJxF81n3gO73wrmUMgpDwrqah9ZOoUGPj12ng8p9163AHDUA18F3OzYihHUMDpOxjbzQ035AUO8q8SDDmer1bzZOR94FLB2IeZ9VxOx47Vb+bH+/7g5SJRpKlK2vl9XMeaOVSvkp3vLoegbmPx2ECrc3JNdsd1nCYyso95LMSI4+nqXCjRdoeJs3U28xgo1xxfy0mBJwgF1seqyGds8TOOp1NIZKQymAFlQ3cO3oSollbCjTlUJtwRgqRRZljP1yvcPFckjTJoih728lyyHXZkjd3GiDAh+WE338kkxxmJNZAUGmjrI57OGqXLgosygNdf+ILmpSHOnT0L4HWczSOZ0843VoMjjJVzpmS4M7QXJriz5w/fIyG6xhZG9y92GXLLzYoRgbhspZpV8gFj3jPhEoBOTSVTvY8Nv9RplCal5xwO844n62nAyeOX3+p/Gy6IHbfhKGK2x7pzUYBrOYaq9M2DM1DnXcP2pITiYQM4+Ef5fVAQuiqVuJk8= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(6666004)(2906002)(54906003)(508600001)(8936002)(8676002)(2616005)(70206006)(426003)(6916009)(36756003)(5660300002)(7696005)(36860700001)(83380400001)(36906005)(82310400003)(26005)(336012)(316002)(4326008)(70586007)(356005)(9786002)(186003)(47076005)(7636003)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:06:45.1163 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b402bf5-966b-4cbd-aa4a-08d96dd7d797 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT050.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4218 Change function type of following function to access during runtime: 1. handle_device_interrupt() 2. map_irq_to_domain() 3. map_range_to_domain() 4. unflatten_dt_node() 5. unflatten_device_tree() Remove .init from domain_build.o and move map_range_data declaration to domain_build.h. These changes are done to support the dynamic programming of a nodes where an overlay node will be added to fdt and unflattened node will be added to dt_host. Furthermore, irq and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal --- xen/arch/arm/Makefile | 2 +- xen/arch/arm/domain_build.c | 15 ++++----------- xen/common/device_tree.c | 18 +++++++++--------- xen/include/asm-arm/domain_build.h | 10 ++++++++++ xen/include/xen/device_tree.h | 5 +++++ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 3d3b97b..bef4517 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -15,7 +15,7 @@ obj-y += decode.o obj-y += device.o obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o -obj-y += domain_build.init.o +obj-y += domain_build.o obj-y += domctl.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += gic.o diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 206038d..3a457d3 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -47,12 +47,6 @@ static int __init parse_dom0_mem(const char *s) } custom_param("dom0_mem", parse_dom0_mem); -struct map_range_data -{ - struct domain *d; - p2m_type_t p2mt; -}; - /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) @@ -1144,7 +1138,7 @@ int __init make_chosen_node(const struct kernel_info *kinfo) return res; } -int __init map_irq_to_domain(struct domain *d, unsigned int irq, +int map_irq_to_domain(struct domain *d, unsigned int irq, bool need_mapping, const char *devname) { int res; @@ -1210,7 +1204,7 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, return 0; } -static int __init map_range_to_domain(const struct dt_device_node *dev, +int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, void *data) { @@ -1300,9 +1294,8 @@ static int __init map_device_children(struct domain *d, * < 0 error * 0 success */ -static int __init handle_device_interrupts(struct domain *d, - struct dt_device_node *dev, - bool need_mapping) +int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping) { unsigned int i, nirq; int res; diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 03d25a8..cda21be 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1750,12 +1750,12 @@ int dt_count_phandle_with_args(const struct dt_device_node *np, * @allnextpp: pointer to ->allnext from last allocated device_node * @fpsize: Size of the node path up at the current depth. */ -static unsigned long __init unflatten_dt_node(const void *fdt, - unsigned long mem, - unsigned long *p, - struct dt_device_node *dad, - struct dt_device_node ***allnextpp, - unsigned long fpsize) +static unsigned long unflatten_dt_node(const void *fdt, + unsigned long mem, + unsigned long *p, + struct dt_device_node *dad, + struct dt_device_node ***allnextpp, + unsigned long fpsize) { struct dt_device_node *np; struct dt_property *pp, **prev_pp = NULL; @@ -1986,7 +1986,7 @@ static unsigned long __init unflatten_dt_node(const void *fdt, } /** - * __unflatten_device_tree - create tree of device_nodes from flat blob + * unflatten_device_tree - create tree of device_nodes from flat blob * * unflattens a device-tree, creating the * tree of struct device_node. It also fills the "name" and "type" @@ -1995,7 +1995,7 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, +void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) { unsigned long start, mem, size; @@ -2118,7 +2118,7 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - __unflatten_device_tree(device_tree_flattened, &dt_host); + unflatten_device_tree(device_tree_flattened, &dt_host); dt_alias_scan(); } diff --git a/xen/include/asm-arm/domain_build.h b/xen/include/asm-arm/domain_build.h index 34ceddc..17449b1 100644 --- a/xen/include/asm-arm/domain_build.h +++ b/xen/include/asm-arm/domain_build.h @@ -4,10 +4,20 @@ #include #include +struct map_range_data +{ + struct domain *d; + p2m_type_t p2mt; +}; + int map_irq_to_domain(struct domain *d, unsigned int irq, bool need_mapping, const char *devname); int make_chosen_node(const struct kernel_info *kinfo); void evtchn_allocate(struct domain *d); +int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping); +int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, + void *data); #ifndef CONFIG_ACPI static inline int prepare_acpi(struct domain *d, struct kernel_info *kinfo) diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index b02696b..a4e98a7 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -177,6 +177,11 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/* + * unflatten any device tree. + */ +void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes); + /** * IRQ translation callback * TODO: For the moment we assume that we only have ONE From patchwork Thu Sep 2 06:05:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C76AC43214 for ; Thu, 2 Sep 2021 06:51:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B13CF60C3E for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B13CF60C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176913.322087 (Exim 4.92) (envelope-from ) id 1mLgYr-0004t7-0L; Thu, 02 Sep 2021 06:50:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176913.322087; Thu, 02 Sep 2021 06:50:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYq-0004qA-Mm; Thu, 02 Sep 2021 06:50:56 +0000 Received: by outflank-mailman (input) for mailman id 176913; Thu, 02 Sep 2021 06:07:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsP-0004aK-62 for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:05 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:7ea9::620]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8dbdcee9-9b09-417a-9938-75d68b68fcde; Thu, 02 Sep 2021 06:07:04 +0000 (UTC) Received: from SN6PR08CA0015.namprd08.prod.outlook.com (2603:10b6:805:66::28) by DM6PR02MB5963.namprd02.prod.outlook.com (2603:10b6:5:150::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Thu, 2 Sep 2021 06:07:01 +0000 Received: from SN1NAM02FT0033.eop-nam02.prod.protection.outlook.com (2603:10b6:805:66:cafe::27) by SN6PR08CA0015.outlook.office365.com (2603:10b6:805:66::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:01 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0033.mail.protection.outlook.com (10.97.5.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:00 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:06:53 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:06:53 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsD-000F6q-LT; Wed, 01 Sep 2021 23:06:53 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8dbdcee9-9b09-417a-9938-75d68b68fcde ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kjYN5gRN41ONS/9py890LcpPZatY8XZoRIXzL4G1r2Fv+MDCZ6TA1BJpViPe9TMa95LQq249H/uWXqzYGBca1ndVn8vRQslgXx68qicKNWOFYiB9gclZjFvJu+2s+eOkpDIKc8cZfRjaiz3KGHNZmHag77JSio/RziVaNqnUrxpVUgCiGVdbvjBvFdT9iIyDPEhdfCzZtmWNj8otE0U/t3MEHxHLHjuyGo/lLTvAFZ6vTDAOp1+nfWbzCUUeo7jzEgqAX0C15cEec9fEUtmmJobhXxkDaJVI+U7jqv7tIgC99xpi+fW5dBEZtVZkT/jIJRSbw+HqxBuXCvxU6QbglA== 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; bh=ZeeTflOXr2fLy1zXz1tSECVgWqlU5geTYJsntNlox3s=; b=OF+IgvEhO5Y5P+PZkSDmLjnOguHEuvAr7js1bLekz+GPSoYqZS4ZvstfYo+XHHrB2pSiX9z9pgRmuw3UBl8w9n5tZ9rINAG1Md+0QpyQBh64B+rdbFxcmD3j1Ata26vC9AOzbNI7XeBEGcQeliqMrX6qYB/FCgzv3luuvIbfLy4kfnC1jAUcwtw/H5w9jcnbeIllWoQDN0PPiHWt+afr/AWdfz5el+im+AEc0ZraXq9vafa6zLhGWOmysMMFRFHsZkvMl6XMZqFqJiAMFp7bfpLAJwLSZ/1+qIMJCNZnEPQEJNJVGZ/KSfkfO9g7Y1gMWyXNYu+Z6DKy74qMI0QoQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZeeTflOXr2fLy1zXz1tSECVgWqlU5geTYJsntNlox3s=; b=eo4dZRj8Dg/W/uPTz4yYReeQwF2MlpnkcUwpSlWoSbdvtIdY2FQoM9GT3vHowOSGar5hcJNf8m1nxWchrO/Ih7Pf1LJr5rlO6WyVJEwxpox5N5MDDGe5B54r9T7YSKdrE3dHCwNwZS3CbXh0REORFjjw7Uy2jflkVIeDcko72PU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 02/13] libfdt: Keep fdt functions after init. Date: Wed, 1 Sep 2021 23:05:52 -0700 Message-ID: <1630562763-390068-3-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b4bb6bb-5988-4c66-fc7d-08d96dd7e0bc X-MS-TrafficTypeDiagnostic: DM6PR02MB5963: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:162; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BMAij+jdIAVuLQQq++CAx7Fjpjid4kCxlOJKB2jkx8H22EVbZIYETpXZY/UCpQf/T2eT7XXOTWRRjj8OF2mjIeVhcDSjAXf2TXVcDU2nWjOBSl4tDRrZQfm6q7mAIxfBzj4zFCy4zmpKJfisMkJPsQPL4MIAs8c04MIszjuOfyeCALzoSLlpUy5gGw88m6lLR0wgiuFFNGj42Cpfe8kB98CAheKbvbTFYNIrTE84nFqeftyoDOzR02CYdRR+ddYaf5EfOoOMRHrsgOSSBoORg2sF67apzaLYJ1tpCb/Z8xO3Bnomk3rNqcVkcqCvV78T0bKwskjGuJutelYrTPIdUohIe1FdNCeGsKrHwCeEDTM9fveL5mYqHR+eur7B0iqImCEreEFDz/uS9/x74uzGUeAZ3dgTnCNq0XPc5WiBEYXSQeIIBNFxZxuD9uy/yvp+bLCeVvjsTcZUvWRq9BO4CTj2yISC+0KAdAa5Xun7PlWMHnbRje3B2iLunyjgLwI+4CuVXa4lSAArDotueBp0wsy4sUia65pDcBvPZkeqQP1jA5ymA5daNrjsvW7Npq61RMRGUWVeDyX5hjatss6JDfroF2Kp4jXwhlI3xmMB0FJxCwulIZWvQo/dx8oEssY92/wNy1h8FraBUd7oO9qDIRGsoxCrhJ6x84O5jAlATBkOmsXWEOqwihkB1J+aJLRSAdVZISWikNhQ5mj+tO7dhxHgvVbObyCnivnsMsMeIYo= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(346002)(396003)(39860400002)(376002)(136003)(46966006)(36840700001)(4326008)(356005)(70586007)(336012)(107886003)(426003)(478600001)(82310400003)(70206006)(36860700001)(6916009)(2616005)(47076005)(186003)(7636003)(26005)(83380400001)(82740400003)(5660300002)(9786002)(54906003)(7696005)(8936002)(36756003)(2906002)(8676002)(36906005)(316002)(4744005)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:00.4714 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b4bb6bb-5988-4c66-fc7d-08d96dd7e0bc X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0033.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB5963 Keep libfdt library functionalities after boot of hw_domain. This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Signed-off-by: Vikram Garhwal --- xen/common/libfdt/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile index 6bd207c..8002f8c 100644 --- a/xen/common/libfdt/Makefile +++ b/xen/common/libfdt/Makefile @@ -1,7 +1,6 @@ include Makefile.libfdt SECTIONS := text data $(SPECIAL_DATA_SECTIONS) -OBJCOPYFLAGS := $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) obj-y += libfdt.o nocov-y += libfdt.o From patchwork Thu Sep 2 06:05:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23EBFC43216 for ; Thu, 2 Sep 2021 06:51:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B1EB260FC0 for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B1EB260FC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176912.322080 (Exim 4.92) (envelope-from ) id 1mLgYq-0004la-JG; Thu, 02 Sep 2021 06:50:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176912.322080; Thu, 02 Sep 2021 06:50:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYq-0004l5-DG; Thu, 02 Sep 2021 06:50:56 +0000 Received: by outflank-mailman (input) for mailman id 176912; Thu, 02 Sep 2021 06:07:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsO-0004aE-Nu for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:04 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (unknown [40.107.236.63]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fd80c276-0bb3-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:02 +0000 (UTC) Received: from DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) by BN7PR02MB4211.namprd02.prod.outlook.com (2603:10b6:406:fc::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:06:59 +0000 Received: from DM3NAM02FT042.eop-nam02.prod.protection.outlook.com (2603:10b6:0:57:cafe::58) by DM3PR12CA0089.outlook.office365.com (2603:10b6:0:57::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 06:06:59 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT042.mail.protection.outlook.com (10.13.4.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:06:58 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:06:56 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:06:56 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsG-000F6q-6V; Wed, 01 Sep 2021 23:06:56 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fd80c276-0bb3-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6Vc4VFGnNuCCjRMR92oBl1bAZff2gHkQsaMvWJXlyY7ssCfoaZvdezkRw+D+7ISyeq/qMDSjl7kbYmvkJzBkz9SdCRIJwyPEe/NjbMCZ9veKiS1a5mJYM2wkeS/RdoA+Hapri/rlW/dwjOYfbA7Q1aNIsJi82YWAflviuIxk2K4r0XAaR/ECDp/MxCXtPNHwOphzdcG8lj60/Ir862yHzu+nj3KRU+LT8AsbDpS3dBRcV/2gE0Vw3mg3Lms/odAE2WpZBOpPpjfpFIjRY6HbXHOLoF2ry7/Nl6Eolf/EC3+iEwf1FXuoc5oqxHiO+NAtj/9lRmp2l0nRbp7Y+CH0w== 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-SenderADCheck; bh=FBIDlGqTHEriiyE7H+BVFfcsrCknmNO0E31FG6ZulT4=; b=Sun1v8s7rdBMypKl7wq30b8gHJPwCCBjAd+LZIlTy5RKSVCuQ+JFQUIrpkfuO3iPgIKo06YrM7jJcPj6d+htlJ5SBc8kZ4l9awvjC5pJy7PWXsQzPDiwIJS3CPH3h7BRc7FnaIDyA/ioFmpXjRIDCL68LDNSE/xzeq1fwhyxLf1q5rLqT/8DR2U57jvH2ZBl+RkXaFPK6vxPToe/YimCwGOBmc/hQYvwFQgc+BO+/LViin+qP14BwoDINaaBOfeUOuwlDJddA/WK+bNzaD5IGBpuXUCu9+VFwADGytv7ARragyJwe0gb7GxbyyCT0aDt1geqC2C/NwMo+70THM5xPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FBIDlGqTHEriiyE7H+BVFfcsrCknmNO0E31FG6ZulT4=; b=FLUVpOfTD/W41h3mRIDt6XCQPHQ/wBHdw8Bikj2+6WL57PbHWKTUgLJ0gE0kEgvb3ankE03JYrvY2bsnHXLb5TTv0dYxcGvRPbOa/v1jI/zZneHcpAM+rFK5HCWkhfPQX54SPftiqiT0jO6BbNS3PpGYAC6o71QPgXc6+kOZuMU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 03/13] libfdt: import fdt_overlay from Linux Date: Wed, 1 Sep 2021 23:05:53 -0700 Message-ID: <1630562763-390068-4-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89b30686-b128-471c-dc4a-08d96dd7df9f X-MS-TrafficTypeDiagnostic: BN7PR02MB4211: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:130; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yjqvN7lSYivxzQcNipLCYLIXc4ae1BOoYUmYeHnmYIX8DTF6TSc1F/EjcJYyBj0RClsoXswFmP1pYPOntxMIa/Hf38w7L2LRjfd2YgMKITmooPwKbBANrmeAuC0fkkRDfcfVwwbQvDcXxUTsj965VFj/Q2uqV81ebBusq/wlnH9iL0WjRpyGzDBhwriBTlENWG0K5/o5C3p/q6OKvCSn/euwvLHrcuTeO8WN8zruf2HbHEUqAEJvVmerEGAJ5Qv0z/TbdVRWZk/fZ9aybpC7SoXTUeZo4+VpqC79c14An8H1XdVyphz3f0uhjdBezhfsuQ+nyqd1YiftQQfhtaf3N9BIWJVoZfnwid0IshabO6fhIhhPDdr5dcnF8rr7DB13AJz3fasHb3l2+msrHuU1piCpLfe+Z3uEhCK0TfEmAuucqXUDPet+OUf19iAlx2lgDlF4oAtThVTbj4k8V/yDUOUmxsA88S+WMwxTqKJEyJcJDF4x/6SRG/gdHPNIr/PTmSDoeubHZw2q6jbIz4Qo/ADLGEFxyMyJVgMw6cv42042qrUvMuMNaKZhVYR3ElLt/FPUX7lhiiFYMXkjuOjfpGtp/6/GvTIpbNCBo7zfeDx98cB2lLvbSDu9z57yFzfWocbGA5/sP2Pjxw+lradx5EOpTiXWEZabxIYujNTRt2mKwALw27u1neemjh8bKWA9E62myncgQcz75B9GOfuoc1mpn+DgoKdKIZrBYp6LA84= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(83380400001)(2906002)(426003)(186003)(82310400003)(54906003)(508600001)(7636003)(6916009)(7696005)(30864003)(70206006)(5660300002)(316002)(47076005)(36906005)(36860700001)(9786002)(8676002)(2616005)(70586007)(336012)(4326008)(8936002)(356005)(6666004)(26005)(36756003)(107886003)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:06:58.5918 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89b30686-b128-471c-dc4a-08d96dd7df9f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT042.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB4211 Xen is missing fdt overlay functionalities. FDT overlay is required for changing the device tree nodes during run-time. fdt_overlay.c file is copied from Linux tree's following patch: commit: 6e9c9686d826564f44c93cdd6f111b1c0a9dc224 scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea121 Signed-off-by: Vikram Garhwal --- xen/common/libfdt/fdt_overlay.c | 882 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 882 insertions(+) create mode 100644 xen/common/libfdt/fdt_overlay.c diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c new file mode 100644 index 0000000..d217e79 --- /dev/null +++ b/xen/common/libfdt/fdt_overlay.c @@ -0,0 +1,882 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * libfdt - Flat Device Tree manipulation + * Copyright (C) 2016 Free Electrons + * Copyright (C) 2016 NextThing Co. + */ +#include "libfdt_env.h" + +#include +#include + +#include "libfdt_internal.h" + +/** + * overlay_get_target_phandle - retrieves the target phandle of a fragment + * @fdto: pointer to the device tree overlay blob + * @fragment: node offset of the fragment in the overlay + * + * overlay_get_target_phandle() retrieves the target phandle of an + * overlay fragment when that fragment uses a phandle (target + * property) instead of a path (target-path property). + * + * returns: + * the phandle pointed by the target property + * 0, if the phandle was not found + * -1, if the phandle was malformed + */ +static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) +{ + const fdt32_t *val; + int len; + + val = fdt_getprop(fdto, fragment, "target", &len); + if (!val) + return 0; + + if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1)) + return (uint32_t)-1; + + return fdt32_to_cpu(*val); +} + +/** + * overlay_get_target - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * overlay_get_target() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targeting is + * done (through a phandle or a path) + * + * returns: + * the targeted node offset in the base device tree + * Negative error code on error + */ +static int overlay_get_target(const void *fdt, const void *fdto, + int fragment, char const **pathp) +{ + uint32_t phandle; + const char *path = NULL; + int path_len = 0, ret; + + /* Try first to do a phandle based lookup */ + phandle = overlay_get_target_phandle(fdto, fragment); + if (phandle == (uint32_t)-1) + return -FDT_ERR_BADPHANDLE; + + /* no phandle, try path */ + if (!phandle) { + /* And then a path based lookup */ + path = fdt_getprop(fdto, fragment, "target-path", &path_len); + if (path) + ret = fdt_path_offset(fdt, path); + else + ret = path_len; + } else + ret = fdt_node_offset_by_phandle(fdt, phandle); + + /* + * If we haven't found either a target or a + * target-path property in a node that contains a + * __overlay__ subnode (we wouldn't be called + * otherwise), consider it a improperly written + * overlay + */ + if (ret < 0 && path_len == -FDT_ERR_NOTFOUND) + ret = -FDT_ERR_BADOVERLAY; + + /* return on error */ + if (ret < 0) + return ret; + + /* return pointer to path (if available) */ + if (pathp) + *pathp = path ? path : NULL; + + return ret; +} + +/** + * overlay_phandle_add_offset - Increases a phandle by an offset + * @fdt: Base device tree blob + * @node: Device tree overlay blob + * @name: Name of the property to modify (phandle or linux,phandle) + * @delta: offset to apply + * + * overlay_phandle_add_offset() increments a node phandle by a given + * offset. + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int overlay_phandle_add_offset(void *fdt, int node, + const char *name, uint32_t delta) +{ + const fdt32_t *val; + uint32_t adj_val; + int len; + + val = fdt_getprop(fdt, node, name, &len); + if (!val) + return len; + + if (len != sizeof(*val)) + return -FDT_ERR_BADPHANDLE; + + adj_val = fdt32_to_cpu(*val); + if ((adj_val + delta) < adj_val) + return -FDT_ERR_NOPHANDLES; + + adj_val += delta; + if (adj_val == (uint32_t)-1) + return -FDT_ERR_NOPHANDLES; + + return fdt_setprop_inplace_u32(fdt, node, name, adj_val); +} + +/** + * overlay_adjust_node_phandles - Offsets the phandles of a node + * @fdto: Device tree overlay blob + * @node: Offset of the node we want to adjust + * @delta: Offset to shift the phandles of + * + * overlay_adjust_node_phandles() adds a constant to all the phandles + * of a given node. This is mainly use as part of the overlay + * application process, when we want to update all the overlay + * phandles to not conflict with the overlays of the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_adjust_node_phandles(void *fdto, int node, + uint32_t delta) +{ + int child; + int ret; + + ret = overlay_phandle_add_offset(fdto, node, "phandle", delta); + if (ret && ret != -FDT_ERR_NOTFOUND) + return ret; + + ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta); + if (ret && ret != -FDT_ERR_NOTFOUND) + return ret; + + fdt_for_each_subnode(child, fdto, node) { + ret = overlay_adjust_node_phandles(fdto, child, delta); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay + * @fdto: Device tree overlay blob + * @delta: Offset to shift the phandles of + * + * overlay_adjust_local_phandles() adds a constant to all the + * phandles of an overlay. This is mainly use as part of the overlay + * application process, when we want to update all the overlay + * phandles to not conflict with the overlays of the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_adjust_local_phandles(void *fdto, uint32_t delta) +{ + /* + * Start adjusting the phandles from the overlay root + */ + return overlay_adjust_node_phandles(fdto, 0, delta); +} + +/** + * overlay_update_local_node_references - Adjust the overlay references + * @fdto: Device tree overlay blob + * @tree_node: Node offset of the node to operate on + * @fixup_node: Node offset of the matching local fixups node + * @delta: Offset to shift the phandles of + * + * overlay_update_local_nodes_references() update the phandles + * pointing to a node within the device tree overlay by adding a + * constant delta. + * + * This is mainly used as part of a device tree application process, + * where you want the device tree overlays phandles to not conflict + * with the ones from the base device tree before merging them. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_update_local_node_references(void *fdto, + int tree_node, + int fixup_node, + uint32_t delta) +{ + int fixup_prop; + int fixup_child; + int ret; + + fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { + const fdt32_t *fixup_val; + const char *tree_val; + const char *name; + int fixup_len; + int tree_len; + int i; + + fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, + &name, &fixup_len); + if (!fixup_val) + return fixup_len; + + if (fixup_len % sizeof(uint32_t)) + return -FDT_ERR_BADOVERLAY; + fixup_len /= sizeof(uint32_t); + + tree_val = fdt_getprop(fdto, tree_node, name, &tree_len); + if (!tree_val) { + if (tree_len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + + return tree_len; + } + + for (i = 0; i < fixup_len; i++) { + fdt32_t adj_val; + uint32_t poffset; + + poffset = fdt32_to_cpu(fixup_val[i]); + + /* + * phandles to fixup can be unaligned. + * + * Use a memcpy for the architectures that do + * not support unaligned accesses. + */ + memcpy(&adj_val, tree_val + poffset, sizeof(adj_val)); + + adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta); + + ret = fdt_setprop_inplace_namelen_partial(fdto, + tree_node, + name, + strlen(name), + poffset, + &adj_val, + sizeof(adj_val)); + if (ret == -FDT_ERR_NOSPACE) + return -FDT_ERR_BADOVERLAY; + + if (ret) + return ret; + } + } + + fdt_for_each_subnode(fixup_child, fdto, fixup_node) { + const char *fixup_child_name = fdt_get_name(fdto, fixup_child, + NULL); + int tree_child; + + tree_child = fdt_subnode_offset(fdto, tree_node, + fixup_child_name); + if (tree_child == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + if (tree_child < 0) + return tree_child; + + ret = overlay_update_local_node_references(fdto, + tree_child, + fixup_child, + delta); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_update_local_references - Adjust the overlay references + * @fdto: Device tree overlay blob + * @delta: Offset to shift the phandles of + * + * overlay_update_local_references() update all the phandles pointing + * to a node within the device tree overlay by adding a constant + * delta to not conflict with the base overlay. + * + * This is mainly used as part of a device tree application process, + * where you want the device tree overlays phandles to not conflict + * with the ones from the base device tree before merging them. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_update_local_references(void *fdto, uint32_t delta) +{ + int fixups; + + fixups = fdt_path_offset(fdto, "/__local_fixups__"); + if (fixups < 0) { + /* There's no local phandles to adjust, bail out */ + if (fixups == -FDT_ERR_NOTFOUND) + return 0; + + return fixups; + } + + /* + * Update our local references from the root of the tree + */ + return overlay_update_local_node_references(fdto, 0, fixups, + delta); +} + +/** + * overlay_fixup_one_phandle - Set an overlay phandle to the base one + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * @symbols_off: Node offset of the symbols node in the base device tree + * @path: Path to a node holding a phandle in the overlay + * @path_len: number of path characters to consider + * @name: Name of the property holding the phandle reference in the overlay + * @name_len: number of name characters to consider + * @poffset: Offset within the overlay property where the phandle is stored + * @label: Label of the node referenced by the phandle + * + * overlay_fixup_one_phandle() resolves an overlay phandle pointing to + * a node in the base device tree. + * + * This is part of the device tree overlay application process, when + * you want all the phandles in the overlay to point to the actual + * base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_one_phandle(void *fdt, void *fdto, + int symbols_off, + const char *path, uint32_t path_len, + const char *name, uint32_t name_len, + int poffset, const char *label) +{ + const char *symbol_path; + uint32_t phandle; + fdt32_t phandle_prop; + int symbol_off, fixup_off; + int prop_len; + + if (symbols_off < 0) + return symbols_off; + + symbol_path = fdt_getprop(fdt, symbols_off, label, + &prop_len); + if (!symbol_path) + return prop_len; + + symbol_off = fdt_path_offset(fdt, symbol_path); + if (symbol_off < 0) + return symbol_off; + + phandle = fdt_get_phandle(fdt, symbol_off); + if (!phandle) + return -FDT_ERR_NOTFOUND; + + fixup_off = fdt_path_offset_namelen(fdto, path, path_len); + if (fixup_off == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + if (fixup_off < 0) + return fixup_off; + + phandle_prop = cpu_to_fdt32(phandle); + return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, + name, name_len, poffset, + &phandle_prop, + sizeof(phandle_prop)); +}; + +/** + * overlay_fixup_phandle - Set an overlay phandle to the base one + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * @symbols_off: Node offset of the symbols node in the base device tree + * @property: Property offset in the overlay holding the list of fixups + * + * overlay_fixup_phandle() resolves all the overlay phandles pointed + * to in a __fixups__ property, and updates them to match the phandles + * in use in the base device tree. + * + * This is part of the device tree overlay application process, when + * you want all the phandles in the overlay to point to the actual + * base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, + int property) +{ + const char *value; + const char *label; + int len; + + value = fdt_getprop_by_offset(fdto, property, + &label, &len); + if (!value) { + if (len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + + return len; + } + + do { + const char *path, *name, *fixup_end; + const char *fixup_str = value; + uint32_t path_len, name_len; + uint32_t fixup_len; + char *sep, *endptr; + int poffset, ret; + + fixup_end = memchr(value, '\0', len); + if (!fixup_end) + return -FDT_ERR_BADOVERLAY; + fixup_len = fixup_end - fixup_str; + + len -= fixup_len + 1; + value += fixup_len + 1; + + path = fixup_str; + sep = memchr(fixup_str, ':', fixup_len); + if (!sep || *sep != ':') + return -FDT_ERR_BADOVERLAY; + + path_len = sep - path; + if (path_len == (fixup_len - 1)) + return -FDT_ERR_BADOVERLAY; + + fixup_len -= path_len + 1; + name = sep + 1; + sep = memchr(name, ':', fixup_len); + if (!sep || *sep != ':') + return -FDT_ERR_BADOVERLAY; + + name_len = sep - name; + if (!name_len) + return -FDT_ERR_BADOVERLAY; + + poffset = strtoul(sep + 1, &endptr, 10); + if ((*endptr != '\0') || (endptr <= (sep + 1))) + return -FDT_ERR_BADOVERLAY; + + ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off, + path, path_len, name, name_len, + poffset, label); + if (ret) + return ret; + } while (len > 0); + + return 0; +} + +/** + * overlay_fixup_phandles - Resolve the overlay phandles to the base + * device tree + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_fixup_phandles() resolves all the overlay phandles pointing + * to nodes in the base device tree. + * + * This is one of the steps of the device tree overlay application + * process, when you want all the phandles in the overlay to point to + * the actual base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_phandles(void *fdt, void *fdto) +{ + int fixups_off, symbols_off; + int property; + + /* We can have overlays without any fixups */ + fixups_off = fdt_path_offset(fdto, "/__fixups__"); + if (fixups_off == -FDT_ERR_NOTFOUND) + return 0; /* nothing to do */ + if (fixups_off < 0) + return fixups_off; + + /* And base DTs without symbols */ + symbols_off = fdt_path_offset(fdt, "/__symbols__"); + if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND))) + return symbols_off; + + fdt_for_each_property_offset(property, fdto, fixups_off) { + int ret; + + ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_apply_node - Merges a node into the base device tree + * @fdt: Base Device Tree blob + * @target: Node offset in the base device tree to apply the fragment to + * @fdto: Device tree overlay blob + * @node: Node offset in the overlay holding the changes to merge + * + * overlay_apply_node() merges a node into a target base device tree + * node pointed. + * + * This is part of the final step in the device tree overlay + * application process, when all the phandles have been adjusted and + * resolved and you just have to merge overlay into the base device + * tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_apply_node(void *fdt, int target, + void *fdto, int node) +{ + int property; + int subnode; + + fdt_for_each_property_offset(property, fdto, node) { + const char *name; + const void *prop; + int prop_len; + int ret; + + prop = fdt_getprop_by_offset(fdto, property, &name, + &prop_len); + if (prop_len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + if (prop_len < 0) + return prop_len; + + ret = fdt_setprop(fdt, target, name, prop, prop_len); + if (ret) + return ret; + } + + fdt_for_each_subnode(subnode, fdto, node) { + const char *name = fdt_get_name(fdto, subnode, NULL); + int nnode; + int ret; + + nnode = fdt_add_subnode(fdt, target, name); + if (nnode == -FDT_ERR_EXISTS) { + nnode = fdt_subnode_offset(fdt, target, name); + if (nnode == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + } + + if (nnode < 0) + return nnode; + + ret = overlay_apply_node(fdt, nnode, fdto, subnode); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_merge - Merge an overlay into its base device tree + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_merge() merges an overlay into its base device tree. + * + * This is the next to last step in the device tree overlay application + * process, when all the phandles have been adjusted and resolved and + * you just have to merge overlay into the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_merge(void *fdt, void *fdto) +{ + int fragment; + + fdt_for_each_subnode(fragment, fdto, 0) { + int overlay; + int target; + int ret; + + /* + * Each fragments will have an __overlay__ node. If + * they don't, it's not supposed to be merged + */ + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + if (overlay == -FDT_ERR_NOTFOUND) + continue; + + if (overlay < 0) + return overlay; + + target = overlay_get_target(fdt, fdto, fragment, NULL); + if (target < 0) + return target; + + ret = overlay_apply_node(fdt, target, fdto, overlay); + if (ret) + return ret; + } + + return 0; +} + +static int get_path_len(const void *fdt, int nodeoffset) +{ + int len = 0, namelen; + const char *name; + + FDT_RO_PROBE(fdt); + + for (;;) { + name = fdt_get_name(fdt, nodeoffset, &namelen); + if (!name) + return namelen; + + /* root? we're done */ + if (namelen == 0) + break; + + nodeoffset = fdt_parent_offset(fdt, nodeoffset); + if (nodeoffset < 0) + return nodeoffset; + len += namelen + 1; + } + + /* in case of root pretend it's "/" */ + if (len == 0) + len++; + return len; +} + +/** + * overlay_symbol_update - Update the symbols of base tree after a merge + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_symbol_update() updates the symbols of the base tree with the + * symbols of the applied overlay + * + * This is the last step in the device tree overlay application + * process, allowing the reference of overlay symbols by subsequent + * overlay operations. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_symbol_update(void *fdt, void *fdto) +{ + int root_sym, ov_sym, prop, path_len, fragment, target; + int len, frag_name_len, ret, rel_path_len; + const char *s, *e; + const char *path; + const char *name; + const char *frag_name; + const char *rel_path; + const char *target_path; + char *buf; + void *p; + + ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__"); + + /* if no overlay symbols exist no problem */ + if (ov_sym < 0) + return 0; + + root_sym = fdt_subnode_offset(fdt, 0, "__symbols__"); + + /* it no root symbols exist we should create them */ + if (root_sym == -FDT_ERR_NOTFOUND) + root_sym = fdt_add_subnode(fdt, 0, "__symbols__"); + + /* any error is fatal now */ + if (root_sym < 0) + return root_sym; + + /* iterate over each overlay symbol */ + fdt_for_each_property_offset(prop, fdto, ov_sym) { + path = fdt_getprop_by_offset(fdto, prop, &name, &path_len); + if (!path) + return path_len; + + /* verify it's a string property (terminated by a single \0) */ + if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1]) + return -FDT_ERR_BADVALUE; + + /* keep end marker to avoid strlen() */ + e = path + path_len; + + if (*path != '/') + return -FDT_ERR_BADVALUE; + + /* get fragment name first */ + s = strchr(path + 1, '/'); + if (!s) { + /* Symbol refers to something that won't end + * up in the target tree */ + continue; + } + + frag_name = path + 1; + frag_name_len = s - path - 1; + + /* verify format; safe since "s" lies in \0 terminated prop */ + len = sizeof("/__overlay__/") - 1; + if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) { + /* //__overlay__/ */ + rel_path = s + len; + rel_path_len = e - rel_path - 1; + } else if ((e - s) == len + && (memcmp(s, "/__overlay__", len - 1) == 0)) { + /* //__overlay__ */ + rel_path = ""; + rel_path_len = 0; + } else { + /* Symbol refers to something that won't end + * up in the target tree */ + continue; + } + + /* find the fragment index in which the symbol lies */ + ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, + frag_name_len); + /* not found? */ + if (ret < 0) + return -FDT_ERR_BADOVERLAY; + fragment = ret; + + /* an __overlay__ subnode must exist */ + ret = fdt_subnode_offset(fdto, fragment, "__overlay__"); + if (ret < 0) + return -FDT_ERR_BADOVERLAY; + + /* get the target of the fragment */ + ret = overlay_get_target(fdt, fdto, fragment, &target_path); + if (ret < 0) + return ret; + target = ret; + + /* if we have a target path use */ + if (!target_path) { + ret = get_path_len(fdt, target); + if (ret < 0) + return ret; + len = ret; + } else { + len = strlen(target_path); + } + + ret = fdt_setprop_placeholder(fdt, root_sym, name, + len + (len > 1) + rel_path_len + 1, &p); + if (ret < 0) + return ret; + + if (!target_path) { + /* again in case setprop_placeholder changed it */ + ret = overlay_get_target(fdt, fdto, fragment, &target_path); + if (ret < 0) + return ret; + target = ret; + } + + buf = p; + if (len > 1) { /* target is not root */ + if (!target_path) { + ret = fdt_get_path(fdt, target, buf, len + 1); + if (ret < 0) + return ret; + } else + memcpy(buf, target_path, len + 1); + + } else + len--; + + buf[len] = '/'; + memcpy(buf + len + 1, rel_path, rel_path_len); + buf[len + 1 + rel_path_len] = '\0'; + } + + return 0; +} + +int fdt_overlay_apply(void *fdt, void *fdto) +{ + uint32_t delta; + int ret; + + FDT_RO_PROBE(fdt); + FDT_RO_PROBE(fdto); + + ret = fdt_find_max_phandle(fdt, &delta); + if (ret) + goto err; + + ret = overlay_adjust_local_phandles(fdto, delta); + if (ret) + goto err; + + ret = overlay_update_local_references(fdto, delta); + if (ret) + goto err; + + ret = overlay_fixup_phandles(fdt, fdto); + if (ret) + goto err; + + ret = overlay_merge(fdt, fdto); + if (ret) + goto err; + + ret = overlay_symbol_update(fdt, fdto); + if (ret) + goto err; + + /* + * The overlay has been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + return 0; + +err: + /* + * The overlay might have been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + /* + * The base device tree might have been damaged, erase its + * magic. + */ + fdt_set_magic(fdt, ~0); + + return ret; +} From patchwork Thu Sep 2 06:05:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F4CC25AEC for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9694160FC0 for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9694160FC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176921.322112 (Exim 4.92) (envelope-from ) id 1mLgYs-0005Po-JV; Thu, 02 Sep 2021 06:50:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176921.322112; Thu, 02 Sep 2021 06:50:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYs-0005LP-69; Thu, 02 Sep 2021 06:50:58 +0000 Received: by outflank-mailman (input) for mailman id 176921; Thu, 02 Sep 2021 06:07:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsa-0004fO-NW for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:16 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (unknown [40.107.101.78]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 68a4c72f-d06d-41dc-b586-46d6db34e47a; Thu, 02 Sep 2021 06:07:13 +0000 (UTC) Received: from SA0PR11CA0205.namprd11.prod.outlook.com (2603:10b6:806:1bc::30) by DM6PR02MB4955.namprd02.prod.outlook.com (2603:10b6:5:11::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:07:11 +0000 Received: from SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com (2603:10b6:806:1bc:cafe::14) by SA0PR11CA0205.outlook.office365.com (2603:10b6:806:1bc::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20 via Frontend Transport; Thu, 2 Sep 2021 06:07:11 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0051.mail.protection.outlook.com (10.97.5.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:11 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:06:58 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:06:58 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsI-000F6q-7C; Wed, 01 Sep 2021 23:06:58 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 68a4c72f-d06d-41dc-b586-46d6db34e47a ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dTzketYN7Sz9QYVI5TRbaykYekb6lQdCGNL14wDwjJbJvkqKNVRJCetHXBYkG+hsmyd2Ec8byYIh61Gtd2EfhNv6hb1OZQmxvAJFlVSjrJZkajCzIt1gklA0SW5eD820aD3fY4CFtvmf0mHa94SgyWefsoiIGE2omU+sX7X4WRAdIDIj37C6YiSZNFG4wRBfqpdnLOqg8LqpIaElCJoPa4kc5jt69+btV+7MVARN50Zx3Vu9rB8/QzHdYkNWb1GzlmiZqCF5xKw4iScINXD4X6ROBD6N+iyo4cEObCCVMxtuUlz2qPvNKTSiqusuDCEyPbJEKHNJd6j+Xn2+B36tjQ== 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-SenderADCheck; bh=odPD3Pqm1GqjPKTu4SCQEahFowuxrRf5d2NDi//Xqhc=; b=b7t7Q08EDV9jbIAi9YacfuBNdYe5UT9DpmdR6zksyt/pmhLaGS2kRte8K2x4uJaEm1NWO9Op5HQKZ91pulo2xbQKc2MWcAy0iyGt0rNlJOvfWNZ1gfqN+kcnNhhAQx8niMQQNIUPx8MelvpDp/Fd3bftwrhxpk4quWX3He2RBQ5nXzbYfFQFv9e0fJitZRMvba7N4Y3o7tz2NiL25fwOOuTTo05iHtxSl4xZmQlB3eZTdGSssp9UAawVn9G00bkhmYYy9U/CihHVRADRV0qxkhHQEixrShWiwoU8Yqm8S+8kOvxPM8/FNRzvu7pMOFbq6E8hdCZ68Zl+zjWVxdZn7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=odPD3Pqm1GqjPKTu4SCQEahFowuxrRf5d2NDi//Xqhc=; b=ptPq88z/q1iJFHOMrdxAUhpYrrVwcYiB+PwZY66JsKYHwoqXy9IQ133PTfzXon9J80oEQU/sriailXFqa2EXkeJeejxPwYvTGTU1IemAuXExyfpRgWL+DL4VVKHZNNKqgRhkx+94la5pgFnFq/6i2nBjTrj/mRXo0cPoqY1nW4w= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 04/13] libfdt: Copy required libfdt functions from Linux Date: Wed, 1 Sep 2021 23:05:54 -0700 Message-ID: <1630562763-390068-5-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8327c211-e114-4ee9-c4a0-08d96dd7e711 X-MS-TrafficTypeDiagnostic: DM6PR02MB4955: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cnMudUiEYwg/DRZQQkVkoNMDqoPlKtpzwpPFJo7zR8JLQKmfQrcYbRsNCvbg5qnJkg+uaCcQwgsriP26Jxf2LXmVRuAYzfbj4Z/29wGNs0lLrQyqoJ+5zzUa693okFFhTgRSmPx3BmfeU14ssAhxNHLtwAzZyG5vLj5xVkiT3SyLaH5Zdhy5V6u+uni9bxXwxgR2RxqhgooqPAjciVrZGBSemg0bOlZyncSpCBfICq5SaIGN9WMJI+Z/GlWCQAgjK4Az3DcemyaqG9+vmIaQdWj4+crR+/P62B8QW58x9pCy2yuyFR647M43LHE6xXMwJDuf306VPsCITNoSYfD1UPK4Tv8wifiCrwDMkIgpVtR6IDJ5W4MOviwPdbQrjRwXOCmm4yWKqRVaZwjt2xGhaqRx2fL1IPLggcodKjr1nUN4IlsvdXPRtHXWubnPufa2NBth9VoYgZfKV/ccIqfqL1xhCePueVMrFBlc3G/EERsFKIqjS0JKygrwHqDCu17zmug8CRjf1/28MPDeO91F9bbAfPgQNxdiXH4yrCUveMJRy9KRCDuwEDd8bh1z+TJfrBsFm5i35botvPmsX3jLVxv7a4EjPNr1YQU1/5TkRbj7HmOOpgh6Ivmu6xQam2X7fAIBmCSUrTmj8S5YbyvBH1ZE5jYHC1gmojKwzCKjy4MB7jkNKU2xVGSKnYnpNIGk551FBZi2fpc28QysuVyu1qmgVEiKnhr11zBwZMf4euM= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(39860400002)(136003)(346002)(396003)(376002)(36840700001)(46966006)(47076005)(426003)(186003)(36756003)(107886003)(6666004)(8676002)(2616005)(7636003)(2906002)(70586007)(6916009)(70206006)(82310400003)(83380400001)(82740400003)(26005)(36906005)(336012)(356005)(316002)(478600001)(5660300002)(7696005)(4326008)(9786002)(54906003)(36860700001)(30864003)(8936002)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:11.0913 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8327c211-e114-4ee9-c4a0-08d96dd7e711 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4955 fdt_overlay.c uses a number of functions. Below is the list of functions copied from Linux tree(commid: 6e9c9686d826564f44c93cdd6f111b1c0a9dc224) to compile the fdt_overlay.c(): libfdt_internal.h: FDT_RO_PROBE() and can_assume(). libfdt.h: fdt_for_each_subnode(), fdt_get_max_phandle(), fdt_for_each_property_offset() and fdt_getprop_namelen_w(). fdt.c: fdt_ro_probe_(). fdt_ro.c: fdt_find_max_phandle(), fdt_path_offset_namelen() and fdt_path_offset(). fdt_rw.c: fdt_rw_probe_(), FDT_RW_PROBE(), fdt_del_last_string_(), fdt_setprop_placeholder() and fdt_setprop(). fdt_wip.c: fdt_setprop_inplace_namelen_partial(). Updated fdt_rw.c: _fdt_find_add_string() with required changes from Linux fdt_rw.c:fdt_find_add_string_(). Updated fdt_rw.c: _fdt_add_property() with required changes from Linux fdt_rw.c:fdt_find_add_string_(). Replaced strtoul() with simple_strtoull(). Signed-off-by: Vikram Garhwal --- xen/common/libfdt/Makefile.libfdt | 2 +- xen/common/libfdt/fdt.c | 35 ++++++ xen/common/libfdt/fdt_overlay.c | 6 +- xen/common/libfdt/fdt_ro.c | 52 ++++++-- xen/common/libfdt/fdt_rw.c | 81 +++++++++++-- xen/common/libfdt/fdt_wip.c | 20 ++++ xen/common/libfdt/libfdt_internal.h | 130 ++++++++++++++++++++ xen/include/xen/libfdt/libfdt.h | 230 +++++++++++++++++++++++++++++++++++- 8 files changed, 536 insertions(+), 20 deletions(-) diff --git a/xen/common/libfdt/Makefile.libfdt b/xen/common/libfdt/Makefile.libfdt index 91126c0..aea9d9b 100644 --- a/xen/common/libfdt/Makefile.libfdt +++ b/xen/common/libfdt/Makefile.libfdt @@ -6,5 +6,5 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h LIBFDT_VERSION = version.lds -LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c +LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c fdt_overlay.c LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) diff --git a/xen/common/libfdt/fdt.c b/xen/common/libfdt/fdt.c index bbc7717..55a9de6 100644 --- a/xen/common/libfdt/fdt.c +++ b/xen/common/libfdt/fdt.c @@ -53,6 +53,41 @@ #include "libfdt_internal.h" +/* + * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks + * that the given buffer contains what appears to be a flattened + * device tree with sane information in its header. + */ +int32_t fdt_ro_probe_(const void *fdt) +{ + uint32_t totalsize = fdt_totalsize(fdt); + + if (can_assume(VALID_DTB)) + return totalsize; + + if (fdt_magic(fdt) == FDT_MAGIC) { + /* Complete tree */ + if (!can_assume(LATEST)) { + if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) + return -FDT_ERR_BADVERSION; + if (fdt_last_comp_version(fdt) > + FDT_LAST_SUPPORTED_VERSION) + return -FDT_ERR_BADVERSION; + } + } else if (fdt_magic(fdt) == FDT_SW_MAGIC) { + /* Unfinished sequential-write blob */ + if (!can_assume(VALID_INPUT) && fdt_size_dt_struct(fdt) == 0) + return -FDT_ERR_BADSTATE; + } else { + return -FDT_ERR_BADMAGIC; + } + + if (totalsize < INT32_MAX) + return totalsize; + else + return -FDT_ERR_TRUNCATED; +} + int fdt_check_header(const void *fdt) { if (fdt_magic(fdt) == FDT_MAGIC) { diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index d217e79..15a8cdb 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -9,6 +9,7 @@ #include #include +#include #include "libfdt_internal.h" /** @@ -446,7 +447,8 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, const char *fixup_str = value; uint32_t path_len, name_len; uint32_t fixup_len; - char *sep, *endptr; + char *sep; + const char *endptr; int poffset, ret; fixup_end = memchr(value, '\0', len); @@ -476,7 +478,7 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, if (!name_len) return -FDT_ERR_BADOVERLAY; - poffset = strtoul(sep + 1, &endptr, 10); + poffset = simple_strtoull(sep + 1, &endptr, 10); if ((*endptr != '\0') || (endptr <= (sep + 1))) return -FDT_ERR_BADOVERLAY; diff --git a/xen/common/libfdt/fdt_ro.c b/xen/common/libfdt/fdt_ro.c index 36f9b48..383791d 100644 --- a/xen/common/libfdt/fdt_ro.c +++ b/xen/common/libfdt/fdt_ro.c @@ -86,6 +86,34 @@ static int _fdt_string_eq(const void *fdt, int stroffset, return (strlen(p) == len) && (memcmp(p, s, len) == 0); } +int fdt_find_max_phandle(const void *fdt, uint32_t *phandle) +{ + uint32_t max = 0; + int offset = -1; + + while (true) { + uint32_t value; + + offset = fdt_next_node(fdt, offset, NULL); + if (offset < 0) { + if (offset == -FDT_ERR_NOTFOUND) + break; + + return offset; + } + + value = fdt_get_phandle(fdt, offset); + + if (value > max) + max = value; + } + + if (phandle) + *phandle = max; + + return 0; +} + int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) { FDT_CHECK_HEADER(fdt); @@ -152,17 +180,17 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); } -int fdt_path_offset(const void *fdt, const char *path) +int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) { - const char *end = path + strlen(path); + const char *end = path + namelen; const char *p = path; int offset = 0; - FDT_CHECK_HEADER(fdt); + FDT_RO_PROBE(fdt); /* see if we have an alias */ if (*path != '/') { - const char *q = strchr(path, '/'); + const char *q = memchr(path, '/', end - p); if (!q) q = end; @@ -175,14 +203,15 @@ int fdt_path_offset(const void *fdt, const char *path) p = q; } - while (*p) { + while (p < end) { const char *q; - while (*p == '/') + while (*p == '/') { p++; - if (! *p) - return offset; - q = strchr(p, '/'); + if (p == end) + return offset; + } + q = memchr(p, '/', end - p); if (! q) q = end; @@ -196,6 +225,11 @@ int fdt_path_offset(const void *fdt, const char *path) return offset; } +int fdt_path_offset(const void *fdt, const char *path) +{ + return fdt_path_offset_namelen(fdt, path, strlen(path)); +} + const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) { const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); diff --git a/xen/common/libfdt/fdt_rw.c b/xen/common/libfdt/fdt_rw.c index 8b8cd25..fc53644 100644 --- a/xen/common/libfdt/fdt_rw.c +++ b/xen/common/libfdt/fdt_rw.c @@ -65,6 +65,30 @@ static int _fdt_blocks_misordered(const void *fdt, (fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt))); } +static int fdt_rw_probe_(void *fdt) +{ + if (can_assume(VALID_DTB)) + return 0; + FDT_RO_PROBE(fdt); + + if (!can_assume(LATEST) && fdt_version(fdt) < 17) + return -FDT_ERR_BADVERSION; + if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), + fdt_size_dt_struct(fdt))) + return -FDT_ERR_BADLAYOUT; + if (!can_assume(LATEST) && fdt_version(fdt) > 17) + fdt_set_version(fdt, 17); + + return 0; +} + +#define FDT_RW_PROBE(fdt) \ + { \ + int err_; \ + if ((err_ = fdt_rw_probe_(fdt)) != 0) \ + return err_; \ + } + static int _fdt_rw_check_header(void *fdt) { FDT_CHECK_HEADER(fdt); @@ -133,6 +157,14 @@ static int _fdt_splice_struct(void *fdt, void *p, return 0; } +/* Must only be used to roll back in case of error */ +static void fdt_del_last_string_(void *fdt, const char *s) +{ + int newlen = strlen(s) + 1; + + fdt_set_size_dt_strings(fdt, fdt_size_dt_strings(fdt) - newlen); +} + static int _fdt_splice_string(void *fdt, int newlen) { void *p = (char *)fdt @@ -146,7 +178,16 @@ static int _fdt_splice_string(void *fdt, int newlen) return 0; } -static int _fdt_find_add_string(void *fdt, const char *s) +/** + * New _fdt_find_add_string() - Find or allocate a string + * + * @fdt: pointer to the device tree to check/adjust + * @s: string to find/add + * @allocated: Set to 0 if the string was found, 1 if not found and so + * allocated. Ignored if can_assume(NO_ROLLBACK) + * @return offset of string in the string table (whether found or added) + */ +static int _fdt_find_add_string(void *fdt, const char *s, int *allocated) { char *strtab = (char *)fdt + fdt_off_dt_strings(fdt); const char *p; @@ -154,6 +195,9 @@ static int _fdt_find_add_string(void *fdt, const char *s) int len = strlen(s) + 1; int err; + if (!can_assume(NO_ROLLBACK)) + *allocated = 0; + p = _fdt_find_string(strtab, fdt_size_dt_strings(fdt), s); if (p) /* found it */ @@ -164,6 +208,9 @@ static int _fdt_find_add_string(void *fdt, const char *s) if (err) return err; + if (!can_assume(NO_ROLLBACK)) + *allocated = 1; + memcpy(new, s, len); return (new - strtab); } @@ -226,11 +273,12 @@ static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, int nextoffset; int namestroff; int err; + int allocated; if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) return nextoffset; - namestroff = _fdt_find_add_string(fdt, name); + namestroff = _fdt_find_add_string(fdt, name, &allocated); if (namestroff < 0) return namestroff; @@ -238,8 +286,12 @@ static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, proplen = sizeof(**prop) + FDT_TAGALIGN(len); err = _fdt_splice_struct(fdt, *prop, 0, proplen); - if (err) + if (err) { + /* Delete the string if we failed to add it */ + if (!can_assume(NO_ROLLBACK) && allocated) + fdt_del_last_string_(fdt, name); return err; + } (*prop)->tag = cpu_to_fdt32(FDT_PROP); (*prop)->nameoff = cpu_to_fdt32(namestroff); @@ -270,13 +322,13 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name) return 0; } -int fdt_setprop(void *fdt, int nodeoffset, const char *name, - const void *val, int len) +int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, + int len, void **prop_data) { struct fdt_property *prop; int err; - FDT_RW_CHECK_HEADER(fdt); + FDT_RW_PROBE(fdt); err = _fdt_resize_property(fdt, nodeoffset, name, len, &prop); if (err == -FDT_ERR_NOTFOUND) @@ -284,7 +336,22 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, if (err) return err; - memcpy(prop->data, val, len); + *prop_data = prop->data; + return 0; +} + +int fdt_setprop(void *fdt, int nodeoffset, const char *name, + const void *val, int len) +{ + void *prop_data; + int err; + + err = fdt_setprop_placeholder(fdt, nodeoffset, name, len, &prop_data); + if (err) + return err; + + if (len) + memcpy(prop_data, val, len); return 0; } diff --git a/xen/common/libfdt/fdt_wip.c b/xen/common/libfdt/fdt_wip.c index 2d1cac0..3f61085 100644 --- a/xen/common/libfdt/fdt_wip.c +++ b/xen/common/libfdt/fdt_wip.c @@ -53,6 +53,26 @@ #include "libfdt_internal.h" +int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, + const char *name, int namelen, + uint32_t idx, const void *val, + int len) +{ + void *propval; + int proplen; + + propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, + &proplen); + if (!propval) + return proplen; + + if ((unsigned)proplen < (len + idx)) + return -FDT_ERR_NOSPACE; + + memcpy((char *)propval + idx, val, len); + return 0; +} + int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, const void *val, int len) { diff --git a/xen/common/libfdt/libfdt_internal.h b/xen/common/libfdt/libfdt_internal.h index d50c4e1..523bcee 100644 --- a/xen/common/libfdt/libfdt_internal.h +++ b/xen/common/libfdt/libfdt_internal.h @@ -60,6 +60,14 @@ return err; \ } +int32_t fdt_ro_probe_(const void *fdt); +#define FDT_RO_PROBE(fdt) \ + { \ + int32_t totalsize_; \ + if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ + return totalsize_; \ + } + int _fdt_check_node_offset(const void *fdt, int offset); int _fdt_check_prop_offset(const void *fdt, int offset); const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); @@ -90,4 +98,126 @@ static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n) #define FDT_SW_MAGIC (~FDT_MAGIC) +/**********************************************************************/ +/* Checking controls */ +/**********************************************************************/ + +#ifndef FDT_ASSUME_MASK +#define FDT_ASSUME_MASK 0 +#endif + +/* + * Defines assumptions which can be enabled. Each of these can be enabled + * individually. For maximum safety, don't enable any assumptions! + * + * For minimal code size and no safety, use ASSUME_PERFECT at your own risk. + * You should have another method of validating the device tree, such as a + * signature or hash check before using libfdt. + * + * For situations where security is not a concern it may be safe to enable + * ASSUME_SANE. + */ +enum { + /* + * This does essentially no checks. Only the latest device-tree + * version is correctly handled. Inconsistencies or errors in the device + * tree may cause undefined behaviour or crashes. Invalid parameters + * passed to libfdt may do the same. + * + * If an error occurs when modifying the tree it may leave the tree in + * an intermediate (but valid) state. As an example, adding a property + * where there is insufficient space may result in the property name + * being added to the string table even though the property itself is + * not added to the struct section. + * + * Only use this if you have a fully validated device tree with + * the latest supported version and wish to minimise code size. + */ + ASSUME_PERFECT = 0xff, + + /* + * This assumes that the device tree is sane. i.e. header metadata + * and basic hierarchy are correct. + * + * With this assumption enabled, normal device trees produced by libfdt + * and the compiler should be handled safely. Malicious device trees and + * complete garbage may cause libfdt to behave badly or crash. Truncated + * device trees (e.g. those only partially loaded) can also cause + * problems. + * + * Note: Only checks that relate exclusively to the device tree itself + * (not the parameters passed to libfdt) are disabled by this + * assumption. This includes checking headers, tags and the like. + */ + ASSUME_VALID_DTB = 1 << 0, + + /* + * This builds on ASSUME_VALID_DTB and further assumes that libfdt + * functions are called with valid parameters, i.e. not trigger + * FDT_ERR_BADOFFSET or offsets that are out of bounds. It disables any + * extensive checking of parameters and the device tree, making various + * assumptions about correctness. + * + * It doesn't make sense to enable this assumption unless + * ASSUME_VALID_DTB is also enabled. + */ + ASSUME_VALID_INPUT = 1 << 1, + + /* + * This disables checks for device-tree version and removes all code + * which handles older versions. + * + * Only enable this if you know you have a device tree with the latest + * version. + */ + ASSUME_LATEST = 1 << 2, + + /* + * This assumes that it is OK for a failed addition to the device tree, + * due to lack of space or some other problem, to skip any rollback + * steps (such as dropping the property name from the string table). + * This is safe to enable in most circumstances, even though it may + * leave the tree in a sub-optimal state. + */ + ASSUME_NO_ROLLBACK = 1 << 3, + + /* + * This assumes that the device tree components appear in a 'convenient' + * order, i.e. the memory reservation block first, then the structure + * block and finally the string block. + * + * This order is not specified by the device-tree specification, + * but is expected by libfdt. The device-tree compiler always created + * device trees with this order. + * + * This assumption disables a check in fdt_open_into() and removes the + * ability to fix the problem there. This is safe if you know that the + * device tree is correctly ordered. See fdt_blocks_misordered_(). + */ + ASSUME_LIBFDT_ORDER = 1 << 4, + + /* + * This assumes that libfdt itself does not have any internal bugs. It + * drops certain checks that should never be needed unless libfdt has an + * undiscovered bug. + * + * This can generally be considered safe to enable. + */ + ASSUME_LIBFDT_FLAWLESS = 1 << 5, +}; + +/** + * can_assume_() - check if a particular assumption is enabled + * + * @mask: Mask to check (ASSUME_...) + * @return true if that assumption is enabled, else false + */ +static inline bool can_assume_(int mask) +{ + return FDT_ASSUME_MASK & mask; +} + +/** helper macros for checking assumptions */ +#define can_assume(_assume) can_assume_(ASSUME_ ## _assume) + #endif /* _LIBFDT_INTERNAL_H */ diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index 7c75688..b6c8b67 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -114,7 +114,30 @@ * Should never be returned, if it is, it indicates a bug in * libfdt itself. */ -#define FDT_ERR_MAX 13 +/* Errors in device tree content */ +#define FDT_ERR_BADNCELLS 14 + /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells + * or similar property with a bad format or value */ + +#define FDT_ERR_BADVALUE 15 + /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected + * value. For example: a property expected to contain a string list + * is not NUL-terminated within the length of its value. */ + +#define FDT_ERR_BADOVERLAY 16 + /* FDT_ERR_BADOVERLAY: The device tree overlay, while + * correctly structured, cannot be applied due to some + * unexpected or missing value, property or node. */ + +#define FDT_ERR_NOPHANDLES 17 + /* FDT_ERR_NOPHANDLES: The device tree doesn't have any + * phandle available anymore without causing an overflow */ + +#define FDT_ERR_BADFLAGS 18 + /* FDT_ERR_BADFLAGS: The function was passed a flags field that + * contains invalid flags or an invalid combination of flags. */ + +#define FDT_ERR_MAX 18 /**********************************************************************/ /* Low-level functions (you probably don't need these) */ @@ -156,6 +179,33 @@ int fdt_first_subnode(const void *fdt, int offset); */ int fdt_next_subnode(const void *fdt, int offset); +/** + * fdt_for_each_subnode - iterate over all subnodes of a parent + * + * @node: child node (int, lvalue) + * @fdt: FDT blob (const void *) + * @parent: parent node (int) + * + * This is actually a wrapper around a for loop and would be used like so: + * + * fdt_for_each_subnode(node, fdt, parent) { + * Use node + * ... + * } + * + * if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) { + * Error handling + * } + * + * Note that this is implemented as a macro and @node is used as + * iterator in the loop. The parent variable be constant or even a + * literal. + */ +#define fdt_for_each_subnode(node, fdt, parent) \ + for (node = fdt_first_subnode(fdt, parent); \ + node >= 0; \ + node = fdt_next_subnode(fdt, node)) + /**********************************************************************/ /* General functions */ /**********************************************************************/ @@ -247,6 +297,47 @@ int fdt_move(const void *fdt, void *buf, int bufsize); const char *fdt_string(const void *fdt, int stroffset); /** + * fdt_find_max_phandle - find and return the highest phandle in a tree + * @fdt: pointer to the device tree blob + * @phandle: return location for the highest phandle value found in the tree + * + * fdt_find_max_phandle() finds the highest phandle value in the given device + * tree. The value returned in @phandle is only valid if the function returns + * success. + * + * returns: + * 0 on success or a negative error code on failure + */ +int fdt_find_max_phandle(const void *fdt, uint32_t *phandle); + +/** + * fdt_get_max_phandle - retrieves the highest phandle in a tree + * @fdt: pointer to the device tree blob + * + * fdt_get_max_phandle retrieves the highest phandle in the given + * device tree. This will ignore badly formatted phandles, or phandles + * with a value of 0 or -1. + * + * This function is deprecated in favour of fdt_find_max_phandle(). + * + * returns: + * the highest phandle on success + * 0, if no phandle was found in the device tree + * -1, if an error occurred + */ +static inline uint32_t fdt_get_max_phandle(const void *fdt) +{ + uint32_t phandle; + int err; + + err = fdt_find_max_phandle(fdt, &phandle); + if (err < 0) + return (uint32_t)-1; + + return phandle; +} + +/** * fdt_num_mem_rsv - retrieve the number of memory reserve map entries * @fdt: pointer to the device tree blob * @@ -316,6 +407,21 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); /** + * fdt_path_offset_namelen - find a tree node by its full path + * @fdt: pointer to the device tree blob + * @path: full path of the node to locate + * @namelen: number of characters of path to consider + * + * Identical to fdt_path_offset(), but only consider the first namelen + * characters of path as the path name. + * + * Return: offset of the node or negative libfdt error value otherwise + */ +#ifndef SWIG /* Not available in Python */ +int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen); +#endif + +/** * fdt_path_offset - find a tree node by its full path * @fdt: pointer to the device tree blob * @path: full path of the node to locate @@ -404,6 +510,33 @@ int fdt_first_property_offset(const void *fdt, int nodeoffset); int fdt_next_property_offset(const void *fdt, int offset); /** + * fdt_for_each_property_offset - iterate over all properties of a node + * + * @property: property offset (int, lvalue) + * @fdt: FDT blob (const void *) + * @node: node offset (int) + * + * This is actually a wrapper around a for loop and would be used like so: + * + * fdt_for_each_property_offset(property, fdt, node) { + * Use property + * ... + * } + * + * if ((property < 0) && (property != -FDT_ERR_NOTFOUND)) { + * Error handling + * } + * + * Note that this is implemented as a macro and property is used as + * iterator in the loop. The node variable can be constant or even a + * literal. + */ +#define fdt_for_each_property_offset(property, fdt, node) \ + for (property = fdt_first_property_offset(fdt, node); \ + property >= 0; \ + property = fdt_next_property_offset(fdt, property)) + +/** * fdt_get_property_by_offset - retrieve the property at a given offset * @fdt: pointer to the device tree blob * @offset: offset of the property to retrieve @@ -532,6 +665,14 @@ const void *fdt_getprop_by_offset(const void *fdt, int offset, const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, const char *name, int namelen, int *lenp); +static inline void *fdt_getprop_namelen_w(void *fdt, int nodeoffset, + const char *name, int namelen, + int *lenp) +{ + return (void *)(uintptr_t)fdt_getprop_namelen(fdt, nodeoffset, name, + namelen, lenp); +} + /** * fdt_getprop - retrieve the value of a given property * @fdt: pointer to the device tree blob @@ -993,6 +1134,31 @@ static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset, int fdt_nop_property(void *fdt, int nodeoffset, const char *name); /** + * fdt_setprop_inplace_namelen_partial - change a property's value, + * but not its size + * @fdt: pointer to the device tree blob + * @nodeoffset: offset of the node whose property to change + * @name: name of the property to change + * @namelen: number of characters of name to consider + * @idx: index of the property to change in the array + * @val: pointer to data to replace the property value with + * @len: length of the property value + * + * Identical to fdt_setprop_inplace(), but modifies the given property + * starting from the given index, and using only the first characters + * of the name. It is useful when you want to manipulate only one value of + * an array and you have a string that doesn't end with \0. + * + * Return: 0 on success, negative libfdt error value otherwise + */ +#ifndef SWIG /* Not available in Python */ +int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, + const char *name, int namelen, + uint32_t idx, const void *val, + int len); +#endif + +/** * fdt_nop_node - replace a node (subtree) with nop tags * @fdt: pointer to the device tree blob * @nodeoffset: offset of the node to nop @@ -1158,6 +1324,37 @@ int fdt_setprop(void *fdt, int nodeoffset, const char *name, const void *val, int len); /** + * fdt_setprop_placeholder - allocate space for a property + * @fdt: pointer to the device tree blob + * @nodeoffset: offset of the node whose property to change + * @name: name of the property to change + * @len: length of the property value + * @prop_data: return pointer to property data + * + * fdt_setprop_placeholer() allocates the named property in the given node. + * If the property exists it is resized. In either case a pointer to the + * property data is returned. + * + * This function may insert or delete data from the blob, and will + * therefore change the offsets of some existing nodes. + * + * returns: + * 0, on success + * -FDT_ERR_NOSPACE, there is insufficient free space in the blob to + * contain the new property value + * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, + int len, void **prop_data); + +/** * fdt_setprop_u32 - set a property to a 32-bit integer * @fdt: pointer to the device tree blob * @nodeoffset: offset of the node whose property to change @@ -1503,6 +1700,37 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name); */ int fdt_del_node(void *fdt, int nodeoffset); +/** + * fdt_overlay_apply - Applies a DT overlay on a base DT + * @fdt: pointer to the base device tree blob + * @fdto: pointer to the device tree overlay blob + * + * fdt_overlay_apply() will apply the given device tree overlay on the + * given base device tree. + * + * Expect the base device tree to be modified, even if the function + * returns an error. + * + * returns: + * 0, on success + * -FDT_ERR_NOSPACE, there's not enough space in the base device tree + * -FDT_ERR_NOTFOUND, the overlay points to some inexistant nodes or + * properties in the base DT + * -FDT_ERR_BADPHANDLE, + * -FDT_ERR_BADOVERLAY, + * -FDT_ERR_NOPHANDLES, + * -FDT_ERR_INTERNAL, + * -FDT_ERR_BADLAYOUT, + * -FDT_ERR_BADMAGIC, + * -FDT_ERR_BADOFFSET, + * -FDT_ERR_BADPATH, + * -FDT_ERR_BADVERSION, + * -FDT_ERR_BADSTRUCTURE, + * -FDT_ERR_BADSTATE, + * -FDT_ERR_TRUNCATED, standard meanings + */ +int fdt_overlay_apply(void *fdt, void *fdto); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ From patchwork Thu Sep 2 06:05:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DEFDC19F3A for ; Thu, 2 Sep 2021 06:51:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 43AB560C3E for ; Thu, 2 Sep 2021 06:51:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 43AB560C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176917.322095 (Exim 4.92) (envelope-from ) id 1mLgYr-00051E-Bb; Thu, 02 Sep 2021 06:50:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176917.322095; Thu, 02 Sep 2021 06:50:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYr-0004z1-2e; Thu, 02 Sep 2021 06:50:57 +0000 Received: by outflank-mailman (input) for mailman id 176917; Thu, 02 Sep 2021 06:07:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsU-0004aK-4w for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:10 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (unknown [40.107.223.42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6b740e9e-d45e-48aa-a9e2-50634644e3d4; Thu, 02 Sep 2021 06:07:07 +0000 (UTC) Received: from DM3PR12CA0077.namprd12.prod.outlook.com (2603:10b6:0:57::21) by SN1PR02MB3678.namprd02.prod.outlook.com (2603:10b6:802:24::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Thu, 2 Sep 2021 06:07:05 +0000 Received: from DM3NAM02FT042.eop-nam02.prod.protection.outlook.com (2603:10b6:0:57:cafe::6f) by DM3PR12CA0077.outlook.office365.com (2603:10b6:0:57::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:05 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT042.mail.protection.outlook.com (10.13.4.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:04 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:03 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:03 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsN-000F6q-2G; Wed, 01 Sep 2021 23:07:03 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6b740e9e-d45e-48aa-a9e2-50634644e3d4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rl4T92K7Fut2IIfUEKMpAEcvU69Hlgw4vqQXXLOgTc3QCZhwAtKznHM+TT77SjKpL+8iKTZV2if0Bq/ogNoqrBwsnX7T+oOrGxG1rbCro0PrhpjawwTpzdeBpYxyF8pFoSA8bhG6RNxLmNgcHcJqhwUOHtpXYTE5d7BEcp/IB/yk86gbUorlTmdYZOlojDET28UlZT690kpdDD3VfYUij/LnPcb8jzDYxm0DRKGaLQ+7rAt4fbjbDLdxSer+q2udMdkxk2XMxpKZ3MBC96zMq02TYTMLr+lB8uCgdSpxM/OMIzc6Gr/KGn2/sYQdAt/r7Cx334uckbIt9vi7ng5kpg== 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; bh=98AtMQVzaAHOwKKFvylID8GyFmwvLo9S59QnYCd+rzM=; b=G5j+giD11VwxA/+WjkeuVgz1IKhyT5QrsNZcBBg+HfzHOPGvK/TD4n7zzgbwieSfiw4kuHNN9SSUShmjvL3fFvF/XTkyFEh77acor6VGTtm+4yrkk9YtndmWIsmziVD+9N0h2HJBuY+blFa+BaC+pRWxKsXIqLopX95qgKk18I30pa0cVtKvhdm9TJRtFqr0KO3pWnGFshhN+8GaNrCrygYYZ3vzjyJVHUu/+i3ToFA5NZCr2QPw75PVVdPZpmBrGCZbFdh3Cxr6vb7zaM4pFOlh67bWMwgl9hjzGVGvELRG7XKcoh2R3/F0r7t6A26MW0VFDRWh6yIborcIqxESXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=98AtMQVzaAHOwKKFvylID8GyFmwvLo9S59QnYCd+rzM=; b=fEWmNfRVw1Iw8SEg1ZJOVObVMv/9iTTh6owNYcdnonI8ZYPCJGVNVTb8SUJJmGVD8VH+egahPgwdubShCsrwZwyHUKeYy87EnMpegIxRJW4PJxce9p3oQh06ta2cXK5iJUM+w4SRa5AFroCrtqfEIv2zBOn67BqTh1F8aoAkQkE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 05/13] libfdt: Change overlay_get_target() type Date: Wed, 1 Sep 2021 23:05:55 -0700 Message-ID: <1630562763-390068-6-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f9a09cc-64e5-4749-23cf-08d96dd7e370 X-MS-TrafficTypeDiagnostic: SN1PR02MB3678: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ckx58VpUs6M3WyHg9+f3TqPbipbP2X8Vt1GQIVqSNAERsgzKnshwp3cxb9Nns37n+s5ns0VbNIB544kPvP5jy0tLHvh7SMNMggeLtvftBKBZBqEEL5SJ1yi/CKgXDuQjuzekuB5+fr+LKGPVnlNhcBmRU+bl7V69dfXqFUkzjXp6ic0Znws3VNTV3NYqcXatPYo4s472WDu/hQXjofqak6d22e/tgeFGX4el0eIRH9Z8+pADwfxVXpkrXQpCQfWN47nPcFQrIKTN+ItqgIHv7VSpvr7cNvns4K7tPEXVAVZbIlvLO+6QEv+4qsSZdQ0IWrW53dOZuxPBTNGOulf/EoITBmfrO7n7nC42oqCU8HCFwCiqEjI8r25ATcrhSvAG69J6Ro9sOfLlueIHT+8BoFWHaHR4yjbC+F+8DzwQefiGtc1bhE9a9X0ysfRYHDxzY2qNzyUyf+PBvut6oMDmfQZndm5O5UaijpHnCzB0lXwW0fMJpUCQzedaNBHmHypWBwhYibwKLQbVbfdYS93wbc+iNOfWJeTmX8533vx+SRAz1bLSlbLCMiQmYjyZCAydXqcrK+ckVgopGap6iDzd7kwuBW3Mlu8RWa1cnsXeYmBXsiJKDdl+/gdKBYoqT9cHy3NYUUAUBsZfSJgcTCFg5JCtdgKL2f1PBl6vrsJmSnrvH9/Yrhwjxke23jXA6uUY/evD5iFC2yvEpoT/aHEF4c1sSn7IAYVKKzyvtNZsb0A= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(376002)(396003)(346002)(136003)(39860400002)(46966006)(36840700001)(82310400003)(47076005)(36756003)(70586007)(2616005)(336012)(6666004)(426003)(186003)(26005)(478600001)(2906002)(83380400001)(8936002)(316002)(70206006)(9786002)(8676002)(7696005)(5660300002)(36906005)(82740400003)(7636003)(356005)(54906003)(36860700001)(4326008)(107886003)(6916009)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:04.9759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f9a09cc-64e5-4749-23cf-08d96dd7e370 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT042.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR02MB3678 Remove static function type from overlay_get_target(). Signed-off-by: Vikram Garhwal --- xen/common/libfdt/fdt_overlay.c | 2 +- xen/include/xen/libfdt/libfdt.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index 15a8cdb..1ffb669 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -56,7 +56,7 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) * the targeted node offset in the base device tree * Negative error code on error */ -static int overlay_get_target(const void *fdt, const void *fdto, +int overlay_get_target(const void *fdt, const void *fdto, int fragment, char const **pathp) { uint32_t phandle; diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index b6c8b67..e1cc6f2 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -1737,4 +1737,6 @@ int fdt_overlay_apply(void *fdt, void *fdto); const char *fdt_strerror(int errval); +int overlay_get_target(const void *fdt, const void *fdto, int fragment, + char const **pathp); #endif /* _LIBFDT_H */ From patchwork Thu Sep 2 06:05:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5858C4320E for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 668D760F6C for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 668D760F6C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176918.322102 (Exim 4.92) (envelope-from ) id 1mLgYr-0005C1-T7; Thu, 02 Sep 2021 06:50:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176918.322102; Thu, 02 Sep 2021 06:50:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYr-00058P-Ij; Thu, 02 Sep 2021 06:50:57 +0000 Received: by outflank-mailman (input) for mailman id 176918; Thu, 02 Sep 2021 06:07:10 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsU-0004ds-5y for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:10 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (unknown [40.107.100.73]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 01ae88ce-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:09 +0000 (UTC) Received: from DM3PR12CA0074.namprd12.prod.outlook.com (2603:10b6:0:57::18) by PH0PR02MB8501.namprd02.prod.outlook.com (2603:10b6:510:100::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:07:08 +0000 Received: from DM3NAM02FT042.eop-nam02.prod.protection.outlook.com (2603:10b6:0:57:cafe::8) by DM3PR12CA0074.outlook.office365.com (2603:10b6:0:57::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:08 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by DM3NAM02FT042.mail.protection.outlook.com (10.13.4.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:07 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:05 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:04 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsO-000F6q-Ug; Wed, 01 Sep 2021 23:07:04 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 01ae88ce-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQLsUwitGlfNT7El7H4B/XS7vcpOlCuP/nodYDXRqQkXDeLL04P0W7cYSfDMKGPtH0AbUkmZFOX5nWIdLeZy6vWnUNESCqlg6nQzfS4ht43yxzw2uTaYy9KN1e88ohU+8r0KfXBxfqfxo97N1fcCiJAsl1nvZOzEiFxz1nZyzg6WLGQPOZrg35nUqc84G3fsTGCMoagz1SDvySFGmu875Brmw6ZgRgooquKEXkZUdDUaW737wPQjEzy5QO5Jpluxd6IPhCoJAeIhUVn5nQH81XdrXf3T5jtxMe0WszjetHKnjU+cuqGb5d5rJPNN1y6gaDkZeCNIewxuaMq3I346kA== 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-SenderADCheck; bh=qQqiWML3nRBgAmoYFeaXNgx+nXTK27DqgxYrbIIxS+4=; b=Fw8d6SeJXhmuguBjdLmY99Wwotpio0YOuUCFzzVbWSn+WsIQaw4+4/CeKH2+ruwASa4t4P2CBfm1eWis+A9Uy1jITMljZaBBxM0on3nZYre/UuU2+fHY/s3FJouDH7ZhcAfVxHURiBjTSmwlqfJsEzuuCSrEwe5Sb8RwckxRINNhzAo217+b8dQrxL8N4chvAg7CYjGXuJT97QB8GHRd3D9mAudWhgDyeJuEMfHAqcwkFiH2TTGsIicLmuKHlHKZqoBa/YP2b3l54n27o6ORY8ZHItHEsS/LB0NAxaMsXrldiyT0spy8UxYr0LrxHGt81H3kEHWLZtul+7voG8uHCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qQqiWML3nRBgAmoYFeaXNgx+nXTK27DqgxYrbIIxS+4=; b=bYD62rRraU3PKWxLybe0b2QGpjErYChmHJwCmVGwIkmBM1E5XlYWcgzaj4e6pWT0oyrKQvWRm5ulz7DQcSUDue0+HedEjxHDd2px7TTkm05+bMLBB/Gg/DRY5pc/2PvDEAHU4ILDqEEqgV8WBUOV9ljDcTwJMYLi3ESjdZxo5T8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 06/13] device tree: Add dt_print_node_names() Date: Wed, 1 Sep 2021 23:05:56 -0700 Message-ID: <1630562763-390068-7-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3613ec78-5dcd-4519-f133-08d96dd7e514 X-MS-TrafficTypeDiagnostic: PH0PR02MB8501: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:154; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zthyOMV3KedVnyLP35/3+eY38V0CwfqIzFmRHxK9tLY7wM6M9jxmRgrxqR8NzYhhIMkWg//XpjuzbLt1AepqGZi73OonoWXkDmTiXW27iFtgSZJVIeukVxIZlqHA/uynne6XkDwNOgniVQwpicQmOJDJwF3UjPsihvA3wXR+bZpR3cyoOgX5HKMkC14zVquC8H+xLO1OTJlBEuGZHBrtTMaH/+kzXLJYVXfCwIyf/LZswVXemlEA+zcCboGZKoFm54BAGYXe7APBk0K1L6nokdbBjNXfaE2VRYgt9fD0ddcpNqEOLvAejQdjP11hjPgdPR2LB6Z2IpjSQ1SqmryNOv4xvmvuxCWwjFzvupbrTwNJGXOyVG2J5mWeVaz3vKTOOFUnb6wGtfe4SRNC+9eHM36uUamS/k6KP+VJtbbKdixrW2ZZ0BLU72nvNINHeiFmYY7kspSOjwKPmmdqq3saD1jPQC2V67BPzILD+Lzqt1AtOlwJOax1nPF6eNFAq99Kk5wocNO2CImmhvhxuAshcJYeWTj1zhpYjL3uQa4wxlGOoCBT+mnaWE1xFsVtMlZVbbHzFbqmHiwc2iTXXugYkH9ZJm2l1R9cZNdm6eG493rQzXm5r0Y6KQRLzTJff9wknn8ON58geKCJSTQJAJ0Faf9AfLrc8/cA1BTAmqa6rR15lHk85dQdlE2P7WEHcHMY1Sah9XkS5lFRCm9E3fBBuvbMLeGfHwPMwwYd5KgErs0= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(426003)(186003)(2616005)(6666004)(8676002)(107886003)(36756003)(7636003)(2906002)(26005)(6916009)(82310400003)(70206006)(70586007)(336012)(47076005)(316002)(36906005)(36860700001)(508600001)(7696005)(5660300002)(9786002)(4326008)(8936002)(356005)(54906003)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:07.7477 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3613ec78-5dcd-4519-f133-08d96dd7e514 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: DM3NAM02FT042.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB8501 Add dt_print_node_names() to print all nodes under a dt_device_node. dt_print_node_names() takes a dt_device_node type input and prints the node name of all the subsequent nodes. This is added for debugging purpose for device tree overlays. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 10 ++++++++++ xen/include/xen/device_tree.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index cda21be..bfe3191 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -308,6 +308,16 @@ struct dt_device_node *dt_find_node_by_path(const char *path) return np; } +void dt_print_node_names(struct dt_device_node *dt) +{ + struct dt_device_node *np; + + dt_for_each_device_node(dt, np) + dt_dprintk("Node name: %s Full name %s\n", np->name, np->full_name); + + return; +} + int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, struct dt_device_node **node) { diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index a4e98a7..dcd96b4 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -483,6 +483,11 @@ struct dt_device_node *dt_find_node_by_path(const char *path); int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, struct dt_device_node **node); +/* + * Prints all node names. + */ +void dt_print_node_names(struct dt_device_node *dt); + /** * dt_get_parent - Get a node's parent if any * @node: Node to get parent From patchwork Thu Sep 2 06:05:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25757C432BE for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7DA560F6C for ; Thu, 2 Sep 2021 06:51:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C7DA560F6C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176924.322120 (Exim 4.92) (envelope-from ) id 1mLgYt-0005dZ-AL; Thu, 02 Sep 2021 06:50:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176924.322120; Thu, 02 Sep 2021 06:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYs-0005aj-Rl; Thu, 02 Sep 2021 06:50:58 +0000 Received: by outflank-mailman (input) for mailman id 176924; Thu, 02 Sep 2021 06:07:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsu-0004hL-Fg for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:36 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (unknown [40.107.220.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 10ba58f3-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:35 +0000 (UTC) Received: from BN8PR12CA0025.namprd12.prod.outlook.com (2603:10b6:408:60::38) by MWHPR02MB3245.namprd02.prod.outlook.com (2603:10b6:301:6b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.24; Thu, 2 Sep 2021 06:07:31 +0000 Received: from BN1NAM02FT008.eop-nam02.prod.protection.outlook.com (2603:10b6:408:60:cafe::92) by BN8PR12CA0025.outlook.office365.com (2603:10b6:408:60::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 06:07:31 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT008.mail.protection.outlook.com (10.13.2.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:30 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:08 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:08 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsS-000F6q-2P; Wed, 01 Sep 2021 23:07:08 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 10ba58f3-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SYzw5n/WzHl182B+tAIvwfDyBmQvwX19sQvk72oOM9gOO9pzTW5DcD4zRUZysYkRyMrGBsT0kUqeVsB3T0HQmB/lC8Qnb/7fQNEaeGSQp/Vu5fow0E46fi/E/RWVcs0Us3ArSspm0y5n3+upKgeo4of4OUsGXkJi3tuUfLlaQGwK664iUDUMrdw/71qdgOqYXufRwXESfV2ez7gwnABVT6OmXmucUdzOTYBh54RwWW7lOv2yRXdDhYYz6sA60QIoFna9SS5JmplJ/25wLpAVyAUDsvMNpj0s9B/zH1DlUFpdJyBBV05H1+ipjYqSoz2S9yw6xGkk93Ovg+4P/Ky87Q== 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-SenderADCheck; bh=02lvqIFeq5ueMXlcG0MgTjXHnFIspvYKtsnJlaQoi8I=; b=VmAPSp6bs7xh91+LR0Ait+pq78OmwpFJ1L1fdgJW39/e4zIba+z+k8HdNdsJ9GCBUOnKnog+A0eu8d0PBf+j9rVpSHpHm/0Orh/PhZkfYSjZf23sLtyW7nRtCuDJmh7UO0P0FHSNVQQyOlnNc3T7MtOXwfrGCjhdoV/MVFSAeyXMlwnqrPRUk4Kse69kEJGk2hETXFH15/JoKZUyhsRcsCjPsiGsM84GgWCVpnADsa7HijwP6nGHmHL8HoJ7OB/LlPGqghRc+b3KOHE9LYQKyqKI63Ldl6j5dObSwLkDmS7ne8nvu3RAgF1E2Pud6Ig1k704DWPyTzc6yfvrirfplg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=02lvqIFeq5ueMXlcG0MgTjXHnFIspvYKtsnJlaQoi8I=; b=lLuKWj6CBelA+oFhxzhOFkaU5QhzYs/lLiXHL53JnI+IJuh6JBqKImZkJ4rUunsLnPKwyxCufvVDnnujlGHT296ZVtj29/KUiy2fwsg/Pn8IrwKZWVjFgLrcl4mH1A3JpSleBEDJbbLB5z5wi7sIEAU2RIHZXy10nlCyE/hz5bs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal Subject: [XEN][RFC PATCH 07/13] device tree: Add _dt_find_node_by_path() to find nodes in device tree Date: Wed, 1 Sep 2021 23:05:57 -0700 Message-ID: <1630562763-390068-8-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d13ac05-bd98-4b27-6ce7-08d96dd7f2d7 X-MS-TrafficTypeDiagnostic: MWHPR02MB3245: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tIH8MefcwcRpvihGrdXSfRE9v6Hh/IeHlbfK0/zW9GVbZG02tTx7mx2WfKTl1kS27XrYGS++2+AbkpfEUxznalv9QcGNa9Xw4ATLF+8X8eWrrJ6OjM1PzkTMc55rJ2mspgTgI8Abc4Lxf2Z1aba7EgnEzQsF1TzasW/+uW32vq2jDAwJGtOJu2NrVA5TjoehMMc8+xjln7mQKtICIzp/vJLCjNAxpzAOlDcRQDJBLrmUtA6T6IufcGRc0acDgammV7QwrNoK3ZbLRqtUVQJue3Q24ZPpDiB/JrvXLASyaa+tZdK8zBpjLF3Rzf332cZE+5QRPt3uNbnioYymlGJ9iVUExJfYzbBGlCVPsVnwHK5FwHm9h8TSTB9ysGBUYj1VjHfeMI9ARGpgUT/TkVzqqffUf1Xa6MqaX43uEyD6HARRLOiv5/7KzBsxIXZdUJc5OqWWWCJwTxD1JHwh9J+uzsQ0sz3nD32KS8pivxqlIH6Y+oXgsJORcXLmLTYhSelNKaWSgHgPKrnDWFCbi58qM3obS9rrG+apG8PMtYf6147KYreB9Y86VyekTnm875mKseajHfXIaxMHXR4A7j+ZVtnFRYivHOhx0X2HUyT5nTX+hNJuvc34XHaPbD8C2ADR7Sn5urTeU0KSsvb4FKapaph+Tyunhlwu+906YXgP05fzz41bOY8ahI26oXBnVH8l7ZEoV+IKV6IrTDPVEc2DvvK0AcJPXpnbTKWd8V6GguhNBWG9P7kHyZVb9ZmNUJRO X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(376002)(46966006)(36840700001)(26005)(9786002)(426003)(36860700001)(47076005)(478600001)(82310400003)(2616005)(6916009)(70206006)(7696005)(6666004)(7636003)(8676002)(70586007)(186003)(107886003)(8936002)(2906002)(4326008)(54906003)(5660300002)(36756003)(336012)(356005)(316002)(36906005)(82740400003)(83380400001)(102446001)(37363002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:30.7817 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d13ac05-bd98-4b27-6ce7-08d96dd7f2d7 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT008.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB3245 Add _dt_find_by_path() to find a matching node with path for a dt_device_node. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 10 ++++++++-- xen/include/xen/device_tree.h | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index bfe3191..4946e83 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -297,17 +297,23 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, return np; } -struct dt_device_node *dt_find_node_by_path(const char *path) +struct dt_device_node *_dt_find_node_by_path(struct dt_device_node *dt, + const char *path) { struct dt_device_node *np; - dt_for_each_device_node(dt_host, np) + dt_for_each_device_node(dt, np) if ( np->full_name && (dt_node_cmp(np->full_name, path) == 0) ) break; return np; } +struct dt_device_node *dt_find_node_by_path(const char *path) +{ + return _dt_find_node_by_path(dt_host, path); +} + void dt_print_node_names(struct dt_device_node *dt) { struct dt_device_node *np; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index dcd96b4..7cc6093 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -469,6 +469,15 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias); */ struct dt_device_node *dt_find_node_by_path(const char *path); +/** + * _dt_find_node_by_path - Find a node matching a full DT path + * @dt_node: The device tree to search + * @path: The full path to match + * + * Returns a node pointer. + */ +struct dt_device_node *_dt_find_node_by_path(struct dt_device_node *dt, + const char *path); /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Thu Sep 2 06:05:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5885C4320A for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 56CA060C3E for ; Thu, 2 Sep 2021 06:51:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 56CA060C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176926.322132 (Exim 4.92) (envelope-from ) id 1mLgYu-0005n8-5L; Thu, 02 Sep 2021 06:51:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176926.322132; Thu, 02 Sep 2021 06:50:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYt-0005kp-Co; Thu, 02 Sep 2021 06:50:59 +0000 Received: by outflank-mailman (input) for mailman id 176926; Thu, 02 Sep 2021 06:07:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsv-0004hX-Ty for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:37 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (unknown [40.107.243.58]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d71d7a5a-f0b0-458d-8457-d905d920e6b9; Thu, 02 Sep 2021 06:07:36 +0000 (UTC) Received: from SA0PR11CA0187.namprd11.prod.outlook.com (2603:10b6:806:1bc::12) by MWHPR02MB2606.namprd02.prod.outlook.com (2603:10b6:300:44::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Thu, 2 Sep 2021 06:07:35 +0000 Received: from SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com (2603:10b6:806:1bc:cafe::47) by SA0PR11CA0187.outlook.office365.com (2603:10b6:806:1bc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 06:07:35 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0051.mail.protection.outlook.com (10.97.5.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:34 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:13 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:13 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsX-000F6q-F6; Wed, 01 Sep 2021 23:07:13 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d71d7a5a-f0b0-458d-8457-d905d920e6b9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PwWMyGPlBKtFHj1zM/gtcQiLwDgH+yShnsoTOJSsSbOnxUVjkYii203fAKF2tfN3J0iRBuAX9wx2as5wSlKlDt7V+FZrd5iC0gVGQmYWWG6l1u2+ald2Ldc28FAhqxaxOqHB95/lLOX0PQ6w9Uf+eziftZfbnhPOZPC4nlsOK8vd6eHFz2IGUuP2CYDoC7lqInZ7kIp9FnGC+b2SqJCkMEoYcQjlpokiCL4h7ppC7IrStudyGvXuVfRJ1OuYls8OmMwPwoS/unmsvEVPgF+rhyFN00spTN9ZDa1lN8WsIyt7iDsLSrm/KNbWnGNkaRbrpvr2JtRAxwcQcOOwNzZZpA== 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; bh=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=baGfgKv6wfpslNLcyv4rKCbR3vhTEl/V+OdFy+IgivH9xZIn3/bMExf23cMh7y5/jpnd9xauUSY+AQopw3w2txn1uXKketaIOsJ9OE96cbKG8aOyLa+/RvbFZ33Uoa7wfbcWnx3buXcylsfn7L8sElihGqZIUKiUn+imUsnMxQcuvuTBjh1wWN6YaOXhpaCkf2vvWBC0PXRpMOd5b1OwiUMgmRyVdYf2DpvDx325qbPUsd2ZieSnwbQp6m/NYoDF90spKygJvB4ITpEYVyGH8hwE4+3SlbWGxcCjRbVdCNbrnCuFGFQk50cJvNXa6LFZxpPRXK7uYgoB2G1ntl4guA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EVas2kXYqY8J1i69hD1pnLTQnzKqbS4jKsdjLz6x97c=; b=OhDJ97JWnZlQmoCvp1jgfKBkXfc7CTrXRjx9a1itEgWqm+nvR8rkYqPd8FEVw2kYPd3cEUQhMrGgpdT85MROte2W9HmBJLrRE6QRIrg35hC2a3+dMECG4dqdsnbXG30TvYW1g4f8/V9tmF/jQQc2SBdGJdPfTKe99GV9/AcniQ8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Volodymyr Babchuk , Jan Beulich , Paul Durrant Subject: [XEN][RFC PATCH 08/13] xen/iommu: Introduce iommu_remove_dt_devices function Date: Wed, 1 Sep 2021 23:05:58 -0700 Message-ID: <1630562763-390068-9-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9508a7b-7601-4ec8-4fbb-08d96dd7f529 X-MS-TrafficTypeDiagnostic: MWHPR02MB2606: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TMQQTZIpkWWv10Ikt+KPGzuRQXvsobuI7WlcFc7zHglAU7EPq34TwwLc8REM6x9UCzfA+OIWUlUkYBJPchPItU4BduToxXXwNtLikwy+i7xfVo7EBHiKkws/1TqNsdPhOjOeeIU4/db7oS1GreqCl1UXP0bSnlLzYoKVeaQJcWRxIWK3OO8dN0xWFGzZDiNNDOZavcS6X4K6iaKtE7loInF61Q2w+ETeuV2N5+GfUytah1iE3bB5GlQE+0G5k4eYfJpVHh1lj/GMfiKHvfJOEgpPSVRIslaa6SaVTOlidGQGcRd/E59DAmBJYDB+dOvMh0IMoxSIYMMge3QPEq9XwmUFiQMcB0gowseVr41IVhhO74seru+ixoSQZAiF4vQmR83rQ2Z66odrEQPai81dJBE9LMr6stnG5nya1WpvLFLMUVjzXWAgcl2p73NIeUjaz6xVHoDqgkJvayixjJz9K6oKBsvaimIBnHgBmo9EZuMf/fKiZMhLfCdAxzKp856xouT9IuQDMHBRiAp9LC8+wLaFFt0QgvW4seVVdPaTqKshfyFW0HghGsv2ChgU0zWonNdP/KXYv14FP+4LKIwm+HnpUKyxycO2gGqCnKjeqyMVTRrxRUKuv5DRkb+wDyVapCTNoWkgaIo5OGoUchKQhTvO2tKEC8thALJM8DI8adV44qAHjuUdRh4SwMc9JbRWtA4N4i9tD9nUU1S3CwiHfSUsqE3SfXHG7yvIsw6KMJU= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(376002)(39860400002)(346002)(136003)(396003)(46966006)(36840700001)(36860700001)(186003)(336012)(36906005)(2906002)(9786002)(26005)(82740400003)(316002)(4326008)(426003)(54906003)(70206006)(70586007)(7636003)(47076005)(5660300002)(7696005)(8936002)(356005)(36756003)(82310400003)(6916009)(2616005)(478600001)(8676002)(6666004)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:34.7337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e9508a7b-7601-4ec8-4fbb-08d96dd7f529 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0051.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2606 iommu_remove_dt_device function is introduced for supporting dynamic programming i.e. adding and removing a node during runtime. When user removes the device node, iommu_remove_dt_device() removes the device entry from smmu-masters too using following steps: 1. Find if SMMU master exists for the device node. 2. Remove the SMMU master. Signed-off-by: Vikram Garhwal --- xen/drivers/passthrough/arm/smmu.c | 53 +++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/device_tree.c | 30 ++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 3 files changed, 85 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index c9dfc4c..7b615bc 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -816,6 +816,17 @@ static int insert_smmu_master(struct arm_smmu_device *smmu, return 0; } +static int remove_smmu_master(struct arm_smmu_device *smmu, + struct arm_smmu_master *master) +{ + if (!(smmu->masters.rb_node)) + return -ENOENT; + + rb_erase(&master->node, &smmu->masters); + + return 0; +} + static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, struct device *dev, struct iommu_fwspec *fwspec) @@ -853,6 +864,31 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, return insert_smmu_master(smmu, master); } +static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu, + struct device *dev) +{ + struct arm_smmu_master *master; + struct device_node *dev_node = dev_get_dev_node(dev); + int ret; + + master = find_smmu_master(smmu, dev_node); + if (master == NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret = remove_smmu_master(smmu, master); + + if (ret) + return ret; + + master->of_node = NULL; + kfree(master); + return 0; +} + static int register_smmu_master(struct arm_smmu_device *smmu, struct device *dev, struct of_phandle_args *masterspec) @@ -876,6 +912,22 @@ static int register_smmu_master(struct arm_smmu_device *smmu, fwspec); } +static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev) +{ + struct arm_smmu_device *smmu; + struct iommu_fwspec *fwspec; + + fwspec = dev_iommu_fwspec_get(dev); + if (fwspec == NULL) + return -ENXIO; + + smmu = find_smmu(fwspec->iommu_dev); + if (smmu == NULL) + return -ENXIO; + + return arm_smmu_dt_remove_device_legacy(smmu, dev); +} + static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev) { struct arm_smmu_device *smmu; @@ -2876,6 +2928,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arm_smmu_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .iotlb_flush_all = arm_smmu_iotlb_flush_all, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 98f2aa0..37f4945 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -127,6 +127,36 @@ int iommu_release_dt_devices(struct domain *d) return 0; } +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops = iommu_get_ops(); + struct device *dev = dt_to_dev(np); + int rc = 1; + + if ( !ops ) + return -EINVAL; + + if ( iommu_dt_device_is_assigned(np) ) + return -EPERM; + + /* + * The driver which supports generic IOMMU DT bindings must have + * these callback implemented. + */ + if ( !ops->remove_device ) + return -EINVAL; + + /* + * Remove master device from the IOMMU if latter is present and available. + */ + rc = ops->remove_device(0, dev); + + if ( rc == 0 ) + iommu_fwspec_free(dev); + + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops = iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 6b2cdff..c4d5d12 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -215,6 +215,8 @@ int iommu_release_dt_devices(struct domain *d); */ int iommu_add_dt_device(struct dt_device_node *np); +int iommu_remove_dt_device(struct dt_device_node *np); + int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); From patchwork Thu Sep 2 06:05:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D2A6C432BE for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4223860C3E for ; Thu, 2 Sep 2021 06:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4223860C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176928.322136 (Exim 4.92) (envelope-from ) id 1mLgYu-0005wr-NY; Thu, 02 Sep 2021 06:51:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176928.322136; Thu, 02 Sep 2021 06:51:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYt-0005sp-VH; Thu, 02 Sep 2021 06:50:59 +0000 Received: by outflank-mailman (input) for mailman id 176928; Thu, 02 Sep 2021 06:07:41 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLfsz-0004hL-EG for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:41 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (unknown [40.107.236.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 13554a0e-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:38 +0000 (UTC) Received: from SN4PR0501CA0080.namprd05.prod.outlook.com (2603:10b6:803:22::18) by CY4PR02MB2181.namprd02.prod.outlook.com (2603:10b6:903:e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:07:35 +0000 Received: from SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com (2603:10b6:803:22:cafe::39) by SN4PR0501CA0080.outlook.office365.com (2603:10b6:803:22::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.6 via Frontend Transport; Thu, 2 Sep 2021 06:07:35 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0029.mail.protection.outlook.com (10.97.4.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:34 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:14 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:14 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsY-000F6q-R6; Wed, 01 Sep 2021 23:07:14 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 13554a0e-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DqkxgLDre73op25XKcR7jwvLLzEuiKnjoIesQcZcYYRcePW/Wczl6JfiC9Uir3gQK8nM3zNoTtErqKygYvEy1dkmH4H9s4dfeAcxub7lv7x/8yGC94r71oG++PKDB7197eywaey815bCUl1WDPiL8AKZgQForTwgwTew6DltJlL/GvTk59TdUROA7meHHXL0d3lvAienNWYmBxeeNvKJEwzNCesJMfJkCd0wPd22bYrW0rpilKaP9Dp0YrOpwS27MpaU4WA3ZWmtN2KLkmXp00ruvPiNHODynhRfxIUs5VHSzlRewe7EzZa2eajXfdcANqW+hcYQsQEiO2yS8zjMAQ== 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-SenderADCheck; bh=Bk58T2PdmP0MpUXqDTQL+WHaYdm6dJQvCtJfKGAwTtY=; b=Gr3IkqVkZ3nbcF2g6AmzHCrwhD7TpaUL/J623YInRRQQwNuMt0oEvfHv5RSjQtxp3YhARmZ3vE0TTPOP7MKObZb4/07WxGKA915Kle7tovwA9WvaGcIFyFQvFp9h1oKBBd6PbzfsfeI5r+XzZjGW8aPlErba6h9U94tvttjLgmLyrV3+26LieVWrzMbj6GESn/dMMgvM3MLMeCxsanApdfTAgNQVUrVt8r8O+4U0He9qiA7a0XfqalW14nCi+lmvZ/Bf53OgWkHqnfDfsAGh5qEsg6TmhfOoJaiV9vHZzNYkARYxCAWTRmSj2JRtpbVSVKNX/B5QhCDefVSLvqeucg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bk58T2PdmP0MpUXqDTQL+WHaYdm6dJQvCtJfKGAwTtY=; b=mUirYEvbfTT77RlG81HQUzD6LadetmXz6xk4ERMiEy5FuyPHTdnz0h7q3CYy64U9pEAsjH9zCIHJfLSN+Tf/FuyXJKY8tprwYgxI8skLWFuHgbteNYu+lx/BMF59auKMGQqsEbFfG7K76I6T6OL/axyftPGhkQgq2eKeJDyjlQY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH 09/13] xen/arm: Implement device tree node removal functionalities Date: Wed, 1 Sep 2021 23:05:59 -0700 Message-ID: <1630562763-390068-10-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dce2cf17-de68-461f-9cf7-08d96dd7f531 X-MS-TrafficTypeDiagnostic: CY4PR02MB2181: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:199; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IO8yxi2Y5dHAysq/2g414+Sg8E//eFoQU44RCwtQOiZRJ45iK2Z11EfoBqD38MwB5c6tln/ETy+B1062kNw8CAcMX+uISjGSF9J6aqN8Q/cchBpHfbvaiMQe+2zh8wDXcMXvcZDymRr3GnCkTFw1RcMAr0kR6mVqN9hz14BV3TVHAI+FJzjJTKlgWUYcVxBGecl7a+V/yWwBFEr9nJOqmRQpsPDbQGPhekageHEsJnBOKmMP181lmd1EPdHnk4E9L4ewggaOV2RbyoAkdh7Ke0nGgc6Ry+Fdle8lS2aAI1jzykBKyt0lctPLi/rRbw9VawYyEPmcLZ6/CnAEYbOTSZMboVV/lyGXSInFazTxOO4TV5O6PABU5BSj77jglhKQ7y+xZWgUk/qDeb2ReM/fEsUPW14IqA54VxYG0y+Ur+5phrSPCwu5bZEi997EHmThvGM9xWqK3lYZ/PCO4tqWn3dZaFobHt0jjwLGAEV3X0fkLc0thkUcT0YLmdw1fD2GWrMGdKSWxwH34Mziy2AlrtAba1hCoK5PJJ/sTwprTIld2ergybfXEc7IG+jdTrQiTpLrG51Ubu+yT54ov+p3J0K6RtBGfIN48j1wEXmCgtegRnQvPMf3b0i//posj6G+nNCMIVLT9wLAbDnITeaR+Z2AeRiE4sgemxCKg/m4LF0AVj8Jc5ecC/2IUqfyZXVjzYjGnk2fPxxEvohGqPshaojBjpLFjTKVIorgzprAnXjDGnZ/GSCPLlnDmOssbvQO4Q2+d2Uc5oZOPOHV6l5Ntw== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(346002)(39860400002)(396003)(136003)(376002)(36840700001)(46966006)(82740400003)(36860700001)(36756003)(4326008)(6916009)(316002)(2616005)(36906005)(83380400001)(7636003)(8676002)(54906003)(47076005)(2906002)(70206006)(70586007)(6666004)(9786002)(5660300002)(7696005)(186003)(82310400003)(356005)(8936002)(26005)(478600001)(426003)(336012)(102446001)(403724002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:34.7861 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dce2cf17-de68-461f-9cf7-08d96dd7f531 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR02MB2181 Introduce domctl XEN_DOMCTL_delfpga to remove a device-tree node added through device tree overlay. Currently, this supports removing one node at a time. DT node removal works with the following steps: 1. finds a node with given path. 2. Check if the node is used by any of dom0 or domus. It removes the node only when it's not used by any domain. 3. Removes IRQ permissions. 4. Remove MMIO access. 5. Find the node in dt_host and delete the device node entry from dt_host. 6. Free the overlay_tracker node. Also, added overlay_track struct to keep the track of added node through device tree overlay. overlay_track has dt_host_new which is unflattened form of updated fdt and name of overlay node. When a node is removed, we also free the memory used by overlay_track for the particular overlay node. Signed-off-by: Vikram Garhwal --- xen/arch/arm/domctl.c | 183 ++++++++++++++++++++++++++++++++++++++++++ xen/common/device_tree.c | 51 ++++++++++++ xen/include/public/domctl.h | 9 +++ xen/include/xen/device_tree.h | 1 + 4 files changed, 244 insertions(+) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index b7d27f3..5986934 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -9,11 +9,34 @@ #include #include #include +#include #include #include #include #include #include +#include +#include +#include + +/* + * overlay_node_track describes information about added nodes through dtbo. + * @dt_host_new: Pointer to the updated dt_host_new unflattened 'updated fdt'. + * @node_fullname: Store the name of nodes. + * @entry: List pointer. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + /* + * TODO: We keep max nodes to 10 in an overlay. But for now we will be + * adding one node only. + */ + char *node_fullname; +}; + +static LIST_HEAD(overlay_tracker); +static DEFINE_SPINLOCK(overlay_lock); void arch_get_domain_info(const struct domain *d, struct xen_domctl_getdomaininfo *info) @@ -45,6 +68,132 @@ static int handle_vuart_init(struct domain *d, return rc; } +/* + * First finds the device node to remove. Check if the device is being used by + * any dom and finally remove it from dt_host. IOMMU is already being taken care + * while destroying the domain. + */ +static long handle_del_fpga_nodes(char *full_dt_node_path) +{ + struct domain *d = hardware_domain; + int rc = 0; + uint32_t ret = 0; + struct dt_device_node *fpga_device; + struct overlay_track *entry, *temp; + unsigned int naddr; + unsigned int i, nirq; + struct dt_raw_irq rirq; + u64 addr, size; + + fpga_device = dt_find_node_by_path(full_dt_node_path); + + if ( fpga_device == NULL ) + { + printk(XENLOG_G_ERR "Device %s is not present in the tree\n", + full_dt_node_path); + return -EINVAL; + } + + ret = dt_device_used_by(fpga_device); + + if ( ret != 0 && ret != DOMID_IO ) + { + printk(XENLOG_G_ERR "Cannot remove the device as it is being used by" + "domain %d\n", ret); + return -EPERM; + } + + spin_lock(&overlay_lock); + + nirq = dt_number_of_irq(fpga_device); + + /* Remove IRQ permission */ + for ( i = 0; i < nirq; i++ ) + { + rc = dt_device_get_raw_irq(fpga_device, i, &rirq); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(fpga_device)); + goto out; + } + + rc = platform_get_irq(fpga_device, i); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Unable to get irq %u for %s\n", + i, dt_node_full_name(fpga_device)); + goto out; + } + + rc = irq_deny_access(d, rc); + + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %u for %s\n", + i, dt_node_full_name(fpga_device)); + goto out; + } + } + + rc = iommu_remove_dt_device(fpga_device); + + if ( rc ) + goto out; + + naddr = dt_number_of_address(fpga_device); + + /* Remove mmio access. */ + for ( i = 0; i < naddr; i++ ) + { + rc = dt_device_get_address(fpga_device, i, &addr, &size); + + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(fpga_device)); + goto out; + } + + rc = iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + size - 1))); + + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); + goto out; + } + } + + rc = fpga_del_node(fpga_device); + + if ( rc ) + goto out; + + list_for_each_entry_safe( entry, temp, &overlay_tracker, entry ) + { + if ( (strcmp(full_dt_node_path, entry->node_fullname) == 0) ) + { + list_del(&entry->entry); + xfree(entry->node_fullname); + xfree(entry->dt_host_new); + xfree(entry); + goto out; + } + } + + printk(XENLOG_G_ERR "Cannot find the node in tracker. Memory will not" + "be freed\n"); + rc = -ENOENT; + +out: + spin_unlock(&overlay_lock); + return rc; +} + long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { @@ -173,6 +322,40 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return rc; } + + case XEN_DOMCTL_delfpga: + { + char *full_dt_node_path; + int rc; + + if ( domctl->u.fpga_del_dt.size > 0 ) + full_dt_node_path = xmalloc_bytes(domctl->u.fpga_del_dt.size); + else + return -EINVAL; + + if ( full_dt_node_path == NULL ) + return -ENOMEM; + + rc = copy_from_guest(full_dt_node_path, + domctl->u.fpga_del_dt.full_dt_node_path, + domctl->u.fpga_del_dt.size); + if ( rc ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(full_dt_node_path); + + return -EFAULT; + } + + full_dt_node_path[domctl->u.fpga_del_dt.size - 1] = '\0'; + + rc = handle_del_fpga_nodes(full_dt_node_path); + + xfree(full_dt_node_path); + + return rc; + } + default: { int rc; diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 4946e83..04f2578 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -324,6 +324,57 @@ void dt_print_node_names(struct dt_device_node *dt) return; } +int fpga_del_node(struct dt_device_node *device_node) +{ + struct dt_device_node *np; + struct dt_device_node *parent_node; + struct dt_device_node *current_node; + + parent_node = device_node->parent; + + current_node = parent_node; + + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + np = parent_node->child; + + if ( np == NULL ) + { + dt_dprintk("parent node %s's not found\n", parent_node->name); + return -EFAULT; + } + + /* If node to be removed is only child node or first child. */ + if ( np->name == device_node->name ) + { + current_node->allnext = np->next; + return 0; + } + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + current_node = np; + if ( np->sibling->name == device_node->name ) + { + /* Found the node. Now we remove it. */ + current_node->allnext = np->allnext->allnext; + + if ( np->sibling->sibling ) + current_node->sibling = np->sibling->sibling; + else + current_node->sibling = NULL; + + break; + } + } + + return 0; +} + int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, struct dt_device_node **node) { diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 96696e3..b1b8efd 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1169,6 +1169,13 @@ struct xen_domctl_vmtrace_op { typedef struct xen_domctl_vmtrace_op xen_domctl_vmtrace_op_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_vmtrace_op_t); +/* XEN_DOMCTL_fpga_del. */ +struct xen_domctl_fpga_del_dt { + XEN_GUEST_HANDLE_64(char) full_dt_node_path; + uint32_t size; +}; + + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1254,6 +1261,7 @@ struct xen_domctl { #define XEN_DOMCTL_get_cpu_policy 82 #define XEN_DOMCTL_set_cpu_policy 83 #define XEN_DOMCTL_vmtrace_op 84 +#define XEN_DOMCTL_delfpga 86 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1315,6 +1323,7 @@ struct xen_domctl { struct xen_domctl_psr_alloc psr_alloc; struct xen_domctl_vuart_op vuart_op; struct xen_domctl_vmtrace_op vmtrace_op; + struct xen_domctl_fpga_del_dt fpga_del_dt; uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 7cc6093..eb7f645 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -496,6 +496,7 @@ int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, * Prints all node names. */ void dt_print_node_names(struct dt_device_node *dt); +int fpga_del_node(struct dt_device_node *device_node); /** * dt_get_parent - Get a node's parent if any From patchwork Thu Sep 2 06:06:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB92EC4320A for ; Thu, 2 Sep 2021 06:51:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4BD4C60C3E for ; Thu, 2 Sep 2021 06:51:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4BD4C60C3E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176930.322145 (Exim 4.92) (envelope-from ) id 1mLgYv-0006BB-CL; Thu, 02 Sep 2021 06:51:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176930.322145; Thu, 02 Sep 2021 06:51:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYu-000669-Pc; Thu, 02 Sep 2021 06:51:00 +0000 Received: by outflank-mailman (input) for mailman id 176930; Thu, 02 Sep 2021 06:07:46 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLft4-0004hL-EK for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:46 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (unknown [40.107.93.85]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1425e966-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:40 +0000 (UTC) Received: from SN4PR0501CA0073.namprd05.prod.outlook.com (2603:10b6:803:22::11) by BL0PR02MB4721.namprd02.prod.outlook.com (2603:10b6:208:59::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:07:38 +0000 Received: from SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com (2603:10b6:803:22:cafe::e9) by SN4PR0501CA0073.outlook.office365.com (2603:10b6:803:22::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.11 via Frontend Transport; Thu, 2 Sep 2021 06:07:38 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0029.mail.protection.outlook.com (10.97.4.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:38 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:17 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:17 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsb-000F6q-4A; Wed, 01 Sep 2021 23:07:17 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1425e966-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Te3CLIQwSSYtGGBlbzgNjB+UBGrhjIq38k9KB7AOSVEw/gPnlTGnHTH852/N/X7gaX5SG46VL9qkBWskLRdlMgk22CMaN3nSRlw7vY7agl7h69FaIdZx0l3BNIy6IDFC7AycymdJKo/B9SA8AS2xj45WLx7C4bCRQdXWGvwPezaeHxgIzQDBA7cz+YOENgQTuF4ywnBRySDg5jdP3feB4i44GkxbpiJAsJEQ8tYdLNorCfzutV6G9Lxp4GsdMimRQu41Bvj2iaIwRmmiY08u1OYaY1puN/yBaQzUrSbHA0hRtvja/Pp7xR0LPKiUWlm/FKB+OZAhGqP6bxsEPmIR/g== 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-SenderADCheck; bh=PuN2b2H12aJwTeXjwq0M4sE74WKCTLZyi/JgSK4cHCM=; b=EaqN0tOBrpnsA6ddF4D8tgIRkFZgE0U6CGwWzSSAdleOzxyTKEsVTzNTcDIhC+k/atll/tzLaeAOEkZErvNO1kfaT70ONMdPGCCTzAeyZuHl7+z8RLUDZaC8MWURa7hMdelENdcF1cC7RxJukQUDIsBW8xJNWD41ERi7i2KNgeOTGOeeIaBpoeD4W+/wD941V2PVoWwRgIK/sBqxnUOOjAz0DPmGEL+cqnnaDAAzYbO8hJw2g7A8NMdio8Ud/Xmq2VmlgR72RvAgg9DMNxmaofCvLrJBU71ZYARIAffj+ngE5VQ3bGZuKz6dmYj8DMb+mDHbHEO2KsK2HxSigj26UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PuN2b2H12aJwTeXjwq0M4sE74WKCTLZyi/JgSK4cHCM=; b=hkwddA76I8tqtEvqpBsYNlYYwVHbCraLiYVXg6Z7D79GDPw64Q1cKYMKkaN+vov4YExUUlIsMTb3JA9kZuSJ6Soz3OaM1TN+M8NpV6ns5XBLEsYtJe02khQd+bV4ywA8luHBgFVNInkX8sLDh6Xpv5pFTFer8bnXSA07NolVq3U= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH 10/13] xen/arm: Implement device tree node addition functionalities Date: Wed, 1 Sep 2021 23:06:00 -0700 Message-ID: <1630562763-390068-11-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 291affca-15c1-4473-a81f-08d96dd7f72b X-MS-TrafficTypeDiagnostic: BL0PR02MB4721: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:366; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0h6eZwWpeRoOmH8M/+P3RMble3LIBuH/jz0oYTE0UXq7ZqgCDd2SyiFG/EBxNy4duillUNfdkMFi4VLSZFB8BjkRTMvfQFkHifKB0UnEqgLnlFOwz7x5FFSzIyyL5kBxDIcAeQ8Efx8bfzJa9FqTQO1b3tFqyP0JCk0OJjzFnAJzqYI0CIHVxmnIcfyRhqisSunIOo1BFSc6Ys3A9Fo/XgL6cf1LvpGjCsDHiGxp8QKwIPCdIbrjinno3sxVvrDFjoEOhDV62ng9IZffiZib1QnUICSNoLB+mMSpBxY/pGyxKs0OLxc8oD6kEoybh8z4QED8bo8jXJ+SGQ8pFPCV/M1DsHAcdltf7qAMxL5tBfZYFnHG+o+LgVsn+PDhHYjD/GcfExjDka/u3wq7TQIUQPvZ2u0C9bgMYfyInrJKTk7ng4G0/BcG5Qj1yYNILcV/z33/AdwNowahz2Zd0rsPw+kwAAFhT+Y87j9pqr+EU8bfSFCGiuBtfCVe2Cpdy4GP43vN2AoArGDhIiA+JzcuCOmRYH3loNGHXK8bm50xae7BqOb2/2pNpyacj7tjPbFQxvemvT2ebzM1x0aGmqip0PqDHGHwSVsEfwpd5htY/yTm9w9ka66IEvVxgVVv17mLUKMfmUGKoPQ//JtWUIZFVwDa0XL0WCkrGdE7TBrHp9lK8zJC+sVYCtJhY6ZXfLaQFmyoUG8qyQExTC1VjK5M/WCeGCH9qzdW1/nu621QgmM89h19U6ug4UQruy5SeKSieeBOITb5Iu3VJgHh3WcI3w== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(39860400002)(376002)(136003)(346002)(396003)(46966006)(36840700001)(4326008)(7696005)(2616005)(186003)(478600001)(36860700001)(356005)(83380400001)(7636003)(47076005)(30864003)(5660300002)(6666004)(36906005)(6916009)(54906003)(8676002)(2906002)(36756003)(8936002)(426003)(70586007)(82740400003)(70206006)(9786002)(316002)(336012)(82310400003)(26005)(102446001)(403724002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:38.1075 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 291affca-15c1-4473-a81f-08d96dd7f72b X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR02MB4721 Introduce domctl XEN_DOMCTL_addfpga to add a device-tree node through device tree overlay. This works with a device tree overlay(.dtbo) as input. Add check_pfdt() to do sanity check on the dtbo. Also, added overlay_get_node_info() to get the node's full name with path. This comes handy when checking node for duplication. Each time a overlay node is added, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay node. This updated fdt is further unflattened to a dt_host_new. Next, it checks if overlay node already exists in the dt_host. If overlay node doesn't exist then find the overlay node in dt_host_new, find the overlay node's parent in dt_host and add the node as child under parent in the dt_host. The node is attached as the last node under target parent. Finally, add IRQs, add device to IOMMUs, set permissions and map MMIO for the overlay node. When a node is added using overlay, a new entry is allocated in the overlay_track to keep the track of memory allocation due to addition of overlay node. This is helpful for freeing the memory allocated when a device tree node is removed with domctl XEN_DOMCTL_delfpga domctl. Signed-off-by: Vikram Garhwal --- xen/arch/arm/domctl.c | 262 ++++++++++++++++++++++++++++++++++++++++++ xen/common/device_tree.c | 54 +++++++++ xen/include/public/domctl.h | 7 ++ xen/include/xen/device_tree.h | 1 + 4 files changed, 324 insertions(+) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 5986934..0ac635f 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -15,6 +15,8 @@ #include #include #include +/* Included for FPGA dt add. */ +#include #include #include #include @@ -68,6 +70,61 @@ static int handle_vuart_init(struct domain *d, return rc; } +static int check_pfdt(void *pfdt, uint32_t pfdt_size) +{ + if ( fdt_totalsize(pfdt) != pfdt_size ) + { + printk(XENLOG_ERR "Partial FDT is not a valid Flat Device Tree\n"); + return -EFAULT; + } + + if ( fdt_check_header(pfdt) ) + { + printk(XENLOG_ERR "Partial FDT is not a valid Flat Device Tree\n"); + return -EFAULT; + } + + return 0; +} + +static void overlay_get_node_info(void *fdto, char *node_full_path) +{ + int fragment; + + /* + * Handle overlay nodes. But for now we are just handling one node. + */ + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target = overlay_get_target(device_tree_flattened, fdto, fragment, + &target_path); + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name = fdt_get_name(fdto, subnode, NULL); + int node_name_len = strlen(node_name); + int target_path_len = strlen(target_path); + + memcpy(node_full_path, target_path, target_path_len); + + node_full_path[target_path_len] = '/'; + + memcpy(node_full_path + target_path_len + 1, node_name, + node_name_len); + + node_full_path[target_path_len + 1 + node_name_len] = '\0'; + + return; + } + } +} + /* * First finds the device node to remove. Check if the device is being used by * any dom and finally remove it from dt_host. IOMMU is already being taken care @@ -194,6 +251,181 @@ out: return rc; } +/* + * Adds only one device node at a time under target node. + * We use dt_host_new to unflatten the updated device_tree_flattened. This is + * done to avoid the removal of device_tree generation, iomem regions mapping to + * DOM0 done by handle_node(). + */ +static long handle_add_fpga_overlay(void *pfdt, uint32_t pfdt_size) +{ + int rc = 0; + struct dt_device_node *fpga_node; + char node_full_path[128]; + void *fdt = xmalloc_bytes(fdt_totalsize(device_tree_flattened)); + struct dt_device_node *dt_host_new; + struct domain *d = hardware_domain; + struct overlay_track *tr = NULL; + int node_full_path_namelen; + unsigned int naddr; + unsigned int i; + u64 addr, size; + + if ( fdt == NULL ) + return ENOMEM; + + spin_lock(&overlay_lock); + + memcpy(fdt, device_tree_flattened, fdt_totalsize(device_tree_flattened)); + + rc = check_pfdt(pfdt, pfdt_size); + + if ( rc ) + goto err; + + overlay_get_node_info(pfdt, node_full_path); + + rc = fdt_overlay_apply(fdt, pfdt); + + if ( rc ) + { + printk(XENLOG_ERR "Adding overlay node %s failed with error %d\n", + node_full_path, rc); + goto err; + } + + /* Check if node already exists in dt_host. */ + fpga_node = dt_find_node_by_path(node_full_path); + + if ( fpga_node != NULL ) + { + printk(XENLOG_ERR "node %s exists in device tree\n", node_full_path); + rc = -EINVAL; + goto err; + } + + /* Unflatten the fdt into a new dt_host. */ + unflatten_device_tree(fdt, &dt_host_new); + + /* Find the newly added node in dt_host_new by it's full path. */ + fpga_node = _dt_find_node_by_path(dt_host_new, node_full_path); + + if ( fpga_node == NULL ) + { + dt_dprintk("%s node not found\n", node_full_path); + rc = -EFAULT; + xfree(dt_host_new); + goto err; + } + + /* Just keep the node we intend to add. Remove every other node in list. */ + fpga_node->allnext = NULL; + fpga_node->sibling = NULL; + + /* Add the node to dt_host. */ + rc = fpga_add_node(fpga_node, fpga_node->parent->full_name); + + if ( rc ) + { + /* Node not added in dt_host. Safe to free dt_host_new. */ + xfree(dt_host_new); + goto err; + } + + /* Get the node from dt_host and add interrupt and IOMMUs. */ + fpga_node = dt_find_node_by_path(fpga_node->full_name); + + if ( fpga_node == NULL ) + { + /* Sanity check. But code will never come in this loop. */ + printk(XENLOG_ERR "Cannot find %s node under updated dt_host\n", + fpga_node->name); + goto remove_node; + } + + /* First let's handle the interrupts. */ + rc = handle_device_interrupts(d, fpga_node, false); + + if ( rc ) + { + printk(XENLOG_G_ERR "Interrupt failed\n"); + goto remove_node; + } + + /* Add device to IOMMUs */ + rc = iommu_add_dt_device(fpga_node); + + if ( rc < 0 ) + { + printk(XENLOG_G_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(fpga_node)); + goto remove_node; + } + + /* Set permissions. */ + naddr = dt_number_of_address(fpga_node); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(fpga_node), false, naddr); + + /* Give permission and map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + struct map_range_data mr_data = { .d = d, .p2mt = p2m_mmio_direct_c }; + rc = dt_device_get_address(fpga_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(fpga_node)); + goto remove_node; + } + + rc = map_range_to_domain(fpga_node, addr, size, &mr_data); + if ( rc ) + goto remove_node; + } + + /* This will happen if everything above goes right. */ + tr = xzalloc(struct overlay_track); + tr->dt_host_new = dt_host_new; + node_full_path_namelen = strlen(node_full_path); + tr->node_fullname = xmalloc_bytes(node_full_path_namelen + 1); + + if ( tr->node_fullname == NULL ) + { + rc = -ENOMEM; + goto remove_node; + } + + memcpy(tr->node_fullname, node_full_path, node_full_path_namelen); + tr->node_fullname[node_full_path_namelen] = '\0'; + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + +err: + spin_unlock(&overlay_lock); + xfree(fdt); + return rc; + +/* + * Failure case. We need to remove the node, free tracker(if tr exists) and + * dt_host_new. As the tracker is not in list yet so it doesn't get freed in + * handle_del_fpga_nodes() and due to that dt_host_new will not get freed so we + * we free tracker and dt_host_new here. + */ +remove_node: + spin_unlock(&overlay_lock); + handle_del_fpga_nodes(node_full_path); + xfree(dt_host_new); + + if ( tr ) + xfree(tr); + + xfree(fdt); + return rc; +} + long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) { @@ -323,6 +555,36 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return rc; } + case XEN_DOMCTL_addfpga: + { + void *pfdt; + int rc; + + if ( domctl->u.fpga_add_dt.pfdt_size > 0 ) + pfdt = xmalloc_bytes(domctl->u.fpga_add_dt.pfdt_size); + else + return -EINVAL; + + if ( pfdt == NULL ) + return -ENOMEM; + + rc = copy_from_guest(pfdt, domctl->u.fpga_add_dt.pfdt, + domctl->u.fpga_add_dt.pfdt_size); + if ( rc ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(pfdt); + + return -EFAULT; + } + + rc = handle_add_fpga_overlay(pfdt, domctl->u.fpga_add_dt.pfdt_size); + + xfree(pfdt); + + return rc; + } + case XEN_DOMCTL_delfpga: { char *full_dt_node_path; diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 04f2578..d062c17 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -324,6 +324,60 @@ void dt_print_node_names(struct dt_device_node *dt) return; } +int fpga_add_node(struct dt_device_node *fpga_node, + const char *parent_node_path) +{ + struct dt_device_node *parent_node; + struct dt_device_node *np; + struct dt_device_node *next_node; + struct dt_device_node *new_node; + + parent_node = dt_find_node_by_path(parent_node_path); + + new_node = fpga_node; + + if ( new_node == NULL ) + return -EINVAL; + + if ( parent_node == NULL ) + { + dt_dprintk("Node not found. Partial dtb will not be added"); + return -EINVAL; + } + + /* + * If node is found. We can attach the fpga_node as a child of the + * parent node. + */ + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + } + + /* + * Before attaching also check if the parent node of fpga_node is also + * same named as parent. + */ + next_node = np->allnext; + + new_node->parent = parent_node; + np->sibling = new_node; + np->allnext = new_node; + + /* + * Reach at the end of fpga_node. + * TODO: Remove this loop as we are just adding one node for now. + */ + for ( np = new_node; np->allnext != NULL; np = np->allnext ) + { + } + + /* Now plug next_node at the end of fpga_node. */ + np->allnext = next_node; + + return 0; +} + int fpga_del_node(struct dt_device_node *device_node) { struct dt_device_node *np; diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index b1b8efd..ce4667e 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1175,6 +1175,11 @@ struct xen_domctl_fpga_del_dt { uint32_t size; }; +/* XEN_DOMCTL_fpga_add. */ +struct xen_domctl_fpga_add_dt { + XEN_GUEST_HANDLE_64(void) pfdt; + uint32_t pfdt_size; /* Partial dtb size. */ +}; struct xen_domctl { uint32_t cmd; @@ -1261,6 +1266,7 @@ struct xen_domctl { #define XEN_DOMCTL_get_cpu_policy 82 #define XEN_DOMCTL_set_cpu_policy 83 #define XEN_DOMCTL_vmtrace_op 84 +#define XEN_DOMCTL_addfpga 85 #define XEN_DOMCTL_delfpga 86 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 @@ -1323,6 +1329,7 @@ struct xen_domctl { struct xen_domctl_psr_alloc psr_alloc; struct xen_domctl_vuart_op vuart_op; struct xen_domctl_vmtrace_op vmtrace_op; + struct xen_domctl_fpga_add_dt fpga_add_dt; struct xen_domctl_fpga_del_dt fpga_del_dt; uint8_t pad[128]; } u; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index eb7f645..4c8dec6 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -496,6 +496,7 @@ int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, * Prints all node names. */ void dt_print_node_names(struct dt_device_node *dt); +int fpga_add_node(struct dt_device_node *fpga_node, const char *parent_node); int fpga_del_node(struct dt_device_node *device_node); /** From patchwork Thu Sep 2 06:06:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1D24C19F3A for ; Thu, 2 Sep 2021 06:51:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5540360FC0 for ; Thu, 2 Sep 2021 06:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5540360FC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176934.322169 (Exim 4.92) (envelope-from ) id 1mLgYx-0006nJ-Pj; Thu, 02 Sep 2021 06:51:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176934.322169; Thu, 02 Sep 2021 06:51:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYw-0006gN-R6; Thu, 02 Sep 2021 06:51:02 +0000 Received: by outflank-mailman (input) for mailman id 176934; Thu, 02 Sep 2021 06:08:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLftL-0004km-3p for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:08:03 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (unknown [40.107.236.50]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 21108f96-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:08:01 +0000 (UTC) Received: from BN1PR14CA0017.namprd14.prod.outlook.com (2603:10b6:408:e3::22) by DM6PR02MB4043.namprd02.prod.outlook.com (2603:10b6:5:9f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Thu, 2 Sep 2021 06:08:00 +0000 Received: from BN1NAM02FT024.eop-nam02.prod.protection.outlook.com (2603:10b6:408:e3:cafe::64) by BN1PR14CA0017.outlook.office365.com (2603:10b6:408:e3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:08:00 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT024.mail.protection.outlook.com (10.13.2.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:59 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:21 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:21 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsf-000F6q-32; Wed, 01 Sep 2021 23:07:21 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 21108f96-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wha1qfH0ZPATby9Q4mskRJHLQuUFsgYuFwayM2JLL9kFOEi6UTuLqfGD7h0DHAwEvM25P+v7FwjXuyf8LxrWZm+lLPC/JyxnMaLUs45BrdupAe0jyBpmKlBjoSuJWsik/UbiO+vbYwJ0hek69GpbGuFMtormyMIFSRCXRsMJhGspWj5k+2+KICf2Kx5bW+PxLfEjejhWYExkrM/y+r5acvQ/WI+lVWYzKSlwypNrCqMsJ9euHDgfCUbxaQwpTwrHqqdBhaaZcfaJAJmDJGz3SuJqxM+JSuQUYvKvQwdfL+6RRmaIMp7/hSd5tJqjJRd4FkSXYzwT5AHjn6L7OefJxg== 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-SenderADCheck; bh=6vRNUT8x84jkmg4e61wPSC8IbP4rdyDEfRG2ff/C/Jw=; b=JBGHCjEfJN7w/dKGMVnu9wvudHVio860healWWmpFiTxuP0vQ8rclTzp3VqJrrIluzImVYGDwVm8+ENZCeQtJ9LJktWjDSmJ65qSD/3tJ6ETgjEpIoyDUuqv3zPOglf2fpSWz7N7bNe8boXWH98nR1bVLSg1ZdRyyTm7qoGiWAdzNEyJxOnS1upCl3WuhptAsGsxq+jxW/skkfjLog2CCuPY1YyN7OqVEXca5FUULzEUr3lsCOYJRKCbSoqq4xM/1XPYPajy/Ba4OTYwyINvv7KsIxkVuv9QOL9FtJ8lnz9ZzWzYZzYCsKaRn8rB60+kIrld0xEhbpIAmP9CRa0lgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6vRNUT8x84jkmg4e61wPSC8IbP4rdyDEfRG2ff/C/Jw=; b=D7zaaaYViPL0cynA6mP7xFHD5UMNWK19BWJoTPyo4QVUQovhGIpQmJT0Ckg1aJwVQxS2U7kPrTTZRbHpgVM7eCNnBe1hytLGalfNRyYYkfp+HXu/qBirtZznZuDsQyhglo6zq1pBjvcCPgxocRHUrQXOFMIw56X2OQ+z0sO2v50= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Ian Jackson , Wei Liu , Juergen Gross Subject: [XEN][RFC PATCH 11/13] tools/libs/ctrl: Implement new xc interfaces for fpga-add and fpga-del Date: Wed, 1 Sep 2021 23:06:01 -0700 Message-ID: <1630562763-390068-12-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: becd6285-e0dd-4a35-7bf2-08d96dd80433 X-MS-TrafficTypeDiagnostic: DM6PR02MB4043: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:1468; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u+EdAWF8Cc9fzd1XrneN/sHZ+iXJv8tDOsLWUoefmZO87ab09jnLPwNvpTIrdRuyfJ8yiVlSwU387RfV53S3f8AnPgHqed9e0SxF3idUHXTl2LnuLB9AS73NSST9YDr8mriSWDu/+lGUB83RTkfB2ZafObA1jk8Z9ucKCyfMmlmkJFNPF/fuOyykc4t2uC1+TQJim2D+QP+UYH6kONTgaKelrjNAmGFlJXDbiaEMraCQQqAAZOdBhd/61P/mf1i8UbWktvzArgodv9Bae6HNw5/h5TK6WkgbMvksl2MAEst/KgzzW4AtNPxo0ZhHAXsLFk6tEIckc3qVCaXpMEVBL/8F/ca0Kaqyd+6gOUC9hTe1QLZfpe19vNQSjuE8R280yO6J2ZWShVYeHpVU2ZL4FVI9p0mk0f1SStGX8z98SQaNkLVqG9Lqw7y6HeimywkEApQIvwYG6vvWNHF/e/+gQiwbatYrcoIC5pY4u3m20RI2ARhBqLWTHp2THuGUacTDXFW+G3BHoHb6tmMyXQRk9v4uRHPkKKMaqmb0+B3WkXGUaYTM0ansGwfup+m33drd5WU+Y+75XtoSV0bO/6K5YeBLmIsqEidFRcb5tTa+PT9uUEC4vv9CMQlE4LXJ+9W1oPK8IqUAqSZoIti85EZlzN/q/skqWfkEUAi0x/vup2QenryjPDemBN5PA0N9ofLyrtZn8ItZSZzclp2yoEogRDYHRmF1QjbUs9A7o6kwNrmVtEcmdFAAwQpK/ZzIynuKUdAnWMymH2Tu1hZbHzOWsFeB659FH7F6bIDo+R798gxude+KJ1GxwNjRlCLZdH/mnt8R3LA1JM6zGBXNTADcdg== X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(136003)(396003)(39860400002)(376002)(346002)(36840700001)(46966006)(478600001)(82740400003)(47076005)(36756003)(8676002)(70206006)(82310400003)(6666004)(36906005)(26005)(8936002)(36860700001)(2616005)(186003)(7636003)(336012)(426003)(2906002)(4326008)(7696005)(5660300002)(316002)(70586007)(9786002)(356005)(6916009)(54906003)(102446001)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:59.9152 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: becd6285-e0dd-4a35-7bf2-08d96dd80433 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT024.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB4043 xc_domain_add_fpga() sends the device tree binary overlay and size of .dtbo to xen. xc_domain_del_fpga() sends full path for the node to be removed. Signed-off-by: Vikram Garhwal --- tools/include/xenctrl.h | 4 +++ tools/libs/ctrl/Makefile | 1 + tools/libs/ctrl/xc_fpga.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 tools/libs/ctrl/xc_fpga.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index b77726e..d14b3df 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2679,6 +2679,10 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +int xc_domain_add_fpga(xc_interface *xch, void *pfdt, int pdft_size); +int xc_domain_del_fpga(xc_interface *xch, char *full_dt_node_path); + + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile index 519246b..95021b9 100644 --- a/tools/libs/ctrl/Makefile +++ b/tools/libs/ctrl/Makefile @@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk SRCS-y += xc_altp2m.c SRCS-y += xc_cpupool.c +SRCS-$(CONFIG_ARM) += xc_fpga.c SRCS-y += xc_domain.c SRCS-y += xc_evtchn.c SRCS-y += xc_gnttab.c diff --git a/tools/libs/ctrl/xc_fpga.c b/tools/libs/ctrl/xc_fpga.c new file mode 100644 index 0000000..41c37b5 --- /dev/null +++ b/tools/libs/ctrl/xc_fpga.c @@ -0,0 +1,82 @@ +/* + * + * FPGA control functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_bitops.h" +#include "xc_private.h" +#include +#include + +int xc_domain_add_fpga(xc_interface *xch, void *pfdt, int pfdt_size) +{ + int err; + DECLARE_DOMCTL; + + DECLARE_HYPERCALL_BOUNCE(pfdt, pfdt_size, XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, pfdt)) ) + goto err; + + domctl.cmd = XEN_DOMCTL_addfpga; + /* Adding the device to hardware domain by default. */ + domctl.domain = 0; + domctl.u.fpga_add_dt.pfdt_size = pfdt_size; + + set_xen_guest_handle(domctl.u.fpga_add_dt.pfdt, pfdt); + + if ( (err = do_domctl(xch, &domctl)) != 0 ) + PERROR("%s failed\n", __func__); + +err: + xc_hypercall_bounce_post(xch, pfdt); + + return err; +} + +int xc_domain_del_fpga(xc_interface *xch, char *full_dt_node_path) +{ + int err; + DECLARE_DOMCTL; + size_t size = strlen(full_dt_node_path) + 1; + + DECLARE_HYPERCALL_BOUNCE(full_dt_node_path, size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, full_dt_node_path)) ) + goto err; + + domctl.cmd = XEN_DOMCTL_delfpga; + /* + * Remove the device from the dt_host, setting hardware domain by + * default. + */ + domctl.domain = 0; + domctl.u.fpga_del_dt.size = size; + + set_xen_guest_handle(domctl.u.fpga_del_dt.full_dt_node_path, + full_dt_node_path); + + if ( (err = do_domctl(xch, &domctl)) != 0 ) + PERROR("%s failed\n", __func__); + +err: + xc_hypercall_bounce_post(xch, full_dt_node_path); + + return err; +} From patchwork Thu Sep 2 06:06:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0111C25AEE for ; Thu, 2 Sep 2021 06:51:13 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C22D61008 for ; Thu, 2 Sep 2021 06:51:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3C22D61008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176932.322158 (Exim 4.92) (envelope-from ) id 1mLgYw-0006WX-IT; Thu, 02 Sep 2021 06:51:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176932.322158; Thu, 02 Sep 2021 06:51:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYv-0006R6-Rs; Thu, 02 Sep 2021 06:51:01 +0000 Received: by outflank-mailman (input) for mailman id 176932; Thu, 02 Sep 2021 06:07:51 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLft9-0004hL-Ea for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:07:51 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (unknown [40.107.96.81]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 17559226-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:07:45 +0000 (UTC) Received: from SN4PR0501CA0083.namprd05.prod.outlook.com (2603:10b6:803:22::21) by DM6PR02MB6716.namprd02.prod.outlook.com (2603:10b6:5:218::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.24; Thu, 2 Sep 2021 06:07:43 +0000 Received: from SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com (2603:10b6:803:22:cafe::de) by SN4PR0501CA0083.outlook.office365.com (2603:10b6:803:22::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.12 via Frontend Transport; Thu, 2 Sep 2021 06:07:42 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0029.mail.protection.outlook.com (10.97.4.175) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:07:42 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:22 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:22 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsg-000F6q-Dd; Wed, 01 Sep 2021 23:07:22 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 17559226-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LnC/zNap3NmjyBziOpMvDWQXaPdOpD89oEQX+ubKVltND/+dxXMhbCEef2RIk5fspdbgiS9gDPtZQq3zCITQVgOVF1uZiVBRGPBF7wpnaJTpPeHrFM6OkggsLyVJXDrhtYW2hrXmePDB4S66IzUgNe1UyNA2WdXvOQQLI4APdUegOtGSTURqS7M+l4rabkrgmWs2KasRCUHP8uTwnNkhmUMw8levOdkR+5/ef3tXxyRGteEuIiiPxpHccPEQ0mrrxSu5Lf1S0P9rmY1nIWJnpDRWxnOupSWTCQf0yuuFfW6LcczPQwRCjIjtYlwpFaunZxeeisESEJ6n96k94KLBag== 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-SenderADCheck; bh=U7bgcXdJTXoKYKNKTamQfYEjcYOoItL0nadg/TeJWjc=; b=mCyKJMgU9KJR2RtMojV/Nq0IeDvxGu8cciiDV6vgXxXvjrWj2YRRx7I2AzY38N1UdzdvOgh4xi6nk9LpDA+IMz7IU+v6u2krT0D5+nlafEs9Mlc/thIRB9/f+HueuSPg/MzfghNoCoH0BQXn+HvbqziYrlX7dBED9WI6WNok43sUhExApe4rGUy5ruW0DJcToXlawTIBdQDNJOZ6pNpuml+IciSWp+0ITRqq2I6lQBShh0erdZVReobp6e9oRS8JH0PCdrz9jxTXADdWK/DuvCe9dt2eO2pZm51SeD2FwORtIOlMoj07k1gPrdl9ZkfVklibdDbwKiS/FzLqT9VnPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U7bgcXdJTXoKYKNKTamQfYEjcYOoItL0nadg/TeJWjc=; b=ZG9hLXS8uar1ahAzaZbhU+0vOk/tGHggI3e0eGYbEHfIYivRIYEWMUhYiJ9hbCFMovIqQCluPtHSXTRMAzhns7Vc8PT+WQtJ+jrN1lll1hYQl2ifrGQIHF+Z3W+pE3/s0ztIMnMN5dMMaoDB8xO7KnPWrDnWmzMjC2PiSCYk87c= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][RFC PATCH 12/13] tools/libs/light: Implement new libxl functions for fpga-add and fpga-del Date: Wed, 1 Sep 2021 23:06:02 -0700 Message-ID: <1630562763-390068-13-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 486282e8-4a79-441f-0264-08d96dd7f9cd X-MS-TrafficTypeDiagnostic: DM6PR02MB6716: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7da38gZlNn3e0k98mCCgPkePjD0Y6Mmg0n0YzpnVhA0UlfuB5PtLftDi2EmxPx5t2ro6pNFEXqnNkkCuwKgzDXPCcxuP1NQyaLEa8ErqZ9iRkiuY3Ru/vGcOe9xBKTySCWC2jPD8fVxCnIejAHeTXFhe5Zu7LhTJPAslvMCEOMpCuiqF02LrUaQFBAc06+i5E8dtctC7wPCXS2VMh0HOcpkloSw7Zov9gZFEYKc5ZtjpC8YJ5OhFVHPu/n0fkee9oel19yvc/bWYJQ8bOJwaJRRmrkDu5aQTERE+/0ujwxzwhs/OO97SWl4ryH5dgZfiDB6/iwxsDtMi2BtK1mzxH/Ri91eBsA1UUY7NC6ZiBySz30zgJJznLRtqvX0CPlWKLfE/vl8NqfWnoJUioVY9Ya6PSfz8VhsRByWdoF6B9PtbyDzEGL5eeMNaPyGC7LZwq/PKJkM1+DPNyUInV1dWmmteoA6KmE1g8Cv0DQSgjd0iAstUEPIgJQIH6K8JJCb74AlYyaP4QTpJgXq1j0F9e/vyJbavJaZBGsYQbzMpSn9cSvIeao19phWmnSuthBGWkPTRWHbjMuhFJldRoo/hjmn2xPT1bHJ5TbmTVFyINAGBDRa+cLHf6wE7gJL/8QbP+q2edzuWDNuHBamFm2RKM9eTGDaWXqJMImXayVfl8p6iYd/UZDAo/GPZw0F4IFtifKL+xW3y56Ldghk2SNF8Q62oJmzgOArPmE1rQTWg0D2NpE3qqGoclTPp1VXZ6V2X X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch02.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(39860400002)(346002)(396003)(376002)(136003)(36840700001)(46966006)(82310400003)(70206006)(70586007)(5660300002)(36756003)(8676002)(9786002)(36860700001)(8936002)(47076005)(478600001)(4326008)(54906003)(82740400003)(316002)(2906002)(36906005)(356005)(7636003)(336012)(186003)(2616005)(426003)(6666004)(7696005)(26005)(6916009)(102446001)(2004002);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:07:42.5194 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 486282e8-4a79-441f-0264-08d96dd7f9cd X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0029.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB6716 Signed-off-by: Vikram Garhwal --- tools/include/libxl.h | 5 +++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_fpga.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tools/libs/light/libxl_fpga.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index b9ba16d..896cbcf 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -2386,6 +2386,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); +/* FPGA device add. */ +int libxl_add_fpga_node(libxl_ctx *ctx, void *pfdt, int pfdt_size); +/* FPGA device remove. */ +int libxl_del_fpga_node(libxl_ctx *ctx, char *full_dt_node_path); + /* * Turns the current process into a backend device service daemon * for a driver domain. diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 7d8c51d..b17d4a6 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -115,6 +115,7 @@ SRCS-y += libxl_genid.c SRCS-y += _libxl_types.c SRCS-y += libxl_flask.c SRCS-y += _libxl_types_internal.c +SRCS-y += libxl_fpga.o ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS) diff --git a/tools/libs/light/libxl_fpga.c b/tools/libs/light/libxl_fpga.c new file mode 100644 index 0000000..a33d00f --- /dev/null +++ b/tools/libs/light/libxl_fpga.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" +#include +#include +#include + +static int check_partial_fdt(libxl__gc *gc, void *fdt, size_t size) +{ + int r; + + if (fdt_magic(fdt) != FDT_MAGIC) { + LOG(ERROR, "Partial FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r = fdt_check_header(fdt); + if (r) { + LOG(ERROR, "Failed to check the partial FDT (%d)", r); + return ERROR_FAIL; + } + + if (fdt_totalsize(fdt) > size) { + LOG(ERROR, "Partial FDT totalsize is too big"); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_add_fpga_node(libxl_ctx *ctx, void *pfdt, int pfdt_size) +{ + int rc = 0; + GC_INIT(ctx); + + if (check_partial_fdt(gc, pfdt, pfdt_size)) { + LOG(ERROR, "Partial DTB check failed\n"); + return ERROR_FAIL; + } else + LOG(DEBUG, "Partial DTB check passed\n"); + + /* We don't need to do xc_interface_open here. */ + rc = xc_domain_add_fpga(ctx->xch, pfdt, pfdt_size); + + if (rc) + LOG(ERROR, "%s: Adding partial dtb failed.\n", __func__); + + return rc; +} + +int libxl_del_fpga_node(libxl_ctx *ctx, char *device_path) +{ + int rc = 0; + + /* We don't need to do xc_interface_open here. */ + rc = xc_domain_del_fpga(ctx->xch, device_path); + + return rc; +} From patchwork Thu Sep 2 06:06:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 12470927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D60C4320E for ; Thu, 2 Sep 2021 06:51:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2213861008 for ; Thu, 2 Sep 2021 06:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2213861008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xilinx.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.176935.322181 (Exim 4.92) (envelope-from ) id 1mLgYz-00078B-Ia; Thu, 02 Sep 2021 06:51:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 176935.322181; Thu, 02 Sep 2021 06:51:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLgYy-00071s-7R; Thu, 02 Sep 2021 06:51:04 +0000 Received: by outflank-mailman (input) for mailman id 176935; Thu, 02 Sep 2021 06:08:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mLftM-0004km-9P for xen-devel@lists.xenproject.org; Thu, 02 Sep 2021 06:08:04 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (unknown [40.107.236.89]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 22069f30-0bb4-11ec-ae3e-12813bfff9fa; Thu, 02 Sep 2021 06:08:03 +0000 (UTC) Received: from BN1PR14CA0026.namprd14.prod.outlook.com (2603:10b6:408:e3::31) by SA0PR02MB7500.namprd02.prod.outlook.com (2603:10b6:806:e9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Thu, 2 Sep 2021 06:08:02 +0000 Received: from BN1NAM02FT024.eop-nam02.prod.protection.outlook.com (2603:10b6:408:e3:cafe::fd) by BN1PR14CA0026.outlook.office365.com (2603:10b6:408:e3::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17 via Frontend Transport; Thu, 2 Sep 2021 06:08:02 +0000 Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT024.mail.protection.outlook.com (10.13.2.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4478.19 via Frontend Transport; Thu, 2 Sep 2021 06:08:01 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Wed, 1 Sep 2021 23:07:23 -0700 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Wed, 1 Sep 2021 23:07:23 -0700 Received: from [172.19.2.115] (port=56596 helo=xsjfnuv50.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1mLfsh-000F6q-AB; Wed, 01 Sep 2021 23:07:23 -0700 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 22069f30-0bb4-11ec-ae3e-12813bfff9fa ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PqXc9nZHuBVpovZhtd88HvzHVB8dah0yQfDIGTWKMs+Vv+T5UAMeNAT5E/D6uYfZvEm2uWuuW82J0pjvKifUUNzrwm8/+Skpdi4AgJYGFABnVQlR1QgqiMShDXODKmneMn0YfQ7HenSe8ZdVbg0X9CbRUUoQ58IXoSIVM4kcEwfMGBD8ZHvQGiV9a1oRl/njSUh56tAgKvZ0Z9VmjL7B63ywm2zS46nBMW61TPi9YYsSgCIOKhuJfFrtbgoFyEMWiDRv8iDnNrPZtzBQDaDYMbyJtGdWXnpsWvarRn7AgaWu1S4r7vT+UjOGUWcAE0JFsM8Uc/4twb5JwWjyCZYPUQ== 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; bh=ykNwRHO6V8HwcABuxYp6Pws7yb5pYX82KhqW7gTX5nc=; b=CgY1gDga71hBm89KMbDdD2WJPWR2lnb/Xx0NUtEGdx/Aw+gXSQYIMeiDGyLL7+PNgMeIfowbOOSaH7E5JSBSbypdS0/VXeSh3BEKcwaHOYfuDe/st6iirOvHFrBBabzMUaKQ0Jnuvfy6lRliYhPAgAO+LgwPb05j7ix8uy4Sg+u63jMr8JgSS4eXOkeM54EVt75XTLeTsRPwhnqKsZwEwqct5IDv7ZZWoWvRQ1rk36RitMlitsv4YO81ODiL8BBmXC33L7k8CRYvUXpzkiy6QmiiPJuJvbXM3uSM/Si5wJuctlwhhH5H5QvOYTfR6QvCOIWw7JlroSUjWv05IEXO2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ykNwRHO6V8HwcABuxYp6Pws7yb5pYX82KhqW7gTX5nc=; b=G6+822z/VzQ5VXb3CZJGI+vF84PpPixiKHazT8usadnJUJV3GNk1pVcE09e/4/lWTYLrRrqJANikEdGS8Q7HDuOaeJf0OAsaoKBMNTKKIdKqsz910P17k8I65eu3sITtESFZsvSLWPYJWbHL6S82yLDzUN3R2VCtNwLPBI9cy6c= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; From: Vikram Garhwal To: CC: , , Vikram Garhwal , Ian Jackson , Wei Liu , Anthony PERARD Subject: [XEN][RFC PATCH 13/13] tools/xl: Add new xl commands fpga-add and fpga-del Date: Wed, 1 Sep 2021 23:06:03 -0700 Message-ID: <1630562763-390068-14-git-send-email-fnu.vikram@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> References: <1630562763-390068-1-git-send-email-fnu.vikram@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c76b6324-d7df-4ebd-1549-08d96dd8056b X-MS-TrafficTypeDiagnostic: SA0PR02MB7500: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:580; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X4ERjSdA+RWK/hy0b42uEAoSAyrO4UpkaYB7WUQ0Tf+YwDLtoSbqoAuTzatAkj6FhC8rhHhQGKykX/auKQywlj/5IU8rd8cbCIY5D35NXs671zs+GEb6yMwqBcw3jqL2CiAmal8ElmIacC1yg4j2ZBgTZeI5Pan+W85+dlZrw96rE3WFvLZVmy40X+U5EjfL2gvYzbN4XTJXyxSs4X/D9dhZM9Vcp0n62NU+cdvbrCs8zq/h20wNOHmjvXdi2X7UPyNx0/HOLcaRX0FuU3CBAaY38n4XRK2xUh8jCShiMoKV3Fux49PWP9fJOFviHMCTxOWGfxSqLm2JcQ3rz36dWUWmLRBjij8P3NFW7XTyvy+1vm7QP4AlMOIqZVEOzmS9ovfOroBuVdPvb47lY945NumWVBscmwakiIbHieNIfHd33rI5tB6VokevY0nh4DBQ1yuVvIi2utIE5hE4oQcm5kw89FKpZ2rJL2TyisKW21MwN+fJi3JWEsXluiWYrpw7RBPQTstRe3aGMISukcWxV2jpynYMMRoDT/kgQyWB+8YSekOQKARDNKYGzhhZ4qcdKY+jrL5Sehx/poY9pIE6sn65lrLGy9B25mj3p7EG2PFMazDrzFMJjG4eUvtOZnY7ly712XLFUptEP+WlAo4K+E/FvFBmIRW1kqRvkSfqnzfHVhoIM+vlQjHMUHLdzZ8RUHKKyan5BSFtOyKMhIkbucxxenwgKbY5F3olGZtBoQI= X-Forefront-Antispam-Report: CIP:149.199.62.198;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:xsj-pvapexch01.xlnx.xilinx.com;PTR:unknown-62-198.xilinx.com;CAT:NONE;SFS:(4636009)(396003)(376002)(346002)(39860400002)(136003)(36840700001)(46966006)(316002)(7696005)(36906005)(426003)(83380400001)(478600001)(36756003)(54906003)(26005)(2906002)(36860700001)(9786002)(8936002)(336012)(82310400003)(5660300002)(4326008)(2616005)(82740400003)(356005)(7636003)(8676002)(6916009)(70586007)(6666004)(70206006)(186003)(47076005)(102446001);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 06:08:01.9563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c76b6324-d7df-4ebd-1549-08d96dd8056b X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.62.198];Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT024.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR02MB7500 Signed-off-by: Vikram Garhwal --- tools/xl/xl.h | 2 ++ tools/xl/xl_cmdtable.c | 12 ++++++++++++ tools/xl/xl_vmcontrol.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 7e23f30..63be31e 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -140,6 +140,8 @@ int main_shutdown(int argc, char **argv); int main_reboot(int argc, char **argv); int main_list(int argc, char **argv); int main_vm_list(int argc, char **argv); +int main_fpga_add(int argc, char **argv); +int main_fpga_del(int argc, char **argv); int main_create(int argc, char **argv); int main_config_update(int argc, char **argv); int main_button_press(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 661323d..135fe6a 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -20,6 +20,18 @@ #include "xl.h" const struct cmd_spec cmd_table[] = { + { "fpga-add", + &main_fpga_add, 1, 1, + "Add a PL block", + "<.dtbo>" + "-h print this help\n" + }, + { "fpga-del", + &main_fpga_del, 1, 1, + "Remove a PL block", + "" + "-h print this help\n" + }, { "create", &main_create, 1, 1, "Create a domain from config file ", diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 435155a..f5bfdbc 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1262,6 +1262,57 @@ int main_create(int argc, char **argv) return 0; } +int main_fpga_add(int argc, char **argv) +{ + const char *fpga_config_file = argv[1]; + void *pfdt = NULL; + int rc; + int pfdt_size = 0; + + if (fpga_config_file) { + rc = libxl_read_file_contents(ctx, fpga_config_file, + &pfdt, &pfdt_size); + + if (rc) { + fprintf(stderr, "failed to read the fpga-partial device file %s\n", + fpga_config_file); + free(pfdt); + return ERROR_FAIL; + } + } else { + fprintf(stderr, "FPGA config file is not provided\n"); + return ERROR_FAIL; + } + + rc = libxl_add_fpga_node(ctx, pfdt, pfdt_size); + if (rc) + fprintf(stderr, "Adding FPGA node failed\n"); + + free(pfdt); + return rc; +} + +int main_fpga_del(int argc, char **argv) +{ + char *full_dt_node_path = argv[1]; + int rc = 0; + + if (full_dt_node_path) { + rc = libxl_del_fpga_node(ctx, full_dt_node_path); + + fprintf(stdout, "fpga-del called for device = %s\n", full_dt_node_path); + + if (rc) + fprintf(stderr, "Removing FPGA node failed\n"); + + } else { + fprintf(stderr, "No device node path provided\n"); + return ERROR_FAIL; + } + + return rc; +} + /* * Local variables: * mode: C