]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/ArmPlatformGlobalVariableLib/Sec/SecArmPlatformGlobalVariableLib.c
ArmPlatformPkg/ArmPlatformGlobalVariableLib: Added new function ArmPlatformGetGlobalV...
[mirror_edk2.git] / ArmPlatformPkg / Library / ArmPlatformGlobalVariableLib / Sec / SecArmPlatformGlobalVariableLib.c
CommitLineData
8fc38a3f 1/** @file
2*
782d45d1 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
8fc38a3f 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>
782d45d1 20#include <Library/DebugLib.h>
8fc38a3f 21
22VOID
23ArmPlatformGetGlobalVariable (
24 IN UINTN VariableOffset,
25 IN UINTN VariableSize,
26 OUT VOID* Variable
27 )
28{
29 UINTN GlobalVariableBase;
30
782d45d1 31 // Ensure the Global Variable Size have been initialized
32 ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
33
8fc38a3f 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) {
f15f91a2 39 *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));
8fc38a3f 40 } else {
41 CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);
42 }
8fc38a3f 43}
44
45VOID
46ArmPlatformSetGlobalVariable (
47 IN UINTN VariableOffset,
48 IN UINTN VariableSize,
49 OUT VOID* Variable
50 )
51{
52 UINTN GlobalVariableBase;
53
782d45d1 54 // Ensure the Global Variable Size have been initialized
55 ASSERT (VariableOffset < PcdGet32 (PcdSecGlobalVariableSize));
56
8fc38a3f 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 }
8fc38a3f 66}
67
d9efd68e 68VOID*
69ArmPlatformGetGlobalVariableAddress (
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}