]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/PlatformPei/MemDetect.c
Add initial version of Open Virtual Machine Firmware (OVMF) platform.
[mirror_edk2.git] / OvmfPkg / PlatformPei / MemDetect.c
CommitLineData
49ba9447 1/**@file\r
2 Memory Detection for Virtual Machines.\r
3\r
4 Copyright (c) 2006 - 2009, Intel Corporation\r
5 All rights reserved. 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
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
30#include <Library/PeimEntryPoint.h>\r
31#include <Library/ResourcePublicationLib.h>\r
32\r
33#include "Platform.h"\r
34#include "Cmos.h"\r
35\r
36STATIC\r
37UINTN\r
38GetSystemMemorySize (\r
39 )\r
40{\r
41 UINT8 Cmos0x34;\r
42 UINT8 Cmos0x35;\r
43\r
44 //\r
45 // CMOS 0x34/0x35 specifies the system memory above 16 MB.\r
46 // * CMOS(0x35) is the high byte\r
47 // * CMOS(0x34) is the low byte\r
48 // * The size is specified in 64kb chunks\r
49 // * Since this is memory above 16MB, the 16MB must be added\r
50 // into the calculation to get the total memory size.\r
51 //\r
52\r
53 Cmos0x34 = (UINT8) CmosRead8 (0x34);\r
54 Cmos0x35 = (UINT8) CmosRead8 (0x35);\r
55\r
56 return ((((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);\r
57}\r
58\r
59\r
60/**\r
61 Peform Memory Detection\r
62\r
63 @return EFI_SUCCESS The PEIM initialized successfully.\r
64\r
65**/\r
66EFI_STATUS\r
67MemDetect (\r
68 )\r
69{\r
70 EFI_STATUS Status;\r
71 EFI_PHYSICAL_ADDRESS MemoryBase;\r
72 UINT64 MemorySize;\r
73 UINT64 TotalMemorySize;\r
74\r
75 DEBUG ((EFI_D_ERROR, "MemDetect called\n"));\r
76\r
77 //\r
78 // Determine total memory size available\r
79 //\r
80 TotalMemorySize = (UINT64)GetSystemMemorySize ();\r
81\r
82 MemoryBase = 0x800000;\r
83 MemorySize = TotalMemorySize - MemoryBase - 0x100000;\r
84\r
85 //\r
86 // Publish this memory to the PEI Core\r
87 //\r
88 Status = PublishSystemMemory(MemoryBase, MemorySize);\r
89 ASSERT_EFI_ERROR (Status);\r
90\r
91 //\r
92 // Create memory HOBs\r
93 //\r
94 AddMemoryBaseSizeHob (MemoryBase, MemorySize);\r
95 AddMemoryRangeHob (0x100000, 0x800000);\r
96 AddMemoryRangeHob (0x000000, 0x0A0000);\r
97\r
98 return EFI_SUCCESS;\r
99}\r
100\r