This change allows to change the top of the System Memory that was hardcoded by: FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize) It allows to add support when the Trusted Firmware reserves the top of the System Memory as Trusted. The size of this region might not be known in advance. Note: The reason why the start of the System Memory has not been made dynamic is because the early code calculates where to place the stack from the top of the System Memory. So there is no need to make the start of the System Memory a dynamic value at the early stage of the boot phase. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <Olivier.Martin@arm.com> Reviewed-by: Ronald Cron <Ronald.Cron@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17835 6f19259b-4bc3-4df7-8a09-765794883524
108 lines
3.6 KiB
C
108 lines
3.6 KiB
C
/** @file
|
|
*
|
|
* Copyright (c) 2011-2015, ARM Limited. All rights reserved.
|
|
*
|
|
* This program and the accompanying materials
|
|
* are licensed and made available under the terms and conditions of the BSD License
|
|
* which accompanies this distribution. The full text of the license may be found at
|
|
* http://opensource.org/licenses/bsd-license.php
|
|
*
|
|
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
*
|
|
**/
|
|
|
|
#include <Uefi.h>
|
|
#include <Library/ArmPlatformGlobalVariableLib.h>
|
|
#include <Library/BaseLib.h>
|
|
#include <Library/BaseMemoryLib.h>
|
|
#include <Library/PcdLib.h>
|
|
#include <Library/DebugLib.h>
|
|
|
|
extern UINT64 mSystemMemoryEnd;
|
|
|
|
#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(mSystemMemoryEnd)) || \
|
|
((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))
|
|
|
|
// Declared by ArmPlatformPkg/PrePi Module
|
|
extern UINTN mGlobalVariableBase;
|
|
|
|
VOID
|
|
ArmPlatformGetGlobalVariable (
|
|
IN UINTN VariableOffset,
|
|
IN UINTN VariableSize,
|
|
OUT VOID* Variable
|
|
)
|
|
{
|
|
UINTN GlobalVariableBase;
|
|
|
|
// Ensure the Global Variable Size have been initialized
|
|
ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
|
|
|
|
if (IS_XIP()) {
|
|
// In Case of XIP, we expect the Primary Stack at the top of the System Memory
|
|
// The size must be 64bit aligned to allow 64bit variable to be aligned
|
|
GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);
|
|
} else {
|
|
GlobalVariableBase = mGlobalVariableBase;
|
|
}
|
|
|
|
if (VariableSize == 4) {
|
|
*(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
|
|
} else if (VariableSize == 8) {
|
|
*(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
|
|
} else {
|
|
CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
|
|
}
|
|
}
|
|
|
|
VOID
|
|
ArmPlatformSetGlobalVariable (
|
|
IN UINTN VariableOffset,
|
|
IN UINTN VariableSize,
|
|
OUT VOID* Variable
|
|
)
|
|
{
|
|
UINTN GlobalVariableBase;
|
|
|
|
// Ensure the Global Variable Size have been initialized
|
|
ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
|
|
|
|
if (IS_XIP()) {
|
|
// In Case of XIP, we expect the Primary Stack at the top of the System Memory
|
|
// The size must be 64bit aligned to allow 64bit variable to be aligned
|
|
GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);
|
|
} else {
|
|
GlobalVariableBase = mGlobalVariableBase;
|
|
}
|
|
|
|
if (VariableSize == 4) {
|
|
WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
|
|
} else if (VariableSize == 8) {
|
|
WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
|
|
} else {
|
|
CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
|
|
}
|
|
}
|
|
|
|
VOID*
|
|
ArmPlatformGetGlobalVariableAddress (
|
|
IN UINTN VariableOffset
|
|
)
|
|
{
|
|
UINTN GlobalVariableBase;
|
|
|
|
// Ensure the Global Variable Size have been initialized
|
|
ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
|
|
|
|
if (IS_XIP()) {
|
|
// In Case of XIP, we expect the Primary Stack at the top of the System Memory
|
|
// The size must be 64bit aligned to allow 64bit variable to be aligned
|
|
GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);
|
|
} else {
|
|
GlobalVariableBase = mGlobalVariableBase;
|
|
}
|
|
|
|
return (VOID*)(GlobalVariableBase + VariableOffset);
|
|
}
|