]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
ArmPlatformPkg: Introduce ArmPlatformGlobalVariableLib
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / Sec / SecArmPlatformGlobalVariableLib.c
1 /** @file
2 *
3 * Copyright (c) 2011, 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
21 //TODO: RemoveMe
22 //#include <Library/DebugLib.h>
23
24 VOID
25 ArmPlatformGetGlobalVariable (
26 IN UINTN VariableOffset,
27 IN UINTN VariableSize,
28 OUT VOID* Variable
29 )
30 {
31 UINTN GlobalVariableBase;
32
33 GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize) + VariableOffset;
34
35 if (VariableSize == 4) {
36 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
37 } else if (VariableSize == 8) {
38 *(UINT32*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
39 } else {
40 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
41 }
42
43 //DEBUG((EFI_D_ERROR,"++ GET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable));
44 }
45
46 VOID
47 ArmPlatformSetGlobalVariable (
48 IN UINTN VariableOffset,
49 IN UINTN VariableSize,
50 OUT VOID* Variable
51 )
52 {
53 UINTN GlobalVariableBase;
54
55 GlobalVariableBase = PcdGet32 (PcdCPUCoresSecStackBase) + PcdGet32 (PcdCPUCoreSecPrimaryStackSize) - PcdGet32 (PcdSecGlobalVariableSize) + VariableOffset;
56
57 if (VariableSize == 4) {
58 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
59 } else if (VariableSize == 8) {
60 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
61 } else {
62 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
63 }
64
65 //DEBUG((EFI_D_ERROR,"++ SET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable));
66 }
67