]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Pei/PeiArmPlatformGlobalVariableLib.c
f82b6b1c5d6477e511bf1f0761503500a51e26f8
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / Pei / PeiArmPlatformGlobalVariableLib.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 // Declared by ArmPlatformPkg/PrePi Module
23 extern UINTN mGlobalVariableBase;
24
25 VOID
26 ArmPlatformGetGlobalVariable (
27 IN UINTN VariableOffset,
28 IN UINTN VariableSize,
29 OUT VOID* Variable
30 )
31 {
32 UINTN GlobalVariableBase;
33
34 // Ensure the Global Variable Size have been initialized
35 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
36
37 GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize) + VariableOffset;
38
39 if (VariableSize == 4) {
40 *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));
41 } else if (VariableSize == 8) {
42 *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
43 } else {
44 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
45 }
46
47 //DEBUG((EFI_D_ERROR,"++ GET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable));
48 }
49
50 VOID
51 ArmPlatformSetGlobalVariable (
52 IN UINTN VariableOffset,
53 IN UINTN VariableSize,
54 OUT VOID* Variable
55 )
56 {
57 UINTN GlobalVariableBase;
58
59 // Ensure the Global Variable Size have been initialized
60 ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));
61
62 GlobalVariableBase = PcdGet32 (PcdCPUCoresStackBase) + PcdGet32 (PcdCPUCorePrimaryStackSize) - PcdGet32 (PcdPeiGlobalVariableSize) + VariableOffset;
63
64 if (VariableSize == 4) {
65 WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);
66 } else if (VariableSize == 8) {
67 WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);
68 } else {
69 CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);
70 }
71
72 //DEBUG((EFI_D_ERROR,"++ SET Offset[%d] = 0x%x\n",VariableOffset,*(UINTN*)Variable));
73 }
74