From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.10802.1581107431629520226 for ; Fri, 07 Feb 2020 12:30:31 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: ashraf.javeed@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2020 12:30:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,414,1574150400"; d="scan'208";a="430949452" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga005.fm.intel.com with ESMTP; 07 Feb 2020 12:30:31 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 7 Feb 2020 12:30:31 -0800 Received: from bgsmsx151.gar.corp.intel.com (10.224.48.42) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 7 Feb 2020 12:30:30 -0800 Received: from bgsmsx101.gar.corp.intel.com ([169.254.1.155]) by BGSMSX151.gar.corp.intel.com ([169.254.3.195]) with mapi id 14.03.0439.000; Sat, 8 Feb 2020 02:00:26 +0530 From: "Javeed, Ashraf" To: "devel@edk2.groups.io" , "Javeed, Ashraf" CC: "Wang, Jian J" , "Wu, Hao A" , "Ni, Ray" Subject: Re: [edk2-devel] [edk2-staging/UEFI_PCI_ENHANCE-2 PATCH 11/12] PciBusDxe: New PCI Express feature ASPM support Thread-Topic: [edk2-devel] [edk2-staging/UEFI_PCI_ENHANCE-2 PATCH 11/12] PciBusDxe: New PCI Express feature ASPM support Thread-Index: AQHV3fIhwesJWVR2JEuFVpsg3tFUqKgQLtjg Date: Fri, 7 Feb 2020 20:30:26 +0000 Message-ID: <95C5C2B113DE604FB208120C742E9824579AB06F@BGSMSX101.gar.corp.intel.com> References: <20200207200447.10536-1-ashraf.javeed@intel.com> <15F13786546CB2AB.15938@groups.io> In-Reply-To: <15F13786546CB2AB.15938@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZWViODQ5MDgtNDZhZC00ZWJmLTlmZjktZDU0ZWQzNTBjMDJmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTHFZSXYxckhUTkdzbmxycUtPZTZPQm91Y1d2UlFQTnBqbVBlTjQzWWxqMkpIZHZ2K09KVUYwRDdGa2hDcncrMyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.223.10.10] MIME-Version: 1.0 Return-Path: ashraf.javeed@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable This patch can also be viewed in the following repo:- https://github.com/ashrafj/edk2-staging/commit/b44091c0f18fd578dbdaf209114= 5367042bdfba5 Thanks Ashraf > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Javeed, > Ashraf > Sent: Saturday, February 8, 2020 1:35 AM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Wu, Hao A = ; > Ni, Ray > Subject: [edk2-devel] [edk2-staging/UEFI_PCI_ENHANCE-2 PATCH 11/12] > PciBusDxe: New PCI Express feature ASPM support >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2500 >=20 > This code change is to enable the common ASPM state for all the connecte= d > devices, as per the PCI Express Base Specification 5, Revision 1. > This feature is not applicable to RCiEP, and to a vacant bridge device. > The device policy request from platform is applied if that is applicable= as per its > Link Capability register. Since all the connected devices have to have c= ommon > applicable ASPM value, it would be overuled as per PCI Ex- press Base > Specification. > The device L0s/L1 Acceptance Latency is used to measure against the L0s/= L1 Exit > Latencies comprising from Root Bridge to all its EP devices. If not appl= icable > ASPM would be disabled for all the devices. >=20 > This programming of ASPM, gets the device-specific platform policy using= the > new PCI Express Platform Protocol interface (ECR version 0.8), defined i= n the > below feature request:- > https://bugzilla.tianocore.org/show_bug.cgi?id=3D1954 >=20 > Signed-off-by: Ashraf Javeed > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Ray Ni > --- > MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 1 + > MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.c | 391 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > + > MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.h | 52 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.c | 23 > ++++++++++++++++++++++- > MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.h | 14 ++++++++++++++ > MdeModulePkg/Bus/Pci/PciBusDxe/PciPlatformSupport.c | 45 > +++++++++++++++++++++++++++++++++++++++++++++ > 6 files changed, 525 insertions(+), 1 deletion(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > index 6a6f648..b5caffe 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > @@ -298,6 +298,7 @@ struct _PCI_IO_DEVICE { > EFI_PCI_EXPRESS_ATOMIC_OP SetupAtomicOp; > BOOLEAN SetupLtr; > UINT8 SetupExtTag; > + UINT8 SetupAspm; > }; >=20 > #define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \ diff --git > a/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.c > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.c > index eaef3d3..5e350e7 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.c > @@ -1518,3 +1518,394 @@ ProgramExtTag ( > return Status; > } >=20 > +/** > + Set the ASPM device policy as per the device's link capability. > +**/ > +UINT8 > +SetAspmPolicy ( > + IN UINT8 PciExpressLinkCapAspm > + ) > +{ > + switch (PciExpressLinkCapAspm) { > + case 0: > + // > + // cannot support ASPM state, disable > + // > + return EFI_PCI_EXPRESS_ASPM_DISABLE; > + case 1: > + // > + // supports only ASPM L0s state > + // > + return EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT; > + case 2: > + // > + // supports only ASPM L1 state > + // > + return EFI_PCI_EXPRESS_ASPM_L1_SUPPORT; > + case 3: > + // > + // supports both L0s and L1 ASPM states > + // > + return EFI_PCI_EXPRESS_ASPM_L0S_L1_SUPPORT; > + } > + return EFI_PCI_EXPRESS_ASPM_DISABLE; > +} > + > +/** > + The main routine to setup the PCI Express feature ASPM as per the > + device-specific platform policy, as well as in complaince with the > +PCI Express > + Base specification Revision 5. > + > + @param PciDevice A pointer to the PCI_IO_DEVICE. > + @param PciExpressConfigurationTable pointer to > + PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > + > + @retval EFI_SUCCESS setup of PCI feature LTR is suc= cessful. > +**/ > +EFI_STATUS > +SetupAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > +*PciExpressConfigurationTable > + ) > +{ > + PCI_REG_PCIE_LINK_CAPABILITY PciExLinkCap; > + PCI_REG_PCIE_DEVICE_CAPABILITY PciExpressDeviceCapability; > + BOOLEAN AlignAspmPolicy; > + > + PciExLinkCap.Uint32 =3D > + PciDevice->PciExpressCapabilityStructure.LinkCapability.Uint32; > + PciExpressDeviceCapability.Uint32 =3D > + PciDevice->PciExpressCapabilityStructure.DeviceCapability.Uint32; > + // > + // ASPM support is only applicable to root bridge and its child > + devices. Not // applicable to empty bridge devices or RCiEP devices > + // if (PciExpressConfigurationTable) { > + PciExpressConfigurationTable->L0sExitLatency =3D MAX ( > + PciExpressConfigurationTable->L0sExitLatency, > + (UINT8)PciExLinkCap.Bits.L0sExitLatency > + ); > + PciExpressConfigurationTable->L1ExitLatency =3D MAX ( > + PciExpressConfigurationTable->L1ExitLatency, > + (UINT8)PciExLinkCap.Bits.L1ExitLatency > + ); > + if (PciDevice->SetupAspm =3D=3D EFI_PCI_EXPRESS_ASPM_AUTO) { > + // > + // set the ASPM support as per device's link capability > + // > + PciDevice->SetupAspm =3D SetAspmPolicy ((UINT8)PciExLinkCap.Bits.= Aspm); > + } else { > + // > + // Check the ASPM device policy is applicable to the link capabil= ity. > + // In case of invalid device policy, there are 2 options: > + // (1) ASPM disable -> platform request rightly denied, and no AS= PM > + // (2) set as per the device capability -> platform request right= ly denied, > + // but still set applicable power management > + // this implementation shall take option 2 to overule invalid pla= tform > request > + // and go with applicable policy as per device capability > + // > + switch (SetAspmPolicy ((UINT8)PciExLinkCap.Bits.Aspm)) { > + case EFI_PCI_EXPRESS_ASPM_DISABLE: > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_ASPM_DISABLE; > + break; > + case EFI_PCI_EXPRESS_ASPM_L1_SUPPORT: > + if (PciDevice->SetupAspm =3D=3D EFI_PCI_EXPRESS_ASPM_L0s_SUPP= ORT) { > + // > + // not applicable, set as per device's link capability > + // > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_ASPM_L1_SUPPORT; > + } > + break; > + case EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT: > + if (PciDevice->SetupAspm =3D=3D EFI_PCI_EXPRESS_ASPM_L1_SUPPO= RT) { > + // > + // not applicable, set as per device's link capability > + // > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT; > + } > + break; > + } > + } > + // > + // set the ASPM policy to minimum state among all the devices links > + // > + PciExpressConfigurationTable->AspmSupport =3D MIN ( > + PciExpressConfigurati= onTable->AspmSupport, > + PciDevice->SetupAspm > + ); > + // > + // check the common ASPM value applicable as per this device capabi= lity, if > + // not applicable disable the ASPM for all the devices > + // > + if ( > + (PciExpressConfigurationTable->AspmSupport =3D=3D > EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT > + && SetAspmPolicy ((UINT8)PciExLinkCap.Bits.Aspm) =3D=3D > EFI_PCI_EXPRESS_ASPM_L1_SUPPORT) > + || > + (PciExpressConfigurationTable->AspmSupport =3D=3D > EFI_PCI_EXPRESS_ASPM_L1_SUPPORT > + && SetAspmPolicy ((UINT8)PciExLinkCap.Bits.Aspm) =3D=3D > EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT) > + ) { > + // > + // disable the ASPM > + // > + PciExpressConfigurationTable->AspmSupport =3D > EFI_PCI_EXPRESS_ASPM_DISABLE; > + PciDevice->SetupAspm =3D PciExpressConfigurationTable->AspmSuppor= t; > + } > + > + if (PciExpressConfigurationTable->AspmSupport !=3D > EFI_PCI_EXPRESS_ASPM_DISABLE) { > + // > + // in case of ASPM policy is not to disable the ASPM support, che= ck other > + // condition of EP device L0s/L1 acceptance latency with the L0s/= L1 exit > + // latencies comprising from this endpoint all the way up to root= complex > + // root port, to determine whether the ASPM L0s/L1 entry can be u= sed with > + // no loss of performance > + // > + if (!IS_PCI_BRIDGE (&PciDevice->Pci)) { > + > + switch (PciExpressConfigurationTable->AspmSupport) { > + case EFI_PCI_EXPRESS_ASPM_L0S_L1_SUPPORT: > + if ( > + PciExpressDeviceCapability.Bits.EndpointL0sAcceptableLa= tency >=3D > PciExpressConfigurationTable->L0sExitLatency > + && PciExpressDeviceCapability.Bits.EndpointL1Acceptable= Latency >=3D > PciExpressConfigurationTable->L1ExitLatency > + ) { > + // > + // both the L0s & L1 acceptance of this endpoint device i= s greater > + // than or equal to all of the comprised L0s & L1 exit la= tencies > + // thus good to set the ASPM to L0s & L1 state > + // > + AlignAspmPolicy =3D TRUE; > + } else { > + // > + // in case the EP device L0s and L1 Acceptance latency do= es not match > + // with the comprised L0s & L1 exit latencies than disabl= e the ASPM > + // state > + // > + AlignAspmPolicy =3D FALSE; > + } > + break; > + > + case EFI_PCI_EXPRESS_ASPM_L1_SUPPORT: > + if ( > + PciExpressDeviceCapability.Bits.EndpointL1AcceptableLat= ency >=3D > PciExpressConfigurationTable->L1ExitLatency > + ) { > + // > + // the endpoint device L1 acceptance latency meets the al= l the > + // comprised L1 exit latencies of all the devices from th= e bridge > + // hence ASPM L1 is applicable state for the PCI tree > + // > + AlignAspmPolicy =3D TRUE; > + } else { > + // > + // in case the EP device L1 Acceptance latency does not m= atch > + // with the comprised L1 exit latencies than disable the = ASPM > + // state > + // > + AlignAspmPolicy =3D FALSE; > + } > + break; > + > + case EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT: > + if ( > + PciExpressDeviceCapability.Bits.EndpointL0sAcceptableLa= tency >=3D > PciExpressConfigurationTable->L0sExitLatency > + ) { > + // > + // the endpoint device L0s acceptance latency meets the a= ll the > + // comprised L0s exit latencies of all the devices from t= he bridge > + // hence ASPM L0s is applicable state for the PCI tree > + // > + AlignAspmPolicy =3D TRUE; > + } else { > + // > + // in case the EP device L0s Acceptance latency does not = match > + // with the comprised L0s exit latencies than disable the= ASPM > + // state > + // > + AlignAspmPolicy =3D FALSE; > + } > + break; > + } > + } else { > + // > + // align the bridge with the global common ASPM value > + // > + AlignAspmPolicy =3D TRUE; > + } > + } else { > + // > + // ASPM is disabled for all the devices > + // > + AlignAspmPolicy =3D FALSE; > + } > + > + if (AlignAspmPolicy) { > + // > + // reset the device's ASPM policy to common minimum value > + // > + if (PciDevice->SetupAspm !=3D PciExpressConfigurationTable->AspmS= upport) { > + PciDevice->SetupAspm =3D PciExpressConfigurationTable->AspmSupp= ort; > + } > + } else { > + // > + // disable the ASPM > + // > + PciExpressConfigurationTable->AspmSupport =3D > EFI_PCI_EXPRESS_ASPM_DISABLE; > + PciDevice->SetupAspm =3D PciExpressConfigurationTable->AspmSuppor= t; > + } > + DEBUG (( > + DEBUG_INFO, > + "Aspm: %d [cap:%d],", > + PciDevice->SetupAspm, > + (PciExLinkCap.Bits.Aspm + 1) > + )); > + } > + > + return EFI_SUCCESS; > +} > + > +/** > + Setup of PCI Express feature ASPM in the > +PciExpressFeatureEntendedSetupPhase > +**/ > +EFI_STATUS > +AlignAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > +*PciExpressConfigurationTable > + ) > +{ > + // > + // ASPM support is only applicable to root bridge and its child > +devices. Not > + // applicable to empty bridge devices or RCiEP devices > + // > + if (PciExpressConfigurationTable) { > + // > + // reset the device's ASPM policy to common minimum ASPM value > + // > + if (PciDevice->SetupAspm !=3D PciExpressConfigurationTable->AspmSup= port) { > + PciDevice->SetupAspm =3D PciExpressConfigurationTable->AspmSuppor= t; > + } > + DEBUG (( > + DEBUG_INFO, > + "Aspm: %d,", > + PciDevice->SetupAspm > + )); > + } > + > + return EFI_SUCCESS; > +} > + > + > +/** > + Get the ASPM value from the ASPM device policy. > +**/ > +UINT8 > +GetAspmValue ( > + IN UINT8 AspmPolicy > + ) > +{ > + switch (AspmPolicy) { > + case EFI_PCI_EXPRESS_ASPM_DISABLE: > + // > + // ASPM disable > + // > + return 0; > + case EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT: > + // > + // ASPM L0s state > + // > + return 1; > + case EFI_PCI_EXPRESS_ASPM_L1_SUPPORT: > + // > + // ASPM L1 state > + // > + return 2; > + case EFI_PCI_EXPRESS_ASPM_L0S_L1_SUPPORT: > + // > + // L0s and L1 ASPM states > + // > + return 3; > + } > + return 0; > +} > + > +/** > + Program the PCIe Link Control register ASPM Control field; if > + the hardware value is different than the intended value. > + > + @param PciDevice A pointer to the PCI_IO_DEVICE instance= . > + > + @retval EFI_SUCCESS The data was read from or written to th= e PCI > device. > + @retval EFI_UNSUPPORTED The address range specified by Offset, = Width, > and Count is not > + valid for the PCI configuration header = of the PCI controller. > + @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid. > + > +**/ > +EFI_STATUS > +ProgramAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN VOID *PciExFeatureConfiguration > + ) > +{ > + PCI_REG_PCIE_LINK_CONTROL LinkCtl; > + UINT32 Offset; > + EFI_STATUS Status; > + EFI_TPL OldTpl; > + UINT8 AspmValue; > + > + // > + // ASPM support is only applicable to root bridge and its child > + devices. Not // applicable to empty bridge devices or RCiEP devices > + // if (!PciExFeatureConfiguration) { > + return EFI_SUCCESS; > + } > + > + // > + // read the link Control register for the ASPM Control // > + LinkCtl.Uint16 =3D 0; > + Offset =3D PciDevice->PciExpressCapabilityOffset + > + OFFSET_OF (PCI_CAPABILITY_PCIEXP, LinkControl); Status = =3D > + PciDevice->PciIo.Pci.Read ( > + &PciDevice->PciIo, > + EfiPciIoWidthUint16, > + Offset, > + 1, > + &LinkCtl.Uint16 > + ); > + ASSERT (Status =3D=3D EFI_SUCCESS); > + > + AspmValue =3D GetAspmValue (PciDevice->SetupAspm); if (AspmValue != =3D > + LinkCtl.Bits.AspmControl) { > + DEBUG (( > + DEBUG_INFO, > + "Aspm: %d,", > + AspmValue > + )); > + // > + // Raise TPL to high level to disable timer interrupt while the wri= te operation > completes > + // > + OldTpl =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); > + > + Status =3D PciDevice->PciIo.Pci.Write ( > + &PciDevice->PciIo, > + EfiPciIoWidthUint16, > + Offset, > + 1, > + &LinkCtl.Uint16 > + ); > + // > + // Restore TPL to its original level > + // > + gBS->RestoreTPL (OldTpl); > + > + if (!EFI_ERROR (Status)) { > + PciDevice->PciExpressCapabilityStructure.LinkControl.Uint16 =3D > LinkCtl.Uint16; > + } else { > + ReportPciWriteError (PciDevice->BusNumber, PciDevice->DeviceNumbe= r, > PciDevice->FunctionNumber, Offset); > + return Status; > + } > + } else { > + DEBUG (( > + DEBUG_INFO, > + "No Aspm (%d),", > + AspmValue > + )); > + } > + return EFI_SUCCESS; > +} > + > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.h > index 1cfca54..351c61e 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciExpressFeatures.h > @@ -9,6 +9,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef > _EFI_PCI_EXPRESS_FEATURES_H_ #define _EFI_PCI_EXPRESS_FEATURES_H_ >=20 > +// > +// PCIe L0s Exit Latencies declarations // > +#define PCIE_LINK_CAPABILITY_L0S_EXIT_LATENCY_64NS 0 // less than 64= ns > + > +// > +// PCIe L1 Exit latencies declarations > +// > +#define PCIE_LINK_CAPABILITY_L1_EXIT_LATENCY_1US 0 // less than 1u= s >=20 > /** > The main routine which process the PCI feature Max_Payload_Size as pe= r the > @@ -293,4 +302,47 @@ ProgramExtTag ( > IN VOID *PciExFeatureConfiguration > ); >=20 > +/** > + The main routine to setup the PCI Express feature ASPM as per the > + device-specific platform policy, as well as in complaince with the > +PCI Express > + Base specification Revision 5. > + > + @param PciDevice A pointer to the PCI_IO_DEVICE. > + @param PciFeaturesConfigurationTable pointer to > + PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > + > + @retval EFI_SUCCESS setup of PCI feature LTR is suc= cessful. > +**/ > +EFI_STATUS > +SetupAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > +*PciFeaturesConfigurationTable > + ); > + > +/** > + Setup of PCI Express feature ASPM in the > +PciExpressFeatureEntendedSetupPhase > +**/ > +EFI_STATUS > +AlignAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE > +*PciFeaturesConfigurationTable > + ); > + > +/** > + Program the PCIe Link Control register ASPM Control field; if > + the hardware value is different than the intended value. > + > + @param PciDevice A pointer to the PCI_IO_DEVICE instance= . > + > + @retval EFI_SUCCESS The data was read from or written to th= e PCI > device. > + @retval EFI_UNSUPPORTED The address range specified by Offset, = Width, > and Count is not > + valid for the PCI configuration header = of the PCI controller. > + @retval EFI_INVALID_PARAMETER Buffer is NULL or Width is invalid. > + > +**/ > +EFI_STATUS > +ProgramAspm ( > + IN PCI_IO_DEVICE *PciDevice, > + IN VOID *PciExFeatureConfiguration > + ); > + > #endif > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.c > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.c > index 58d3780..24781c6 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.c > @@ -50,7 +50,7 @@ EFI_PCI_EXPRESS_PLATFORM_POLICY > mPciExpressPlatformPolicy =3D { > // > // support for PCI Express feature - ASPM state > // > - FALSE, > + TRUE, > // > // support for PCI Express feature - Common Clock Configuration > // > @@ -96,6 +96,15 @@ BOOLEAN mPciExpressGetPlatformPolicyComplete =3D > FALSE; > // > PCI_EXPRESS_FEATURE_INITIALIZATION_POINT > mPciExpressFeatureInitializationList[] =3D { >=20 > + { > + PciExpressFeatureSetupPhase, PciExpressAspm, SetupAs= pm > + }, > + { > + PciExpressFeatureEntendedSetupPhase, PciExpressAspm, AlignAs= pm > + }, > + { > + PciExpressFeatureProgramPhase, PciExpressAspm, Program= Aspm > + }, > { > PciExpressFeatureSetupPhase, PciExpressMps, SetupMa= xPayloadSize > }, > @@ -688,6 +697,18 @@ CreatePciRootBridgeDeviceNode ( > // start by assuming the Extended Tag is 10b Requester capable > // > PciConfigTable->ExtendedTag =3D > EFI_PCI_EXPRESS_EXTENDED_TAG_10BIT; > + // > + // initial state set to ASPM L0s and L1 both > + // > + PciConfigTable->AspmSupport =3D > EFI_PCI_EXPRESS_ASPM_L0S_L1_SUPPORT; > + // > + // start by assuming less than 64ns of L0s Exit Latency > + // > + PciConfigTable->L0sExitLatency =3D > PCIE_LINK_CAPABILITY_L0S_EXIT_LATENCY_64NS; > + // > + // start by assuming less than 1us of L1 Exit Latency > + // > + PciConfigTable->L1ExitLatency =3D > PCIE_LINK_CAPABILITY_L1_EXIT_LATENCY_1US; > } >=20 > RootBridgeNode->PciExFeaturesConfigurationTable =3D PciConfigTable; = diff -- > git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.h > index c7cc7e5..5e0f43b 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciFeatureSupport.h > @@ -98,6 +98,20 @@ struct > _PCI_EXPRESS_FEATURES_CONFIGURATION_TABLE { > // to configure a common extended tag size for all the childs of a ro= ot port > // > UINT8 ExtendedTag; > + // > + // to configure common ASPM state for all the devices link // > + UINT8 AspmSupport; > + // > + // to record maximum L0s Exit Latency among all the devices starting > + from root // bridge device to its downstream bridge and its endpoint > + device // > + UINT8 L0sExitLatency; > + // > + // to record maximum L1 Exit Latency among all the devices starting > + from root // bridge device to its downstream bridge and its endpoint > + device // > + UINT8 L1ExitLatency; > }; >=20 > // > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciPlatformSupport.c > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciPlatformSupport.c > index 98d9875..f301557 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciPlatformSupport.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciPlatformSupport.c > @@ -374,6 +374,16 @@ SetupDefaultPciExpressDevicePolicy ( > PciDevice->SetupExtTag =3D EFI_PCI_EXPRESS_NOT_APPLICABLE; > } >=20 > + // > + // default device policy for device's link ASPM // if > + (mPciExpressPlatformPolicy.Aspm) { > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_ASPM_AUTO; } else { > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_NOT_APPLICABLE; } > + > + > } >=20 > /** > @@ -517,6 +527,14 @@ GetPciExpressDevicePolicy ( > PciDevice->SetupExtTag =3D EFI_PCI_EXPRESS_NOT_APPLICABLE; > } >=20 > + // > + // set the device-specific policy for the PCI Express feature ASPM > + // > + if (mPciExpressPlatformPolicy.Aspm) { > + PciDevice->SetupAspm =3D PciExpressDevicePolicy.LinkCtlASPMState; > + } else { > + PciDevice->SetupAspm =3D EFI_PCI_EXPRESS_NOT_APPLICABLE; > + } >=20 > DEBUG (( > DEBUG_INFO, > @@ -697,6 +715,24 @@ GetPciExpressExtTag ( > } > } >=20 > +EFI_PCI_EXPRESS_ASPM_SUPPORT > +GetPciExpressAspmState ( > + IN PCI_IO_DEVICE *PciDevice > + ) > +{ > + switch (PciDevice- > >PciExpressCapabilityStructure.LinkControl.Bits.AspmControl) { > + case 0: > + return EFI_PCI_EXPRESS_ASPM_DISABLE; > + case 1: > + return EFI_PCI_EXPRESS_ASPM_L0s_SUPPORT; > + case 2: > + return EFI_PCI_EXPRESS_ASPM_L1_SUPPORT; > + case 3: > + return EFI_PCI_EXPRESS_ASPM_L0S_L1_SUPPORT; > + } > + return EFI_PCI_EXPRESS_NOT_APPLICABLE; } > + > /** > Notifies the platform about the current PCI Express state of the devi= ce. >=20 > @@ -805,6 +841,15 @@ PciExpressPlatformNotifyDeviceState ( > PciExDeviceConfiguration.DeviceCtlExtTag =3D > EFI_PCI_EXPRESS_NOT_APPLICABLE; > } >=20 > + // > + // get the device-specific state for PCIe ASPM state // if > + (mPciExpressPlatformPolicy.Aspm) { > + PciExDeviceConfiguration.LinkCtlASPMState =3D GetPciExpressAspmStat= e > + (PciDevice); } else { > + PciExDeviceConfiguration.LinkCtlASPMState =3D > + EFI_PCI_EXPRESS_NOT_APPLICABLE; } > + > if (mPciExPlatformProtocol !=3D NULL) { > return mPciExPlatformProtocol->NotifyDeviceState ( > mPciExPlatformProtocol, > -- > 2.21.0.windows.1 >=20 >=20 >=20