]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/PlatformPei/MemDetect.c
Update the copyright notice format
[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
39GetSystemMemorySize (\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 ((((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);\r
58}\r
59\r
60\r
61/**\r
62 Peform Memory Detection\r
63\r
64 @return EFI_SUCCESS The PEIM initialized successfully.\r
65\r
66**/\r
67EFI_STATUS\r
68MemDetect (\r
69 )\r
70{\r
71 EFI_STATUS Status;\r
72 EFI_PHYSICAL_ADDRESS MemoryBase;\r
73 UINT64 MemorySize;\r
74 UINT64 TotalMemorySize;\r
75\r
76 DEBUG ((EFI_D_ERROR, "MemDetect called\n"));\r
77\r
78 //\r
79 // Determine total memory size available\r
80 //\r
81 TotalMemorySize = (UINT64)GetSystemMemorySize ();\r
82\r
c1c2669c 83 //\r
84 // Determine the range of memory to use during PEI\r
85 //\r
86 MemoryBase = PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize);\r
87 MemorySize = TotalMemorySize - MemoryBase;\r
88 if (MemorySize > SIZE_16MB) {\r
89 MemoryBase = TotalMemorySize - SIZE_16MB;\r
90 MemorySize = SIZE_16MB;\r
91 }\r
49ba9447 92\r
93 //\r
94 // Publish this memory to the PEI Core\r
95 //\r
96 Status = PublishSystemMemory(MemoryBase, MemorySize);\r
97 ASSERT_EFI_ERROR (Status);\r
98\r
99 //\r
100 // Create memory HOBs\r
101 //\r
102 AddMemoryBaseSizeHob (MemoryBase, MemorySize);\r
c1c2669c 103 AddMemoryRangeHob (BASE_1MB, MemoryBase);\r
104 AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);\r
49ba9447 105\r
106 return EFI_SUCCESS;\r
107}\r
108\r