]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S
ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
[mirror_edk2.git] / ArmVirtPkg / PrePi / AArch64 / ModuleEntryPoint.S
index 7a9c0c3787cc2b4512e48df31c3cbd2a9fff7df2..3296aedfe9aac671cc304e94a3f0aa087c111f5c 100644 (file)
@@ -49,8 +49,7 @@ ASM_FUNC(_ModuleEntryPoint)
   b     .Lreloc_loop\r
 .Lreloc_done:\r
 \r
-  // Do early platform specific actions\r
-  bl    ASM_PFX(ArmPlatformPeiBootAction)\r
+  bl    ASM_PFX(DiscoverDramFromDt)\r
 \r
   // Get ID of this CPU in Multicore system\r
   bl    ASM_PFX(ArmReadMpidr)\r
@@ -140,3 +139,77 @@ _GetStackBase:
 \r
 _NeverReturn:\r
   b _NeverReturn\r
+\r
+// VOID\r
+// DiscoverDramFromDt (\r
+//   VOID   *DeviceTreeBaseAddress,   // passed by loader in x0\r
+//   VOID   *ImageBase                // passed by FDF trampoline in x1\r
+//   );\r
+ASM_PFX(DiscoverDramFromDt):\r
+  //\r
+  // If we are booting from RAM using the Linux kernel boot protocol, x0 will\r
+  // point to the DTB image in memory. Otherwise, use the default value defined\r
+  // by the platform.\r
+  //\r
+  cbnz  x0, 0f\r
+  ldr   x0, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+\r
+0:mov   x29, x30            // preserve LR\r
+  mov   x28, x0             // preserve DTB pointer\r
+  mov   x27, x1             // preserve base of image pointer\r
+\r
+  //\r
+  // The base of the runtime image has been preserved in x1. Check whether\r
+  // the expected magic number can be found in the header.\r
+  //\r
+  ldr   w8, .LArm64LinuxMagic\r
+  ldr   w9, [x1, #0x38]\r
+  cmp   w8, w9\r
+  bne   .Lout\r
+\r
+  //\r
+  //\r
+  // OK, so far so good. We have confirmed that we likely have a DTB and are\r
+  // booting via the arm64 Linux boot protocol. Update the base-of-image PCD\r
+  // to the actual relocated value, and add the shift of PcdFdBaseAddress to\r
+  // PcdFvBaseAddress as well\r
+  //\r
+  adr   x8, PcdGet64 (PcdFdBaseAddress)\r
+  adr   x9, PcdGet64 (PcdFvBaseAddress)\r
+  ldr   x6, [x8]\r
+  ldr   x7, [x9]\r
+  sub   x7, x7, x6\r
+  add   x7, x7, x1\r
+  str   x1, [x8]\r
+  str   x7, [x9]\r
+\r
+  //\r
+  // Discover the memory size and offset from the DTB, and record in the\r
+  // respective PCDs. This will also return false if a corrupt DTB is\r
+  // encountered. Since we are calling a C function, use the window at the\r
+  // beginning of the FD image as a temp stack.\r
+  //\r
+  adr   x1, PcdGet64 (PcdSystemMemoryBase)\r
+  adr   x2, PcdGet64 (PcdSystemMemorySize)\r
+  mov   sp, x7\r
+  bl    FindMemnode\r
+  cbz   x0, .Lout\r
+\r
+  //\r
+  // Copy the DTB to the slack space right after the 64 byte arm64/Linux style\r
+  // image header at the base of this image (defined in the FDF), and record the\r
+  // pointer in PcdDeviceTreeInitialBaseAddress.\r
+  //\r
+  adr   x8, PcdGet64 (PcdDeviceTreeInitialBaseAddress)\r
+  add   x27, x27, #0x40\r
+  str   x27, [x8]\r
+\r
+  mov   x0, x27\r
+  mov   x1, x28\r
+  bl    CopyFdt\r
+\r
+.Lout:\r
+  ret    x29\r
+\r
+.LArm64LinuxMagic:\r
+  .byte   0x41, 0x52, 0x4d, 0x64\r