]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r | |
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 | |
22 | #define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \\r | |
23 | ((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))\r | |
24 | \r | |
25 | // Declared by ArmPlatformPkg/PrePi Module\r | |
26 | extern UINTN mGlobalVariableBase;\r | |
27 | \r | |
28 | VOID\r | |
29 | ArmPlatformGetGlobalVariable (\r | |
30 | IN UINTN VariableOffset,\r | |
31 | IN UINTN VariableSize,\r | |
32 | OUT VOID* Variable\r | |
33 | )\r | |
34 | {\r | |
35 | UINTN GlobalVariableBase;\r | |
36 | \r | |
37 | // Ensure the Global Variable Size have been initialized\r | |
38 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
39 | \r | |
40 | if (IS_XIP()) {\r | |
41 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
42 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
43 | GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r | |
44 | } else {\r | |
45 | GlobalVariableBase = mGlobalVariableBase;\r | |
46 | }\r | |
47 | \r | |
48 | if (VariableSize == 4) {\r | |
49 | *(UINT32*)Variable = ReadUnaligned32 ((CONST UINT32*)(GlobalVariableBase + VariableOffset));\r | |
50 | } else if (VariableSize == 8) {\r | |
51 | *(UINT64*)Variable = ReadUnaligned64 ((CONST UINT64*)(GlobalVariableBase + VariableOffset));\r | |
52 | } else {\r | |
53 | CopyMem (Variable, (VOID*)(GlobalVariableBase + VariableOffset), VariableSize);\r | |
54 | }\r | |
55 | }\r | |
56 | \r | |
57 | VOID\r | |
58 | ArmPlatformSetGlobalVariable (\r | |
59 | IN UINTN VariableOffset,\r | |
60 | IN UINTN VariableSize,\r | |
61 | OUT VOID* Variable\r | |
62 | )\r | |
63 | {\r | |
64 | UINTN GlobalVariableBase;\r | |
65 | \r | |
66 | // Ensure the Global Variable Size have been initialized\r | |
67 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
68 | \r | |
69 | if (IS_XIP()) {\r | |
70 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
71 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
72 | GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r | |
73 | } else {\r | |
74 | GlobalVariableBase = mGlobalVariableBase;\r | |
75 | }\r | |
76 | \r | |
77 | if (VariableSize == 4) {\r | |
78 | WriteUnaligned32 ((UINT32*)(GlobalVariableBase + VariableOffset), *(UINT32*)Variable);\r | |
79 | } else if (VariableSize == 8) {\r | |
80 | WriteUnaligned64 ((UINT64*)(GlobalVariableBase + VariableOffset), *(UINT64*)Variable);\r | |
81 | } else {\r | |
82 | CopyMem ((VOID*)(GlobalVariableBase + VariableOffset), Variable, VariableSize);\r | |
83 | }\r | |
84 | }\r | |
85 | \r | |
86 | VOID*\r | |
87 | ArmPlatformGetGlobalVariableAddress (\r | |
88 | IN UINTN VariableOffset\r | |
89 | )\r | |
90 | {\r | |
91 | UINTN GlobalVariableBase;\r | |
92 | \r | |
93 | // Ensure the Global Variable Size have been initialized\r | |
94 | ASSERT (VariableOffset < PcdGet32 (PcdPeiGlobalVariableSize));\r | |
95 | \r | |
96 | if (IS_XIP()) {\r | |
97 | // In Case of XIP, we expect the Primary Stack at the top of the System Memory\r | |
98 | // The size must be 64bit aligned to allow 64bit variable to be aligned\r | |
99 | GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);\r | |
100 | } else {\r | |
101 | GlobalVariableBase = mGlobalVariableBase;\r | |
102 | }\r | |
103 | \r | |
104 | return (VOID*)(GlobalVariableBase + VariableOffset);\r | |
105 | }\r |