From nobody Sun Nov 24 21:36:52 2024 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=1727455135; cv=none; d=zohomail.com; s=zohoarc; b=IxU+Q6VVRFX6WW4e94kydujn6UZP4tI+V16plqB2zrkYGJ7yARG2VaWNliZ+WInePvt6CJ0aHrZPOTaGThuQM7apFMGXjcUDAqnoPpUWDINE9BPRwwtIBByYwkeOCcW7j0TXVEdRLstxvgBkAsLgAsQTjHXTpGrubo5N5V71Ok8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727455135; 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=ghl72hwaxwhJtVodRAQ4IqGk8w7bdQ1cXJih3Z6pDfI=; b=YUkIFVVUQNF+RNg6iAK3jR8AdsycagvVVgjoYuu/vt7MbPP6mC7TrKOCL8KhAMo598tbFQ7kLHigZICT66xl7BJWmU+kjkXnDM0tt5xRjhqk2LUQM14KamQrIhX0bfqrwpssiQ1mkLXE5ufVrO9IcsBFc9u2CKeWMUPwCEuC/vM= 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 1727455135526531.4798051256988; Fri, 27 Sep 2024 09:38:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.806466.1217877 (Exim 4.92) (envelope-from ) id 1suDzM-0000T8-TA; Fri, 27 Sep 2024 16:38:40 +0000 Received: by outflank-mailman (output) from mailman id 806466.1217877; Fri, 27 Sep 2024 16:38:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1suDzM-0000Sz-Q1; Fri, 27 Sep 2024 16:38:40 +0000 Received: by outflank-mailman (input) for mailman id 806466; Fri, 27 Sep 2024 16:38:39 +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 1suDuT-0001aC-UI for xen-devel@lists.xenproject.org; Fri, 27 Sep 2024 16:33:37 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3c35a461-7cee-11ef-99a2-01e77a169b0f; Fri, 27 Sep 2024 18:33:32 +0200 (CEST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5c5b9d2195eso2758619a12.1 for ; Fri, 27 Sep 2024 09:33:32 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27d47a2sm150697966b.89.2024.09.27.09.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 09:33:31 -0700 (PDT) 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: 3c35a461-7cee-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727454812; x=1728059612; 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=ghl72hwaxwhJtVodRAQ4IqGk8w7bdQ1cXJih3Z6pDfI=; b=aJmNJ4bmjR1x27STdMBQx9CMBLQIQQGtNzyMZuDyfqLbc3QeSjojkmQ8kk+tZRFlrl Qbobq4JVaWnkZTHCsrCVX4qvvetK9C/7iS95GqYkbIAwauYE3K66Pac1DuZP00/lALQ2 ScBGutzmQ4LxL0L7sFtr09lh/C6xfqFid6b7VAul0X2CAn0MIzibofPUcYlfOKJyqtX9 hgM1NgpzPZekdFxWscRI/7GcOKKGd3KP7TQ2YzeuYSHVbE2dE0aP364+WCEeZJTkzTUl tfBV8HNu3/4KVfYGEQG3ihcewW8rYkFelWmKOE6NhcYifpLVnz3TdFfLp8vCyypvhWV9 1Mcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727454812; x=1728059612; 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=ghl72hwaxwhJtVodRAQ4IqGk8w7bdQ1cXJih3Z6pDfI=; b=ruTh7/1wrct3cPtL/JnijsI7ufxq/X/N+DDjDNKhYXqdEkhSxzndwv6IZsvD7KdA1F +ZPI0i1uAzDCAbgrvcyy8/pvrb0sD9sOss9rZ20dR9wxPAAX2tUoDzspBHVb43k78GK4 vhU6vkr1pdknSavXgpgt+DHBL9zDNRv+QO5yhwQKzBMcN1y3ZUWAWeqsicG1yD4CxBaz ofHTzcSnae0KKIVliWxaFoAH+uxCag1Lo4U4uqp6wD09iK/HHxQGxKeo4nOF/ClstVBq I3JWdNW7WVIDQvTi+vNnkN7mxWeaPy9i2gdu0A4b6VHJ1GROBUYkx4gVhRDvwqkbm5bZ nwWg== X-Gm-Message-State: AOJu0Yx5qUxLHzmn8JjiAova0hebdjM/UzRDoDaRVe9/HDQujcokNqAC rQJ/4Tp5KAVOXftXJbwV+jmBY7y3qRZe7gXszG8EdavkZ86UmylSWhZoAQ== X-Google-Smtp-Source: AGHT+IFg4M+WfEDQE2Zk/Wh79VNEHm6x6c0tNkZGB1AmvmEqyvMOU0ctCqPpEzyJeQRLNVjYWdLLug== X-Received: by 2002:a17:906:730d:b0:a7a:a0c2:8be9 with SMTP id a640c23a62f3a-a93c4908e28mr387347866b.18.1727454811793; Fri, 27 Sep 2024 09:33:31 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v8 7/7] xen/riscv: introduce early_fdt_map() Date: Fri, 27 Sep 2024 18:33:19 +0200 Message-ID: <65c49e7aa25249cd94be3ce9b850d023c9dff731.1727449154.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1727455135790116600 Content-Type: text/plain; charset="utf-8" Introduce function which allows to map FDT to Xen. Also, initialization of device_tree_flattened happens using early_fdt_map(). Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- xen/arch/riscv/include/asm/mm.h | 2 ++ xen/arch/riscv/mm.c | 55 +++++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 7 +++++ 3 files changed, 64 insertions(+) diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/m= m.h index ce1557bb27..4b7b00b850 100644 --- a/xen/arch/riscv/include/asm/mm.h +++ b/xen/arch/riscv/include/asm/mm.h @@ -259,4 +259,6 @@ static inline unsigned int arch_get_dma_bitsize(void) =20 void setup_fixmap_mappings(void); =20 +void *early_fdt_map(paddr_t fdt_paddr); + #endif /* _ASM_RISCV_MM_H */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index e8430def14..4a628aef83 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -1,13 +1,16 @@ /* SPDX-License-Identifier: GPL-2.0-only */ =20 +#include #include #include #include #include +#include #include #include #include #include +#include =20 #include #include @@ -369,3 +372,55 @@ int destroy_xen_mappings(unsigned long s, unsigned lon= g e) BUG_ON("unimplemented"); return -1; } + +void * __init early_fdt_map(paddr_t fdt_paddr) +{ + /* We are using 2MB superpage for mapping the FDT */ + paddr_t base_paddr =3D fdt_paddr & XEN_PT_LEVEL_MAP_MASK(1); + paddr_t offset; + void *fdt_virt; + uint32_t size; + int rc; + + /* + * Check whether the physical FDT address is set and meets the minimum + * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be = at + * least 8 bytes so that we always access the magic and size fields + * of the FDT header after mapping the first chunk, double check if + * that is indeed the case. + */ + BUILD_BUG_ON(MIN_FDT_ALIGN < 8); + if ( !fdt_paddr || fdt_paddr % MIN_FDT_ALIGN ) + return NULL; + + /* The FDT is mapped using 2MB superpage */ + BUILD_BUG_ON(BOOT_FDT_VIRT_START % MB(2)); + + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START, maddr_to_mfn(base_paddr), + MB(2) >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO); + if ( rc ) + panic("Unable to map the device-tree.\n"); + + offset =3D fdt_paddr % XEN_PT_LEVEL_SIZE(1); + fdt_virt =3D (void *)BOOT_FDT_VIRT_START + offset; + + if ( fdt_magic(fdt_virt) !=3D FDT_MAGIC ) + return NULL; + + size =3D fdt_totalsize(fdt_virt); + if ( size > BOOT_FDT_VIRT_SIZE ) + return NULL; + + if ( (offset + size) > MB(2) ) + { + rc =3D map_pages_to_xen(BOOT_FDT_VIRT_START + MB(2), + maddr_to_mfn(base_paddr + MB(2)), + MB(2) >> PAGE_SHIFT, + PAGE_HYPERVISOR_RO); + if ( rc ) + panic("Unable to map the device-tree\n"); + } + + return fdt_virt; +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index c4fadd36c6..a316901fd4 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -57,6 +58,12 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 setup_fixmap_mappings(); =20 + device_tree_flattened =3D early_fdt_map(dtb_addr); + if ( !device_tree_flattened ) + panic("Invalid device tree blob at physical address %#lx. The DTB = must be 8-byte aligned and must not exceed %lld bytes in size.\n\n" + "Please check your bootloader.\n", + dtb_addr, BOOT_FDT_VIRT_SIZE); + printk("All set up\n"); =20 machine_halt(); --=20 2.46.1