]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/PlatformPei/MemDetect.c
Remove a unnecessary Macro in SecureBootConfigImpl.h.
[mirror_edk2.git] / OvmfPkg / PlatformPei / MemDetect.c
CommitLineData
49ba9447 1/**@file\r
2 Memory Detection for Virtual Machines.\r
3\r
56d7640a
HT
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
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
13Module 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
33\r
34#include "Platform.h"\r
35#include "Cmos.h"\r
36\r
37STATIC\r
38UINTN\r
c0e10976 39GetSystemMemorySizeBelow4gb (\r
49ba9447 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
55cdb67a 57 return (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);\r
49ba9447 58}\r
59\r
60\r
c0e10976 61STATIC\r
62UINT64\r
63GetSystemMemorySizeAbove4gb (\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
49ba9447 86/**\r
87 Peform Memory Detection\r
88\r
89 @return EFI_SUCCESS The PEIM initialized successfully.\r
90\r
91**/\r
55cdb67a 92EFI_PHYSICAL_ADDRESS\r
49ba9447 93MemDetect (\r
94 )\r
95{\r
96 EFI_STATUS Status;\r
97 EFI_PHYSICAL_ADDRESS MemoryBase;\r
98 UINT64 MemorySize;\r
c0e10976 99 UINT64 LowerMemorySize;\r
100 UINT64 UpperMemorySize;\r
49ba9447 101\r
102 DEBUG ((EFI_D_ERROR, "MemDetect called\n"));\r
103\r
104 //\r
105 // Determine total memory size available\r
106 //\r
c0e10976 107 LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r
108 UpperMemorySize = GetSystemMemorySizeAbove4gb ();\r
49ba9447 109\r
c1c2669c 110 //\r
111 // Determine the range of memory to use during PEI\r
112 //\r
113 MemoryBase = PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize);\r
c0e10976 114 MemorySize = LowerMemorySize - MemoryBase;\r
115 if (MemorySize > SIZE_64MB) {\r
116 MemoryBase = LowerMemorySize - SIZE_64MB;\r
117 MemorySize = SIZE_64MB;\r
c1c2669c 118 }\r
49ba9447 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
c1c2669c 130 AddMemoryRangeHob (BASE_1MB, MemoryBase);\r
131 AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);\r
49ba9447 132\r
c0e10976 133 if (UpperMemorySize != 0) {\r
134 AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);\r
135 }\r
136\r
55cdb67a 137 return MemoryBase + MemorySize;\r
49ba9447 138}\r
139\r