3 * Copyright (c) 2011-2012, 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 #define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \
23 ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))
25 // Declared by ArmPlatformPkg/PrePi Module
26 extern UINTN mGlobalVariableBase
;
29 ArmPlatformGetGlobalVariable (
30 IN UINTN VariableOffset
,
31 IN UINTN VariableSize
,
35 UINTN GlobalVariableBase
;
37 // Ensure the Global Variable Size have been initialized
38 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
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
= PcdGet64 (PcdSystemMemoryBase
) + PcdGet64 (PcdSystemMemorySize
) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize
),0x8);
45 GlobalVariableBase
= mGlobalVariableBase
;
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
));
53 CopyMem (Variable
, (VOID
*)(GlobalVariableBase
+ VariableOffset
), VariableSize
);
58 ArmPlatformSetGlobalVariable (
59 IN UINTN VariableOffset
,
60 IN UINTN VariableSize
,
64 UINTN GlobalVariableBase
;
66 // Ensure the Global Variable Size have been initialized
67 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
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
= PcdGet64 (PcdSystemMemoryBase
) + PcdGet64 (PcdSystemMemorySize
) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize
),0x8);
74 GlobalVariableBase
= mGlobalVariableBase
;
77 if (VariableSize
== 4) {
78 WriteUnaligned32 ((UINT32
*)(GlobalVariableBase
+ VariableOffset
), *(UINT32
*)Variable
);
79 } else if (VariableSize
== 8) {
80 WriteUnaligned64 ((UINT64
*)(GlobalVariableBase
+ VariableOffset
), *(UINT64
*)Variable
);
82 CopyMem ((VOID
*)(GlobalVariableBase
+ VariableOffset
), Variable
, VariableSize
);
87 ArmPlatformGetGlobalVariableAddress (
88 IN UINTN VariableOffset
91 UINTN GlobalVariableBase
;
93 // Ensure the Global Variable Size have been initialized
94 ASSERT (VariableOffset
< PcdGet32 (PcdPeiGlobalVariableSize
));
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
= PcdGet64 (PcdSystemMemoryBase
) + PcdGet64 (PcdSystemMemorySize
) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize
),0x8);
101 GlobalVariableBase
= mGlobalVariableBase
;
104 return (VOID
*)(GlobalVariableBase
+ VariableOffset
);