]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | /** @file\r |
2 | *\r | |
5dbacdb2 | 3 | * Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r |
1e57a462 | 4 | *\r |
5 | * This program and the accompanying materials\r | |
6 | * are licensed and made available under the terms and conditions of the BSD License\r | |
7 | * which accompanies this distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include <Uefi.h>\r | |
16 | #include <Library/ArmPlatformGlobalVariableLib.h>\r | |
17 | #include <Library/BaseLib.h>\r | |
18 | #include <Library/BaseMemoryLib.h>\r | |
19 | #include <Library/PcdLib.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | \r | |
5dbacdb2 OM |
22 | extern UINT64 mSystemMemoryEnd;\r |
23 | \r | |
24 | #define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(mSystemMemoryEnd)) || \\r | |
bb5420bb | 25 | ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))\r |
1e57a462 | 26 | \r |
27 | // Declared by ArmPlatformPkg/PrePi Module\r | |
28 | extern UINTN mGlobalVariableBase;\r | |
29 | \r | |
30 | VOID\r | |
31 | ArmPlatformGetGlobalVariable (\r | |
32 | IN UINTN VariableOffset,\r | |
33 | IN UINTN VariableSize,\r | |
34 | OUT VOID* Variable\r | |
35 | )\r | |
36 | {\r | |
37 | UINTN GlobalVariableBase;\r | |
38 | \r | |
39 | // Ensure the Global Variable Size have been initialized\r | |
40 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
41 | \r | |
42 | if (IS_XIP()) {\r | |
43 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
44 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
5dbacdb2 | 45 | GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);\r |
1e57a462 | 46 | } else {\r |
47 | GlobalVariableBase = mGlobalVariableBase;\r | |
48 | }\r | |
49 | \r | |
50 | if (VariableSize == 4) {\r | |
51 | *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));\r | |
52 | } else if (VariableSize == 8) {\r | |
53 | *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));\r | |
54 | } else {\r | |
55 | CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);\r | |
56 | }\r | |
57 | }\r | |
58 | \r | |
59 | VOID\r | |
60 | ArmPlatformSetGlobalVariable (\r | |
61 | IN UINTN VariableOffset,\r | |
62 | IN UINTN VariableSize,\r | |
63 | OUT VOID* Variable\r | |
64 | )\r | |
65 | {\r | |
66 | UINTN GlobalVariableBase;\r | |
67 | \r | |
68 | // Ensure the Global Variable Size have been initialized\r | |
69 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
70 | \r | |
71 | if (IS_XIP()) {\r | |
72 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
73 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
5dbacdb2 | 74 | GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);\r |
1e57a462 | 75 | } else {\r |
76 | GlobalVariableBase = mGlobalVariableBase;\r | |
77 | }\r | |
78 | \r | |
79 | if (VariableSize == 4) {\r | |
80 | WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);\r | |
81 | } else if (VariableSize == 8) {\r | |
82 | WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);\r | |
83 | } else {\r | |
84 | CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);\r | |
85 | }\r | |
86 | }\r | |
87 | \r | |
88 | VOID*\r | |
89 | ArmPlatformGetGlobalVariableAddress (\r | |
90 | IN UINTN VariableOffset\r | |
91 | )\r | |
92 | {\r | |
93 | UINTN GlobalVariableBase;\r | |
94 | \r | |
95 | // Ensure the Global Variable Size have been initialized\r | |
96 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
97 | \r | |
98 | if (IS_XIP()) {\r | |
99 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
100 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
5dbacdb2 | 101 | GlobalVariableBase = mSystemMemoryEnd + 1 - ALIGN_VALUE (PcdGet32 (PcdPeiGlobalVariableSize), 0x8);\r |
1e57a462 | 102 | } else {\r |
103 | GlobalVariableBase = mGlobalVariableBase;\r | |
104 | }\r | |
105 | \r | |
106 | return (VOID*)(GlobalVariableBase + VariableOffset);\r | |
107 | }\r |