mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-03 22:17:03 +00:00
1. move HPA2HVA/HVA2HPA to page.h 2. add pgtable_types.h to define MACRO for page table types 3. add pgtable.h to set/get page table 4. add pagetable.c to refine walk page table attributes modify Signed-off-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
97 lines
2.0 KiB
C
97 lines
2.0 KiB
C
/*
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef PGTABLE_H
|
|
#define PGTABLE_H
|
|
|
|
#include <pgtable_types.h>
|
|
|
|
/* hpa <--> hva, now it is 1:1 mapping */
|
|
#define HPA2HVA(x) ((void *)(x))
|
|
#define HVA2HPA(x) ((uint64_t)(x))
|
|
|
|
static inline uint64_t pml4e_index(uint64_t address)
|
|
{
|
|
return (address >> PML4E_SHIFT) & (PTRS_PER_PML4E - 1UL);
|
|
}
|
|
|
|
static inline uint64_t pdpte_index(uint64_t address)
|
|
{
|
|
return (address >> PDPTE_SHIFT) & (PTRS_PER_PDPTE - 1UL);
|
|
}
|
|
|
|
static inline uint64_t pde_index(uint64_t address)
|
|
{
|
|
return (address >> PDE_SHIFT) & (PTRS_PER_PDE - 1UL);
|
|
}
|
|
|
|
static inline uint64_t pte_index(uint64_t address)
|
|
{
|
|
return (address >> PTE_SHIFT) & (PTRS_PER_PTE - 1UL);
|
|
}
|
|
|
|
static inline uint64_t *pml4e_page_vaddr(uint64_t pml4e)
|
|
{
|
|
return HPA2HVA(pml4e & PML4E_PFN_MASK);
|
|
}
|
|
|
|
static inline uint64_t *pdpte_page_vaddr(uint64_t pdpte)
|
|
{
|
|
return HPA2HVA(pdpte & PDPTE_PFN_MASK);
|
|
}
|
|
|
|
static inline uint64_t *pde_page_vaddr(uint64_t pde)
|
|
{
|
|
return HPA2HVA(pde & PDE_PFN_MASK);
|
|
}
|
|
|
|
static inline uint64_t *pml4e_offset(uint64_t *pml4_page, uint64_t addr)
|
|
{
|
|
return pml4_page + pml4e_index(addr);
|
|
}
|
|
|
|
static inline uint64_t *pdpte_offset(uint64_t *pml4e, uint64_t addr)
|
|
{
|
|
return pml4e_page_vaddr(*pml4e) + pdpte_index(addr);
|
|
}
|
|
|
|
static inline uint64_t *pde_offset(uint64_t *pdpte, uint64_t addr)
|
|
{
|
|
return pdpte_page_vaddr(*pdpte) + pde_index(addr);
|
|
}
|
|
|
|
static inline uint64_t *pte_offset(uint64_t *pde, uint64_t addr)
|
|
{
|
|
return pde_page_vaddr(*pde) + pte_index(addr);
|
|
}
|
|
|
|
static inline uint64_t get_pte(uint64_t *pte)
|
|
{
|
|
return *pte;
|
|
}
|
|
|
|
static inline void set_pte(uint64_t *ptep, uint64_t pte)
|
|
{
|
|
*ptep = pte;
|
|
}
|
|
|
|
static inline uint64_t pde_large(uint64_t pde)
|
|
{
|
|
return pde & PAGE_PSE;
|
|
}
|
|
|
|
static inline uint64_t pdpte_large(uint64_t pdpte)
|
|
{
|
|
return pdpte & PAGE_PSE;
|
|
}
|
|
|
|
static inline uint64_t pgentry_present(enum _page_table_type ptt, uint64_t pte)
|
|
{
|
|
return (ptt == PTT_HOST) ? (pte & PAGE_PRESENT) : (pte & EPT_RWX);
|
|
}
|
|
|
|
#endif /* PGTABLE_H */
|