]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
ArmPlatformPkg/ArmPlatformGlobalVariableLib: Added new function ArmPlatformGetGlobalV...
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / Sec / SecArmPlatformGlobalVariableLib.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 VOID
23 ArmPlatformGetGlobalVariable (
24 IN UINTN VariableOffset,
25 IN UINTN VariableSize,
26 OUT VOID* Variable
27 )
28 {
29 UINTN GlobalVariableBase;
30
31 // Ensure the Global Variable Size have been initialized
32 ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
33
34 GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize) + VariableOffset;
35
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));
40 } else {
41 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
42 }
43 }
44
45 VOID
46 ArmPlatformSetGlobalVariable (
47 IN UINTN VariableOffset,
48 IN UINTN VariableSize,
49 OUT VOID* Variable
50 )
51 {
52 UINTN GlobalVariableBase;
53
54 // Ensure the Global Variable Size have been initialized
55 ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
56
57 GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize) + VariableOffset;
58
59 if (VariableSize == 4) {
60 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
61 } else if (VariableSize == 8) {
62 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
63 } else {
64 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
65 }
66 }
67
68 VOID*
69 ArmPlatformGetGlobalVariableAddress (
70 IN UINTN VariableOffset
71 )
72 {
73 UINTN GlobalVariableBase;
74
75 // Ensure the Global Variable Size have been initialized
76 ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
77
78 GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize);
79
80 return (VOID*)(GlobalVariableBase + VariableOffset);
81 }