From nobody Thu Sep 19 16:34:33 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=1725296520; cv=none; d=zohomail.com; s=zohoarc; b=QZBewLXszhEUhhFnrdKYfmE4BdA86kgbNgv1kjuA0j18Qj9PO6+8vWs4cmuTriJeQ2vOETPn/g9CHhnR+CuEcTkr0g92hWbZXgC4jsbXE4ge9EzNJLkLpD6ROgj23OfXkaCCHbMUR7ibcOIB9u77n8aKpqsdxDGPHbtGrTN6L8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725296520; 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=U5CqShvy1X+IfLQdEA3UCNoLebQ2CuAj+ldoJL6mxt8=; b=jRfszrylRT8SUGbjEGRjqjmGQGBeMGtG+Ou8diNMYMimaAHwI7+bYW7dj/UHS/dy0pRNYJXBUkJe8XCQrWQUTzVb4+DNdX4d1UE9Fo+vv7mBrPwueytR0/15qHRNstAkZboSuzUpJlmFtPq80o9Ep29GrS5sK4cZx44frncJJ6Y= 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 172529652078321.356487898158548; Mon, 2 Sep 2024 10:02:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.788313.1197873 (Exim 4.92) (envelope-from ) id 1slAQr-0004Va-ED; Mon, 02 Sep 2024 17:01:37 +0000 Received: by outflank-mailman (output) from mailman id 788313.1197873; Mon, 02 Sep 2024 17:01:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1slAQr-0004UW-1x; Mon, 02 Sep 2024 17:01:37 +0000 Received: by outflank-mailman (input) for mailman id 788313; Mon, 02 Sep 2024 17:01:35 +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 1slAQp-0002dz-Of for xen-devel@lists.xenproject.org; Mon, 02 Sep 2024 17:01:35 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 02c19481-694d-11ef-a0b2-8be0dac302b0; Mon, 02 Sep 2024 19:01:35 +0200 (CEST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-53436e04447so4613699e87.1 for ; Mon, 02 Sep 2024 10:01:35 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-535408410f5sm1677618e87.211.2024.09.02.10.01.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 10:01:33 -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: 02c19481-694d-11ef-a0b2-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725296494; x=1725901294; 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=U5CqShvy1X+IfLQdEA3UCNoLebQ2CuAj+ldoJL6mxt8=; b=mU1Suh4jsBYEv5SD3rWCDPb6JGO/F762ZT9vypr0ATLyd65DxF2H+0advML8HCzUBJ cmTAVD9zFHr8KhLitoqe0lVKEDmpARyvTv6ddFNt7dt79r47CcUcvauRxF5VP2G2C+TW vyETS4Q2UrwOGkhgKQrXhvY3t+evj7x3byp2D9Oa1UJwGsZqCGBcUtj2hiWnJEwHhReL 4DVX1dMTYVakxQTrJW5cQCfobWlH78EVqXZHWWqQ8eWKMB5EhlO8LoeRhbDe//S8P+A6 eDQ6YKURD1t3YTvc+AK+8VbBRqZjF77wvaBRoIs5PMBnB1gjRF6mtj/ukUiAgOFmXTVn jufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725296494; x=1725901294; 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=U5CqShvy1X+IfLQdEA3UCNoLebQ2CuAj+ldoJL6mxt8=; b=dVN3yb1grV2x+E6r+4T+bcs9pH+Qjk1hVwibGnAm+y+LTabGU6XVrvCIDINCrjcOZt fIdPispaY4XFy2lEcH3HSltWiTATueoD2v/Xm74yS4z4eTGNgBCfgCwe0GgvTCyDOkX9 y33Lw8VLOIxrOW7mUbQ15ltr+FLNKbeCXFlC5Ewk2y51oOn6XDQ5RkXodgTG854lYiav 0rzL/QdbGWGh0mjxn3cfI2wxmhFSZcdNEOaxVg7QJhpNjiGmhYb2TPIATnx59taWsH31 mI98bLDs9b9yBt57RpRtb+RXoLfcHJfI2/3oYKJjbZQcekgAVmSpZHnI2kap/oYTsiWg AXOw== X-Gm-Message-State: AOJu0YzZS1jDWiq8fGTROP9YxDIE7a8EQYhS4glgSLAIqHG/BKWPnoVZ oEyBzGePxJGt2g/CKRF6fsbbGqpLKYV7eenLC9UsupnTiV4KE9poDKs1KA== X-Google-Smtp-Source: AGHT+IGO4Q+xYcVNPAJ1D6gAcHW5VV+5SFTNWbhSH0Nd3J4SrL+XfdvqK4/FsJWLdYvoAfQXtsbDUg== X-Received: by 2002:a05:6512:3085:b0:530:ad97:78ba with SMTP id 2adb3069b0e04-5353ebb01c6mr5488861e87.9.1725296493640; Mon, 02 Sep 2024 10:01:33 -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 v6 9/9] xen/riscv: introduce early_fdt_map() Date: Mon, 2 Sep 2024 19:01:22 +0200 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1725296522257116600 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: - 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 164b9cfdd1..a671a5442b 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include =20 @@ -56,6 +57,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 for ( ;; ) --=20 2.46.0