]>
Commit | Line | Data |
---|---|---|
49ba9447 | 1 | /**@file\r |
2 | Memory Detection for Virtual Machines.\r | |
3 | \r | |
4b455f7b | 4 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
56d7640a | 5 | This program and the accompanying materials\r |
49ba9447 | 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 | Module Name:\r | |
14 | \r | |
15 | MemDetect.c\r | |
16 | \r | |
17 | **/\r | |
18 | \r | |
19 | //\r | |
20 | // The package level header files this module uses\r | |
21 | //\r | |
22 | #include <PiPei.h>\r | |
23 | \r | |
24 | //\r | |
25 | // The Library classes this module consumes\r | |
26 | //\r | |
27 | #include <Library/DebugLib.h>\r | |
28 | #include <Library/HobLib.h>\r | |
29 | #include <Library/IoLib.h>\r | |
c1c2669c | 30 | #include <Library/PcdLib.h>\r |
49ba9447 | 31 | #include <Library/PeimEntryPoint.h>\r |
32 | #include <Library/ResourcePublicationLib.h>\r | |
e8e5cd4a | 33 | #include <Library/MtrrLib.h>\r |
49ba9447 | 34 | \r |
35 | #include "Platform.h"\r | |
36 | #include "Cmos.h"\r | |
37 | \r | |
4b455f7b | 38 | UINT32\r |
c0e10976 | 39 | GetSystemMemorySizeBelow4gb (\r |
4b455f7b | 40 | VOID\r |
49ba9447 | 41 | )\r |
42 | {\r | |
43 | UINT8 Cmos0x34;\r | |
44 | UINT8 Cmos0x35;\r | |
45 | \r | |
46 | //\r | |
47 | // CMOS 0x34/0x35 specifies the system memory above 16 MB.\r | |
48 | // * CMOS(0x35) is the high byte\r | |
49 | // * CMOS(0x34) is the low byte\r | |
50 | // * The size is specified in 64kb chunks\r | |
51 | // * Since this is memory above 16MB, the 16MB must be added\r | |
52 | // into the calculation to get the total memory size.\r | |
53 | //\r | |
54 | \r | |
55 | Cmos0x34 = (UINT8) CmosRead8 (0x34);\r | |
56 | Cmos0x35 = (UINT8) CmosRead8 (0x35);\r | |
57 | \r | |
55cdb67a | 58 | return (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);\r |
49ba9447 | 59 | }\r |
60 | \r | |
61 | \r | |
c0e10976 | 62 | STATIC\r |
63 | UINT64\r | |
64 | GetSystemMemorySizeAbove4gb (\r | |
65 | )\r | |
66 | {\r | |
67 | UINT32 Size;\r | |
68 | UINTN CmosIndex;\r | |
69 | \r | |
70 | //\r | |
71 | // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.\r | |
72 | // * CMOS(0x5d) is the most significant size byte\r | |
73 | // * CMOS(0x5c) is the middle size byte\r | |
74 | // * CMOS(0x5b) is the least significant size byte\r | |
75 | // * The size is specified in 64kb chunks\r | |
76 | //\r | |
77 | \r | |
78 | Size = 0;\r | |
79 | for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {\r | |
80 | Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);\r | |
81 | }\r | |
82 | \r | |
83 | return LShiftU64 (Size, 16);\r | |
84 | }\r | |
85 | \r | |
36658fff WL |
86 | /**\r |
87 | Publish PEI core memory\r | |
88 | \r | |
89 | @return EFI_SUCCESS The PEIM initialized successfully.\r | |
90 | \r | |
91 | **/\r | |
92 | EFI_STATUS\r | |
93 | PublishPeiMemory (\r | |
94 | VOID\r | |
95 | )\r | |
96 | {\r | |
97 | EFI_STATUS Status;\r | |
98 | EFI_PHYSICAL_ADDRESS MemoryBase;\r | |
99 | UINT64 MemorySize;\r | |
100 | UINT64 LowerMemorySize;\r | |
101 | \r | |
102 | LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r | |
103 | \r | |
4a9fab7d LE |
104 | //\r |
105 | // Determine the range of memory to use during PEI\r | |
106 | //\r | |
b36f701d | 107 | MemoryBase = PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);\r |
36658fff WL |
108 | MemorySize = LowerMemorySize - MemoryBase;\r |
109 | if (MemorySize > SIZE_64MB) {\r | |
110 | MemoryBase = LowerMemorySize - SIZE_64MB;\r | |
111 | MemorySize = SIZE_64MB;\r | |
112 | }\r | |
113 | \r | |
114 | //\r | |
115 | // Publish this memory to the PEI Core\r | |
116 | //\r | |
117 | Status = PublishSystemMemory(MemoryBase, MemorySize);\r | |
118 | ASSERT_EFI_ERROR (Status);\r | |
119 | \r | |
120 | return Status;\r | |
121 | }\r | |
122 | \r | |
c0e10976 | 123 | \r |
49ba9447 | 124 | /**\r |
c034906e | 125 | Peform Memory Detection for QEMU / KVM\r |
49ba9447 | 126 | \r |
127 | **/\r | |
c034906e JJ |
128 | STATIC\r |
129 | VOID\r | |
130 | QemuInitializeRam (\r | |
131 | VOID\r | |
49ba9447 | 132 | )\r |
133 | {\r | |
c0e10976 | 134 | UINT64 LowerMemorySize;\r |
135 | UINT64 UpperMemorySize;\r | |
49ba9447 | 136 | \r |
c034906e | 137 | DEBUG ((EFI_D_INFO, "%a called\n", __FUNCTION__));\r |
49ba9447 | 138 | \r |
139 | //\r | |
140 | // Determine total memory size available\r | |
141 | //\r | |
c0e10976 | 142 | LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r |
143 | UpperMemorySize = GetSystemMemorySizeAbove4gb ();\r | |
49ba9447 | 144 | \r |
49ba9447 | 145 | //\r |
146 | // Create memory HOBs\r | |
147 | //\r | |
9ab36385 | 148 | AddMemoryRangeHob (BASE_1MB, LowerMemorySize);\r |
c1c2669c | 149 | AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);\r |
49ba9447 | 150 | \r |
9ab36385 | 151 | MtrrSetMemoryAttribute (BASE_1MB, LowerMemorySize - BASE_1MB, CacheWriteBack);\r |
e8e5cd4a | 152 | \r |
27d7e63f | 153 | MtrrSetMemoryAttribute (0, BASE_512KB + BASE_128KB, CacheWriteBack);\r |
e8e5cd4a | 154 | \r |
c0e10976 | 155 | if (UpperMemorySize != 0) {\r |
156 | AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);\r | |
e8e5cd4a | 157 | \r |
27d7e63f | 158 | MtrrSetMemoryAttribute (BASE_4GB, UpperMemorySize, CacheWriteBack);\r |
c0e10976 | 159 | }\r |
49ba9447 | 160 | }\r |
161 | \r | |
c034906e JJ |
162 | /**\r |
163 | Publish system RAM and reserve memory regions\r | |
164 | \r | |
165 | **/\r | |
166 | VOID\r | |
167 | InitializeRamRegions (\r | |
168 | VOID\r | |
169 | )\r | |
170 | {\r | |
2818c158 JJ |
171 | if (!mXen) {\r |
172 | QemuInitializeRam ();\r | |
173 | } else {\r | |
174 | DEBUG ((EFI_D_INFO, "Using memory map provided by Xen\n"));\r | |
175 | XenPublishRamRegions ();\r | |
176 | }\r | |
c034906e | 177 | }\r |