From d9efd68ef54883f8142d833212d66870248c0dd7 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Wed, 2 May 2012 19:51:08 +0000 Subject: [PATCH] ArmPlatformPkg/ArmPlatformGlobalVariableLib: Added new function ArmPlatformGetGlobalVariableAddress() This function returns the address of a Global Variable in the Global Variable Region. Signed-off-by: Olivier Martin git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13246 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/ArmPlatformGlobalVariableLib.h | 7 ++++++- .../Dxe/DxeArmPlatformGlobalVariableLib.c | 9 ++++++++- .../Dxe/DxeArmPlatformGlobalVariableLib.inf | 1 + .../Pei/PeiArmPlatformGlobalVariableLib.c | 18 +++++++++++++---- .../PrePi/PrePiArmPlatformGlobalVariableLib.c | 20 +++++++++++++++++++ .../Sec/SecArmPlatformGlobalVariableLib.c | 14 +++++++++++++ 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h b/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h index c0264c24bd..02ef1ea832 100644 --- a/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h +++ b/ArmPlatformPkg/Include/Library/ArmPlatformGlobalVariableLib.h @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2011-2012, 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 @@ -29,5 +29,10 @@ ArmPlatformSetGlobalVariable ( OUT VOID* Variable ); +VOID* +ArmPlatformGetGlobalVariableAddress ( + IN UINTN VariableOffset + ); + #endif diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c index aebc912935..278138759f 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.c @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2011-2012, 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 @@ -67,3 +67,10 @@ ArmPlatformSetGlobalVariable ( CopyMem ((VOID*)(mGlobalVariableBase + VariableOffset), Variable, VariableSize); } +VOID* +ArmPlatformGetGlobalVariableAddress ( + IN UINTN VariableOffset + ) +{ + return (VOID*)(mGlobalVariableBase + VariableOffset); +} diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf index 2b1c7aaf53..f2284ce4ca 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Dxe/DxeArmPlatformGlobalVariableLib.inf @@ -3,6 +3,7 @@ # # # Copyright (c) 2011-2012, ARM Ltd. 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 diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c index f82b6b1c5d..78563acae9 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c @@ -43,8 +43,6 @@ ArmPlatformGetGlobalVariable ( } else { CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize); } - - //DEBUG((EFI_D_ERROR,"++ GET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable)); } VOID @@ -68,7 +66,19 @@ ArmPlatformSetGlobalVariable ( } else { CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize); } - - //DEBUG((EFI_D_ERROR,"++ SET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable)); } +VOID* +ArmPlatformGetGlobalVariableAddress ( + IN UINTN VariableOffset + ) +{ + UINTN GlobalVariableBase; + + // Ensure the Global Variable Size have been initialized + ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize)); + + GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize); + + return (VOID*)(GlobalVariableBase + VariableOffset); +} diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c index b2474e6934..563e405f66 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c @@ -83,3 +83,23 @@ ArmPlatformSetGlobalVariable ( } } +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 = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8); + } else { + GlobalVariableBase = mGlobalVariableBase; + } + + return (VOID*)(GlobalVariableBase + VariableOffset); +} diff --git a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c index 847d2b7e81..f5d7bb54a3 100644 --- a/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c +++ b/ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c @@ -65,3 +65,17 @@ ArmPlatformSetGlobalVariable ( } } +VOID* +ArmPlatformGetGlobalVariableAddress ( + IN UINTN VariableOffset + ) +{ + UINTN GlobalVariableBase; + + // Ensure the Global Variable Size have been initialized + ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize)); + + GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize); + + return (VOID*)(GlobalVariableBase + VariableOffset); +} -- 2.39.2