summaryrefslogtreecommitdiffstats
path: root/ArmVirtPkg/PrePi/Arm
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2017-11-17 11:09:44 +0000
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2017-11-23 16:05:03 +0000
commit832709565e76a3f068848964a9c1dac4fa5d21f2 (patch)
tree685643626e5e3da52598f9d656102bec840f0994 /ArmVirtPkg/PrePi/Arm
parent888559acf98ae954af0418c1f72bc603aa9b9e88 (diff)
downloadedk2-832709565e76a3f068848964a9c1dac4fa5d21f2.tar.gz
edk2-832709565e76a3f068848964a9c1dac4fa5d21f2.tar.bz2
edk2-832709565e76a3f068848964a9c1dac4fa5d21f2.zip
ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
ArmVirtQemuKernel and ArmVirtXen use essentially the same code to retrieve DRAM information from the DT /memory node at early boot, and invoke it via the ArmPlatformPeiBootAction () hook exposed by ArmPlatformLib. Let's move this code into the PrePi implementation these platforms share between them (and not with any other platforms) so we can eliminate another dependency on the messy ArmPlatformLib. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'ArmVirtPkg/PrePi/Arm')
-rw-r--r--ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S71
1 files changed, 71 insertions, 0 deletions
diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
index eebf660acd..a918c19143 100644
--- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
+++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S
@@ -148,3 +148,74 @@ _GetStackBase:
_NeverReturn:
b _NeverReturn
+
+ASM_PFX(ArmPlatformPeiBootAction):
+ //
+ // If we are booting from RAM using the Linux kernel boot protocol, r0 will
+ // point to the DTB image in memory. Otherwise, use the default value defined
+ // by the platform.
+ //
+ teq r0, #0
+ bne 0f
+ LDRL (r0, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
+
+0:mov r11, r14 // preserve LR
+ mov r10, r0 // preserve DTB pointer
+ mov r9, r1 // preserve base of image pointer
+
+ //
+ // The base of the runtime image has been preserved in r1. Check whether
+ // the expected magic number can be found in the header.
+ //
+ ldr r8, .LArm32LinuxMagic
+ ldr r7, [r1, #0x24]
+ cmp r7, r8
+ bne .Lout
+
+ //
+ //
+ // OK, so far so good. We have confirmed that we likely have a DTB and are
+ // booting via the ARM Linux boot protocol. Update the base-of-image PCD
+ // to the actual relocated value, and add the shift of PcdFdBaseAddress to
+ // PcdFvBaseAddress as well
+ //
+ ADRL (r8, PcdGet64 (PcdFdBaseAddress))
+ ADRL (r7, PcdGet64 (PcdFvBaseAddress))
+ ldr r6, [r8]
+ ldr r5, [r7]
+ sub r5, r5, r6
+ add r5, r5, r1
+ str r1, [r8]
+ str r5, [r7]
+
+ //
+ // Discover the memory size and offset from the DTB, and record in the
+ // respective PCDs. This will also return false if a corrupt DTB is
+ // encountered. Since we are calling a C function, use the window at the
+ // beginning of the FD image as a temp stack.
+ //
+ ADRL (r1, PcdGet64 (PcdSystemMemoryBase))
+ ADRL (r2, PcdGet64 (PcdSystemMemorySize))
+ mov sp, r5
+ bl FindMemnode
+ teq r0, #0
+ beq .Lout
+
+ //
+ // Copy the DTB to the slack space right after the 64 byte arm64/Linux style
+ // image header at the base of this image (defined in the FDF), and record the
+ // pointer in PcdDeviceTreeInitialBaseAddress.
+ //
+ ADRL (r8, PcdGet64 (PcdDeviceTreeInitialBaseAddress))
+ add r9, r9, #0x40
+ str r9, [r8]
+
+ mov r0, r9
+ mov r1, r10
+ bl CopyFdt
+
+.Lout:
+ bx r11
+
+.LArm32LinuxMagic:
+ .byte 0x18, 0x28, 0x6f, 0x01