Files
acrn-hypervisor/hypervisor/include/arch/x86/asm/pgtable.h
hangliu1 5cc6694eab hv: multiarch: move page table entry function
this patch moves function xx_offset and xx_index to common code,
Add arch interface arch_quirk/arch_pgtle_page_vaddr and
arch_pgtle_large.

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

205 lines
4.3 KiB
C

/*
* Copyright (C) 2018-2024 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef PGTABLE_H
#define PGTABLE_H
#include <asm/page.h>
/**
* @addtogroup hwmgmt_page
*
* @{
*/
/**
* @file
* @brief All APIs to support page table management
*
* This file defines macros, structures, declarations and functions related for managing page tables.
*
*/
#define PAGE_PRESENT (1UL << 0U)
#define PAGE_RW (1UL << 1U)
#define PAGE_USER (1UL << 2U)
#define PAGE_PWT (1UL << 3U)
#define PAGE_PCD (1UL << 4U)
#define PAGE_ACCESSED (1UL << 5U)
#define PAGE_DIRTY (1UL << 6U)
#define PAGE_PSE (1UL << 7U)
#define PAGE_GLOBAL (1UL << 8U)
#define PAGE_PAT_LARGE (1UL << 12U)
#define PAGE_NX (1UL << 63U)
#define PAGE_CACHE_MASK (PAGE_PCD | PAGE_PWT)
#define PAGE_CACHE_WB 0UL
#define PAGE_CACHE_WT PAGE_PWT
#define PAGE_CACHE_UC_MINUS PAGE_PCD
#define PAGE_CACHE_UC (PAGE_PCD | PAGE_PWT)
#define PAGE_ATTR_USER (PAGE_PRESENT | PAGE_RW | PAGE_USER | PAGE_NX)
/**
* @defgroup ept_mem_access_right EPT Memory Access Right
*
* This is a group that includes EPT Memory Access Right Definitions.
*
* @{
*/
/**
* @brief EPT memory access right is read-only.
*/
#define EPT_RD (1UL << 0U)
/**
* @brief EPT memory access right is read/write.
*/
#define EPT_WR (1UL << 1U)
/**
* @brief EPT memory access right is executable.
*/
#define EPT_EXE (1UL << 2U)
/**
* @brief EPT memory access right is read/write and executable.
*/
#define EPT_RWX (EPT_RD | EPT_WR | EPT_EXE)
/**
* @}
*/
/* End of ept_mem_access_right */
/**
* @defgroup ept_mem_type EPT Memory Type
*
* This is a group that includes EPT Memory Type Definitions.
*
* @{
*/
/**
* @brief EPT memory type is specified in bits 5:3 of the EPT paging-structure entry.
*/
#define EPT_MT_SHIFT 3U
/**
* @brief EPT memory type is uncacheable.
*/
#define EPT_UNCACHED (0UL << EPT_MT_SHIFT)
/**
* @brief EPT memory type is write combining.
*/
#define EPT_WC (1UL << EPT_MT_SHIFT)
/**
* @brief EPT memory type is write through.
*/
#define EPT_WT (4UL << EPT_MT_SHIFT)
/**
* @brief EPT memory type is write protected.
*/
#define EPT_WP (5UL << EPT_MT_SHIFT)
/**
* @brief EPT memory type is write back.
*/
#define EPT_WB (6UL << EPT_MT_SHIFT)
/**
* @brief Ignore PAT memory type.
*/
#define EPT_IGNORE_PAT (1UL << 6U)
/**
* @}
*/
/* End of ept_mem_type */
#define EPT_MT_MASK (7UL << EPT_MT_SHIFT)
#define EPT_VE (1UL << 63U)
/* EPT leaf entry bits (bit 52 - bit 63) should be maksed when calculate PFN */
#define EPT_PFN_HIGH_MASK 0xFFF0000000000000UL
#define PML4E_SHIFT 39U
#define PTRS_PER_PML4E 512UL
#define PDPTE_SHIFT 30U
#define PTRS_PER_PDPTE 512UL
#define PDE_SHIFT 21U
#define PTRS_PER_PDE 512UL
#define PTE_SHIFT 12U
#define PTRS_PER_PTE 512UL
#define PFN_MASK 0x0000FFFFFFFFF000UL
#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;
}
void *pgtable_create_trusty_root(const struct pgtable *table,
void *nworld_pml4_page, uint64_t prot_table_present, uint64_t prot_clr);
#endif /* PGTABLE_H */
/**
* @}
*/