Files
acrn-hypervisor/hypervisor/include/common/pgtable.h
hangliu1 2ab068400b hv: multiarch: move some function to common
move some funcitons like hpa2hva to common file.
change some files to include file from asm/pgtable.h to common/pgtable.h

Tracked-On: #8831
Signed-off-by: hangliu1 <hang1.liu@intel.com>
Reviewed-by: Fei Li <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-10-21 14:14:55 +08:00

70 lines
1.6 KiB
C

/*
* Copyright (C) 2018-2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef COMMON_PGTABLE_H
#define COMMON_PGTABLE_H
#include <asm/page.h>
/**
* @brief Translate a host physical address to a host virtual address.
*
* This function is used to translate a host physical address to a host virtual address. HPA is 1:1 mapping to HVA.
*
* It returns the host virtual address that corresponds to the given host physical address.
*
* @param[in] hpa The host physical address to be translated.
*
* @return The translated host virtual address
*
* @retval NULL if hpa == 0
*
* @pre N/A
*
* @post N/A
*
* @remark This function is used after paging mode enabled.
*/
static inline void *hpa2hva(uint64_t hpa)
{
return (void *)hpa;
}
/**
* @brief Translate a host virtual address to a host physical address.
*
* This function is used to translate a host virtual address to a host physical address. HVA is 1:1 mapping to HPA.
*
* It returns the host physical address that corresponds to the given host virtual address.
*
* @param[in] va The host virtual address to be translated.
*
* @return The translated host physical address.
*
* @retval 0 if va == NULL
*
* @pre N/A
*
* @post N/A
*
* @remark This function is used after paging mode enabled.
*/
static inline uint64_t hva2hpa(const void *va)
{
return (uint64_t)va;
}
static inline uint64_t round_page_up(uint64_t addr)
{
return (((addr + (uint64_t)PAGE_SIZE) - 1UL) & PAGE_MASK);
}
static inline uint64_t round_page_down(uint64_t addr)
{
return (addr & PAGE_MASK);
}
#endif /* COMMON_PGTABLE_H*/