]>
Commit | Line | Data |
---|---|---|
1 | /**@file\r | |
2 | Memory Detection for Virtual Machines.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\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 | 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 | |
30 | #include <Library/PcdLib.h>\r | |
31 | #include <Library/PeimEntryPoint.h>\r | |
32 | #include <Library/ResourcePublicationLib.h>\r | |
33 | \r | |
34 | #include "Platform.h"\r | |
35 | #include "Cmos.h"\r | |
36 | \r | |
37 | STATIC\r | |
38 | UINTN\r | |
39 | GetSystemMemorySizeBelow4gb (\r | |
40 | )\r | |
41 | {\r | |
42 | UINT8 Cmos0x34;\r | |
43 | UINT8 Cmos0x35;\r | |
44 | \r | |
45 | //\r | |
46 | // CMOS 0x34/0x35 specifies the system memory above 16 MB.\r | |
47 | // * CMOS(0x35) is the high byte\r | |
48 | // * CMOS(0x34) is the low byte\r | |
49 | // * The size is specified in 64kb chunks\r | |
50 | // * Since this is memory above 16MB, the 16MB must be added\r | |
51 | // into the calculation to get the total memory size.\r | |
52 | //\r | |
53 | \r | |
54 | Cmos0x34 = (UINT8) CmosRead8 (0x34);\r | |
55 | Cmos0x35 = (UINT8) CmosRead8 (0x35);\r | |
56 | \r | |
57 | return (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);\r | |
58 | }\r | |
59 | \r | |
60 | \r | |
61 | STATIC\r | |
62 | UINT64\r | |
63 | GetSystemMemorySizeAbove4gb (\r | |
64 | )\r | |
65 | {\r | |
66 | UINT32 Size;\r | |
67 | UINTN CmosIndex;\r | |
68 | \r | |
69 | //\r | |
70 | // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.\r | |
71 | // * CMOS(0x5d) is the most significant size byte\r | |
72 | // * CMOS(0x5c) is the middle size byte\r | |
73 | // * CMOS(0x5b) is the least significant size byte\r | |
74 | // * The size is specified in 64kb chunks\r | |
75 | //\r | |
76 | \r | |
77 | Size = 0;\r | |
78 | for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {\r | |
79 | Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);\r | |
80 | }\r | |
81 | \r | |
82 | return LShiftU64 (Size, 16);\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
86 | /**\r | |
87 | Peform Memory Detection\r | |
88 | \r | |
89 | @return EFI_SUCCESS The PEIM initialized successfully.\r | |
90 | \r | |
91 | **/\r | |
92 | EFI_PHYSICAL_ADDRESS\r | |
93 | MemDetect (\r | |
94 | )\r | |
95 | {\r | |
96 | EFI_STATUS Status;\r | |
97 | EFI_PHYSICAL_ADDRESS MemoryBase;\r | |
98 | UINT64 MemorySize;\r | |
99 | UINT64 LowerMemorySize;\r | |
100 | UINT64 UpperMemorySize;\r | |
101 | \r | |
102 | DEBUG ((EFI_D_ERROR, "MemDetect called\n"));\r | |
103 | \r | |
104 | //\r | |
105 | // Determine total memory size available\r | |
106 | //\r | |
107 | LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r | |
108 | UpperMemorySize = GetSystemMemorySizeAbove4gb ();\r | |
109 | \r | |
110 | //\r | |
111 | // Determine the range of memory to use during PEI\r | |
112 | //\r | |
113 | MemoryBase = PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize);\r | |
114 | MemorySize = LowerMemorySize - MemoryBase;\r | |
115 | if (MemorySize > SIZE_64MB) {\r | |
116 | MemoryBase = LowerMemorySize - SIZE_64MB;\r | |
117 | MemorySize = SIZE_64MB;\r | |
118 | }\r | |
119 | \r | |
120 | //\r | |
121 | // Publish this memory to the PEI Core\r | |
122 | //\r | |
123 | Status = PublishSystemMemory(MemoryBase, MemorySize);\r | |
124 | ASSERT_EFI_ERROR (Status);\r | |
125 | \r | |
126 | //\r | |
127 | // Create memory HOBs\r | |
128 | //\r | |
129 | AddMemoryBaseSizeHob (MemoryBase, MemorySize);\r | |
130 | AddMemoryRangeHob (BASE_1MB, MemoryBase);\r | |
131 | AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);\r | |
132 | \r | |
133 | if (UpperMemorySize != 0) {\r | |
134 | AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);\r | |
135 | }\r | |
136 | \r | |
137 | return MemoryBase + MemorySize;\r | |
138 | }\r | |
139 | \r |