diff --git a/hypervisor/arch/riscv/pgtable.c b/hypervisor/arch/riscv/pgtable.c index 8a76f41a7..0e75267ff 100644 --- a/hypervisor/arch/riscv/pgtable.c +++ b/hypervisor/arch/riscv/pgtable.c @@ -17,3 +17,15 @@ uint64_t arch_pgtl_page_paddr(uint64_t pgtle) uint64_t base = (pgtle & PTE_PFN_MASK) >> PAGE_BASE_OFFSET; return ((base << PTE_SHIFT) & PAGE_PFN_MASK); } + +void *arch_hpa2hva_early(uint64_t x) +{ + /* ASSUMPTION: MMU is in bare mode or using identical mapping */ + return (void *)x; +} + +uint64_t arch_hva2hpa_early(void *x) +{ + /* ASSUMPTION: MMU is in bare mode or using identical mapping */ + return (uint64_t)x; +} diff --git a/hypervisor/arch/x86/pgtable.c b/hypervisor/arch/x86/pgtable.c index fc593b2c2..6e502e9d2 100644 --- a/hypervisor/arch/x86/pgtable.c +++ b/hypervisor/arch/x86/pgtable.c @@ -30,3 +30,13 @@ uint64_t arch_pgtl_large(uint64_t pgtle) { return pgtle & PAGE_PSE; } + +void *arch_hpa2hva_early(uint64_t x) +{ + return (void *)x; +} + +uint64_t arch_hva2hpa_early(void *x) +{ + return (uint64_t)x; +} diff --git a/hypervisor/boot/multiboot/multiboot.c b/hypervisor/boot/multiboot/multiboot.c index bcb004e29..dcd4cb158 100644 --- a/hypervisor/boot/multiboot/multiboot.c +++ b/hypervisor/boot/multiboot/multiboot.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include "multiboot_priv.h" diff --git a/hypervisor/boot/multiboot/multiboot2.c b/hypervisor/boot/multiboot/multiboot2.c index cb6ea83e7..3aa5b082b 100644 --- a/hypervisor/boot/multiboot/multiboot2.c +++ b/hypervisor/boot/multiboot/multiboot2.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "multiboot_priv.h" /** diff --git a/hypervisor/include/arch/riscv/asm/pgtable.h b/hypervisor/include/arch/riscv/asm/pgtable.h index a8120d7fa..3493578f8 100644 --- a/hypervisor/include/arch/riscv/asm/pgtable.h +++ b/hypervisor/include/arch/riscv/asm/pgtable.h @@ -8,21 +8,6 @@ #include -/* FIXME: Temporary RISC-V build workaround - * This file provides hva2hpa[_early] and hpa2hva[_early] function stubs to - * satisfy existing code dependencies. Remove this file and migrate to the - * common pgtable.h implementation once the MMU module is properly integrated. - */ -static inline void *hpa2hva_early(uint64_t x) -{ - return (void *)x; -} - -static inline uint64_t hva2hpa_early(void *x) -{ - return (uint64_t)x; -} - #define SATP_MODE_SV48 0x9000000000000000UL #define SATP_PPN_MASK 0x00000FFFFFFFFFFFUL diff --git a/hypervisor/include/arch/x86/asm/pgtable.h b/hypervisor/include/arch/x86/asm/pgtable.h index 272296a2a..6c5210cb2 100644 --- a/hypervisor/include/arch/x86/asm/pgtable.h +++ b/hypervisor/include/arch/x86/asm/pgtable.h @@ -144,55 +144,7 @@ #define EPT_ENTRY_PFN_MASK ((~EPT_PFN_HIGH_MASK) & PAGE_MASK) -/** - * @brief Translate a host physical address to a host virtual address before paging mode enabled. - * - * This function is used to translate a host physical address to a host virtual address before paging mode enabled. HPA - * is 1:1 mapping to HVA. - * - * It returns the host virtual address that corresponds to the given host physical address. - * - * @param[in] x The host physical address - * - * @return The translated host virtual address - * - * @retval NULL if x == 0 - * - * @pre N/A - * - * @post N/A - * - * @remark This function is used before paging mode enabled. - */ -static inline void *hpa2hva_early(uint64_t x) -{ - return (void *)x; -} - -/** - * @brief Translate a host virtual address to a host physical address before paging mode enabled. - * - * This function is used to translate a host virtual address to a host physical address before paging mode enabled. HVA - * is 1:1 mapping to HPA. - * - * It returns the host physical address that corresponds to the given host virtual address. - * - * @param[in] x The host virtual address to be translated - * - * @return The translated host physical address - * - * @retval 0 if x == NULL - * - * @pre N/A - * - * @post N/A - * - * @remark This function is used before paging mode enabled. - */ -static inline uint64_t hva2hpa_early(void *x) -{ - return (uint64_t)x; -} +#define HAS_EARLY_MAP #endif /* PGTABLE_H */ diff --git a/hypervisor/include/common/pgtable.h b/hypervisor/include/common/pgtable.h index 5be500118..05c48d4ed 100644 --- a/hypervisor/include/common/pgtable.h +++ b/hypervisor/include/common/pgtable.h @@ -12,6 +12,8 @@ uint64_t arch_pgtl_page_paddr(uint64_t pgtle); uint64_t arch_pgtl_large(uint64_t pgtle); +void *arch_hpa2hva_early(uint64_t x); +uint64_t arch_hva2hpa_early(void *x); /** * @brief Translate a host physical address to a host virtual address. @@ -221,4 +223,54 @@ static inline uint64_t paddr2pfn(uint64_t paddr) return ((paddr >> PAGE_SHIFT) << PAGE_PFN_OFFSET); } +/** + * @brief Translate a host physical address to a host virtual address before paging mode enabled. + * + * This function is used to translate a host physical address to a host virtual address before paging mode enabled. + * To get HVA by calling arch_hpa2hva_early. + * + * It returns the host virtual address that corresponds to the given host physical address. + * + * @param[in] x The host physical address + * + * @return The translated host virtual address + * + * @retval NULL if x == 0 + * + * @pre N/A + * + * @post N/A + * + * @remark This function is used before paging mode enabled. + */ +static inline void *hpa2hva_early(uint64_t x) +{ + return arch_hpa2hva_early(x); +} + +/** + * @brief Translate a host virtual address to a host physical address before paging mode enabled. + * + * This function is used to translate a host virtual address to a host physical address before paging mode enabled. HVA + * To get HPA by calling arch_hva2hpa_early. + * + * It returns the host physical address that corresponds to the given host virtual address. + * + * @param[in] x The host virtual address to be translated + * + * @return The translated host physical address + * + * @retval 0 if x == NULL + * + * @pre N/A + * + * @post N/A + * + * @remark This function is used before paging mode enabled. + */ +static inline uint64_t hva2hpa_early(void *x) +{ + return arch_hva2hpa_early(x); +} + #endif /* COMMON_PGTABLE_H*/