]>
Commit | Line | Data |
---|---|---|
eec7d420 | 1 | /**@file\r |
2 | Xen Platform PEI support\r | |
3 | \r | |
b621bb0a | 4 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
eec7d420 | 5 | Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r |
6 | \r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | //\r | |
18 | // The package level header files this module uses\r | |
19 | //\r | |
20 | #include <PiPei.h>\r | |
21 | \r | |
22 | //\r | |
23 | // The Library classes this module consumes\r | |
24 | //\r | |
25 | #include <Library/DebugLib.h>\r | |
26 | #include <Library/HobLib.h>\r | |
27 | #include <Library/MemoryAllocationLib.h>\r | |
28 | #include <Library/PcdLib.h>\r | |
29 | #include <Guid/XenInfo.h>\r | |
30 | \r | |
31 | #include "Platform.h"\r | |
bb6a9a93 | 32 | #include "Xen.h"\r |
eec7d420 | 33 | \r |
b621bb0a JJ |
34 | BOOLEAN mXen = FALSE;\r |
35 | \r | |
b98b4941 JJ |
36 | STATIC UINT32 mXenLeaf = 0;\r |
37 | \r | |
eec7d420 | 38 | EFI_XEN_INFO mXenInfo;\r |
39 | \r | |
bb6a9a93 WL |
40 | /**\r |
41 | Returns E820 map provided by Xen\r | |
42 | \r | |
43 | @param Entries Pointer to E820 map\r | |
44 | @param Count Number of entries\r | |
45 | \r | |
46 | @return EFI_STATUS\r | |
47 | **/\r | |
48 | EFI_STATUS\r | |
49 | XenGetE820Map (\r | |
50 | EFI_E820_ENTRY64 **Entries,\r | |
51 | UINT32 *Count\r | |
52 | )\r | |
53 | {\r | |
54 | EFI_XEN_OVMF_INFO *Info =\r | |
55 | (EFI_XEN_OVMF_INFO *)(UINTN) OVMF_INFO_PHYSICAL_ADDRESS;\r | |
56 | \r | |
57 | if (AsciiStrCmp ((CHAR8 *) Info->Signature, "XenHVMOVMF")) {\r | |
58 | return EFI_NOT_FOUND;\r | |
59 | }\r | |
60 | \r | |
61 | ASSERT (Info->E820 < MAX_ADDRESS);\r | |
62 | *Entries = (EFI_E820_ENTRY64 *)(UINTN) Info->E820;\r | |
63 | *Count = Info->E820EntriesCount;\r | |
64 | \r | |
65 | return EFI_SUCCESS;\r | |
66 | }\r | |
eec7d420 | 67 | \r |
68 | /**\r | |
69 | Connects to the Hypervisor.\r | |
70 | \r | |
71 | @param XenLeaf CPUID index used to connect.\r | |
72 | \r | |
73 | @return EFI_STATUS\r | |
74 | \r | |
75 | **/\r | |
76 | EFI_STATUS\r | |
77 | XenConnect (\r | |
78 | UINT32 XenLeaf\r | |
79 | )\r | |
80 | {\r | |
81 | UINT32 Index;\r | |
82 | UINT32 TransferReg;\r | |
83 | UINT32 TransferPages;\r | |
84 | UINT32 XenVersion;\r | |
85 | \r | |
86 | AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL);\r | |
87 | mXenInfo.HyperPages = AllocatePages (TransferPages);\r | |
88 | if (!mXenInfo.HyperPages) {\r | |
89 | return EFI_OUT_OF_RESOURCES;\r | |
90 | }\r | |
91 | \r | |
92 | for (Index = 0; Index < TransferPages; Index++) {\r | |
93 | AsmWriteMsr64 (TransferReg,\r | |
94 | (UINTN) mXenInfo.HyperPages +\r | |
95 | (Index << EFI_PAGE_SHIFT) + Index);\r | |
96 | }\r | |
97 | \r | |
98 | AsmCpuid (XenLeaf + 1, &XenVersion, NULL, NULL, NULL);\r | |
99 | DEBUG ((EFI_D_ERROR, "Detected Xen version %d.%d\n",\r | |
100 | XenVersion >> 16, XenVersion & 0xFFFF));\r | |
670a64e7 | 101 | mXenInfo.VersionMajor = (UINT16)(XenVersion >> 16);\r |
102 | mXenInfo.VersionMinor = (UINT16)(XenVersion & 0xFFFF);\r | |
eec7d420 | 103 | \r |
104 | /* TBD: Locate hvm_info and reserve it away. */\r | |
105 | mXenInfo.HvmInfo = NULL;\r | |
106 | \r | |
107 | BuildGuidDataHob (\r | |
108 | &gEfiXenInfoGuid,\r | |
109 | &mXenInfo,\r | |
110 | sizeof(mXenInfo)\r | |
111 | );\r | |
112 | \r | |
113 | return EFI_SUCCESS;\r | |
114 | }\r | |
115 | \r | |
116 | /**\r | |
117 | Figures out if we are running inside Xen HVM.\r | |
118 | \r | |
b98b4941 JJ |
119 | @retval TRUE Xen was detected\r |
120 | @retval FALSE Xen was not detected\r | |
eec7d420 | 121 | \r |
122 | **/\r | |
b98b4941 | 123 | BOOLEAN\r |
eec7d420 | 124 | XenDetect (\r |
125 | VOID\r | |
126 | )\r | |
127 | {\r | |
eec7d420 | 128 | UINT8 Signature[13];\r |
129 | \r | |
b98b4941 JJ |
130 | if (mXenLeaf != 0) {\r |
131 | return TRUE;\r | |
132 | }\r | |
133 | \r | |
134 | Signature[12] = '\0';\r | |
135 | for (mXenLeaf = 0x40000000; mXenLeaf < 0x40010000; mXenLeaf += 0x100) {\r | |
136 | AsmCpuid (mXenLeaf,\r | |
137 | NULL,\r | |
138 | (UINT32 *) &Signature[0],\r | |
eec7d420 | 139 | (UINT32 *) &Signature[4],\r |
140 | (UINT32 *) &Signature[8]);\r | |
eec7d420 | 141 | \r |
142 | if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {\r | |
b621bb0a | 143 | mXen = TRUE;\r |
b98b4941 | 144 | return TRUE;\r |
eec7d420 | 145 | }\r |
146 | }\r | |
147 | \r | |
b98b4941 JJ |
148 | mXenLeaf = 0;\r |
149 | return FALSE;\r | |
eec7d420 | 150 | }\r |
151 | \r | |
152 | /**\r | |
153 | Perform Xen PEI initialization.\r | |
154 | \r | |
155 | @return EFI_SUCCESS Xen initialized successfully\r | |
156 | @return EFI_NOT_FOUND Not running under Xen\r | |
157 | \r | |
158 | **/\r | |
159 | EFI_STATUS\r | |
160 | InitializeXen (\r | |
b98b4941 | 161 | VOID\r |
eec7d420 | 162 | )\r |
163 | {\r | |
b98b4941 JJ |
164 | if (mXenLeaf == 0) {\r |
165 | return EFI_NOT_FOUND;\r | |
166 | }\r | |
167 | \r | |
168 | XenConnect (mXenLeaf);\r | |
eec7d420 | 169 | \r |
170 | //\r | |
171 | // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).\r | |
172 | // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE.\r | |
173 | //\r | |
174 | AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000);\r | |
175 | \r | |
176 | return EFI_SUCCESS;\r | |
177 | }\r |