TianoCore EDK2 master
Loading...
Searching...
No Matches
PageTbl.c File Reference
#include "PiSmmCpuCommon.h"

Go to the source code of this file.

Macros

#define PAGE_TABLE_PAGES   8
 
#define ACC_MAX_BIT   BIT3
 

Functions

BOOLEAN Is1GPageSupport (VOID)
 
BOOLEAN Is5LevelPagingNeeded (VOID)
 
VOID SetSubEntriesNum (IN OUT UINT64 *Entry, IN UINT64 SubEntryNum)
 
UINT64 GetSubEntriesNum (IN UINT64 *Entry)
 
UINT8 CalculateMaximumSupportAddress (BOOLEAN Is5LevelPagingNeeded)
 
UINT32 SmmInitPageTable (VOID)
 
VOID SetAccNum (IN OUT UINT64 *Entry, IN UINT64 Acc)
 
UINT64 GetAccNum (IN UINT64 *Entry)
 
UINT64 GetAndUpdateAccNum (IN OUT UINT64 *Entry)
 
VOID ReclaimPages (VOID)
 
UINT64 AllocPage (VOID)
 
VOID EFIAPI SmiPFHandler (IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
 
VOID SaveCr2 (OUT UINTN *Cr2)
 
VOID RestoreCr2 (IN UINTN Cr2)
 

Variables

LIST_ENTRY mPagePool = INITIALIZE_LIST_HEAD_VARIABLE (mPagePool)
 
BOOLEAN m1GPageTableSupport = FALSE
 
X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPagingNeeded
 

Detailed Description

Page Fault (#PF) handler for X64 processors

Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Incorporated. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file PageTbl.c.

Macro Definition Documentation

◆ ACC_MAX_BIT

#define ACC_MAX_BIT   BIT3

Definition at line 14 of file PageTbl.c.

◆ PAGE_TABLE_PAGES

#define PAGE_TABLE_PAGES   8

Definition at line 13 of file PageTbl.c.

Function Documentation

◆ AllocPage()

UINT64 AllocPage ( VOID  )

Allocate free Page for PageFault handler use.

Returns
Page address.

Definition at line 688 of file PageTbl.c.

◆ CalculateMaximumSupportAddress()

UINT8 CalculateMaximumSupportAddress ( BOOLEAN  Is5LevelPagingNeeded)

Calculate the maximum support address.

Parameters
[in]Is5LevelPagingNeededIf 5-level paging enabling is needed.
Returns
the maximum support address.

Definition at line 144 of file PageTbl.c.

◆ GetAccNum()

UINT64 GetAccNum ( IN UINT64 *  Entry)

Return access record in entry.

Parameters
[in]EntryPointer to entry
Returns
Access record value.

Definition at line 353 of file PageTbl.c.

◆ GetAndUpdateAccNum()

UINT64 GetAndUpdateAccNum ( IN OUT UINT64 *  Entry)

Return and update the access record in entry.

Parameters
[in,out]EntryPointer to entry
Returns
Access record value.

Definition at line 372 of file PageTbl.c.

◆ GetSubEntriesNum()

UINT64 GetSubEntriesNum ( IN UINT64 *  Entry)

Return sub-entries number in entry.

Parameters
[in]EntryPointer to entry
Returns
Sub-entries number based on 0: 0 means there is 1 sub-entry under this entry 0x1ff means there is 512 sub-entries under this entry

Definition at line 126 of file PageTbl.c.

◆ Is1GPageSupport()

BOOLEAN Is1GPageSupport ( VOID  )

Check if 1-GByte pages is supported by processor or not.

Return values
TRUE1-GByte pages is supported.
FALSE1-GByte pages is not supported.

Definition at line 28 of file PageTbl.c.

◆ Is5LevelPagingNeeded()

BOOLEAN Is5LevelPagingNeeded ( VOID  )

The routine returns TRUE when CPU supports it (CPUID[7,0].ECX.BIT[16] is set) and the max physical address bits is bigger than 48. Because 4-level paging can support to address physical address up to 2^48 - 1, there is no need to enable 5-level paging with max physical address bits <= 48.

Return values
TRUE5-level paging enabling is needed.
FALSE5-level paging enabling is not needed.

Definition at line 56 of file PageTbl.c.

◆ ReclaimPages()

VOID ReclaimPages ( VOID  )

Reclaim free pages for PageFault handler.

Search the whole entries tree to find the leaf entry that has the smallest access record value. Insert the page pointed by this leaf entry into the page pool. And check its upper entries if need to be inserted into the page pool or not.

Definition at line 409 of file PageTbl.c.

◆ RestoreCr2()

VOID RestoreCr2 ( IN UINTN  Cr2)

This function restores CR2 register.

Parameters
[in]Cr2Value to write into CR2 register.

Definition at line 884 of file PageTbl.c.

◆ SaveCr2()

VOID SaveCr2 ( OUT UINTN Cr2)

This function reads CR2 register.

Parameters
[out]*Cr2Pointer to variable to hold CR2 register value.

Definition at line 863 of file PageTbl.c.

◆ SetAccNum()

VOID SetAccNum ( IN OUT UINT64 *  Entry,
IN UINT64  Acc 
)

Set access record in entry.

Parameters
[in,out]EntryPointer to entry
[in]AccAccess record value

Definition at line 333 of file PageTbl.c.

◆ SetSubEntriesNum()

VOID SetSubEntriesNum ( IN OUT UINT64 *  Entry,
IN UINT64  SubEntryNum 
)

Set sub-entries number in entry.

Parameters
[in,out]EntryPointer to entry
[in]SubEntryNumSub-entries number based on 0: 0 means there is 1 sub-entry under this entry 0x1ff means there is 512 sub-entries under this entry

Definition at line 105 of file PageTbl.c.

◆ SmiPFHandler()

VOID EFIAPI SmiPFHandler ( IN EFI_EXCEPTION_TYPE  InterruptType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

ThePage Fault handler wrapper for SMM use.

Parameters
InterruptTypeDefines the type of interrupt or exception that occurred on the processor.This parameter is processor architecture specific.
SystemContextA pointer to the processor context when the interrupt occurred on the processor.

Definition at line 723 of file PageTbl.c.

◆ SmmInitPageTable()

UINT32 SmmInitPageTable ( VOID  )

Create PageTable for SMM use.

Returns
The address of PML4 (to set CR3). Zero if any error occurs.

Definition at line 191 of file PageTbl.c.

Variable Documentation

◆ gPatch5LevelPagingNeeded

X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPagingNeeded

Definition at line 18 of file PageTbl.c.

◆ m1GPageTableSupport

BOOLEAN m1GPageTableSupport = FALSE

Definition at line 17 of file PageTbl.c.

◆ mPagePool

LIST_ENTRY mPagePool = INITIALIZE_LIST_HEAD_VARIABLE (mPagePool)

Definition at line 16 of file PageTbl.c.