]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
ArmPlatform/PrePi: Fixed PrePi for MP Cores platform and Global Variable region settings
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / PrePi / PrePiArmPlatformGlobalVariableLib.c
CommitLineData
8fc38a3f 1/** @file
2*
3* Copyright (c) 2011, ARM Limited. All rights reserved.
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>
20
99565b88 21#define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
8fc38a3f 22 ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
23
24// Declared by ArmPlatformPkg/PrePi Module
25extern UINTN mGlobalVariableBase;
26
27VOID
28ArmPlatformGetGlobalVariable (
29 IN UINTN VariableOffset,
30 IN UINTN VariableSize,
31 OUT VOID* Variable
32 )
33{
34 UINTN GlobalVariableBase;
35
36 if (IS_XIP()) {
37 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
99565b88 38 // The size must be 64bit aligned to allow 64bit variable to be aligned
39 GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
8fc38a3f 40 } else {
41 GlobalVariableBase = mGlobalVariableBase;
42 }
43
44 if (VariableSize == 4) {
45 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
46 } else if (VariableSize == 8) {
47 *(UINT32*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
48 } else {
49 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
50 }
51}
52
53VOID
54ArmPlatformSetGlobalVariable (
55 IN UINTN VariableOffset,
56 IN UINTN VariableSize,
57 OUT VOID* Variable
58 )
59{
60 UINTN GlobalVariableBase;
61
62 if (IS_XIP()) {
63 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
99565b88 64 // The size must be 64bit aligned to allow 64bit variable to be aligned
65 GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
8fc38a3f 66 } else {
67 GlobalVariableBase = mGlobalVariableBase;
68 }
69
70 if (VariableSize == 4) {
71 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
72 } else if (VariableSize == 8) {
73 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
74 } else {
75 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
76 }
77}
78