From patchwork Tue Jan 17 17:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13104942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 57DEAC54E76 for ; Tue, 17 Jan 2023 17:45:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.479665.743677 (Exim 4.92) (envelope-from ) id 1pHq1P-0001ig-Bh; Tue, 17 Jan 2023 17:45:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 479665.743677; Tue, 17 Jan 2023 17:45:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHq1P-0001iX-8n; Tue, 17 Jan 2023 17:45:19 +0000 Received: by outflank-mailman (input) for mailman id 479665; Tue, 17 Jan 2023 17:45:18 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pHq1N-0000oY-VH for xen-devel@lists.xenproject.org; Tue, 17 Jan 2023 17:45:18 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2068.outbound.protection.outlook.com [40.107.93.68]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b26ea08b-968e-11ed-b8d0-410ff93cb8f0; Tue, 17 Jan 2023 18:45:15 +0100 (CET) Received: from BN9P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::12) by DS0PR12MB7748.namprd12.prod.outlook.com (2603:10b6:8:130::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.19; Tue, 17 Jan 2023 17:45:11 +0000 Received: from BN8NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10c:cafe::37) by BN9P222CA0007.outlook.office365.com (2603:10b6:408:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.19 via Frontend Transport; Tue, 17 Jan 2023 17:45:11 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT040.mail.protection.outlook.com (10.13.177.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6002.13 via Frontend Transport; Tue, 17 Jan 2023 17:45:10 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 17 Jan 2023 11:45:10 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 17 Jan 2023 11:45:10 -0600 Received: from xcbayankuma41x.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 17 Jan 2023 11:45:09 -0600 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: b26ea08b-968e-11ed-b8d0-410ff93cb8f0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GXCny/wSrrhscW19374vRe2281HDS0fgBasSUpoii5rIXRDlcOQgQmINLmzxGNTcvZNogd+jsaihG22k37zLpn2JSQo6Jvby6CWPCJ1aJbzuc9Z+ht09Q4MhhgCPcGnzDj3tt6T1Dy1IoEEAhVGSuAB10dd3F4ZQHlPUa5r3mXLoXunZIX8kFwWa1v1F+I3xbplTGwnJw6EhE6mw9beZeXBuj+hC+OJZze8hpVxtYv/6VzFq/p6Dp6cofo1ZwmJnFPwPhDkfocis0THKPEyycUXELnL3uXDc/HKCb4WEzYkjkuXvsbRL5wbZv4qNjEgv1duv0D/c4KIhziajnYOXVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vkQVewwIqXR9Op0ttYXasbtHBsayU2os3eE5hDirBvk=; b=FQoEYkNw6yYTn7jYm4rVnCNRg7gWuQdZy85JnySDVeruMPmgg79kJu9+I90PXeGIkjxYlVZ8EF+jZAqt5dyLgiRbzYq/bCzvstZg4nASxM2uK1Zk+OGjv5r5unceKXbCMGAYPObL8cCLpGNtvtbrSVeEvuWgArP9jI6GKuYKbZ+QWN66dfYYmYXEbSsWobuptfQarGjb9yi4wgcfKCrigtC/pO2/VW3LCltCtNTaYNfavOEPw9wrIiYyKrPyOgKf0gZsHatEKuHhYwdqerJrX0xECTHmpwYQlpsUQvakUAA/atYasmckBmtP0JYIvZZfFHJLBzW+4TRWgx8K1s4cqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vkQVewwIqXR9Op0ttYXasbtHBsayU2os3eE5hDirBvk=; b=N+749NBDsQndCdGQprdG18U2/zH7ULvaxiouy8Hv1GWcU30Y2v53MOMC3mQKY8mTZf2QjWiHN0ugmyV+ERXaa391oezfW2S7ETee80u1eu8Hx7XOAETOStJj4VEhzOZmOkD4sH0nGKwBSL2bbWWmgbu6yvde6HwZBxki16Zh3/c= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: , , , , , Ayan Kumar Halder Subject: [XEN v2 04/11] xen/arm: Typecast the DT values into paddr_t Date: Tue, 17 Jan 2023 17:43:51 +0000 Message-ID: <20230117174358.15344-5-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230117174358.15344-1-ayan.kumar.halder@amd.com> References: <20230117174358.15344-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT040:EE_|DS0PR12MB7748:EE_ X-MS-Office365-Filtering-Correlation-Id: 08810278-fe2d-4d21-a9ab-08daf8b294bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MVFlhh3hGOr3WfjuYxrYsEIcglild1rl/1gZIfaWf6OXo3zO6ozVTvoKvpDtc5ZGg4wsRcZA2+nSSsiJlRh5bdz72y8Pwp5XO2XxVVRvajNDbopwmzTKCdOgDm3cvB2noL3WT6OFvYjnGUN/cdM45EbzTpFvQN4VcfzV6lgL4DHupaZfu3rS+O4t/oCdM5ZmYZ0iW2IctRZhg8c5X1FDv1I26MJvnzlzsg9rQ7ps3W9ecP+tVovRBFfGR2gEeMutvU0AWPqCZ0CbfkYlJ/1mNrgB0cf+tobqz0gXf2aRyTcLy4Fs5kx6jtnF2iPhrLHlHdjrGSXyYOqoUjs63BM/ZAS+jXiF4PSg21laIUEfaSA2U4Z6neRilkmKgwyVCG+SShOrxywqSHyku+RXtLhqzlVk6OsOMITRXDGhXYxExoXaYsIIq2I7V/vukoPmZ6ZJjg83nlC6Oca+WxrGs3k/q5ZX/GhPyAIxo3PCFOD7o9/ikroezzt3ML4qczmwq510Pm3LOYuEFjbvM7edJvgKtjcjdSHgRqHWmuDHcyeXd9FEOalxIt2KySw7WxN8yfGyQvfnR35/OmSvu9Gc63PMTOpcc3S9hdKB3+bx+Zz/LLAmaBnC4GitzQkfuh8E4xhhhYUBcK9pfxH7lyw7VMpmtfJa+0PCxdoePW3ii+v9BnE2Z4Z9Fv1izVmkrI/1+ZKxiFSpJeCWoApF6Mydf5NHHomgnuviXMYlfW+JWm2i6i0= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(346002)(136003)(396003)(376002)(451199015)(40470700004)(46966006)(36840700001)(36860700001)(47076005)(426003)(83380400001)(82740400003)(86362001)(356005)(40480700001)(2906002)(82310400005)(5660300002)(8936002)(40460700003)(316002)(8676002)(6916009)(478600001)(6666004)(26005)(1076003)(186003)(70206006)(2616005)(336012)(4326008)(70586007)(81166007)(54906003)(41300700001)(103116003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2023 17:45:10.9227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08810278-fe2d-4d21-a9ab-08daf8b294bb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7748 In future, we wish to support 32 bit physical address. However, one can only read u64 values from the DT. Thus, we need to typecast the values appropriately from u64 to paddr_t. device_tree_get_reg() should now be able to return paddr_t. This is invoked by various callers to get DT address and size. Similarly, dt_read_number() is invoked as well to get DT address and size. The return value is typecasted to paddr_t. fdt_get_mem_rsv() can only accept u64 values. So, we provide a warpper for this called fdt_get_mem_rsv_paddr() which will do the necessary typecasting before invoking fdt_get_mem_rsv() and while returning. Signed-off-by: Ayan Kumar Halder --- Changes from v1 - 1. Dropped "[XEN v1 2/9] xen/arm: Define translate_dt_address_size() for the translation between u64 and paddr_t" and "[XEN v1 4/9] xen/arm: Use translate_dt_address_size() to translate between device tree addr/size and paddr_t", instead this approach achieves the same purpose. 2. No need to check for truncation while converting values from u64 to paddr_t. xen/arch/arm/bootfdt.c | 23 +++++++++------ xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/include/asm/device_tree.h | 40 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/setup.h | 2 +- xen/arch/arm/setup.c | 14 ++++----- xen/arch/arm/smpboot.c | 2 +- 6 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 xen/arch/arm/include/asm/device_tree.h diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c index 0085c28d74..f536a3f3ab 100644 --- a/xen/arch/arm/bootfdt.c +++ b/xen/arch/arm/bootfdt.c @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include #include static bool __init device_tree_node_matches(const void *fdt, int node, @@ -53,10 +53,15 @@ static bool __init device_tree_node_compatible(const void *fdt, int node, } void __init device_tree_get_reg(const __be32 **cell, u32 address_cells, - u32 size_cells, u64 *start, u64 *size) + u32 size_cells, paddr_t *start, paddr_t *size) { - *start = dt_next_cell(address_cells, cell); - *size = dt_next_cell(size_cells, cell); + /* + * dt_next_cell will return u64 whereas paddr_t may be u64 or u32. Thus, one + * needs to cast paddr_t to u32. Note that we do not check for truncation as + * it is user's responsibility to provide the correct values in the DT. + */ + *start = (paddr_t) dt_next_cell(address_cells, cell); + *size = (paddr_t) dt_next_cell(size_cells, cell); } static int __init device_tree_get_meminfo(const void *fdt, int node, @@ -326,7 +331,7 @@ static int __init process_chosen_node(const void *fdt, int node, printk("linux,initrd-start property has invalid length %d\n", len); return -EINVAL; } - start = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); + start = (paddr_t) dt_read_number((void *)&prop->data, dt_size_to_cells(len)); prop = fdt_get_property(fdt, node, "linux,initrd-end", &len); if ( !prop ) @@ -339,7 +344,7 @@ static int __init process_chosen_node(const void *fdt, int node, printk("linux,initrd-end property has invalid length %d\n", len); return -EINVAL; } - end = dt_read_number((void *)&prop->data, dt_size_to_cells(len)); + end = (paddr_t) dt_read_number((void *)&prop->data, dt_size_to_cells(len)); if ( start >= end ) { @@ -594,9 +599,11 @@ static void __init early_print_info(void) for ( i = 0; i < nr_rsvd; i++ ) { paddr_t s, e; - if ( fdt_get_mem_rsv(device_tree_flattened, i, &s, &e) < 0 ) + + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &s, &e) < 0 ) continue; - /* fdt_get_mem_rsv returns length */ + + /* fdt_get_mem_rsv_paddr returns length */ e += s; printk(" RESVD[%u]: %"PRIpaddr" - %"PRIpaddr"\n", i, s, e); } diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f904f12408..72b9afbb4c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -949,7 +949,7 @@ static int __init process_shm(struct domain *d, struct kernel_info *kinfo, BUG_ON(!prop); cells = (const __be32 *)prop->value; device_tree_get_reg(&cells, addr_cells, addr_cells, &pbase, &gbase); - psize = dt_read_number(cells, size_cells); + psize = (paddr_t) dt_read_number(cells, size_cells); if ( !IS_ALIGNED(pbase, PAGE_SIZE) || !IS_ALIGNED(gbase, PAGE_SIZE) ) { printk("%pd: physical address 0x%"PRIpaddr", or guest address 0x%"PRIpaddr" is not suitably aligned.\n", diff --git a/xen/arch/arm/include/asm/device_tree.h b/xen/arch/arm/include/asm/device_tree.h new file mode 100644 index 0000000000..51e0f0ae20 --- /dev/null +++ b/xen/arch/arm/include/asm/device_tree.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * xen/arch/arm/include/asm/device_tree.h + * + * Wrapper functions for device tree. This helps to convert dt values + * between u64 and paddr_t. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + */ + +#ifndef __ARCH_ARM_DEVICE_TREE__ +#define __ARCH_ARM_DEVICE_TREE__ + +#include + +inline int fdt_get_mem_rsv_paddr(const void *fdt, int n, + paddr_t *address, + paddr_t *size) +{ + uint64_t dt_addr; + uint64_t dt_size; + int ret = 0; + + ret = fdt_get_mem_rsv(fdt, n, &dt_addr, &dt_size); + + *address = (paddr_t) dt_addr; + *size = (paddr_t) dt_size; + + return ret; +} + +#endif /* __ARCH_ARM_DEVICE_TREE__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index a926f30a2b..6105e5cae3 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -158,7 +158,7 @@ extern uint32_t hyp_traps_vector[]; void init_traps(void); void device_tree_get_reg(const __be32 **cell, u32 address_cells, - u32 size_cells, u64 *start, u64 *size); + u32 size_cells, paddr_t *start, paddr_t *size); u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 1f26f67b90..da13439e62 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -39,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -222,11 +222,11 @@ static void __init dt_unreserved_regions(paddr_t s, paddr_t e, { paddr_t r_s, r_e; - if ( fdt_get_mem_rsv(device_tree_flattened, i, &r_s, &r_e ) < 0 ) + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, i, &r_s, &r_e ) < 0 ) /* If we can't read it, pretend it doesn't exist... */ continue; - r_e += r_s; /* fdt_get_mem_rsv returns length */ + r_e += r_s; /* fdt_get_mem_rsv_paddr returns length */ if ( s < r_e && r_s < e ) { @@ -502,13 +502,13 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e, { paddr_t mod_s, mod_e; - if ( fdt_get_mem_rsv(device_tree_flattened, - i - mi->nr_mods, - &mod_s, &mod_e ) < 0 ) + if ( fdt_get_mem_rsv_paddr(device_tree_flattened, + i - mi->nr_mods, + &mod_s, &mod_e ) < 0 ) /* If we can't read it, pretend it doesn't exist... */ continue; - /* fdt_get_mem_rsv returns length */ + /* fdt_get_mem_rsv_paddr returns length */ mod_e += mod_s; if ( s < mod_e && mod_s < e ) diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 412ae22869..ee59b1d379 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -159,7 +159,7 @@ static void __init dt_smp_init_cpus(void) continue; } - addr = dt_read_number(prop, dt_n_addr_cells(cpu)); + addr = (paddr_t) dt_read_number(prop, dt_n_addr_cells(cpu)); hwid = addr; if ( hwid != addr )