]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/CpuDxe/Mmu.c
Added a library for the default exception handler and started to add a dissasembler...
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / Mmu.c
index a0977dd1107379edc05915b68f51a879a2fe6cbe..e81e58a9b113ec8a3d0c94feb8786619c16d3bf1 100644 (file)
@@ -16,10 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "CpuDxe.h"\r
 \r
-//\r
-// For debug switch me back to to EFI_D_PAGE when done\r
-//\r
-#define L_EFI_D_PAGE EFI_D_ERROR\r
 \r
 //\r
 // Translation/page table definitions\r
@@ -353,7 +349,7 @@ SyncCacheConfig (
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR     *MemorySpaceMap;\r
 \r
 \r
-  DEBUG ((L_EFI_D_PAGE, "SyncCacheConfig()\n"));\r
+  DEBUG ((EFI_D_PAGE, "SyncCacheConfig()\n"));\r
 \r
   // This code assumes MMU is enabled and filed with section translations\r
   ASSERT (ArmMmuEnabled ());\r
@@ -442,38 +438,41 @@ UpdatePageEntries (
   volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
   volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
 \r
+  Status = EFI_SUCCESS;\r
+\r
   // EntryMask: bitmask of values to change (1 = change this value, 0 = leave alone)\r
   // EntryValue: values at bit positions specified by EntryMask\r
-\r
+  EntryMask = ARM_PAGE_DESC_TYPE_MASK;\r
+  EntryValue = ARM_PAGE_TYPE_SMALL;\r
   // Although the PI spec is unclear on this the GCD guarantees that only\r
   // one Attribute bit is set at a time, so we can safely use a switch statement\r
   switch (Attributes) {\r
     case EFI_MEMORY_UC:\r
       // modify cacheability attributes\r
-      EntryMask = ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
+      EntryMask |= ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
       // map to strongly ordered\r
-      EntryValue = 0; // TEX[2:0] = 0, C=0, B=0\r
+      EntryValue |= 0; // TEX[2:0] = 0, C=0, B=0\r
       break;\r
 \r
     case EFI_MEMORY_WC:\r
       // modify cacheability attributes\r
-      EntryMask = ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
+      EntryMask |= ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
       // map to normal non-cachable\r
-      EntryValue = (0x1 << ARM_SMALL_PAGE_TEX_SHIFT); // TEX [2:0]= 001 = 0x2, B=0, C=0\r
+      EntryValue |= (0x1 << ARM_SMALL_PAGE_TEX_SHIFT); // TEX [2:0]= 001 = 0x2, B=0, C=0\r
       break;\r
 \r
     case EFI_MEMORY_WT:\r
       // modify cacheability attributes\r
-      EntryMask = ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
+      EntryMask |= ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
       // write through with no-allocate\r
-      EntryValue = ARM_PAGE_C; // TEX [2:0] = 0, C=1, B=0\r
+      EntryValue |= ARM_PAGE_C; // TEX [2:0] = 0, C=1, B=0\r
       break;\r
 \r
     case EFI_MEMORY_WB:\r
       // modify cacheability attributes\r
-      EntryMask = ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
+      EntryMask |= ARM_SMALL_PAGE_TEX_MASK | ARM_PAGE_C | ARM_PAGE_B;\r
       // write back (with allocate)\r
-      EntryValue = (0x1 << ARM_SMALL_PAGE_TEX_SHIFT) | ARM_PAGE_C | ARM_PAGE_B; // TEX [2:0] = 001, C=1, B=1\r
+      EntryValue |= (0x1 << ARM_SMALL_PAGE_TEX_SHIFT) | ARM_PAGE_C | ARM_PAGE_B; // TEX [2:0] = 001, C=1, B=1\r
       break;\r
 \r
     case EFI_MEMORY_WP:\r
@@ -481,9 +480,8 @@ UpdatePageEntries (
     case EFI_MEMORY_UCE:\r
       // cannot be implemented UEFI definition unclear for ARM\r
       // Cause a page fault if these ranges are accessed.\r
-      EntryMask   = 0x3;\r
-      EntryValue = 0;\r
-      DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(): setting page %lx with unsupported attribute %x will page fault on access\n", BaseAddress, Attributes));\r
+      EntryValue = ARM_PAGE_TYPE_FAULT;\r
+      DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): setting page %lx with unsupported attribute %x will page fault on access\n", BaseAddress, Attributes));\r
       break;\r
 \r
     default:\r
@@ -617,7 +615,7 @@ UpdateSectionEntries (
       // cannot be implemented UEFI definition unclear for ARM\r
       // Cause a page fault if these ranges are accessed.\r
       EntryValue = ARM_DESC_TYPE_FAULT;\r
-      DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(): setting section %lx with unsupported attribute %x will page fault on access\n", BaseAddress, Attributes));\r
+      DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): setting section %lx with unsupported attribute %x will page fault on access\n", BaseAddress, Attributes));\r
       break;\r
 \r
 \r
@@ -680,7 +678,7 @@ ConvertSectionToPages (
   volatile ARM_FIRST_LEVEL_DESCRIPTOR   *FirstLevelTable;\r
   volatile ARM_PAGE_TABLE_ENTRY         *PageTable;\r
 \r
-  DEBUG ((L_EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));\r
+  DEBUG ((EFI_D_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));\r
 \r
   // obtain page table base\r
   FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTranslationTableBaseAddress ();\r
@@ -727,10 +725,6 @@ ConvertSectionToPages (
   }\r
 \r
   // flush d-cache so descriptors make it back to uncached memory for subsequent table walks\r
-  // TODO: change to use only PageTable base and length\r
-  // ArmInvalidateDataCache ();\r
-DEBUG ((EFI_D_ERROR, "InvalidateDataCacheRange (%x, %x)\n", (UINTN)PageTableAddr, EFI_PAGE_SIZE));\r
-\r
   InvalidateDataCacheRange ((VOID *)(UINTN)PageTableAddr, EFI_PAGE_SIZE);\r
 \r
   // formulate page table entry, Domain=0, NS=0\r
@@ -756,11 +750,11 @@ SetMemoryAttributes (
   \r
   if(((BaseAddress & 0xFFFFF) == 0) && ((Length & 0xFFFFF) == 0)) {\r
     // is the base and length a multiple of 1 MB?\r
-    DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(): MMU section 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
+    DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU section 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
     Status = UpdateSectionEntries (BaseAddress, Length, Attributes, VirtualMask);\r
   } else {\r
     // base and/or length is not a multiple of 1 MB\r
-    DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(): MMU page 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
+    DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU page 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
     Status = UpdatePageEntries (BaseAddress, Length, Attributes, VirtualMask);\r
   }\r
 \r
@@ -807,10 +801,10 @@ CpuSetMemoryAttributes (
   IN UINT64                    Attributes\r
   )\r
 {\r
-  DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(%lx, %lx, %lx)\n", BaseAddress, Length, Attributes));\r
+  DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(%lx, %lx, %lx)\n", BaseAddress, Length, Attributes));\r
   if ( ((BaseAddress & (EFI_PAGE_SIZE-1)) != 0) || ((Length & (EFI_PAGE_SIZE-1)) != 0)){\r
     // minimum granularity is EFI_PAGE_SIZE (4KB on ARM)\r
-    DEBUG ((L_EFI_D_PAGE, "SetMemoryAttributes(%lx, %lx, %lx): minimum ganularity is EFI_PAGE_SIZE\n", BaseAddress, Length, Attributes));\r
+    DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(%lx, %lx, %lx): minimum ganularity is EFI_PAGE_SIZE\n", BaseAddress, Length, Attributes));\r
     return EFI_UNSUPPORTED;\r
   }\r
   \r
@@ -843,7 +837,7 @@ CpuConvertPagesToUncachedVirtualAddress (
       *Attributes = GcdDescriptor.Attributes;\r
     }\r
   }\r
-ASSERT (FALSE);  \r
+\r
   //\r
   // Make this address range page fault if accessed. If it is a DMA buffer than this would \r
   // be the PCI address. Code should always use the CPU address, and we will or in VirtualMask\r
@@ -854,13 +848,15 @@ ASSERT (FALSE);
     Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_UC, VirtualMask);\r
   }\r
 \r
+  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "ConvertPagesToUncachedVirtualAddress()\n    Unmapped 0x%08lx Mapped 0x%08lx 0x%x bytes\n", Address, Address | VirtualMask, Length));\r
+\r
   return Status;\r
 }\r
 \r
 \r
 EFI_STATUS\r
 EFIAPI\r
-CpuReconvertPagesPages (\r
+CpuReconvertPages (\r
   IN  VIRTUAL_UNCACHED_PAGES_PROTOCOL   *This,\r
   IN  EFI_PHYSICAL_ADDRESS              Address,\r
   IN  UINTN                             Length,\r
@@ -869,6 +865,8 @@ CpuReconvertPagesPages (
   )\r
 {\r
   EFI_STATUS      Status;\r
+\r
+  DEBUG ((DEBUG_INFO | DEBUG_LOAD, "CpuReconvertPages(%lx, %x, %lx, %lx)\n", Address, Length, VirtualMask, Attributes));\r
   \r
   //\r
   // Unmap the alaised Address\r
@@ -887,7 +885,7 @@ CpuReconvertPagesPages (
 \r
 VIRTUAL_UNCACHED_PAGES_PROTOCOL  gVirtualUncachedPages = {\r
   CpuConvertPagesToUncachedVirtualAddress,\r
-  CpuReconvertPagesPages\r
+  CpuReconvertPages\r
 };\r
 \r
 \r