@@ -17,6 +17,7 @@ Module Name:
1717#include <IndustryStandard/I440FxPiix4.h>
1818#include <IndustryStandard/Q35MchIch9.h>
1919#include <IndustryStandard/CloudHv.h>
20+ #include <IndustryStandard/Xen/arch-x86/hvm/start_info.h>
2021#include <PiPei.h>
2122#include <Register/Intel/SmramSaveStateMap.h>
2223
@@ -315,6 +316,73 @@ ScanOrAdd64BitE820Ram (
315316 return EFI_SUCCESS ;
316317}
317318
319+ /**
320+ Returns PVH memmap
321+
322+ @param Entries Pointer to PVH memmap
323+ @param Count Number of entries
324+
325+ @return EFI_STATUS
326+ **/
327+ EFI_STATUS
328+ GetPvhMemmapEntries (
329+ struct hvm_memmap_table_entry * * Entries ,
330+ UINT32 * Count
331+ )
332+ {
333+ UINT32 * PVHResetVectorData ;
334+ struct hvm_start_info * pvh_start_info ;
335+
336+ PVHResetVectorData = (VOID * )(UINTN )PcdGet32 (PcdXenPvhStartOfDayStructPtr );
337+ if (PVHResetVectorData == 0 ) {
338+ return EFI_NOT_FOUND ;
339+ }
340+
341+ pvh_start_info = (struct hvm_start_info * )(UINTN )PVHResetVectorData [0 ];
342+
343+ * Entries = (struct hvm_memmap_table_entry * )(UINTN )pvh_start_info -> memmap_paddr ;
344+ * Count = pvh_start_info -> memmap_entries ;
345+
346+ return EFI_SUCCESS ;
347+ }
348+
349+ STATIC
350+ UINT64
351+ GetHighestSystemMemoryAddressFromPvhMemmap (
352+ BOOLEAN Below4gb
353+ )
354+ {
355+ struct hvm_memmap_table_entry * Memmap ;
356+ UINT32 MemmapEntriesCount ;
357+ struct hvm_memmap_table_entry * Entry ;
358+ EFI_STATUS Status ;
359+ UINT32 Loop ;
360+ UINT64 HighestAddress ;
361+ UINT64 EntryEnd ;
362+
363+ HighestAddress = 0 ;
364+
365+ Status = GetPvhMemmapEntries (& Memmap , & MemmapEntriesCount );
366+ ASSERT_EFI_ERROR (Status );
367+
368+ for (Loop = 0 ; Loop < MemmapEntriesCount ; Loop ++ ) {
369+ Entry = Memmap + Loop ;
370+ EntryEnd = Entry -> addr + Entry -> size ;
371+
372+ if ((Entry -> type == XEN_HVM_MEMMAP_TYPE_RAM ) &&
373+ (EntryEnd > HighestAddress ))
374+ {
375+ if (Below4gb && (EntryEnd <= BASE_4GB )) {
376+ HighestAddress = EntryEnd ;
377+ } else if (!Below4gb && (EntryEnd >= BASE_4GB )) {
378+ HighestAddress = EntryEnd ;
379+ }
380+ }
381+ }
382+
383+ return HighestAddress ;
384+ }
385+
318386UINT32
319387GetSystemMemorySizeBelow4gb (
320388 VOID
@@ -325,6 +393,11 @@ GetSystemMemorySizeBelow4gb (
325393 UINT8 Cmos0x34 ;
326394 UINT8 Cmos0x35 ;
327395
396+ if (mHostBridgeDevId == CLOUDHV_DEVICE_ID ) {
397+ // Get the information from PVH memmap
398+ return (UINT32 )GetHighestSystemMemoryAddressFromPvhMemmap (TRUE);
399+ }
400+
328401 Status = ScanOrAdd64BitE820Ram (FALSE, & LowerMemorySize , NULL );
329402 if ((Status == EFI_SUCCESS ) && (LowerMemorySize > 0 )) {
330403 return (UINT32 )LowerMemorySize ;
0 commit comments