@@ -8,6 +8,7 @@
#include <xen/const.h>
#include <xen/mm-frame.h>
#include <xen/pdx.h>
+#include <xen/pfn.h>
#include <xen/types.h>
#include <asm/page-bits.h>
@@ -148,8 +149,11 @@ static inline void *page_to_virt(const struct page_info *pg)
/* Convert between Xen-heap virtual addresses and page-info structures. */
static inline struct page_info *virt_to_page(const void *v)
{
- BUG_ON("unimplemented");
- return NULL;
+ unsigned long va = (unsigned long)v;
+
+ ASSERT((va >= DIRECTMAP_VIRT_START) && (va <= DIRECTMAP_VIRT_END));
+
+ return frametable_virt_start + PFN_DOWN(va - directmap_virt_start);
}
/*
@@ -7,6 +7,7 @@
#include <xen/bug.h>
#include <xen/const.h>
+#include <xen/domain_page.h>
#include <xen/errno.h>
#include <xen/types.h>
@@ -176,10 +177,17 @@ static inline void invalidate_icache(void)
#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
#define copy_page(dp, sp) memcpy(dp, sp, PAGE_SIZE)
-/* TODO: Flush the dcache for an entire page. */
static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache)
{
- BUG_ON("unimplemented");
+ const void *v = map_domain_page(_mfn(mfn));
+
+ if ( clean_and_invalidate_dcache_va_range(v, PAGE_SIZE) )
+ BUG();
+
+ unmap_domain_page(v);
+
+ if ( sync_icache )
+ invalidate_icache();
}
/* Write a pagetable entry. */
@@ -3,10 +3,14 @@
#ifndef ASM__RISCV__SETUP_H
#define ASM__RISCV__SETUP_H
+#include <xen/types.h>
+
#define max_init_domid (0)
void setup_mm(void);
+void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
+
#endif /* ASM__RISCV__SETUP_H */
/*
@@ -12,6 +12,7 @@
#include <public/version.h>
#include <asm/early_printk.h>
+#include <asm/fixmap.h>
#include <asm/sbi.h>
#include <asm/setup.h>
#include <asm/smp.h>
@@ -26,6 +27,31 @@ void arch_get_xen_caps(xen_capabilities_info_t *info)
unsigned char __initdata cpu0_boot_stack[STACK_SIZE]
__aligned(STACK_SIZE);
+/**
+ * copy_from_paddr - copy data from a physical address
+ * @dst: destination virtual address
+ * @paddr: source physical address
+ * @len: length to copy
+ */
+void __init copy_from_paddr(void *dst, paddr_t paddr, unsigned long len)
+{
+ const void *src = (void *)FIXMAP_ADDR(FIX_MISC);
+
+ while ( len )
+ {
+ unsigned long s = paddr & (PAGE_SIZE - 1);
+ unsigned long l = min(PAGE_SIZE - s, len);
+
+ set_fixmap(FIX_MISC, maddr_to_mfn(paddr), PAGE_HYPERVISOR_RW);
+ memcpy(dst, src + s, l);
+ clear_fixmap(FIX_MISC);
+
+ paddr += l;
+ dst += l;
+ len -= l;
+ }
+}
+
void __init noreturn start_xen(unsigned long bootcpu_id,
paddr_t dtb_addr)
{