]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
ArmPlatformPkg/ArmPlatformGlobalVariableLib: Added new function ArmPlatformGetGlobalV...
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / PrePi / PrePiArmPlatformGlobalVariableLib.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
99565b88 22#define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
8fc38a3f 23 ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
24
25// Declared by ArmPlatformPkg/PrePi Module
26extern UINTN mGlobalVariableBase;
27
28VOID
29ArmPlatformGetGlobalVariable (
30 IN UINTN VariableOffset,
31 IN UINTN VariableSize,
32 OUT VOID* Variable
33 )
34{
35 UINTN GlobalVariableBase;
36
782d45d1 37 // Ensure the Global Variable Size have been initialized
38 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
39
8fc38a3f 40 if (IS_XIP()) {
41 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
99565b88 42 // The size must be 64bit aligned to allow 64bit variable to be aligned
43 GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
8fc38a3f 44 } else {
45 GlobalVariableBase = mGlobalVariableBase;
46 }
47
48 if (VariableSize == 4) {
49 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
50 } else if (VariableSize == 8) {
f15f91a2 51 *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
8fc38a3f 52 } else {
53 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
54 }
55}
56
57VOID
58ArmPlatformSetGlobalVariable (
59 IN UINTN VariableOffset,
60 IN UINTN VariableSize,
61 OUT VOID* Variable
62 )
63{
64 UINTN GlobalVariableBase;
65
782d45d1 66 // Ensure the Global Variable Size have been initialized
67 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
68
8fc38a3f 69 if (IS_XIP()) {
70 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
99565b88 71 // The size must be 64bit aligned to allow 64bit variable to be aligned
72 GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
8fc38a3f 73 } else {
74 GlobalVariableBase = mGlobalVariableBase;
75 }
76
77 if (VariableSize == 4) {
78 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
79 } else if (VariableSize == 8) {
80 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
81 } else {
82 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
83 }
84}
85
d9efd68e 86VOID*
87ArmPlatformGetGlobalVariableAddress (
88 IN UINTN VariableOffset
89 )
90{
91 UINTN GlobalVariableBase;
92
93 // Ensure the Global Variable Size have been initialized
94 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
95
96 if (IS_XIP()) {
97 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
98 // The size must be 64bit aligned to allow 64bit variable to be aligned
99 GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
100 } else {
101 GlobalVariableBase = mGlobalVariableBase;
102 }
103
104 return (VOID*)(GlobalVariableBase + VariableOffset);
105}