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>
23 ArmPlatformGetGlobalVariable (
24 IN UINTN VariableOffset
,
25 IN UINTN VariableSize
,
29 UINTN GlobalVariableBase
;
31 // Ensure the Global Variable Size have been initialized
32 ASSERT (VariableOffset
< PcdGet32 (PcdSecGlobalVariableSize
));
34 GlobalVariableBase
= PcdGet32 (PcdCPUCoresSecStackBase
) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize
) - PcdGet32 (PcdSecGlobalVariableSize
);
36 if (VariableSize
== 4) {
37 *(UINT32
*)Variable
= ReadUnaligned32 ((CONST UINT32
*)(GlobalVariableBase
+ VariableOffset
));
38 } else if (VariableSize
== 8) {
39 *(UINT64
*)Variable
= ReadUnaligned64 ((CONST UINT64
*)(GlobalVariableBase
+ VariableOffset
));
41 CopyMem (Variable
, (VOID
*)(GlobalVariableBase
+ VariableOffset
), VariableSize
);
46 ArmPlatformSetGlobalVariable (
47 IN UINTN VariableOffset
,
48 IN UINTN VariableSize
,
52 UINTN GlobalVariableBase
;
54 // Ensure the Global Variable Size have been initialized
55 ASSERT (VariableOffset
< PcdGet32 (PcdSecGlobalVariableSize
));
57 GlobalVariableBase
= PcdGet32 (PcdCPUCoresSecStackBase
) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize
) - PcdGet32 (PcdSecGlobalVariableSize
);
59 if (VariableSize
== 4) {
60 WriteUnaligned32 ((UINT32
*)(GlobalVariableBase
+ VariableOffset
), *(UINT32
*)Variable
);
61 } else if (VariableSize
== 8) {
62 WriteUnaligned64 ((UINT64
*)(GlobalVariableBase
+ VariableOffset
), *(UINT64
*)Variable
);
64 CopyMem ((VOID
*)(GlobalVariableBase
+ VariableOffset
), Variable
, VariableSize
);
69 ArmPlatformGetGlobalVariableAddress (
70 IN UINTN VariableOffset
73 UINTN GlobalVariableBase
;
75 // Ensure the Global Variable Size have been initialized
76 ASSERT (VariableOffset
< PcdGet32 (PcdSecGlobalVariableSize
));
78 GlobalVariableBase
= PcdGet32 (PcdCPUCoresSecStackBase
) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize
) - PcdGet32 (PcdSecGlobalVariableSize
);
80 return (VOID
*)(GlobalVariableBase
+ VariableOffset
);