30#define DEFAULT_BIT_WIDTH_PER_LEVEL (EFI_PAGE_SHIFT - 3)
43 IN OUT UINT64 *PageWalkCfg OPTIONAL,
47 CPUCFG_REG1_INFO_DATA CpucfgReg1Data;
48 UINT8 CpuVirtMemAddressWidth;
49 UINT8 PageTableLevelNum;
50 UINT8 CurrentPageTableLevel;
58 BitWidth = DEFAULT_BIT_WIDTH_PER_LEVEL;
64 AsmCpucfg (CPUCFG_REG1_INFO, &CpucfgReg1Data.Uint32);
66 CpuVirtMemAddressWidth = (UINT8)(CpucfgReg1Data.Bits.VALEN + 1);
71 PageTableLevelNum = 0x0;
72 if (((CpuVirtMemAddressWidth - EFI_PAGE_SHIFT) % BitWidth) > 0) {
76 PageTableLevelNum += (CpuVirtMemAddressWidth - EFI_PAGE_SHIFT) / BitWidth;
83 for (CurrentPageTableLevel = 0x0; CurrentPageTableLevel < PageTableLevelNum; CurrentPageTableLevel++) {
84 if (CurrentPageTableLevel < 0x3) {
86 Pwcl0Value |= ((BitWidth * CurrentPageTableLevel + EFI_PAGE_SHIFT) << 10 * CurrentPageTableLevel) |
87 BitWidth << (10 * CurrentPageTableLevel + 5);
90 Pwcl1Value |= ((BitWidth * CurrentPageTableLevel + EFI_PAGE_SHIFT) << 12 * (CurrentPageTableLevel - 3)) |
91 BitWidth << (12 * (CurrentPageTableLevel - 3) + 6);
96 "%a %d Level %d DIR shift %d.\n",
99 (CurrentPageTableLevel + 1),
100 (BitWidth * CurrentPageTableLevel + EFI_PAGE_SHIFT)
104 *PageWalkCfg = ((UINT64)Pwcl1Value << 32) | Pwcl0Value;
106 return PageTableLevelNum;
130 if (MemoryTable ==
NULL) {
131 ASSERT (MemoryTable !=
NULL);
132 return EFI_INVALID_PARAMETER;
140 if ((MaxLevel < 0) || (MaxLevel > 5)) {
141 return EFI_UNSUPPORTED;
151 while (MemoryTable->NumberOfPages != 0) {
154 "%a %d VirtualBase %p VirtualEnd %p Attributes %p .\n",
157 MemoryTable->VirtualStart,
159 MemoryTable->Attribute
165 MemoryTable->VirtualStart,
167 MemoryTable->Attribute,
171 if (EFI_ERROR (Status)) {
172 return EFI_UNSUPPORTED;
181 CsrWrite (LOONGARCH_CSR_PWCTL0, (UINT32)PageWalkCfg);
182 if ((PageWalkCfg >> 32) != 0x0) {
183 CsrWrite (LOONGARCH_CSR_PWCTL1, (UINT32)(PageWalkCfg >> 32));
189 CsrXChg (LOONGARCH_CSR_TLBIDX, (DEFAULT_PAGE_SIZE << CSR_TLBIDX_SIZE), CSR_TLBIDX_SIZE_MASK);
190 CsrWrite (LOONGARCH_CSR_STLBPGSIZE, DEFAULT_PAGE_SIZE);
191 CsrXChg (LOONGARCH_CSR_TLBREHI, (DEFAULT_PAGE_SIZE << CSR_TLBREHI_PS_SHIFT), CSR_TLBREHI_PS);
196 CsrWrite (LOONGARCH_CSR_PGDL, PageTable);
201 CsrXChg (LOONGARCH_CSR_CRMD, BIT4, BIT4|BIT3);
203 DEBUG ((DEBUG_INFO,
"%a %d Enable MMU Start PageBassAddress %p.\n", __func__, __LINE__, PageTable));
STATIC UINT8 DecidePageWalkConfiguration(IN OUT UINT64 *PageWalkCfg OPTIONAL, IN UINT8 BitWidth)
EFI_STATUS EFIAPI ConfigureMemoryManagementUnit(IN EFI_MEMORY_DESCRIPTOR *MemoryTable)
EFI_STATUS EFIAPI MemoryRegionMap(IN OUT UINTN *PageTable OPTIONAL, IN UINT64 PageWalkCfg, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN UINT64 AttributeMask)
UINTN EFIAPI CsrXChg(IN UINT16 Select, IN OUT UINTN Value, IN UINTN Mask)
UINTN EFIAPI CsrWrite(IN UINT16 Select, IN OUT UINTN Value)
#define DEBUG(Expression)
#define EFI_PAGES_TO_SIZE(Pages)