From nobody Wed Feb 5 20:04:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1733938112; cv=none; d=zohomail.com; s=zohoarc; b=DtBgRaMj+Vd0UgxUSj6r4VhWrWi1EUH0hXKAOCtq3ONp5MCnEIPhXS9YHnJFMy0DgcEHzmh5u+YLlQlNq+LeflSOn7aUsYKCyBmV6m6czvtuxKGvlprl9pmjxoKdAW9CDiUUp6nJQAGp7UdsmcAseaK70a2ZLirnEj1lQv7XWuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733938112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MVUeGYT1/F6OE3Cc8TjMGFB+HbFqEqO/qxv449JXpGc=; b=leYb1V7Rd3aZfrwVCY2z9TSkSGfSJ+u7zGmgAOdC0CeKc762GHSuSn/S1wuMP9i8/iYFzzWf9zfItdepJAgTpbUfKQekcaIi80GtWhVg4v799fpDak+5dehHfviHGODJVudZZisX1Q14Y6pfXqyR5yGkCe2y6GQt/PqTteUdRng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733938112904644.2937264080234; Wed, 11 Dec 2024 09:28:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.855083.1268174 (Exim 4.92) (envelope-from ) id 1tLQVK-0000PG-Ph; Wed, 11 Dec 2024 17:28:06 +0000 Received: by outflank-mailman (output) from mailman id 855083.1268174; Wed, 11 Dec 2024 17:28:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tLQVK-0000OE-IB; Wed, 11 Dec 2024 17:28:06 +0000 Received: by outflank-mailman (input) for mailman id 855083; Wed, 11 Dec 2024 17:28:05 +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 1tLQVJ-0007J6-Gk for xen-devel@lists.xenproject.org; Wed, 11 Dec 2024 17:28:05 +0000 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [2a00:1450:4864:20::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4722f73b-b7e5-11ef-99a3-01e77a169b0f; Wed, 11 Dec 2024 18:28:04 +0100 (CET) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9e8522445dso1396545366b.1 for ; Wed, 11 Dec 2024 09:28:04 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6656f306csm687297466b.61.2024.12.11.09.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 09:28:02 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 4722f73b-b7e5-11ef-99a3-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733938083; x=1734542883; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MVUeGYT1/F6OE3Cc8TjMGFB+HbFqEqO/qxv449JXpGc=; b=HCWkt8Ic8xaYwSk49tmcqrKvGfvT2dO4IUidbkqpU3s6I4vfcTAi1Bq67ITpfKa/4E BjIKQQUmXeEE86MJ+iWnkJxX+kfSl9LDWfvyrUgp89EPZHP2GpS3vg3UN7uqG9Lv+K3m ctVDK1KKpIC9eT63F0PsPLbfKzXKUKgjK3gJmFqMonf9kD7QLRWbcwQ71njFeQxYaDbO uDT4nN/qc7/zc2tfStBK5x2B4q/iwr7AZibT47U5QdGikBwH/2UpiglEipj5z+Re2phJ 3yaYt3CXrxiDbmY+srWQaaKIhCOj5LZ+CEsAlpCfJd2EQfSvZrbzcDokpmriLkxOcrui k1aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733938083; x=1734542883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MVUeGYT1/F6OE3Cc8TjMGFB+HbFqEqO/qxv449JXpGc=; b=LeoXpqqSd+zlLogdX8nLJS9WS4C1V1liX/KcYz6WMQLZBAWC/ZcZnTAYLlMoejl5s1 hTr46quNkqGfwQ5wNppqXrMLBsvA2OG2HdvqJerCCZ9icN8C1TuVdBicPT0eVZbc3kEY UwdCz3EkgLJqVE2I8ONjKkA1xLi2jd1qgyfeTp3aU8kMEWUuQ0tMpdrvCiiPfE0dLZyd dLxMUR+Zzvtnj2E55oDITUx6vCtlKhO+jzrGkspnHubCr+E7SFi66637yWKBlsE+VKE9 Wgrr1Ubty2WGJaaCxp//vjiBDeGhCR2yfwKljUn6gCOzGu88huY4lB8ncEC8ESIrkgnE t3Yw== X-Gm-Message-State: AOJu0YwNbd2+5YQHJoH3OB27Fg5QZgqspm500t5ZQDFdFoBlqR7fs/WT 2VqsVDhhcsgcUe3QTx4pU/LlIiUI4cKLYf9Fub3pF75T/LdgqG7aslDYPfJk X-Gm-Gg: ASbGncscme+breO1q1yUtCmQok2Tsd8QVrDQu4WvfJ2fhoMC5a3rqOO/iPFp+IAw+EO w42vuRZGLQ2ofxRSCvjQ8KkhZwJzvu9//4sIk+VApOBpEGHuZRrxbz7wNJnCRebPzpUIb/yl3sF Rvrc4dwio3bn2/AOHInZ/8lCAsNwx00xDm0xi5vWgzBCB1hJ3XrmYU5uIyen3er2He+VBmboa6A lLLiw/nGbykaINFkljJ+q5qTMd4jqvpF2wChD5SDao2Z3/ihvvTlt8= X-Google-Smtp-Source: AGHT+IHk81CkV2ksl1MLimg86CXEDzadwLfuTlvYafnNlthU8knKAYe1HaxlGYqoNPeORU4oJS52nA== X-Received: by 2002:a17:906:3299:b0:aa6:6510:f27e with SMTP id a640c23a62f3a-aa6b115bc46mr379902766b.14.1733938082630; Wed, 11 Dec 2024 09:28:02 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 7/7] xen/riscv: relocating and unflattening host device tree Date: Wed, 11 Dec 2024 18:27:51 +0100 Message-ID: <8906108d2e29637a42d5e127e393337d6b259b30.1733937787.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1733938114924116600 Content-Type: text/plain; charset="utf-8" Introduce relocate_fdt() and call it to relocate FDT to Xen heap instead of using early mapping as it is expected that discard_initial_modul= es() ( is supposed to call in the future ) discards the FDT boot module and remove_early_mappings() destroys the early mapping. Unflatten a device tree, creating the tree of struct device_node. It also fills the "name" and "type" pointers of the nodes so the normal device-tree walking functions can be used. Set device_tree_flattened to NULL in the case when acpi_disabled is equal to false. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in V2: - Move introduction of relocate_fdt() to the current patch with the follow= ing change: - use xvmalloc() instead of xmalloc_bytes() in relocate_fdt(); - Drop the check of returned fdt_size from boot_fdt_info() to be in sync with Arm and boot_fdt_info() will panic anyway if something wrong with DTB. - Update the commit message. --- xen/arch/riscv/setup.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index bea3f27c4d..fb6bbba684 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include @@ -8,6 +9,7 @@ #include #include #include +#include =20 #include =20 @@ -52,10 +54,24 @@ void __init copy_from_paddr(void *dst, paddr_t paddr, u= nsigned long len) } } =20 +/* Relocate the FDT in Xen heap */ +static void * __init relocate_fdt(paddr_t dtb_paddr, size_t dtb_size) +{ + void *fdt =3D xvmalloc_array(uint8_t, dtb_size); + + if ( !fdt ) + panic("Unable to allocate memory for relocating the Device-Tree.\n= "); + + copy_from_paddr(fdt, dtb_paddr, dtb_size); + + return fdt; +} + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { const char *cmdline; + size_t fdt_size; =20 remove_identity_mapping(); =20 @@ -80,8 +96,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id, _end - _start, false) ) panic("Failed to add BOOTMOD_XEN\n"); =20 - if ( !boot_fdt_info(device_tree_flattened, dtb_addr) ) - BUG(); + fdt_size =3D boot_fdt_info(device_tree_flattened, dtb_addr); =20 cmdline =3D boot_fdt_cmdline(device_tree_flattened); printk("Command line: %s\n", cmdline); @@ -99,6 +114,18 @@ void __init noreturn start_xen(unsigned long bootcpu_id, */ system_state =3D SYS_STATE_boot; =20 + if ( acpi_disabled ) + { + printk("Booting using Device Tree\n"); + device_tree_flattened =3D relocate_fdt(dtb_addr, fdt_size); + dt_unflatten_host_device_tree(); + } + else + { + device_tree_flattened =3D NULL; + panic("Booting using ACPI isn't supported\n"); + } + printk("All set up\n"); =20 machine_halt(); --=20 2.47.1