TianoCore EDK2 master
Loading...
Searching...
No Matches
CreatePageTable.c
Go to the documentation of this file.
1
9#include <Base.h>
11#include <Library/DebugLib.h>
12#include <Library/BaseLib.h>
13
22 IN UINTN Address,
23 IN UINTN Length
24 )
25{
26 EFI_STATUS Status;
27 VOID *PageTableBuffer;
28 UINTN PageTableBufferSize;
29 UINTN PageTable;
30 PAGING_MODE PagingMode;
31 IA32_CR4 Cr4;
32
33 IA32_MAP_ATTRIBUTE MapAttribute;
34 IA32_MAP_ATTRIBUTE MapMask;
35
36 MapAttribute.Uint64 = Address;
37 MapAttribute.Bits.Present = 1;
38 MapAttribute.Bits.ReadWrite = 1;
39 MapMask.Uint64 = MAX_UINT64;
40
41 PageTable = 0;
42 PageTableBufferSize = 0;
43
44 Cr4.UintN = AsmReadCr4 ();
45
46 if (Cr4.Bits.LA57 == 1) {
47 PagingMode = Paging5Level;
48 } else {
49 PagingMode = Paging4Level;
50 }
51
52 Status = PageTableMap (
53 &PageTable,
54 PagingMode,
55 NULL,
56 &PageTableBufferSize,
57 Address,
58 Length,
59 &MapAttribute,
60 &MapMask,
61 NULL
62 );
63 ASSERT (Status == EFI_BUFFER_TOO_SMALL);
64 DEBUG ((DEBUG_INFO, "AP Page Table Buffer Size = %x\n", PageTableBufferSize));
65
66 PageTableBuffer = AllocateReservedPages (EFI_SIZE_TO_PAGES (PageTableBufferSize));
67 ASSERT (PageTableBuffer != NULL);
68 Status = PageTableMap (
69 &PageTable,
70 PagingMode,
71 PageTableBuffer,
72 &PageTableBufferSize,
73 Address,
74 Length,
75 &MapAttribute,
76 &MapMask,
77 NULL
78 );
79 ASSERT_EFI_ERROR (Status);
80 return PageTable;
81}
UINT64 UINTN
RETURN_STATUS EFIAPI PageTableMap(IN OUT UINTN *PageTable OPTIONAL, IN PAGING_MODE PagingMode, IN VOID *Buffer, IN OUT UINTN *BufferSize, IN UINT64 LinearAddress, IN UINT64 Length, IN IA32_MAP_ATTRIBUTE *Attribute, IN IA32_MAP_ATTRIBUTE *Mask, OUT BOOLEAN *IsModified OPTIONAL)
VOID *EFIAPI AllocateReservedPages(IN UINTN Pages)
UINTN CreatePageTable(IN UINTN Address, IN UINTN Length)
UINTN EFIAPI AsmReadCr4(VOID)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200