]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
xen/riscv: introduce asm/pmap.h header
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Mon, 30 Sep 2024 08:09:37 +0000 (10:09 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 30 Sep 2024 08:09:37 +0000 (10:09 +0200)
Introduce arch_pmap_{un}map functions and select HAS_PMAP for CONFIG_RISCV.

Add pte_from_mfn() for use in arch_pmap_map().

Introduce flush_xen_tlb_one_local() and use it in arch_pmap_{un}map().

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/riscv/Kconfig
xen/arch/riscv/include/asm/flushtlb.h
xen/arch/riscv/include/asm/page.h
xen/arch/riscv/include/asm/pmap.h [new file with mode: 0644]

index 7a113c77749c409cc3ccb7b52573546343953ea5..18580046769dee454b37630f662d514e3eea58aa 100644 (file)
@@ -3,6 +3,7 @@ config RISCV
        select FUNCTION_ALIGNMENT_16B
        select GENERIC_BUG_FRAME
        select HAS_DEVICE_TREE
+       select HAS_PMAP
        select HAS_VMAP
 
 config RISCV_64
index 7ce32bea0b97d27b2cb9ba7a9e25f3b7ad7cb51f..f4a735fd6c29cf211ea9f6b6f6d414bb7abf4cd5 100644 (file)
@@ -5,6 +5,12 @@
 #include <xen/bug.h>
 #include <xen/cpumask.h>
 
+/* Flush TLB of local processor for address va. */
+static inline void flush_tlb_one_local(vaddr_t va)
+{
+    asm volatile ( "sfence.vma %0" :: "r" (va) : "memory" );
+}
+
 /*
  * Filter the given set of CPUs, removing those that definitely flushed their
  * TLB since @page_timestamp.
index d4a500982351d70a478920337ec8b0fb0a7e6030..eb79cb94096114744d51942db875faff9adfad3b 100644 (file)
@@ -94,6 +94,12 @@ static inline pte_t read_pte(const pte_t *p)
     return read_atomic(p);
 }
 
+static inline pte_t pte_from_mfn(mfn_t mfn, unsigned int flags)
+{
+    unsigned long pte = (mfn_x(mfn) << PTE_PPN_SHIFT) | flags;
+    return (pte_t){ .pte = pte };
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_RISCV_PAGE_H */
diff --git a/xen/arch/riscv/include/asm/pmap.h b/xen/arch/riscv/include/asm/pmap.h
new file mode 100644 (file)
index 0000000..60065c9
--- /dev/null
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ASM_PMAP_H
+#define ASM_PMAP_H
+
+#include <xen/bug.h>
+#include <xen/init.h>
+#include <xen/mm.h>
+#include <xen/page-size.h>
+
+#include <asm/fixmap.h>
+#include <asm/flushtlb.h>
+#include <asm/system.h>
+
+static inline void __init arch_pmap_map(unsigned int slot, mfn_t mfn)
+{
+    pte_t *entry = &xen_fixmap[slot];
+    pte_t pte;
+
+    ASSERT(!pte_is_valid(*entry));
+
+    pte = pte_from_mfn(mfn, PAGE_HYPERVISOR_RW);
+    write_pte(entry, pte);
+
+    flush_tlb_one_local(FIXMAP_ADDR(slot));
+}
+
+static inline void __init arch_pmap_unmap(unsigned int slot)
+{
+    pte_t pte = {};
+
+    write_pte(&xen_fixmap[slot], pte);
+
+    flush_tlb_one_local(FIXMAP_ADDR(slot));
+}
+
+#endif /* ASM_PMAP_H */