]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/PrePi/PrePiArmPlatformGlobalVariableLib.c
b2474e693438ef5f6365a44e0b317a4459fc1062
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / PrePi / PrePiArmPlatformGlobalVariableLib.c
1 /** @file
2 *
3 * Copyright (c) 2011-2012, 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 #include <Library/DebugLib.h>
21
22 #define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
23 ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
24
25 // Declared by ArmPlatformPkg/PrePi Module
26 extern UINTN mGlobalVariableBase;
27
28 VOID
29 ArmPlatformGetGlobalVariable (
30 IN UINTN VariableOffset,
31 IN UINTN VariableSize,
32 OUT VOID* Variable
33 )
34 {
35 UINTN GlobalVariableBase;
36
37 // Ensure the Global Variable Size have been initialized
38 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
39
40 if (IS_XIP()) {
41 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
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);
44 } else {
45 GlobalVariableBase = mGlobalVariableBase;
46 }
47
48 if (VariableSize == 4) {
49 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
50 } else if (VariableSize == 8) {
51 *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
52 } else {
53 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
54 }
55 }
56
57 VOID
58 ArmPlatformSetGlobalVariable (
59 IN UINTN VariableOffset,
60 IN UINTN VariableSize,
61 OUT VOID* Variable
62 )
63 {
64 UINTN GlobalVariableBase;
65
66 // Ensure the Global Variable Size have been initialized
67 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
68
69 if (IS_XIP()) {
70 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
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);
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