From 3b81aa91d31f485f97b1e9b8d401571ab9822be8 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Tue, 19 Jul 2016 13:36:27 +0100 Subject: [PATCH] Introduce more memory management helpers These are still simply, relying on identity mappings and state provided by the domain builder for PV guests. Signed-off-by: Andrew Cooper --- include/arch/x86/mm.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/arch/x86/mm.h b/include/arch/x86/mm.h index dfdab21..d2a65d0 100644 --- a/include/arch/x86/mm.h +++ b/include/arch/x86/mm.h @@ -24,9 +24,15 @@ static inline void *pfn_to_virt(unsigned long pfn) return (void *)(pfn << PAGE_SHIFT); } +static inline unsigned long virt_to_pfn(const void *va) +{ + return ((unsigned long)va) >> PAGE_SHIFT; +} + #if defined(CONFIG_PV) #define m2p ((unsigned long *)MACH2PHYS_VIRT_START) +extern struct start_info *start_info; static inline void *mfn_to_virt(unsigned long mfn) { @@ -38,6 +44,18 @@ static inline void *maddr_to_virt(uint64_t maddr) return mfn_to_virt(maddr >> PAGE_SHIFT) + (maddr & ~PAGE_MASK); } +static inline unsigned long pfn_to_mfn(unsigned long pfn) +{ + unsigned long *p2m = _p(start_info->mfn_list); + + return p2m[pfn]; +} + +static inline unsigned long virt_to_mfn(const void *va) +{ + return pfn_to_mfn(virt_to_pfn(va)); +} + #undef m2p #endif /* CONFIG_PV */ -- 2.39.5