Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
645 changes: 102 additions & 543 deletions MsvmPkg/AcpiPlatformDxe/AcpiPlatform.c

Large diffs are not rendered by default.

22 changes: 4 additions & 18 deletions MsvmPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
CrashLib
DebugLib
DxeServicesLib
HobLib
IoLib
IsolationLib
PcdLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiLib

[Guids]
gAcpiReplacementTableHobGuid ## CONSUMES

[Protocols]
gEfiAcpiTableProtocolGuid ## CONSUMES

Expand All @@ -53,8 +57,6 @@
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdAcpiTablePtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdAcpiTableSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdBiosBaseAddress ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdCom1RegisterBase ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdCom1Vector ## CONSUMES
Expand All @@ -73,34 +75,18 @@
gMsvmPkgTokenSpaceGuid.PcdLowPowerS0IdleEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdMadtPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdMadtSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdMcfgPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdMcfgSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSsdtPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSsdtSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdIortPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdIortSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdNvdimmCount ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdPpttPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdPpttSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdProcessorCount ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdProcIdleEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdCxlMemoryEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSerialControllersEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSgxMemoryEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSlitPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSlitSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSratPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdSratSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdHmatPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdHmatSize ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdTpmEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdVirtualBatteryEnabled ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdWatchdogEnabled ## CONSUMES

[Pcd.X64]
gMsvmPkgTokenSpaceGuid.PcdAcpiMadtMpMailBoxAddress ## PRODUCES
gMsvmPkgTokenSpaceGuid.PcdAsptPtr ## CONSUMES
gMsvmPkgTokenSpaceGuid.PcdAsptSize ## CONSUMES

