From nobody Mon Nov 25 05:27:45 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=1727781757; cv=none; d=zohomail.com; s=zohoarc; b=OIU0IdouKI1NLR4vJtFpjCPKufM5lXBrJq1BaIPiid2tHxtspFGMQrswz2XBxClEtx2DnDWOkKq8CAPmhx3OBd9isW4o3JE1OJql7VHIZlNaEnEf4V94b333J7i0HB5pmxMkvS5t7fBWaPG4dZ4oEhO9iNnFgzCPLTh9wkQ9Ce0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727781757; 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=pzyb+S2cXg2nYubA3PbWR50woG4ltgAkzmb2CBniKuU=; b=fai5r7xHXoHLgxNZggFwdcVi+CVEN8TLfE8AIG+4dRMLUe1q6q+cHdzTh7MBKnEPDlvjK8m+qKEzxEb/Ul11haCZyETn9DSw8swyddX/7Q9EeeomxYCFHF9DcjvAKIvLM/Mf8uE0tQeQCF1TsG2in53tcw9WXz3nseuFc/2UzuU= 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 17277817571251010.1935302428053; Tue, 1 Oct 2024 04:22:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.808011.1219807 (Exim 4.92) (envelope-from ) id 1svax9-0006Yk-OF; Tue, 01 Oct 2024 11:22:03 +0000 Received: by outflank-mailman (output) from mailman id 808011.1219807; Tue, 01 Oct 2024 11:22: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 1svax9-0006Yd-Km; Tue, 01 Oct 2024 11:22:03 +0000 Received: by outflank-mailman (input) for mailman id 808011; Tue, 01 Oct 2024 11:22:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svax7-0006KO-KI for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 11:22:01 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 60815ba0-7fe7-11ef-a0ba-8be0dac302b0; Tue, 01 Oct 2024 13:22:00 +0200 (CEST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5398e58ceebso2489856e87.0 for ; Tue, 01 Oct 2024 04:22:00 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53980fcdcd6sm1445087e87.153.2024.10.01.04.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 04:21:59 -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: 60815ba0-7fe7-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727781720; x=1728386520; 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=pzyb+S2cXg2nYubA3PbWR50woG4ltgAkzmb2CBniKuU=; b=J54fvM7AU93cR4kFdS9MEhxffuYvw+OZxuleeuNIH6uU2GNLufqm/iTR42zpOm34Zw 6Fc6c8IvpfljlnRQv6XH9yJDuTfZbn7wYiioUX9A/KtbErLfbHP1qyx/EFulbwQpoAFo C1tNK19fP4zzWH6/pRgu1VODMrm4kZUOdo9L46giifwaGzZqquuxugUZnuG4EQwlyXBv mJ2u2P9VveZxqLflzJo8GMxfgj5MtwxqyrC1QA3ikWUK2p0O3I6n9CkjrMwx+Yb7W46Y Fa+jpPpibkOMl8YGBWF7+3WOewzaKqqicbOXw/lVAWJYebPe+PGubAJqb93b+xi2aros yTRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727781720; x=1728386520; 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=pzyb+S2cXg2nYubA3PbWR50woG4ltgAkzmb2CBniKuU=; b=Oylu2ytpVqcNTorHuaB6WBUSI3DpjkPaxcKQy5aYKAZEPywJFrm/DKzb3L1ZRF7C12 rUq6mi2JTW0ZVfQVuxb+CT2jcamRo2HiLWommbSExQG/F8S8PacXszZ5fRAQekEfFHZX ftVjhyGbXGkJWFLyjpdgcfIybMmj5juJyg/4+zC4loFfKXY7QYfQuP7o4EuZMe9UnHzZ oxxFSpr0hdQ2l74w7vTAQsSJLSjO7VGeIi7vm4R2jKe/M9cu2ILMC/VF2VQE2XtSEgDO TibkywmsQ4QnO++nC8BvqY5/6Y7XnVzpLtdOKUUDiC2B3eefQAZ8CBLpKA801HXq0nTd jGFw== X-Gm-Message-State: AOJu0YzQVbOXYZb8IzF3oqjjpSBatYG10m7WzuJSI7G7ipHB2mhukznv mSWs9RPMjpXu8UgXMfIiOy6JT/zzzXQBSPZzIQdduRZXxIzFo2R8IvVyDw== X-Google-Smtp-Source: AGHT+IGZID+EOqA1XEWrqtW7RXPGrTlUIDK3EMOVPHyIL1V8s7ekWo/LA+b89W1g/IOIOD6BsSXe3g== X-Received: by 2002:a05:6512:2203:b0:52f:260:c459 with SMTP id 2adb3069b0e04-5399a25bc6fmr1061039e87.22.1727781719520; Tue, 01 Oct 2024 04:21:59 -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 v9 2/2] xen/riscv: introduce early_fdt_map() Date: Tue, 1 Oct 2024 13:21:22 +0200 Message-ID: <921235d8075bdd296752a7cbe0fa70b728a57b58.1727781468.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: 1727781758871116600 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 --- Changes in V6-V9: - Nothing changed. Only rebase. --- Changes in V5: - drop usage of PTE_BLOCK for flag argument of map_pages_to_xen() in early= _fdt_map() as block mapping is now default behaviour. Also PTE_BLOCK was dropped in= the patch "xen/riscv: page table handling". --- Changes in V4: - s/_PAGE_BLOCK/PTE_BLOCK - Add Acked-by: Jan Beulich - unwarap two lines in panic() in case when device_tree_flattened is NULL so grep-ing for any part of the message line will always produce a hit. - slightly update the commit message. --- Changes in V3: - Code style fixes - s/SZ_2M/MB(2) - fix condition to check if early_fdt_map() in setup.c return NULL or not. --- Changes in V2: - rework early_fdt_map to use map_pages_to_xen() - move call early_fdt_map() to C code after MMU is enabled. --- 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 1d81e0b64f..6d156c3a40 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -37,6 +38,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