2 Memory Detection for Virtual Machines.
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 // The package level header files this module uses
25 // The Library classes this module consumes
27 #include <Library/DebugLib.h>
28 #include <Library/HobLib.h>
29 #include <Library/IoLib.h>
30 #include <Library/PcdLib.h>
31 #include <Library/PeimEntryPoint.h>
32 #include <Library/ResourcePublicationLib.h>
46 // CMOS 0x34/0x35 specifies the system memory above 16 MB.
47 // * CMOS(0x35) is the high byte
48 // * CMOS(0x34) is the low byte
49 // * The size is specified in 64kb chunks
50 // * Since this is memory above 16MB, the 16MB must be added
51 // into the calculation to get the total memory size.
54 Cmos0x34
= (UINT8
) CmosRead8 (0x34);
55 Cmos0x35
= (UINT8
) CmosRead8 (0x35);
57 return (((UINTN
)((Cmos0x35
<< 8) + Cmos0x34
) << 16) + SIZE_16MB
);
62 Peform Memory Detection
64 @return EFI_SUCCESS The PEIM initialized successfully.
72 EFI_PHYSICAL_ADDRESS MemoryBase
;
74 UINT64 TotalMemorySize
;
76 DEBUG ((EFI_D_ERROR
, "MemDetect called\n"));
79 // Determine total memory size available
81 TotalMemorySize
= (UINT64
)GetSystemMemorySize ();
84 // Determine the range of memory to use during PEI
86 MemoryBase
= PcdGet32 (PcdOvmfMemFvBase
) + PcdGet32 (PcdOvmfMemFvSize
);
87 MemorySize
= TotalMemorySize
- MemoryBase
;
88 if (MemorySize
> SIZE_16MB
) {
89 MemoryBase
= TotalMemorySize
- SIZE_16MB
;
90 MemorySize
= SIZE_16MB
;
94 // Publish this memory to the PEI Core
96 Status
= PublishSystemMemory(MemoryBase
, MemorySize
);
97 ASSERT_EFI_ERROR (Status
);
100 // Create memory HOBs
102 AddMemoryBaseSizeHob (MemoryBase
, MemorySize
);
103 AddMemoryRangeHob (BASE_1MB
, MemoryBase
);
104 AddMemoryRangeHob (0, BASE_512KB
+ BASE_128KB
);
106 return MemoryBase
+ MemorySize
;