[Depex]
gEfiAcpiTableProtocolGuid
Expand Down
95 changes: 95 additions & 0 deletions MsvmPkg/Include/AcpiReplacementTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/** @file
Shared definitions for VMM-provided ACPI table replacements passed via HOBs.

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#pragma once

#include <Uefi.h>
#include <Library/HobLib.h>
#include <IndustryStandard/Acpi.h>

//
// GUID used to identify ACPI replacement table HOBs.
// Each HOB with this GUID contains an ACPI_REPLACEMENT_TABLE_HOB_DATA
// structure that points to a complete ACPI table (starting with
// EFI_ACPI_DESCRIPTION_HEADER) in persistent memory. When an ACPI table from
// the firmware volume has the same signature as a replacement table HOB, the
// FV table is suppressed and the HOB-referenced table is installed instead.
//
#define ACPI_REPLACEMENT_TABLE_HOB_GUID \
{ 0xa24aef4c, 0xa824, 0x48e9, { 0xb5, 0xb8, 0xbc, 0xd9, 0x6a, 0x59, 0x71, 0xaf } }

extern EFI_GUID gAcpiReplacementTableHobGuid;

//
// HOB payload: pointer to an ACPI table in persistent memory.
//
typedef struct {
EFI_ACPI_DESCRIPTION_HEADER *Table;
} ACPI_REPLACEMENT_TABLE_HOB_DATA;

//
// Helper: get the ACPI table header from a replacement table HOB.
// HobRaw must point to a valid GUIDed HOB with gAcpiReplacementTableHobGuid.
//
static inline EFI_ACPI_DESCRIPTION_HEADER *
AcpiReplacementTableFromHob(
IN VOID *HobRaw
)
{
EFI_HOB_GUID_TYPE *GuidHob = (EFI_HOB_GUID_TYPE *)HobRaw;
ACPI_REPLACEMENT_TABLE_HOB_DATA *Data =
(ACPI_REPLACEMENT_TABLE_HOB_DATA *)GET_GUID_HOB_DATA(GuidHob);
return Data->Table;
}

//
// Helper: get the first replacement table HOB, returning the raw HOB pointer.
// Returns NULL if none exist. Use with AcpiReplacementTableFromHob() and
// GetNextAcpiReplacementTableHob() to iterate.
//
static inline VOID *
GetFirstAcpiReplacementTableHob(
VOID
)
{
return GetFirstGuidHob(&gAcpiReplacementTableHobGuid);
}

//
// Helper: get the next replacement table HOB after CurrentHob.
// Returns NULL if no more exist.
//
static inline VOID *
GetNextAcpiReplacementTableHob(
IN VOID *CurrentHob
)
{
return GetNextGuidHob(&gAcpiReplacementTableHobGuid, GET_NEXT_HOB(CurrentHob));
}

//
// Helper: find the first replacement table matching a given ACPI signature.
// Returns the table header pointer, or NULL if not found.
//
static inline EFI_ACPI_DESCRIPTION_HEADER *
FindAcpiReplacementTable(
IN UINT32 Signature
)
{
VOID *Hob = GetFirstAcpiReplacementTableHob();
while (Hob != NULL)
{
EFI_ACPI_DESCRIPTION_HEADER *Table = AcpiReplacementTableFromHob(Hob);
if (Table->Signature == Signature)
{
return Table;
}
Hob = GetNextAcpiReplacementTableHob(Hob);
}
return NULL;
}
28 changes: 9 additions & 19 deletions MsvmPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @file
Platform PCI Host Bridge Library for Hyper-V Gen2 VMs.

Reads MCFG + PcieBarApertures from config blob PCDs and returns
a PCI_ROOT_BRIDGE array for PciHostBridgeDxe.
Reads MCFG from the ACPI replacement table HOB + PcieBarApertures from
config blob PCDs and returns a PCI_ROOT_BRIDGE array for PciHostBridgeDxe.

Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -12,13 +12,15 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/HobLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
#include <AcpiReplacementTable.h>
#include <BiosInterface.h>
#include <PciConstants.h>

Expand Down Expand Up @@ -62,9 +64,6 @@ PciHostBridgeGetRootBridges (
OUT UINTN *Count
)
{
UINT64 McfgPtr;
UINT32 McfgSize;
MCFG_TABLE_HEADER *McfgHdr;
UINT32 McfgDataLen;
UINT32 McfgEntryCount;
MCFG_ALLOCATION_ENTRY *McfgEntries;
Expand All @@ -80,27 +79,18 @@ PciHostBridgeGetRootBridges (
*Count = 0;

//
// Read MCFG from PCD.
// Find MCFG table from HOB list.
//
McfgPtr = PcdGet64 (PcdMcfgPtr);
McfgSize = PcdGet32 (PcdMcfgSize);
MCFG_TABLE_HEADER *McfgHdr = (MCFG_TABLE_HEADER *)FindAcpiReplacementTable(
EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE);

DEBUG ((DEBUG_VERBOSE, "PCIe: PciHostBridgeLib McfgPtr=0x%lx McfgSize=%u\n", McfgPtr, McfgSize));
DEBUG ((DEBUG_VERBOSE, "PCIe: PciHostBridgeLib McfgHdr=%p\n", McfgHdr));

if (McfgPtr == 0 || McfgSize < sizeof (MCFG_TABLE_HEADER)) {
if (McfgHdr == NULL || McfgHdr->Header.Length < sizeof(MCFG_TABLE_HEADER)) {
DEBUG ((DEBUG_INFO, "PCIe: No MCFG table, no root bridges\n"));
return NULL;
}

McfgHdr = (MCFG_TABLE_HEADER *)(UINTN)McfgPtr;

if (McfgHdr->Header.Length < sizeof (MCFG_TABLE_HEADER) ||
McfgHdr->Header.Length > McfgSize) {
DEBUG ((DEBUG_ERROR, "PCIe: Invalid MCFG Length %u (PCD size %u)\n",
McfgHdr->Header.Length, McfgSize));
return NULL;
}

McfgDataLen = McfgHdr->Header.Length - sizeof (MCFG_TABLE_HEADER);
McfgEntryCount = McfgDataLen / sizeof (MCFG_ALLOCATION_ENTRY);

Expand Down
6 changes: 4 additions & 2 deletions MsvmPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
[LibraryClasses]
BaseMemoryLib
DebugLib
HobLib
PcdLib
MemoryAllocationLib
DevicePathLib

[Pcd]
gMsvmPkgTokenSpaceGuid.PcdMcfgPtr
gMsvmPkgTokenSpaceGuid.PcdMcfgSize
gMsvmPkgTokenSpaceGuid.PcdPcieBarAperturesPtr
gMsvmPkgTokenSpaceGuid.PcdPcieBarAperturesSize

[Guids]
gAcpiReplacementTableHobGuid
28 changes: 8 additions & 20 deletions MsvmPkg/Library/PciSegmentInfoLib/PciSegmentInfoLib.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Platform PCI Segment Info Library for Hyper-V Gen2 VMs.

Reads MCFG from config blob PCD and provides segment-to-ECAM-base
Reads MCFG from the ACPI replacement table HOB and provides segment-to-ECAM-base
mapping for BasePciSegmentLibSegmentInfo.

Copyright (c) Microsoft Corporation.
Expand All @@ -11,11 +11,12 @@
#include <PiDxe.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciSegmentInfoLib.h>
#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
#include <AcpiReplacementTable.h>
#include <PciConstants.h>

STATIC
Expand All @@ -34,9 +35,6 @@ GetPciSegmentInfo (
OUT UINTN *Count
)
{
UINT64 McfgPtr;
UINT32 McfgSize;
MCFG_TABLE_HEADER *McfgHdr;
UINT32 DataLen;
UINT32 EntryCount;
MCFG_ALLOCATION_ENTRY *Entries;
Expand All @@ -48,23 +46,13 @@ GetPciSegmentInfo (
}

//
// Parse MCFG table from PCD (same data PlatformPei extracted from config blob).
// Find MCFG table from HOB list.
//
McfgPtr = PcdGet64 (PcdMcfgPtr);
McfgSize = PcdGet32 (PcdMcfgSize);
MCFG_TABLE_HEADER *McfgHdr = (MCFG_TABLE_HEADER *)FindAcpiReplacementTable(
EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE);

if (McfgPtr == 0 || McfgSize < sizeof (MCFG_TABLE_HEADER)) {
DEBUG ((DEBUG_INFO, "PCIe: PciSegmentInfoLib: No MCFG table\n"));
*Count = 0;
return NULL;
}

McfgHdr = (MCFG_TABLE_HEADER *)(UINTN)McfgPtr;

if (McfgHdr->Header.Length < sizeof (MCFG_TABLE_HEADER) ||
McfgHdr->Header.Length > McfgSize) {
DEBUG ((DEBUG_ERROR, "PCIe: PciSegmentInfoLib: Invalid MCFG Length %u (PCD size %u)\n",
McfgHdr->Header.Length, McfgSize));
if (McfgHdr == NULL || McfgHdr->Header.Length < sizeof(MCFG_TABLE_HEADER)) {
DEBUG ((DEBUG_INFO, "PCIe: PciSegmentInfoLib: No MCFG table in HOBs\n"));
*Count = 0;
return NULL;
}
Expand Down
7 changes: 3 additions & 4 deletions MsvmPkg/Library/PciSegmentInfoLib/PciSegmentInfoLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
[LibraryClasses]
BaseMemoryLib
DebugLib
PcdLib
HobLib
MemoryAllocationLib

[Pcd]
gMsvmPkgTokenSpaceGuid.PcdMcfgPtr
gMsvmPkgTokenSpaceGuid.PcdMcfgSize
[Guids]
gAcpiReplacementTableHobGuid
5 changes: 5 additions & 0 deletions MsvmPkg/MsvmPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
gSyntheticVmbfsClassGuid = {0xc376c1c3, 0xd276, 0x48d2, {0x90, 0xa9, 0xc0, 0x47, 0x48, 0x07, 0x2c, 0x60}}
gSyntheticVpciClassGuid = {0x44c4f61d, 0x4444, 0x4400, {0x9d, 0x52, 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f}}

#
# HOB GUID for VMM-provided ACPI table replacements
#
gAcpiReplacementTableHobGuid = {0xa24aef4c, 0xa824, 0x48e9, {0xb5, 0xb8, 0xbc, 0xd9, 0x6a, 0x59, 0x71, 0xaf}}

#
# MsvmPkg specific events
#
Expand Down
Loading
Loading