3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
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
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.
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>
22 extern UINT64 mSystemMemoryEnd
;
24 #define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(mSystemMemoryEnd)) || \
25 ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))
27 // Declared by ArmPlatformPkg/PrePi Module
28 extern UINTN mGlobalVariableBase
;
31 ArmPlatformGetGlobalVariable (
32 IN UINTN VariableOffset
,
33 IN UINTN VariableSize
,
37 UINTN GlobalVariableBase
;
39 // Ensure the Global Variable Size have been initialized
40 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
43 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
44 // The size must be 64bit aligned to allow 64bit variable to be aligned
45 GlobalVariableBase
= mSystemMemoryEnd
+ 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize
), 0x8);
47 GlobalVariableBase
= mGlobalVariableBase
;
50 if (VariableSize
== 4) {
51 *(UINT32
*)Variable
= ReadUnaligned32 ((CONST UINT32
*)(GlobalVariableBase
+ VariableOffset
));
52 } else if (VariableSize
== 8) {
53 *(UINT64
*)Variable
= ReadUnaligned64 ((CONST UINT64
*)(GlobalVariableBase
+ VariableOffset
));
55 CopyMem (Variable
, (VOID
*)(GlobalVariableBase
+ VariableOffset
), VariableSize
);
60 ArmPlatformSetGlobalVariable (
61 IN UINTN VariableOffset
,
62 IN UINTN VariableSize
,
66 UINTN GlobalVariableBase
;
68 // Ensure the Global Variable Size have been initialized
69 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
72 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
73 // The size must be 64bit aligned to allow 64bit variable to be aligned
74 GlobalVariableBase
= mSystemMemoryEnd
+ 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize
), 0x8);
76 GlobalVariableBase
= mGlobalVariableBase
;
79 if (VariableSize
== 4) {
80 WriteUnaligned32 ((UINT32
*)(GlobalVariableBase
+ VariableOffset
), *(UINT32
*)Variable
);
81 } else if (VariableSize
== 8) {
82 WriteUnaligned64 ((UINT64
*)(GlobalVariableBase
+ VariableOffset
), *(UINT64
*)Variable
);
84 CopyMem ((VOID
*)(GlobalVariableBase
+ VariableOffset
), Variable
, VariableSize
);
89 ArmPlatformGetGlobalVariableAddress (
90 IN UINTN VariableOffset
93 UINTN GlobalVariableBase
;
95 // Ensure the Global Variable Size have been initialized
96 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
99 // In Case of XIP, we expect the Primary Stack at the top of the System Memory
100 // The size must be 64bit aligned to allow 64bit variable to be aligned
101 GlobalVariableBase
= mSystemMemoryEnd
+ 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize
), 0x8);
103 GlobalVariableBase
= mGlobalVariableBase
;
106 return (VOID
*)(GlobalVariableBase
+ VariableOffset
);