]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c
ArmPlatformPkg/ArmPlatformGlobalVariableLib: Fixed calculation of GlobalVariableBase
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / Pei / PeiArmPlatformGlobalVariableLib.c
CommitLineData
8fc38a3f 1/** @file
2*
782d45d1 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
8fc38a3f 4*
5* This program and the accompanying materials
6* are licensed and made available under the terms and conditions of the BSD License
7* which accompanies this distribution. The full text of the license may be found at
8* http://opensource.org/licenses/bsd-license.php
9*
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12*
13**/
14
15#include <Uefi.h>
16#include <Library/ArmPlatformGlobalVariableLib.h>
17#include <Library/BaseLib.h>
18#include <Library/BaseMemoryLib.h>
19#include <Library/PcdLib.h>
782d45d1 20#include <Library/DebugLib.h>
8fc38a3f 21
22// Declared by ArmPlatformPkg/PrePi Module
23extern UINTN mGlobalVariableBase;
24
25VOID
26ArmPlatformGetGlobalVariable (
27 IN UINTN VariableOffset,
28 IN UINTN VariableSize,
29 OUT VOID* Variable
30 )
31{
32 UINTN GlobalVariableBase;
33
782d45d1 34 // Ensure the Global Variable Size have been initialized
35 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
36
f463bb00 37 GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
8fc38a3f 38
39 if (VariableSize == 4) {
40 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
41 } else if (VariableSize == 8) {
f15f91a2 42 *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
8fc38a3f 43 } else {
44 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
45 }
8fc38a3f 46}
47
48VOID
49ArmPlatformSetGlobalVariable (
50 IN UINTN VariableOffset,
51 IN UINTN VariableSize,
52 OUT VOID* Variable
53 )
54{
55 UINTN GlobalVariableBase;
56
782d45d1 57 // Ensure the Global Variable Size have been initialized
58 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
59
f463bb00 60 GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
8fc38a3f 61
62 if (VariableSize == 4) {
63 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
64 } else if (VariableSize == 8) {
65 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
66 } else {
67 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
68 }
8fc38a3f 69}
70
d9efd68e 71VOID*
72ArmPlatformGetGlobalVariableAddress (
73 IN UINTN VariableOffset
74 )
75{
76 UINTN GlobalVariableBase;
77
78 // Ensure the Global Variable Size have been initialized
79 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
80
81 GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize);
82
83 return (VOID*)(GlobalVariableBase + VariableOffset);
84}