EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

OvmfPkg/PlatformPei/MemDetect.c

Go to the documentation of this file.
00001 
00019 //
00020 // The package level header files this module uses
00021 //
00022 #include <PiPei.h>
00023 
00024 //
00025 // The Library classes this module consumes
00026 //
00027 #include <Library/DebugLib.h>
00028 #include <Library/HobLib.h>
00029 #include <Library/IoLib.h>
00030 #include <Library/PcdLib.h>
00031 #include <Library/PeimEntryPoint.h>
00032 #include <Library/ResourcePublicationLib.h>
00033 #include <Library/MtrrLib.h>
00034 
00035 #include "Platform.h"
00036 #include "Cmos.h"
00037 
00038 STATIC
00039 UINTN
00040 GetSystemMemorySizeBelow4gb (
00041   )
00042 {
00043   UINT8 Cmos0x34;
00044   UINT8 Cmos0x35;
00045 
00046   //
00047   // CMOS 0x34/0x35 specifies the system memory above 16 MB.
00048   // * CMOS(0x35) is the high byte
00049   // * CMOS(0x34) is the low byte
00050   // * The size is specified in 64kb chunks
00051   // * Since this is memory above 16MB, the 16MB must be added
00052   //   into the calculation to get the total memory size.
00053   //
00054 
00055   Cmos0x34 = (UINT8) CmosRead8 (0x34);
00056   Cmos0x35 = (UINT8) CmosRead8 (0x35);
00057 
00058   return (((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
00059 }
00060 
00061 
00062 STATIC
00063 UINT64
00064 GetSystemMemorySizeAbove4gb (
00065   )
00066 {
00067   UINT32 Size;
00068   UINTN  CmosIndex;
00069 
00070   //
00071   // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
00072   // * CMOS(0x5d) is the most significant size byte
00073   // * CMOS(0x5c) is the middle size byte
00074   // * CMOS(0x5b) is the least significant size byte
00075   // * The size is specified in 64kb chunks
00076   //
00077 
00078   Size = 0;
00079   for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
00080     Size = (UINT32) (Size << 8) + (UINT32) CmosRead8 (CmosIndex);
00081   }
00082 
00083   return LShiftU64 (Size, 16);
00084 }
00085 
00086 
00093 EFI_PHYSICAL_ADDRESS
00094 MemDetect (
00095   )
00096 {
00097   EFI_STATUS                  Status;
00098   EFI_PHYSICAL_ADDRESS        MemoryBase;
00099   UINT64                      MemorySize;
00100   UINT64                      LowerMemorySize;
00101   UINT64                      UpperMemorySize;
00102 
00103   DEBUG ((EFI_D_ERROR, "MemDetect called\n"));
00104 
00105   //
00106   // Determine total memory size available
00107   //
00108   LowerMemorySize = GetSystemMemorySizeBelow4gb ();
00109   UpperMemorySize = GetSystemMemorySizeAbove4gb ();
00110 
00111   //
00112   // Determine the range of memory to use during PEI
00113   //
00114   MemoryBase = PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize);
00115   MemorySize = LowerMemorySize - MemoryBase;
00116   if (MemorySize > SIZE_64MB) {
00117     MemoryBase = LowerMemorySize - SIZE_64MB;
00118     MemorySize = SIZE_64MB;
00119   }
00120 
00121   //
00122   // Publish this memory to the PEI Core
00123   //
00124   Status = PublishSystemMemory(MemoryBase, MemorySize);
00125   ASSERT_EFI_ERROR (Status);
00126 
00127   //
00128   // Create memory HOBs
00129   //
00130   AddMemoryBaseSizeHob (MemoryBase, MemorySize);
00131   AddMemoryRangeHob (BASE_1MB, MemoryBase);
00132   AddMemoryRangeHob (0, BASE_512KB + BASE_128KB);
00133 
00134   MtrrSetMemoryAttribute (BASE_1MB, MemoryBase + MemorySize - BASE_1MB, CacheWriteBack);
00135 
00136   MtrrSetMemoryAttribute (0, BASE_512KB + BASE_128KB, CacheWriteBack);
00137 
00138   if (UpperMemorySize != 0) {
00139     AddUntestedMemoryBaseSizeHob (BASE_4GB, UpperMemorySize);
00140 
00141     MtrrSetMemoryAttribute (BASE_4GB, UpperMemorySize, CacheWriteBack);
00142   }
00143 
00144   return MemoryBase + MemorySize;
00145 }
00146 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines