From patchwork Fri Jul 12 16:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13731950 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 07D71C3DA4D for ; Fri, 12 Jul 2024 16:23:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.758169.1167551 (Exim 4.92) (envelope-from ) id 1sSJ36-0000TK-7E; Fri, 12 Jul 2024 16:23:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 758169.1167551; Fri, 12 Jul 2024 16:23:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sSJ36-0000Sd-2v; Fri, 12 Jul 2024 16:23:08 +0000 Received: by outflank-mailman (input) for mailman id 758169; Fri, 12 Jul 2024 16:23:06 +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 1sSJ34-00088h-Cn for xen-devel@lists.xenproject.org; Fri, 12 Jul 2024 16:23:06 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04a90504-406b-11ef-bbfb-fd08da9f4363; Fri, 12 Jul 2024 18:23:05 +0200 (CEST) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a77c4309fc8so324178766b.3 for ; Fri, 12 Jul 2024 09:23:05 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a7ffa13sm358464966b.129.2024.07.12.09.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 09:23:04 -0700 (PDT) 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: 04a90504-406b-11ef-bbfb-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720801385; x=1721406185; 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=Bg0oBapFdQirltpvyBrsFHo+q+G6ZrURZn0a9gYnXDs=; b=MqnMPen49Z3G8uoByQrVlKwd4cozIjdTAIP1Ydar3lqbImjrDVxjPYlDnFmg9QsgtO +5RNjv56erHLXbNe8Ni1TDu+qFtc04YA+Rtn5SQWsMqNftSEUxyh2mh5100AuYibdYDw 873JQmpADqDpuy4IDK5tFekl8Jwlt6nED8WLYAmR1INqCD1ucVAj9oLDuYt2yzWlvb8B Jxazbmmx/XRk4HW/BmTMmiapnunPmEwWLL3ncOMXDInp9g1bAq9d1yFYNrrTslGAVBe3 N/a3lpj5GmtFh09Go+uDVx47/KABgGagW11L71sWhf+h1srGDmiX+ln21WQxKRdRYgta HUIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720801385; x=1721406185; 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=Bg0oBapFdQirltpvyBrsFHo+q+G6ZrURZn0a9gYnXDs=; b=foBAK4Is+zfGpfBEoeOgNKas/P1/CqlIRCB7k4c9OnqnLC89mrCjot86WX6OX1zQaP iKsfU+fP2BHDS6WQSpmZ/+pBuusha8fVL2/ZFCNiwPh3awqLVPsxe2qxMMuzV4N9YKCQ +Ox9c0NmKzS+mb74G7cHAr2fbPSn5ujRqq06h1mMlwNWAVZ4szgbTJZSqvq6AI+9Ix8k utt5WEWaiiasDrevQcIsb0aB3udcBNw3cM2QEPnCqyvx7mdECJYUncR2yiL2qNpmOmfq u6UbFAZucyifnp3iYFUiWojfJzVPS3eq/VYL6iFdRnzXbxx7+WPkfk9915OuF6G9ok0a R8Ew== X-Gm-Message-State: AOJu0YyuKKzVwCZ9cs7lk9/MNwPKZKQK3SUsm+q8fWUMzL7hTY4BDlx4 RIenXMwqvoUG+M3dnmfkAPoYYY6acwUwIFsCOIK40qZz7xBXcqDtl1rCf3hM X-Google-Smtp-Source: AGHT+IE3yEHvZhM9zyREcD1rAhp1stu3IBi5eHZWIAhH+gJluVx9/VRBhJiGToUSVSwUgAK4KZl/Ug== X-Received: by 2002:a17:906:50c:b0:a77:c6c4:2bb7 with SMTP id a640c23a62f3a-a780b68a8c6mr829041066b.1.1720801384926; Fri, 12 Jul 2024 09:23:04 -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 v2 5/8] xen/riscv: introduce asm/pmap.h header Date: Fri, 12 Jul 2024 18:22:54 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Introduces arch_pmap_{un}map functions and select HAS_PMAP for CONFIG_RISCV. Additionaly it was necessary to introduce functions: - mfn_to_xen_entry - mfn_to_pte Signed-off-by: Oleksii Kurochko --- Changes in V2: - newly introduced patch --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/page.h | 2 ++ xen/arch/riscv/include/asm/pmap.h | 28 ++++++++++++++++++++++++++++ xen/arch/riscv/mm.c | 14 ++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 xen/arch/riscv/include/asm/pmap.h diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index 259eea8d3b..0112aa8778 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -3,6 +3,7 @@ config RISCV select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select HAS_DEVICE_TREE + select HAS_PMAP config RISCV_64 def_bool y diff --git a/xen/arch/riscv/include/asm/page.h b/xen/arch/riscv/include/asm/page.h index cbbf3656d1..339074d502 100644 --- a/xen/arch/riscv/include/asm/page.h +++ b/xen/arch/riscv/include/asm/page.h @@ -51,6 +51,8 @@ typedef struct { #endif } pte_t; +pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr); + static inline pte_t paddr_to_pte(paddr_t paddr, unsigned int permissions) { diff --git a/xen/arch/riscv/include/asm/pmap.h b/xen/arch/riscv/include/asm/pmap.h new file mode 100644 index 0000000000..eb4c48515c --- /dev/null +++ b/xen/arch/riscv/include/asm/pmap.h @@ -0,0 +1,28 @@ +#ifndef __ASM_PMAP_H__ +#define __ASM_PMAP_H__ + +#include +#include + +#include + +static inline void arch_pmap_map(unsigned int slot, mfn_t mfn) +{ + pte_t *entry = &xen_fixmap[slot]; + pte_t pte; + + ASSERT(!pte_is_valid(*entry)); + + pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW); + pte.pte |= PTE_LEAF_DEFAULT; + write_pte(entry, pte); +} + +static inline void arch_pmap_unmap(unsigned int slot) +{ + pte_t pte = {}; + + write_pte(&xen_fixmap[slot], pte); +} + +#endif /* __ASM_PMAP_H__ */ diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c index d69a174b5d..445319af08 100644 --- a/xen/arch/riscv/mm.c +++ b/xen/arch/riscv/mm.c @@ -370,3 +370,17 @@ int map_pages_to_xen(unsigned long virt, BUG_ON("unimplemented"); return -1; } + +static inline pte_t mfn_to_pte(mfn_t mfn) +{ + unsigned long pte = mfn_x(mfn) << PTE_PPN_SHIFT; + return (pte_t){ .pte = pte}; +} + +inline pte_t mfn_to_xen_entry(mfn_t mfn, unsigned int attr) +{ + /* there is no attr field in RISC-V's pte */ + (void) attr; + + return mfn_to_pte(mfn); +}